protected internal static async Task <TResponse> QueryGoogleAPI(TRequest request, TimeSpan timeout) { if (request == null) { throw new ArgumentNullException("request"); } var uri = request.GetUri(); if (OnUriCreated != null) { uri = OnUriCreated(uri); } var data = await new HttpClient().DownloadDataTaskAsync(uri, timeout).ConfigureAwait(false); OnRawResponseRecivied?.Invoke(data); return(Deserialize(data)); }
private static void DownloadDataComplete(Task <byte[]> task, TaskCompletionSource <TResponse> completionSource) { if (task.IsCanceled) { completionSource.SetCanceled(); } else if (task.IsFaulted) { if (IndicatesAuthenticationFailed(task.Exception.InnerException)) { completionSource.SetException(new AuthenticationException(AuthenticationFailedMessage, task.Exception.InnerException)); } else { completionSource.SetException(task.Exception.InnerException); } } else { OnRawResponseRecivied?.Invoke(task.Result); completionSource.SetResult(Deserialize(task.Result)); } }