private static void _ValidateFactory(Evaluation.BuildContext bsettings, Func <string, SDK.ContentObject> filterFactory, Task[] tasks) { var classIds = tasks .SelectMany(item => item.Pipeline.Nodes) .Select(item => item.ClassIdentifier) .Distinct(); foreach (var cid in classIds) { try { var instance = filterFactory(cid); if (instance is Evaluation._UnknownNode) { throw new NullReferenceException(); } if (instance == null) { throw new NullReferenceException(); } } catch (Exception ex) { throw new ArgumentException($"Unable to create {cid} instance.", nameof(filterFactory), ex); } } }
public static void BuildProject(Project srcDoc, Evaluation.BuildContext bsettings, Func <String, SDK.ContentObject> filterFactory, SDK.IMonitorContext monitor, Evaluation.PipelineClientState.Manager outState) { if (srcDoc == null) { throw new ArgumentNullException(nameof(srcDoc)); } if (bsettings == null) { throw new ArgumentNullException(nameof(bsettings)); } if (filterFactory == null) { throw new ArgumentNullException(nameof(filterFactory)); } var tasks = srcDoc .Items .OfType <Task>() .Where(item => item.Enabled) .ToArray(); // Before running the tasks we have to ensure: // 1- BuildContext is valid // 2- there's enough space to write // 3- we're able to create instances of all the filters // 4- all the source files are available _ValidateFactory(bsettings, filterFactory, tasks); for (int i = 0; i < tasks.Length; ++i) { if (monitor.IsCancelRequested) { throw new OperationCanceledException(); } var watch = new System.Diagnostics.Stopwatch(); watch.Start(); var task = tasks[i]; var instance = Evaluation.PipelineInstance.CreatePipelineInstance(task.Pipeline, filterFactory, srcDoc.UseSettings); instance.Setup(bsettings); using (var evaluator = instance.CreateEvaluator(monitor.CreatePart(i, tasks.Length))) { var result = evaluator.EvaluateRoot(); // if (result is Exception ex) throw new InvalidOperationException($"Failed processing {task.Title}", ex); var fileReport = result.FileManager; watch.Stop(); outState?.SetResults(task.Pipeline.RootIdentifier, result, watch.Elapsed, fileReport); } } }