示例#1
0
        public IEnumerable <TableOfContents> GenerateTableOfContents(DirectoryInfo directoryInfo)
        {
            var directoryName        = directoryInfo.Name;
            var documentationVersion = directoryName;
            var directory            = _options.GetPathToDocumentationPagesDirectory(documentationVersion);

            Debug.Assert(Directory.Exists(_options.GetPathToDocumentationPagesDirectory(documentationVersion)));

            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                yield break;
            }

            foreach (var item in DocumentationFileHelper.ParseFile(docsFilePath))
            {
                if (!item.IsFolder)
                {
                    continue;
                }

                var tableOfContents = new TableOfContents
                {
                    Version  = documentationVersion,
                    Category = CategoryHelper.ExtractCategoryFromPath(item.Name),
                    Items    = GenerateTableOfContentItems(Path.Combine(directory, item.Name), item.Name).ToList()
                };

                yield return(tableOfContents);
            }
        }
示例#2
0
        private static IEnumerable <TableOfContents.TableOfContentsItem> GenerateTableOfContentItems(string directory, string keyPrefix)
        {
            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                yield break;
            }

            foreach (var item in DocumentationFileHelper.ParseFile(docsFilePath))
            {
                var tableOfContentsItem = new TableOfContents.TableOfContentsItem
                {
                    Key      = keyPrefix + "/" + item.Name,
                    Title    = item.Description,
                    IsFolder = item.IsFolder
                };

                if (tableOfContentsItem.IsFolder)
                {
                    tableOfContentsItem.Items = GenerateTableOfContentItems(Path.Combine(directory, item.Name), tableOfContentsItem.Key).ToList();
                }
                else
                {
                    tableOfContentsItem.Languages = GetLanguagesForTableOfContentsItem(directory, item.Name).ToList();
                }

                yield return(tableOfContentsItem);
            }
        }
示例#3
0
        private IEnumerable <DocumentationPage> CompileIndexFileInDirectory(string directory, string documentationVersion, List <DocumentationMapping> mappings = null)
        {
            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                yield break;
            }

            foreach (var item in DocumentationFileHelper.ParseFile(docsFilePath))
            {
                if (item.IsFolder == false)
                {
                    continue;
                }

                foreach (var page in CompileIndexFileInDirectory(Path.Combine(directory, item.Name), documentationVersion, item.Mappings))
                {
                    yield return(page);
                }
            }

            var indexFilePath = Path.Combine(directory, "index" + Constants.MarkdownFileExtension);

            if (File.Exists(indexFilePath))
            {
                yield return(CompileIndexFile(directory, documentationVersion, mappings));
            }
        }
        private IEnumerable <TableOfContents> GenerateTableOfContents(string documentationVersion, CompilationUtils.Context context)
        {
            var directory = _options.GetPathToDocumentationPagesDirectory(documentationVersion);

            Debug.Assert(Directory.Exists(directory));

            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                yield break;
            }

            foreach (var item in DocumentationFileHelper.ParseFile(docsFilePath))
            {
                if (!item.IsFolder)
                {
                    continue;
                }

                var category = CategoryHelper.ExtractCategoryFromPath(item.Name);

                var compilationResults = GenerateTableOfContentItems(Path.Combine(directory, item.Name), item.Name, documentationVersion, context).ToList();

                yield return(_converter.ConvertToTableOfContents(compilationResults, documentationVersion, category));

                var additionalSupportedVersions = GetAdditionalSupportedVersions(documentationVersion, compilationResults);

                foreach (var supportedVersion in additionalSupportedVersions)
                {
                    yield return(GetAdditionalSupportedTableOfContent(supportedVersion, category, compilationResults));
                }
            }
        }
示例#5
0
        private void ValidateHashesInDirectory(string directory)
        {
            if (Directory.Exists(directory) == false)
            {
                return;
            }

            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                return;
            }

            ValidateHashesInDocsJson(docsFilePath);

            foreach (var item in DocumentationFileHelper.ParseFile(docsFilePath))
            {
                if (item.IsFolder == false)
                {
                    continue;
                }

                var innerDirectoryPath = Path.Combine(directory, item.Name);
                ValidateHashesInDirectory(innerDirectoryPath);
            }
        }
        private IEnumerable <CompilationResult> GenerateTableOfContentItems(string directory, string keyPrefix,
                                                                            string documentationVersion, CompilationUtils.Context context)
        {
            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                yield break;
            }

            foreach (var item in DocumentationFileHelper.ParseFile(docsFilePath))
            {
                Validate(item, docsFilePath);

                var tableOfContentsItem = new CompilationResult
                {
                    Key      = keyPrefix + "/" + item.Name,
                    Title    = item.Description,
                    IsFolder = item.IsFolder
                };

                if (item.IsFolder)
                {
                    var compilationResults = GenerateTableOfContentItems(Path.Combine(directory, item.Name),
                                                                         tableOfContentsItem.Key, documentationVersion, context).ToList();

                    tableOfContentsItem.Items = compilationResults;
                    var supportedVersions = compilationResults.SelectMany(x => x.SupportedVersions);
                    tableOfContentsItem.AddSupportedVersions(supportedVersions);
                }
                else
                {
                    tableOfContentsItem.Languages = GetLanguagesForTableOfContentsItem(directory, item.Name).ToList();

                    if (MarkdownFileExists(directory, item))
                    {
                        var supportedVersions =
                            _versions.GetMinorVersionsInRange(documentationVersion, item.LastSupportedVersion);

                        tableOfContentsItem.AddSupportedVersions(supportedVersions);
                        tableOfContentsItem.SourceVersion = documentationVersion;
                    }

                    context.RegisterCompilation(new CompilationUtils.Context.RegistrationInput
                    {
                        Key                  = tableOfContentsItem.Key,
                        Language             = item.Language,
                        DocumentationVersion = documentationVersion,
                        LastSupportedVersion = item.LastSupportedVersion,
                        SupportedVersions    = tableOfContentsItem.SupportedVersions?.ToList()
                    });
                }

                yield return(tableOfContentsItem);
            }
        }
