aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy <roy.mail.net@gmail.com>2017-12-25 11:06:31 +0200
committerRoy <roy.mail.net@gmail.com>2017-12-25 11:06:31 +0200
commit6450fc175114a6f8d0b75cb21386d1bb0c902711 (patch)
tree374c3005e7073855264c16f8ea0ad1d022f9f627 /Software/Visual_Studio
parent6e095fe0b74ee090603fc25980fa0c71f61c6467 (diff)
downloadTango-6450fc175114a6f8d0b75cb21386d1bb0c902711.tar.gz
Tango-6450fc175114a6f8d0b75cb21386d1bb0c902711.zip
Implemented Container ErrorCode handling on .NET + Java.
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj7
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineLoginView.xaml12
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineLoginView.xaml.cs28
-rw-r--r--Software/Visual_Studio/Tango.PMR/TangoMessage.cs14
-rw-r--r--Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs10
-rw-r--r--Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj17
-rw-r--r--Software/Visual_Studio/Tango.Stubs/packages.config6
-rw-r--r--Software/Visual_Studio/Tango.Transport/ITransporter.cs4
-rw-r--r--Software/Visual_Studio/Tango.Transport/ResponseErrorException.cs32
-rw-r--r--Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj1
-rw-r--r--Software/Visual_Studio/Tango.Transport/TransportMessage.cs35
-rw-r--r--Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs7
-rw-r--r--Software/Visual_Studio/Tango.Transport/TransporterBase.cs46
13 files changed, 185 insertions, 34 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
index 3becf0252..355d59083 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj
@@ -126,6 +126,9 @@
<Compile Include="Views\MachineConnectionView.xaml.cs">
<DependentUpon>MachineConnectionView.xaml</DependentUpon>
</Compile>
+ <Compile Include="Views\MachineLoginView.xaml.cs">
+ <DependentUpon>MachineLoginView.xaml</DependentUpon>
+ </Compile>
<Compile Include="Views\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
</Compile>
@@ -170,6 +173,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="Views\MachineLoginView.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="Views\MainView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineLoginView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineLoginView.xaml
new file mode 100644
index 000000000..83f7cc884
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineLoginView.xaml
@@ -0,0 +1,12 @@
+<UserControl x:Class="Tango.MachineStudio.UI.Views.MachineLoginView"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views"
+ mc:Ignorable="d"
+ d:DesignHeight="300" d:DesignWidth="300">
+ <Grid>
+
+ </Grid>
+</UserControl>
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineLoginView.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineLoginView.xaml.cs
new file mode 100644
index 000000000..c0bfdc25d
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineLoginView.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Tango.MachineStudio.UI.Views
+{
+ /// <summary>
+ /// Interaction logic for MachineLoginView.xaml
+ /// </summary>
+ public partial class MachineLoginView : UserControl
+ {
+ public MachineLoginView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.PMR/TangoMessage.cs b/Software/Visual_Studio/Tango.PMR/TangoMessage.cs
index dec963e36..4819ac509 100644
--- a/Software/Visual_Studio/Tango.PMR/TangoMessage.cs
+++ b/Software/Visual_Studio/Tango.PMR/TangoMessage.cs
@@ -107,5 +107,19 @@ namespace Tango.PMR
{
return MessageFactory.ParseTangoMessage<T>(data);
}
+
+ /// <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 String.Format(@"Message Type: {0}
+Token: {1}
+Error: {2}
+Message: {3}",Container.Type,Container.Token,Container.Error,Message.ToString());
+ }
}
}
diff --git a/Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs b/Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs
index cd13a84ff..9ce96e633 100644
--- a/Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs
+++ b/Software/Visual_Studio/Tango.Stubs/Stubs/Progress.cs
@@ -32,9 +32,15 @@ namespace Tango.Stubs.Stubs
{
Amount = (int)Amount,
Delay = (int)Delay,
- }), (response) =>
+ })).Subscribe((x) =>
{
- multiResponseCallback(response.Message.Progress.ToString());
+ multiResponseCallback(x.Message.Progress.ToString());
+ }, (ex) =>
+ {
+ multiResponseCallback(ex.Message);
+ }, () =>
+ {
+ multiResponseCallback("Completed!");
});
return Task.FromResult<String>("");
diff --git a/Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj b/Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj
index 6d4538830..541119a44 100644
--- a/Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj
+++ b/Software/Visual_Studio/Tango.Stubs/Tango.Stubs.csproj
@@ -36,12 +36,29 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.Reactive.Core, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Interfaces, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Reactive.Interfaces.3.1.1\lib\net45\System.Reactive.Interfaces.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Linq, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Reactive.Linq.3.1.1\lib\net46\System.Reactive.Linq.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.PlatformServices, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Reactive.PlatformServices.3.1.1\lib\net46\System.Reactive.PlatformServices.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Reactive.Windows.Threading, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
+ <HintPath>..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Windows" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
+ <Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Versioning\GlobalVersionInfo.cs">
diff --git a/Software/Visual_Studio/Tango.Stubs/packages.config b/Software/Visual_Studio/Tango.Stubs/packages.config
index e7e6cbade..97f56d4cc 100644
--- a/Software/Visual_Studio/Tango.Stubs/packages.config
+++ b/Software/Visual_Studio/Tango.Stubs/packages.config
@@ -1,4 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Google.Protobuf" version="3.4.1" targetFramework="net45" />
+ <package id="System.Reactive" version="3.1.1" targetFramework="net46" />
+ <package id="System.Reactive.Core" version="3.1.1" targetFramework="net46" />
+ <package id="System.Reactive.Interfaces" version="3.1.1" targetFramework="net46" />
+ <package id="System.Reactive.Linq" version="3.1.1" targetFramework="net46" />
+ <package id="System.Reactive.PlatformServices" version="3.1.1" targetFramework="net46" />
+ <package id="System.Reactive.Windows.Threading" version="3.1.1" targetFramework="net46" />
</packages> \ No newline at end of file
diff --git a/Software/Visual_Studio/Tango.Transport/ITransporter.cs b/Software/Visual_Studio/Tango.Transport/ITransporter.cs
index d805afa2b..d2eb03e5e 100644
--- a/Software/Visual_Studio/Tango.Transport/ITransporter.cs
+++ b/Software/Visual_Studio/Tango.Transport/ITransporter.cs
@@ -52,7 +52,7 @@ namespace Tango.Transport
/// <param name="adapter">Transport adapter</param>
/// <param name="responseCallback">The response callback delegate.</param>
/// <returns></returns>
- void SendContinuousRequest<Request, Response>(TangoMessage<Request> request, Action<TangoMessage<Response>> responseCallback) where Request : IMessage<Request> where Response : IMessage<Response>;
+ IObservable<TangoMessage<Response>> SendContinuousRequest<Request, Response>(TangoMessage<Request> request) where Request : IMessage<Request> where Response : IMessage<Response>;
/// <summary>
/// Sends a request through the specified adapter which is expected to return multiple response messages.
@@ -63,7 +63,7 @@ namespace Tango.Transport
/// <param name="adapter">Transport adapter</param>
/// <param name="responseCallback">The response callback delegate.</param>
/// <returns></returns>
- void SendContinuousRequest<Request, Response>(TangoMessage<Request> request, ITransportAdapter adapter, Action<TangoMessage<Response>> responseCallback) where Request : IMessage<Request> where Response : IMessage<Response>;
+ IObservable<TangoMessage<Response>> SendContinuousRequest<Request, Response>(TangoMessage<Request> request, ITransportAdapter adapter) where Request : IMessage<Request> where Response : IMessage<Response>;
/// <summary>
/// Sends a response.
diff --git a/Software/Visual_Studio/Tango.Transport/ResponseErrorException.cs b/Software/Visual_Studio/Tango.Transport/ResponseErrorException.cs
new file mode 100644
index 000000000..365a5d432
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Transport/ResponseErrorException.cs
@@ -0,0 +1,32 @@
+using Google.Protobuf;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.PMR;
+using Tango.PMR.Common;
+
+namespace Tango.Transport
+{
+ /// <summary>
+ /// Represents a tango message response exception which indicates a response container with <see cref="ErrorCode"/> different from <see cref="ErrorCode.None"/>.
+ /// </summary>
+ /// <seealso cref="System.Exception" />
+ public class ResponseErrorException : Exception
+ {
+ /// <summary>
+ /// Gets or sets the error.
+ /// </summary>
+ public ErrorCode Error { get; set; }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ResponseErrorException{T}"/> class.
+ /// </summary>
+ /// <param name="error">The error.</param>
+ public ResponseErrorException(ErrorCode error) : base("Response received with error " + error.ToString())
+ {
+ Error = error;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
index 2d6bc617a..7b0b1a121 100644
--- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
+++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
@@ -72,6 +72,7 @@
<Compile Include="PendingResponse.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ITransporter.cs" />
+ <Compile Include="ResponseErrorException.cs" />
<Compile Include="Routing\SimpleTransportRouter.cs" />
<Compile Include="Servers\ClientConnectedEventArgs.cs" />
<Compile Include="Servers\TcpServer.cs" />
diff --git a/Software/Visual_Studio/Tango.Transport/TransportMessage.cs b/Software/Visual_Studio/Tango.Transport/TransportMessage.cs
index 90e600a06..d4ba54272 100644
--- a/Software/Visual_Studio/Tango.Transport/TransportMessage.cs
+++ b/Software/Visual_Studio/Tango.Transport/TransportMessage.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR;
@@ -17,7 +18,7 @@ namespace Tango.Transport
{
private TaskCompletionSource<T> _completionSource;
- public Action<T> ResponseCallback { get; set; }
+ public Subject<T> ContinuesResponseSubject { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="TransportMessage{T}"/> class.
@@ -38,7 +39,19 @@ namespace Tango.Transport
/// <param name="result">The result.</param>
public override void SetResult(object result, bool completed)
{
- _completionSource.SetResult((T)result);
+ if (!IsContinuous)
+ {
+ _completionSource.SetResult((T)result);
+ }
+ else
+ {
+ ContinuesResponseSubject.OnNext((T)result);
+
+ if (completed)
+ {
+ ContinuesResponseSubject.OnCompleted();
+ }
+ }
}
/// <summary>
@@ -47,16 +60,14 @@ namespace Tango.Transport
/// <param name="ex">The ex.</param>
public override void SetException(Exception ex)
{
- _completionSource.SetException(ex);
- }
-
- /// <summary>
- /// Invokes the response callback.
- /// </summary>
- /// <param name="response">The response.</param>
- public override void InvokeResponseCallback(object response, bool completed)
- {
- ResponseCallback((T)response);
+ if (!IsContinuous)
+ {
+ _completionSource.SetException(ex);
+ }
+ else
+ {
+ ContinuesResponseSubject.OnError(ex);
+ }
}
}
}
diff --git a/Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs b/Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs
index c9202efc6..4cc3823cf 100644
--- a/Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs
+++ b/Software/Visual_Studio/Tango.Transport/TransportMessageBase.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
@@ -54,12 +55,6 @@ namespace Tango.Transport
public abstract void SetException(Exception ex);
/// <summary>
- /// Invokes the response callback.
- /// </summary>
- /// <param name="response">The response.</param>
- public abstract void InvokeResponseCallback(object response, bool completed);
-
- /// <summary>
/// Initializes a new instance of the <see cref="TransportMessageBase"/> class.
/// </summary>
/// <param name="token">The token.</param>
diff --git a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
index ec53d0fc6..cf7c79864 100644
--- a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
+++ b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
@@ -4,6 +4,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
+using System.Reactive.Subjects;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -11,6 +12,7 @@ using Tango.Core;
using Tango.Logging;
using Tango.PMR;
using Tango.PMR.Common;
+using System.Reactive.Linq;
namespace Tango.Transport
{
@@ -313,9 +315,9 @@ namespace Tango.Transport
/// <typeparam name="Response">The type of the response.</typeparam>
/// <param name="request">The request.</param>
/// <param name="responseCallback">The response callback delegate.</param>
- public void SendContinuousRequest<Request, Response>(TangoMessage<Request> request, Action<TangoMessage<Response>> responseCallback) where Request : IMessage<Request> where Response : IMessage<Response>
+ public IObservable<TangoMessage<Response>> SendContinuousRequest<Request, Response>(TangoMessage<Request> request) where Request : IMessage<Request> where Response : IMessage<Response>
{
- SendContinuousRequest(request, null, responseCallback);
+ return SendContinuousRequest<Request, Response>(request, null);
}
/// <summary>
@@ -326,8 +328,10 @@ namespace Tango.Transport
/// <param name="request">The request.</param>
/// <param name="adapter">Transport adapter</param>
/// <param name="responseCallback">The response callback delegate.</param>
- public void SendContinuousRequest<Request, Response>(TangoMessage<Request> request, ITransportAdapter adapter, Action<TangoMessage<Response>> responseCallback) where Request : IMessage<Request> where Response : IMessage<Response>
+ public IObservable<TangoMessage<Response>> SendContinuousRequest<Request, Response>(TangoMessage<Request> request, ITransportAdapter adapter) where Request : IMessage<Request> where Response : IMessage<Response>
{
+ Subject<TangoMessage<Response>> subject = new Subject<TangoMessage<Response>>();
+
LogManager.Log("Queuing continuous request message: " + typeof(Request).Name + " on adapter: " + (adapter != null ? adapter.Address : "ALL"));
LogManager.Log("Expected response: " + typeof(Response).Name);
@@ -337,9 +341,11 @@ namespace Tango.Transport
TransportMessage<TangoMessage<Response>> message = new TransportMessage<TangoMessage<Response>>(adapter, request.Container.Token, request, TransportMessageDirection.Request, OnSerializeingMessage(request), null)
{
IsContinuous = true,
- ResponseCallback = responseCallback,
+ ContinuesResponseSubject = subject,
};
_sendingQueue.Enqueue(message);
+
+ return subject.AsObservable();
}
/// <summary>
@@ -517,12 +523,20 @@ namespace Tango.Transport
try
{
- LogManager.Log("Parsing inner response message and setting pending request task result...");
- request.SetResult(OnParseTangoMessage(data.Value), true);
+ if (container.Error == ErrorCode.None)
+ {
+ LogManager.Log("Parsing inner response message and setting pending request task result...");
+ request.SetResult(OnParseTangoMessage(data.Value), true);
+ }
+ else
+ {
+ LogManager.Log("Response has returned with error: " + container.Error.ToString());
+ request.SetException(new ResponseErrorException(container.Error));
+ }
}
catch (Exception ex)
{
- request.SetException(LogManager.Log(ex, "Error parsing inner message."));
+ request.SetException(LogManager.Log(ex, "Error parsing response message."));
}
}
else
@@ -531,16 +545,24 @@ namespace Tango.Transport
try
{
- LogManager.Log("Parsing inner response message and invoking continuous response callback...");
- if (container.Completed)
+ if (container.Error == ErrorCode.None)
+ {
+ LogManager.Log("Parsing inner response message and invoking continuous response callback...");
+ if (container.Completed)
+ {
+ LogManager.Log("Continuous sequence completed.");
+ }
+ request.SetResult(OnParseTangoMessage(data.Value), container.Completed);
+ }
+ else
{
- LogManager.Log("Continuous sequence completed.");
+ LogManager.Log("Response has returned with error: " + container.Error.ToString());
+ request.SetException(new ResponseErrorException(container.Error));
}
- request.InvokeResponseCallback(OnParseTangoMessage(data.Value), container.Completed);
}
catch (Exception ex)
{
- LogManager.Log(ex, "Error parsing inner message.");
+ LogManager.Log(ex, "Error parsing response message.");
}
}
}