public Manifest Process(Manifest manifest, string outputFolder) { if (manifest == null) { throw new ArgumentNullException(nameof(manifest)); } if (outputFolder == null) { throw new ArgumentNullException(nameof(outputFolder)); } var context = new HtmlPostProcessContext(PostProcessorHost); foreach (var handler in Handlers) { handler.LoadContext(context); manifest = handler.PreHandle(manifest); } foreach (var tuple in from item in manifest.Files ?? Enumerable.Empty<ManifestItem>() from output in item.OutputFiles where output.Key.Equals(".html", StringComparison.OrdinalIgnoreCase) select new { Item = item, InputFile = item.SourceRelativePath, OutputFile = output.Value.RelativePath, }) { if (!EnvironmentContext.FileAbstractLayer.Exists(tuple.OutputFile)) { continue; } var document = new HtmlDocument(); try { using (var stream = EnvironmentContext.FileAbstractLayer.OpenRead(tuple.OutputFile)) { document.Load(stream, Encoding.UTF8); } } catch (Exception ex) { Logger.LogWarning($"Warning: Can't load content from {tuple.OutputFile}: {ex.Message}"); continue; } foreach (var handler in Handlers) { handler.Handle(document, tuple.Item, tuple.InputFile, tuple.OutputFile); } using (var stream = EnvironmentContext.FileAbstractLayer.Create(tuple.OutputFile)) { document.Save(stream, Encoding.UTF8); } } foreach (var handler in Handlers) { manifest = handler.PostHandle(manifest); handler.SaveContext(context); } context.Save(); return manifest; }
public override void SaveContext(HtmlPostProcessContext context) { context.Save(nameof(_registeredBookmarks), stream => Serialize(stream, _registeredBookmarks)); context.Save(nameof(_fileMapping), stream => Serialize(stream, _fileMapping)); }