From e0453b237211da8a116d9b9dce24eae5f43d20f9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 26 Dec 2023 20:58:22 -0600 Subject: add ListScansAsync --- src/slskd/Shares/IShareService.cs | 53 +++++++++++++++++++++++---------------- src/slskd/Shares/ShareService.cs | 39 +++++++++++++++++----------- 2 files changed, 55 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index aea3240a..957b0639 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -17,7 +17,9 @@ namespace slskd.Shares { + using System; using System.Collections.Generic; + using System.Linq.Expressions; using System.Threading.Tasks; using Soulseek; @@ -61,12 +63,11 @@ namespace slskd.Shares Task DumpAsync(string filename); /// - /// Returns the share host with the specified . + /// Initializes the service and shares. /// - /// The name of the host. - /// The host, if found. - /// A value indicating whether the host was found. - bool TryGetHost(string name, out Host host); + /// A value indicating whether a full re-scan of shares should be performed. + /// The operation context. + Task InitializeAsync(bool forceRescan = false); /// /// Returns the contents of the specified . @@ -76,11 +77,16 @@ namespace slskd.Shares Task ListDirectoryAsync(string directory); /// - /// Removes the share host with the specified . + /// Returns the list of all records matching the specified . /// - /// The name of the host. - /// A value indicating whether the host was removed. - bool TryRemoveHost(string name); + /// An optional expression used to locate scans. + /// The operation context, including the list of found scans. + Task> ListScansAsync(Expression> predicate = null); + + /// + /// Requests that a share scan is performed. + /// + void RequestScan(); /// /// Resolves the local filename of the specified , if the mask is associated with a @@ -94,9 +100,11 @@ namespace slskd.Shares Task<(string Host, string Filename)> ResolveFileAsync(string remoteFilename); /// - /// Requests that a share scan is performed. + /// Scans the configured shares on the local host. /// - void RequestScan(); + /// The operation context. + /// Thrown when a scan is already in progress. + Task ScanAsync(); /// /// Searches the cache for the specified and returns the matching files. @@ -105,13 +113,6 @@ namespace slskd.Shares /// The matching files. Task> SearchAsync(SearchQuery query); - /// - /// Scans the configured shares on the local host. - /// - /// The operation context. - /// Thrown when a scan is already in progress. - Task ScanAsync(); - /// /// Cancels the currently running scan on the local host, if one is running. /// @@ -119,10 +120,18 @@ namespace slskd.Shares bool TryCancelScan(); /// - /// Initializes the service and shares. + /// Returns the share host with the specified . /// - /// A value indicating whether a full re-scan of shares should be performed. - /// The operation context. - Task InitializeAsync(bool forceRescan = false); + /// The name of the host. + /// The host, if found. + /// A value indicating whether the host was found. + bool TryGetHost(string name, out Host host); + + /// + /// Removes the share host with the specified . + /// + /// The name of the host. + /// A value indicating whether the host was removed. + bool TryRemoveHost(string name); } } \ No newline at end of file diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index 98f76e72..7ca366b7 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -23,6 +23,7 @@ namespace slskd.Shares using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; + using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using Serilog; @@ -306,6 +307,14 @@ namespace slskd.Shares throw new NotFoundException($"The requested filename '{remoteFilename}' could not be resolved to a physical file"); } + /// + /// Returns the list of all records matching the specified . + /// + /// An optional expression used to locate scans. + /// The operation context, including the list of found scans. + public Task> ListScansAsync(Expression> predicate = null) + => Task.FromResult(Local.Repository.ListScans(predicate)); + /// /// Requests that a share scan is performed. /// @@ -344,25 +353,25 @@ namespace slskd.Shares try { - State.SetValue(state => state with { Ready = false }); + State.SetValue(state => state with { Ready = false }); - await Scanner.ScanAsync(Local.Host.Shares, OptionsMonitor.CurrentValue.Shares, Local.Repository); + await Scanner.ScanAsync(Local.Host.Shares, OptionsMonitor.CurrentValue.Shares, Local.Repository); - Log.Debug("Backing up shared file cache database..."); - Local.Repository.BackupTo(ShareRepositoryFactory.CreateFromHostBackup(Local.Host.Name)); - Log.Debug("Shared file cache database backup complete"); + Log.Debug("Backing up shared file cache database..."); + Local.Repository.BackupTo(ShareRepositoryFactory.CreateFromHostBackup(Local.Host.Name)); + Log.Debug("Shared file cache database backup complete"); - Log.Debug("Recomputing share statistics..."); - ComputeShareStatistics(); - Log.Debug("Share statistics updated: {Shares}", Local.Host.Shares.ToJson()); + Log.Debug("Recomputing share statistics..."); + ComputeShareStatistics(); + Log.Debug("Share statistics updated: {Shares}", Local.Host.Shares.ToJson()); - State.SetValue(state => state with - { - Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories ?? 0 ), - Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files ?? 0), - Ready = true, - }); - } + State.SetValue(state => state with + { + Directories = Hosts.SelectMany(host => host.Shares).Sum(share => share.Directories ?? 0), + Files = Hosts.SelectMany(host => host.Shares).Sum(share => share.Files ?? 0), + Ready = true, + }); + } finally { ScannerSyncRoot.Release(); -- cgit v1.2.3