Lock win
parent
bfc1e863ad
commit
4d3b9cc4bf
|
@ -0,0 +1,47 @@
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NetworkResurrector.Agent.Application.Services.Abstractions;
|
||||||
|
using NetworkResurrector.Agent.PublishedLanguage.Commands;
|
||||||
|
using NetworkResurrector.Agent.PublishedLanguage.Events;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NetworkResurrector.Agent.Application.CommandHandlers
|
||||||
|
{
|
||||||
|
public class LockHandler : IRequestHandler<Lock, LockResult>
|
||||||
|
{
|
||||||
|
private readonly ILogger<LockHandler> _logger;
|
||||||
|
private readonly IPowerService _powerService;
|
||||||
|
private readonly IValidationService _validationService;
|
||||||
|
|
||||||
|
public LockHandler(ILogger<LockHandler> logger, IPowerService powerService, IValidationService validationService)
|
||||||
|
{
|
||||||
|
_logger=logger;
|
||||||
|
_powerService=powerService;
|
||||||
|
_validationService=validationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<LockResult> Handle(Lock command, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return await Task.Run(() => Handle(command));
|
||||||
|
}
|
||||||
|
|
||||||
|
private LockResult Handle(Lock command)
|
||||||
|
{
|
||||||
|
_validationService.ValidateRestrictions(command.Owner);
|
||||||
|
|
||||||
|
_logger.LogDebug($"Start locking the user.");
|
||||||
|
|
||||||
|
var stopWatch = new Stopwatch();
|
||||||
|
stopWatch.Start();
|
||||||
|
|
||||||
|
_powerService.Lock();
|
||||||
|
|
||||||
|
stopWatch.Stop();
|
||||||
|
_logger.LogDebug($"User lock finished - {stopWatch.ElapsedMilliseconds:N0} ms");
|
||||||
|
|
||||||
|
return new LockResult() { Success = true };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,7 +55,7 @@ namespace NetworkResurrector.Agent.Application.Services.Windows
|
||||||
msg.Append($"Errors:\n {commandError}\n");
|
msg.Append($"Errors:\n {commandError}\n");
|
||||||
msg.Append($"Process ended at: {DateTime.Now}");
|
msg.Append($"Process ended at: {DateTime.Now}");
|
||||||
|
|
||||||
return (commandError.Length > 0, msg.ToString());
|
return (commandError.Length == 0, msg.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
using NDB.Application.DataContracts;
|
||||||
|
using NetworkResurrector.Agent.PublishedLanguage.Dto;
|
||||||
|
using NetworkResurrector.Agent.PublishedLanguage.Events;
|
||||||
|
|
||||||
|
namespace NetworkResurrector.Agent.PublishedLanguage.Commands
|
||||||
|
{
|
||||||
|
public class Lock : Command<LockResult>
|
||||||
|
{
|
||||||
|
public ActionOwner Owner { get; set; }
|
||||||
|
public ActionOptions Options { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
using NetworkResurrector.Agent.PublishedLanguage.Dto;
|
||||||
|
|
||||||
|
namespace NetworkResurrector.Agent.PublishedLanguage.Events
|
||||||
|
{
|
||||||
|
public class LockResult
|
||||||
|
{
|
||||||
|
public bool Success { get; set; }
|
||||||
|
public HostInfo Host { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,5 +45,12 @@ namespace NetworkResurrector.Agent.Controllers
|
||||||
var result = await _mediator.Send(logout);
|
var result = await _mediator.Send(logout);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("lock")]
|
||||||
|
public async Task<IActionResult> Lock([FromBody] Lock _lock)
|
||||||
|
{
|
||||||
|
var result = await _mediator.Send(_lock);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue