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 { /// /// Represents the default implementation. /// /// /// [TangoCreateWhenRegistered] public class DefaultPerformanceProvider : ExtendedObject, IPerformanceProvider { /// /// Gets or sets the machine provider. /// private IMachineProvider MachineProvider { get; set; } [TangoInject] private INotificationProvider NotificationProvider { get; set; } /// /// Occurs when a new performance monitoring frame is available. /// public event EventHandler PerformancePackageAvailable; /// /// Initializes a new instance of the class. /// /// The machine provider. 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(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 }); } } }