aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-12-10 18:29:04 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-12-10 18:29:04 +0200
commita899cdbb2c5f36d9fb5d89744b69387289765cf8 (patch)
tree7063118161488afab380205772a634bed3ea26ef /Software/Visual_Studio
parent6240aad18f5dc54d4e29bf2d39f49ef1ba39742f (diff)
downloadTango-a899cdbb2c5f36d9fb5d89744b69387289765cf8.tar.gz
Tango-a899cdbb2c5f36d9fb5d89744b69387289765cf8.zip
Improved Transporter keep alive and disconnection/connection procedures.
Added Disconnected machine state.
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs2
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs146
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItem.cs1
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItemView.xaml10
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Images/GlobalStatus/machine-off.pngbin0 -> 861 bytes
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj1
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml3
-rw-r--r--Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs2
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs9
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/MachineStatuses.cs2
-rw-r--r--Software/Visual_Studio/Tango.Transport/TransportMessage.cs84
-rw-r--r--Software/Visual_Studio/Tango.Transport/TransporterBase.cs74
12 files changed, 203 insertions, 131 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs
index 2b4a5a75b..81b6e5942 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs
@@ -88,7 +88,7 @@ namespace Tango.PPC.Events.ViewModels
notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Error;
break;
case EventTypesCategories.Critical:
- notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Error;
+ notificationItem.MessageType = MessageNotificationItem.MessageNotificationItemTypes.Critical;
break;
}
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 09d4ed9f8..52d738220 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs
@@ -18,6 +18,8 @@ using Tango.PPC.Common.Messages;
using Tango.Emulations.Emulators;
using Tango.Transport.Transporters;
using Tango.Integration;
+using Tango.Transport;
+using System.Threading;
namespace Tango.PPC.Common.Connection
{
@@ -29,6 +31,7 @@ namespace Tango.PPC.Common.Connection
public class DefaultMachineProvider : ExtendedObject, IMachineProvider
{
private bool _isInitialized;
+ private Thread _connection_thread;
/// <summary>
/// Occurs when current <see cref="IMachineOperator" /> has changed.
@@ -89,6 +92,82 @@ namespace Tango.PPC.Common.Connection
MachineOperator = new MachineOperator();
MachineOperator.EnableEventsNotification = true;
MachineOperator.EnableJobResume = true;
+ MachineOperator.UseKeepAlive = true;
+ }
+
+ private async void ConnectionThreadMethod()
+ {
+ while (true)
+ {
+ if (MachineOperator.State != TransportComponentState.Connected)
+ {
+ try
+ {
+ LogManager.Log("Starting machine connection procedure...");
+
+ var settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
+
+ var demo = settings.DemoMode;
+
+ if (!demo)
+ {
+ if (String.IsNullOrWhiteSpace(settings.EmbeddedComPort))
+ {
+ TimeSpan timeout = TimeSpan.FromSeconds(SettingsManager.Default.GetOrCreate<PPCSettings>().MachineScanningTimeoutSeconds);
+
+ LogManager.Log("Scanning for machine on available serial ports...");
+ Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse> scanner = new Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse>(UsbSerialBaudRates.BR_115200);
+ var response = await scanner.Scan(new ConnectRequest() { Password = "1234" }, timeout);
+
+ LogManager.Log("Machine discovered on port: " + response.Adapter.Address);
+ LogManager.Log("Device Information:");
+ LogManager.Log(response.Response.DeviceInformation.ToJsonString());
+
+ LogManager.Log("Disconnecting machine operator...");
+ await MachineOperator.Disconnect();
+ MachineOperator.Adapter = response.Adapter;
+ MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp;
+ LogManager.Log("Connecting machine operator...");
+ MachineOperatorChanged?.Invoke(this, new MachineOperatorChangedEventArgs(MachineOperator, MachineOperator));
+ await MachineOperator.Connect();
+ }
+ else
+ {
+ LogManager.Log($"Connecting to machine on {settings.EmbeddedComPort}...");
+
+ UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200);
+ MachineOperator.Adapter = adapter;
+ MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp;
+ MachineOperatorChanged?.Invoke(this, new MachineOperatorChangedEventArgs(MachineOperator, MachineOperator));
+ await MachineOperator.Connect();
+ }
+ }
+ else
+ {
+ LogManager.Log("Application in demo mode!");
+
+ LogManager.Log("Starting embedded emulator...");
+ MachineEmulator emulator = new MachineEmulator(new BasicTransporter(new MemoryTransportAdapter("emulator")));
+ await emulator.Start();
+
+ LogManager.Log("Emulator started. Connecting to emulator...");
+
+ MemoryTransportAdapter adapter = new MemoryTransportAdapter("emulator");
+ MachineOperator.Adapter = adapter;
+ MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp;
+ LogManager.Log("Connecting machine operator...");
+ MachineOperatorChanged?.Invoke(this, new MachineOperatorChangedEventArgs(MachineOperator, MachineOperator));
+ await MachineOperator.Connect();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error while trying to scan and connect to the machine.");
+ }
+ }
+
+ Thread.Sleep(5000);
+ }
}
/// <summary>
@@ -122,70 +201,13 @@ namespace Tango.PPC.Common.Connection
/// Tries to connect to the machine by scanning all available serial ports.
/// The timeout for a scan cycle is specified on <see cref="PPCSettings.MachineScanningTimeoutSeconds"/>.
/// </summary>
- private async void ConnectToMachine()
+ private void ConnectToMachine()
{
- try
- {
- LogManager.Log("Starting machine connection procedure...");
-
- var settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
-
- var demo = settings.DemoMode;
-
- if (!demo)
- {
- if (String.IsNullOrWhiteSpace(settings.EmbeddedComPort))
- {
- TimeSpan timeout = TimeSpan.FromSeconds(SettingsManager.Default.GetOrCreate<PPCSettings>().MachineScanningTimeoutSeconds);
-
- LogManager.Log("Scanning for machine on available serial ports...");
- Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse> scanner = new Transport.Discovery.UsbCommunicationScanner<ConnectRequest, ConnectResponse>(UsbSerialBaudRates.BR_115200);
- var response = await scanner.Scan(new ConnectRequest() { Password = "1234" }, timeout);
-
- LogManager.Log("Machine discovered on port: " + response.Adapter.Address);
- LogManager.Log("Device Information:");
- LogManager.Log(response.Response.DeviceInformation.ToJsonString());
-
- LogManager.Log("Disconnecting machine operator...");
- await MachineOperator.Disconnect();
- MachineOperator.Adapter = response.Adapter;
- MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp;
- LogManager.Log("Connecting machine operator...");
- MachineOperatorChanged?.Invoke(this, new MachineOperatorChangedEventArgs(MachineOperator, MachineOperator));
- await MachineOperator.Connect();
- }
- else
- {
- LogManager.Log($"Connecting to machine on {settings.EmbeddedComPort}...");
-
- UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200);
- MachineOperator.Adapter = adapter;
- MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp;
- MachineOperatorChanged?.Invoke(this, new MachineOperatorChangedEventArgs(MachineOperator, MachineOperator));
- await MachineOperator.Connect();
- }
- }
- else
- {
- LogManager.Log("Application in demo mode!");
-
- LogManager.Log("Starting embedded emulator...");
- MachineEmulator emulator = new MachineEmulator(new BasicTransporter(new MemoryTransportAdapter("emulator")));
- await emulator.Start();
-
- LogManager.Log("Emulator started. Connecting to emulator...");
-
- MemoryTransportAdapter adapter = new MemoryTransportAdapter("emulator");
- MachineOperator.Adapter = adapter;
- MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp;
- LogManager.Log("Connecting machine operator...");
- MachineOperatorChanged?.Invoke(this, new MachineOperatorChangedEventArgs(MachineOperator, MachineOperator));
- await MachineOperator.Connect();
- }
- }
- catch (Exception ex)
+ if (_connection_thread == null)
{
- LogManager.Log(ex, "Error while trying to scan and connect to the machine.");
+ _connection_thread = new Thread(ConnectionThreadMethod);
+ _connection_thread.IsBackground = true;
+ _connection_thread.Start();
}
}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItem.cs
index 0f8354157..a9de336a1 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItem.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItem.cs
@@ -21,6 +21,7 @@ namespace Tango.PPC.Common.Notifications.NotificationItems
Success,
Warning,
Error,
+ Critical,
}
private String _message;
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItemView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItemView.xaml
index dbd9a0eca..efb6a5447 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItemView.xaml
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Notifications/NotificationItems/MessageNotificationItemView.xaml
@@ -25,6 +25,9 @@
<DataTrigger Binding="{Binding MessageType}" Value="Error">
<Setter Property="Foreground" Value="{StaticResource TangoErrorBrush}"></Setter>
</DataTrigger>
+ <DataTrigger Binding="{Binding MessageType}" Value="Critical">
+ <Setter Property="Foreground" Value="{StaticResource TangoErrorBrush}"></Setter>
+ </DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
@@ -41,10 +44,13 @@
<Setter Property="Icon" Value="Check"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding MessageType}" Value="Warning">
- <Setter Property="Icon" Value="Alert"></Setter>
+ <Setter Property="Icon" Value="AlertCircleOutline"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding MessageType}" Value="Error">
- <Setter Property="Icon" Value="AlertOctagon"></Setter>
+ <Setter Property="Icon" Value="AlertCircleOutline"></Setter>
+ </DataTrigger>
+ <DataTrigger Binding="{Binding MessageType}" Value="Critical">
+ <Setter Property="Icon" Value="Alert"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/GlobalStatus/machine-off.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/GlobalStatus/machine-off.png
new file mode 100644
index 000000000..6dc569e35
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/GlobalStatus/machine-off.png
Binary files differ
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj
index 0f088e9dd..786eca0c9 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj
@@ -393,6 +393,7 @@
<Link>Tango.ColorLib.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Resource Include="Images\GlobalStatus\machine-off.png" />
<Resource Include="Images\machine-update-firmware.png" />
<Resource Include="Images\chip_128px.png" />
<Resource Include="Images\warning-red.png" />
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml
index 076cd09e4..98451dacb 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml
@@ -105,6 +105,9 @@
<Style TargetType="Image">
<Setter Property="Source" Value="/Images/GlobalStatus/standby.png"></Setter>
<Style.Triggers>
+ <DataTrigger Binding="{Binding MachineProvider.MachineOperator.Status}" Value="{x:Static operations:MachineStatuses.Disconnected}">
+ <Setter Property="Source" Value="/Images/GlobalStatus/machine-off.png"></Setter>
+ </DataTrigger>
<DataTrigger Binding="{Binding MachineProvider.MachineOperator.Status}" Value="{x:Static operations:MachineStatuses.Standby}">
<Setter Property="Source" Value="/Images/GlobalStatus/standby.png"></Setter>
</DataTrigger>
diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
index 3ef0808c4..56a2877b1 100644
--- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
+++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
@@ -488,7 +488,7 @@ namespace Tango.Emulations.Emulators
Transporter.SendResponse<StartEventsNotificationResponse>(res, request.Container.Token);
- Thread.Sleep(100);
+ Thread.Sleep(1000);
}
});
}
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
index 64e8d87c5..080fc6cd8 100644
--- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
+++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
@@ -649,6 +649,7 @@ namespace Tango.Integration.Operation
{
_diagnosticsSent = false;
_debugSent = false;
+ Status = MachineStatuses.Disconnected;
}
}
@@ -668,7 +669,7 @@ namespace Tango.Integration.Operation
var response = await SendRequest<DisconnectRequest, DisconnectResponse>(request);
LogResponseReceived(response.Message);
- Status = MachineStatuses.Standby;
+ Status = MachineStatuses.Disconnected;
}
catch (Exception ex)
{
@@ -690,6 +691,8 @@ namespace Tango.Integration.Operation
/// <returns></returns>
public async override Task Connect()
{
+ var keep_alive = UseKeepAlive;
+ UseKeepAlive = false;
await base.Connect();
if (State == TransportComponentState.Connected)
@@ -721,6 +724,10 @@ namespace Tango.Integration.Operation
await base.Disconnect();
throw ex;
}
+ finally
+ {
+ UseKeepAlive = keep_alive;
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineStatuses.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineStatuses.cs
index 3850ba769..6e5b51891 100644
--- a/Software/Visual_Studio/Tango.Integration/Operation/MachineStatuses.cs
+++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineStatuses.cs
@@ -9,6 +9,8 @@ namespace Tango.Integration.Operation
{
public enum MachineStatuses
{
+ [Description("Disconnected")]
+ Disconnected,
[Description("Standby")]
Standby,
[Description("Ready To Dye")]
diff --git a/Software/Visual_Studio/Tango.Transport/TransportMessage.cs b/Software/Visual_Studio/Tango.Transport/TransportMessage.cs
index 81c7bc6a0..18f130d7b 100644
--- a/Software/Visual_Studio/Tango.Transport/TransportMessage.cs
+++ b/Software/Visual_Studio/Tango.Transport/TransportMessage.cs
@@ -48,47 +48,50 @@ namespace Tango.Transport
{
Completed = completed;
- if (!IsContinuous)
+ Task.Factory.StartNew(() =>
{
- if (!_completionSource.Task.IsCompleted)
+ if (!IsContinuous)
{
- if (_completionSource.GetType() == typeof(TaskCompletionSource<IMessage>))
+ if (!_completionSource.Task.IsCompleted)
{
- _completionSource.SetResult((T)result.GetType().GetProperty("Message").GetValue(result));
+ if (_completionSource.GetType() == typeof(TaskCompletionSource<IMessage>))
+ {
+ _completionSource.SetResult((T)result.GetType().GetProperty("Message").GetValue(result));
+ }
+ else if (_completionSource.GetType() == typeof(TaskCompletionSource<MessageContainer>))
+ {
+ _completionSource.SetResult((T)result.GetType().GetProperty("Container").GetValue(result));
+ }
+ else
+ {
+ _completionSource.SetResult((T)result);
+ }
}
- else if (_completionSource.GetType() == typeof(TaskCompletionSource<MessageContainer>))
+ }
+ else
+ {
+ LastResponseTime = DateTime.Now;
+ AtLeastOneResponseReceived = true;
+
+ if (ContinuesResponseSubject.GetType() == typeof(Subject<IMessage>))
{
- _completionSource.SetResult((T)result.GetType().GetProperty("Container").GetValue(result));
+ ContinuesResponseSubject.OnNext((T)result.GetType().GetProperty("Message").GetValue(result));
+ }
+ else if (ContinuesResponseSubject.GetType() == typeof(Subject<MessageContainer>))
+ {
+ ContinuesResponseSubject.OnNext((T)result.GetType().GetProperty("Container").GetValue(result));
}
else
{
- _completionSource.SetResult((T)result);
+ ContinuesResponseSubject.OnNext((T)result);
}
- }
- }
- else
- {
- LastResponseTime = DateTime.Now;
- AtLeastOneResponseReceived = true;
- if (ContinuesResponseSubject.GetType() == typeof(Subject<IMessage>))
- {
- ContinuesResponseSubject.OnNext((T)result.GetType().GetProperty("Message").GetValue(result));
- }
- else if (ContinuesResponseSubject.GetType() == typeof(Subject<MessageContainer>))
- {
- ContinuesResponseSubject.OnNext((T)result.GetType().GetProperty("Container").GetValue(result));
- }
- else
- {
- ContinuesResponseSubject.OnNext((T)result);
- }
-
- if (completed)
- {
- ContinuesResponseSubject.OnCompleted();
+ if (completed)
+ {
+ ContinuesResponseSubject.OnCompleted();
+ }
}
- }
+ });
}
/// <summary>
@@ -99,18 +102,21 @@ namespace Tango.Transport
{
Completed = true;
- if (!IsContinuous)
+ Task.Factory.StartNew(() =>
{
- if (!_completionSource.Task.IsCompleted)
+ if (!IsContinuous)
{
- _completionSource.SetException(ex);
+ if (!_completionSource.Task.IsCompleted)
+ {
+ _completionSource.SetException(ex);
+ }
}
- }
- else
- {
- AtLeastOneResponseReceived = true;
- ContinuesResponseSubject.OnError(ex);
- }
+ else
+ {
+ AtLeastOneResponseReceived = true;
+ ContinuesResponseSubject.OnError(ex);
+ }
+ });
}
}
}
diff --git a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
index ed57e5014..35f60f76c 100644
--- a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
+++ b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
@@ -222,10 +222,10 @@ namespace Tango.Transport
/// <param name="ex">The ex.</param>
protected virtual void OnFailed(Exception ex)
{
- Disconnect().Wait();
FailedStateException = ex;
State = TransportComponentState.Failed;
LogManager.Log(ex, "Transporter failed.");
+ Disconnect().Wait();
}
/// <summary>
@@ -312,6 +312,15 @@ namespace Tango.Transport
public virtual async Task Disconnect()
{
State = TransportComponentState.Disconnected;
+
+ try
+ {
+ _pullThread.Abort();
+ _pushThread.Abort();
+ _keepAliveThread.Abort();
+ }
+ catch { }
+
if (Adapter != null)
{
await Adapter.Disconnect();
@@ -895,6 +904,10 @@ namespace Tango.Transport
}
}
}
+ catch (ThreadAbortException)
+ {
+ LogManager.Log("Push thread has been aborted.");
+ }
catch (Exception ex)
{
OnFailed(ex);
@@ -1046,6 +1059,10 @@ namespace Tango.Transport
}
}
}
+ catch (ThreadAbortException)
+ {
+ LogManager.Log("Pull thread has been aborted.");
+ }
catch (Exception ex)
{
OnFailed(ex);
@@ -1061,40 +1078,47 @@ namespace Tango.Transport
/// </summary>
private void KeepAliveThreadMethod()
{
- while (State == TransportComponentState.Connected)
+ try
{
- try
- {
- Thread.Sleep(2000);
+ Thread.Sleep(2000);
- if (UseKeepAlive)
- {
- var task = SendRequest<KeepAliveRequest, KeepAliveResponse>(new KeepAliveRequest(), TimeSpan.FromSeconds(2));
- task.Wait();
- var response = task.Result;
- }
- }
- catch (Exception ex) when (ex is TimeoutException || ex is AggregateException)
+ while (State == TransportComponentState.Connected)
{
- if (State != TransportComponentState.Connected) return;
-
- if (UseKeepAlive)
+ try
{
- OnFailed(new KeepAliveException("The transporter has not received a KeepAlive response within the given time."));
- return;
+ Thread.Sleep(2000);
+
+ if (UseKeepAlive)
+ {
+ var response = SendRequest<KeepAliveRequest, KeepAliveResponse>(new KeepAliveRequest(), TimeSpan.FromSeconds(2)).Result;
+ }
}
- }
- catch (Exception ex)
- {
- if (State != TransportComponentState.Connected) return;
+ catch (Exception ex) when (ex is TimeoutException || ex is AggregateException)
+ {
+ if (State != TransportComponentState.Connected) return;
- if (UseKeepAlive)
+ if (UseKeepAlive)
+ {
+ OnFailed(new KeepAliveException("The transporter has not received a KeepAlive response within the given time."));
+ return;
+ }
+ }
+ catch (Exception ex)
{
- OnFailed(ex);
- return;
+ if (State != TransportComponentState.Connected) return;
+
+ if (UseKeepAlive)
+ {
+ OnFailed(ex);
+ return;
+ }
}
}
}
+ catch (ThreadAbortException)
+ {
+ LogManager.Log("KeepAlive thread has been aborted.");
+ }
}
#endregion