public Task <UpdateInfo> Check() { TaskCompletionSource <UpdateInfo> result = new TaskCompletionSource <UpdateInfo>(); WebClient client = BrowserUtils.CreateWebClient(); client.Headers[HttpRequestHeader.Accept] = "application/vnd.github.v3+json"; client.DownloadStringTaskAsync(ApiLatestRelease).ContinueWith(task => { if (task.IsCanceled) { result.SetCanceled(); } else if (task.IsFaulted) { result.SetException(ExpandWebException(task.Exception.InnerException)); } else { try{ result.SetResult(ParseFromJson(task.Result)); }catch (Exception e) { result.SetException(e); } } }); return(result.Task); }
private void SendReport() { AnalyticsReportGenerator.ExternalInfo info = AnalyticsReportGenerator.ExternalInfo.From(browser); Task.Factory.StartNew(() => { AnalyticsReport report = AnalyticsReportGenerator.Create(File, info, plugins); BrowserUtils.CreateWebClient().UploadValues(CollectionUrl, "POST", report.ToNameValueCollection()); }).ContinueWith(task => browser.InvokeAsyncSafe(() => { if (task.Status == TaskStatus.RanToCompletion) { SetLastDataCollectionTime(DateTime.Now); } else if (task.Exception != null) { string message = null; if (task.Exception.InnerException is WebException e) { switch (e.Status) { case WebExceptionStatus.ConnectFailure: message = "Connection Error"; break; case WebExceptionStatus.NameResolutionFailure: message = "DNS Error"; break; case WebExceptionStatus.ProtocolError: HttpWebResponse response = e.Response as HttpWebResponse; message = "HTTP Error " + (response != null ? $"{(int)response.StatusCode} ({response.StatusDescription})" : "(unknown code)"); break; } } ScheduleReportIn(TimeSpan.FromHours(4), message ?? "Error: " + (task.Exception.InnerException?.Message ?? task.Exception.Message)); } })); }