NetworkResurrector.Server.Wrapper

master
Tudor Stanciu 2022-01-13 10:39:02 +02:00
parent 2e88564d21
commit 3571a26262
20 changed files with 145 additions and 21 deletions

View File

@ -58,9 +58,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Ap
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Wrapper", "src\agent\NetworkResurrector.Agent.Wrapper\NetworkResurrector.Agent.Wrapper.csproj", "{BA96E3C3-3E18-4882-8BDB-ED7B40836892}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetworkResurrector.Agent.Wrapper", "src\agent\NetworkResurrector.Agent.Wrapper\NetworkResurrector.Agent.Wrapper.csproj", "{BA96E3C3-3E18-4882-8BDB-ED7B40836892}"
EndProject 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{750531C0-CB4D-44AE-ADDE-CC815F2539C5}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -153,6 +165,8 @@ Global
{BA96E3C3-3E18-4882-8BDB-ED7B40836892} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} {BA96E3C3-3E18-4882-8BDB-ED7B40836892} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
{2B084ADC-829E-4B72-8FF3-69780E06083D} = {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} {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 EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7} SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7}

View File

@ -1,8 +1,8 @@
using MediatR; using MediatR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NetworkResurrector.Server.Application.Commands;
using NetworkResurrector.Server.Application.Events;
using NetworkResurrector.Server.Application.Services; using NetworkResurrector.Server.Application.Services;
using NetworkResurrector.Server.PublishedLanguage.Commands;
using NetworkResurrector.Server.PublishedLanguage.Events;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,8 +1,8 @@
using MediatR; using MediatR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NetworkResurrector.Server.Application.Commands;
using NetworkResurrector.Server.Application.Events;
using NetworkResurrector.Server.Application.Services; using NetworkResurrector.Server.Application.Services;
using NetworkResurrector.Server.PublishedLanguage.Commands;
using NetworkResurrector.Server.PublishedLanguage.Events;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,8 +1,8 @@
using MediatR; using MediatR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NetworkResurrector.Server.Abstractions; using NetworkResurrector.Server.Abstractions;
using NetworkResurrector.Server.Application.Commands; using NetworkResurrector.Server.PublishedLanguage.Commands;
using NetworkResurrector.Server.Application.Events; using NetworkResurrector.Server.PublishedLanguage.Events;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -11,13 +11,13 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.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" /> <PackageReference Include="System.Management" Version="5.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\NetworkResurrector.Server.Abstractions\NetworkResurrector.Server.Abstractions.csproj" /> <ProjectReference Include="..\NetworkResurrector.Server.Abstractions\NetworkResurrector.Server.Abstractions.csproj" />
<ProjectReference Include="..\NetworkResurrector.Server.Domain\NetworkResurrector.Server.Domain.csproj" /> <ProjectReference Include="..\NetworkResurrector.Server.Domain\NetworkResurrector.Server.Domain.csproj" />
<ProjectReference Include="..\NetworkResurrector.Server.PublishedLanguage\NetworkResurrector.Server.PublishedLanguage.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,8 +1,8 @@
using NDB.Application.DataContracts; using NDB.Application.DataContracts;
using NetworkResurrector.Server.Application.Events; using NetworkResurrector.Server.PublishedLanguage.Events;
using System; using System;
namespace NetworkResurrector.Server.Application.Commands namespace NetworkResurrector.Server.PublishedLanguage.Commands
{ {
public class PingMachine : Command<MachinePinged> public class PingMachine : Command<MachinePinged>
{ {

View File

@ -1,8 +1,8 @@
using NDB.Application.DataContracts; using NDB.Application.DataContracts;
using NetworkResurrector.Server.Application.Events; using NetworkResurrector.Server.PublishedLanguage.Events;
using System; using System;
namespace NetworkResurrector.Server.Application.Commands namespace NetworkResurrector.Server.PublishedLanguage.Commands
{ {
public class ShutdownMachine : Command<MachineShutdown> public class ShutdownMachine : Command<MachineShutdown>
{ {

View File

@ -1,8 +1,8 @@
using NDB.Application.DataContracts; using NDB.Application.DataContracts;
using NetworkResurrector.Server.Application.Events; using NetworkResurrector.Server.PublishedLanguage.Events;
using System; using System;
namespace NetworkResurrector.Server.Application.Commands namespace NetworkResurrector.Server.PublishedLanguage.Commands
{ {
public class WakeMachine : Command<MachineWaked> public class WakeMachine : Command<MachineWaked>
{ {

View File

@ -1,4 +1,4 @@
namespace NetworkResurrector.Server.Application.Events namespace NetworkResurrector.Server.PublishedLanguage.Events
{ {
public class MachinePinged public class MachinePinged
{ {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace NetworkResurrector.Server.Application.Events namespace NetworkResurrector.Server.PublishedLanguage.Events
{ {
public class MachineShutdown public class MachineShutdown
{ {

View File

@ -1,4 +1,4 @@
namespace NetworkResurrector.Server.Application.Events namespace NetworkResurrector.Server.PublishedLanguage.Events
{ {
public class MachineWaked public class MachineWaked
{ {

View File

@ -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>

View File

@ -0,0 +1,9 @@
namespace NetworkResurrector.Server.Wrapper.Constants
{
internal struct ApiRoutes
{
public const string
Wake = "resurrector/wake",
Ping = "resurrector/ping";
}
}

View File

@ -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>();
}
}
}

View File

@ -0,0 +1,12 @@
namespace NetworkResurrector.Server.Wrapper.Models
{
internal class ServiceConfiguration
{
public string BaseAddress { get; }
public ServiceConfiguration(string baseAddress)
{
BaseAddress = baseAddress;
}
}
}

View File

@ -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>

View File

@ -0,0 +1,7 @@
namespace NetworkResurrector.Server.Wrapper.Services
{
public interface IResurrectorService
{
}
}

View File

@ -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;
}
}
}

View File

@ -1,7 +1,7 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NetworkResurrector.Server.Application.Commands; using NetworkResurrector.Server.PublishedLanguage.Commands;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NetworkResurrector.Server.Controllers namespace NetworkResurrector.Server.Controllers

View File

@ -80,7 +80,7 @@ namespace NetworkResurrector.Server
private Assembly[] GetMediatRAssemblies() private Assembly[] GetMediatRAssemblies()
{ {
var assembly = typeof(Application.Commands.WakeMachine).Assembly; var assembly = typeof(Application.CommandHandlers.PingMachineHandler).Assembly;
return new Assembly[] { assembly }; return new Assembly[] { assembly };
} }
} }