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 TaskViewModel(string taskName, IApplicationController applicationController, FileSystemCancellableTaskToken taskToken) { if (applicationController == null) { throw new ArgumentNullException("applicationController"); } if (taskToken == null) { throw new ArgumentNullException("taskToken"); } _applicationController = applicationController; _taskToken = taskToken; this.TaskName = taskName; _taskToken.ProgressChanged += TaskTokenProgressChanged; }
public void StartImportingFilesFromVirtualSystem() { var filePath = _userInteractionService.PickAFile( "Выберите файл, содержащий файловую систему, из корня которой следует проимпортировать все данные"); if (!String.IsNullOrEmpty(filePath)) { var taskToken = new FileSystemCancellableTaskToken(); var taskViewModel = new TaskViewModel("Импорт данных из корня виртуальной файловой системы, работающей на файле \"{0}\"".FormatWith(filePath), _applicationController, taskToken); _tasks.Insert(0, taskViewModel); _artifactImporter.KickOffVirtualSystemImport(filePath, this.CurrentFolderPath, taskViewModel, taskToken); } }
public void StartImportingFilesFromLocalSystem() { string folderPicked = _userInteractionService.PickAFolder("Выберите папку, все данные из которой следует проимпортировать"); if (String.IsNullOrEmpty(folderPicked)) { return; } var taskToken = new FileSystemCancellableTaskToken(); var taskViewModel = new TaskViewModel("Импорт данных файловой системы компьютера из \"{0}\"".FormatWith(folderPicked), _applicationController, taskToken); _tasks.Insert(0, taskViewModel); string currentFolderPath = this.CurrentFolderPath; _artifactImporter.KickOffRealFileSystemImport(taskViewModel, folderPicked, currentFolderPath, taskToken); }
public void VisitFile(FileViewModel fileViewModel) { if (fileViewModel == null) { throw new ArgumentNullException("fileViewModel"); } var pathViewModel = new VirtualFolderPathViewModel(_pathValidator) { Path = VirtualFileSystem.Root }; if (_userInteractionService.GetVirtualFolderPath(pathViewModel)) { var taskToken = new FileSystemCancellableTaskToken(); _taskViewModel = new TaskViewModel( "Копирование файла \"{0}\" по следующему пути \"{1}\"".FormatWith(fileViewModel.FullPath, pathViewModel.Path), _applicationController, taskToken); _taskCounter.IncreaseNumberOfOutstandingTasks(); ThreadPool.QueueUserWorkItem( delegate { try { _fileSystem.CopyFile(fileViewModel.FullPath, pathViewModel.Path, taskToken); _taskViewModel.SetResult(new[] { new TaskResultViewModel(fileViewModel.FullPath, pathViewModel.Path, true, String.Empty) }); } catch (TaskCancelledException exception) { this.SetCopyFileError(fileViewModel.FullPath, pathViewModel.Path, exception); } catch (FileNotFoundException exception) { this.SetCopyFileError(fileViewModel.FullPath, pathViewModel.Path, exception); } catch (FileLockedException exception) { this.SetCopyFileError(fileViewModel.FullPath, pathViewModel.Path, exception); } catch (InvalidPathException exception) { this.SetCopyFileError(fileViewModel.FullPath, pathViewModel.Path, exception); } catch (FileAlreadyExistsException exception) { this.SetCopyFileError(fileViewModel.FullPath, pathViewModel.Path, exception); } catch (FolderNotFoundException exception) { this.SetCopyFileError(fileViewModel.FullPath, pathViewModel.Path, exception); } catch (MaximumFileCountReachedException exception) { this.SetCopyFileError(fileViewModel.FullPath, pathViewModel.Path, exception); } catch (InsufficientSpaceException exception) { this.SetCopyFileError(fileViewModel.FullPath, pathViewModel.Path, 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(); } }); }
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(); } }); }