Пример #1
0
 private void Save(IDocumentProcessor processor, HostService hostService, DocumentBuildContext context)
 {
     hostService.Models.RunAll(
         m =>
     {
         if (m.Type != DocumentType.Override)
         {
             using (new LoggerFileScope(m.OriginalFileAndType.File))
             {
                 Logger.LogVerbose($"Plug-in {processor.Name}: Saving...");
                 m.BaseDir = context.BuildOutputFolder;
                 if (m.PathRewriter != null)
                 {
                     m.File = m.PathRewriter(m.File);
                 }
                 var result = processor.Save(m);
                 if (result != null)
                 {
                     m.File           = TemplateProcessor.UpdateFilePath(m.File, result.DocumentType, context.TemplateCollection);
                     result.ModelFile = TemplateProcessor.UpdateFilePath(result.ModelFile, result.DocumentType, context.TemplateCollection);
                     HandleSaveResult(context, hostService, m, result);
                 }
             }
         }
     });
 }
Пример #2
0
        private void Prebuild(IDocumentProcessor processor, HostService hostService)
        {
            var models = processor.Prebuild(hostService.Models, hostService);

            if (!object.ReferenceEquals(models, hostService.Models))
            {
                hostService.Reload(models);
            }
        }
Пример #3
0
 private void Postbuild(IDocumentProcessor processor, HostService hostService)
 {
     RunBuildSteps(
         processor.BuildSteps,
         buildStep =>
     {
         Logger.LogVerbose($"Plug-in {processor.Name}, build step {buildStep.Name}: Postprocessing...");
         buildStep.Postbuild(hostService.Models, hostService);
     });
 }
Пример #4
0
        private void Postbuild(IDocumentProcessor processor, HostService hostService)
        {
            var models = processor.Postbuild(hostService.Models, hostService);

            if (!object.ReferenceEquals(models, hostService.Models))
            {
                Logger.LogVerbose($"Plug-in {processor.Name}: Reloading models...");
                hostService.Reload(models);
            }
        }
Пример #5
0
 private void BuildArticle(IDocumentProcessor processor, HostService hostService)
 {
     hostService.Models.RunAll(m =>
     {
         using (new LoggerFileScope(m.OriginalFileAndType.File))
         {
             Logger.LogVerbose($"Plug-in {processor.Name}: Building...");
             processor.Build(m, hostService);
         }
     });
 }
Пример #6
0
 private static void CheckFileLink(HostService hostService, SaveResult result)
 {
     result.LinkToFiles.RunAll(fileLink =>
     {
         if (!hostService.SourceFiles.ContainsKey(fileLink))
         {
             var message = $"Invalid file link({fileLink})";
             Logger.LogWarning(message);
         }
     });
 }
Пример #7
0
 private static void CheckFileLink(HostService hostService, FileModel model, SaveResult result)
 {
     result.LinkToFiles.RunAll(
         fileLink =>
     {
         if (!hostService.SourceFiles.ContainsKey(fileLink))
         {
             var message = $"Invalid file link({fileLink}) in file \"{model.LocalPathFromRepoRoot}\"";
             Logger.LogError(message, file: model.LocalPathFromRepoRoot);
             throw new DocumentException(message);
         }
     });
 }
Пример #8
0
 private void HandleSaveResult(
     DocumentBuildContext context,
     HostService hostService,
     FileModel model,
     SaveResult result)
 {
     context.FileMap[((RelativePath)model.OriginalFileAndType.File).GetPathFromWorkingFolder()] = ((RelativePath)model.File).GetPathFromWorkingFolder();
     DocumentException.RunAll(
         () => CheckFileLink(hostService, model, result),
         () => HandleUids(context, model, result),
         () => HandleToc(context, result),
         () => RegisterXRefSpec(context, model, result),
         () => RegisterManifest(context, model, result));
 }
