Skip to content

Commit 89e9f51

Browse files
author
Ahmad Noman Musleh
committed
Fixed some issues
1 parent 227fc5e commit 89e9f51

2 files changed

Lines changed: 16 additions & 27 deletions

File tree

src/OpenAPI.Net/OpenAPI.Net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageTags>cTrader, Open API, Spotware</PackageTags>
1010
<Description>A .NET RX library for Spotware Open API</Description>
1111
<PackageId>Spotware.OpenAPI.Net</PackageId>
12-
<Version>1.3.7-rc2</Version>
12+
<Version>1.3.7-rc3</Version>
1313
<Platforms>AnyCPU</Platforms>
1414
<Company>Spotware</Company>
1515
<Authors>Spotware</Authors>

src/OpenAPI.Net/OpenClient.cs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ public async Task Connect()
138138
}
139139
catch(Exception ex)
140140
{
141-
Dispose();
142-
143141
var connectionException = new ConnectionException(ex);
144142

145143
throw connectionException;
@@ -229,9 +227,13 @@ public async Task SendMessage(ProtoMessage message)
229227
/// Use the other SendMessage methods to avoid issues with multiple threads trying to send message at the same time
230228
/// </summary>
231229
/// <param name="message">Message</param>
230+
/// <exception cref="ObjectDisposedException">If client is already disposed</exception>
231+
/// <exception cref="WriteException">If something went wrong while sending the message, please check the inner exception for more detail</exception>
232232
/// <returns>Task</returns>
233233
public async Task SendMessageInstant(ProtoMessage message)
234234
{
235+
ThrowObjectDisposedExceptionIfDisposed();
236+
235237
try
236238
{
237239
var messageByte = message.ToByteArray();
@@ -249,7 +251,9 @@ public async Task SendMessageInstant(ProtoMessage message)
249251
}
250252
catch (Exception ex)
251253
{
252-
OnError(ex);
254+
var writeException = new WriteException(ex);
255+
256+
throw writeException;
253257
}
254258
}
255259

@@ -307,14 +311,7 @@ private async Task ConnectWebScoket()
307311

308312
_webSocketDisconnectionHappenedDisposable = _websocketClient.DisconnectionHappened.Subscribe(OnWebSocketDisconnectionHappened);
309313

310-
try
311-
{
312-
await _websocketClient.StartOrFail();
313-
}
314-
catch (Exception ex)
315-
{
316-
OnError(ex);
317-
}
314+
await _websocketClient.StartOrFail();
318315
}
319316

320317
/// <summary>
@@ -354,7 +351,10 @@ private async Task StartSendingMessages(CancellationToken cancellationToken)
354351
await Task.Delay(_requestDelay - timeElapsedSinceLastMessageSent);
355352
}
356353

357-
await SendMessageInstant(message);
354+
if (IsDisposed is false)
355+
{
356+
await SendMessageInstant(message);
357+
}
358358

359359
if (MessagesQueueCount > 0) MessagesQueueCount -= 1;
360360
}
@@ -434,22 +434,11 @@ private async Task ReadTcp(CancellationToken cancellationToken)
434434
/// <returns>Task</returns>
435435
private async Task WriteTcp(byte[] messageByte, CancellationToken cancellationToken)
436436
{
437-
ThrowObjectDisposedExceptionIfDisposed();
438-
439-
try
440-
{
441-
var data = BitConverter.GetBytes(messageByte.Length).Reverse().Concat(messageByte).ToArray();
437+
var data = BitConverter.GetBytes(messageByte.Length).Reverse().Concat(messageByte).ToArray();
442438

443-
await _sslStream.WriteAsync(data, 0, data.Length, cancellationToken).ConfigureAwait(false);
439+
await _sslStream.WriteAsync(data, 0, data.Length, cancellationToken).ConfigureAwait(false);
444440

445-
await _sslStream.FlushAsync(cancellationToken).ConfigureAwait(false);
446-
}
447-
catch (Exception ex)
448-
{
449-
var writeException = new WriteException(ex);
450-
451-
OnError(writeException);
452-
}
441+
await _sslStream.FlushAsync(cancellationToken).ConfigureAwait(false);
453442
}
454443

455444
/// <summary>

0 commit comments

Comments
 (0)