LANCommander/LANCommander.Server/Startup/Beacon.cs
Pat Hartl add770b227 Refactor Settings
Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
2025-11-16 12:31:25 -06:00

22 lines
No EOL
930 B
C#

using LANCommander.SDK;
using LANCommander.SDK.Interceptors;
using LANCommander.SDK.Services;
using LANCommander.Server.Services;
namespace LANCommander.Server.Startup;
public static class Beacon
{
public static async Task StartBeaconAsync(this WebApplication app)
{
var settingsProvider = app.Services.GetRequiredService<SettingsProvider<Settings.Settings>>();
var beaconService = app.Services.GetRequiredService<BeaconClient>();
var interceptor = app.Services.GetRequiredService<IBeaconMessageInterceptor>();
beaconService.Initialize();
beaconService.AddBeaconMessageInterceptor(interceptor);
if (settingsProvider.CurrentValue.Server.Beacon.Enabled)
await beaconService.StartBeaconAsync(settingsProvider.CurrentValue.Server.Beacon.Port, settingsProvider.CurrentValue.Server.Beacon.Address, settingsProvider.CurrentValue.Server.Beacon.Name);
}
}