Пример #9
0
 private void Postbuild(IDocumentProcessor processor, HostService hostService)
 {
     RunBuildSteps(
         processor.BuildSteps,
         buildStep =>
     {
         Logger.LogVerbose($"Plug-in {processor.Name}, build step {buildStep.Name}: Postprocessing...");
         var models = buildStep.Postbuild(hostService.Models, hostService);
         if (!object.ReferenceEquals(models, hostService.Models))
         {
             Logger.LogVerbose($"Plug-in {processor.Name}, build step {buildStep.Name}: Reloading models...");
             hostService.Reload(models);
         }
     });
 }
Пример #10
0
        private ManifestItem HandleSaveResult(
            DocumentBuildContext context,
            HostService hostService,
            FileModel model,
            SaveResult result)
        {
            context.FileMap[model.Key] = ((RelativePath)model.File).GetPathFromWorkingFolder();
            DocumentException.RunAll(
                () => CheckFileLink(hostService, result),
                () => HandleUids(context, result),
                () => HandleToc(context, result),
                () => RegisterXRefSpec(context, result));

            return(GetManifestItem(context, model, result));
        }
Пример #11
0
 private void BuildArticle(IDocumentProcessor processor, HostService hostService)
 {
     hostService.Models.RunAll(
         m =>
     {
         using (new LoggerFileScope(m.LocalPathFromRepoRoot))
         {
             Logger.LogVerbose($"Plug-in {processor.Name}: Building...");
             RunBuildSteps(
                 processor.BuildSteps,
                 buildStep =>
             {
                 Logger.LogVerbose($"Plug-in {processor.Name}, build step {buildStep.Name}: Building...");
                 buildStep.Build(m, hostService);
             });
         }
     },
         Constants.DefaultParallelism);
 }
Пример #12
0
 private void BuildCore(HostService hostService, IDocumentProcessor processor, DocumentBuildContext context)
 {
     Logger.LogInfo($"Plug-in {processor.Name}: Loading document...");
     hostService.SourceFiles = context.AllSourceFiles;
     foreach (var m in hostService.Models)
     {
         if (m.LocalPathFromRepoRoot == null)
         {
             m.LocalPathFromRepoRoot = Path.Combine(m.BaseDir, m.File);
         }
     }
     Logger.LogInfo($"Plug-in {processor.Name}: Document loaded (count = {hostService.Models.Count}).");
     Logger.LogInfo($"Plug-in {processor.Name}: Preprocessing...");
     Prebuild(processor, hostService);
     Logger.LogInfo($"Plug-in {processor.Name}: Building...");
     BuildArticle(processor, hostService);
     Logger.LogInfo($"Plug-in {processor.Name}: Postprocessing...");
     Postbuild(processor, hostService);
     Logger.LogInfo($"Plug-in {processor.Name}: Saving...");
     Save(processor, hostService, context);
 }
Пример #13
0
        private void UpdateHref(HostService hostService, IDocumentProcessor processor, DocumentBuildContext context)
        {
            Func <string, string, string> updater = (originalPathToFile, filePathToRoot) =>
            {
                string href;
                if (string.IsNullOrEmpty(originalPathToFile) || !context.FileMap.TryGetValue(originalPathToFile, out href))
                {
                    return(originalPathToFile);
                }
                var relativePath = ((RelativePath)href).MakeRelativeTo(((RelativePath)filePathToRoot).GetPathFromWorkingFolder());
                return(relativePath);
            };

            hostService.Models.RunAll(
                m =>
            {
                using (new LoggerFileScope(m.OriginalFileAndType.File))
                {
                    Logger.LogVerbose($"Plug-in {processor.Name}: Updating href...");
                    processor.UpdateHref(m, updater);
                }
            });
        }
Пример #14
0
 private static void CheckFileLink(HostService hostService, FileModel model, SaveResult result)
 {
     result.LinkToFiles.RunAll(
         fileLink =>
         {
             if (!hostService.SourceFiles.ContainsKey(fileLink))
             {
                 var message = $"Invalid file link({fileLink}) in file \"{model.LocalPathFromRepoRoot}\"";
                 Logger.LogError(message, file: model.LocalPathFromRepoRoot);
                 throw new DocumentException(message);
             }
         });
 }
