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(); } }); } }
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(); } }); }
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(); } }); }