2019-11-24 15:47:17 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2019-11-26 18:24:27 +00:00
|
|
|
using Microsoft.Extensions.Options;
|
2019-11-24 15:47:17 +00:00
|
|
|
using NucuCar.Domain.Telemetry;
|
2019-12-28 15:09:17 +00:00
|
|
|
|
2019-11-30 15:19:56 +00:00
|
|
|
// ReSharper disable ClassWithVirtualMembersNeverInherited.Global
|
2019-11-24 15:47:17 +00:00
|
|
|
|
2020-04-17 15:11:07 +00:00
|
|
|
namespace NucuCar.Telemetry
|
2019-11-24 15:47:17 +00:00
|
|
|
{
|
2020-05-01 08:29:59 +00:00
|
|
|
public class Telemetry
|
2019-11-24 15:47:17 +00:00
|
|
|
{
|
2019-11-30 15:19:56 +00:00
|
|
|
public TelemetryPublisher Publisher { get; set; }
|
2019-11-24 15:47:17 +00:00
|
|
|
|
2020-05-01 08:29:59 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Class used together with the DI, holds a Publisher instance that's being create by options from
|
|
|
|
/// TelemetryConfig.
|
|
|
|
/// </summary>
|
|
|
|
public Telemetry()
|
2019-11-30 15:19:56 +00:00
|
|
|
{
|
|
|
|
}
|
2019-12-28 15:09:17 +00:00
|
|
|
|
2020-05-01 08:29:59 +00:00
|
|
|
public Telemetry(ILogger<Telemetry> logger, IOptions<TelemetryConfig> options)
|
2019-11-24 15:47:17 +00:00
|
|
|
{
|
2019-11-26 18:24:27 +00:00
|
|
|
if (options.Value.ServiceEnabled)
|
2019-11-24 15:47:17 +00:00
|
|
|
{
|
2019-12-28 15:09:17 +00:00
|
|
|
Publisher = TelemetryPublisherFactory.Create(options.Value.Publisher, options.Value.ConnectionString,
|
2019-11-25 09:40:17 +00:00
|
|
|
"NucuCar.Sensors", logger);
|
2019-11-24 15:47:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Publisher = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|