public override void Download()
 {
     if (Downloading)
     {
         throw new Exception("Can't download, since the previous download is not complete.");
     }
     DoneSize      = 0;
     Success       = false;
     IsCancelled   = false;
     Error         = null;
     Downloading   = true;
     SliceFileName = null;
     SliceList     = null;
     bigfile       = null;
     try
     {
         SliceFileName = "download-" + from.md5 + ".slice";
         SliceFileName = Path.Combine(Path.Combine(WorkFolder, pcs.getUID()), SliceFileName);
         StateFileNameDecideEventArgs args = new StateFileNameDecideEventArgs()
         {
             SliceFileName = SliceFileName
         };
         fireStateFileNameDecide(args);
         SliceFileName = args.SliceFileName;
         CreateOrRestoreSliceList();                 // 创建或还原分片列表
         CreateDirectory(to);                        //创建目录
         CreateLocalFile();                          // 如果需要则创建本地文件
         bigfile = new BigFileHelper(to, from.size); //映射文件到内存
         foreach (Slice slice in SliceList)
         {
             if (slice.status != SliceStatus.Successed)
             {
                 slice.status   = SliceStatus.Pending; //重新下载未成功的分片
                 slice.doneSize = 0;
             }
             else
             {
                 DoneSize += slice.doneSize;
             }
         }
         DownloadSliceList(); // 启动线程来下载分片
         Wait();              // 等待所有线程退出
         CheckResult();       // 检查下载结果
     }
     catch (Exception ex)
     {
         Success     = false;
         IsCancelled = false;
         Error       = ex;
     }
     if (bigfile != null)
     {
         bigfile.Dispose();
         bigfile = null;
     }
     if (Success)
     {
         SliceHelper.DeleteSliceFile(SliceFileName);
     }
     Downloading = false;
     fireCompleted(new CompletedEventArgs(Success, IsCancelled, Error));
 }
 public override void Download()
 {
     if (Downloading)
         throw new Exception("Can't download, since the previous download is not complete.");
     DoneSize = 0;
     Success = false;
     IsCancelled = false;
     Error = null;
     Downloading = true;
     SliceFileName = null;
     SliceList = null;
     bigfile = null;
     try
     {
         SliceFileName = "download-" + from.md5 + ".slice";
         SliceFileName = Path.Combine(Path.Combine(WorkFolder, pcs.getUID()), SliceFileName);
         StateFileNameDecideEventArgs args = new StateFileNameDecideEventArgs()
         {
             SliceFileName = SliceFileName
         };
         fireStateFileNameDecide(args);
         SliceFileName = args.SliceFileName;
         CreateOrRestoreSliceList(); // 创建或还原分片列表
         CreateLocalFile(); // 如果需要则创建本地文件
         bigfile = new BigFileHelper(to); //映射文件到内存
         foreach (Slice slice in SliceList)
         {
             if (slice.status != SliceStatus.Successed)
             {
                 slice.status = SliceStatus.Pending; //重新下载未成功的分片
                 slice.doneSize = 0;
             }
             else
             {
                 DoneSize += slice.doneSize;
             }
         }
         DownloadSliceList(); // 启动线程来下载分片
         Wait(); // 等待所有线程退出
         CheckResult(); // 检查下载结果
     }
     catch (Exception ex)
     {
         Success = false;
         IsCancelled = false;
         Error = ex;
     }
     if (bigfile != null)
     {
         bigfile.Dispose();
         bigfile = null;
     }
     if (Success)
         SliceHelper.DeleteSliceFile(SliceFileName);
     Downloading = false;
     fireCompleted(new CompletedEventArgs(Success, IsCancelled, Error));
 }