public async Task <IList <BaseDocumentDto> > GetDocumentsAsync(string projectId, string branchName)
        {
            await _commonValidator.ProjectHaveToExists(projectId);

            await _commonValidator.BranchHaveToExists(projectId, branchName);

            var baseDocuments = new List <BaseDocumentDto>();
            var files         = await _fileSystemService.GetFilesAsync(projectId, branchName);

            foreach (var file in files)
            {
                var extension = Path.GetExtension(file);
                var mimeType  = MimeTypeMap.GetMimeType(extension);

                var baseDocument = new BaseDocumentDto
                {
                    Uri        = file,
                    Name       = Path.GetFileName(file),
                    ConentType = mimeType
                };

                baseDocuments.Add(baseDocument);
            }

            return(baseDocuments);
        }
        public async Task <IList <BranchDto> > GetBranchesAsync(string projectId)
        {
            await _commonValidator.ProjectHaveToExists(projectId);

            var branchesNames = await _fileSystemService.GetBranchesNamesAsync(projectId);

            var branches = new List <BranchDto>();

            foreach (var branchName in branchesNames)
            {
                try
                {
                    string mkDocsYaml = await _fileSystemService.ReadTextAsync(projectId, branchName, "mkdocs.yml");

                    var branch = new BranchDto
                    {
                        Name       = branchName,
                        MkDocsYaml = mkDocsYaml
                    };

                    branches.Add(branch);
                }
                catch (FileNotFoundException)
                {
                    _logger.LogWarning($"Branch '{branchName}' in project '{projectId}' doesn't have mkdocs file.");
                }
            }

            branches = branches.OrderBy(x => x.Name).ToList();
            return(branches);
        }
示例#3
0
        public async Task <ProjectDto> GetProjectAsync(string projectId)
        {
            await _commonValidator.ProjectHaveToExists(projectId);

            try
            {
                var configurationFile = await _fileSystemService.ReadTextAsync(projectId, "configuration.json");

                var projectDto = JsonConvert.DeserializeObject <ProjectDto>(configurationFile);

                projectDto.Id = projectId;
                return(projectDto);
            }
            catch (FileNotFoundException)
            {
                _logger.LogWarning($"Project '{projectId}' doesn't have configuration file.");
                throw new ConfigurationFileNotFoundException($"Configuration file for project '{projectId}' not found.");
            }
        }