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); } } } }); }
private void Prebuild(IDocumentProcessor processor, HostService hostService) { var models = processor.Prebuild(hostService.Models, hostService); if (!object.ReferenceEquals(models, hostService.Models)) { hostService.Reload(models); } }
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); }); }
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); } }
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); } }); }
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); } }); }
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); } }); }
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)); }
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); } }); }
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)); }
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); }
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); }
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); } }); }
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(); } }); }
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); } }); }
public InnerBuildContext(HostService hostService, IDocumentProcessor processor, TemplateProcessor templateProcessor) { HostService = hostService; Processor = processor; TemplateProcessor = templateProcessor; }
private void Cleanup(HostService hostService) { hostService.Models.RunAll(m => m.Dispose()); }
public InnerBuildContext(HostService hostService, IDocumentProcessor processor) { HostService = hostService; Processor = processor; }
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); } }
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); } }); }