From 8d77e37304d16cae7d1b4528cdbce8ffd62e02ee Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 2 Feb 2022 08:22:43 -0600 Subject: add TransferService to encapsulate Governor and UploadQueue --- src/slskd/Transfers/TransferService.cs | 78 ++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/slskd/Transfers/TransferService.cs (limited to 'src/slskd/Transfers/TransferService.cs') diff --git a/src/slskd/Transfers/TransferService.cs b/src/slskd/Transfers/TransferService.cs new file mode 100644 index 00000000..952e5e38 --- /dev/null +++ b/src/slskd/Transfers/TransferService.cs @@ -0,0 +1,78 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +using Microsoft.Extensions.Options; + +namespace slskd.Transfers +{ + using slskd.Users; + + /// + /// Manages transfers. + /// + public interface ITransferService + { + /// + /// Gets the upload governor. + /// + IGovernor Governor { get; } + + /// + /// Gets the upload queue. + /// + IUploadQueue Uploads { get; } + } + + /// + /// Manages transfers. + /// + public class TransferService : ITransferService + { + /// + /// Initializes a new instance of the class. + /// + /// The UserService instance to use. + /// The OptionsMonitor instance to use. + /// The optional Governor instance to use. + /// The optional UploadQueue instance to use. + public TransferService( + IUserService userService, + IOptionsMonitor optionsMonitor, + IGovernor governor = null, + IUploadQueue uploadQueue = null) + { + Users = userService; + OptionsMonitor = optionsMonitor; + + Governor = governor ?? new Governor(userService: Users, optionsMonitor: OptionsMonitor); + Uploads = uploadQueue ?? new UploadQueue(userService: Users, optionsMonitor: OptionsMonitor); + } + + /// + /// Gets the upload governor. + /// + public IGovernor Governor { get; init; } + + /// + /// Gets the upload queue. + /// + public IUploadQueue Uploads { get; init; } + + private IOptionsMonitor OptionsMonitor { get; init; } + private IUserService Users { get; init; } + } +} \ No newline at end of file -- cgit v1.2.3