예제 #1
0
        private async Task UploadFilesAsync(IEnumerable <FileTransferInfo> fileInfos)
        {
            await ftpSemaphore.WaitAsync();

            try
            {
                progressBar.Visibility      = Visibility.Visible;
                progressBar.IsIndeterminate = true;

                cancelSource = new CancellationTokenSource();
                bool overwriteAll = false;
                bool skipAll      = false;

                var count     = fileInfos.Count();
                int doneCount = 0;
                foreach (var fileInfo in fileInfos)
                {
                    if (!overwriteAll && await client.FileExistsAsync(fileInfo.RemotePath))
                    {
                        if (skipAll)
                        {
                            continue;
                        }
                        OverwriteDialog content = new OverwriteDialog
                        {
                            Text         = string.Format("文件{0}已存在,是否覆盖?", fileInfo.File.Name),
                            CheckBoxText = "对所有项目执行此操作"
                        };
                        ContentDialog dialog = new ContentDialog()
                        {
                            Content                  = content,
                            PrimaryButtonText        = "覆盖",
                            IsPrimaryButtonEnabled   = true,
                            SecondaryButtonText      = "跳过",
                            IsSecondaryButtonEnabled = true,
                            CloseButtonText          = "取消"
                        };
                        switch (await dialog.ShowAsync())
                        {
                        case ContentDialogResult.Primary:
                            if (content.IsChecked)
                            {
                                overwriteAll = true;
                            }
                            break;

                        case ContentDialogResult.Secondary:
                            if (content.IsChecked)
                            {
                                skipAll = true;
                            }
                            continue;

                        case ContentDialogResult.None:
                            goto CancelAll;
                        }
                    }

                    jobManager.AddUploadFile(client, fileInfo.RemotePath, fileInfo.File, () => { });

                    doneCount++;
                    progressBar.Value = (double)doneCount / count * 100;
                }
CancelAll:
                jobListFlyout.ShowAt(jobListButton);
            }
            finally
            {
                ftpSemaphore.Release();
                progressBar.Visibility = Visibility.Collapsed;
            }
        }