Beispiel #1
0
        private void upload(OperationInfo op)
        {
            Uploader u = null;

            try
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(op.from);
                op.totalSize = fi.Length;
                fireOnProgress(op); // 触发一次进度改变
                //如果在进度处理程序中,改变了状态,则跳过继续处理
                if (op.status == OperationStatus.Processing)
                {
                    if (fi.Length > MultiThreadUploader.MIN_SLICE_SIZE)
                    {
                        u = new RapidUploader(pcs, op.from, op.to);
                        u.Upload();
                        if (u.Success)
                        {
                            op.status = OperationStatus.Success;
                        }
                        else if (u.IsCancelled)
                        {
                            op.status = OperationStatus.Cancel;
                        }
                        else if (op.status == OperationStatus.Processing)
                        {
                            u = new MultiThreadUploader(pcs, op.from, op.to, workfolder, getUploadMaxThreadCount());
                        }
                        else
                        {
                            u = null; // op 的状态已经被改变,且不是 OperationStatus.Processing
                        }
                    }
                    else if (op.status == OperationStatus.Processing)
                    {
                        u = new Uploader(pcs, op.from, op.to);
                    }
                    else
                    {
                        u = null; // op 的状态已经被改变,且不是 OperationStatus.Processing
                    }
                    if (u != null && op.status == OperationStatus.Processing)
                    {
                        u.IsOverWrite          = AppSettings.OverWriteWhenUploadFile;
                        u.Progress            += du_onProgress;
                        u.Completed           += du_onCompleted;
                        u.StateFileNameDecide += du_onStateFileNameDecide;
                        u.ThreadChanged       += du_onThreadChanged;
                        u.State = op;
                        u.Upload();
                    }
                }
            }
            catch (Exception ex)
            {
                op.status = OperationStatus.Fail;
                op.errmsg = ex.Message;
            }
        }
Beispiel #2
0
 private void upload(OperationInfo op)
 {
     Uploader u = null;
     try
     {
         System.IO.FileInfo fi = new System.IO.FileInfo(op.from);
         op.totalSize = fi.Length;
         fireOnProgress(op); // 触发一次进度改变
         //如果在进度处理程序中,改变了状态,则跳过继续处理
         if (op.status == OperationStatus.Processing)
         {
             if (fi.Length > MultiThreadUploader.MIN_SLICE_SIZE)
             {
                 u = new RapidUploader(pcs, op.from, op.to);
                 u.Upload();
                 if (u.Success)
                     op.status = OperationStatus.Success;
                 else if (u.IsCancelled)
                     op.status = OperationStatus.Cancel;
                 else if (op.status == OperationStatus.Processing)
                     u = new MultiThreadUploader(pcs, op.from, op.to, workfolder, getUploadMaxThreadCount());
                 else
                     u = null; // op 的状态已经被改变,且不是 OperationStatus.Processing
             }
             else if (op.status == OperationStatus.Processing)
                 u = new Uploader(pcs, op.from, op.to);
             else
                 u = null; // op 的状态已经被改变,且不是 OperationStatus.Processing
             if (u != null && op.status == OperationStatus.Processing)
             {
                 u.IsOverWrite = AppSettings.OverWriteWhenUploadFile;
                 u.Progress += du_onProgress;
                 u.Completed += du_onCompleted;
                 u.StateFileNameDecide += du_onStateFileNameDecide;
                 u.State = op;
                 u.Upload();
             }
         }
     }
     catch (Exception ex)
     {
         op.status = OperationStatus.Fail;
         op.errmsg = ex.Message;
     }
 }