diff options
| author | Avi Levkovich <avi@twine-s.com> | 2020-04-21 14:21:19 +0300 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2020-04-21 14:21:19 +0300 |
| commit | cd728bf3a7d1db76747cb18bcfe396c83d690e86 (patch) | |
| tree | 99347262eef3f175a7ff1441b6c5a031be74d26f /Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs | |
| parent | 7fe23e68512e2462de107e76ae3a92ddd381ac77 (diff) | |
| parent | 97a784b6ce43960bdb92465b08f26d3562a4f202 (diff) | |
| download | Tango-cd728bf3a7d1db76747cb18bcfe396c83d690e86.tar.gz Tango-cd728bf3a7d1db76747cb18bcfe396c83d690e86.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
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()); + } } } |
