using System; using System.Collections.Generic; using System.Linq; namespace Asb.Base.V2; public class SysAuthenticatorServiceCache : SynchronizedKeyedCollection { private static readonly SysAuthenticatorServiceCache serviceConnections = new SysAuthenticatorServiceCache(); private static readonly object serviceCacheLockObject = new object(); private SysAuthenticatorServiceCache() { } public static IEnumerable GetAllServiceAuthenticators() { return serviceConnections.Items.AsEnumerable(); } public static void AddServiceAuthenticator(SystemAuthenticationServiceAuthentication serviceAuthenticator) { if (serviceAuthenticator == null) { return; } lock (serviceCacheLockObject) { if (!serviceConnections.Contains(serviceAuthenticator.ConnectionId)) { serviceConnections.Add(serviceAuthenticator); } } } public static SystemAuthenticationServiceAuthentication GetServiceAuthenticator(Guid connectionId) { SystemAuthenticationServiceAuthentication result = null; lock (serviceCacheLockObject) { if (serviceConnections.Contains(connectionId)) { result = serviceConnections[connectionId]; } } return result; } public static SystemAuthenticationServiceAuthentication RemoveServiceAuthenticator(Guid connectionId) { SystemAuthenticationServiceAuthentication serviceAuthenticator = GetServiceAuthenticator(connectionId); if (serviceAuthenticator != null) { lock (serviceCacheLockObject) { serviceConnections.Remove(connectionId); } } return serviceAuthenticator; } protected override Guid GetKeyForItem(SystemAuthenticationServiceAuthentication item) { return item.ConnectionId; } }