diff options
| author | Roy Ben Shabat <roy.mail.net@gmail.com> | 2025-08-31 04:48:46 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <roy.mail.net@gmail.com> | 2025-08-31 04:48:46 +0300 |
| commit | 76a913a9d3e70f4379c3aaca7e6dd8e4da6aff13 (patch) | |
| tree | 5c1faa8986974daed7393c61e2fe67abb87f275b /Software/Visual_Studio | |
| parent | a1d55aa060450b0a16b597794686b2aa41eea259 (diff) | |
| download | Tango-76a913a9d3e70f4379c3aaca7e6dd8e4da6aff13.tar.gz Tango-76a913a9d3e70f4379c3aaca7e6dd8e4da6aff13.zip | |
Telemetry closed corners.
Diffstat (limited to 'Software/Visual_Studio')
4 files changed, 90 insertions, 33 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Telemetry/ITelemetryProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Telemetry/ITelemetryProvider.cs index 529775d0e..9d6aceff1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Telemetry/ITelemetryProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Telemetry/ITelemetryProvider.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Tango.PPC.Common.Telemetry { - public interface ITelemetryProvider + public interface ITelemetryProvider : IDisposable { TelemetrySettings Settings { get; set; } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index f980d9c22..2cc03891b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -41,6 +41,7 @@ using Tango.PPC.UI.ViewsContracts; using Tango.PPC.Common.Build; using Tango.Core.Components; using static Tango.Core.Components.CmdCommand; +using Tango.PPC.Common.Telemetry; namespace Tango.PPC.UI.PPCApplication { @@ -799,6 +800,17 @@ namespace Tango.PPC.UI.PPCApplication try { + LogManager.Log("Disposing telemetry services..."); + var telemetryProvider = TangoIOC.Default.GetInstance<ITelemetryProvider>(); + telemetryProvider?.Dispose(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error disposing telemetry services."); + } + + try + { LogManager.Log("Disposing insights manager (max 40 seconds to complete)..."); Stopwatch watch = new Stopwatch(); watch.Start(); @@ -812,6 +824,7 @@ namespace Tango.PPC.UI.PPCApplication { LogManager.Log(ex, "Error disposing insights manager."); } + }, TimeSpan.FromSeconds(40)); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Telemetry/DefaultTelemetryProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Telemetry/DefaultTelemetryProvider.cs index 04837bb38..31646c709 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Telemetry/DefaultTelemetryProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Telemetry/DefaultTelemetryProvider.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Tango.BL; using Tango.BL.Entities; +using Tango.Core; using Tango.Core.DI; using Tango.PPC.Common; using Tango.PPC.Common.Application; @@ -21,7 +22,7 @@ using Tango.Telemetry.Sources; namespace Tango.PPC.UI.Telemetry { [TangoCreateWhenRegistered] - public class DefaultTelemetryProvider : ITelemetryProvider, ITelemetryCheckpointsRecoveryClient + public class DefaultTelemetryProvider : ExtendedObject, ITelemetryProvider, ITelemetryCheckpointsRecoveryClient { private PPCWebClient _webClient; private Machine _machine; @@ -60,44 +61,63 @@ namespace Tango.PPC.UI.Telemetry _ppcSettings = SettingsManager.Default.GetOrCreate<PPCSettings>(); - using (ObservablesContext db = ObservablesContext.CreateDefault()) + try { - var site = db.Sites.FirstOrDefault(x => x.Guid == _machine.SiteGuid); - - TelemetryPublisher = new TelemetryPublisher(new TelemetryPublisherConfiguration() + using (ObservablesContext db = ObservablesContext.CreateDefault()) { - Environment = _ppcSettings.DeploymentSlot.ToString(), - Organization = _machine.Organization.Name, - Site = site?.Name, - SerialNumber = _machine.SerialNumber, - MachineType = _machine.Type, - EnableBackoff = Settings.EnableBackoff, - HistorySourcesRequestInterval = Settings.HistorySourcesRequestInterval, - MaxExponentialBackoff = Settings.MaxExponentialBackoff, - PendingStorageCheckInterval = Settings.PendingStorageCheckInterval, - }, this); + var site = db.Sites.FirstOrDefault(x => x.Guid == _machine.SiteGuid); - (TelemetryPublisher.StorageManager as TelemetryLiteDBStorageManager).EnableCheckPointsRecovery = true; - (TelemetryPublisher.StorageManager as TelemetryLiteDBStorageManager).EnforceCheckpointsRecovery = true; - } + TelemetryPublisher = new TelemetryPublisher(new TelemetryPublisherConfiguration() + { + Environment = _ppcSettings.DeploymentSlot.ToString(), + Organization = _machine.Organization.Name, + Site = site?.Name, + SerialNumber = _machine.SerialNumber, + MachineType = _machine.Type, + EnableBackoff = Settings.EnableBackoff, + HistorySourcesRequestInterval = Settings.HistorySourcesRequestInterval, + MaxExponentialBackoff = Settings.MaxExponentialBackoff, + PendingStorageCheckInterval = Settings.PendingStorageCheckInterval, + }, this); - InternetConnectivity.EnsureStarted(); + (TelemetryPublisher.StorageManager as TelemetryLiteDBStorageManager).EnableCheckPointsRecovery = true; + (TelemetryPublisher.StorageManager as TelemetryLiteDBStorageManager).EnforceCheckpointsRecovery = true; + } + + InternetConnectivity.EnsureStarted(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error initializing telemetry publisher."); + return; + } Task.Factory.StartNew(async () => { + LogManager.Log("Telemetry is waiting for an Internet connection..."); + while (!InternetConnectivity.IsInternetAvailable()) { Thread.Sleep(5000); } - if (!_webClient.IsAuthenticated) + LogManager.Log("Retrieving telemetry device connection string from machine service..."); + + try { - await _webClient.Login(new LoginRequest() { Mode = LoginMode.Machine, SerialNumber = _machine.SerialNumber, MachineGuid = _machine.Guid }); - } + if (!_webClient.IsAuthenticated) + { + await _webClient.Login(new LoginRequest() { Mode = LoginMode.Machine, SerialNumber = _machine.SerialNumber, MachineGuid = _machine.Guid }); + } - var response = await _webClient.GetTelemetryDeviceConnection(new TelemetryDeviceRegistrationRequest()); - Settings.IoTHubConnectionString = response.ConnectionString; - Settings.Save(); + var response = await _webClient.GetTelemetryDeviceConnection(new TelemetryDeviceRegistrationRequest()); + Settings.IoTHubConnectionString = response.ConnectionString; + Settings.Save(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Failed to retrieve telemetry device connection string from machine service. Falling back to the current connection string from settings..."); + } if (Settings.EnableIoTHub) { @@ -171,7 +191,14 @@ namespace Tango.PPC.UI.Telemetry TelemetryPublisher.RegisterSource(new TelemetryWireStreamingSource(_machineProvider.MachineOperator)); } - await TelemetryPublisher.Start(); + try + { + await TelemetryPublisher.Start(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error starting telemetry publisher."); + } }); } @@ -203,7 +230,7 @@ namespace Tango.PPC.UI.Telemetry public void Dispose() { - + TelemetryPublisher?.Dispose(); } } } diff --git a/Software/Visual_Studio/Tango.Telemetry/TelemetryPublisher.cs b/Software/Visual_Studio/Tango.Telemetry/TelemetryPublisher.cs index 45da1a1ca..eb4ba57f1 100644 --- a/Software/Visual_Studio/Tango.Telemetry/TelemetryPublisher.cs +++ b/Software/Visual_Studio/Tango.Telemetry/TelemetryPublisher.cs @@ -191,6 +191,8 @@ namespace Tango.Telemetry /// </summary> private void StreamingSource_TelemetryAvailable(object sender, TelemetryAvailableEventArgs e) { + if (_isDisposed) return; + var source = sender as ITelemetrySource; if (source != null) { @@ -1022,12 +1024,20 @@ namespace Tango.Telemetry _isDisposed = true; foreach (var source in InnerSources) { - if (source is ITelemetryStreamingSource streamingSource) + try + { + if (source is ITelemetryStreamingSource streamingSource) + { + streamingSource.Stop(); + streamingSource.TelemetryAvailable -= StreamingSource_TelemetryAvailable; + } + + source.Dispose(); + } + catch (Exception ex) { - streamingSource.Stop(); - streamingSource.TelemetryAvailable -= StreamingSource_TelemetryAvailable; + LogManager.Log(ex, $"Error disposing telemetry source {source.Name}."); } - source.Dispose(); } if (IsStarted) @@ -1037,7 +1047,14 @@ namespace Tango.Telemetry foreach (var destination in Destinations) { - destination.Dispose(); + try + { + destination.Dispose(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error disposing telemetry destination {destination.Name}."); + } } } } |
