46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using BeaconLib;
|
|
using LANCommander.Server.Models;
|
|
using LANCommander.Server.Services.Abstractions;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace LANCommander.Server.Services
|
|
{
|
|
public class BeaconService(
|
|
ILogger<BeaconService> logger,
|
|
IVersionProvider versionProvider) : BaseService(logger), IHostedService, IDisposable
|
|
{
|
|
private Beacon _beacon;
|
|
|
|
public override void Initialize()
|
|
{
|
|
_beacon = new Beacon("LANCommander", Convert.ToUInt16(_settings.Port));
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_beacon?.Dispose();
|
|
}
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
string[] dataParts = new string[]
|
|
{
|
|
_settings.Beacon?.Address,
|
|
_settings.Beacon?.Name,
|
|
versionProvider.GetCurrentVersion().ToString(),
|
|
};
|
|
|
|
_beacon.BeaconData = String.Join('|', dataParts);
|
|
_beacon.Start();
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_beacon.Stop();
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|