/// <summary> /// A task that encapusulates executeing a single request parseing the result and calling its callback. /// </summary> /// <param name="innerRequest">the innerRequest</param> /// <param name="requestIndex">the index of the request</param> /// <param name="cancellationToken">a cancelation token</param> /// <returns></returns> private async Task ExecuteParseCallbackTask(MultiRequest.InnerRequest innerRequest, int requestIndex, CancellationToken cancellationToken) { ConfigurableHttpClient httpClient = innerRequest.ClientRequest.Service.HttpClient; HttpResponseMessage httpResponseMessage; using (HttpRequestMessage request = innerRequest.ClientRequest.CreateRequest(new bool?())) { httpResponseMessage = await httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); } if (httpResponseMessage.IsSuccessStatusCode) { string responseContent = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); object content = innerRequest.ClientRequest.Service.Serializer.Deserialize(responseContent, innerRequest.ResponseType); innerRequest.OnResponse(content, (RequestError)null, requestIndex, httpResponseMessage); } else { RequestError error = await innerRequest.ClientRequest.Service.DeserializeError(httpResponseMessage).ConfigureAwait(false); innerRequest.OnResponse((object)null, error, requestIndex, httpResponseMessage); } }
/// <summary> /// Queues an individaul request /// </summary> /// <typeparam name="TResponse">The Response type</typeparam> /// <param name="request">The individual request </param> /// <param name="callback">A callback which will be called on request completion</param> public void Queue <TResponse>(IClientServiceRequest request, MultiRequest.OnResponse <TResponse> callback) where TResponse : class { _services.Add(request.Service); var innerRequest = new MultiRequest.InnerRequest <TResponse> { ClientRequest = request, ResponseType = typeof(TResponse), OnResponseCallback = callback }; this._allRequests.Add(innerRequest); }