-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEnableAgentCommandHandler.cs
More file actions
37 lines (32 loc) · 1.27 KB
/
EnableAgentCommandHandler.cs
File metadata and controls
37 lines (32 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Mediator;
using OpenAlprWebhookProcessor.Data.Repositories;
using OpenAlprWebhookProcessor.Features.Webhooks.WebhookProcessor.OpenAlprWebsocket;
using System.Threading;
using System.Threading.Tasks;
namespace OpenAlprWebhookProcessor.Features.Settings.Commands.EnableAgent
{
public class EnableAgentCommandHandler : IQueryHandler<EnableAgentCommand, bool>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IWebsocketClientOrganizer _websocketClientOrganizer;
public EnableAgentCommandHandler(
IUnitOfWork unitOfWork,
IWebsocketClientOrganizer websocketClientOrganizer)
{
_unitOfWork = unitOfWork;
_websocketClientOrganizer = websocketClientOrganizer;
}
public async ValueTask<bool> Handle(EnableAgentCommand request, CancellationToken cancellationToken)
{
var agent = await _unitOfWork.Agents.GetFirstAgentAsync(cancellationToken);
if (agent == null)
{
return false;
}
return await _websocketClientOrganizer.DisableEnableAgentAsync(
agent.Uid,
AgentStartStopType.Start,
cancellationToken);
}
}
}