34 lines
841 B
C#
34 lines
841 B
C#
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<string, Session> Sessions;
|
|
|
|
public ActiveSessionManager()
|
|
{
|
|
Sessions = new ConcurrentDictionary<string, Session>();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|