diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-17 01:14:07 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-17 01:14:07 +0300 |
| commit | f4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0 (patch) | |
| tree | 6407154a8f42f45e9045b81a54d5f981567faec2 /Software/Visual_Studio/PPC/Tango.PPC.Common | |
| parent | e47e602cd61bcca8eb7fbef40dc4aa8798510ccc (diff) | |
| download | Tango-f4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0.tar.gz Tango-f4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0.zip | |
Working on insights...
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common')
3 files changed, 79 insertions, 7 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs index e5148cfe5..bfbf7114f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs @@ -1,28 +1,33 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Core.DI; using Tango.Insights; +using Tango.Integration.ExternalBridge; +using Tango.Logging; using Tango.PPC.Common.Application; using Tango.PPC.Common.Connection; +using Tango.PPC.Common.ExternalBridge; +using Tango.PPC.Shared.Insights; +using Tango.Settings; namespace Tango.PPC.Common.Insights { [TangoCreateWhenRegistered] - public class DefaultInsightsService : ExtendedObject, IInsightsService + public class DefaultInsightsService : ExtendedObject, IInsightsService, IExternalBridgeRequestHandler { private InsightsListener _listener; - public bool Enabled { get; set; } private IMachineProvider MachineProvider { get; set; } - public DefaultInsightsService(IMachineProvider machineProvider, IPPCApplicationManager applicationManager) + public DefaultInsightsService(IPPCExternalBridgeService externalBridge, IMachineProvider machineProvider, IPPCApplicationManager applicationManager) { + externalBridge.RegisterRequestHandler(this); MachineProvider = machineProvider; - applicationManager.ApplicationStarted += ApplicationManager_ApplicationStarted; } @@ -32,8 +37,25 @@ namespace Tango.PPC.Common.Insights { try { - _listener = new InsightsListener(MachineProvider.MachineOperator); - _listener.Start(); + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + + if (settings.InsightsEnabled) + { + LogManager.Log("Starting insights service..."); + + _listener = new InsightsListener(MachineProvider.MachineOperator); + _listener.SamplingInterval = settings.InsightsSamplingInterval; + _listener.StorageCleanupInterval = settings.InsightsStorageCleanupInterval; + _listener.MaxStorageDuration = settings.InsightsMaxStorageDuration; + + LogManager.Log($"Insights configuration:\nSampling Interval: {_listener.SamplingInterval}\nStorage Cleanup Interval: {_listener.StorageCleanupInterval}\nMax Storage Duration: {_listener.MaxStorageDuration}"); + + _listener.Start(); + } + else + { + LogManager.Log("Insights service is disabled.", LogCategory.Warning); + } } catch (Exception ex) { @@ -41,5 +63,30 @@ namespace Tango.PPC.Common.Insights } }); } + + [ExternalBridgeRequestHandlerMethod(typeof(InsightsRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnInsightsRequest(InsightsRequest request, String token, ExternalBridgeReceiver receiver) + { + InsightsFile insightsFile = new InsightsFile(); + var filePath = TemporaryManager.CreateImaginaryFile(); + + await Task.Factory.StartNew(() => + { + var frames = InsightsManager.Default.GetFrames(request.StartDateUTC, request.EndDateUTC); + insightsFile.Frames = frames; + insightsFile.ToFile(filePath); + }); + + await receiver.SendGenericResponse(new InsightsResponse() + { + InisightsFilePath = filePath, + InsightsFileLength = new FileInfo(filePath).Length + }, token); + } + + public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) + { + //Do Nothing... + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/IInsightsService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/IInsightsService.cs index d7c5497d6..268bb269b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/IInsightsService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/IInsightsService.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Tango.PPC.Common.Insights { - public interface IInsightsService: IPPCService + public interface IInsightsService { } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index 5586b5341..9afbb52b6 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -256,6 +256,26 @@ namespace Tango.PPC.Common public int RemoteDesktopFrameRate { get; set; } /// <summary> + /// Gets or sets a value indicating whether to enable insights. + /// </summary> + public bool InsightsEnabled { get; set; } + + /// <summary> + /// Gets or sets the insights sampling interval. + /// </summary> + public TimeSpan InsightsSamplingInterval { get; set; } + + /// <summary> + /// Gets or sets the insights storage cleanup interval. + /// </summary> + public TimeSpan InsightsStorageCleanupInterval { get; set; } + + /// <summary> + /// Gets or sets the duration of the insights maximum storage duration. + /// </summary> + public TimeSpan InsightsMaxStorageDuration { get; set; } + + /// <summary> /// Gets the machine service address. /// </summary> /// <returns></returns> @@ -305,6 +325,11 @@ namespace Tango.PPC.Common ExternalBridgeSignalRHub = "ExternalBridgeHub"; EnableRemoteDesktop = true; RemoteDesktopFrameRate = 5; + + InsightsEnabled = true; + InsightsSamplingInterval = TimeSpan.FromMinutes(1); + InsightsMaxStorageDuration = TimeSpan.FromDays(30); + InsightsStorageCleanupInterval = TimeSpan.FromMinutes(60); } } } |
