using Serilog; namespace CommonSocketLibrary.Abstract { public abstract class HandlerManager { private readonly IDictionary _handlers; protected readonly ILogger _logger; public IDictionary Handlers { get => _handlers; } public HandlerManager(ILogger logger) { _handlers = new Dictionary(); _logger = logger; } protected void Add(int op, Handler handler) { _handlers.Add(op, handler); } public async Task Execute(Client sender, int opcode, T val) { if (opcode < 0 || !_handlers.TryGetValue(opcode, out Handler? handler) || handler == null) { _logger.Warning("Invalid opcode received: " + opcode); return; } await Execute(sender, handler, val); } protected abstract Task Execute(Client sender, Handler handler, T value); } }