diff --git a/NetworkResurrector.sln b/NetworkResurrector.sln index a68b6aa..4c343fe 100644 --- a/NetworkResurrector.sln +++ b/NetworkResurrector.sln @@ -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} diff --git a/src/server/NetworkResurrector.Server.Application/CommandHandlers/PingMachineHandler.cs b/src/server/NetworkResurrector.Server.Application/CommandHandlers/PingMachineHandler.cs index 16bcf42..079ad87 100644 --- a/src/server/NetworkResurrector.Server.Application/CommandHandlers/PingMachineHandler.cs +++ b/src/server/NetworkResurrector.Server.Application/CommandHandlers/PingMachineHandler.cs @@ -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; diff --git a/src/server/NetworkResurrector.Server.Application/CommandHandlers/ShutdownMachineHandler.cs b/src/server/NetworkResurrector.Server.Application/CommandHandlers/ShutdownMachineHandler.cs index 6b07a5c..5580607 100644 --- a/src/server/NetworkResurrector.Server.Application/CommandHandlers/ShutdownMachineHandler.cs +++ b/src/server/NetworkResurrector.Server.Application/CommandHandlers/ShutdownMachineHandler.cs @@ -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; diff --git a/src/server/NetworkResurrector.Server.Application/CommandHandlers/WakeMachineHandler.cs b/src/server/NetworkResurrector.Server.Application/CommandHandlers/WakeMachineHandler.cs index 700c4c3..7e676ae 100644 --- a/src/server/NetworkResurrector.Server.Application/CommandHandlers/WakeMachineHandler.cs +++ b/src/server/NetworkResurrector.Server.Application/CommandHandlers/WakeMachineHandler.cs @@ -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; diff --git a/src/server/NetworkResurrector.Server.Application/NetworkResurrector.Server.Application.csproj b/src/server/NetworkResurrector.Server.Application/NetworkResurrector.Server.Application.csproj index 509a5bc..f5441e7 100644 --- a/src/server/NetworkResurrector.Server.Application/NetworkResurrector.Server.Application.csproj +++ b/src/server/NetworkResurrector.Server.Application/NetworkResurrector.Server.Application.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net5.0 @@ -11,13 +11,13 @@ - + diff --git a/src/server/NetworkResurrector.Server.Application/Commands/PingMachine.cs b/src/server/NetworkResurrector.Server.PublishedLanguage/Commands/PingMachine.cs similarity index 75% rename from src/server/NetworkResurrector.Server.Application/Commands/PingMachine.cs rename to src/server/NetworkResurrector.Server.PublishedLanguage/Commands/PingMachine.cs index 0fa0a91..2b394cb 100644 --- a/src/server/NetworkResurrector.Server.Application/Commands/PingMachine.cs +++ b/src/server/NetworkResurrector.Server.PublishedLanguage/Commands/PingMachine.cs @@ -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 { diff --git a/src/server/NetworkResurrector.Server.Application/Commands/ShutdownMachine.cs b/src/server/NetworkResurrector.Server.PublishedLanguage/Commands/ShutdownMachine.cs similarity index 76% rename from src/server/NetworkResurrector.Server.Application/Commands/ShutdownMachine.cs rename to src/server/NetworkResurrector.Server.PublishedLanguage/Commands/ShutdownMachine.cs index bf7cb11..fe63c7e 100644 --- a/src/server/NetworkResurrector.Server.Application/Commands/ShutdownMachine.cs +++ b/src/server/NetworkResurrector.Server.PublishedLanguage/Commands/ShutdownMachine.cs @@ -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 { diff --git a/src/server/NetworkResurrector.Server.Application/Commands/WakeMachine.cs b/src/server/NetworkResurrector.Server.PublishedLanguage/Commands/WakeMachine.cs similarity index 73% rename from src/server/NetworkResurrector.Server.Application/Commands/WakeMachine.cs rename to src/server/NetworkResurrector.Server.PublishedLanguage/Commands/WakeMachine.cs index 9e3f250..1307d2b 100644 --- a/src/server/NetworkResurrector.Server.Application/Commands/WakeMachine.cs +++ b/src/server/NetworkResurrector.Server.PublishedLanguage/Commands/WakeMachine.cs @@ -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 { diff --git a/src/server/NetworkResurrector.Server.Application/Events/MachinePinged.cs b/src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachinePinged.cs similarity index 80% rename from src/server/NetworkResurrector.Server.Application/Events/MachinePinged.cs rename to src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachinePinged.cs index a33683b..64b0209 100644 --- a/src/server/NetworkResurrector.Server.Application/Events/MachinePinged.cs +++ b/src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachinePinged.cs @@ -1,4 +1,4 @@ -namespace NetworkResurrector.Server.Application.Events +namespace NetworkResurrector.Server.PublishedLanguage.Events { public class MachinePinged { diff --git a/src/server/NetworkResurrector.Server.Application/Events/MachineShutdown.cs b/src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachineShutdown.cs similarity index 84% rename from src/server/NetworkResurrector.Server.Application/Events/MachineShutdown.cs rename to src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachineShutdown.cs index 4ca2ccc..f88326e 100644 --- a/src/server/NetworkResurrector.Server.Application/Events/MachineShutdown.cs +++ b/src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachineShutdown.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace NetworkResurrector.Server.Application.Events +namespace NetworkResurrector.Server.PublishedLanguage.Events { public class MachineShutdown { diff --git a/src/server/NetworkResurrector.Server.Application/Events/MachineWaked.cs b/src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachineWaked.cs similarity index 80% rename from src/server/NetworkResurrector.Server.Application/Events/MachineWaked.cs rename to src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachineWaked.cs index 2ee5973..32a843b 100644 --- a/src/server/NetworkResurrector.Server.Application/Events/MachineWaked.cs +++ b/src/server/NetworkResurrector.Server.PublishedLanguage/Events/MachineWaked.cs @@ -1,4 +1,4 @@ -namespace NetworkResurrector.Server.Application.Events +namespace NetworkResurrector.Server.PublishedLanguage.Events { public class MachineWaked { diff --git a/src/server/NetworkResurrector.Server.PublishedLanguage/NetworkResurrector.Server.PublishedLanguage.csproj b/src/server/NetworkResurrector.Server.PublishedLanguage/NetworkResurrector.Server.PublishedLanguage.csproj new file mode 100644 index 0000000..6f3df08 --- /dev/null +++ b/src/server/NetworkResurrector.Server.PublishedLanguage/NetworkResurrector.Server.PublishedLanguage.csproj @@ -0,0 +1,10 @@ + + + + net5.0 + + + + + + diff --git a/src/server/NetworkResurrector.Server.Wrapper/Constants/ApiRoutes.cs b/src/server/NetworkResurrector.Server.Wrapper/Constants/ApiRoutes.cs new file mode 100644 index 0000000..dcbfdf3 --- /dev/null +++ b/src/server/NetworkResurrector.Server.Wrapper/Constants/ApiRoutes.cs @@ -0,0 +1,9 @@ +namespace NetworkResurrector.Server.Wrapper.Constants +{ + internal struct ApiRoutes + { + public const string + Wake = "resurrector/wake", + Ping = "resurrector/ping"; + } +} diff --git a/src/server/NetworkResurrector.Server.Wrapper/DependencyInjectionExtension.cs b/src/server/NetworkResurrector.Server.Wrapper/DependencyInjectionExtension.cs new file mode 100644 index 0000000..c3cc218 --- /dev/null +++ b/src/server/NetworkResurrector.Server.Wrapper/DependencyInjectionExtension.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/src/server/NetworkResurrector.Server.Wrapper/Models/ServiceConfiguration.cs b/src/server/NetworkResurrector.Server.Wrapper/Models/ServiceConfiguration.cs new file mode 100644 index 0000000..ddfa5ec --- /dev/null +++ b/src/server/NetworkResurrector.Server.Wrapper/Models/ServiceConfiguration.cs @@ -0,0 +1,12 @@ +namespace NetworkResurrector.Server.Wrapper.Models +{ + internal class ServiceConfiguration + { + public string BaseAddress { get; } + + public ServiceConfiguration(string baseAddress) + { + BaseAddress = baseAddress; + } + } +} diff --git a/src/server/NetworkResurrector.Server.Wrapper/NetworkResurrector.Server.Wrapper.csproj b/src/server/NetworkResurrector.Server.Wrapper/NetworkResurrector.Server.Wrapper.csproj new file mode 100644 index 0000000..cd666cb --- /dev/null +++ b/src/server/NetworkResurrector.Server.Wrapper/NetworkResurrector.Server.Wrapper.csproj @@ -0,0 +1,17 @@ + + + + net5.0 + + + + + + + + + + + + + diff --git a/src/server/NetworkResurrector.Server.Wrapper/Services/IResurrectorService.cs b/src/server/NetworkResurrector.Server.Wrapper/Services/IResurrectorService.cs new file mode 100644 index 0000000..6e2ef2a --- /dev/null +++ b/src/server/NetworkResurrector.Server.Wrapper/Services/IResurrectorService.cs @@ -0,0 +1,7 @@ +namespace NetworkResurrector.Server.Wrapper.Services +{ + public interface IResurrectorService + { + + } +} \ No newline at end of file diff --git a/src/server/NetworkResurrector.Server.Wrapper/Services/ResurrectorService.cs b/src/server/NetworkResurrector.Server.Wrapper/Services/ResurrectorService.cs new file mode 100644 index 0000000..be0136e --- /dev/null +++ b/src/server/NetworkResurrector.Server.Wrapper/Services/ResurrectorService.cs @@ -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 Wake(string macAddress) + { + var body = new WakeMachine(macAddress); + var result = await _httpClient.ExecutePostRequest(ApiRoutes.Wake, body); + return result; + } + + public async Task Ping(string ipAddressOrMachineName) + { + var body = new PingMachine(ipAddressOrMachineName); + var result = await _httpClient.ExecutePostRequest(ApiRoutes.Wake, body); + return result; + } + } +} diff --git a/src/server/NetworkResurrector.Server/Controllers/ResurrectorController.cs b/src/server/NetworkResurrector.Server/Controllers/ResurrectorController.cs index 0e4ed98..6e31ebf 100644 --- a/src/server/NetworkResurrector.Server/Controllers/ResurrectorController.cs +++ b/src/server/NetworkResurrector.Server/Controllers/ResurrectorController.cs @@ -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 diff --git a/src/server/NetworkResurrector.Server/Startup.cs b/src/server/NetworkResurrector.Server/Startup.cs index 7a6449e..388d5dc 100644 --- a/src/server/NetworkResurrector.Server/Startup.cs +++ b/src/server/NetworkResurrector.Server/Startup.cs @@ -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 }; } }