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 = HtmlPostProcessContext.Load(PostProcessorHost); foreach (var handler in Handlers) { handler.SetContext(context); manifest = handler.PreHandleWithScopeWrapper(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.HandleWithScopeWrapper(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.PostHandleWithScopeWrapper(manifest); } context.Save(); return(manifest); }
private static OSPlatformSensitiveDictionary <T> Deserialize <T>(HtmlPostProcessContext context, string name) where T : class { return(context.Load( name, stream => { using var sr = new StreamReader(stream); return JsonUtility.Deserialize <OSPlatformSensitiveDictionary <T> >(sr); })); }