示例#1
0
        public void Merge(MetadataMergeParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (parameters.OutputBaseDir == null)
            {
                throw new ArgumentException("Output folder cannot be null.", nameof(parameters) + "." + nameof(parameters.OutputBaseDir));
            }
            if (parameters.Files == null)
            {
                throw new ArgumentException("Source files cannot be null.", nameof(parameters) + "." + nameof(parameters.Files));
            }
            if (parameters.Metadata == null)
            {
                parameters.Metadata = ImmutableDictionary <string, object> .Empty;
            }

            using (new LoggerPhaseScope(PhaseName))
            {
                Directory.CreateDirectory(parameters.OutputBaseDir);
                Logger.LogInfo("Start merge metadata...");
                MergePageViewModel(parameters);
                MergeToc(parameters);
                Logger.LogInfo("Merge metadata completed.");
            }
        }
示例#2
0
        private static void MergePageViewModel(MetadataMergeParameters parameters, string outputBase)
        {
            var p = new ManagedReferenceDocumentProcessor();

            p.BuildSteps = new List <IDocumentBuildStep>
            {
                new ApplyPlatformVersion(),
                new MergeManagedReferenceDocument(),
            };
            var fc = new FileCollection(parameters.Files);

            fc.RemoveAll(x => "toc.yml".Equals(Path.GetFileName(x.File), StringComparison.OrdinalIgnoreCase));
            var models = DocumentBuilder.Build(
                p,
                new DocumentBuildParameters
            {
                Files          = fc,
                FileMetadata   = parameters.FileMetadata,
                MaxParallelism = 1,
                Metadata       = parameters.Metadata,
                OutputBaseDir  = parameters.OutputBaseDir,
            });

            foreach (var m in models)
            {
                m.File = m.PathRewriter(m.File);
            }
            foreach (var m in models)
            {
                YamlUtility.Serialize(Path.Combine(outputBase, m.File), m.Content);
            }
        }
示例#3
0
        private static void MergeToc(MetadataMergeParameters parameters, string outputBase)
        {
            var tocFiles =
                (from f in parameters.Files.EnumerateFiles()
                 where f.Type == DocumentType.Article && "toc.yml".Equals(Path.GetFileName(f.File), StringComparison.OrdinalIgnoreCase)
                 select f).ToList();
            var vm = MergeTocViewModel(
                from f in tocFiles
                select YamlUtility.Deserialize <TocViewModel>(Path.Combine(f.BaseDir, f.File)));

            YamlUtility.Serialize(Path.Combine(outputBase, tocFiles[0].PathRewriter(tocFiles[0].File)), vm);
        }
示例#4
0
        private void MergeToc(MetadataMergeParameters parameters)
        {
            var tocFiles =
                (from f in parameters.Files.EnumerateFiles()
                 where f.Type == DocumentType.Article && "toc.yml".Equals(Path.GetFileName(f.File), StringComparison.OrdinalIgnoreCase)
                 select f).ToList();
            var vm = MergeTocViewModel(
                from f in tocFiles
                select YamlUtility.Deserialize <TocViewModel>(f.File));

            CopyMetadataToToc(vm);
            YamlUtility.Serialize(
                ((RelativePath)tocFiles[0].DestinationDir + (((RelativePath)tocFiles[0].File) - (RelativePath)tocFiles[0].SourceDir)).ToString(),
                vm,
                YamlMime.TableOfContent);
        }
示例#5
0
        private static void MergeToc(MetadataMergeParameters parameters, string outputBase)
        {
            var tocFiles =
                (from f in parameters.Files.EnumerateFiles()
                 where f.Type == DocumentType.Article && "toc.yml".Equals(Path.GetFileName(f.File), StringComparison.OrdinalIgnoreCase)
                 select f).ToList();
            var vm = MergeTocViewModel(
                from f in tocFiles
                select YamlUtility.Deserialize <TocViewModel>(Path.Combine(f.BaseDir, f.File)));

            YamlUtility.Serialize(
                Path.Combine(
                    outputBase,
                    (TypeForwardedToRelativePath)tocFiles[0].DestinationDir + (((TypeForwardedToRelativePath)tocFiles[0].File) - (TypeForwardedToRelativePath)tocFiles[0].SourceDir)),
                vm,
                YamlMime.TableOfContent);
        }
示例#6
0
        private void MergePageViewModel(MetadataMergeParameters parameters)
        {
            var p = new ManagedReferenceDocumentProcessor()
            {
                BuildSteps = new List <IDocumentBuildStep>
                {
                    new ApplyPlatformVersion(),
                    new MergeManagedReferenceDocument(),
                }
            };
            var fc = new FileCollection(parameters.Files);

            fc.RemoveAll(x => "toc.yml".Equals(Path.GetFileName(x.File), StringComparison.OrdinalIgnoreCase));
            var models = SingleDocumentBuilder.Build(
                p,
                new DocumentBuildParameters
            {
                Files          = fc,
                FileMetadata   = parameters.FileMetadata,
                MaxParallelism = 1,
                Metadata       = parameters.Metadata,
                OutputBaseDir  = parameters.OutputBaseDir,
            },
                new DfmServiceProvider().CreateMarkdownService(
                    new MarkdownServiceParameters
            {
                BasePath = fc.DefaultBaseDir,
            }));

            foreach (var m in models)
            {
                m.File = (RelativePath)m.FileAndType.DestinationDir + (((RelativePath)m.File) - (RelativePath)m.FileAndType.SourceDir);
                Console.WriteLine($"File:{m.OriginalFileAndType.File} from:{m.FileAndType.SourceDir} to:{m.FileAndType.DestinationDir} => {m.File}");
            }
            foreach (var m in models)
            {
                InitTable(m, parameters.TocMetadata);
                YamlUtility.Serialize(m.File, m.Content, YamlMime.ManagedReference);
            }
        }