private void AddDownloadingTask(DownloadInfo info)
        {
            var download = HttpDownload.GetTaskByInfo(info);

            download.DownloadStateChangedEvent      += Download_DownloadStateChangedEvent;
            download.DownloadPercentageChangedEvent += Download_DownloadPercentageChangedEvent;
            download.Start();
            _downloadingTasks.Add(download);
        }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
0
 /// <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
     });
 }
Esempio n. 4
0
 /// <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;
     }));
 }
Esempio n. 5
0
 public NextResult(DownloadInfo info, int errorCode, string errorMessage)
 {
     Info         = info;
     ErrorCode    = errorCode;
     ErrorMessage = errorMessage;
 }
Esempio n. 6
0
 public long GetFileIdByDownloadInfo(DownloadInfo info)
 {
     return(GetFileIdByPath(info.DownloadPath));
 }