示例#7
0
        private void AssignDiscussionIdsInDocsFile(TableOfContents.TableOfContentsItem tocItem, string directory, string discussionId = null)
        {
            var matchingFolderItem = GetFolderItemForTocItem(directory, tocItem);

            if (matchingFolderItem == null)
            {
                return;
            }

            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            DocumentationFileHelper.AssignDiscussionIdIfNeeded(docsFilePath, matchingFolderItem, discussionId);
        }
示例#8
0
        private FolderItem GetFolderItemForTocItem(string directory, TableOfContents.TableOfContentsItem tocItem)
        {
            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                return(null);
            }

            var keySuffix = tocItem.GetKeySuffix();

            var matchingFolderItem = DocumentationFileHelper.ParseFile(docsFilePath)
                                     .SingleOrDefault(x => x.Name == keySuffix);

            return(matchingFolderItem);
        }
示例#9
0
        private static string GenerateFilesList(string pathToDocumentationPage, string directoryName)
        {
            var path = Path.Combine(pathToDocumentationPage, Constants.DocumentationFileName);

            if (File.Exists(path) == false)
            {
                return(string.Empty);
            }

            var builder = new StringBuilder();

            foreach (var item in DocumentationFileHelper.ParseFile(path))
            {
                builder.AppendLine(string.Format("* [{0}]({1}/{2})", item.Description, directoryName, item.Name));
            }

            return(builder.ToString());
        }
示例#10
0
        private IEnumerable <DocumentationPage> CompileDocumentationDirectory(string directory, string documentationVersion, List <DocumentationMapping> mappings = null)
        {
            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                yield break;
            }

            foreach (var item in DocumentationFileHelper.ParseFile(docsFilePath))
            {
                if (item.IsFolder)
                {
                    foreach (var page in CompileDocumentationDirectory(Path.Combine(directory, item.Name), documentationVersion, item.Mappings))
                    {
                        yield return(page);
                    }

                    continue;
                }

                foreach (var pageToCompile in GetPages(directory, item))
                {
                    yield return(CompileDocumentationPage(pageToCompile, directory, documentationVersion, pageToCompile.Mappings));
                }
            }

            var indexFilePath = Path.Combine(directory, "index" + Constants.MarkdownFileExtension);

            if (File.Exists(indexFilePath) == false)
            {
                yield break;
            }

            var indexItem = new FolderItem(isFolder: false)
            {
                Description = string.Empty,
                Language    = Language.All,
                Name        = "index"
            };

            yield return(CompileDocumentationPage(indexItem, directory, documentationVersion, mappings ?? new List <DocumentationMapping>()));
        }
示例#11
0
        private IEnumerable <FolderItem> GetPagesForTocItem(TableOfContents.TableOfContentsItem tocItem, string directory)
        {
            var docsFilePath = Path.Combine(directory, Constants.DocumentationFileName);

            if (File.Exists(docsFilePath) == false)
            {
                yield break;
            }

            var keySuffix = tocItem.GetKeySuffix();

            var matchingFolderItems = DocumentationFileHelper.ParseFile(docsFilePath)
                                      .Where(x => x.Name == keySuffix)
                                      .SelectMany(x => GetPages(directory, x));

            foreach (var folderItem in matchingFolderItems)
            {
                yield return(folderItem);
            }
        }
示例#12
0
        private void ValidateHashesInDocsJson(string docsFilePath)
        {
            var folderItems = DocumentationFileHelper.ParseFile(docsFilePath);

            foreach (var item in folderItems)
            {
                if (item.IsFolder)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(item.DiscussionId))
                {
                    var errorMessage = new StringBuilder();
                    errorMessage.Append($"{nameof(DocumentationPage.DiscussionId)} is missing in {docsFilePath} for item: {item.Name}. ");
                    errorMessage.Append("Please generate the documentation again and make sure to commit the .docs.json file changes.");

                    throw new InvalidOperationException(errorMessage.ToString());
                }
            }
        }