blob: e0ca2265cdb9b84af5045a6d8f56330c6ab597dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.DI;
using Tango.FSE.Common.Connection;
using Tango.FSE.Common.Notifications;
using Tango.FSE.Common.Performance;
using Tango.PPC.Shared.Performance;
namespace Tango.FSE.UI.Performance
{
/// <summary>
/// Represents the <see cref="IPerformanceProvider"/> default implementation.
/// </summary>
/// <seealso cref="Tango.Core.ExtendedObject" />
/// <seealso cref="Tango.FSE.Common.Performance.IPerformanceProvider" />
[TangoCreateWhenRegistered]
public class DefaultPerformanceProvider : ExtendedObject, IPerformanceProvider
{
/// <summary>
/// Gets or sets the machine provider.
/// </summary>
private IMachineProvider MachineProvider { get; set; }
[TangoInject]
private INotificationProvider NotificationProvider { get; set; }
/// <summary>
/// Occurs when a new performance monitoring frame is available.
/// </summary>
public event EventHandler<PerformancePackageEventArgs> PerformancePackageAvailable;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultPerformanceProvider"/> class.
/// </summary>
/// <param name="machineProvider">The machine provider.</param>
public DefaultPerformanceProvider(IMachineProvider machineProvider)
{
MachineProvider = machineProvider;
MachineProvider.MachineConnected += MachineProvider_MachineConnected;
}
private void MachineProvider_MachineConnected(object sender, MachineConnectedEventArgs e)
{
if (MachineProvider.ConnectionType.IsRemote())
{
LogManager.Log("Starting remote PPC performance provider. Sending continuous performance updates request...");
try
{
MachineProvider.MachineOperator.SendGenericContinuousRequest<StartPerformanceUpdatesRequest, StartPerformanceUpdatesResponse>(new StartPerformanceUpdatesRequest()).Subscribe((response) =>
{
OnPerformancePackageAvailable(response.Package);
}, (ex) =>
{
if (!(ex is Transport.TransporterDisconnectedException))
{
LogManager.Log(ex, "Error starting remote PPC performance updates.");
NotificationProvider.PushErrorReportingSnackbar(ex, "PPC Module Error", "Error starting remote PPC performance updates.");
}
}, () =>
{
//Do nothing.
});
}
catch (Exception ex)
{
LogManager.Log(ex, "Error starting remote PPC performance updates.");
NotificationProvider.PushErrorReportingSnackbar(ex, "PPC Module Error", "Error starting remote PPC performance updates.");
}
}
}
protected virtual void OnPerformancePackageAvailable(PerformancePackage package)
{
PerformancePackageAvailable?.Invoke(this, new PerformancePackageEventArgs() { Package = package });
}
}
}
|