diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-21 00:59:11 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-21 00:59:11 +0300 |
| commit | d74d21c1ef5c908aa98d7d067a94812a97257cfa (patch) | |
| tree | 9630f762ba8f14a755952eb7aa62a714989058de /Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs | |
| parent | f06785ae3312a82b8f2237b55e8c4eeb174c3519 (diff) | |
| download | Tango-d74d21c1ef5c908aa98d7d067a94812a97257cfa.tar.gz Tango-d74d21c1ef5c908aa98d7d067a94812a97257cfa.zip | |
Several PPC bug fixes.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs | 57 |
1 files changed, 57 insertions, 0 deletions
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; + /// <summary> + /// Occurs when the machine has connected. + /// </summary> + public event EventHandler MachineConnected; + + /// <summary> + /// Occurs when the machine has disconnected. + /// </summary> + public event EventHandler MachineDisconnected; + + private bool _isConnected; + /// <summary> + /// Gets a value indicating whether the machine is currently connected. + /// </summary> + public bool IsConnected + { + get { return _isConnected; } + private set { _isConnected = value; RaisePropertyChangedAuto(); } + } + private Machine _machine; /// <summary> /// Gets the database machine entity associated with the current machine. @@ -78,6 +98,7 @@ namespace Tango.PPC.Common.Connection var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); 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; } + + /// <summary> + /// Called when the machine has connected. + /// </summary> + protected virtual void OnMachineConnected() + { + IsConnected = true; + MachineConnected?.Invoke(this, new EventArgs()); + } + + /// <summary> + /// Called when the machine has disconnected. + /// </summary> + protected virtual void OnMachineDisconnected() + { + IsConnected = false; + MachineDisconnected?.Invoke(this, new EventArgs()); + } } } |
