From d74d21c1ef5c908aa98d7d067a94812a97257cfa Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 21 Apr 2020 00:59:11 +0300 Subject: Several PPC bug fixes. --- .../Connection/DefaultMachineProvider.cs | 57 ++++++++++++++++++++++ .../Connection/IMachineProvider.cs | 15 ++++++ 2 files changed, 72 insertions(+) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs index 1c0c52196..9fe6d24bd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -36,6 +36,26 @@ namespace Tango.PPC.Common.Connection private ObservablesContext _context; private bool disableConnectionFileLogging; + /// + /// Occurs when the machine has connected. + /// + public event EventHandler MachineConnected; + + /// + /// Occurs when the machine has disconnected. + /// + public event EventHandler MachineDisconnected; + + private bool _isConnected; + /// + /// Gets a value indicating whether the machine is currently connected. + /// + public bool IsConnected + { + get { return _isConnected; } + private set { _isConnected = value; RaisePropertyChangedAuto(); } + } + private Machine _machine; /// /// Gets the database machine entity associated with the current machine. @@ -78,6 +98,7 @@ namespace Tango.PPC.Common.Connection var settings = SettingsManager.Default.GetOrCreate(); MachineOperator = new MachineOperator(); + MachineOperator.StatusChanged += MachineOperator_StatusChanged; MachineOperator.EnableEventsNotification = true; MachineOperator.EnableJobResume = true; MachineOperator.UseKeepAlive = true; @@ -101,6 +122,24 @@ namespace Tango.PPC.Common.Connection MachineOperator.EnableJobLiquidQuantityValidation = settings.EnableJobLiquidQuantityValidation; } + private void MachineOperator_StatusChanged(object sender, MachineStatuses status) + { + if (status != MachineStatuses.Disconnected) + { + if (!IsConnected) + { + OnMachineConnected(); + } + } + else + { + if (IsConnected) + { + OnMachineConnected(); + } + } + } + private async void ConnectionThreadMethod() { while (true) @@ -358,5 +397,23 @@ namespace Tango.PPC.Common.Connection return machineOperator; } + + /// + /// Called when the machine has connected. + /// + protected virtual void OnMachineConnected() + { + IsConnected = true; + MachineConnected?.Invoke(this, new EventArgs()); + } + + /// + /// Called when the machine has disconnected. + /// + protected virtual void OnMachineDisconnected() + { + IsConnected = false; + MachineDisconnected?.Invoke(this, new EventArgs()); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs index 10180b9cc..774fa7c9e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs @@ -15,6 +15,21 @@ namespace Tango.PPC.Common.Connection /// public interface IMachineProvider { + /// + /// Occurs when the machine has connected. + /// + event EventHandler MachineConnected; + + /// + /// Occurs when the machine has disconnected. + /// + event EventHandler MachineDisconnected; + + /// + /// Gets a value indicating whether the machine is currently connected. + /// + bool IsConnected { get; } + /// /// Gets the database machine entity associated with the current machine. /// -- cgit v1.3.1