From d4fcdf1b7e6a0287d2e388bcef243ad80720ac3f Mon Sep 17 00:00:00 2001 From: Ahmad Noman Musleh Date: Tue, 8 Mar 2022 10:22:09 +0300 Subject: [PATCH 1/2] Made some changes on console sample --- src/Console.Sample/Program.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Console.Sample/Program.cs b/src/Console.Sample/Program.cs index a28ba10..7bfb2f2 100644 --- a/src/Console.Sample/Program.cs +++ b/src/Console.Sample/Program.cs @@ -18,7 +18,7 @@ internal class Program private static OpenClient _client; - private static readonly List _disposables = new List(); + private static readonly List _disposables = new(); private static async Task Main() { @@ -298,6 +298,13 @@ private static void ProcessSubscriptionCommand(string[] commandSplit) private static async void RefreshToken() { + if (string.IsNullOrWhiteSpace(_token.RefreshToken)) + { + Console.Write("Refresh Token: "); + + _token.RefreshToken = Console.ReadLine(); + } + Console.WriteLine("Sending ProtoOARefreshTokenReq..."); var request = new ProtoOARefreshTokenReq From f10a484c6d1ebd459b63ef29fee5afef0048f375 Mon Sep 17 00:00:00 2001 From: Ahmad Noman Musleh Date: Sat, 12 Mar 2022 09:41:42 +0300 Subject: [PATCH 2/2] Added try/catch inside send heartbeat to avoid channel closed exception --- src/OpenAPI.Net/OpenAPI.Net.csproj | 2 +- src/OpenAPI.Net/OpenClient.cs | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/OpenAPI.Net/OpenAPI.Net.csproj b/src/OpenAPI.Net/OpenAPI.Net.csproj index c580b18..7b73bde 100644 --- a/src/OpenAPI.Net/OpenAPI.Net.csproj +++ b/src/OpenAPI.Net/OpenAPI.Net.csproj @@ -9,7 +9,7 @@ cTrader, Open API, Spotware A .NET RX library for Spotware Open API Spotware.OpenAPI.Net - 1.3.9-rc0 + 1.3.9 AnyCPU Spotware Spotware diff --git a/src/OpenAPI.Net/OpenClient.cs b/src/OpenAPI.Net/OpenClient.cs index 4b821cb..fc0d3ef 100644 --- a/src/OpenAPI.Net/OpenClient.cs +++ b/src/OpenAPI.Net/OpenClient.cs @@ -169,8 +169,7 @@ public IDisposable Subscribe(IObserver observer) /// The client message ID (optional) /// If getting message payload type fails /// Task - public async Task SendMessage(T message, string clientMsgId = null) where T : - IMessage + public async Task SendMessage(T message, string clientMsgId = null) where T : IMessage { var protoMessage = MessageFactory.GetMessage(message.GetPayloadType(), message.ToByteString(), clientMsgId); @@ -185,8 +184,7 @@ public async Task SendMessage(T message, string clientMsgId = null) where T : /// Message Payload Type (ProtoPayloadType) /// The client message ID (optional) /// Task - public async Task SendMessage(T message, ProtoPayloadType payloadType, string clientMsgId = null) where T : - IMessage + public async Task SendMessage(T message, ProtoPayloadType payloadType, string clientMsgId = null) where T : IMessage { var protoMessage = MessageFactory.GetMessage(message, payloadType, clientMsgId); @@ -201,8 +199,7 @@ public async Task SendMessage(T message, ProtoPayloadType payloadType, string /// Message Payload Type (ProtoOAPayloadType) /// The client message ID (optional) /// Task - public async Task SendMessage(T message, ProtoOAPayloadType payloadType, string clientMsgId = null) where T : - IMessage + public async Task SendMessage(T message, ProtoOAPayloadType payloadType, string clientMsgId = null) where T : IMessage { var protoMessage = MessageFactory.GetMessage(message, payloadType, clientMsgId); @@ -457,7 +454,14 @@ private async void SendHeartbeat() { if (IsDisposed || DateTimeOffset.Now - LastSentMessageTime < _heartbeatInerval) return; - await SendMessage(_heartbeatEvent, ProtoPayloadType.HeartbeatEvent).ConfigureAwait(false); + try + { + await SendMessage(_heartbeatEvent, ProtoPayloadType.HeartbeatEvent).ConfigureAwait(false); + } + catch (Exception ex) + { + OnError(ex); + } } ///