Пример #15
0
 private void HandleSaveResult(
     DocumentBuildContext context,
     HostService hostService,
     FileModel model,
     SaveResult result)
 {
     context.FileMap[((RelativePath)model.OriginalFileAndType.File).GetPathFromWorkingFolder()] = ((RelativePath)model.File).GetPathFromWorkingFolder();
     DocumentException.RunAll(
         () => CheckFileLink(hostService, model, result),
         () => HandleUids(context, model, result),
         () => HandleToc(context, result),
         () => RegisterXRefSpec(context, model, result),
         () => RegisterManifest(context, model, result));
 }
Пример #16
0
 private void Save(IDocumentProcessor processor, HostService hostService, DocumentBuildContext context)
 {
     hostService.Models.RunAll(
         m =>
         {
             try
             {
                 if (m.Type != DocumentType.Override)
                 {
                     using (new LoggerFileScope(m.OriginalFileAndType.File))
                     {
                         Logger.LogVerbose($"Plug-in {processor.Name}: Saving...");
                         m.BaseDir = context.BuildOutputFolder;
                         var result = processor.Save(m);
                         if (result != null)
                         {
                             HandleSaveResult(context, hostService, m, result);
                         }
                     }
                 }
             }
             finally
             {
                 m.Dispose();
             }
         });
 }
Пример #17
0
 private void Postbuild(IDocumentProcessor processor, HostService hostService)
 {
     var models = processor.Postbuild(hostService.Models, hostService);
     if (!object.ReferenceEquals(models, hostService.Models))
     {
         Logger.LogVerbose($"Plug-in {processor.Name}: Reloading models...");
         hostService.Reload(models);
     }
 }
Пример #18
0
 private void UpdateHref(HostService hostService, IDocumentProcessor processor, DocumentBuildContext context)
 {
     Func<string, string, string> updater = (originalPathToFile, filePathToRoot) =>
     {
         string href;
         if (string.IsNullOrEmpty(originalPathToFile) || !context.FileMap.TryGetValue(originalPathToFile, out href))
         {
             return originalPathToFile;
         }
         var relativePath = ((RelativePath)href).MakeRelativeTo(((RelativePath)filePathToRoot).GetPathFromWorkingFolder());
         return relativePath;
     };
     hostService.Models.RunAll(
         m =>
         {
             using (new LoggerFileScope(m.OriginalFileAndType.File))
             {
                 Logger.LogVerbose($"Plug-in {processor.Name}: Updating href...");
                 processor.UpdateHref(m, updater);
             }
         });
 }
Пример #19
0
 public InnerBuildContext(HostService hostService, IDocumentProcessor processor, TemplateProcessor templateProcessor)
 {
     HostService       = hostService;
     Processor         = processor;
     TemplateProcessor = templateProcessor;
 }
Пример #20
0
 private void Cleanup(HostService hostService)
 {
     hostService.Models.RunAll(m => m.Dispose());
 }
Пример #21
0
 private void Save(IDocumentProcessor processor, HostService hostService, DocumentBuildContext context)
 {
     hostService.Models.RunAll(
         m =>
         {
             if (m.Type != DocumentType.Override)
             {
                 using (new LoggerFileScope(m.OriginalFileAndType.File))
                 {
                     Logger.LogVerbose($"Plug-in {processor.Name}: Saving...");
                     m.BaseDir = context.BuildOutputFolder;
                     if (m.PathRewriter != null)
                     {
                         m.File = m.PathRewriter(m.File);
                     }
                     var result = processor.Save(m);
                     if (result != null)
                     {
                         m.File = TemplateProcessor.UpdateFilePath(m.File, result.DocumentType, context.TemplateCollection);
                         result.ModelFile = TemplateProcessor.UpdateFilePath(result.ModelFile, result.DocumentType, context.TemplateCollection);
                         HandleSaveResult(context, hostService, m, result);
                     }
                 }
             }
         });
 }
Пример #22
0
 private void Cleanup(HostService hostService)
 {
     hostService.Models.RunAll(m => m.Dispose());
 }
Пример #23
0
 public InnerBuildContext(HostService hostService, IDocumentProcessor processor)
 {
     HostService = hostService;
     Processor = processor;
 }
