/// <summary> /// Asynchronously queries this method with the provided ID and HTTP POST data. /// </summary> /// <typeparam name="T">The subtype to deserialize (the deserialized type being <see cref="CCPAPIResult{T}" />).</typeparam> /// <param name="method">The method to query</param> /// <param name="callback">The callback to invoke once the query has been completed.</param> /// <param name="state">State to be passed to the callback when it is used.</param> /// <param name="data">The parameters to use for the request, including the token, arguments, and POST data.</param> /// <exception cref="System.ArgumentNullException">callback; The callback cannot be null.</exception> private void QueryEsiAsync <T>(Enum method, ESIRequestCallback <T> callback, object state, EsiParams data) where T : class { // Check callback not null callback.ThrowIfNull(nameof(callback), "The callback cannot be null."); // Lazy download Uri url = GetESIUrl(method, data.ParamOne, data.ParamTwo, data.GetData); Util.DownloadJsonAsync <T>(url, data.Token, SupportsCompressedResponse, data.PostData) .ContinueWith(task => { var esiResult = new EsiResult <T>(task.Result); // Sync clock on the answer if necessary var sync = esiResult.Result as ISynchronizableWithLocalClock; if (sync != null) { sync.SynchronizeWithLocalClock(DateTime.UtcNow - esiResult.CurrentTime); } // Invokes the callback Dispatcher.Invoke(() => callback.Invoke(esiResult, state)); }); }
/// <summary> /// Asynchronously queries this method, fetching all pages if necessary, with the /// provided request data. /// </summary> /// <typeparam name="T">The subtype to deserialize (the deserialized type being /// <see cref="CCPAPIResult{T}" />). It must be a collection type of U!</typeparam> /// <typeparam name="U">The item type to deserialize.</typeparam> /// <param name="method">The method to query</param> /// <param name="callback">The callback to invoke once the query has been completed. /// </param> /// <param name="data">The parameters to use for the request, including the token, /// arguments, and POST data.</param> /// <param name="state">State to be passed to the callback when it is used.</param> /// <exception cref="System.ArgumentNullException">callback; The callback cannot be /// null.</exception> public void QueryPagedEsi <T, U>(Enum method, ESIRequestCallback <T> callback, ESIParams data, object state = null) where T : List <U> where U : class { callback.ThrowIfNull(nameof(callback), "The callback cannot be null."); Uri url = GetESIUrl(method, data); Util.DownloadJsonAsync <T>(url, GetRequestParams(data)).ContinueWith(task => { var esiResult = GetESIResult(task.Result); // Check page count int pages = esiResult.Response.Pages; if (pages > 1 && esiResult.HasData && !esiResult.HasError) { // Fetch the other pages QueryEsiPageHelper(method, callback, data, new PageInfo <T, U>(esiResult, pages, state)); } else { // Invokes the callback Dispatcher.Invoke(() => callback.Invoke(esiResult, state)); } }); }
/// <summary> /// Asynchronously queries this method with the provided ID and HTTP POST data. /// </summary> /// <typeparam name="T">The subtype to deserialize (the deserialized type being /// <see cref="CCPAPIResult{T}" />).</typeparam> /// <param name="method">The method to query</param> /// <param name="callback">The callback to invoke once the query has been completed. /// </param> /// <param name="data">The parameters to use for the request, including the token, /// arguments, and POST data.</param> /// <param name="state">State to be passed to the callback when it is used.</param> /// <exception cref="System.ArgumentNullException">callback; The callback cannot be /// null.</exception> public void QueryEsi <T>(Enum method, ESIRequestCallback <T> callback, ESIParams data, object state = null) where T : class { var response = data.LastResponse; // Check callback not null callback.ThrowIfNull(nameof(callback), "The callback cannot be null."); Uri url = GetESIUrl(method, data.ParamOne, data.ParamTwo, data.GetData); Util.DownloadJsonAsync <T>(url, new RequestParams(data.PostData) { Authentication = data.Token, AcceptEncoded = SupportsCompressedResponse, ETag = response?.ETag, IfModifiedSince = response?.Expires }).ContinueWith(task => { var esiResult = new EsiResult <T>(task.Result); // Sync clock on the answer if necessary and provided var sync = esiResult.Result as ISynchronizableWithLocalClock; DateTime?when = esiResult.CurrentTime; if (sync != null && when != null) { sync.SynchronizeWithLocalClock(DateTime.UtcNow - (DateTime)when); } // Invokes the callback Dispatcher.Invoke(() => callback.Invoke(esiResult, state)); }); }
/// <summary> /// Asynchronously queries this method with the provided request data. /// </summary> /// <typeparam name="T">The subtype to deserialize (the deserialized type being /// <see cref="CCPAPIResult{T}" />).</typeparam> /// <param name="method">The method to query</param> /// <param name="callback">The callback to invoke once the query has been completed. /// </param> /// <param name="data">The parameters to use for the request, including the token, /// arguments, and POST data.</param> /// <param name="state">State to be passed to the callback when it is used.</param> /// <exception cref="System.ArgumentNullException">callback; The callback cannot be /// null.</exception> public void QueryEsi <T>(Enum method, ESIRequestCallback <T> callback, ESIParams data, object state = null) where T : class { callback.ThrowIfNull(nameof(callback), "The callback cannot be null."); Uri url = GetESIUrl(method, data); Util.DownloadJsonAsync <T>(url, GetRequestParams(data)).ContinueWith(task => { // Invokes the callback Dispatcher.Invoke(() => callback.Invoke(GetESIResult(task.Result), state)); }); }