From dcd51ecd3d2e7e47fc64d2f02e9901c48a39c808 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Sat, 1 Aug 2020 17:49:20 +0300 Subject: [PATCH] NUH-38: Implement TelemetryPublisherConsole --- .../TelemetryPublisherConsole.cs | 29 +++++++++++++++++++ .../TelemetryPublisherFactory.cs | 3 +- .../TelemetryPublisherType.cs | 1 + .../Telemetry/TelemetryPublisher.cs | 3 +- .../Properties/launchSettings.json | 3 +- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 NucuCar.Domain.Telemetry/TelemetryPublisherConsole.cs diff --git a/NucuCar.Domain.Telemetry/TelemetryPublisherConsole.cs b/NucuCar.Domain.Telemetry/TelemetryPublisherConsole.cs new file mode 100644 index 0000000..f944fc2 --- /dev/null +++ b/NucuCar.Domain.Telemetry/TelemetryPublisherConsole.cs @@ -0,0 +1,29 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using NucuCar.Domain.Telemetry; + +namespace NucuCar.Telemetry +{ + public class TelemetryPublisherConsole : TelemetryPublisher + { + + public TelemetryPublisherConsole(TelemetryPublisherBuilderOptions opts) : base(opts) + { + } + + public override Task PublishAsync(CancellationToken cancellationToken) + { + var data = GetTelemetry(); + var messageString = JsonConvert.SerializeObject(data); + Logger?.LogDebug($"Telemetry message: {messageString}"); + Logger?.LogInformation(messageString); + return Task.CompletedTask; + } + + public override void Dispose() + { + } + } +} \ No newline at end of file diff --git a/NucuCar.Domain.Telemetry/TelemetryPublisherFactory.cs b/NucuCar.Domain.Telemetry/TelemetryPublisherFactory.cs index e5bba2b..205d45b 100644 --- a/NucuCar.Domain.Telemetry/TelemetryPublisherFactory.cs +++ b/NucuCar.Domain.Telemetry/TelemetryPublisherFactory.cs @@ -47,9 +47,10 @@ namespace NucuCar.Telemetry { return type switch { - TelemetryPublisherType.Azure => (TelemetryPublisher) new TelemetryPublisherAzure(opts), + TelemetryPublisherType.Azure => new TelemetryPublisherAzure(opts), TelemetryPublisherType.Disk => new TelemetryPublisherDisk(opts), TelemetryPublisherType.Firestore => new TelemetryPublisherFirestore(opts), + TelemetryPublisherType.Console => new TelemetryPublisherConsole(opts), _ => throw new ArgumentException($"Invalid TelemetryPublisher type: {type}.") }; } diff --git a/NucuCar.Domain.Telemetry/TelemetryPublisherType.cs b/NucuCar.Domain.Telemetry/TelemetryPublisherType.cs index a49a219..b987869 100644 --- a/NucuCar.Domain.Telemetry/TelemetryPublisherType.cs +++ b/NucuCar.Domain.Telemetry/TelemetryPublisherType.cs @@ -10,5 +10,6 @@ namespace NucuCar.Telemetry public const string Azure = "Azure"; public const string Disk = "Disk"; public const string Firestore = "Firestore"; + public const string Console = "Console"; } } \ No newline at end of file diff --git a/NucuCar.Domain/Telemetry/TelemetryPublisher.cs b/NucuCar.Domain/Telemetry/TelemetryPublisher.cs index 0220e43..0ba7693 100644 --- a/NucuCar.Domain/Telemetry/TelemetryPublisher.cs +++ b/NucuCar.Domain/Telemetry/TelemetryPublisher.cs @@ -37,6 +37,7 @@ namespace NucuCar.Domain.Telemetry /// public TelemetryPublisher() { + RegisteredTelemeters = new List(10); } /// @@ -88,7 +89,7 @@ namespace NucuCar.Domain.Telemetry ConnectionString = opts.ConnectionString; TelemetrySource = opts.TelemetrySource; Logger = opts.Logger; - RegisteredTelemeters = new List(5); + RegisteredTelemeters = new List(10); } /// diff --git a/NucuCar.Sensors/Properties/launchSettings.json b/NucuCar.Sensors/Properties/launchSettings.json index 396d86e..5e94a43 100644 --- a/NucuCar.Sensors/Properties/launchSettings.json +++ b/NucuCar.Sensors/Properties/launchSettings.json @@ -9,7 +9,8 @@ "NucuCar.Sensors.Development": { "commandName": "Project", "environmentVariables": { - "DOTNET_ENVIRONMENT": "Development" + "DOTNET_ENVIRONMENT": "Development", + "Telemetry:Publisher": "Console" } } }