diff --git a/notes/nugets.txt b/notes/nugets.txt index c1b96e4..1e3a717 100644 --- a/notes/nugets.txt +++ b/notes/nugets.txt @@ -5,5 +5,5 @@ dotnet pack /*--include-symbols*/ # Server: dotnet nuget push NetworkResurrector.Server.PublishedLanguage.1.0.3.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget -dotnet nuget push NetworkResurrector.Server.Wrapper.1.0.3.1.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget +dotnet nuget push NetworkResurrector.Server.Wrapper.1.0.3.2.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget ####################################################################################################################################################### \ No newline at end of file diff --git a/src/api/NetworkResurrector.Api.Application/CommandHandlers/ShutdownMachineHandler.cs b/src/api/NetworkResurrector.Api.Application/CommandHandlers/ShutdownMachineHandler.cs new file mode 100644 index 0000000..d66cc14 --- /dev/null +++ b/src/api/NetworkResurrector.Api.Application/CommandHandlers/ShutdownMachineHandler.cs @@ -0,0 +1,38 @@ +using MediatR; +using Microsoft.Extensions.Logging; +using NetworkResurrector.Api.Domain.Repositories; +using NetworkResurrector.Api.PublishedLanguage.Commands; +using NetworkResurrector.Api.PublishedLanguage.Events; +using NetworkResurrector.Server.Wrapper.Services; +using System.Threading; +using System.Threading.Tasks; + +namespace NetworkResurrector.Api.Application.CommandHandlers +{ + public class ShutdownMachineHandler : IRequestHandler + { + private readonly ILogger _logger; + private readonly IResurrectorService _resurrectorService; + private readonly INetworkRepository _repository; + + public ShutdownMachineHandler(ILogger logger, IResurrectorService resurrectorService, INetworkRepository repository) + { + _logger=logger; + _resurrectorService=resurrectorService; + _repository=repository; + } + + public async Task Handle(ShutdownMachine command, CancellationToken cancellationToken) + { + _logger.LogDebug($"Start shutdown machine {command.MachineId}"); + var machine = await _repository.GetMachine(command.MachineId); + + //log activity + var pingResult = await _resurrectorService.sh(machine.IPv4Address ?? machine.MachineName); + var result = new MachineShutdown(pingResult.Success, pingResult.Status); + _logger.LogDebug($"Machine {command.MachineId} shutdown finished. Success: {result.Success}; Status: {result.Status}"); + + return result; + } + } +} diff --git a/src/server/NetworkResurrector.Server.Wrapper/Constants/ApiRoutes.cs b/src/server/NetworkResurrector.Server.Wrapper/Constants/ApiRoutes.cs index dcbfdf3..52d4810 100644 --- a/src/server/NetworkResurrector.Server.Wrapper/Constants/ApiRoutes.cs +++ b/src/server/NetworkResurrector.Server.Wrapper/Constants/ApiRoutes.cs @@ -4,6 +4,7 @@ { public const string Wake = "resurrector/wake", - Ping = "resurrector/ping"; + Ping = "resurrector/ping", + Shutdown = "resurrector/shutdown"; } } diff --git a/src/server/NetworkResurrector.Server.Wrapper/NetworkResurrector.Server.Wrapper.csproj b/src/server/NetworkResurrector.Server.Wrapper/NetworkResurrector.Server.Wrapper.csproj index 9fcfdc5..bdc1d8b 100644 --- a/src/server/NetworkResurrector.Server.Wrapper/NetworkResurrector.Server.Wrapper.csproj +++ b/src/server/NetworkResurrector.Server.Wrapper/NetworkResurrector.Server.Wrapper.csproj @@ -6,7 +6,7 @@ https://dev.azure.com/tstanciu94/NetworkResurrector https://dev.azure.com/tstanciu94/NetworkResurrector Git - 1.0.3.1 + 1.0.3.2 diff --git a/src/server/NetworkResurrector.Server.Wrapper/Services/IResurrectorService.cs b/src/server/NetworkResurrector.Server.Wrapper/Services/IResurrectorService.cs index 920667f..f1e99ca 100644 --- a/src/server/NetworkResurrector.Server.Wrapper/Services/IResurrectorService.cs +++ b/src/server/NetworkResurrector.Server.Wrapper/Services/IResurrectorService.cs @@ -7,5 +7,6 @@ namespace NetworkResurrector.Server.Wrapper.Services { Task Wake(string macAddress); Task Ping(string ipAddressOrMachineName); + Task Shutdown(string ipAddressOrMachineName); } } \ No newline at end of file diff --git a/src/server/NetworkResurrector.Server.Wrapper/Services/ResurrectorService.cs b/src/server/NetworkResurrector.Server.Wrapper/Services/ResurrectorService.cs index be0136e..1dff873 100644 --- a/src/server/NetworkResurrector.Server.Wrapper/Services/ResurrectorService.cs +++ b/src/server/NetworkResurrector.Server.Wrapper/Services/ResurrectorService.cs @@ -36,5 +36,12 @@ namespace NetworkResurrector.Server.Wrapper.Services var result = await _httpClient.ExecutePostRequest(ApiRoutes.Wake, body); return result; } + + public async Task Shutdown(string ipAddressOrMachineName) + { + var body = new ShutdownMachine(ipAddressOrMachineName); + var result = await _httpClient.ExecutePostRequest(ApiRoutes.Shutdown, body); + return result; + } } }