private void webClientDownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { TotalRequestCount++; TotalRequestTime += DateTime.Now - lastAccessTime.Value; TvdbDelegates delegates = e.UserState as TvdbDelegates; delegates.AsyncHandler(null, new TvdbAsyncEventArgs(delegates.JsonHandler(Encoding.UTF8.GetString(e.Result)))); }
private object getData(string url, string languageCode, TvdbDelegates delegates) { webClient = getWebClient(languageCode); if (delegates.AsyncHandler != null) { checkRequestRate(); webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(webClientDownloadDataCompleted); webClient.DownloadDataAsync(new Uri(url), delegates); return(null); } else { try { checkRequestRate(); byte[] response = webClient.DownloadData(new Uri(url)); TotalRequestCount++; TotalRequestTime += DateTime.Now - lastAccessTime.Value; return(delegates.JsonHandler(Encoding.UTF8.GetString(response))); } catch (WebException e) { if (webClient.ResponseHeaders != null) { ResponseKeys = new StringDictionary(); for (int index = 0; index < webClient.ResponseHeaders.Count; index++) { string header = webClient.ResponseHeaders.GetKey(index); string[] values = webClient.ResponseHeaders.GetValues(index); if (values != null) { foreach (string headerValue in values) { ResponseKeys.Add(header, headerValue); } } } } if (e.Message.Contains("404")) { return(null); } throw; } } }