From 35a7b19db1af34a8b96ad7cfb6cc6989b1b94087 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 5 Dec 2021 22:22:14 +0200 Subject: [PATCH] NetworkResurrector.Agent project --- Directory.Build.props | 2 +- NetworkResurrector.sln | 10 ++++ ReleaseNotes.xml | 6 +- .../Controllers/WeatherForecastController.cs | 39 +++++++++++++ .../NetworkResurrector.Agent.csproj | 11 ++++ src/agent/NetworkResurrector.Agent/Program.cs | 26 +++++++++ .../Properties/launchSettings.json | 31 ++++++++++ src/agent/NetworkResurrector.Agent/Startup.cs | 56 +++++++++++++++++++ .../WeatherForecast.cs | 15 +++++ .../appsettings.Development.json | 9 +++ .../NetworkResurrector.Agent/appsettings.json | 10 ++++ 11 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 src/agent/NetworkResurrector.Agent/Controllers/WeatherForecastController.cs create mode 100644 src/agent/NetworkResurrector.Agent/NetworkResurrector.Agent.csproj create mode 100644 src/agent/NetworkResurrector.Agent/Program.cs create mode 100644 src/agent/NetworkResurrector.Agent/Properties/launchSettings.json create mode 100644 src/agent/NetworkResurrector.Agent/Startup.cs create mode 100644 src/agent/NetworkResurrector.Agent/WeatherForecast.cs create mode 100644 src/agent/NetworkResurrector.Agent/appsettings.Development.json create mode 100644 src/agent/NetworkResurrector.Agent/appsettings.json diff --git a/Directory.Build.props b/Directory.Build.props index 82a33f8..b60f2f6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.0.2.0 + 1.0.2 Tudor Stanciu STA NetworkResurrector diff --git a/NetworkResurrector.sln b/NetworkResurrector.sln index 3e5c69c..3cedfdf 100644 --- a/NetworkResurrector.sln +++ b/NetworkResurrector.sln @@ -50,6 +50,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "api", "api", "{C5096F61-731 release.sh = release.sh EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "agent", "agent", "{C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Agent", "src\agent\NetworkResurrector.Agent\NetworkResurrector.Agent.csproj", "{C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -96,6 +100,10 @@ Global {509767A7-D11C-4143-8D45-01E62DFC2C74}.Debug|Any CPU.Build.0 = Debug|Any CPU {509767A7-D11C-4143-8D45-01E62DFC2C74}.Release|Any CPU.ActiveCfg = Release|Any CPU {509767A7-D11C-4143-8D45-01E62DFC2C74}.Release|Any CPU.Build.0 = Release|Any CPU + {C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -115,6 +123,8 @@ Global {509767A7-D11C-4143-8D45-01E62DFC2C74} = {43C78941-52E6-4AB8-9170-CC7C006E4784} {DF5CBFF4-B348-4D4C-A6D4-B65BA1D64CEF} = {FDDE879C-E0A3-4BF1-945F-7FEA324C8EBA} {C5096F61-7319-453B-AA28-7A1A854A6220} = {DF5CBFF4-B348-4D4C-A6D4-B65BA1D64CEF} + {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} = {B0C5F0C1-0BF8-4651-AAFC-BE01F516D7B8} + {C8C4CA6F-39E2-46FE-89E2-0A81D2F4161E} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7} diff --git a/ReleaseNotes.xml b/ReleaseNotes.xml index f82298c..d343014 100644 --- a/ReleaseNotes.xml +++ b/ReleaseNotes.xml @@ -1,20 +1,20 @@  - 1.0.0.0 + 1.0.0 Simple .net core 3.1 console application that serve as an REST API through witch a user can execute wake or shutdown commands on machines from his network. Has been added Wake on LAN support and "wake" route in the API controller. - 1.0.1.0 + 1.0.1 Has been added "ping" and "shutdown" support. Routes with same names have also been added to the controller. - 1.0.2.0 + 1.0.2 Replaced Swagger and MediatR implementations with inhouse nuget packages. Integration with local Identity Server. diff --git a/src/agent/NetworkResurrector.Agent/Controllers/WeatherForecastController.cs b/src/agent/NetworkResurrector.Agent/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..633d97c --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +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/NetworkResurrector.Agent.csproj b/src/agent/NetworkResurrector.Agent/NetworkResurrector.Agent.csproj new file mode 100644 index 0000000..2884716 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/NetworkResurrector.Agent.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/src/agent/NetworkResurrector.Agent/Program.cs b/src/agent/NetworkResurrector.Agent/Program.cs new file mode 100644 index 0000000..fe10858 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NetworkResurrector.Agent +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/src/agent/NetworkResurrector.Agent/Properties/launchSettings.json b/src/agent/NetworkResurrector.Agent/Properties/launchSettings.json new file mode 100644 index 0000000..4f86b50 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:58125", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "NetworkResurrector.Agent": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/agent/NetworkResurrector.Agent/Startup.cs b/src/agent/NetworkResurrector.Agent/Startup.cs new file mode 100644 index 0000000..3aab1cf --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/Startup.cs @@ -0,0 +1,56 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NetworkResurrector.Agent +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "NetworkResurrector.Agent", Version = "v1" }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "NetworkResurrector.Agent v1")); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/src/agent/NetworkResurrector.Agent/WeatherForecast.cs b/src/agent/NetworkResurrector.Agent/WeatherForecast.cs new file mode 100644 index 0000000..146091e --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/WeatherForecast.cs @@ -0,0 +1,15 @@ +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; } + } +} diff --git a/src/agent/NetworkResurrector.Agent/appsettings.Development.json b/src/agent/NetworkResurrector.Agent/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/agent/NetworkResurrector.Agent/appsettings.json b/src/agent/NetworkResurrector.Agent/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/src/agent/NetworkResurrector.Agent/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}