diff options
| author | JP Dillingham <jp@dillingham.me> | 2023-09-17 16:18:10 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2023-09-17 16:18:10 -0500 |
| commit | 77201c8144bd88cb5a1f9cc4f5a0a939dd0c46e9 (patch) | |
| tree | b1526093dc196d4d2c9970fa02b1d54e7b4699e5 /src | |
| parent | 38b5449d622e8d7a12708a182a7498ad955654a3 (diff) | |
| download | slskd-77201c8144bd88cb5a1f9cc4f5a0a939dd0c46e9.tar.gz | |
consolidate I/DownloadService
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Transfers/Downloads/DownloadService.cs | 78 | ||||
| -rw-r--r-- | src/slskd/Transfers/Downloads/IDownloadService.cs | 94 |
2 files changed, 78 insertions, 94 deletions
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 827a0528..685bcb43 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -36,6 +36,84 @@ namespace slskd.Transfers.Downloads /// <summary> /// Manages downloads. /// </summary> + public interface IDownloadService + { + /// <summary> + /// Adds the specified <paramref name="transfer"/>. Supersedes any existing record for the same file and username. + /// </summary> + /// <remarks>This should generally not be called; use EnqueueAsync() instead.</remarks> + /// <param name="transfer"></param> + void AddOrSupersede(Transfer transfer); + + /// <summary> + /// Enqueues the requested list of <paramref name="files"/>. + /// </summary> + /// <remarks> + /// If one file in the specified collection fails, the rest will continue. An <see cref="AggregateException"/> will be + /// thrown after all files are dispositioned if any throws. + /// </remarks> + /// <param name="username">The username of remote user.</param> + /// <param name="files">The list of files to enqueue.</param> + /// <returns>The operation context.</returns> + /// <exception cref="ArgumentException">Thrown when the username is null or an empty string.</exception> + /// <exception cref="ArgumentException">Thrown when no files are requested.</exception> + /// <exception cref="AggregateException">Thrown when at least one of the requested files throws.</exception> + Task EnqueueAsync(string username, IEnumerable<(string Filename, long Size)> files); + + /// <summary> + /// Finds a single download matching the specified <paramref name="expression"/>. + /// </summary> + /// <param name="expression">The expression to use to match downloads.</param> + /// <returns>The found transfer, or default if not found.</returns> + Transfer Find(Expression<Func<Transfer, bool>> expression); + + /// <summary> + /// Retrieves the place in the remote queue for the download matching the specified <paramref name="id"/>. + /// </summary> + /// <param name="id">The unique identifier for the download.</param> + /// <returns>The retrieved place in queue.</returns> + Task<int> GetPlaceInQueueAsync(Guid id); + + /// <summary> + /// Returns a list of all downloads matching the optional <paramref name="expression"/>. + /// </summary> + /// <param name="expression">An optional expression used to match downloads.</param> + /// <param name="includeRemoved">Optionally include downloads that have been removed previously.</param> + /// <returns>The list of downloads matching the specified expression, or all downloads if no expression is specified.</returns> + List<Transfer> List(Expression<Func<Transfer, bool>> expression = null, bool includeRemoved = false); + + /// <summary> + /// Removes <see cref="TransferStates.Completed"/> downloads older than the specified <paramref name="age"/>. + /// </summary> + /// <param name="age">The age after which downloads are eligible for pruning, in hours.</param> + /// <param name="state">An optional, additional state by which downloads are filtered for pruning.</param> + /// <returns>The number of pruned downloads.</returns> + int Prune(int age, TransferStates state = TransferStates.Completed); + + /// <summary> + /// Removes the download matching the specified <paramref name="id"/>. + /// </summary> + /// <remarks>This is a soft delete; the record is retained for historical retrieval.</remarks> + /// <param name="id">The unique identifier of the download.</param> + void Remove(Guid id); + + /// <summary> + /// Cancels the download matching the specified <paramref name="id"/>, if it is in progress. + /// </summary> + /// <param name="id">The unique identifier for the download.</param> + /// <returns>A value indicating whether the download was successfully cancelled.</returns> + bool TryCancel(Guid id); + + /// <summary> + /// Updates the specified <paramref name="transfer"/>. + /// </summary> + /// <param name="transfer">The transfer to update.</param> + void Update(Transfer transfer); + } + + /// <summary> + /// Manages downloads. + /// </summary> public class DownloadService : IDownloadService { public DownloadService( diff --git a/src/slskd/Transfers/Downloads/IDownloadService.cs b/src/slskd/Transfers/Downloads/IDownloadService.cs deleted file mode 100644 index b49d575c..00000000 --- a/src/slskd/Transfers/Downloads/IDownloadService.cs +++ /dev/null @@ -1,94 +0,0 @@ -// <copyright file="IDownloadService.cs" company="slskd Team"> -// 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/. -// </copyright> - -namespace slskd.Transfers.Downloads -{ - using System; - using System.Collections.Generic; - using System.Linq.Expressions; - using System.Threading.Tasks; - - /// <summary> - /// Manages downloads. - /// </summary> - public interface IDownloadService - { - /// <summary> - /// Adds the specified <paramref name="transfer"/>. Supersedes any existing record for the same file and username. - /// </summary> - /// <remarks>This should generally not be called; use EnqueueAsync() instead.</remarks> - /// <param name="transfer"></param> - void AddOrSupersede(Transfer transfer); - - /// <summary> - /// Enqueues the requested list of <paramref name="files"/>. - /// </summary> - /// <remarks> - /// If one file in the specified collection fails, the rest will continue. An <see cref="AggregateException"/> will be - /// thrown after all files are dispositioned if any throws. - /// </remarks> - /// <param name="username">The username of remote user.</param> - /// <param name="files">The list of files to enqueue.</param> - /// <returns>The operation context.</returns> - /// <exception cref="ArgumentException">Thrown when the username is null or an empty string.</exception> - /// <exception cref="ArgumentException">Thrown when no files are requested.</exception> - /// <exception cref="AggregateException">Thrown when at least one of the requested files throws.</exception> - Task EnqueueAsync(string username, IEnumerable<(string Filename, long Size)> files); - - /// <summary> - /// Finds a single download matching the specified <paramref name="expression"/>. - /// </summary> - /// <param name="expression">The expression to use to match downloads.</param> - /// <returns>The found transfer, or default if not found.</returns> - Transfer Find(Expression<Func<Transfer, bool>> expression); - - /// <summary> - /// Retrieves the place in the remote queue for the download matching the specified <paramref name="id"/>. - /// </summary> - /// <param name="id">The unique identifier for the download.</param> - /// <returns>The retrieved place in queue.</returns> - Task<int> GetPlaceInQueueAsync(Guid id); - - /// <summary> - /// Returns a list of all downloads matching the optional <paramref name="expression"/>. - /// </summary> - /// <param name="expression">An optional expression used to match downloads.</param> - /// <param name="includeRemoved">Optionally include downloads that have been removed previously.</param> - /// <returns>The list of downloads matching the specified expression, or all downloads if no expression is specified.</returns> - List<Transfer> List(Expression<Func<Transfer, bool>> expression = null, bool includeRemoved = false); - - /// <summary> - /// Removes the download matching the specified <paramref name="id"/>. - /// </summary> - /// <remarks>This is a soft delete; the record is retained for historical retrieval.</remarks> - /// <param name="id">The unique identifier of the download.</param> - void Remove(Guid id); - - /// <summary> - /// Cancels the download matching the specified <paramref name="id"/>, if it is in progress. - /// </summary> - /// <param name="id">The unique identifier for the download.</param> - /// <returns>A value indicating whether the download was successfully cancelled.</returns> - bool TryCancel(Guid id); - - /// <summary> - /// Updates the specified <paramref name="transfer"/>. - /// </summary> - /// <param name="transfer">The transfer to update.</param> - void Update(Transfer transfer); - } -}
\ No newline at end of file |
