ResurrectorAgentService

master
Tudor Stanciu 2022-01-14 01:48:08 +02:00
parent 9d892ba1e8
commit e1bcfc01c0
2 changed files with 17 additions and 4 deletions

View File

@ -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<ShutdownResult> Shutdown(string ipAddressOrMachineName, int agentPort, ActionOwner actionOwner = null, ActionOptions actionOptions = null);
}
}

View File

@ -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<ShutdownResult> 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<ShutdownResult> 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<ShutdownResult, Shutdown>(ApiRoutes.Shutdown, body);
return result;
}