NetworkResurrector.Server.Wrapper
parent
2e88564d21
commit
3571a26262
|
@ -58,9 +58,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Ap
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Wrapper", "src\agent\NetworkResurrector.Agent.Wrapper\NetworkResurrector.Agent.Wrapper.csproj", "{BA96E3C3-3E18-4882-8BDB-ED7B40836892}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Agent.PublishedLanguage", "src\agent\NetworkResurrector.Agent.PublishedLanguage\NetworkResurrector.Agent.PublishedLanguage.csproj", "{2B084ADC-829E-4B72-8FF3-69780E06083D}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.PublishedLanguage", "src\agent\NetworkResurrector.Agent.PublishedLanguage\NetworkResurrector.Agent.PublishedLanguage.csproj", "{2B084ADC-829E-4B72-8FF3-69780E06083D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Agent.Domain", "src\agent\NetworkResurrector.Agent.Domain\NetworkResurrector.Agent.Domain.csproj", "{750531C0-CB4D-44AE-ADDE-CC815F2539C5}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Domain", "src\agent\NetworkResurrector.Agent.Domain\NetworkResurrector.Agent.Domain.csproj", "{750531C0-CB4D-44AE-ADDE-CC815F2539C5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Server.Wrapper", "src\server\NetworkResurrector.Server.Wrapper\NetworkResurrector.Server.Wrapper.csproj", "{696DAC79-9C18-4DC3-9925-755AD6C1FEC9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Server.PublishedLanguage", "src\server\NetworkResurrector.Server.PublishedLanguage\NetworkResurrector.Server.PublishedLanguage.csproj", "{388D632D-8104-45E2-8017-D04848941F29}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -128,6 +132,14 @@ Global
|
|||
{750531C0-CB4D-44AE-ADDE-CC815F2539C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{750531C0-CB4D-44AE-ADDE-CC815F2539C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{750531C0-CB4D-44AE-ADDE-CC815F2539C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{696DAC79-9C18-4DC3-9925-755AD6C1FEC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{696DAC79-9C18-4DC3-9925-755AD6C1FEC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{696DAC79-9C18-4DC3-9925-755AD6C1FEC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{696DAC79-9C18-4DC3-9925-755AD6C1FEC9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{388D632D-8104-45E2-8017-D04848941F29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{388D632D-8104-45E2-8017-D04848941F29}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{388D632D-8104-45E2-8017-D04848941F29}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{388D632D-8104-45E2-8017-D04848941F29}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -153,6 +165,8 @@ Global
|
|||
{BA96E3C3-3E18-4882-8BDB-ED7B40836892} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
|
||||
{2B084ADC-829E-4B72-8FF3-69780E06083D} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
|
||||
{750531C0-CB4D-44AE-ADDE-CC815F2539C5} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
|
||||
{696DAC79-9C18-4DC3-9925-755AD6C1FEC9} = {6889D39C-D8DA-4B99-AFC1-F0B6355E73C0}
|
||||
{388D632D-8104-45E2-8017-D04848941F29} = {6889D39C-D8DA-4B99-AFC1-F0B6355E73C0}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetworkResurrector.Server.Application.Commands;
|
||||
using NetworkResurrector.Server.Application.Events;
|
||||
using NetworkResurrector.Server.Application.Services;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Commands;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Events;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetworkResurrector.Server.Application.Commands;
|
||||
using NetworkResurrector.Server.Application.Events;
|
||||
using NetworkResurrector.Server.Application.Services;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Commands;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Events;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetworkResurrector.Server.Abstractions;
|
||||
using NetworkResurrector.Server.Application.Commands;
|
||||
using NetworkResurrector.Server.Application.Events;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Commands;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Events;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -11,13 +11,13 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
|
||||
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
|
||||
<PackageReference Include="System.Management" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NetworkResurrector.Server.Abstractions\NetworkResurrector.Server.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\NetworkResurrector.Server.Domain\NetworkResurrector.Server.Domain.csproj" />
|
||||
<ProjectReference Include="..\NetworkResurrector.Server.PublishedLanguage\NetworkResurrector.Server.PublishedLanguage.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using NDB.Application.DataContracts;
|
||||
using NetworkResurrector.Server.Application.Events;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Events;
|
||||
using System;
|
||||
|
||||
namespace NetworkResurrector.Server.Application.Commands
|
||||
namespace NetworkResurrector.Server.PublishedLanguage.Commands
|
||||
{
|
||||
public class PingMachine : Command<MachinePinged>
|
||||
{
|
|
@ -1,8 +1,8 @@
|
|||
using NDB.Application.DataContracts;
|
||||
using NetworkResurrector.Server.Application.Events;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Events;
|
||||
using System;
|
||||
|
||||
namespace NetworkResurrector.Server.Application.Commands
|
||||
namespace NetworkResurrector.Server.PublishedLanguage.Commands
|
||||
{
|
||||
public class ShutdownMachine : Command<MachineShutdown>
|
||||
{
|
|
@ -1,8 +1,8 @@
|
|||
using NDB.Application.DataContracts;
|
||||
using NetworkResurrector.Server.Application.Events;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Events;
|
||||
using System;
|
||||
|
||||
namespace NetworkResurrector.Server.Application.Commands
|
||||
namespace NetworkResurrector.Server.PublishedLanguage.Commands
|
||||
{
|
||||
public class WakeMachine : Command<MachineWaked>
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetworkResurrector.Server.Application.Events
|
||||
namespace NetworkResurrector.Server.PublishedLanguage.Events
|
||||
{
|
||||
public class MachinePinged
|
||||
{
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace NetworkResurrector.Server.Application.Events
|
||||
namespace NetworkResurrector.Server.PublishedLanguage.Events
|
||||
{
|
||||
public class MachineShutdown
|
||||
{
|
|
@ -1,4 +1,4 @@
|
|||
namespace NetworkResurrector.Server.Application.Events
|
||||
namespace NetworkResurrector.Server.PublishedLanguage.Events
|
||||
{
|
||||
public class MachineWaked
|
||||
{
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,9 @@
|
|||
namespace NetworkResurrector.Server.Wrapper.Constants
|
||||
{
|
||||
internal struct ApiRoutes
|
||||
{
|
||||
public const string
|
||||
Wake = "resurrector/wake",
|
||||
Ping = "resurrector/ping";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NetworkResurrector.Server.Wrapper.Models;
|
||||
using NetworkResurrector.Server.Wrapper.Services;
|
||||
|
||||
namespace NetworkResurrector.Server.Wrapper
|
||||
{
|
||||
public static class DependencyInjectionExtension
|
||||
{
|
||||
public static void UseResurrectorServices(this IServiceCollection services, string baseAddress)
|
||||
{
|
||||
services.AddSingleton(new ServiceConfiguration(baseAddress));
|
||||
services.AddHttpClient<IResurrectorService, ResurrectorService>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
namespace NetworkResurrector.Server.Wrapper.Models
|
||||
{
|
||||
internal class ServiceConfiguration
|
||||
{
|
||||
public string BaseAddress { get; }
|
||||
|
||||
public ServiceConfiguration(string baseAddress)
|
||||
{
|
||||
BaseAddress = baseAddress;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftExtensionsPackageVersion)" />
|
||||
<PackageReference Include="NDB.Extensions.Http" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NetworkResurrector.Server.PublishedLanguage\NetworkResurrector.Server.PublishedLanguage.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,7 @@
|
|||
namespace NetworkResurrector.Server.Wrapper.Services
|
||||
{
|
||||
public interface IResurrectorService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
using NDB.Extensions.Http;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Commands;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Events;
|
||||
using NetworkResurrector.Server.Wrapper.Constants;
|
||||
using NetworkResurrector.Server.Wrapper.Models;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetworkResurrector.Server.Wrapper.Services
|
||||
{
|
||||
internal class ResurrectorService : IResurrectorService
|
||||
{
|
||||
private const string _contentType = "application/json";
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public ResurrectorService(HttpClient httpClient, ServiceConfiguration configuration)
|
||||
{
|
||||
httpClient.BaseAddress = new Uri(configuration.BaseAddress);
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_contentType));
|
||||
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async Task<MachineWaked> Wake(string macAddress)
|
||||
{
|
||||
var body = new WakeMachine(macAddress);
|
||||
var result = await _httpClient.ExecutePostRequest<MachineWaked, WakeMachine>(ApiRoutes.Wake, body);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<MachinePinged> Ping(string ipAddressOrMachineName)
|
||||
{
|
||||
var body = new PingMachine(ipAddressOrMachineName);
|
||||
var result = await _httpClient.ExecutePostRequest<MachinePinged, PingMachine>(ApiRoutes.Wake, body);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NetworkResurrector.Server.Application.Commands;
|
||||
using NetworkResurrector.Server.PublishedLanguage.Commands;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetworkResurrector.Server.Controllers
|
||||
|
|
|
@ -80,7 +80,7 @@ namespace NetworkResurrector.Server
|
|||
|
||||
private Assembly[] GetMediatRAssemblies()
|
||||
{
|
||||
var assembly = typeof(Application.Commands.WakeMachine).Assembly;
|
||||
var assembly = typeof(Application.CommandHandlers.PingMachineHandler).Assembly;
|
||||
return new Assembly[] { assembly };
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue