Exemplo n.º 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);
                 }
             }
         }
     });
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
     });
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
         }
     });
 }
Exemplo n.º 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);
         }
     });
 }
Exemplo n.º 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);
         }
     });
 }
Exemplo n.º 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));
 }
Exemplo n.º 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);
         }
     });
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
                }
            });
        }
Exemplo n.º 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);
             }
         });
 }
Exemplo n.º 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));
 }
Exemplo n.º 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();
             }
         });
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
             }
         });
 }
Exemplo n.º 19
0
 public InnerBuildContext(HostService hostService, IDocumentProcessor processor, TemplateProcessor templateProcessor)
 {
     HostService       = hostService;
     Processor         = processor;
     TemplateProcessor = templateProcessor;
 }
Exemplo n.º 20
0
 private void Cleanup(HostService hostService)
 {
     hostService.Models.RunAll(m => m.Dispose());
 }
Exemplo n.º 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);
                     }
                 }
             }
         });
 }
Exemplo n.º 22
0
 private void Cleanup(HostService hostService)
 {
     hostService.Models.RunAll(m => m.Dispose());
 }
Exemplo n.º 23
0
 public InnerBuildContext(HostService hostService, IDocumentProcessor processor)
 {
     HostService = hostService;
     Processor = processor;
 }
Exemplo n.º 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);
                 }
             });
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
             }
         });
 }
Exemplo n.º 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);
         }
     });
 }