Exemple #1
0
        private void UpdateStatusFromJob(FtpJob job)
        {
            switch (job.Status)
            {
            case FtpJob.JobStatus.Cancelled:
                Status       = "已取消";
                ShowProgress = false;
                break;

            case FtpJob.JobStatus.Faulted:
                var message = job.Exception?.Message ?? "无错误信息。";
                if (job.Exception?.InnerException is FluentFTP.FtpCommandException cmdEx)
                {
                    if (cmdEx.CompletionCode == "550")
                    {
                        message = "没有访问权限。";
                    }
                }
                Status       = string.Format("出错:{0}", message);
                ShowProgress = false;
                break;

            case FtpJob.JobStatus.Completed:
                Status       = string.Format("已完成");
                ShowProgress = false;
                break;

            case FtpJob.JobStatus.Created:
                Status       = string.Empty;
                ShowProgress = true;
                break;
            }
        }
Exemple #2
0
 public FtpJobViewModel(FtpJob job, CoreDispatcher dispatcher)
 {
     this.job = job;
     Name     = job.Name;
     if (double.IsNaN(job.Progress))
     {
         Progress = 0;
         IsProgressIndeterminate = true;
     }
     else
     {
         Progress = job.Progress;
         IsProgressIndeterminate = false;
     }
     UpdateStatusFromJob(job);
     {
         job.ProgressChanged += async(sender, e) =>
         {
             await dispatcher.RunIdleAsync(e1 =>
             {
                 if (double.IsNaN(job.Progress))
                 {
                     IsProgressIndeterminate = true;
                 }
                 else
                 {
                     IsProgressIndeterminate = false;
                     Progress = job.Progress;
                 }
             });
         };
     }
     {
         job.StatusChanged += async(sender, e) =>
         {
             await dispatcher.RunIdleAsync(e1 =>
             {
                 UpdateStatusFromJob(job);
             });
         };
     }
 }
Exemple #3
0
        public void AddDownloadFile(FluentFTP.FtpClient client, string remotePath, StorageFile localFile, Action callBack)
        {
            client = CloneFtpClient(client);
            FtpJob job      = new FtpJob();
            var    cts      = new CancellationTokenSource();
            var    progress = new Progress <double>(x =>
            {
                job.Progress = x;
            });

            job.Task = DownloadFileAsync(client, remotePath, localFile, cts.Token, progress).ContinueWith(x =>
            {
                if (!cts.IsCancellationRequested)
                {
                    job.Progress = double.NaN;
                    try
                    {
                        callBack();
                    }
                    catch { }
                }
                if (x.IsCanceled)
                {
                    job.Status = FtpJob.JobStatus.Cancelled;
                }
                else if (x.IsFaulted)
                {
                    job.Status = FtpJob.JobStatus.Faulted;
                }
                else if (x.IsCompleted)
                {
                    job.Status = FtpJob.JobStatus.Completed;
                }
                job.Exception = x.Exception;
            });
            job.Name = string.Format("下载{0}", Path.GetFileName(remotePath));
            job.CancellationTokenSource = cts;

            _jobs.Add(job);
        }