コード例 #1
0
        public void VisitFolder(FolderViewModel folderViewModel)
        {
            if (folderViewModel == null)
            {
                throw new ArgumentNullException("folderViewModel");
            }

            var pathViewModel = new VirtualFolderPathViewModel(_pathValidator)
            {
                Path = VirtualFileSystem.Root
            };

            if (_userInteractionService.GetVirtualFolderPath(pathViewModel))
            {
                var taskToken = new FileSystemCancellableTaskToken();

                _taskViewModel = new TaskViewModel(
                    "Копирование папки \"{0}\" по следующему пути \"{1}\"".FormatWith(folderViewModel.FullPath, pathViewModel.Path),
                    _applicationController,
                    taskToken);

                _taskCounter.IncreaseNumberOfOutstandingTasks();

                ThreadPool.QueueUserWorkItem(
                    delegate
                {
                    try
                    {
                        var results = _fileSystem.CopyFolder(folderViewModel.FullPath, pathViewModel.Path, taskToken);

                        var viewModels = TaskViewModelConverter.CreateViewModelsFromResults(results);

                        _taskViewModel.SetResult(viewModels);
                    }
                    catch (FolderNotFoundException exception)
                    {
                        this.SetCopyFileError(folderViewModel.FullPath, pathViewModel.Path, exception);
                    }
                    catch (InvalidPathException exception)
                    {
                        this.SetCopyFileError(folderViewModel.FullPath, pathViewModel.Path, exception);
                    }
                    catch (MaximumFolderCountReachedException exception)
                    {
                        this.SetCopyFileError(folderViewModel.FullPath, pathViewModel.Path, exception);
                    }
                    catch (InsufficientSpaceException exception)
                    {
                        this.SetCopyFileError(folderViewModel.FullPath, pathViewModel.Path, exception);
                    }
                    finally
                    {
                        MarkTaskViewModelAsCompleted(_taskViewModel);
                        _taskCounter.DecreaseNumberOfOutstandingTasks();
                    }
                });
            }
        }
コード例 #2
0
        public void KickOffRealFileSystemImport(TaskViewModel taskViewModel, string sourceFolder, string destinationFolderPath, FileSystemCancellableTaskToken taskToken)
        {
            _taskCounter.IncreaseNumberOfOutstandingTasks();

            ThreadPool.QueueUserWorkItem(
                delegate
            {
                try
                {
                    var results = _fileSystem.ImportFolderFromRealFileSystem(
                        sourceFolder,
                        destinationFolderPath,
                        taskToken);

                    var viewModels = TaskViewModelConverter.CreateViewModelsFromResults(results);

                    taskViewModel.SetResult(viewModels);
                }
                catch (FolderNotFoundException exception)
                {
                    SetTaskModelFromError(sourceFolder, taskViewModel, exception);
                }
                catch (InsufficientSpaceException exception)
                {
                    SetTaskModelFromError(sourceFolder, taskViewModel, exception);
                }
                catch (CannotGetImportedFolderStructureException exception)
                {
                    SetTaskModelFromError(sourceFolder, taskViewModel, exception);
                }
                finally
                {
                    MarkTaskViewModelAsCompleted(taskViewModel);
                    _taskCounter.DecreaseNumberOfOutstandingTasks();
                }
            });
        }
コード例 #3
0
        public void KickOffVirtualSystemImport(string fileSystemContainer, string destinationPath, TaskViewModel taskViewModel, FileSystemCancellableTaskToken taskToken)
        {
            _taskCounter.IncreaseNumberOfOutstandingTasks();

            ThreadPool.QueueUserWorkItem(
                delegate
            {
                VirtualFileSystem sourceFileSystem = null;

                try
                {
                    string fileSystemId;
                    sourceFileSystem = _virtualFileSystemInstanceManager.CreateFromFile(fileSystemContainer, out fileSystemId);

                    if (Object.ReferenceEquals(_fileSystem, sourceFileSystem))
                    {
                        taskViewModel.SetResult(new List <TaskResultViewModel> {
                            new TaskResultViewModel(VirtualFileSystem.Root, null, false, "Рекурсивный импорт (из системы в себя) запрещен.")
                        });

                        MarkTaskViewModelAsCompleted(taskViewModel);
                        return;
                    }

                    try
                    {
                        var results =
                            _fileSystem.ImportFolderFromVirtualFileSystem(
                                sourceFileSystem, VirtualFileSystem.Root, destinationPath,
                                taskToken);

                        var viewModels = TaskViewModelConverter.CreateViewModelsFromResults(results);

                        taskViewModel.SetResult(viewModels);
                    }
                    catch (FolderNotFoundException exception)
                    {
                        SetTaskModelFromError(taskViewModel, exception);
                    }
                    catch (InsufficientSpaceException exception)
                    {
                        SetTaskModelFromError(taskViewModel, exception);
                    }
                    catch (CannotGetImportedFolderStructureException exception)
                    {
                        SetTaskModelFromError(taskViewModel, exception);
                    }
                    finally
                    {
                        MarkTaskViewModelAsCompleted(taskViewModel);
                    }
                }
                catch (FileSystemCreationFailedException exception)
                {
                    taskViewModel.SetResult(new List <TaskResultViewModel> {
                        new TaskResultViewModel(VirtualFileSystem.Root, null, false, exception.Message)
                    });

                    MarkTaskViewModelAsCompleted(taskViewModel);
                }
                finally
                {
                    if (sourceFileSystem != null)
                    {
                        _virtualFileSystemInstanceManager.ReportThatSystemIsNoLongerNeeded(sourceFileSystem);
                    }

                    _taskCounter.DecreaseNumberOfOutstandingTasks();
                }
            });
        }