public async Task <ScanResult> ScanFolderAsync([NotNull] string folder) { var directoryInfo = _directoryInfoFactory.Create(folder); if (directoryInfo.Exists) { return(await Task.Factory.StartNew(() => { var scanResult = new ScanResult(); ProcessFolder(scanResult, folder); return scanResult; })); } else { throw new ArgumentException("Path does not exists"); } }
public OpResult CreateProject(Project inputProject) { // 1. Check input model var directoryInfo = _directoryInfoFactory.Create(inputProject.Path); if (!directoryInfo.Exists) { return(OpResult.Bad(ErrorCode.FOLDER_DOES_NOT_EXIST, $"Folder {inputProject.Path} does not exist")); } // 2. Add project to projects list file var projectsList = _projectsConfigListFileConverter .Read(_configuration.ProjectsListPath) .Object; if (projectsList.Any(config => config.Path == inputProject.Path)) { return(OpResult.Bad(ErrorCode.PROJECT_ALREADY_IN_PROJECT_LIST, $"The configuration already contains a project with the path {inputProject.Path}")); } var projectId = Guid.NewGuid(); projectsList.Add(new Project { Id = projectId, Name = inputProject.Name, Path = Path.Combine(inputProject.Path, _configuration.DefaultProjectFileName) }); _projectsConfigListFileConverter.Dump(projectsList, _configuration.ProjectsListPath); // 3. Build domain object var project = Project.CreateDefaultInstance(); project.Id = projectId; project.Name = inputProject.Name; project.Path = inputProject.Path; // 4. Persist the default project file var dumpResult = _projectFileConverter.Dump( project, Path.Combine(inputProject.Path, _configuration.DefaultProjectFileName) ); // 5. Persist the default annex request file var rootPack = project.Tree as PackNode; if (rootPack != null) { ProjectTreeHelper <Project> .ExecuteTraversal( rootPack, (node, projectContext) => { if (!(node is PackNode)) { _annexFileConverter.Dump(node, Path.Combine(projectContext.Path, projectContext.Name, $"{node.Id}.yml")); } }, project); } return(OpResult.Ok); }