mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 08:26:20 +00:00
Added options to pass a JsonSerializer to the SendRequest method to use for deserialization
This commit is contained in:
parent
93a64b2b1d
commit
8adebea929
@ -2771,7 +2771,7 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns>The roundtrip time of the ping request</returns>
|
<returns>The roundtrip time of the ping request</returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:CryptoExchange.Net.RestClient.SendRequest``1(System.Uri,System.Net.Http.HttpMethod,System.Threading.CancellationToken,System.Collections.Generic.Dictionary{System.String,System.Object},System.Boolean,System.Boolean,System.Nullable{CryptoExchange.Net.Objects.PostParameters},System.Nullable{CryptoExchange.Net.Objects.ArrayParametersSerialization},System.Int32)">
|
<member name="M:CryptoExchange.Net.RestClient.SendRequest``1(System.Uri,System.Net.Http.HttpMethod,System.Threading.CancellationToken,System.Collections.Generic.Dictionary{System.String,System.Object},System.Boolean,System.Boolean,System.Nullable{CryptoExchange.Net.Objects.PostParameters},System.Nullable{CryptoExchange.Net.Objects.ArrayParametersSerialization},System.Int32,Newtonsoft.Json.JsonSerializer)">
|
||||||
<summary>
|
<summary>
|
||||||
Execute a request
|
Execute a request
|
||||||
</summary>
|
</summary>
|
||||||
@ -2784,13 +2784,16 @@
|
|||||||
<param name="checkResult">Whether or not the resulting object should be checked for missing properties in the mapping (only outputs if log verbosity is Debug)</param>
|
<param name="checkResult">Whether or not the resulting object should be checked for missing properties in the mapping (only outputs if log verbosity is Debug)</param>
|
||||||
<param name="postPosition">Where the post parameters should be placed</param>
|
<param name="postPosition">Where the post parameters should be placed</param>
|
||||||
<param name="arraySerialization">How array parameters should be serialized</param>
|
<param name="arraySerialization">How array parameters should be serialized</param>
|
||||||
|
<param name="credits">Credits used for the request</param>
|
||||||
|
<param name="deserializer">The JsonSerializer to use for deserialization</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:CryptoExchange.Net.RestClient.GetResponse``1(CryptoExchange.Net.Interfaces.IRequest,System.Threading.CancellationToken)">
|
<member name="M:CryptoExchange.Net.RestClient.GetResponse``1(CryptoExchange.Net.Interfaces.IRequest,Newtonsoft.Json.JsonSerializer,System.Threading.CancellationToken)">
|
||||||
<summary>
|
<summary>
|
||||||
Executes the request and returns the string result
|
Executes the request and returns the string result
|
||||||
</summary>
|
</summary>
|
||||||
<param name="request">The request object to execute</param>
|
<param name="request">The request object to execute</param>
|
||||||
|
<param name="deserializer">The JsonSerializer to use for deserialization</param>
|
||||||
<param name="cancellationToken">Cancellation token</param>
|
<param name="cancellationToken">Cancellation token</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
@ -169,10 +169,14 @@ namespace CryptoExchange.Net
|
|||||||
/// <param name="checkResult">Whether or not the resulting object should be checked for missing properties in the mapping (only outputs if log verbosity is Debug)</param>
|
/// <param name="checkResult">Whether or not the resulting object should be checked for missing properties in the mapping (only outputs if log verbosity is Debug)</param>
|
||||||
/// <param name="postPosition">Where the post parameters should be placed</param>
|
/// <param name="postPosition">Where the post parameters should be placed</param>
|
||||||
/// <param name="arraySerialization">How array parameters should be serialized</param>
|
/// <param name="arraySerialization">How array parameters should be serialized</param>
|
||||||
|
/// <param name="credits">Credits used for the request</param>
|
||||||
|
/// <param name="deserializer">The JsonSerializer to use for deserialization</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[return: NotNull]
|
[return: NotNull]
|
||||||
protected virtual async Task<WebCallResult<T>> SendRequest<T>(Uri uri, HttpMethod method, CancellationToken cancellationToken,
|
protected virtual async Task<WebCallResult<T>> SendRequest<T>(Uri uri, HttpMethod method, CancellationToken cancellationToken,
|
||||||
Dictionary<string, object>? parameters = null, bool signed = false, bool checkResult = true, PostParameters? postPosition = null, ArrayParametersSerialization? arraySerialization = null, int credits=1) where T : class
|
Dictionary<string, object>? parameters = null, bool signed = false, bool checkResult = true,
|
||||||
|
PostParameters? postPosition = null, ArrayParametersSerialization? arraySerialization = null, int credits = 1,
|
||||||
|
JsonSerializer? deserializer = null) where T : class
|
||||||
{
|
{
|
||||||
var requestId = NextId();
|
var requestId = NextId();
|
||||||
log.Write(LogVerbosity.Debug, $"[{requestId}] Creating request for " + uri);
|
log.Write(LogVerbosity.Debug, $"[{requestId}] Creating request for " + uri);
|
||||||
@ -201,16 +205,17 @@ namespace CryptoExchange.Net
|
|||||||
paramString = " with request body " + request.Content;
|
paramString = " with request body " + request.Content;
|
||||||
|
|
||||||
log.Write(LogVerbosity.Debug, $"[{requestId}] Sending {method}{(signed ? " signed" : "")} request to {request.Uri}{paramString ?? " "}{(apiProxy == null ? "" : $" via proxy {apiProxy.Host}")}");
|
log.Write(LogVerbosity.Debug, $"[{requestId}] Sending {method}{(signed ? " signed" : "")} request to {request.Uri}{paramString ?? " "}{(apiProxy == null ? "" : $" via proxy {apiProxy.Host}")}");
|
||||||
return await GetResponse<T>(request, cancellationToken).ConfigureAwait(false);
|
return await GetResponse<T>(request, deserializer, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the request and returns the string result
|
/// Executes the request and returns the string result
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request">The request object to execute</param>
|
/// <param name="request">The request object to execute</param>
|
||||||
|
/// <param name="deserializer">The JsonSerializer to use for deserialization</param>
|
||||||
/// <param name="cancellationToken">Cancellation token</param>
|
/// <param name="cancellationToken">Cancellation token</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected virtual async Task<WebCallResult<T>> GetResponse<T>(IRequest request, CancellationToken cancellationToken)
|
protected virtual async Task<WebCallResult<T>> GetResponse<T>(IRequest request, JsonSerializer? deserializer, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -238,12 +243,12 @@ namespace CryptoExchange.Net
|
|||||||
if (error != null)
|
if (error != null)
|
||||||
return WebCallResult<T>.CreateErrorResult(response.StatusCode, response.ResponseHeaders, error);
|
return WebCallResult<T>.CreateErrorResult(response.StatusCode, response.ResponseHeaders, error);
|
||||||
|
|
||||||
var deserializeResult = Deserialize<T>(parseResult.Data, null, null, request.RequestId);
|
var deserializeResult = Deserialize<T>(parseResult.Data, null, deserializer, request.RequestId);
|
||||||
return new WebCallResult<T>(response.StatusCode, response.ResponseHeaders, deserializeResult.Data, deserializeResult.Error);
|
return new WebCallResult<T>(response.StatusCode, response.ResponseHeaders, deserializeResult.Data, deserializeResult.Error);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var desResult = await Deserialize<T>(responseStream, null, request.RequestId, sw.ElapsedMilliseconds).ConfigureAwait(false);
|
var desResult = await Deserialize<T>(responseStream, deserializer, request.RequestId, sw.ElapsedMilliseconds).ConfigureAwait(false);
|
||||||
responseStream.Close();
|
responseStream.Close();
|
||||||
response.Close();
|
response.Close();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user