diff --git a/NetworkResurrector.Api/Extensions/WakeOnLanExtensions.cs b/NetworkResurrector.Api/Extensions/WakeOnLanExtensions.cs index 8535986..91034eb 100644 --- a/NetworkResurrector.Api/Extensions/WakeOnLanExtensions.cs +++ b/NetworkResurrector.Api/Extensions/WakeOnLanExtensions.cs @@ -1,14 +1,37 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NetworkResurrector.WakeOnLan.Inhouse; +using NetworkResurrector.WakeOnLan.Nikeee; +using System; namespace NetworkResurrector.Api.Extensions { public static class WakeOnLanExtensions { + private struct WolProvider + { + public const string + Inhouse = "Inhouse", + Nikeee = "Nikeee"; + } + public static void AddWakeOnLan(this IServiceCollection services, IConfiguration configuration) { - services.AddWakeOnLanService(); + var wolProvider = configuration.GetSection("WakeOnLan").GetSection("Provider").GetValue("Use"); + + switch (wolProvider) + { + case WolProvider.Inhouse: + services.AddWakeOnLanInhouseService(); + break; + + case WolProvider.Nikeee: + services.AddWakeOnLanNikeeeService(); + break; + + default: + throw new Exception($"Wake on LAN provider '{wolProvider}' is not implemented."); + } } } } diff --git a/NetworkResurrector.Api/NetworkResurrector.Api.csproj b/NetworkResurrector.Api/NetworkResurrector.Api.csproj index 03ab91d..6a216f4 100644 --- a/NetworkResurrector.Api/NetworkResurrector.Api.csproj +++ b/NetworkResurrector.Api/NetworkResurrector.Api.csproj @@ -24,6 +24,7 @@ + diff --git a/NetworkResurrector.Api/appsettings.json b/NetworkResurrector.Api/appsettings.json index 55dfb99..663fdfd 100644 --- a/NetworkResurrector.Api/appsettings.json +++ b/NetworkResurrector.Api/appsettings.json @@ -17,5 +17,11 @@ "UserName": "***REMOVED***", "Password": "***REMOVED***" } - ] + ], + "WakeOnLan": { + "Provider": { + "Use": "Inhouse", + "Options": [ "Inhouse", "Nikeee" ] + } + } } diff --git a/NetworkResurrector.WakeOnLan.Inhouse/DependencyInjectionExtensions.cs b/NetworkResurrector.WakeOnLan.Inhouse/DependencyInjectionExtensions.cs index 92e30d1..fa16731 100644 --- a/NetworkResurrector.WakeOnLan.Inhouse/DependencyInjectionExtensions.cs +++ b/NetworkResurrector.WakeOnLan.Inhouse/DependencyInjectionExtensions.cs @@ -5,7 +5,7 @@ namespace NetworkResurrector.WakeOnLan.Inhouse { public static class DependencyInjectionExtensions { - public static void AddWakeOnLanService(this IServiceCollection services) + public static void AddWakeOnLanInhouseService(this IServiceCollection services) { services.AddScoped(); services.AddScoped(); diff --git a/NetworkResurrector.WakeOnLan.Nikeee/DependencyInjectionExtensions.cs b/NetworkResurrector.WakeOnLan.Nikeee/DependencyInjectionExtensions.cs index 0176920..e40b483 100644 --- a/NetworkResurrector.WakeOnLan.Nikeee/DependencyInjectionExtensions.cs +++ b/NetworkResurrector.WakeOnLan.Nikeee/DependencyInjectionExtensions.cs @@ -5,7 +5,7 @@ namespace NetworkResurrector.WakeOnLan.Nikeee { public static class DependencyInjectionExtensions { - public static void AddWakeOnLanService(this IServiceCollection services) + public static void AddWakeOnLanNikeeeService(this IServiceCollection services) { services.AddScoped(); } diff --git a/NetworkResurrector.WakeOnLan.Nikeee/WakeOnLanService.cs b/NetworkResurrector.WakeOnLan.Nikeee/WakeOnLanService.cs index 55f874c..f7a1772 100644 --- a/NetworkResurrector.WakeOnLan.Nikeee/WakeOnLanService.cs +++ b/NetworkResurrector.WakeOnLan.Nikeee/WakeOnLanService.cs @@ -1,14 +1,18 @@ using NetworkResurrector.Abstractions; -using System; +using System.Net; +using System.Net.NetworkInformation; using System.Threading.Tasks; namespace NetworkResurrector.WakeOnLan.Nikeee { public class WakeOnLanService : IWakeOnLanService { - public Task<(bool success, string message)> Wake(string macAddress) + public async Task<(bool success, string message)> Wake(string macAddress) { - throw new NotImplementedException(); + var mac = PhysicalAddress.Parse(macAddress); + await mac.SendWolAsync(); + + return (true, "Success"); } } }