Refactor Telemetry project structure

This commit is contained in:
Denis-Cosmin Nutiu 2020-08-01 18:07:13 +03:00
parent 350fc6bc77
commit 937ea25a2c
29 changed files with 81 additions and 68 deletions

View file

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace NucuCar.Domain.Telemetry
namespace NucuCar.Telemetry.Abstractions
{
/// <summary>
/// Interface that specifies that the component implementing it is willing to provide telemetry data and can be

View file

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NucuCar.Telemetry.Publishers;
namespace NucuCar.Domain.Telemetry
namespace NucuCar.Telemetry.Abstractions
{
/// <summary>
/// The TelemetryPublisher is an abstract class, which provides a base for implementing telemetry publishers.
@ -83,8 +84,8 @@ namespace NucuCar.Domain.Telemetry
/// <summary>
/// Constructor for <see cref="TelemetryPublisher"/>.
/// </summary>
/// <param name="opts">TelemetryPublisher options, see: <see cref="TelemetryPublisherBuilderOptions"/></param>
protected TelemetryPublisher(TelemetryPublisherBuilderOptions opts)
/// <param name="opts">TelemetryPublisher options, see: <see cref="TelemetryPublisherOptions"/></param>
protected TelemetryPublisher(TelemetryPublisherOptions opts)
{
ConnectionString = opts.ConnectionString;
TelemetrySource = opts.TelemetrySource;

View file

@ -5,9 +5,9 @@ using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Telemetry
namespace NucuCar.Telemetry.Publishers
{
/// <summary>
/// Constructs an instance of <see cref="TelemetryPublisherAzure"/>. It is used to publish telemetry to Microsoft
@ -20,7 +20,7 @@ namespace NucuCar.Telemetry
{
protected readonly DeviceClient DeviceClient;
public TelemetryPublisherAzure(TelemetryPublisherBuilderOptions opts) : base(opts)
public TelemetryPublisherAzure(TelemetryPublisherOptions opts) : base(opts)
{
try
{

View file

@ -2,14 +2,14 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Telemetry
namespace NucuCar.Telemetry.Publishers
{
public class TelemetryPublisherConsole : TelemetryPublisher
{
public TelemetryPublisherConsole(TelemetryPublisherBuilderOptions opts) : base(opts)
public TelemetryPublisherConsole(TelemetryPublisherOptions opts) : base(opts)
{
}

View file

@ -6,10 +6,10 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NucuCar.Domain.Telemetry;
using NucuCar.Domain.Utilities;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Telemetry
namespace NucuCar.Telemetry.Publishers
{
/// <summary>
/// The TelemetryPublisherDisk is used to publish telemetry data to a file on the disk.
@ -30,7 +30,7 @@ namespace NucuCar.Telemetry
/// </remarks>
/// </summary>
/// <param name="opts"></param>
public TelemetryPublisherDisk(TelemetryPublisherBuilderOptions opts) : base(opts)
public TelemetryPublisherDisk(TelemetryPublisherOptions opts) : base(opts)
{
var connectionStringParams = ConnectionStringParser.Parse(opts.ConnectionString);
var fileName = connectionStringParams.GetValueOrDefault("FileName", "telemetry");

View file

@ -4,12 +4,11 @@ using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NucuCar.Domain;
using NucuCar.Domain.Http;
using NucuCar.Domain.Telemetry;
using NucuCar.Domain.Utilities;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Telemetry
namespace NucuCar.Telemetry.Publishers
{
/// <summary>
/// This class is used to publish the telemetry data to Google's Cloud Firestore.
@ -37,7 +36,7 @@ namespace NucuCar.Telemetry
private readonly string _webPassword;
private readonly string _webApiKey;
public TelemetryPublisherFirestore(TelemetryPublisherBuilderOptions opts) : base(opts)
public TelemetryPublisherFirestore(TelemetryPublisherOptions opts) : base(opts)
{
// Parse Options
var options = ConnectionStringParser.Parse(opts.ConnectionString);

View file

@ -1,6 +1,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry.Abstractions;
// ReSharper disable ClassWithVirtualMembersNeverInherited.Global

View file

@ -1,6 +1,6 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Telemetry
{

View file

@ -1,7 +1,8 @@
using System;
using Microsoft.Extensions.Logging;
using NucuCar.Domain.Telemetry;
using NucuCar.Domain.Utilities;
using NucuCar.Telemetry.Abstractions;
using NucuCar.Telemetry.Publishers;
namespace NucuCar.Telemetry
{
@ -24,7 +25,7 @@ namespace NucuCar.Telemetry
Guard.ArgumentNotNullOrWhiteSpace(nameof(connectionString), connectionString);
Guard.ArgumentNotNullOrWhiteSpace(nameof(telemetrySource), telemetrySource);
Guard.ArgumentNotNull(nameof(logger), logger);
var opts = new TelemetryPublisherBuilderOptions()
var opts = new TelemetryPublisherOptions()
{ConnectionString = connectionString, TelemetrySource = telemetrySource, Logger = logger};
return SpawnPublisher(type, opts);
}
@ -38,12 +39,12 @@ namespace NucuCar.Telemetry
public static TelemetryPublisher CreateFromConnectionString(string type, string connectionString)
{
Guard.ArgumentNotNullOrWhiteSpace(nameof(connectionString), connectionString);
var opts = new TelemetryPublisherBuilderOptions()
var opts = new TelemetryPublisherOptions()
{ConnectionString = connectionString, TelemetrySource = "TelemetryPublisherAzure"};
return SpawnPublisher(type, opts);
}
private static TelemetryPublisher SpawnPublisher(string type, TelemetryPublisherBuilderOptions opts)
private static TelemetryPublisher SpawnPublisher(string type, TelemetryPublisherOptions opts)
{
return type switch
{

View file

@ -1,25 +1,26 @@
using Microsoft.Extensions.Logging;
namespace NucuCar.Domain.Telemetry
{
/// <summary>
/// This class contains options for the <see cref="TelemetryPublisher"/>.
/// </summary>
public class TelemetryPublisherBuilderOptions
{
/// <summary>
/// The ConnectionString used by the publisher to connect to the cloud service.
/// </summary>
public string ConnectionString { get; set; }
/// <summary>
/// A string that indicates the source of the telemetry data.
/// </summary>
public string TelemetrySource { get; set; }
/// <summary>
/// The <see cref="ILogger"/> logger instance.
/// </summary>
public ILogger Logger { get; set; }
}
using Microsoft.Extensions.Logging;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Telemetry
{
/// <summary>
/// This class contains options for the <see cref="TelemetryPublisher"/>.
/// </summary>
public class TelemetryPublisherOptions
{
/// <summary>
/// The ConnectionString used by the publisher to connect to the cloud service.
/// </summary>
public string ConnectionString { get; set; }
/// <summary>
/// A string that indicates the source of the telemetry data.
/// </summary>
public string TelemetrySource { get; set; }
/// <summary>
/// The <see cref="ILogger"/> logger instance.
/// </summary>
public ILogger Logger { get; set; }
}
}

View file

@ -1,4 +1,4 @@
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Telemetry
{

View file

@ -4,7 +4,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Telemetry
{

View file

@ -2,7 +2,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NucuCarSensorsProto;
namespace NucuCar.Domain.Sensors
namespace NucuCar.Sensors.Abstractions
{
/// <summary>
/// The GenericSensor is an abstract class, which provides a base for abstracting hardware sensors.

View file

@ -1,13 +1,13 @@
using System.Collections.Generic;
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.Domain.Sensors
namespace NucuCar.Sensors.Abstractions
{
/// <summary>
/// The GenericSensor is an abstract class, which provides a base for abstracting hardware sensors
/// with telemetry support.
/// See: <see cref="ITelemeter"/>
/// See: <see cref="GenericSensor"/>
/// See: <see cref="NucuCar.Sensors.GenericSensor"/>
/// </summary>
public abstract class GenericTelemeterSensor : GenericSensor, ITelemeter
{

View file

@ -1,6 +1,4 @@
using NucuCar.Domain.Sensors;
namespace NucuCar.Sensors
namespace NucuCar.Sensors.Abstractions
{
public interface ISensor<out TSensor> where TSensor : GenericTelemeterSensor
{

View file

@ -3,6 +3,7 @@ using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NucuCar.Sensors.Abstractions;
using NucuCar.Sensors.Grpc;
using NucuCarSensorsProto;

View file

@ -5,7 +5,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using NucuCar.Domain.Sensors;
using NucuCar.Sensors.Abstractions;
using NucuCar.Sensors.Environment.Bmxx80;
using NucuCarSensorsProto;
using Bme680 = NucuCar.Sensors.Environment.Bmxx80.Bme680;

View file

@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using NucuCar.Sensors.Abstractions;
using NucuCar.Telemetry;
namespace NucuCar.Sensors.Environment

View file

@ -3,6 +3,7 @@ using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NucuCar.Sensors.Abstractions;
using NucuCar.Sensors.Grpc;
using NucuCarSensorsProto;

View file

@ -5,7 +5,7 @@ using Iot.Device.CpuTemperature;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using NucuCar.Domain.Sensors;
using NucuCar.Sensors.Abstractions;
using NucuCarSensorsProto;
namespace NucuCar.Sensors.Health

View file

@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using NucuCar.Sensors.Abstractions;
using NucuCar.Telemetry;
namespace NucuCar.Sensors.Health

View file

@ -81,4 +81,8 @@
<ProjectReference Include="..\NucuCar.Domain.Telemetry\NucuCar.Domain.Telemetry.csproj" />
<ProjectReference Include="..\NucuCar.Domain\NucuCar.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Modules" />
</ItemGroup>
</Project>

View file

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NucuCar.Sensors.Abstractions;
using NucuCar.Sensors.Environment;
using NucuCar.Sensors.Grpc;
using NucuCar.Sensors.Health;

View file

@ -3,8 +3,8 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NucuCar.Domain.Sensors;
using NucuCar.Domain.Telemetry;
using NucuCar.Sensors.Abstractions;
using NucuCar.Telemetry.Abstractions;
using NucuCarSensorsProto;
namespace NucuCar.Sensors

View file

@ -6,8 +6,8 @@ using System.Threading.Tasks;
using CommandLine;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry;
using NucuCar.Telemetry.Abstractions;
namespace NucuCar.TestClient.Telemetry
{

View file

@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using NucuCar.Sensors;
using NucuCar.Sensors.Abstractions;
using NucuCar.Sensors.Environment;
using NucuCarSensorsProto;
using Xunit;

View file

@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using NucuCar.Sensors;
using NucuCar.Sensors.Abstractions;
using NucuCar.Sensors.Environment;
using NucuCarSensorsProto;
using Xunit;

View file

@ -1,5 +1,6 @@
using System;
using NucuCar.Telemetry;
using NucuCar.Telemetry.Publishers;
using Xunit;
namespace NucuCar.UnitTests.NucuCar.Telemetry.Tests

View file

@ -6,8 +6,9 @@ using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using NucuCar.Domain.Http;
using NucuCar.Domain.Telemetry;
using NucuCar.Telemetry;
using NucuCar.Telemetry.Abstractions;
using NucuCar.Telemetry.Publishers;
using Xunit;
using HttpClient = NucuCar.Domain.Http.HttpClient;
@ -20,7 +21,7 @@ namespace NucuCar.UnitTests.NucuCar.Telemetry.Tests
{
private Dictionary<string, object> _mockData;
public MockTelemetryPublisherFirestore(TelemetryPublisherBuilderOptions opts) : base(opts)
public MockTelemetryPublisherFirestore(TelemetryPublisherOptions opts) : base(opts)
{
_mockData = new Dictionary<string, object>();
}
@ -47,7 +48,7 @@ namespace NucuCar.UnitTests.NucuCar.Telemetry.Tests
private void Test_Construct_BadProjectId()
{
// Setup
var opts = new TelemetryPublisherBuilderOptions()
var opts = new TelemetryPublisherOptions()
{
ConnectionString = "ProjectIdBAD=test;CollectionName=test"
};
@ -60,7 +61,7 @@ namespace NucuCar.UnitTests.NucuCar.Telemetry.Tests
private void Test_Construct_BadCollectiontName()
{
// Setup
var opts = new TelemetryPublisherBuilderOptions()
var opts = new TelemetryPublisherOptions()
{
ConnectionString = "ProjectId=test;CollectionNameBAD=test"
};
@ -73,7 +74,7 @@ namespace NucuCar.UnitTests.NucuCar.Telemetry.Tests
private async Task Test_PublishAsync_OK()
{
// Setup
var opts = new TelemetryPublisherBuilderOptions()
var opts = new TelemetryPublisherOptions()
{
ConnectionString = "ProjectId=test;CollectionName=test"
};
@ -98,7 +99,7 @@ namespace NucuCar.UnitTests.NucuCar.Telemetry.Tests
private async Task Test_PublishAsync_Cancel()
{
// Setup
var opts = new TelemetryPublisherBuilderOptions()
var opts = new TelemetryPublisherOptions()
{
ConnectionString = "ProjectId=test;CollectionName=test"
};
@ -122,7 +123,7 @@ namespace NucuCar.UnitTests.NucuCar.Telemetry.Tests
private async Task Test_PublishAsync_Authorization_OK()
{
// Setup
var opts = new TelemetryPublisherBuilderOptions()
var opts = new TelemetryPublisherOptions()
{
ConnectionString =
"ProjectId=test;CollectionName=test;WebApiKey=TAPIKEY;WebApiEmail=t@emai.com;WebApiPassword=tpass"