aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-01-08 18:19:37 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-01-08 18:19:37 +0200
commit3aa8d26fe59aeea616bda89ca325b9f9583fadc6 (patch)
tree064470fd7ba7d2186b257544a3d1675dc7f21b64 /Software/Visual_Studio
parentf95e70a118ed238bbdeea5b44c9be7e6cfb0b89c (diff)
downloadTango-3aa8d26fe59aeea616bda89ca325b9f9583fadc6.tar.gz
Tango-3aa8d26fe59aeea616bda89ca325b9f9583fadc6.zip
Added code comments for:
Integration. Refactored ExternalBridgeClient to: IExternalBridgeSecureClient. ExternalBridgeTcpClient. ExternalBridgeUsbClient. Refactored MachineConnectionView to use the new external bridge clients by data template "data type".
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs2
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs2
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs9
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml68
-rw-r--r--Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs4
-rw-r--r--Software/Visual_Studio/Tango.Emulations/IEmulator.cs2
-rw-r--r--Software/Visual_Studio/Tango.Integration/ExtensionMethods/IExternalBridgeClientExtensions.cs23
-rw-r--r--Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClient.cs110
-rw-r--r--Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClientType.cs15
-rw-r--r--Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs72
-rw-r--r--Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeTcpClient.cs111
-rw-r--r--Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeUsbClient.cs83
-rw-r--r--Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeClient.cs21
-rw-r--r--Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeSecureClient.cs22
-rw-r--r--Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj6
15 files changed, 334 insertions, 216 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs
index 3f8772f0e..5ea6e7aec 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/DirectSynchronizationViewVM.cs
@@ -150,7 +150,7 @@ namespace Tango.MachineStudio.Synchronization.ViewModels
private void Compare()
{
- if (SelectedMachine.SerialNumber != ApplicationManager.ConnectedMachine.SerialNumber)
+ if (SelectedMachine.SerialNumber != ApplicationManager.ConnectedMachine.As<ExternalBridgeTcpClient>().SerialNumber)
{
if (!_notification.ShowQuestion("The selected machine serial number does not match the connected machine. Are you sure you want to continue?"))
{
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs
index de8649c13..36b5074cb 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs
@@ -50,7 +50,7 @@ namespace Tango.MachineStudio.UI.StudioApplication
public bool IsMachineConnectedViaTCP
{
- get { return IsMachineConnected && ConnectedMachine.Type != ExternalBridgeClientType.USB; }
+ get { return IsMachineConnected && ConnectedMachine is ExternalBridgeTcpClient; }
}
private void ConnectedMachine_StateChanged(object sender, Transport.TransportComponentState e)
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
index b08c259af..ceb81a66f 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
@@ -7,6 +7,7 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
+using Tango.Integration.Services;
using Tango.Logging;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.Common.Authentication;
@@ -152,17 +153,17 @@ namespace Tango.MachineStudio.UI.ViewModels
}
}
- if (x.SelectedMachine.Type != Integration.Services.ExternalBridgeClientType.USB)
+ if (x.SelectedMachine.RequiresAuthentication)
{
_notificationProvider.ShowModalDialog<MachineLoginViewVM>(async (login) =>
{
- using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.SerialNumber + "..."))
+ using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.ToString() + "..."))
{
try
{
await x.SelectedMachine.Connect();
- var authenticated = await x.SelectedMachine.Authenticate(login.Password);
+ var authenticated = await x.SelectedMachine.As<IExternalBridgeSecureClient>().Authenticate(login.Password);
if (!authenticated)
{
_notificationProvider.ShowError("It seems like you are not authorized to access the selected machine.");
@@ -184,7 +185,7 @@ namespace Tango.MachineStudio.UI.ViewModels
}
else
{
- using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.Device + "..."))
+ using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "..."))
{
try
{
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml
index 4208c2878..ccab634db 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineConnectionView.xaml
@@ -5,6 +5,7 @@
xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:integration="clr-namespace:Tango.Integration.Services;assembly=Tango.Integration"
xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI"
xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views"
mc:Ignorable="d"
@@ -52,58 +53,37 @@
<Grid Grid.Row="1">
<ListBox ItemsSource="{Binding Scanner.AvailableMachines}" SelectedItem="{Binding SelectedMachine}" Margin="0 0 0 7" BorderThickness="1" BorderBrush="Gainsboro">
- <ListBox.ItemTemplate>
- <DataTemplate>
- <Grid>
- <StackPanel Orientation="Horizontal">
- <StackPanel.Style>
- <Style TargetType="StackPanel">
- <Setter Property="Visibility" Value="Visible"></Setter>
- <Style.Triggers>
- <DataTrigger Binding="{Binding Type}" Value="USB">
- <Setter Property="Visibility" Value="Collapsed"></Setter>
- </DataTrigger>
- </Style.Triggers>
- </Style>
- </StackPanel.Style>
- <Image Source="/Images/external-bridge-tcp.png" Width="38" Height="38" RenderOptions.BitmapScalingMode="Fant"></Image>
- <StackPanel Margin="10 0 0 0">
- <TextBlock FontSize="11">
+ <ListBox.Resources>
+ <DataTemplate DataType="{x:Type integration:ExternalBridgeTcpClient}">
+ <StackPanel Orientation="Horizontal">
+ <Image Source="/Images/external-bridge-tcp.png" Width="38" Height="38" RenderOptions.BitmapScalingMode="Fant"></Image>
+ <StackPanel Margin="10 0 0 0">
+ <TextBlock FontSize="11">
<Run FontWeight="Bold">S/N:</Run> <Run Text="{Binding SerialNumber,Mode=OneWay}"></Run>
- </TextBlock>
- <TextBlock FontSize="11">
+ </TextBlock>
+ <TextBlock FontSize="11">
<Run FontWeight="Bold">IP Address:</Run> <Run Text="{Binding IPAddress,Mode=OneWay}"></Run>
- </TextBlock>
- <TextBlock FontSize="11">
+ </TextBlock>
+ <TextBlock FontSize="11">
<Run FontWeight="Bold">Organization:</Run> <Run Text="{Binding Organization,Mode=OneWay}"></Run>
- </TextBlock>
- </StackPanel>
+ </TextBlock>
</StackPanel>
-
- <StackPanel Orientation="Horizontal">
- <StackPanel.Style>
- <Style TargetType="StackPanel">
- <Setter Property="Visibility" Value="Collapsed"></Setter>
- <Style.Triggers>
- <DataTrigger Binding="{Binding Type}" Value="USB">
- <Setter Property="Visibility" Value="Visible"></Setter>
- </DataTrigger>
- </Style.Triggers>
- </Style>
- </StackPanel.Style>
- <Image Source="/Images/external-bridge-usb.png" Width="38" Height="38" RenderOptions.BitmapScalingMode="Fant"></Image>
- <StackPanel Margin="10 0 0 0">
- <TextBlock FontSize="11">
+ </StackPanel>
+ </DataTemplate>
+ <DataTemplate DataType="{x:Type integration:ExternalBridgeUsbClient}">
+ <StackPanel Orientation="Horizontal">
+ <Image Source="/Images/external-bridge-usb.png" Width="38" Height="38" RenderOptions.BitmapScalingMode="Fant"></Image>
+ <StackPanel Margin="10 0 0 0">
+ <TextBlock FontSize="11">
<Run FontWeight="Bold">Port:</Run> <Run Text="{Binding ComPort,Mode=OneWay}"></Run>
- </TextBlock>
- <TextBlock FontSize="11">
+ </TextBlock>
+ <TextBlock FontSize="11">
<Run FontWeight="Bold">Device:</Run> <Run Text="{Binding Device,Mode=OneWay}"></Run>
- </TextBlock>
- </StackPanel>
+ </TextBlock>
</StackPanel>
- </Grid>
+ </StackPanel>
</DataTemplate>
- </ListBox.ItemTemplate>
+ </ListBox.Resources>
</ListBox>
<mahapps:MetroProgressBar VerticalAlignment="Bottom" Height="1" IsIndeterminate="True"></mahapps:MetroProgressBar>
diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
index 59de23f82..049edfb7f 100644
--- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
+++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs
@@ -17,6 +17,10 @@ using Tango.PMR.Integration;
namespace Tango.Emulations.Emulators
{
+ /// <summary>
+ /// Represents a Tango machine emulator.
+ /// </summary>
+ /// <seealso cref="Tango.Emulations.EmulatorBase" />
public class MachineEmulator : EmulatorBase
{
#region Constructors
diff --git a/Software/Visual_Studio/Tango.Emulations/IEmulator.cs b/Software/Visual_Studio/Tango.Emulations/IEmulator.cs
index 9345c530d..5546bae82 100644
--- a/Software/Visual_Studio/Tango.Emulations/IEmulator.cs
+++ b/Software/Visual_Studio/Tango.Emulations/IEmulator.cs
@@ -16,7 +16,7 @@ namespace Tango.Emulations
Task Stop();
/// <summary>
- /// Starts this instance.
+ /// Starts this emulator.
/// </summary>
Task Start();
diff --git a/Software/Visual_Studio/Tango.Integration/ExtensionMethods/IExternalBridgeClientExtensions.cs b/Software/Visual_Studio/Tango.Integration/ExtensionMethods/IExternalBridgeClientExtensions.cs
new file mode 100644
index 000000000..62a7c1523
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Integration/ExtensionMethods/IExternalBridgeClientExtensions.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Integration.Services;
+
+/// <summary>
+/// Contains <see cref="IExternalBridgeClient"/> extension methods.
+/// </summary>
+public static class IExternalBridgeClientExtensions
+{
+ /// <summary>
+ /// Casts the external bridge client to the specified type T.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="client">The client.</param>
+ /// <returns></returns>
+ public static T As<T>(this IExternalBridgeClient client) where T : IExternalBridgeClient
+ {
+ return (T)client;
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClient.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClient.cs
deleted file mode 100644
index 213ad7cb6..000000000
--- a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClient.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.DAL.Observables;
-using Tango.PMR.Integration;
-using Tango.Settings;
-using Tango.Transport;
-using Tango.Transport.Adapters;
-using Tango.Transport.Transporters;
-
-namespace Tango.Integration.Services
-{
- public class ExternalBridgeClient : BasicTransporter, IExternalBridgeClient
- {
- private String _serialNumber;
-
- public String SerialNumber
- {
- get { return _serialNumber; }
- internal set
- {
- _serialNumber = value;
- RaisePropertyChangedAuto();
-
- var org = ObservablesEntitiesAdapter.Instance.Organizations.SingleOrDefault(x => x.Machines.ToList().Exists(y => y.SerialNumber == SerialNumber));
- Organization = org != null ? org.Name : "Unknown";
- }
- }
-
- private String _ipAddress;
-
- public String IPAddress
- {
- get { return _ipAddress; }
- set { _ipAddress = value; RaisePropertyChangedAuto(); }
- }
-
- private String _comPort;
-
- public String ComPort
- {
- get { return _comPort; }
- set { _comPort = value; RaisePropertyChangedAuto(); }
- }
-
- private String _Device;
-
- public String Device
- {
- get { return _Device; }
- set { _Device = value; RaisePropertyChangedAuto(); }
- }
-
- private String _organization;
-
- public String Organization
- {
- get { return _organization; }
- private set { _organization = value; RaisePropertyChangedAuto(); }
- }
-
- private ExternalBridgeClientType _type;
-
- public ExternalBridgeClientType Type
- {
- get { return _type; }
- internal set { _type = value; RaisePropertyChangedAuto(); }
- }
-
-
- public override async Task Connect()
- {
- await Disconnect();
-
- if (Type == ExternalBridgeClientType.TCP)
- {
- Adapter = new TcpTransportAdapter(IPAddress, SettingsManager.Default.Integration.ExternalBridgeServicePort);
- }
- else if (Type == ExternalBridgeClientType.USB)
- {
- Adapter = new UsbTransportAdapter(ComPort);
- }
- await base.Connect();
- }
-
- public async Task<bool> Authenticate(String password)
- {
- var response = await SendRequest<ExternalClientLoginRequest, ExternalClientLoginResponse>(new ExternalClientLoginRequest() { Password = password });
- return response.Message.Authenticated;
- }
-
- public ExternalBridgeClient(String serialNumber, String ipAddress)
- {
- SerialNumber = serialNumber;
- IPAddress = ipAddress;
- UseKeepAlive = true;
- Type = ExternalBridgeClientType.TCP;
- }
-
- public ExternalBridgeClient(String comPort, String device, String putNull)
- {
- ComPort = comPort;
- Device = device;
- UseKeepAlive = false;
- Type = ExternalBridgeClientType.USB;
- }
- }
-}
diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClientType.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClientType.cs
deleted file mode 100644
index af58414ec..000000000
--- a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClientType.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Tango.Integration.Services
-{
- public enum ExternalBridgeClientType
- {
- TCP,
- USB,
- BT,
- }
-}
diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs
index bd4bce3d7..e4fec580a 100644
--- a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs
+++ b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs
@@ -21,14 +21,18 @@ using Tango.Transport.Adapters;
namespace Tango.Integration.Services
{
+ /// <summary>
+ /// Scans for available machines on the local area network and physically connected via USB.
+ /// </summary>
+ /// <seealso cref="Tango.Core.ExtendedObject" />
public class ExternalBridgeScanner : ExtendedObject
{
- private Thread _discoveryThread;
- private Thread _usbThread;
+ private Thread _tcpDiscoveryThread;
+ private Thread _usbDiscoveryThread;
private ObservableCollection<IExternalBridgeClient> _availableMachines;
/// <summary>
- /// Gets or sets the available services.
+ /// Gets the available machines.
/// </summary>
public ObservableCollection<IExternalBridgeClient> AvailableMachines
{
@@ -55,23 +59,40 @@ namespace Tango.Integration.Services
}
/// <summary>
- /// Starts this instance.
+ /// Start scanning. (Results will be available through <see cref="AvailableMachines"/>).
/// </summary>
public void Start()
{
if (!IsStarted)
{
- _discoveryThread = new Thread(DiscoveryThreadMethod);
- _discoveryThread.IsBackground = true;
- _discoveryThread.Start();
+ LogManager.Log("External bridge scanner started...");
- _usbThread = new Thread(UsbThreadMethod);
- _usbThread.IsBackground = true;
- _usbThread.Start();
+ _tcpDiscoveryThread = new Thread(TcpDiscoveryThreadMethod);
+ _tcpDiscoveryThread.IsBackground = true;
+ _tcpDiscoveryThread.Start();
+
+ _usbDiscoveryThread = new Thread(UsbDiscoveryThreadMethod);
+ _usbDiscoveryThread.IsBackground = true;
+ _usbDiscoveryThread.Start();
}
}
- private void UsbThreadMethod()
+ /// <summary>
+ /// Stops this instance.
+ /// </summary>
+ public void Stop()
+ {
+ if (IsStarted)
+ {
+ IsStarted = false;
+ LogManager.Log("External bridge scanner stopped.");
+ }
+ }
+
+ /// <summary>
+ /// USB discovery thread method.
+ /// </summary>
+ private void UsbDiscoveryThreadMethod()
{
while (!IsStarted)
{
@@ -86,11 +107,12 @@ namespace Tango.Integration.Services
foreach (var device in devices.Where(x => x.Value.Contains(SettingsManager.Default.Integration.EmbeddedDeviceName)))
{
- if (!AvailableMachines.ToList().Exists(x => x.ComPort == device.Key))
+ if (!AvailableMachines.OfType<ExternalBridgeUsbClient>().ToList().Exists(x => x.ComPort == device.Key))
{
+ LogManager.Log("Found a new machine via USB " + device.Value);
ThreadsHelper.InvokeUINow(() =>
{
- AvailableMachines.Add(new ExternalBridgeClient(device.Key, device.Value, null));
+ AvailableMachines.Add(new ExternalBridgeUsbClient(device.Key, device.Value));
});
}
}
@@ -100,7 +122,10 @@ namespace Tango.Integration.Services
}
}
- private void DiscoveryThreadMethod()
+ /// <summary>
+ /// TCP discovery thread method.
+ /// </summary>
+ private void TcpDiscoveryThreadMethod()
{
var Server = new UdpClient(SettingsManager.Default.Integration.ExternalBridgeServiceDiscoveryPort);
@@ -111,9 +136,11 @@ namespace Tango.Integration.Services
ExternalBridgeUdpDiscoveryPacket packet = ExternalBridgeUdpDiscoveryPacket.Parser.ParseFrom(ClientRequestData);
- if (!AvailableMachines.ToList().Exists(x => x.SerialNumber == packet.SerialNumber))
+ if (!AvailableMachines.OfType<ExternalBridgeTcpClient>().ToList().Exists(x => x.SerialNumber == packet.SerialNumber))
{
- ExternalBridgeClient newMachine = new ExternalBridgeClient(packet.SerialNumber, ClientEp.Address.ToString());
+ ExternalBridgeTcpClient newMachine = new ExternalBridgeTcpClient(packet.SerialNumber, ClientEp.Address.ToString());
+
+ LogManager.Log("Found a new machine via TCP " + newMachine.SerialNumber);
ThreadsHelper.InvokeUINow(() =>
{
@@ -128,20 +155,15 @@ namespace Tango.Integration.Services
}
/// <summary>
- /// Stops this instance.
+ /// Handles the available machines component state changed event.
/// </summary>
- public void Stop()
- {
- if (IsStarted)
- {
- IsStarted = false;
- }
- }
-
+ /// <param name="sender">The sender.</param>
+ /// <param name="e">The e.</param>
private void Client_StateChanged(object sender, Transport.TransportComponentState e)
{
if (e == Transport.TransportComponentState.Failed || e == Transport.TransportComponentState.Disposed)
{
+ LogManager.Log("External bridge client failed or disposed. Removing from available machines...");
AvailableMachines.Remove(sender as IExternalBridgeClient);
}
}
diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeTcpClient.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeTcpClient.cs
new file mode 100644
index 000000000..2d00cd4e7
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeTcpClient.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.DAL.Observables;
+using Tango.PMR.Integration;
+using Tango.Settings;
+using Tango.Transport.Adapters;
+using Tango.Transport.Transporters;
+
+namespace Tango.Integration.Services
+{
+ /// <summary>
+ /// Represents a secure external bridge TCP client.
+ /// </summary>
+ /// <seealso cref="Tango.Transport.Transporters.BasicTransporter" />
+ /// <seealso cref="Tango.Integration.Services.IExternalBridgeSecureClient" />
+ public class ExternalBridgeTcpClient : BasicTransporter, IExternalBridgeSecureClient
+ {
+ private String _serialNumber;
+ /// <summary>
+ /// Gets the machine serial number.
+ /// </summary>
+ public String SerialNumber
+ {
+ get { return _serialNumber; }
+ internal set
+ {
+ _serialNumber = value;
+ RaisePropertyChangedAuto();
+
+ var org = ObservablesEntitiesAdapter.Instance.Organizations.SingleOrDefault(x => x.Machines.ToList().Exists(y => y.SerialNumber == SerialNumber));
+ Organization = org != null ? org.Name : "Unknown";
+ }
+ }
+
+ private String _ipAddress;
+ /// <summary>
+ /// Gets or sets the machine IP address.
+ /// </summary>
+ public String IPAddress
+ {
+ get { return _ipAddress; }
+ set { _ipAddress = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _organization;
+ /// <summary>
+ /// Gets the machine organization.
+ /// </summary>
+ public String Organization
+ {
+ get { return _organization; }
+ private set { _organization = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether this client requires authentication.
+ /// </summary>
+ public bool RequiresAuthentication => true;
+
+ /// <summary>
+ /// Connects the transport component.
+ /// </summary>
+ /// <returns></returns>
+ public override async Task Connect()
+ {
+ await Disconnect();
+ Adapter = new TcpTransportAdapter(IPAddress, SettingsManager.Default.Integration.ExternalBridgeServicePort);
+ await base.Connect();
+ }
+
+ /// <summary>
+ /// Authenticates with the service using the specified password.
+ /// </summary>
+ /// <param name="password">The password.</param>
+ /// <returns></returns>
+ public async Task<bool> Authenticate(String password)
+ {
+ var response = await SendRequest<ExternalClientLoginRequest, ExternalClientLoginResponse>(new ExternalClientLoginRequest()
+ {
+ Password = password
+ });
+ return response.Message.Authenticated;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ExternalBridgeTcpClient"/> class.
+ /// </summary>
+ /// <param name="serialNumber">The machine serial number.</param>
+ /// <param name="ipAddress">The machine IP address.</param>
+ public ExternalBridgeTcpClient(String serialNumber, String ipAddress)
+ {
+ SerialNumber = serialNumber;
+ IPAddress = ipAddress;
+ UseKeepAlive = true;
+ }
+
+ /// <summary>
+ /// Returns a <see cref="System.String" /> that represents this instance.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String" /> that represents this instance.
+ /// </returns>
+ public override string ToString()
+ {
+ return SerialNumber;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeUsbClient.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeUsbClient.cs
new file mode 100644
index 000000000..0f9c94e07
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeUsbClient.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.DAL.Observables;
+using Tango.PMR.Integration;
+using Tango.Settings;
+using Tango.Transport.Adapters;
+using Tango.Transport.Transporters;
+
+namespace Tango.Integration.Services
+{
+ /// <summary>
+ /// Represents an external bridge USB client.
+ /// </summary>
+ /// <remarks>
+ /// This isn't really an external bridge client, but merely a transporter for communicating with a Tango machine embedded device.
+ /// </remarks>
+ /// <seealso cref="Tango.Transport.Transporters.BasicTransporter" />
+ /// <seealso cref="Tango.Integration.Services.IExternalBridgeClient" />
+ public class ExternalBridgeUsbClient : BasicTransporter, IExternalBridgeClient
+ {
+ private String _comPort;
+ /// <summary>
+ /// Gets or sets the serial COM port.
+ /// </summary>
+ public String ComPort
+ {
+ get { return _comPort; }
+ set { _comPort = value; RaisePropertyChangedAuto(); }
+ }
+
+ private String _Device;
+ /// <summary>
+ /// Gets or sets the USB device name.
+ /// </summary>
+ public String Device
+ {
+ get { return _Device; }
+ set { _Device = value; RaisePropertyChangedAuto(); }
+ }
+
+ /// <summary>
+ /// Connects the transport component.
+ /// </summary>
+ /// <returns></returns>
+ public override async Task Connect()
+ {
+ await Disconnect();
+ Adapter = new UsbTransportAdapter(ComPort);
+ await base.Connect();
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether this client requires authentication.
+ /// </summary>
+ public bool RequiresAuthentication => false;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ExternalBridgeUsbClient"/> class.
+ /// </summary>
+ /// <param name="comPort">The COM port.</param>
+ /// <param name="device">The device.</param>
+ public ExternalBridgeUsbClient(String comPort, String device)
+ {
+ ComPort = comPort;
+ Device = device;
+ UseKeepAlive = false;
+ }
+
+ /// <summary>
+ /// Returns a <see cref="System.String" /> that represents this instance.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String" /> that represents this instance.
+ /// </returns>
+ public override string ToString()
+ {
+ return Device;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeClient.cs b/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeClient.cs
index 573a9d07c..04721f3ec 100644
--- a/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeClient.cs
+++ b/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeClient.cs
@@ -9,20 +9,15 @@ using Tango.Transport.Transporters;
namespace Tango.Integration.Services
{
+ /// <summary>
+ /// Represents a Tango machine external bridge service client.
+ /// </summary>
+ /// <seealso cref="Tango.Transport.ITransporter" />
public interface IExternalBridgeClient : ITransporter
{
- String SerialNumber { get; }
-
- String Organization { get; }
-
- String IPAddress { get; set; }
-
- ExternalBridgeClientType Type { get; }
-
- String ComPort { get; }
-
- String Device { get; }
-
- Task<bool> Authenticate(String password);
+ /// <summary>
+ /// Gets a value indicating whether this client requires authentication.
+ /// </summary>
+ bool RequiresAuthentication { get; }
}
}
diff --git a/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeSecureClient.cs b/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeSecureClient.cs
new file mode 100644
index 000000000..56eb1976d
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeSecureClient.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Integration.Services
+{
+ /// <summary>
+ /// Represents a secure external bridge client which requires authentication.
+ /// </summary>
+ /// <seealso cref="Tango.Integration.Services.IExternalBridgeClient" />
+ public interface IExternalBridgeSecureClient : IExternalBridgeClient
+ {
+ /// <summary>
+ /// Authenticates with the service using the specified password.
+ /// </summary>
+ /// <param name="password">The password.</param>
+ /// <returns></returns>
+ Task<bool> Authenticate(String password);
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
index 83d7dabf2..f3f2a5dab 100644
--- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
+++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
@@ -47,11 +47,13 @@
<Compile Include="..\Versioning\GlobalVersionInfo.cs">
<Link>GlobalVersionInfo.cs</Link>
</Compile>
- <Compile Include="Services\ExternalBridgeClient.cs" />
- <Compile Include="Services\ExternalBridgeClientType.cs" />
+ <Compile Include="ExtensionMethods\IExternalBridgeClientExtensions.cs" />
<Compile Include="Services\ExternalBridgeScanner.cs" />
+ <Compile Include="Services\ExternalBridgeTcpClient.cs" />
+ <Compile Include="Services\ExternalBridgeUsbClient.cs" />
<Compile Include="Services\IExternalBridgeClient.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Services\IExternalBridgeSecureClient.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tango.Core\Tango.Core.csproj">