aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-04-21 00:59:11 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-04-21 00:59:11 +0300
commitd74d21c1ef5c908aa98d7d067a94812a97257cfa (patch)
tree9630f762ba8f14a755952eb7aa62a714989058de /Software/Visual_Studio/PPC/Tango.PPC.Common/Connection
parentf06785ae3312a82b8f2237b55e8c4eeb174c3519 (diff)
downloadTango-d74d21c1ef5c908aa98d7d067a94812a97257cfa.tar.gz
Tango-d74d21c1ef5c908aa98d7d067a94812a97257cfa.zip
Several PPC bug fixes.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Connection')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs57
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/IMachineProvider.cs15
2 files changed, 72 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());
+ }
}
}
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
@@ -16,6 +16,21 @@ namespace Tango.PPC.Common.Connection
public interface IMachineProvider
{
/// <summary>
+ /// Occurs when the machine has connected.
+ /// </summary>
+ event EventHandler MachineConnected;
+
+ /// <summary>
+ /// Occurs when the machine has disconnected.
+ /// </summary>
+ event EventHandler MachineDisconnected;
+
+ /// <summary>
+ /// Gets a value indicating whether the machine is currently connected.
+ /// </summary>
+ bool IsConnected { get; }
+
+ /// <summary>
/// Gets the database machine entity associated with the current machine.
/// </summary>
Machine Machine { get; }