ResurrectorAgentService
parent
9d892ba1e8
commit
e1bcfc01c0
|
@ -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
|
public interface IResurrectorAgentService
|
||||||
{
|
{
|
||||||
|
Task<ShutdownResult> Shutdown(string ipAddressOrMachineName, int agentPort, ActionOwner actionOwner = null, ActionOptions actionOptions = null);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using NDB.Extensions.Http;
|
using NDB.Extensions.Http;
|
||||||
using NetworkResurrector.Agent.PublishedLanguage.Commands;
|
using NetworkResurrector.Agent.PublishedLanguage.Commands;
|
||||||
|
using NetworkResurrector.Agent.PublishedLanguage.Dto;
|
||||||
using NetworkResurrector.Agent.PublishedLanguage.Events;
|
using NetworkResurrector.Agent.PublishedLanguage.Events;
|
||||||
using NetworkResurrector.Agent.Wrapper.Constants;
|
using NetworkResurrector.Agent.Wrapper.Constants;
|
||||||
using System;
|
using System;
|
||||||
|
@ -16,15 +17,22 @@ namespace NetworkResurrector.Agent.Wrapper.Services
|
||||||
|
|
||||||
public ResurrectorAgentService(HttpClient httpClient)
|
public ResurrectorAgentService(HttpClient httpClient)
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri("");
|
|
||||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_contentType));
|
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_contentType));
|
||||||
|
|
||||||
_httpClient = httpClient;
|
_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);
|
var result = await _httpClient.ExecutePostRequest<ShutdownResult, Shutdown>(ApiRoutes.Shutdown, body);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue