From 56f164196192ffbe62bb9ba2684d5db45f223f24 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 11 Oct 2022 19:05:55 -0500 Subject: add agent shares --- src/slskd/Shares/IShareService.cs | 12 ++++++++++++ src/slskd/Shares/ShareService.cs | 28 +++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Shares/IShareService.cs b/src/slskd/Shares/IShareService.cs index 2a18f5b3..3ec5fd56 100644 --- a/src/slskd/Shares/IShareService.cs +++ b/src/slskd/Shares/IShareService.cs @@ -38,6 +38,18 @@ namespace slskd.Shares /// public IStateMonitor StateMonitor { get; } + /// + /// Adds the shares associated with the specified . + /// + /// The name of the agent. + void AddAgentShares(string agent); + + /// + /// Remotes the shares associated with the specified . + /// + /// The name of the agent. + void RemoveAgentShares(string agent); + /// /// Returns the entire contents of the share. /// diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs index a9c8c629..d500532d 100644 --- a/src/slskd/Shares/ShareService.cs +++ b/src/slskd/Shares/ShareService.cs @@ -24,7 +24,6 @@ namespace slskd.Shares using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; - using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Serilog; @@ -96,6 +95,33 @@ namespace slskd.Shares private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1); private StorageMode CacheStorageMode { get; } private ILogger Log { get; } = Serilog.Log.ForContext(); + private ConcurrentDictionary AgentRepositories { get; } = new(); + + /// + /// Adds the shares associated with the specified . + /// + /// The name of the agent. + public void AddAgentShares(string agent) + { + if (string.IsNullOrEmpty(agent)) + { + throw new ArgumentNullException(nameof(agent)); + } + + AgentRepositories.AddOrUpdate( + key: agent, + addValue: new ShareRepository(BuildConnectionString(agent)), + updateValueFactory: (agent, repository) => new ShareRepository(BuildConnectionString(agent))); + } + + /// + /// Remotes the shares associated with the specified . + /// + /// The name of the agent. + public void RemoveAgentShares(string agent) + { + AgentRepositories.TryRemove(agent, out _); + } /// /// Returns the entire contents of the share. -- cgit v1.2.3