From e1bcfc01c0d0a8593d17266cb1fbcd80101e8173 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Fri, 14 Jan 2022 01:48:08 +0200 Subject: [PATCH] ResurrectorAgentService --- .../Services/IResurrectorAgentService.cs | 7 ++++++- .../Services/ResurrectorAgentService.cs | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/agent/NetworkResurrector.Agent.Wrapper/Services/IResurrectorAgentService.cs b/src/agent/NetworkResurrector.Agent.Wrapper/Services/IResurrectorAgentService.cs index 7b3a732..1790855 100644 --- a/src/agent/NetworkResurrector.Agent.Wrapper/Services/IResurrectorAgentService.cs +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Services/IResurrectorAgentService.cs @@ -1,6 +1,11 @@ -namespace NetworkResurrector.Agent.Wrapper.Services +using NetworkResurrector.Agent.PublishedLanguage.Dto; +using NetworkResurrector.Agent.PublishedLanguage.Events; +using System.Threading.Tasks; + +namespace NetworkResurrector.Agent.Wrapper.Services { public interface IResurrectorAgentService { + Task Shutdown(string ipAddressOrMachineName, int agentPort, ActionOwner actionOwner = null, ActionOptions actionOptions = null); } } \ 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 index 7605122..b7adbbc 100644 --- a/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs +++ b/src/agent/NetworkResurrector.Agent.Wrapper/Services/ResurrectorAgentService.cs @@ -1,5 +1,6 @@ using NDB.Extensions.Http; using NetworkResurrector.Agent.PublishedLanguage.Commands; +using NetworkResurrector.Agent.PublishedLanguage.Dto; using NetworkResurrector.Agent.PublishedLanguage.Events; using NetworkResurrector.Agent.Wrapper.Constants; using System; @@ -16,15 +17,22 @@ namespace NetworkResurrector.Agent.Wrapper.Services public ResurrectorAgentService(HttpClient httpClient) { - httpClient.BaseAddress = new Uri(""); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_contentType)); _httpClient = httpClient; } - public async Task Shutdown(string ipAddressOrMachineName) + private void SetHttpClientBaseAddress(string ipAddressOrMachineName, int agentPort) { - var body = new Shutdown(); + var baseAddress = $"http://{ipAddressOrMachineName}:{agentPort}"; + _httpClient.BaseAddress = new Uri(baseAddress); + } + + public async Task Shutdown(string ipAddressOrMachineName, int agentPort, ActionOwner actionOwner = null, ActionOptions actionOptions = null) + { + SetHttpClientBaseAddress(ipAddressOrMachineName, agentPort); + + var body = new Shutdown { Owner = actionOwner, Options = actionOptions }; var result = await _httpClient.ExecutePostRequest(ApiRoutes.Shutdown, body); return result; }