Example #1
0
        public OpResult UpdateProject(Project inputProject)
        {
            // 1. Check project exists !
            var projectsConfigsList = _projectsConfigListFileConverter
                                      .Read(_configuration.ProjectsListPath)
                                      .Object;
            var projectFromConfig = projectsConfigsList.SingleOrDefault(c => c.Id == inputProject.Id);

            if (projectFromConfig == null)
            {
                return(OpResult.Bad(ErrorCode.PROJECT_DOES_NOT_EXIST, $"Project with id {inputProject.Id} not found in your configuration"));
            }

            inputProject.Path = projectFromConfig.Path;

            var rootPack = inputProject.Tree as PackNode;

            if (rootPack != null)
            {
                ProjectTreeHelper <Project> .ExecuteTraversal(
                    rootPack,
                    (node, projectContext) =>
                {
                    if (!(node is PackNode))
                    {
                        _annexFileConverter.Dump(node, Path.Combine(projectContext.Path, $"{node.Id}.yml"));
                    }
                },
                    inputProject);
            }
            var dumpResult = _projectFileConverter.Dump(
                inputProject,
                Path.Combine(inputProject.Path, _configuration.DefaultProjectFileName)
                );

            return(dumpResult);
        }
Example #2
0
        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);
        }