From 69ce2bfc53c9cc0c449046ca29acf15068352187 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 12 Jan 2022 19:07:15 +0200 Subject: [PATCH] sleep fix --- .../CommandHandlers/SleepHandler.cs | 11 +++-------- .../Services/Abstractions/IPowerService.cs | 2 +- .../Services/Linux/LinuxPowerService.cs | 2 +- .../Services/Windows/WindowsPowerService.cs | 3 +-- .../Commands/Sleep.cs | 1 - 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/agent/NetworkResurrector.Agent.Application/CommandHandlers/SleepHandler.cs b/src/agent/NetworkResurrector.Agent.Application/CommandHandlers/SleepHandler.cs index 92eead7..94422f2 100644 --- a/src/agent/NetworkResurrector.Agent.Application/CommandHandlers/SleepHandler.cs +++ b/src/agent/NetworkResurrector.Agent.Application/CommandHandlers/SleepHandler.cs @@ -1,8 +1,6 @@ -using AutoMapper; -using MediatR; +using MediatR; using Microsoft.Extensions.Logging; using NetworkResurrector.Agent.Application.Services.Abstractions; -using NetworkResurrector.Agent.Domain.Models; using NetworkResurrector.Agent.PublishedLanguage.Commands; using NetworkResurrector.Agent.PublishedLanguage.Events; using System.Diagnostics; @@ -16,14 +14,12 @@ namespace NetworkResurrector.Agent.Application.CommandHandlers private readonly ILogger _logger; private readonly IPowerService _powerService; private readonly IValidationService _validationService; - private readonly IMapper _mapper; - public SleepHandler(ILogger logger, IPowerService powerService, IValidationService validationService, IMapper mapper) + public SleepHandler(ILogger logger, IPowerService powerService, IValidationService validationService) { _logger=logger; _powerService=powerService; _validationService=validationService; - _mapper=mapper; } public async Task Handle(Sleep command, CancellationToken cancellationToken) @@ -40,8 +36,7 @@ namespace NetworkResurrector.Agent.Application.CommandHandlers var stopWatch = new Stopwatch(); stopWatch.Start(); - var options = _mapper.Map(command.Options); - _powerService.Sleep(options); + _powerService.Sleep(); stopWatch.Stop(); _logger.LogDebug($"System sleeping finished - {stopWatch.ElapsedMilliseconds:N0} ms"); diff --git a/src/agent/NetworkResurrector.Agent.Application/Services/Abstractions/IPowerService.cs b/src/agent/NetworkResurrector.Agent.Application/Services/Abstractions/IPowerService.cs index 92a8fc1..6beed27 100644 --- a/src/agent/NetworkResurrector.Agent.Application/Services/Abstractions/IPowerService.cs +++ b/src/agent/NetworkResurrector.Agent.Application/Services/Abstractions/IPowerService.cs @@ -6,7 +6,7 @@ namespace NetworkResurrector.Agent.Application.Services.Abstractions { void Shutdown(PowerOptions options); void Restart(PowerOptions options); - void Sleep(PowerOptions options); + void Sleep(); void Logout(); void Lock(); void Cancel(); diff --git a/src/agent/NetworkResurrector.Agent.Application/Services/Linux/LinuxPowerService.cs b/src/agent/NetworkResurrector.Agent.Application/Services/Linux/LinuxPowerService.cs index 6614e18..6eaac5e 100644 --- a/src/agent/NetworkResurrector.Agent.Application/Services/Linux/LinuxPowerService.cs +++ b/src/agent/NetworkResurrector.Agent.Application/Services/Linux/LinuxPowerService.cs @@ -16,7 +16,7 @@ namespace NetworkResurrector.Agent.Application.Services.Linux throw new NotImplementedException(); } - public void Sleep(PowerOptions options) + public void Sleep() { throw new NotImplementedException(); } diff --git a/src/agent/NetworkResurrector.Agent.Application/Services/Windows/WindowsPowerService.cs b/src/agent/NetworkResurrector.Agent.Application/Services/Windows/WindowsPowerService.cs index 6bc38d7..60613c2 100644 --- a/src/agent/NetworkResurrector.Agent.Application/Services/Windows/WindowsPowerService.cs +++ b/src/agent/NetworkResurrector.Agent.Application/Services/Windows/WindowsPowerService.cs @@ -81,10 +81,9 @@ namespace NetworkResurrector.Agent.Application.Services.Windows ManageExecutionResponse(result); } - public void Sleep(PowerOptions options) + public void Sleep() { var arguments = "-h"; - arguments = SetOptions(arguments, options); _logger.LogInformation($"Sleep arguments: {arguments}"); var result =_cliService.Shutdown(arguments); ManageExecutionResponse(result); diff --git a/src/agent/NetworkResurrector.Agent.PublishedLanguage/Commands/Sleep.cs b/src/agent/NetworkResurrector.Agent.PublishedLanguage/Commands/Sleep.cs index 79090cf..abdf984 100644 --- a/src/agent/NetworkResurrector.Agent.PublishedLanguage/Commands/Sleep.cs +++ b/src/agent/NetworkResurrector.Agent.PublishedLanguage/Commands/Sleep.cs @@ -7,6 +7,5 @@ namespace NetworkResurrector.Agent.PublishedLanguage.Commands public class Sleep : Command { public ActionOwner Owner { get; set; } - public ActionOptions Options { get; set; } } }