aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Transport
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-02-27 23:49:32 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-02-27 23:49:32 +0200
commit5f45be5bae69be7b7e916f02fb6d69b2db60e529 (patch)
tree9aff84020b5eca21df7bf0a7b5439e073969cec1 /Software/Visual_Studio/Tango.Transport
parent03970962af1bfbfc5c13109c3f0a465cf9a1dc29 (diff)
downloadTango-5f45be5bae69be7b7e916f02fb6d69b2db60e529.tar.gz
Tango-5f45be5bae69be7b7e916f02fb6d69b2db60e529.zip
Implemented Generic messages support!
Implemented custom external bridge request handlers.
Diffstat (limited to 'Software/Visual_Studio/Tango.Transport')
-rw-r--r--Software/Visual_Studio/Tango.Transport/ITransporter.cs20
-rw-r--r--Software/Visual_Studio/Tango.Transport/TransporterBase.cs39
2 files changed, 59 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Transport/ITransporter.cs b/Software/Visual_Studio/Tango.Transport/ITransporter.cs
index 5576de0b2..bffcb0444 100644
--- a/Software/Visual_Studio/Tango.Transport/ITransporter.cs
+++ b/Software/Visual_Studio/Tango.Transport/ITransporter.cs
@@ -84,6 +84,26 @@ namespace Tango.Transport
IObservable<TangoMessage<Response>> SendContinuousRequest<Request, Response>(TangoMessage<Request> request, TransportContinuousRequestConfig config = null) where Request : IMessage<Request> where Response : IMessage<Response>;
/// <summary>
+ /// Sends a generic request of any type.
+ /// </summary>
+ /// <typeparam name="Request">The type of the request.</typeparam>
+ /// <typeparam name="Response">The type of the response.</typeparam>
+ /// <param name="request">The request.</param>
+ /// <param name="config">The configuration.</param>
+ /// <returns></returns>
+ Task<Response> SendGenericRequest<Request, Response>(Request request, TransportRequestConfig config = null) where Request : class where Response : class;
+
+ /// <summary>
+ /// Sends a generic response.
+ /// </summary>
+ /// <typeparam name="Response">The type of the response.</typeparam>
+ /// <param name="response">The response.</param>
+ /// <param name="token">The request token.</param>
+ /// <param name="config">The response configuration.</param>
+ /// <returns></returns>
+ Task SendGenericResponse<Response>(Response response, String token, TransportResponseConfig config = null) where Response : class;
+
+ /// <summary>
/// Sends the response.
/// </summary>
/// <param name="container">The container.</param>
diff --git a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
index edd70f22f..e0f9d46dd 100644
--- a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
+++ b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs
@@ -19,6 +19,8 @@ using Tango.PMR.Connection;
using Tango.Core.Threading;
using System.IO;
using Tango.Core.ExtensionMethods;
+using Tango.PMR.Integration;
+using Newtonsoft.Json;
namespace Tango.Transport
{
@@ -40,6 +42,10 @@ namespace Tango.Transport
private ITransportAdapter _adapter;
private Dictionary<String, PendingResponse> _pendingResponses;
private DateTime _lastKeepAliveTime;
+ private static JsonSerializerSettings _genericMessageSettings = new JsonSerializerSettings()
+ {
+ TypeNameHandling = TypeNameHandling.All,
+ };
#region Events
@@ -840,6 +846,39 @@ namespace Tango.Transport
return subject.AsObservable();
}
+ /// <summary>
+ /// Sends a generic request of any type.
+ /// </summary>
+ /// <typeparam name="Request">The type of the request.</typeparam>
+ /// <typeparam name="Response">The type of the response.</typeparam>
+ /// <param name="request">The request.</param>
+ /// <param name="config">The configuration.</param>
+ /// <returns></returns>
+ public async Task<Response> SendGenericRequest<Request, Response>(Request request, TransportRequestConfig config = null) where Request : class where Response : class
+ {
+ GenericRequest genericRequest = new GenericRequest();
+ genericRequest.Type = request.GetType().Name;
+ genericRequest.Data = ByteString.CopyFromUtf8(JsonConvert.SerializeObject(request, _genericMessageSettings));
+ var response = await SendRequest<GenericRequest, GenericResponse>(genericRequest, config);
+ var responseObject = JsonConvert.DeserializeObject<Response>(response.Message.Data.ToStringUtf8());
+ return responseObject;
+ }
+
+ /// <summary>
+ /// Sends a generic response.
+ /// </summary>
+ /// <typeparam name="Response">The type of the response.</typeparam>
+ /// <param name="response">The response.</param>
+ /// <param name="token">The request token.</param>
+ /// <param name="config">The response configuration.</param>
+ /// <returns></returns>
+ public async Task SendGenericResponse<Response>(Response response, String token, TransportResponseConfig config = null) where Response : class
+ {
+ GenericResponse genericResponse = new GenericResponse();
+ genericResponse.Data = ByteString.CopyFromUtf8(JsonConvert.SerializeObject(response, _genericMessageSettings));
+ await SendResponse<GenericResponse>(genericResponse, token, config);
+ }
+
#endregion
#region Public Response Methods