aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-12-26 20:58:22 -0600
committerJP Dillingham <jp@dillingham.me>2023-12-26 20:58:22 -0600
commite0453b237211da8a116d9b9dce24eae5f43d20f9 (patch)
tree40140a0d9540c7172f0b395c2f698e81656d07f9 /src
parentb55d2dcb2d4e04553a34a1044fd85f0ab579b786 (diff)
downloadslskd-e0453b237211da8a116d9b9dce24eae5f43d20f9.tar.gz
add ListScansAsync
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Shares/IShareService.cs53
-rw-r--r--src/slskd/Shares/ShareService.cs39
2 files changed, 55 insertions, 37 deletions
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);
/// <summary>
- /// Returns the share host with the specified <paramref name="name"/>.
+ /// Initializes the service and shares.
/// </summary>
- /// <param name="name">The name of the host.</param>
- /// <param name="host">The host, if found.</param>
- /// <returns>A value indicating whether the host was found.</returns>
- bool TryGetHost(string name, out Host host);
+ /// <param name="forceRescan">A value indicating whether a full re-scan of shares should be performed.</param>
+ /// <returns>The operation context.</returns>
+ Task InitializeAsync(bool forceRescan = false);
/// <summary>
/// Returns the contents of the specified <paramref name="directory"/>.
@@ -76,11 +77,16 @@ namespace slskd.Shares
Task<Directory> ListDirectoryAsync(string directory);
/// <summary>
- /// Removes the share host with the specified <paramref name="name"/>.
+ /// Returns the list of all <see cref="Scan"/> records matching the specified <paramref name="predicate"/>.
/// </summary>
- /// <param name="name">The name of the host.</param>
- /// <returns>A value indicating whether the host was removed.</returns>
- bool TryRemoveHost(string name);
+ /// <param name="predicate">An optional expression used to locate scans.</param>
+ /// <returns>The operation context, including the list of found scans.</returns>
+ Task<IEnumerable<Scan>> ListScansAsync(Expression<Func<Scan, bool>> predicate = null);
+
+ /// <summary>
+ /// Requests that a share scan is performed.
+ /// </summary>
+ void RequestScan();
/// <summary>
/// Resolves the local filename of the specified <paramref name="remoteFilename"/>, if the mask is associated with a
@@ -94,9 +100,11 @@ namespace slskd.Shares
Task<(string Host, string Filename)> ResolveFileAsync(string remoteFilename);
/// <summary>
- /// Requests that a share scan is performed.
+ /// Scans the configured shares on the local host.
/// </summary>
- void RequestScan();
+ /// <returns>The operation context.</returns>
+ /// <exception cref="ShareScanInProgressException">Thrown when a scan is already in progress.</exception>
+ Task ScanAsync();
/// <summary>
/// Searches the cache for the specified <paramref name="query"/> and returns the matching files.
@@ -106,23 +114,24 @@ namespace slskd.Shares
Task<IEnumerable<File>> SearchAsync(SearchQuery query);
/// <summary>
- /// Scans the configured shares on the local host.
- /// </summary>
- /// <returns>The operation context.</returns>
- /// <exception cref="ShareScanInProgressException">Thrown when a scan is already in progress.</exception>
- Task ScanAsync();
-
- /// <summary>
/// Cancels the currently running scan on the local host, if one is running.
/// </summary>
/// <returns>A value indicating whether a scan was cancelled.</returns>
bool TryCancelScan();
/// <summary>
- /// Initializes the service and shares.
+ /// Returns the share host with the specified <paramref name="name"/>.
/// </summary>
- /// <param name="forceRescan">A value indicating whether a full re-scan of shares should be performed.</param>
- /// <returns>The operation context.</returns>
- Task InitializeAsync(bool forceRescan = false);
+ /// <param name="name">The name of the host.</param>
+ /// <param name="host">The host, if found.</param>
+ /// <returns>A value indicating whether the host was found.</returns>
+ bool TryGetHost(string name, out Host host);
+
+ /// <summary>
+ /// Removes the share host with the specified <paramref name="name"/>.
+ /// </summary>
+ /// <param name="name">The name of the host.</param>
+ /// <returns>A value indicating whether the host was removed.</returns>
+ 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;
@@ -307,6 +308,14 @@ namespace slskd.Shares
}
/// <summary>
+ /// Returns the list of all <see cref="Scan"/> records matching the specified <paramref name="predicate"/>.
+ /// </summary>
+ /// <param name="predicate">An optional expression used to locate scans.</param>
+ /// <returns>The operation context, including the list of found scans.</returns>
+ public Task<IEnumerable<Scan>> ListScansAsync(Expression<Func<Scan, bool>> predicate = null)
+ => Task.FromResult(Local.Repository.ListScans(predicate));
+
+ /// <summary>
/// Requests that a share scan is performed.
/// </summary>
public void RequestScan()
@@ -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();