diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-01-27 00:51:16 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-01-27 00:51:16 +0200 |
| commit | bf2f3245339b9fd9148a2ad25b5ba3320e970cc1 (patch) | |
| tree | cb6cc6d0aec317e4f9727aa4294edf65ccc21a85 /Software/Visual_Studio/Tango.Integration/ExternalBridge | |
| parent | 85aef997b7aeedd617da9f195903ed43f94fbed7 (diff) | |
| download | Tango-bf2f3245339b9fd9148a2ad25b5ba3320e970cc1.tar.gz Tango-bf2f3245339b9fd9148a2ad25b5ba3320e970cc1.zip | |
Added TCP write mode setting to MS settings.
Added External Bridge TCP and SignalR settings to advanced settings on PPC.
Added FailsWithAdapter to ExternalBridgeReceiver.
Added TCP write mode to ExternalBridgeService.
Added some error handling on ExternalBridgeService SignalR.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/ExternalBridge')
4 files changed, 60 insertions, 23 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs index 2ca1b08f2..80b16f4d9 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs @@ -85,7 +85,9 @@ namespace Tango.Integration.ExternalBridge public ExternalBridgeReceiver(IMachineOperator machineOperator) { - ComponentName = "External Bridge Receiver"; + ComponentName = $"External Bridge Receiver {_component_counter++}"; + + FailsWithAdapter = true; _machineOperator = machineOperator; diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index 335150491..a9f243812 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -60,6 +60,11 @@ namespace Tango.Integration.ExternalBridge #region Properties /// <summary> + /// Gets or sets the TCP transport adapter write mode when creating a TCP receiver. + /// </summary> + public TcpTransportAdapterWriteMode TcpTransportAdapterWriteMode { get; set; } + + /// <summary> /// Gets or sets the SignalR configuration. /// </summary> public ExternalBridgeSignalRConfiguration SignalRConfiguration { get; set; } @@ -145,6 +150,8 @@ namespace Tango.Integration.ExternalBridge { SignalRConfiguration = new ExternalBridgeSignalRConfiguration(); + TcpTransportAdapterWriteMode = TcpTransportAdapterWriteMode.Interval; + _receivers = new List<ExternalBridgeReceiver>(); var settings = SettingsManager.Default.GetOrCreate<IntegrationSettings>(); @@ -224,6 +231,7 @@ namespace Tango.Integration.ExternalBridge { LogManager.Log("External bridge TCP client connected from: " + e.Socket.GetIPAddress()); ExternalBridgeReceiver receiver = new ExternalBridgeReceiver(e.Socket, MachineOperator); + (receiver.Adapter as TcpTransportAdapter).WriteMode = TcpTransportAdapterWriteMode; receiver.LoginRequest += Receiver_LoginRequest; receiver.ColorProfileRequest += Receiver_ColorProfileRequest; receiver.Disconnected += Receiver_Disconnected; @@ -233,17 +241,23 @@ namespace Tango.Integration.ExternalBridge private async void OnSignalRSessionCreated(String sessionID) { - LogManager.Log("External bridge SignalR client connected."); + try + { + LogManager.Log("External bridge SignalR client connected."); - var adapter = new SignalRTransportAdapter(SignalRConfiguration.Address, SignalRConfiguration.Hub, SignalRTransportAdapterMode.JoinSession, Machine.SerialNumber, sessionID); ; + var adapter = new SignalRTransportAdapter(SignalRConfiguration.Address, SignalRConfiguration.Hub, SignalRTransportAdapterMode.JoinSession, Machine.SerialNumber, sessionID); ; - ExternalBridgeReceiver receiver = new ExternalBridgeReceiver(adapter, MachineOperator); - receiver.LoginRequest += Receiver_LoginRequest; - receiver.ColorProfileRequest += Receiver_ColorProfileRequest; - receiver.Disconnected += Receiver_Disconnected; - _receivers.Add(receiver); - await receiver.Connect(); - //await _proxy.Invoke("NotifySessionCreated"); + ExternalBridgeReceiver receiver = new ExternalBridgeReceiver(adapter, MachineOperator); + receiver.LoginRequest += Receiver_LoginRequest; + receiver.ColorProfileRequest += Receiver_ColorProfileRequest; + receiver.Disconnected += Receiver_Disconnected; + _receivers.Add(receiver); + await receiver.Connect(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error initializing SignalR ExternalBridgeReceiver when session created."); + } } private void MachineOperator_StatusChanged(object sender, MachineStatuses status) @@ -367,21 +381,35 @@ namespace Tango.Integration.ExternalBridge if (SignalRConfiguration.Enabled) { - _connection = new HubConnection(SignalRConfiguration.Address); - _proxy = _connection.CreateHubProxy(SignalRConfiguration.Hub); - _proxy.On<String>("OnSessionCreated", OnSignalRSessionCreated); - _connection.Start(); - _connection.StateChanged += (x) => + try { - if (x.NewState == ConnectionState.Connected) + _connection = new HubConnection(SignalRConfiguration.Address); + _proxy = _connection.CreateHubProxy(SignalRConfiguration.Hub); + _proxy.On<String>("OnSessionCreated", OnSignalRSessionCreated); + _connection.Start(); + _connection.StateChanged += (x) => { - _proxy.Invoke("RegisterMachine", new MachineInfo() + if (x.NewState == ConnectionState.Connected) { - SerialNumber = Machine.SerialNumber, - Organization = Machine.Organization.Name, - }); - } - }; + try + { + _proxy.Invoke("RegisterMachine", new MachineInfo() + { + SerialNumber = Machine.SerialNumber, + Organization = Machine.Organization.Name, + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error registering machine via SignalR."); + } + } + }; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error initializing ExternalBridge SignalR."); + } } IsStarted = true; diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs index df6a4cc01..64220f231 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs @@ -96,7 +96,6 @@ namespace Tango.Integration.ExternalBridge { try { - Adapter = new TcpTransportAdapter(IPAddress, SettingsManager.Default.GetOrCreate<IntegrationSettings>().ExternalBridgeServicePort); await Adapter.Connect(); State = TransportComponentState.Connected; @@ -246,6 +245,8 @@ namespace Tango.Integration.ExternalBridge KeepAliveRetries = 2; UseKeepAlive = false; EnableDiagnostics = true; + + Adapter = new TcpTransportAdapter(IPAddress, SettingsManager.Default.GetOrCreate<IntegrationSettings>().ExternalBridgeServicePort); } /// <summary> diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/IExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/IExternalBridgeService.cs index d2b5ef750..7ae09c11d 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/IExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/IExternalBridgeService.cs @@ -7,6 +7,7 @@ using Tango.BL.Entities; using Tango.Integration.Operation; using Tango.PMR.Integration; using Tango.Transport; +using Tango.Transport.Adapters; using Tango.Transport.Transporters; namespace Tango.Integration.ExternalBridge @@ -49,6 +50,11 @@ namespace Tango.Integration.ExternalBridge ExternalBridgeReceiver FullControlSessionReceiver { get; } /// <summary> + /// Gets or sets the TCP transport adapter write mode when creating a TCP receiver. + /// </summary> + TcpTransportAdapterWriteMode TcpTransportAdapterWriteMode { get; set; } + + /// <summary> /// Gets a value indicating whether this instance is started. /// </summary> bool IsStarted { get; } |
