Exemplo n.º 1
0
        public void TaskStatusDetection()
        {
            while (true)
            {
                switch (UploadTaskList.GetStatus(File.Key))
                {
                case StatusType.RequestPause:
                {
                    uploadTask.Pause();
                    UploadTaskList.SetStatus(File.Key, StatusType.Paused);
                    break;
                }

                case StatusType.RequestRusume:
                {
                    uploadTask.Resume();
                    UploadTaskList.SetStatus(File.Key, StatusType.Running);
                    break;
                }

                case StatusType.RequestCancel:
                {
                    uploadTask.Cancel();
                    UploadTaskList.Remove(File.Key);
                    break;
                }

                default:
                    break;
                }

                Thread.Sleep(500);
            }
        }
Exemplo n.º 2
0
        public void refresh()
        {
            waiting.Clear();
            SortedList <long, FileControlBlock> watingList = UploadTaskList.GetWaitingList();

            foreach (var x in watingList)
            {
                waiting.Add(new FileControlBlockVO(x.Value));
            }
            running.Clear();
            SortedList <long, FileControlBlock> runningList = UploadTaskList.GetRunningList();

            foreach (var x in runningList)
            {
                running.Add(new FileControlBlockVO(x.Value));
            }
            success.Clear();
            SortedList <long, FileControlBlock> successList = UploadTaskList.GetSuccessList();

            foreach (var x in successList)
            {
                success.Add(new FileControlBlockVO(x.Value));
            }
            fail.Clear();
            SortedList <long, FileControlBlock> failList = UploadTaskList.GetFailureList();

            foreach (var x in failList)
            {
                fail.Add(new FileControlBlockVO(x.Value));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 上传文件
 /// </summary>
 /// <param name="localPath"></param>
 /// <param name="cloudPath"></param>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public string upload(string localPath, string cloudPath, string fileName)
 {
     if (userService == null)
     {
         return(null);
     }
     UploadTaskList.Add(new FileControlBlock
     {
         FileName   = fileName,
         LocalPath  = localPath,
         RemotePath = cloudPath,
         Status     = StatusType.Waiting
     });
     return(null);
 }
Exemplo n.º 4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UserRequest userService = new UserRequest();

            userService.Login("sudocat", "ssss11111", out _);


            for (int i = 206; i < 210; i++)
            {
                UploadTaskList.Add(new FileControlBlock
                {
                    FileName   = i + ".txt",
                    LocalPath  = @"C:\Users\i\Desktop\测试数据\a lot of txt",
                    RemotePath = @"/user/sudocat",
                    Status     = StatusType.Waiting
                });
            }
        }
Exemplo n.º 5
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     UploadTaskList.SetStatus(0, StatusType.RequestRusume);
 }
Exemplo n.º 6
0
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     //Convert.ToInt64(tbkey.Text)
     UploadTaskList.SetStatus(0, StatusType.RequestPause);
 }
Exemplo n.º 7
0
        public void Run()
        {
            string srcPath = File.LocalPath + "\\" + File.FileName;    //本地文件绝对路径

            FileRequest fileRequest = new FileRequest();
            int         status      = fileRequest.Upload(srcPath, File.RemotePath + "\\" + File.FileName, out UploadResponse res);

            switch (status)
            {
            case -20000:
                TaskStatusDetectionThread.Abort();
                UploadTaskList.SetFailure(File.Key, "请求服务器失败,请稍后再试。");
                break;

            case -10000:
                TaskStatusDetectionThread.Abort();
                UploadTaskList.SetFailure(File.Key, res.message);
                break;

            case 101:
                TaskStatusDetectionThread.Abort();
                UploadTaskList.SetProgress(File.Key, 1, 1);
                UploadTaskList.SetSuccess(File.Key);
                break;

            case 100:
            {
                string bucket  = res.data.tencentCos.bucket;          //存储桶,格式:BucketName-APPID
                string cosPath = res.data.file.storageName;           //对象在存储桶中的位置标识符,即称对象键

                CosService       cosService       = new CosService(res.data.tencentCos.region);
                CosXml           cosXml           = cosService.getCosXml(res.data.token.credentials.tmpSecretId, res.data.token.credentials.tmpSecretKey, res.data.token.credentials.token, res.data.token.expiredTime);
                TransferConfig   transferConfig   = new TransferConfig();
                TransferManager  transferManager  = new TransferManager(cosXml, transferConfig);
                PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, cosPath, srcPath);
                uploadTask = new COSXMLUploadTask(putObjectRequest);

                uploadTask.SetSrcPath(srcPath);

                uploadTask.progressCallback = delegate(long completed, long total)
                {
                    UploadTaskList.SetProgress(File.Key, completed, total);
                    Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));
                };
                uploadTask.successCallback = delegate(CosResult cosResult)
                {
                    TaskStatusDetectionThread.Abort();
                    fileRequest.ConfirmUpload(res.data.file.id, res.data.file.guid);
                    COSXMLUploadTask.UploadTaskResult result = cosResult as COSXMLUploadTask.UploadTaskResult;
                    Console.WriteLine("successCallback: " + result.GetResultInfo());
                    string eTag = result.eTag;
                    UploadTaskList.SetSuccess(File.Key);
                };
                uploadTask.failCallback = delegate(CosClientException clientEx, CosServerException serverEx)
                {
                    if (clientEx != null)
                    {
                        Console.WriteLine("CosClientException: " + clientEx);
                    }
                    if (serverEx != null)
                    {
                        Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                    }
                    TaskStatusDetectionThread.Abort();
                    UploadTaskList.SetFailure(File.Key, "COS上传出错。");
                };

                transferManager.Upload(uploadTask);
            }
            break;

            default:
                TaskStatusDetectionThread.Abort();
                UploadTaskList.SetFailure(File.Key, "未知原因上传失败。");
                break;
            }
        }