diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-26 08:41:04 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-26 08:41:04 +0200 |
| commit | 7594cea7dc1b3fef5be77fa06c71a954d024723d (patch) | |
| tree | e70e25ef61e938b8c20c1bcdbad164441a3b8542 /Software/Visual_Studio | |
| parent | d6a9f6a9ca9346bdf048c62d810667852bb80d1c (diff) | |
| download | Tango-7594cea7dc1b3fef5be77fa06c71a954d024723d.tar.gz Tango-7594cea7dc1b3fef5be77fa06c71a954d024723d.zip | |
Added support for public IP address on SignalR connection.
Fixed issue with ExternalBridgeScanner.
Added Connection Time.
Diffstat (limited to 'Software/Visual_Studio')
10 files changed, 101 insertions, 22 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/Connection/IMachineProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/Connection/IMachineProvider.cs index be4748617..8055f7177 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/Connection/IMachineProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/Connection/IMachineProvider.cs @@ -36,6 +36,11 @@ namespace Tango.FSE.Common.Connection bool IsConnected { get; } /// <summary> + /// Gets the connection time span. + /// </summary> + TimeSpan ConnectionTime { get; } + + /// <summary> /// Gets a value indicating whether this instance is busy connecting/disconnecting. /// </summary> bool IsBusy { get; } diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Connection/DefaultMachineProvider.cs index c97837fcf..25c2d31a9 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Connection/DefaultMachineProvider.cs @@ -25,9 +25,6 @@ namespace Tango.FSE.UI.Connection { public class DefaultMachineProvider : ExtendedObject, IMachineProvider { - private List<EventRegistration> _eventRegistrations; - private String _lastMachineSerialNumber; - private class EventRegistration { public Delegate Handler { get; set; } @@ -58,6 +55,11 @@ namespace Tango.FSE.UI.Connection } } + private List<EventRegistration> _eventRegistrations; + private String _lastMachineSerialNumber; + private DateTime _connectionStartTime; + private System.Timers.Timer _connectionTimer; + /// <summary> /// Occurs when machine operator has connected. /// </summary> @@ -97,6 +99,16 @@ namespace Tango.FSE.UI.Connection private set { _isConnected = value; RaisePropertyChangedAuto(); } } + private TimeSpan _connectionTime; + /// <summary> + /// Gets the connection time span. + /// </summary> + public TimeSpan ConnectionTime + { + get { return _connectionTime; } + set { _connectionTime = value; RaisePropertyChangedAuto(); } + } + private bool _isBusy; /// <summary> /// Gets a value indicating whether this instance is busy connecting/disconnecting. @@ -125,6 +137,10 @@ namespace Tango.FSE.UI.Connection MachineOperator = new ExternalBridgeTcpClient("N/A", "N/A"); MachineOperator.StateChanged += MachineOperator_StateChanged; MachineOperator.As<ExternalBridgeTcpClient>().SessionClosed += DefaultMachineProvider_SessionClosed; + + _connectionTimer = new System.Timers.Timer(1000); + _connectionTimer.Elapsed += _connectionTimer_Elapsed; + _connectionTimer.Start(); } /// <summary> @@ -352,10 +368,13 @@ namespace Tango.FSE.UI.Connection }); _lastMachineSerialNumber = machineOperator.SerialNumber; + _connectionStartTime = DateTime.Now; } protected virtual void OnMachineDisconnected(IExternalBridgeClient machineOperator, Exception exception) { + LogManager.Log($"Machine disconnected. Total connection time: {DateTime.Now - _connectionStartTime}."); + MachineDisconnected?.Invoke(this, new MachineDisconnectedEventArgs() { MachineOperator = machineOperator, @@ -363,6 +382,14 @@ namespace Tango.FSE.UI.Connection }); } + private void _connectionTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + if (IsConnected) + { + ConnectionTime = DateTime.Now - _connectionStartTime; + } + } + /// <summary> /// Reassigns the event handlers from the previous connected machine to a new one. /// </summary> diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/ConnectedMachinePane.xaml b/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/ConnectedMachinePane.xaml index 5f4bdf547..0e01ab255 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/ConnectedMachinePane.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/ConnectedMachinePane.xaml @@ -48,9 +48,7 @@ <Rectangle Stroke="{StaticResource FSE_BorderBrush}" StrokeThickness="1" Margin="0 2 0 0" /> <controls:TableGrid RowHeight="22" TextElement.FontSize="{StaticResource FSE_SmallFontSize}"> - <TextBlock FontWeight="SemiBold" Text="Address:" /> - <TextBlock Text="{Binding MachineProvider.MachineOperator.Adapter.Address}" /> - <TextBlock FontWeight="SemiBold" Text="Embedded Software Version:" /> + <TextBlock FontWeight="SemiBold" Text="Firmware Version:" /> <TextBlock Text="{Binding MachineProvider.MachineOperator.DeviceInformation.Version}" /> <TextBlock FontWeight="SemiBold">FPGA Version 1:</TextBlock> <TextBlock TextTrimming="CharacterEllipsis" Text="{Binding MachineProvider.MachineOperator.DeviceInformation.FPGA1Version}"></TextBlock> @@ -66,6 +64,10 @@ <Rectangle Stroke="{StaticResource FSE_BorderBrush}" StrokeThickness="1" Margin="0 2 0 0" /> <controls:TableGrid RowHeight="22" TextElement.FontSize="{StaticResource FSE_SmallFontSize}"> + <TextBlock FontWeight="SemiBold" Text="Address:" /> + <TextBlock Text="{Binding MachineProvider.MachineOperator.Adapter.Address}" /> + <TextBlock FontWeight="SemiBold" Text="Connection Time:" /> + <TextBlock Text="{Binding MachineProvider.ConnectionTime,Mode=OneWay,StringFormat=hh\\:mm\\:ss}" /> <TextBlock FontWeight="SemiBold" Text="Total Bytes Sent:" /> <TextBlock Text="{Binding MachineProvider.MachineOperator.Adapter.TotalBytesSent,Converter={StaticResource ByteArrayToFileSizeConverter},Mode=OneWay}" /> <TextBlock FontWeight="SemiBold" Text="Total Bytes Received:" /> diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPane.xaml b/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPane.xaml index 2f0ca8ae8..00b7574cb 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPane.xaml +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPane.xaml @@ -105,7 +105,7 @@ <Run FontWeight="Bold">S/N:</Run> <Run Text="{Binding SerialNumber,Mode=OneWay}"></Run> </TextBlock> <TextBlock FontSize="{StaticResource FSE_SmallFontSize}"> - <Run FontWeight="Bold">Hub:</Run> <Run Text="{Binding IPAddress,Mode=OneWay}"></Run> + <Run FontWeight="Bold">Address:</Run> <Run Text="{Binding IPAddress,Mode=OneWay}"></Run> </TextBlock> <TextBlock FontSize="{StaticResource FSE_SmallFontSize}"> <Run FontWeight="Bold">Organization:</Run> <Run Text="{Binding Machine.Organization.Name,Mode=OneWay}"></Run> diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs index 21767174f..160555550 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs @@ -135,7 +135,7 @@ namespace Tango.Integration.ExternalBridge bool signalRStarted = false; - _connection.StateChanged += (x) => + _connection.StateChanged += (x) => { if (x.NewState == ConnectionState.Connected) { @@ -298,11 +298,11 @@ namespace Tango.Integration.ExternalBridge if (knownMachine == null) { - newMachine = new ExternalBridgeSignalRClient(SignalRConfiguration.Address, SignalRConfiguration.Hub, machine.SerialNumber); + newMachine = new ExternalBridgeSignalRClient(SignalRConfiguration.Address, SignalRConfiguration.Hub, machine); } else { - newMachine = new ExternalBridgeSignalRClient(SignalRConfiguration.Address, SignalRConfiguration.Hub, knownMachine); + newMachine = new ExternalBridgeSignalRClient(SignalRConfiguration.Address, SignalRConfiguration.Hub, knownMachine,machine); } ThreadsHelper.InvokeUINow(() => diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeSignalRClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeSignalRClient.cs index 1596d2c9b..343fb302f 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeSignalRClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeSignalRClient.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Tango.BL; using Tango.BL.Entities; +using Tango.Integration.ExternalBridge.Web; using Tango.Integration.Operation; using Tango.PMR.Integration; using Tango.Settings; @@ -16,28 +17,28 @@ namespace Tango.Integration.ExternalBridge { public class ExternalBridgeSignalRClient : ExternalBridgeTcpClient { - public ExternalBridgeSignalRClient(String url, String hub, String serialNumber) + public ExternalBridgeSignalRClient(String url, String hub, MachineInfo machineInfo) { ComponentName = $"External Bridge SignalR Client {_component_counter++}"; - SerialNumber = serialNumber; - IPAddress = hub; - Machine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == serialNumber); - Adapter = new SignalRTransportAdapter(url, hub, SignalRTransportAdapterMode.CreateSession, serialNumber); + SerialNumber = machineInfo.SerialNumber; + IPAddress = machineInfo.IPAddress; + Machine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == SerialNumber); + Adapter = new SignalRTransportAdapter(url, hub, SignalRTransportAdapterMode.CreateSession, SerialNumber, null, IPAddress); KeepAliveTimeout = TimeSpan.FromSeconds(5); KeepAliveRetries = 2; UseKeepAlive = false; } - public ExternalBridgeSignalRClient(String url, String hub, Machine machine) + public ExternalBridgeSignalRClient(String url, String hub, Machine machine, MachineInfo machineInfo) { ComponentName = $"External Bridge SignalR Client {_component_counter++}"; SerialNumber = machine.SerialNumber; - IPAddress = hub; + IPAddress = machineInfo.IPAddress; Machine = machine; - Adapter = new SignalRTransportAdapter(url, hub, SignalRTransportAdapterMode.CreateSession, SerialNumber); + Adapter = new SignalRTransportAdapter(url, hub, SignalRTransportAdapterMode.CreateSession, SerialNumber, null, IPAddress); KeepAliveTimeout = TimeSpan.FromSeconds(5); KeepAliveRetries = 2; diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/Web/MachineInfo.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/Web/MachineInfo.cs index a7e3f90ca..a33d073d1 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/Web/MachineInfo.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/Web/MachineInfo.cs @@ -10,5 +10,11 @@ namespace Tango.Integration.ExternalBridge.Web { public String SerialNumber { get; set; } public String Organization { get; set; } + public String IPAddress { get; set; } + + public MachineInfo() + { + IPAddress = "Unknown"; + } } } diff --git a/Software/Visual_Studio/Tango.Transport/Adapters/SignalRTransportAdapter.cs b/Software/Visual_Studio/Tango.Transport/Adapters/SignalRTransportAdapter.cs index a8f272292..def4cd741 100644 --- a/Software/Visual_Studio/Tango.Transport/Adapters/SignalRTransportAdapter.cs +++ b/Software/Visual_Studio/Tango.Transport/Adapters/SignalRTransportAdapter.cs @@ -78,7 +78,7 @@ namespace Tango.Transport.Adapters /// <param name="mode">The adapter mode.</param> /// <param name="serialNumber">The machine serial number (when creating session).</param> /// <param name="sessionID">The session identifier (when joining session).</param> - public SignalRTransportAdapter(String url, String hub, SignalRTransportAdapterMode mode, String serialNumber = null, String sessionID = null) : this() + public SignalRTransportAdapter(String url, String hub, SignalRTransportAdapterMode mode, String serialNumber = null, String sessionID = null, String ipAddress = null) : this() { Url = url; Hub = hub; @@ -86,6 +86,11 @@ namespace Tango.Transport.Adapters SerialNumber = serialNumber; SessionID = sessionID; Address = sessionID; + + if (!String.IsNullOrWhiteSpace(ipAddress)) + { + Address = ipAddress; + } } /// <summary> @@ -184,7 +189,6 @@ namespace Tango.Transport.Adapters { LogManager.Log("Creating SignalR adapter Session..."); SessionID = await _proxy.Invoke<String>("CreateSession", SerialNumber); - Address = SessionID; } else { diff --git a/Software/Visual_Studio/Tango.Transport/TransportAdapterBase.cs b/Software/Visual_Studio/Tango.Transport/TransportAdapterBase.cs index 2696f5698..bdcf0ee64 100644 --- a/Software/Visual_Studio/Tango.Transport/TransportAdapterBase.cs +++ b/Software/Visual_Studio/Tango.Transport/TransportAdapterBase.cs @@ -77,10 +77,16 @@ namespace Tango.Transport protected set { _transferRate = value; RaisePropertyChanged(nameof(TransferRate)); } } + private String _address; /// <summary> /// Gets or sets the channel address. /// </summary> - public String Address { get; set; } + public String Address + { + get { return _address; } + set { _address = value; RaisePropertyChangedAuto(); } + } + private TransportComponentState _state; /// <summary> diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs b/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs index 4dd04d33e..9b7f734d2 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Hubs/ExternalBridgeHub.cs @@ -43,6 +43,8 @@ namespace Tango.MachineService.Hubs _externalBridges.RemoveAll(x => x.MachineInfo.SerialNumber == machineInfo.SerialNumber); _sessions.RemoveAll(x => x.ExternalBridge.ConnectionID == Context.ConnectionId); + machineInfo.IPAddress = GetIpAddress(); + _externalBridges.Add(new ExternalBridgeInfo() { MachineInfo = machineInfo, @@ -69,7 +71,7 @@ namespace Tango.MachineService.Hubs public String CreateSession(String serialNumber) { var externalBridge = _externalBridges.SingleOrDefault(x => x.MachineInfo.SerialNumber == serialNumber); - + if (externalBridge != null) { var existingSession = GetSession(); @@ -157,5 +159,31 @@ namespace Tango.MachineService.Hubs return null; } + + protected string GetIpAddress() + { + try + { + string ipAddress; + object tempObject; + + Context.Request.Environment.TryGetValue("server.RemoteIpAddress", out tempObject); + + if (tempObject != null) + { + ipAddress = (string)tempObject; + } + else + { + ipAddress = ""; + } + + return ipAddress; + } + catch + { + return String.Empty; + } + } } }
\ No newline at end of file |
