Moved Requests classes to another projects
This commit is contained in:
parent
a3f3f90817
commit
78bab88165
@ -1,9 +0,0 @@
|
||||
namespace HermesSocketLibrary.Requests
|
||||
{
|
||||
public interface IRequest
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
Task<RequestResult> Grant(string sender, IDictionary<string, object>? data);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using HermesSocketLibrary.Socket.Data;
|
||||
|
||||
namespace HermesSocketLibrary.Requests
|
||||
{
|
||||
public interface IRequestManager
|
||||
{
|
||||
Task<RequestResult> Grant(string sender, RequestMessage? message);
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
using HermesSocketLibrary.Socket.Data;
|
||||
using Serilog;
|
||||
|
||||
namespace HermesSocketLibrary.Requests
|
||||
{
|
||||
public class RequestManager : IRequestManager
|
||||
{
|
||||
private readonly IDictionary<string, IRequest> _requests;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
|
||||
public RequestManager(IEnumerable<IRequest> requests, ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
_requests = requests.ToDictionary(r => r.Name, r => r);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
namespace HermesSocketLibrary.Requests
|
||||
{
|
||||
public class RequestResult
|
||||
{
|
||||
public bool Success;
|
||||
public object? Result;
|
||||
public bool NotifyClientsOnAccount;
|
||||
|
||||
public RequestResult(bool success, object? result, bool notifyClientsOnAccount = true)
|
||||
{
|
||||
Success = success;
|
||||
Result = result;
|
||||
NotifyClientsOnAccount = notifyClientsOnAccount;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user