using Gameboard.ShogiUI.Sockets.Models; using System.Collections.Concurrent; namespace Gameboard.ShogiUI.Sockets.Managers { public interface IActiveSessionManager { void Add(Session session); Session? Get(string sessionName); } // TODO: Consider moving this class' functionality into the ConnectionManager class. public class ActiveSessionManager : IActiveSessionManager { private readonly ConcurrentDictionary Sessions; public ActiveSessionManager() { Sessions = new ConcurrentDictionary(); } public void Add(Session session) => Sessions.TryAdd(session.Name, session); public Session? Get(string sessionName) { if (Sessions.TryGetValue(sessionName, out var session)) { return session; } return null; } } }