aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2018-06-04 01:22:32 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2018-06-04 01:22:32 +0300
commitacf120606f7495bd132c0250fccb1b975e9660da (patch)
tree7ee25d9229317cf5042f20dd3966c7ea21be95c1 /Software/Visual_Studio
parenta56f07ca4373ae1dd6127f7a047a2bf0689ac6ad (diff)
downloadTango-acf120606f7495bd132c0250fccb1b975e9660da.tar.gz
Tango-acf120606f7495bd132c0250fccb1b975e9660da.zip
Added PMR_VS solution.
Refactored discovery to be more generic.
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/Installers/VS Extensions/CeciliaSharp.FolderToSolutionFolder.vsixbin0 -> 57817 bytes
-rw-r--r--Software/Visual_Studio/Installers/VS Extensions/Protobuf.vsixbin0 -> 139785 bytes
-rw-r--r--Software/Visual_Studio/Tango.PMR/Discovery/BasicDiscoveryMessage.cs36
-rw-r--r--Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs19
-rw-r--r--Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs9
-rw-r--r--Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryClient.cs5
-rw-r--r--Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryService.cs4
-rw-r--r--Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs41
-rw-r--r--Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs40
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs8
-rw-r--r--Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/MainWindowVM.cs10
11 files changed, 102 insertions, 70 deletions
diff --git a/Software/Visual_Studio/Installers/VS Extensions/CeciliaSharp.FolderToSolutionFolder.vsix b/Software/Visual_Studio/Installers/VS Extensions/CeciliaSharp.FolderToSolutionFolder.vsix
new file mode 100644
index 000000000..7705e132e
--- /dev/null
+++ b/Software/Visual_Studio/Installers/VS Extensions/CeciliaSharp.FolderToSolutionFolder.vsix
Binary files differ
diff --git a/Software/Visual_Studio/Installers/VS Extensions/Protobuf.vsix b/Software/Visual_Studio/Installers/VS Extensions/Protobuf.vsix
new file mode 100644
index 000000000..bc707bae6
--- /dev/null
+++ b/Software/Visual_Studio/Installers/VS Extensions/Protobuf.vsix
Binary files differ
diff --git a/Software/Visual_Studio/Tango.PMR/Discovery/BasicDiscoveryMessage.cs b/Software/Visual_Studio/Tango.PMR/Discovery/BasicDiscoveryMessage.cs
index e926a55c4..b3c3ec5d5 100644
--- a/Software/Visual_Studio/Tango.PMR/Discovery/BasicDiscoveryMessage.cs
+++ b/Software/Visual_Studio/Tango.PMR/Discovery/BasicDiscoveryMessage.cs
@@ -23,13 +23,13 @@ namespace Tango.PMR.Discovery {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChtCYXNpY0Rpc2NvdmVyeU1lc3NhZ2UucHJvdG8SE1RhbmdvLlBNUi5EaXNj",
- "b3ZlcnkiLAoVQmFzaWNEaXNjb3ZlcnlNZXNzYWdlEhMKC1NlcnZpY2VOYW1l",
- "GAEgASgJQh8KHWNvbS50d2luZS50YW5nby5wbXIuZGlzY292ZXJ5YgZwcm90",
- "bzM="));
+ "b3ZlcnkiOgoVQmFzaWNEaXNjb3ZlcnlNZXNzYWdlEhMKC1NlcnZpY2VOYW1l",
+ "GAEgASgJEgwKBFBvcnQYAiABKAVCHwodY29tLnR3aW5lLnRhbmdvLnBtci5k",
+ "aXNjb3ZlcnliBnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
- new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Discovery.BasicDiscoveryMessage), global::Tango.PMR.Discovery.BasicDiscoveryMessage.Parser, new[]{ "ServiceName" }, null, null, null)
+ new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Discovery.BasicDiscoveryMessage), global::Tango.PMR.Discovery.BasicDiscoveryMessage.Parser, new[]{ "ServiceName", "Port" }, null, null, null)
}));
}
#endregion
@@ -61,6 +61,7 @@ namespace Tango.PMR.Discovery {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public BasicDiscoveryMessage(BasicDiscoveryMessage other) : this() {
serviceName_ = other.serviceName_;
+ port_ = other.port_;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -79,6 +80,17 @@ namespace Tango.PMR.Discovery {
}
}
+ /// <summary>Field number for the "Port" field.</summary>
+ public const int PortFieldNumber = 2;
+ private int port_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Port {
+ get { return port_; }
+ set {
+ port_ = value;
+ }
+ }
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as BasicDiscoveryMessage);
@@ -93,6 +105,7 @@ namespace Tango.PMR.Discovery {
return true;
}
if (ServiceName != other.ServiceName) return false;
+ if (Port != other.Port) return false;
return true;
}
@@ -100,6 +113,7 @@ namespace Tango.PMR.Discovery {
public override int GetHashCode() {
int hash = 1;
if (ServiceName.Length != 0) hash ^= ServiceName.GetHashCode();
+ if (Port != 0) hash ^= Port.GetHashCode();
return hash;
}
@@ -114,6 +128,10 @@ namespace Tango.PMR.Discovery {
output.WriteRawTag(10);
output.WriteString(ServiceName);
}
+ if (Port != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Port);
+ }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -122,6 +140,9 @@ namespace Tango.PMR.Discovery {
if (ServiceName.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(ServiceName);
}
+ if (Port != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Port);
+ }
return size;
}
@@ -133,6 +154,9 @@ namespace Tango.PMR.Discovery {
if (other.ServiceName.Length != 0) {
ServiceName = other.ServiceName;
}
+ if (other.Port != 0) {
+ Port = other.Port;
+ }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -147,6 +171,10 @@ namespace Tango.PMR.Discovery {
ServiceName = input.ReadString();
break;
}
+ case 16: {
+ Port = input.ReadInt32();
+ break;
+ }
}
}
}
diff --git a/Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs b/Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs
index 096ed2bf4..3f01d07c8 100644
--- a/Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs
+++ b/Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs
@@ -1,4 +1,5 @@
-using Google.Protobuf.Reflection;
+using Google.Protobuf;
+using Google.Protobuf.Reflection;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -8,12 +9,10 @@ using System.Text;
using System.Threading.Tasks;
using Tango.PMR.Common;
-namespace Tango.PMR
-{
/// <summary>
/// Contains PMR extension methods.
/// </summary>
- public static class ExtensionMethods
+ public static class ExtensionMethods
{
/// <summary>
/// Gets the protobuf <see cref="OriginalNameAttribute"/> attribute value from the message type.
@@ -32,5 +31,15 @@ namespace Tango.PMR
else
return value.ToString();
}
+
+ /// <summary>
+ /// Gets the message parser.
+ /// </summary>
+ /// <param name="message">The message.</param>
+ /// <returns></returns>
+ public static MessageParser GetParser(this IMessage message)
+ {
+ MessageParser parser = message.GetType().GetProperty("Parser").GetValue(message) as MessageParser;
+ return parser;
+ }
}
-}
diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs b/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs
index f04623792..a9626284f 100644
--- a/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs
+++ b/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs
@@ -19,11 +19,6 @@ namespace Tango.Transport.Discovery
public DiscoveryMessage Message { get; set; }
/// <summary>
- /// Gets or sets the name of the service.
- /// </summary>
- public String ServiceName { get; set; }
-
- /// <summary>
/// Gets or sets the service IP address.
/// </summary>
public String Address { get; set; }
@@ -32,12 +27,10 @@ namespace Tango.Transport.Discovery
/// Initializes a new instance of the <see cref="DiscoveredService{DiscoveryMessage}"/> class.
/// </summary>
/// <param name="address">The address.</param>
- /// <param name="serviceName">Name of the service.</param>
/// <param name="message">The message.</param>
- public DiscoveredService(String address, String serviceName, DiscoveryMessage message)
+ public DiscoveredService(String address, DiscoveryMessage message)
{
Address = address;
- ServiceName = serviceName;
Message = message;
}
}
diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryClient.cs b/Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryClient.cs
index bfbdca1fd..4bc992d77 100644
--- a/Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryClient.cs
+++ b/Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryClient.cs
@@ -20,11 +20,6 @@ namespace Tango.Transport.Discovery
event EventHandler<DiscoveredService<DiscoveryMessage>> ServiceDiscovered;
/// <summary>
- /// Gets or sets the name of the remote service to discover.
- /// </summary>
- String ServiceName { get; set; }
-
- /// <summary>
/// Asynchronous method for awaiting until the service will be discovered.
/// </summary>
/// <returns></returns>
diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryService.cs b/Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryService.cs
index 548bbedc0..9ec48ba47 100644
--- a/Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryService.cs
+++ b/Software/Visual_Studio/Tango.Transport/Discovery/IDiscoveryService.cs
@@ -14,8 +14,8 @@ namespace Tango.Transport.Discovery
public interface IDiscoveryService<DiscoveryMessage> : IDiscoveryComponent where DiscoveryMessage : IMessage
{
/// <summary>
- /// Gets the name of the service.
+ /// Gets or sets the current discovery message.
/// </summary>
- String ServiceName { get; }
+ DiscoveryMessage CurrentDiscoveryMessage { get; set; }
}
}
diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs
index a1086c0fa..617aea61a 100644
--- a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs
+++ b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs
@@ -1,4 +1,5 @@
-using System;
+using Google.Protobuf;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@@ -10,14 +11,14 @@ using Tango.PMR.Discovery;
namespace Tango.Transport.Discovery
{
- public class UdpDiscoveryClient : IDiscoveryClient<BasicDiscoveryMessage>
+ public class UdpDiscoveryClient<DiscoveryMessage> : IDiscoveryClient<DiscoveryMessage> where DiscoveryMessage : IMessage
{
private Timer _timer;
/// <summary>
/// Occurs when a matching service has been discovered.
/// </summary>
- public event EventHandler<DiscoveredService<BasicDiscoveryMessage>> ServiceDiscovered;
+ public event EventHandler<DiscoveredService<DiscoveryMessage>> ServiceDiscovered;
/// <summary>
/// Gets or sets the interval in which the discovery message will be sent.
@@ -30,11 +31,6 @@ namespace Tango.Transport.Discovery
public bool IsStarted { get; private set; }
/// <summary>
- /// Gets the name of the service.
- /// </summary>
- public String ServiceName { get; set; }
-
- /// <summary>
/// Gets the UDP port number.
/// </summary>
public int Port { get; private set; }
@@ -51,10 +47,9 @@ namespace Tango.Transport.Discovery
/// Initializes a new instance of the <see cref="UdpDiscoveryClient"/> class.
/// </summary>
/// <param name="port">The UDP port number.</param>
- public UdpDiscoveryClient(String serviceName, int port) : this()
+ public UdpDiscoveryClient(int port) : this()
{
Port = port;
- ServiceName = serviceName;
}
/// <summary>
@@ -86,8 +81,6 @@ namespace Tango.Transport.Discovery
}
}
-
-
/// <summary>
/// Handles the Elapsed event of the _timer control.
/// </summary>
@@ -103,16 +96,16 @@ namespace Tango.Transport.Discovery
{
var data = udpClient.Receive(ref endPoint);
udpClient.Close();
- BasicDiscoveryMessage message = BasicDiscoveryMessage.Parser.ParseFrom(data);
- if (message.ServiceName == ServiceName)
- {
- ServiceDiscovered?.Invoke(this,
- new DiscoveredService<BasicDiscoveryMessage>(
- endPoint.Address.ToString(),
- ServiceName,
- message));
- }
+ DiscoveryMessage message = Activator.CreateInstance<DiscoveryMessage>();
+ var parser = message.GetParser();
+
+ message = (DiscoveryMessage)parser.ParseFrom(data);
+
+ ServiceDiscovered?.Invoke(this,
+ new DiscoveredService<DiscoveryMessage>(
+ endPoint.Address.ToString(),
+ message));
}
catch { }
finally
@@ -126,13 +119,13 @@ namespace Tango.Transport.Discovery
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
- public Task<DiscoveredService<BasicDiscoveryMessage>> Discover(TimeSpan? timeout = null)
+ public Task<DiscoveredService<DiscoveryMessage>> Discover(TimeSpan? timeout = null)
{
Start();
- TaskCompletionSource<DiscoveredService<BasicDiscoveryMessage>> source = new TaskCompletionSource<DiscoveredService<BasicDiscoveryMessage>>();
+ TaskCompletionSource<DiscoveredService<DiscoveryMessage>> source = new TaskCompletionSource<DiscoveredService<DiscoveryMessage>>();
- EventHandler<DiscoveredService<BasicDiscoveryMessage>> handler = null;
+ EventHandler<DiscoveredService<DiscoveryMessage>> handler = null;
handler = (sender, e) =>
{
diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs
index f33449607..76773a817 100644
--- a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs
+++ b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs
@@ -1,4 +1,5 @@
-using System;
+using Google.Protobuf;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@@ -14,11 +15,16 @@ namespace Tango.Transport.Discovery
/// Represents UDP discovery service broadcasting a discovery message of type <see cref="BasicDiscoveryMessage"/>.
/// </summary>
/// <seealso cref="Tango.Transport.Discovery.IDiscoveryService{Tango.PMR.Discovery.BasicDiscoveryMessage}" />
- public class UdpDiscoveryService : IDiscoveryService<BasicDiscoveryMessage>
+ public class UdpDiscoveryService<DiscoveryMessage> : IDiscoveryService<DiscoveryMessage> where DiscoveryMessage : IMessage
{
private Timer _timer;
/// <summary>
+ /// Gets or sets the current discovery message.
+ /// </summary>
+ public DiscoveryMessage CurrentDiscoveryMessage { get; set; }
+
+ /// <summary>
/// Gets or sets the interval in which the discovery message will be sent.
/// </summary>
public TimeSpan Interval { get; set; }
@@ -29,31 +35,36 @@ namespace Tango.Transport.Discovery
public bool IsStarted { get; private set; }
/// <summary>
- /// Gets the name of the service.
- /// </summary>
- public String ServiceName { get; set; }
-
- /// <summary>
/// Gets the UDP port number.
/// </summary>
public int Port { get; private set; }
/// <summary>
- /// Prevents a default instance of the <see cref="UdpDiscoveryService"/> class from being created.
+ /// Prevents a default instance of the <see cref="UdpDiscoveryService{DiscoveryMessage}"/> class from being created.
/// </summary>
private UdpDiscoveryService()
{
Interval = TimeSpan.FromSeconds(5);
+ CurrentDiscoveryMessage = Activator.CreateInstance<DiscoveryMessage>();
}
/// <summary>
- /// Initializes a new instance of the <see cref="UdpDiscoveryService"/> class.
+ /// Initializes a new instance of the <see cref="UdpDiscoveryService{DiscoveryMessage}"/> class.
/// </summary>
- /// <param name="port">The UDP port number.</param>
- public UdpDiscoveryService(String serviceName, int port) : this()
+ /// <param name="port">The port.</param>
+ public UdpDiscoveryService(int port) : this()
{
Port = port;
- ServiceName = serviceName;
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UdpDiscoveryService{DiscoveryMessage}"/> class.
+ /// </summary>
+ /// <param name="port">The port.</param>
+ /// <param name="discoveryMessage">The discovery message.</param>
+ public UdpDiscoveryService(int port, DiscoveryMessage discoveryMessage) : this(port)
+ {
+ CurrentDiscoveryMessage = discoveryMessage;
}
/// <summary>
@@ -96,10 +107,7 @@ namespace Tango.Transport.Discovery
IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Port);
- BasicDiscoveryMessage message = new BasicDiscoveryMessage();
- message.ServiceName = ServiceName;
-
- byte[] bytes = message.ToBytes();
+ byte[] bytes = CurrentDiscoveryMessage.ToByteArray();
client.Send(bytes, bytes.Length, endPoint);
diff --git a/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs
index 37ade9688..21bdf3295 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs
+++ b/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs
@@ -14,6 +14,7 @@ using Tango.PMR.IO;
using Tango.PMR;
using Google.Protobuf;
using Tango.Transport.Discovery;
+using Tango.PMR.Discovery;
namespace Tango.UnitTesting
{
@@ -29,11 +30,10 @@ namespace Tango.UnitTesting
Thread.Sleep(2000);
- UdpDiscoveryClient discoveryClient = new UdpDiscoveryClient("Tango Remote Runner", 2018);
- var service = discoveryClient.Discover().Result;
+ UdpDiscoveryClient<BasicDiscoveryMessage> discoveryClient = new UdpDiscoveryClient<BasicDiscoveryMessage>(2018);
+ var discoveryResponse = discoveryClient.Discover().Result;
-
- ITransportAdapter adapter = new TcpTransportAdapter(service.Address, 9595);
+ ITransportAdapter adapter = new TcpTransportAdapter(discoveryResponse.Address, discoveryResponse.Message.Port);
ITransporter transporter = new BasicTransporter(adapter);
transporter.Connect().Wait();
diff --git a/Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/MainWindowVM.cs b/Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/MainWindowVM.cs
index 2ba6aa4bb..fd1b05e15 100644
--- a/Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/MainWindowVM.cs
+++ b/Software/Visual_Studio/Utilities/Tango.RemoteRunner.UI/MainWindowVM.cs
@@ -11,6 +11,7 @@ using System.Windows;
using Tango.Logging;
using Tango.PMR;
using Tango.PMR.Common;
+using Tango.PMR.Discovery;
using Tango.PMR.IO;
using Tango.SharedUI;
using Tango.Transport;
@@ -25,7 +26,7 @@ namespace Tango.RemoteRunner.UI
{
private TcpServer _server;
private ITransporter _transporter;
- private UdpDiscoveryService _discoveryService;
+ private UdpDiscoveryService<BasicDiscoveryMessage> _discoveryService;
private const int PORT = 9595;
private List<FileUpload> _uploads;
private const long MAX_CHUNK_LENGTH = 1024;
@@ -71,7 +72,12 @@ namespace Tango.RemoteRunner.UI
_transporter.FailsWithAdapter = false;
_transporter.RequestReceived += _transporter_RequestReceived;
- _discoveryService = new UdpDiscoveryService("Tango Remote Runner", 2018);
+ _discoveryService = new UdpDiscoveryService<BasicDiscoveryMessage>(2018, new BasicDiscoveryMessage()
+ {
+ ServiceName = "Tango Remote Debugger",
+ Port = PORT,
+ });
+
_discoveryService.Interval = TimeSpan.FromSeconds(1);
_discoveryService.Start();
}