From 2e21ad3b600ed657b12f7f604634e30fe9a0c09e Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 9 Dec 2021 15:42:06 +0200 Subject: [PATCH] NetworkResurrector.Agent.Wrapper --- NetworkResurrector.sln | 9 ++++- .../Class1.cs | 8 ++++ .../NetworkResurrector.Agent.Wrapper.csproj | 7 ++++ .../Controllers/HostController.cs | 27 +++++++++++++ .../Controllers/WeatherForecastController.cs | 39 ------------------- .../WeatherForecast.cs | 15 ------- 6 files changed, 50 insertions(+), 55 deletions(-) create mode 100644 src/agent/NetworkResurrector.Agent.Wrapper/Class1.cs create mode 100644 src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj create mode 100644 src/agent/NetworkResurrector.Agent/Controllers/HostController.cs delete mode 100644 src/agent/NetworkResurrector.Agent/Controllers/WeatherForecastController.cs delete mode 100644 src/agent/NetworkResurrector.Agent/WeatherForecast.cs diff --git a/NetworkResurrector.sln b/NetworkResurrector.sln index 89e5d9e..6cbb5da 100644 --- a/NetworkResurrector.sln +++ b/NetworkResurrector.sln @@ -54,7 +54,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "agent", "agent", "{C04663A1 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent", "src\agent\NetworkResurrector.Agent\NetworkResurrector.Agent.csproj", "{C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Agent.Application", "src\agent\NetworkResurrector.Agent.Application\NetworkResurrector.Agent.Application.csproj", "{3795AB02-7F2A-424B-BFD2-1B915E155829}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Application", "src\agent\NetworkResurrector.Agent.Application\NetworkResurrector.Agent.Application.csproj", "{3795AB02-7F2A-424B-BFD2-1B915E155829}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Agent.Wrapper", "src\agent\NetworkResurrector.Agent.Wrapper\NetworkResurrector.Agent.Wrapper.csproj", "{BA96E3C3-3E18-4882-8BDB-ED7B40836892}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -110,6 +112,10 @@ Global {3795AB02-7F2A-424B-BFD2-1B915E155829}.Debug|Any CPU.Build.0 = Debug|Any CPU {3795AB02-7F2A-424B-BFD2-1B915E155829}.Release|Any CPU.ActiveCfg = Release|Any CPU {3795AB02-7F2A-424B-BFD2-1B915E155829}.Release|Any CPU.Build.0 = Release|Any CPU + {BA96E3C3-3E18-4882-8BDB-ED7B40836892}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BA96E3C3-3E18-4882-8BDB-ED7B40836892}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BA96E3C3-3E18-4882-8BDB-ED7B40836892}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BA96E3C3-3E18-4882-8BDB-ED7B40836892}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -132,6 +138,7 @@ Global {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} = {B0C5F0C1-0BF8-4651-AAFC-BE01F516D7B8} {C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} {3795AB02-7F2A-424B-BFD2-1B915E155829} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} + {BA96E3C3-3E18-4882-8BDB-ED7B40836892} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7} diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/Class1.cs b/src/agent/NetworkResurrector.Agent.Wrapper/Class1.cs new file mode 100644 index 0000000..f623fe6 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Class1.cs @@ -0,0 +1,8 @@ +using System; + +namespace NetworkResurrector.Agent.Wrapper +{ + public class Class1 + { + } +} diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj b/src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj new file mode 100644 index 0000000..f208d30 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/src/agent/NetworkResurrector.Agent/Controllers/HostController.cs b/src/agent/NetworkResurrector.Agent/Controllers/HostController.cs new file mode 100644 index 0000000..7234080 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/Controllers/HostController.cs @@ -0,0 +1,27 @@ +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; + +namespace NetworkResurrector.Agent.Controllers +{ + [ApiController] + [Authorize] + [Route("host")] + public class HostController : ControllerBase + { + private readonly IMediator _mediator; + + public HostController(IMediator mediator) + { + _mediator = mediator; + } + + [HttpPost("shutdown")] + public async Task Shutdown([FromBody] Shutdown shutdownMachine) + { + var result = await _mediator.Send(shutdownMachine); + return Ok(result); + } + } +} diff --git a/src/agent/NetworkResurrector.Agent/Controllers/WeatherForecastController.cs b/src/agent/NetworkResurrector.Agent/Controllers/WeatherForecastController.cs deleted file mode 100644 index 633d97c..0000000 --- a/src/agent/NetworkResurrector.Agent/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace NetworkResurrector.Agent.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/src/agent/NetworkResurrector.Agent/WeatherForecast.cs b/src/agent/NetworkResurrector.Agent/WeatherForecast.cs deleted file mode 100644 index 146091e..0000000 --- a/src/agent/NetworkResurrector.Agent/WeatherForecast.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace NetworkResurrector.Agent -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } - } -}