From 9d892ba1e8bf755d9f2eb8cbe72570d6b49a5a10 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Fri, 14 Jan 2022 01:38:56 +0200 Subject: [PATCH] NetworkResurrector.Agent.Wrapper --- NetworkResurrector.sln | 7 ++++ notes/nugets.txt | 3 ++ ...Resurrector.Agent.PublishedLanguage.csproj | 3 ++ .../Constants/ApiRoutes.cs | 13 ++++++++ .../DependencyInjectionExtension.cs | 13 ++++++++ .../NetworkResurrector.Agent.Wrapper.csproj | 14 ++++++++ .../Services/IResurrectorAgentService.cs | 6 ++++ .../Services/ResurrectorAgentService.cs | 32 +++++++++++++++++++ 8 files changed, 91 insertions(+) create mode 100644 src/agent/NetworkResurrector.Agent.Wrapper/Constants/ApiRoutes.cs create mode 100644 src/agent/NetworkResurrector.Agent.Wrapper/DependencyInjectionExtension.cs create mode 100644 src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj create mode 100644 src/agent/NetworkResurrector.Agent.Wrapper/Services/IResurrectorAgentService.cs create mode 100644 src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs diff --git a/NetworkResurrector.sln b/NetworkResurrector.sln index e1ab2a2..4ba14d9 100644 --- a/NetworkResurrector.sln +++ b/NetworkResurrector.sln @@ -71,6 +71,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "notes", "notes", "{6973CB33 notes\nugets.txt = notes\nugets.txt EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Agent.Wrapper", "src\agent\NetworkResurrector.Agent.Wrapper\NetworkResurrector.Agent.Wrapper.csproj", "{3624DFF4-C692-42F8-BDC2-1C2107E6EDC8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -145,6 +147,10 @@ Global {1EA9EAD7-8896-4756-A2C2-7969E9073FA6}.Debug|Any CPU.Build.0 = Debug|Any CPU {1EA9EAD7-8896-4756-A2C2-7969E9073FA6}.Release|Any CPU.ActiveCfg = Release|Any CPU {1EA9EAD7-8896-4756-A2C2-7969E9073FA6}.Release|Any CPU.Build.0 = Release|Any CPU + {3624DFF4-C692-42F8-BDC2-1C2107E6EDC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3624DFF4-C692-42F8-BDC2-1C2107E6EDC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3624DFF4-C692-42F8-BDC2-1C2107E6EDC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3624DFF4-C692-42F8-BDC2-1C2107E6EDC8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -173,6 +179,7 @@ Global {388D632D-8104-45E2-8017-D04848941F29} = {6889D39C-D8DA-4B99-AFC1-F0B6355E73C0} {1EA9EAD7-8896-4756-A2C2-7969E9073FA6} = {43C78941-52E6-4AB8-9170-CC7C006E4784} {6973CB33-B940-41B0-B3BB-22ED2ECB8E1D} = {FDDE879C-E0A3-4BF1-945F-7FEA324C8EBA} + {3624DFF4-C692-42F8-BDC2-1C2107E6EDC8} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7} diff --git a/notes/nugets.txt b/notes/nugets.txt index 1e3a717..315f085 100644 --- a/notes/nugets.txt +++ b/notes/nugets.txt @@ -6,4 +6,7 @@ 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.2.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget + +# Agent +dotnet nuget push NetworkResurrector.Agent.PublishedLanguage.1.0.3.nupkg -k ***REMOVED*** -s https://toodle.ddns.net/public-nuget-server/nuget ####################################################################################################################################################### \ No newline at end of file diff --git a/src/agent/NetworkResurrector.Agent.PublishedLanguage/NetworkResurrector.Agent.PublishedLanguage.csproj b/src/agent/NetworkResurrector.Agent.PublishedLanguage/NetworkResurrector.Agent.PublishedLanguage.csproj index 68d208b..a19c9cc 100644 --- a/src/agent/NetworkResurrector.Agent.PublishedLanguage/NetworkResurrector.Agent.PublishedLanguage.csproj +++ b/src/agent/NetworkResurrector.Agent.PublishedLanguage/NetworkResurrector.Agent.PublishedLanguage.csproj @@ -2,6 +2,9 @@ net5.0 + Network resurrector agent published language nuget package + https://dev.azure.com/tstanciu94/NetworkResurrector + https://dev.azure.com/tstanciu94/NetworkResurrector diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/Constants/ApiRoutes.cs b/src/agent/NetworkResurrector.Agent.Wrapper/Constants/ApiRoutes.cs new file mode 100644 index 0000000..76a2f1e --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Constants/ApiRoutes.cs @@ -0,0 +1,13 @@ +namespace NetworkResurrector.Agent.Wrapper.Constants +{ + internal struct ApiRoutes + { + public const string + Shutdown = "host/shutdown", + Restart = "host/restart", + Sleep = "host/sleep", + Logout = "host/logout", + Lock = "host/lock", + Cancel = "host/cancel"; + } +} diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/DependencyInjectionExtension.cs b/src/agent/NetworkResurrector.Agent.Wrapper/DependencyInjectionExtension.cs new file mode 100644 index 0000000..67b0809 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/DependencyInjectionExtension.cs @@ -0,0 +1,13 @@ +using Microsoft.Extensions.DependencyInjection; +using NetworkResurrector.Agent.Wrapper.Services; + +namespace NetworkResurrector.Agent.Wrapper +{ + public static class DependencyInjectionExtension + { + public static void UseResurrectorAgentServices(this IServiceCollection services) + { + services.AddHttpClient(); + } + } +} 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..08e4347 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/NetworkResurrector.Agent.Wrapper.csproj @@ -0,0 +1,14 @@ + + + + net5.0 + + + + + + + + + + diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/Services/IResurrectorAgentService.cs b/src/agent/NetworkResurrector.Agent.Wrapper/Services/IResurrectorAgentService.cs new file mode 100644 index 0000000..7b3a732 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Services/IResurrectorAgentService.cs @@ -0,0 +1,6 @@ +namespace NetworkResurrector.Agent.Wrapper.Services +{ + public interface IResurrectorAgentService + { + } +} \ No newline at end of file diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs b/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs new file mode 100644 index 0000000..7605122 --- /dev/null +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs @@ -0,0 +1,32 @@ +using NDB.Extensions.Http; +using NetworkResurrector.Agent.PublishedLanguage.Commands; +using NetworkResurrector.Agent.PublishedLanguage.Events; +using NetworkResurrector.Agent.Wrapper.Constants; +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; + +namespace NetworkResurrector.Agent.Wrapper.Services +{ + internal class ResurrectorAgentService : IResurrectorAgentService + { + private const string _contentType = "application/json"; + private readonly HttpClient _httpClient; + + public ResurrectorAgentService(HttpClient httpClient) + { + httpClient.BaseAddress = new Uri(""); + httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_contentType)); + + _httpClient = httpClient; + } + + public async Task Shutdown(string ipAddressOrMachineName) + { + var body = new Shutdown(); + var result = await _httpClient.ExecutePostRequest(ApiRoutes.Shutdown, body); + return result; + } + } +}