Skip to content

Commit fe1e42d

Browse files
authored
Merge pull request ArangoDB-Community#404 from ArangoDB-Community/feature-3.8/DE-25-add-async-serialization-methods
Added async serialization methods
2 parents c5efe09 + 72a097d commit fe1e42d

File tree

19 files changed

+398
-327
lines changed

19 files changed

+398
-327
lines changed

arangodb-net-standard/AdminApi/AdminApiClient.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public virtual async Task<GetLogsResponse> GetLogsAsync(GetLogsQuery query = nul
7070
if (response.IsSuccessStatusCode)
7171
{
7272
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
73-
return DeserializeJsonFromStream<GetLogsResponse>(stream);
73+
return await DeserializeJsonFromStreamAsync<GetLogsResponse>(stream).ConfigureAwait(false);
7474
}
75-
throw await GetApiErrorException(response).ConfigureAwait(false);
75+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
7676
}
7777
}
7878

@@ -96,7 +96,7 @@ public virtual async Task<bool> PostReloadRoutingInfoAsync(CancellationToken tok
9696
{
9797
return true;
9898
}
99-
throw await GetApiErrorException(response).ConfigureAwait(false);
99+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
100100
}
101101
}
102102

@@ -119,9 +119,9 @@ public virtual async Task<GetServerIdResponse> GetServerIdAsync(CancellationToke
119119
if (response.IsSuccessStatusCode)
120120
{
121121
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
122-
return DeserializeJsonFromStream<GetServerIdResponse>(stream);
122+
return await DeserializeJsonFromStreamAsync<GetServerIdResponse>(stream).ConfigureAwait(false);
123123
}
124-
throw await GetApiErrorException(response).ConfigureAwait(false);
124+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
125125
}
126126
}
127127

@@ -143,9 +143,9 @@ public virtual async Task<GetServerRoleResponse> GetServerRoleAsync(Cancellation
143143
if (response.IsSuccessStatusCode)
144144
{
145145
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
146-
return DeserializeJsonFromStream<GetServerRoleResponse>(stream);
146+
return await DeserializeJsonFromStreamAsync<GetServerRoleResponse>(stream).ConfigureAwait(false);
147147
}
148-
throw await GetApiErrorException(response).ConfigureAwait(false);
148+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
149149
}
150150
}
151151

@@ -167,9 +167,9 @@ public virtual async Task<GetServerEngineTypeResponse> GetServerEngineTypeAsync(
167167
if (response.IsSuccessStatusCode)
168168
{
169169
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
170-
return DeserializeJsonFromStream<GetServerEngineTypeResponse>(stream);
170+
return await DeserializeJsonFromStreamAsync<GetServerEngineTypeResponse>(stream).ConfigureAwait(false);
171171
}
172-
throw await GetApiErrorException(response).ConfigureAwait(false);
172+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
173173
}
174174
}
175175

@@ -196,9 +196,9 @@ public virtual async Task<GetServerVersionResponse> GetServerVersionAsync(GetSer
196196
if (response.IsSuccessStatusCode)
197197
{
198198
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
199-
return DeserializeJsonFromStream<GetServerVersionResponse>(stream);
199+
return await DeserializeJsonFromStreamAsync<GetServerVersionResponse>(stream).ConfigureAwait(false);
200200
}
201-
throw await GetApiErrorException(response).ConfigureAwait(false);
201+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
202202
}
203203
}
204204

@@ -220,9 +220,9 @@ public virtual async Task<GetLicenseResponse> GetLicenseAsync(CancellationToken
220220
if (response.IsSuccessStatusCode)
221221
{
222222
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
223-
return DeserializeJsonFromStream<GetLicenseResponse>(stream);
223+
return await DeserializeJsonFromStreamAsync<GetLicenseResponse>(stream).ConfigureAwait(false);
224224
}
225-
throw await GetApiErrorException(response).ConfigureAwait(false);
225+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
226226
}
227227
}
228228

@@ -245,15 +245,15 @@ public virtual async Task<PutLicenseResponse> PutLicenseAsync(string licenseKey,
245245
{
246246
uri += '?' + query.ToQueryString();
247247
}
248-
var content = GetContent(licenseKey, new ApiClientSerializationOptions(true, true));
248+
var content = await GetContentAsync(licenseKey, new ApiClientSerializationOptions(true, true));
249249
using (var response = await _client.PutAsync(uri, content, token: token).ConfigureAwait(false))
250250
{
251251
if (response.IsSuccessStatusCode)
252252
{
253253
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
254-
return DeserializeJsonFromStream<PutLicenseResponse>(stream);
254+
return await DeserializeJsonFromStreamAsync<PutLicenseResponse>(stream).ConfigureAwait(false);
255255
}
256-
throw await GetApiErrorException(response).ConfigureAwait(false);
256+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
257257
}
258258
}
259259
}

