private void SeekActionDerpian(DownloadAsyncWrapper info, AsyncCompletedEventArgs e, object token) { if ((info != null) && (!info.filelist.IsEmpty)) { DownloadInfo item = info.filelist.TakeFirst(); if (item == null) { this.OnDownloadFileCompleted(new AsyncCompletedEventArgs(e.Error, e.Cancelled, token)); return; } this.OnDownloadFileProgressChanged(new DownloadFileProgressChangedEventArgs(info.filelist.CurrentItemCount, info.filelist.Count)); this.DownloadFileAsyncEx(item.URL, item.Filename, info); } else { this.OnDownloadFileCompleted(new AsyncCompletedEventArgs(e.Error, e.Cancelled, token)); } }
private void InnerWebClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { object token = null; DownloadAsyncWrapper info = null; if (e.UserState != null) { if (e.UserState is DownloadAsyncWrapper) { info = e.UserState as DownloadAsyncWrapper; token = info.userToken; } else { token = e.UserState; } } if (e.Error != null) { if (e.Error is WebException) { WebException ex = e.Error as WebException; if (IsHTTP(this.LastURL)) { if (ex.Response is HttpWebResponse && WorthRetry(ex.Response as HttpWebResponse)) { this.innerWebClient.DownloadFileAsync(this.LastURL, this.downloadfileLocalPath + ".dtmp", e.UserState); } else { this.SeekActionDerpian(info, e, token); } } else { this.SeekActionDerpian(info, e, token); } } else if (e.Error.InnerException is WebException) { WebException ex = e.Error.InnerException as WebException; if (IsHTTP(this.LastURL)) { if (ex.Response is HttpWebResponse && WorthRetry(ex.Response as HttpWebResponse)) { this.innerWebClient.DownloadStringAsync(this.LastURL); } else { this.SeekActionDerpian(info, e, token); } } else { this.SeekActionDerpian(info, e, token); } } else { this.SeekActionDerpian(info, e, token); } } else if (e.Cancelled) { this.OnDownloadFileCompleted(new AsyncCompletedEventArgs(e.Error, e.Cancelled, token)); } else { try { File.Delete(this.downloadfileLocalPath); File.Move(this.downloadfileLocalPath + ".dtmp", this.downloadfileLocalPath); } catch (Exception ex) { Log.LogManager.GeneralLog.Print(ex); } this.SeekActionDerpian(info, e, token); } }