aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Telemetry/Destinations/AzureHubTelemetryDestination.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Telemetry/Destinations/AzureHubTelemetryDestination.cs')
-rw-r--r--Software/Visual_Studio/Tango.Telemetry/Destinations/AzureHubTelemetryDestination.cs77
1 files changed, 0 insertions, 77 deletions
diff --git a/Software/Visual_Studio/Tango.Telemetry/Destinations/AzureHubTelemetryDestination.cs b/Software/Visual_Studio/Tango.Telemetry/Destinations/AzureHubTelemetryDestination.cs
deleted file mode 100644
index 7a9cc9f7a..000000000
--- a/Software/Visual_Studio/Tango.Telemetry/Destinations/AzureHubTelemetryDestination.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-using Microsoft.Azure.Devices.Client;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Core;
-
-namespace Tango.Telemetry.Destinations
-{
- public class AzureHubTelemetryDestination : ExtendedObject, ITelemetryDestination
- {
- private DeviceClient _hubClient;
-
- public string Name { get; set; } = "Azure IoT Hub";
- public bool Enable { get; set; } = true;
- public String ConnectionString { get; private set; }
-
- public ConnectionStatus HubConnectionStatus { get; private set; }
- public IReadOnlyList<TelemetrySourceTypes> SupportedSourceTypes { get; private set; }
-
- public AzureHubTelemetryDestination(String connectionString)
- {
- HubConnectionStatus = ConnectionStatus.Connected;
- ConnectionString = connectionString;
- SupportedSourceTypes = new List<TelemetrySourceTypes>() { TelemetrySourceTypes.PendingStorage, TelemetrySourceTypes.Streaming, TelemetrySourceTypes.ExternalStorage };
- }
-
- public Task<bool> IsAvailable()
- {
- if (_hubClient == null)
- {
- return Task.FromResult(true);
- }
- else
- {
- return Task.FromResult(HubConnectionStatus == ConnectionStatus.Connected);
- }
- }
-
- public async Task Publish(TelemetryPublishPackage package, List<KeyValuePair<String, String>> properties)
- {
- if (_hubClient == null)
- {
- _hubClient = DeviceClient.CreateFromConnectionString(ConnectionString, TransportType.Mqtt);
- _hubClient.SetConnectionStatusChangesHandler((status, reason) =>
- {
- HubConnectionStatus = status;
- LogManager.Log($"IoT hub status changed to: {status}, Reason: {reason}.");
- });
- }
-
- var message = new Message(Encoding.UTF8.GetBytes(package.ToPayload()))
- {
- ContentType = "application/json",
- ContentEncoding = "utf-8"
- };
-
- foreach (var prop in properties)
- {
- message.Properties.Add(prop.Key, prop.Value);
- }
-
- await _hubClient.SendEventAsync(message);
- }
-
- public void Dispose()
- {
- _hubClient?.Dispose();
- }
-
- public override string ToString()
- {
- return Name;
- }
- }
-}