Пример #24
0
 private void Postbuild(IDocumentProcessor processor, HostService hostService)
 {
     RunBuildSteps(
         processor.BuildSteps,
         buildStep =>
             {
                 Logger.LogVerbose($"Plug-in {processor.Name}, build step {buildStep.Name}: Postprocessing...");
                 var models = buildStep.Postbuild(hostService.Models, hostService);
                 if (!object.ReferenceEquals(models, hostService.Models))
                 {
                     Logger.LogVerbose($"Plug-in {processor.Name}, build step {buildStep.Name}: Reloading models...");
                     hostService.Reload(models);
                 }
             });
 }
Пример #25
0
 private void BuildCore(
     IDocumentProcessor processor,
     IEnumerable<FileAndType> files,
     ImmutableDictionary<string, object> metadata,
     FileMetadata fileMetadata,
     DocumentBuildContext context)
 {
     Logger.LogInfo($"Plug-in {processor.Name}: Loading document...");
     using (var hostService = new HostService(
         from file in files
         select Load(processor, metadata, fileMetadata, file)))
     {
         hostService.SourceFiles = context.AllSourceFiles;
         foreach (var m in hostService.Models)
         {
             if (m.LocalPathFromRepoRoot == null)
             {
                 m.LocalPathFromRepoRoot = Path.Combine(m.BaseDir, m.File);
             }
         }
         Logger.LogInfo($"Plug-in {processor.Name}: Document loaded (count = {hostService.Models.Count}).");
         Logger.LogInfo($"Plug-in {processor.Name}: Preprocessing...");
         Prebuild(processor, hostService);
         Logger.LogInfo($"Plug-in {processor.Name}: Building...");
         BuildArticle(processor, hostService);
         Logger.LogInfo($"Plug-in {processor.Name}: Postprocessing...");
         Postbuild(processor, hostService);
         Logger.LogInfo($"Plug-in {processor.Name}: Saving...");
         Save(processor, hostService, context);
     }
 }
Пример #26
0
 private void BuildCore(HostService hostService, IDocumentProcessor processor, DocumentBuildContext context)
 {
     Logger.LogInfo($"Plug-in {processor.Name}: Loading document...");
     hostService.SourceFiles = context.AllSourceFiles;
     foreach (var m in hostService.Models)
     {
         if (m.LocalPathFromRepoRoot == null)
         {
             m.LocalPathFromRepoRoot = Path.Combine(m.BaseDir, m.File);
         }
     }
     Logger.LogInfo($"Plug-in {processor.Name}: Document loaded (count = {hostService.Models.Count}).");
     Logger.LogInfo($"Plug-in {processor.Name}: Preprocessing...");
     Prebuild(processor, hostService);
     Logger.LogInfo($"Plug-in {processor.Name}: Building...");
     BuildArticle(processor, hostService);
     Logger.LogInfo($"Plug-in {processor.Name}: Postprocessing...");
     Postbuild(processor, hostService);
     Logger.LogInfo($"Plug-in {processor.Name}: Saving...");
     Save(processor, hostService, context);
 }
Пример #27
0
 private void Prebuild(IDocumentProcessor processor, HostService hostService)
 {
     var models = processor.Prebuild(hostService.Models, hostService);
     if (!object.ReferenceEquals(models, hostService.Models))
     {
         hostService.Reload(models);
     }
 }
Пример #28
0
 private void UpdateHref(HostService hostService, IDocumentProcessor processor, DocumentBuildContext context)
 {
     hostService.Models.RunAll(
         m =>
         {
             using (new LoggerFileScope(m.OriginalFileAndType.File))
             {
                 Logger.LogVerbose($"Plug-in {processor.Name}: Updating href...");
                 processor.UpdateHref(m, context);
             }
         });
 }
Пример #29
0
 private void BuildArticle(IDocumentProcessor processor, HostService hostService)
 {
     hostService.Models.RunAll(m =>
     {
         using (new LoggerFileScope(m.OriginalFileAndType.File))
         {
             Logger.LogVerbose($"Plug-in {processor.Name}: Building...");
             processor.Build(m, hostService);
         }
     });
 }