arangodb-net-standard/AnalyzerApi/AnalyzerApiClient.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public virtual async Task<GetAllAnalyzersResponse> GetAllAnalyzersAsync(Cancella
6262
if (response.IsSuccessStatusCode)
6363
{
6464
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
65-
return DeserializeJsonFromStream<GetAllAnalyzersResponse>(stream);
65+
return await DeserializeJsonFromStreamAsync<GetAllAnalyzersResponse>(stream).ConfigureAwait(false);
6666
}
67-
throw await GetApiErrorException(response).ConfigureAwait(false);
67+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
6868
}
6969
}
7070

@@ -82,15 +82,15 @@ public virtual async Task<Analyzer> PostAnalyzerAsync(Analyzer body, Cancellatio
8282
throw new ArgumentException("body is required", nameof(body));
8383
}
8484
var uri = _analyzerApiPath;
85-
var content = GetContent(body, new ApiClientSerializationOptions(true, true));
85+
var content = await GetContentAsync(body, new ApiClientSerializationOptions(true, true)).ConfigureAwait(false);
8686
using (var response = await _client.PostAsync(uri, content, null, token).ConfigureAwait(false))
8787
{
8888
if (response.IsSuccessStatusCode)
8989
{
9090
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
91-
return DeserializeJsonFromStream<Analyzer>(stream);
91+
return await DeserializeJsonFromStreamAsync<Analyzer>(stream).ConfigureAwait(false);
9292
}
93-
throw await GetApiErrorException(response).ConfigureAwait(false);
93+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
9494
}
9595
}
9696

@@ -113,9 +113,9 @@ public virtual async Task<GetAnalyzerResponse> GetAnalyzerAsync(string analyzerN
113113
if (response.IsSuccessStatusCode)
114114
{
115115
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
116-
return DeserializeJsonFromStream<GetAnalyzerResponse>(stream);
116+
return await DeserializeJsonFromStreamAsync<GetAnalyzerResponse>(stream).ConfigureAwait(false);
117117
}
118-
throw await GetApiErrorException(response).ConfigureAwait(false);
118+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
119119
}
120120
}
121121

@@ -138,9 +138,9 @@ public virtual async Task<DeleteAnalyzerResponse> DeleteAnalyzerAsync(string ana
138138
if (response.IsSuccessStatusCode)
139139
{
140140
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
141-
return DeserializeJsonFromStream<DeleteAnalyzerResponse>(stream);
141+
return await DeserializeJsonFromStreamAsync<DeleteAnalyzerResponse>(stream).ConfigureAwait(false);
142142
}
143-
throw await GetApiErrorException(response).ConfigureAwait(false);
143+
throw await GetApiErrorExceptionAsync(response).ConfigureAwait(false);
144144
}
145145
}
146146
}

arangodb-net-standard/ApiClientBase.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public ApiClientBase(IApiClientSerialization serialization)
2525
/// </summary>
2626
/// <param name="response">The error response from ArangoDB.</param>
2727
/// <returns></returns>
28-
protected async Task<ApiErrorException> GetApiErrorException(IApiClientResponse response)
28+
protected async Task<ApiErrorException> GetApiErrorExceptionAsync(IApiClientResponse response)
2929
{
3030
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
3131
try
3232
{
33-
var error = _serialization.DeserializeFromStream<ApiErrorResponse>(stream);
33+
var error = await _serialization.DeserializeFromStreamAsync<ApiErrorResponse>(stream).ConfigureAwait(false);
3434
return new ApiErrorException(error);
3535
}
3636
catch (Exception e)
@@ -54,35 +54,35 @@ protected void ValidateDocumentId(string documentId)
5454
}
5555
}
5656

57-
protected T DeserializeJsonFromStream<T>(Stream stream)
57+
protected async Task<T> DeserializeJsonFromStreamAsync<T>(Stream stream)
5858
{
5959
try
6060
{
61-
return _serialization.DeserializeFromStream<T>(stream);
61+
return await _serialization.DeserializeFromStreamAsync<T>(stream).ConfigureAwait(false);
6262
}
6363
catch (Exception e)
6464
{
6565
throw new SerializationException($"An error occured while Deserializing the data response from Arango. See InnerException for more details.", e);
6666
}
6767
}
6868

69-
protected byte[] GetContent<T>(T item, ApiClientSerializationOptions serializationOptions)
69+
protected async Task<byte[]> GetContentAsync<T>(T item, ApiClientSerializationOptions serializationOptions)
7070
{
7171
try
7272
{
73-
return _serialization.Serialize(item, serializationOptions);
73+
return await _serialization.SerializeAsync(item, serializationOptions).ConfigureAwait(false);
7474
}
7575
catch (Exception e)
7676
{
7777
throw new SerializationException($"A serialization error occured while preparing a request for Arango. See InnerException for more details.", e);
7878
}
7979
}
8080

81-
protected string GetContentString<T>(T item, ApiClientSerializationOptions serializationOptions)
81+
protected async Task<string> GetContentStringAsync<T>(T item, ApiClientSerializationOptions serializationOptions)
8282
{
8383
try
8484
{
85-
return _serialization.SerializeToString(item, serializationOptions);
85+
return await _serialization.SerializeToStringAsync(item, serializationOptions).ConfigureAwait(false);
8686
}
8787
catch (Exception e)
8888
{

0 commit comments

Comments
 (0)