Skip to content

Commit

Permalink
Apply some R# suggestions and disable other (in backported code).
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegRa committed Nov 16, 2024
1 parent 5671cd6 commit 78fa914
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
18 changes: 16 additions & 2 deletions Alpaca.Markets.Extensions/Reconnection/ClientWithReconnectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,21 @@ protected virtual ValueTask OnReconnection(
CancellationToken cancellationToken) =>
new(); // DO nothing by default for auto-resubscribed clients.

private async void handleSocketClosed() =>
await handleSocketClosedAsync().ConfigureAwait(false);

[SuppressMessage(
"Design", "CA1031:Do not catch general exception types",
Justification = "Expected behavior - we report exceptions via OnError event.")]
private async void handleSocketClosed()
{
try
{
await handleSocketClosedAsync().ConfigureAwait(false);
}
catch (Exception exception)
{
handleOnError(exception);
}
}

[SuppressMessage(
"Design", "CA1031:Do not catch general exception types",
Expand Down Expand Up @@ -174,6 +187,7 @@ await OnReconnection(_cancellationTokenSource.Token)
[SuppressMessage(
"Design", "CA1031:Do not catch general exception types",
Justification = "Expected behavior - we report exceptions via OnError event.")]
// ReSharper disable once AsyncVoidMethod
private async void handleOnError(
Exception exception)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Alpaca.Markets.Extensions;
using System.Diagnostics;

namespace Alpaca.Markets.Extensions;

internal sealed class DisposableAlpacaDataSubscription<TItem> :
IDisposableAlpacaDataSubscription<TItem>
Expand Down Expand Up @@ -39,8 +41,20 @@ public event Action<TItem>? Received
remove => _subscription.Received -= value;
}

public async void Dispose() =>
await DisposeAsync().ConfigureAwait(false);
[SuppressMessage(
"Design", "CA1031:Do not catch general exception types",
Justification = "Expected behavior - we report exceptions via OnError event.")]
public async void Dispose()
{
try
{
await DisposeAsync().ConfigureAwait(false);
}
catch (Exception exception)
{
Trace.TraceInformation(exception.Message);
}
}

public async ValueTask DisposeAsync()
{
Expand Down
23 changes: 17 additions & 6 deletions Alpaca.Markets/AlpacaStreamingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,27 @@ internal AlpacaStreamingClient(
/// <inheritdoc cref="IAlpacaStreamingClient.OnTradeUpdate"/>
public event Action<ITradeUpdate>? OnTradeUpdate;


[SuppressMessage(
"Design", "CA1031:Do not catch general exception types",
Justification = "Expected behavior - we report exceptions via OnError event.")]
protected override async void OnOpened()
{
await SendAsJsonStringAsync(new JsonAuthRequest
try
{
Action = JsonAction.Authenticate,
Data = Configuration.SecurityId
.GetAuthenticationData()
}).ConfigureAwait(false);
await SendAsJsonStringAsync(new JsonAuthRequest
{
Action = JsonAction.Authenticate,
Data = Configuration.SecurityId
.GetAuthenticationData()
}).ConfigureAwait(false);

base.OnOpened();
base.OnOpened();
}
catch (Exception exception)
{
HandleError(exception);
}
}

[SuppressMessage(
Expand Down
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "8.0.404"
}
}

0 comments on commit 78fa914

Please sign in to comment.