public void SetUp() { Engine = new Engine(); Engine.FileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider()); Engine.FileSystem.RootPath = "/"; Engine.FileSystem.InputPaths.Clear(); Engine.FileSystem.InputPaths.Add("/TestFiles/Input"); Pipeline = new Pipeline("Pipeline", null); Context = new ExecutionContext(Engine, Pipeline); Inputs = new[] { Context.GetDocument() }; }
public void SetUp() { Engine = new Engine(); Engine.FileSystem.FileProviders.Add(NormalizedPath.DefaultFileProvider.Scheme, GetFileProvider()); Engine.FileSystem.RootPath = "/"; Engine.FileSystem.InputPaths.Clear(); Engine.FileSystem.InputPaths.Add("/TestFiles/Input"); Pipeline = new ExecutionPipeline("Pipeline", (IModuleList)null); Context = new ExecutionContext(Engine, Guid.Empty, Pipeline); Inputs = new[] { Context.GetDocument() }; }
public void SetUp() { Engine = new Engine(); Engine.FileSystem.FileProviders.Add(string.Empty, GetFileProvider()); Engine.FileSystem.RootPath = "/"; Engine.FileSystem.InputPaths.Clear(); Engine.FileSystem.InputPaths.Add("/TestFiles/Input"); Pipeline = new Pipeline("Pipeline", null); Context = new ExecutionContext(Engine, Pipeline); Inputs = new[] { Context.GetDocument() }; }
public void SitemapGeneratedWithSitemapItemAsString(string hostname, string formatterString, string expected) { // Given Engine engine = new Engine(); if (!string.IsNullOrWhiteSpace(hostname)) { engine.Settings[Keys.Host] = hostname; } ExecutionPipeline contentPipeline = new ExecutionPipeline("Content", (IModuleList)null); IExecutionContext context = new ExecutionContext(engine, Guid.Empty, contentPipeline); IDocument doc = context.GetDocument(context.GetContentStream("Test"), new[] { new KeyValuePair <string, object>(Keys.RelativeFilePath, "sub/testfile.html") }); IDocument[] inputs = { doc }; Core.Modules.Metadata.Meta m = new Core.Modules.Metadata.Meta( Keys.SitemapItem, (d, c) => d[Keys.RelativeFilePath].ToString()); var outputs = m.Execute(inputs, context); Func <string, string> formatter = null; if (!string.IsNullOrWhiteSpace(formatterString)) { formatter = f => string.Format(formatterString, f); } // When Sitemap sitemap = new Sitemap(formatter); List <IDocument> results = sitemap.Execute(outputs.ToList(), context).ToList(); foreach (IDocument document in inputs.Concat(outputs.ToList())) { ((IDisposable)document).Dispose(); } // Then Assert.AreEqual(1, results.Count); Assert.That(results[0].Content, Does.Contain($"<loc>{expected}</loc>")); }
public void SitemapGeneratedWithSitemapItemAsString(string hostname, string formatterString, string expected) { // Given Engine engine = new Engine(); if (!string.IsNullOrWhiteSpace(hostname)) { engine.Settings.Host = hostname; } Pipeline contentPipeline = new Pipeline("Content", null); IExecutionContext context = new ExecutionContext(engine, contentPipeline); IDocument doc = context.GetDocument("Test", new[] { new KeyValuePair<string, object>(Keys.RelativeFilePath, "sub/testfile.html") }); IDocument[] inputs = {doc}; Core.Modules.Metadata.Meta m = new Core.Modules.Metadata.Meta(Keys.SitemapItem, (d, c) => d[Keys.RelativeFilePath].ToString()); var outputs = m.Execute(inputs, context); Func<string, string> formatter = null; if (!string.IsNullOrWhiteSpace(formatterString)) formatter = f => string.Format(formatterString, f); // When Sitemap sitemap = new Sitemap(formatter); List<IDocument> results = sitemap.Execute(outputs.ToList(), context).ToList(); foreach (IDocument document in inputs.Concat(outputs.ToList())) { ((IDisposable) document).Dispose(); } // Then Assert.AreEqual(1, results.Count); Assert.That(results[0].Content, Does.Contain($"<loc>{expected}</loc>")); }
// This executes the specified modules with the specified input documents public IReadOnlyList <IDocument> Execute(ExecutionContext context, IEnumerable <IModule> modules, ImmutableArray <IDocument> documents) { if (_disposed) { throw new ObjectDisposedException(nameof(Pipeline)); } foreach (IModule module in modules.Where(x => x != null)) { string moduleName = module.GetType().Name; System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew(); using (Trace.WithIndent().Verbose("Executing module {0} with {1} input document(s)", moduleName, documents.Length)) { try { // Execute the module IEnumerable <IDocument> outputs = module.Execute(documents, context.Clone(module)); documents = outputs?.Where(x => x != null).ToImmutableArray() ?? ImmutableArray <IDocument> .Empty; // Remove any documents that were previously processed (checking will also mark the cache entry as hit) if (_previouslyProcessedCache != null && _processedSources != null) { ImmutableArray <IDocument> .Builder newDocuments = ImmutableArray.CreateBuilder <IDocument>(); foreach (IDocument document in documents) { if (_processedSources.ContainsKey(document.Source)) { // We've seen this source before and already added it to the processed cache newDocuments.Add(document); } else { List <IDocument> processedDocuments; if (!_previouslyProcessedCache.TryGetValue(document, out processedDocuments)) { // This document was not previously processed, so add it to the current result and set up a list to track final results newDocuments.Add(document); processedDocuments = new List <IDocument>(); _previouslyProcessedCache.Set(document, processedDocuments); _processedSources.Add(document.Source, processedDocuments); } // Otherwise, this document was previously processed so don't add it to the results } } if (newDocuments.Count != documents.Length) { Trace.Verbose("Removed {0} previously processed document(s)", documents.Length - newDocuments.Count); } documents = newDocuments.ToImmutable(); } // Set results in engine and trace context.Engine.DocumentCollection.Set(Name, documents); stopwatch.Stop(); Trace.Verbose("Executed module {0} in {1} ms resulting in {2} output document(s)", moduleName, stopwatch.ElapsedMilliseconds, documents.Length); } catch (Exception) { Trace.Error("Error while executing module {0}", moduleName); documents = ImmutableArray <IDocument> .Empty; context.Engine.DocumentCollection.Set(Name, documents); throw; } } } return(documents); }
private ExecutionContext(ExecutionContext original, IModule module) { Engine = original.Engine; _pipeline = original._pipeline; Module = module; }