aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-17 01:14:07 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-17 01:14:07 +0300
commitf4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0 (patch)
tree6407154a8f42f45e9045b81a54d5f981567faec2 /Software/Visual_Studio/PPC
parente47e602cd61bcca8eb7fbef40dc4aa8798510ccc (diff)
downloadTango-f4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0.tar.gz
Tango-f4c418cced4c6fb25ec5d4cb2bcb4ce0f766efd0.zip
Working on insights...
Diffstat (limited to 'Software/Visual_Studio/PPC')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/DefaultInsightsService.cs59
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Insights/IInsightsService.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs25
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/Insights/InsightsRequest.cs14
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/Insights/InsightsResponse.cs14
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj2
6 files changed, 109 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);
}
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Insights/InsightsRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Insights/InsightsRequest.cs
new file mode 100644
index 000000000..23d19f4c9
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Insights/InsightsRequest.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Shared.Insights
+{
+ public class InsightsRequest
+ {
+ public DateTime StartDateUTC { get; set; }
+ public DateTime EndDateUTC { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Insights/InsightsResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Insights/InsightsResponse.cs
new file mode 100644
index 000000000..38333a459
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Insights/InsightsResponse.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Shared.Insights
+{
+ public class InsightsResponse
+ {
+ public String InisightsFilePath { get; set; }
+ public long InsightsFileLength { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj
index a0cc9b153..cc39c8746 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj
@@ -65,6 +65,8 @@
<Compile Include="Information\GetMachineInformationRequest.cs" />
<Compile Include="Information\GetMachineInformationResponse.cs" />
<Compile Include="Information\InformationPackage.cs" />
+ <Compile Include="Insights\InsightsRequest.cs" />
+ <Compile Include="Insights\InsightsResponse.cs" />
<Compile Include="Jobs\RemoteJobProgress.cs" />
<Compile Include="Jobs\RemoteJobStage.cs" />
<Compile Include="Jobs\RemoteJobUpdateRequest.cs" />