Пример #1
0
        private void download(OperationInfo op)
        {
            Downloader  d = null;
            PcsFileInfo from;

            try
            {
                fireOnProgress(op); // 触发一次进度改变
                from = pcs.meta(op.from);
                if (from.IsEmpty)
                {
                    op.status = OperationStatus.Fail;
                    op.errmsg = "The remote file not exists (" + from.path + ").";
                }
                else if (from.isdir)
                {
                    op.status = OperationStatus.Fail;
                    op.errmsg = "Can't download directory (" + from.path + ").";
                }
                else if (op.status == OperationStatus.Processing)
                {
                    op.totalSize = from.size;
                    fireOnProgress(op); // 触发一次进度改变
                    //如果在进度处理程序中,改变了状态,则跳过继续处理
                    if (op.status == OperationStatus.Processing)
                    {
                        if (from.size > MultiThreadDownloader.MIN_SLICE_SIZE)
                        {
                            d = new MultiThreadDownloader(pcs, from, op.to, workfolder, getDownloadMaxThreadCount(), getMinDownloadSliceSize());
                        }
                        else
                        {
                            d = new Downloader(pcs, from, op.to);
                        }
                        d.Completed           += du_onCompleted;
                        d.Progress            += du_onProgress;
                        d.StateFileNameDecide += du_onStateFileNameDecide;
                        d.ThreadChanged       += du_onThreadChanged;
                        d.State = op;
                        d.Download();
                    }
                }
            }
            catch (Exception ex)
            {
                op.status = OperationStatus.Fail;
                op.errmsg = ex.Message;
            }
        }
Пример #2
0
 private void download(OperationInfo op)
 {
     Downloader d = null;
     PcsFileInfo from;
     try
     {
         fireOnProgress(op); // 触发一次进度改变
         from = pcs.meta(op.from);
         if (from.IsEmpty)
         {
             op.status = OperationStatus.Fail;
             op.errmsg = "The remote file not exists (" + from.path + ").";
         }
         else if (from.isdir)
         {
             op.status = OperationStatus.Fail;
             op.errmsg = "Can't download directory (" + from.path + ").";
         }
         else if (op.status == OperationStatus.Processing)
         {
             op.totalSize = from.size;
             fireOnProgress(op); // 触发一次进度改变
             //如果在进度处理程序中,改变了状态,则跳过继续处理
             if (op.status == OperationStatus.Processing)
             {
                 if (from.size > MultiThreadDownloader.MIN_SLICE_SIZE)
                     d = new MultiThreadDownloader(pcs, from, op.to, workfolder, getDownloadMaxThreadCount(), getMinDownloadSliceSize());
                 else
                     d = new Downloader(pcs, from, op.to);
                 d.Completed += du_onCompleted;
                 d.Progress += du_onProgress;
                 d.StateFileNameDecide += du_onStateFileNameDecide;
                 d.State = op;
                 d.Download();
             }
         }
     }
     catch (Exception ex)
     {
         op.status = OperationStatus.Fail;
         op.errmsg = ex.Message;
     }
 }