Esempio n. 1
0
        public static Dictionary <string, MarkdownIndex> MergeMarkdownResults(List <string> markdownFilePathList, Dictionary <string, MetadataItem> apiList, string workingDirectory, string mdFolderName, string referenceFolderName)
        {
            Dictionary <string, MarkdownIndex> table = new Dictionary <string, MarkdownIndex>();

            foreach (var file in markdownFilePathList.Distinct())
            {
                List <MarkdownIndex> indics;
                MetadataItem         item;
                string apiFolder       = Path.Combine(workingDirectory, mdFolderName);
                string referenceFolder = Path.Combine(workingDirectory, referenceFolderName);
                if (Directory.Exists(apiFolder))
                {
                    ParseResult.WriteToConsole(ResultLevel.Warn, "Folder {0} already exists!", apiFolder);
                }
                else
                {
                    Directory.CreateDirectory(apiFolder);
                }

                string destFileName = Path.Combine(apiFolder, file.ToValidFilePath());
                string resolvedContent;
                try
                {
                    string input = File.ReadAllText(file);
                    resolvedContent = LinkParser.ResolveToMarkdownLink(apiList, input);
                    File.WriteAllText(destFileName, resolvedContent);
                }
                catch (Exception e)
                {
                    ParseResult.WriteToConsole(ResultLevel.Error, "Unable to copy markdown file {0} to output directory {1}: {2}", file, apiFolder, e.Message);
                    continue;
                }

                var result = TryParseCustomizedMarkdown(file, resolvedContent, referenceFolder, s =>
                {
                    if (apiList.TryGetValue(s.Name, out item))
                    {
                        return(new ParseResult(ResultLevel.Success));
                    }
                    else
                    {
                        return(new ParseResult(ResultLevel.Error, "Cannot find {0} in the documentation", s.Name));
                    }
                }, out indics);

                if (result.ResultLevel != ResultLevel.Success)
                {
                    Console.Error.WriteLine(result);
                }

                foreach (var key in indics)
                {
                    MarkdownIndex saved;
                    if (table.TryGetValue(key.ApiName, out saved))
                    {
                        ParseResult.WriteToConsole(ResultLevel.Error, "Already contains {0} in file {1}, current one {2} will be ignored.", key.ApiName, saved.Path, key.Path);
                    }
                    else
                    {
                        key.Href = destFileName.FormatPath(UriKind.Relative, workingDirectory);
                        table.Add(key.ApiName, key);
                        if (key.Items != null)
                        {
                            foreach (var keyItem in key.Items)
                            {
                                keyItem.Href = Path.Combine(referenceFolder.FormatPath(UriKind.Relative, workingDirectory), keyItem.Path.ToValidFilePath());
                            }
                        }
                    }
                }
            }

            return(table);
        }