private void AddDownloadingTask(DownloadInfo info) { var download = HttpDownload.GetTaskByInfo(info); download.DownloadStateChangedEvent += Download_DownloadStateChangedEvent; download.DownloadPercentageChangedEvent += Download_DownloadPercentageChangedEvent; download.Start(); _downloadingTasks.Add(download); }
/// <summary> /// 更新任务数据 /// </summary> /// <param name="info"></param> public void UpdateTask(DownloadInfo info) { if (info == null) { return; } var data = GetDownloadingDataByPath(info.DownloadPath); data.Info = info; data.Save(); }
/// <summary> /// 获取下载任务 /// </summary> /// <param name="info"></param> /// <returns></returns> public static HttpDownload GetTaskByInfo(DownloadInfo info) { return(new HttpDownload() { Url = info.DownloadUrl, DownloadPath = info.DownloadPath, UserCookies = info.UserCookies, Domain = info.Domain, Referer = info.Referer, ThreadNum = info.DownloadBlockList.Count, UserAgent = info.UserAgent, Info = info }); }
/// <summary> /// 创建数据 /// </summary> public async Task <DownloadInfo> CreateData() { return(await Task.Run(() => { var response = GetResponse(); if (response == null) { throw new NullReferenceException("下载链接已失效"); } var info = new DownloadInfo { ContentLength = response.ContentLength, BlockLength = response.ContentLength / ThreadNum, DownloadUrl = Url, DownloadPath = DownloadPath, UserCookies = UserCookies, Domain = Domain, Referer = Referer, UserAgent = UserAgent }; info.init(); return info; })); }
public NextResult(DownloadInfo info, int errorCode, string errorMessage) { Info = info; ErrorCode = errorCode; ErrorMessage = errorMessage; }
public long GetFileIdByDownloadInfo(DownloadInfo info) { return(GetFileIdByPath(info.DownloadPath)); }