Exemple #1
0
 /// <summary>
 /// 检查DownloadTask是否正确(不包括TaskID)
 /// </summary>
 /// <returns></returns>
 public static bool Check(DownloadTask downloadTask)
 {
     if (NetWorkHelp.CanConnection(downloadTask.Url) == true &&
         PathHelp.IsRightForRegex(downloadTask.Path))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #2
0
 /// <summary>
 /// 创建一个DownloadTask(不包括ID)
 /// </summary>
 /// <param name="url"></param>
 /// <param name="path"></param>
 public static DownloadTask Create(string url, string path, MultiDownload target)
 {
     if (NetWorkHelp.CanConnection(url))    //链接是否可以连接
     {                                      //是
         if (path[path.Length - 1] != '\\') //为了修复Path.Combine方法的缺陷,防止路径合并错误
         {
             path = path + '\\';
         }
         //获取下载路径
         string       downloadPath = System.IO.Path.Combine(path + System.IO.Path.GetFileName(HttpUtility.UrlDecode(url))); //合并路径
         DownloadTask downloadTask = new DownloadTask(target);                                                              //新建下载任务
         downloadTask.Path  = downloadPath;                                                                                 //将路径赋值
         downloadTask.Url   = url;                                                                                          //将链接赋值
         downloadTask.State = DownloadTaskState.Waiting;
         return(downloadTask);
     }
     else
     {                                                //否
         throw new UrlCanNotConnectionException(url); //抛出连接无法连接错误
     }
 }