Example #1
0
        private async Task FetchFilesToDownload(string remotePath, StorageFolder localFolder, ICollection <FileTransferInfo> resultOutput,
                                                BooleanReference overwriteAll, BooleanReference skipAll, BooleanReference cancelAll)
        {
            var remoteFiles = await client.GetListingAsync(remotePath);

            foreach (var item in remoteFiles)
            {
                if (cancelAll.Value)
                {
                    return;
                }
                if (item.Type == FluentFTP.FtpFileSystemObjectType.File)
                {
                    StorageFile file = null;
                    if (overwriteAll.Value)
                    {
                        file = await localFolder.CreateFileAsync(item.Name, CreationCollisionOption.ReplaceExisting);
                    }
                    else
                    {
                        try
                        {
                            file = await localFolder.CreateFileAsync(item.Name, CreationCollisionOption.FailIfExists);
                        }
                        catch //TODO: catch what?
                        {
                            if (skipAll.Value)
                            {
                                continue;
                            }

                            OverwriteDialog content = new OverwriteDialog
                            {
                                Text         = string.Format("文件{0}已存在,是否覆盖?", item.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.Value = true;
                                }
                                file = await localFolder.CreateFileAsync(item.Name, CreationCollisionOption.ReplaceExisting);

                                break;

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

                            case ContentDialogResult.None:
                                cancelAll.Value = true;
                                return;
                            }
                        }
                    }

                    resultOutput.Add(new FileTransferInfo
                    {
                        File       = file,
                        RemotePath = item.FullName
                    });
                }
                else
                {
                    var subFolder = await localFolder.CreateFolderAsync(item.Name, CreationCollisionOption.OpenIfExists);
                    await FetchFilesToDownload(item.FullName, subFolder, resultOutput, overwriteAll, skipAll, cancelAll);
                }
            }
        }
Example #2
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;
            }
        }