Пример #1
0
        public Task <IDocumentationIndex> IndexFiles()
        {
            DirectoryInfo directoryInfo = _Options.GetDocumentationFolderAsAbsolute(_HostingEnvironment.ContentRootPath);

            IDocumentationIndex documentationIndex = new DocumentationIndex();

            IDocumentationProject documentationProject = new DocumentationProject(_Options.DefaultDocuments, _Options.LandingPageDocument, null);

            BuildDocumentationSubTree(directoryInfo, directoryInfo, documentationProject);

            foreach (var project in documentationProject.SubProjects)
            {
                documentationIndex.Projects.Add(project);
            }

            documentationIndex.DefaultProject = new DocumentationProject(_Options.DefaultDocuments, _Options.LandingPageDocument, "");
            documentationIndex.DefaultProject.Documents.AddRange(documentationProject.Documents.OrderBy(o => o.Name));

            return(Task.FromResult(documentationIndex));
        }
Пример #2
0
        private DocumentationDocumentType BuildDocumentationSubTree(DirectoryInfo directoryInfo, DirectoryInfo topDirectoryInfo, IDocumentationProject project)
        {
            DocumentationDocumentType subTreeDocumentType = DocumentationDocumentType.Folder;

            project.Path = directoryInfo.FullName;

            foreach (var file in directoryInfo.EnumerateFiles())
            {
                var docType = DocumentationHelper.GetDocumentationDocumentTypeFromName(file.Name);

                switch (docType)
                {
                case DocumentationDocumentType.Markdown:
                    if (!_Options.Documents?.Markdown?.Enabled ?? false)
                    {
                        break;
                    }
                    // The markdown pipeline isn't needed for the content extraction.
                    project.Documents.Add(new MarkdownDocument(null)
                    {
                        Path       = file.FullName,
                        LastUpdate = file.LastWriteTimeUtc
                    });
                    break;

                case DocumentationDocumentType.Word:
                    if (!_Options.Documents?.Word?.Enabled ?? false)
                    {
                        break;
                    }
                    project.Documents.Add(new WordDocument
                    {
                        Path       = file.FullName,
                        LastUpdate = file.LastWriteTimeUtc
                    });
                    break;

                case DocumentationDocumentType.Pdf:
                    if (!_Options.Documents?.Pdf?.Enabled ?? false)
                    {
                        break;
                    }
                    project.Documents.Add(new DocumentationDocument
                    {
                        Path         = file.FullName,
                        DocumentType = docType,
                        LastUpdate   = file.LastWriteTimeUtc
                    });
                    break;

                case DocumentationDocumentType.Html:
                    if (!_Options.Documents?.Html?.Enabled ?? false)
                    {
                        break;
                    }
                    project.Documents.Add(new DocumentationDocument
                    {
                        Path         = file.FullName,
                        DocumentType = docType,
                        LastUpdate   = file.LastWriteTimeUtc
                    });
                    break;

                case DocumentationDocumentType.Drawio:
                    if (!_Options.Documents?.Drawio?.Enabled ?? false)
                    {
                        break;
                    }
                    project.Documents.Add(new DocumentationDocument
                    {
                        Path         = file.FullName,
                        DocumentType = docType,
                        LastUpdate   = file.LastWriteTimeUtc
                    });
                    break;

                case DocumentationDocumentType.DrawioSvg:
                    if (!_Options.Documents?.DrawioSvg?.Enabled ?? false)
                    {
                        break;
                    }
                    project.Documents.Add(new DocumentationDocument
                    {
                        Path         = file.FullName,
                        DocumentType = docType,
                        LastUpdate   = file.LastWriteTimeUtc
                    });
                    break;

                case DocumentationDocumentType.Folder:
                    project.Documents.Add(new DocumentationDocument
                    {
                        Path         = file.FullName,
                        DocumentType = docType,
                        LastUpdate   = file.LastWriteTimeUtc
                    });
                    break;

                case DocumentationDocumentType.Project:
                    subTreeDocumentType = DocumentationDocumentType.Project;
                    break;

                case DocumentationDocumentType.Unknown:
                    break;

                default:
                    break;
                }
            }

            foreach (var directory in directoryInfo.EnumerateDirectories())
            {
                IDocumentationProject subProject = new DocumentationProject(_Options.DefaultDocuments, _Options.LandingPageDocument, project.KeyPath);
                var subDocumentType = BuildDocumentationSubTree(directory, topDirectoryInfo, subProject);

                if (subDocumentType == DocumentationDocumentType.Project)
                {
                    project.SubProjects.Add(subProject);
                }
                else
                {
                    var documentationDirectory = new DocumentationDocument
                    {
                        DocumentType = subDocumentType,
                        Path         = directory.FullName,
                        LastUpdate   = directory.LastWriteTimeUtc
                    };

                    if (subProject.Documents.Any())
                    {
                        documentationDirectory.SubDocuments = subProject.Documents.OrderBy(o => o.Name).ToArray();
                        project.Documents.Add(documentationDirectory);
                    }
                }
            }

            return(subTreeDocumentType);
        }