using HermesSocketLibrary.Socket.Data; using Serilog; namespace HermesSocketLibrary.Requests { public class RequestManager : IRequestManager { private readonly IDictionary _requests; private readonly ILogger _logger; public RequestManager(IEnumerable requests, ILogger logger) { _logger = logger; _requests = requests.ToDictionary(r => r.Name, r => r); } public async Task Grant(string sender, RequestMessage? message) { if (message == null || message.Type == null) return new RequestResult(false, null); if (!_requests.TryGetValue(message.Type, out IRequest? request) || request == null) { _logger.Warning($"Did not find request type '{message.Type}'."); return new RequestResult(false, null); } try { return await request.Grant(sender, message.Data); } catch (Exception e) { _logger.Error(e, $"Failed to grant a request of type '{message.Type}'."); } return new RequestResult(false, null); } } }