using System; using System.Collections.Generic; namespace ArchestrAServices.ASBContract; public class SysAuthenticatorServiceCache : SynchronizedKeyedCollection { private static readonly SysAuthenticatorServiceCache serviceConnections = new SysAuthenticatorServiceCache(); private static object ServiceCacheLockObject = new object(); private SysAuthenticatorServiceCache() { } public static IEnumerable GetAllServiceAuthenticators() { List list = new List(); lock (ServiceCacheLockObject) { list.AddRange(serviceConnections.Items); return list; } } public static void AddServiceAuthenticator(SysAuthServiceAuthentication serviceAuthenticator) { if (serviceAuthenticator == null) { return; } lock (ServiceCacheLockObject) { if (!serviceConnections.Contains(serviceAuthenticator.connectionID)) { serviceConnections.Add(serviceAuthenticator); } } } public static SysAuthServiceAuthentication GetServiceAuthenticator(Guid connectionId) { SysAuthServiceAuthentication result = null; lock (ServiceCacheLockObject) { if (serviceConnections.Contains(connectionId)) { result = serviceConnections[connectionId]; } } return result; } public static SysAuthServiceAuthentication RemoveServiceAuthenticator(Guid connectionId) { SysAuthServiceAuthentication serviceAuthenticator = GetServiceAuthenticator(connectionId); if (serviceAuthenticator != null) { lock (ServiceCacheLockObject) { serviceConnections.Remove(connectionId); } } return serviceAuthenticator; } protected override Guid GetKeyForItem(SysAuthServiceAuthentication item) { return item.connectionID; } }