Skip to content

Commit e710328

Browse files
author
Ahmad Noman Musleh
committed
Added usings to ReadTcp CancellationTokenSources
1 parent fc1f813 commit e710328

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/OpenAPI.Net/Auth/TokenFactory.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ public static async Task<Token> GetToken(string authCode, App app, HttpClient cl
8181
throw new HttpRequestException($"{response.StatusCode}, The HTTP request for getting access token was not successful");
8282
}
8383

84+
/// <summary>
85+
/// Returns the URI for getting access token
86+
/// </summary>
87+
/// <param name="authCode">The authentication code</param>
88+
/// <param name="app">API application</param>
89+
/// <param name="authUri">The auth URI base path</param>
90+
/// <returns>Uri</returns>
8491
public static Uri GetUri(string authCode, App app, string authUri = ApiInfo.AuthUrl)
8592
{
8693
var query = new NameValueCollection
@@ -95,6 +102,12 @@ public static Uri GetUri(string authCode, App app, string authUri = ApiInfo.Auth
95102
return new Uri($"{authUri}token{query}");
96103
}
97104

105+
/// <summary>
106+
/// Deserializes a JSON token response to Token object
107+
/// </summary>
108+
/// <param name="json">JSON response</param>
109+
/// <returns>Token</returns>
110+
/// <exception cref="JsonException"></exception>
98111
public static Token DeserializeToken(string json)
99112
{
100113
var token = JsonSerializer.Deserialize<Token>(json);

src/OpenAPI.Net/OpenClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ private async Task ConnectTcp()
331331

332332
await _sslStream.AuthenticateAsClientAsync(Host).ConfigureAwait(false);
333333

334-
_ = ReadTcp(_cancellationTokenSource.Token);
334+
_ = ReadTcp();
335335
}
336336

337337
/// <summary>
@@ -373,7 +373,7 @@ private async Task StartSendingMessages(CancellationToken cancellationToken)
373373
/// This method will read the TCP stream for incoming messages
374374
/// </summary>
375375
/// <returns>Task</returns>
376-
private async Task ReadTcp(CancellationToken cancellationToken)
376+
private async Task ReadTcp()
377377
{
378378
try
379379
{
@@ -387,7 +387,7 @@ private async Task ReadTcp(CancellationToken cancellationToken)
387387
{
388388
var count = lengthArray.Length - readBytes;
389389

390-
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));
390+
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));
391391

392392
readBytes += await _sslStream.ReadAsync(lengthArray, readBytes, count, cancellationTokenSource.Token).ConfigureAwait(false);
393393
}
@@ -407,7 +407,7 @@ private async Task ReadTcp(CancellationToken cancellationToken)
407407
{
408408
var count = data.Length - readBytes;
409409

410-
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));
410+
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20));
411411

412412
readBytes += await _sslStream.ReadAsync(data, readBytes, count, cancellationTokenSource.Token).ConfigureAwait(false);
413413
}

0 commit comments

Comments
 (0)