private bool TryExportResourceFiles(IEnumerable <string> resourceNames, string outputDirectory, bool overwrite, string regexFilter = null) { if (string.IsNullOrEmpty(outputDirectory)) { throw new ArgumentNullException(nameof(outputDirectory)); } if (!resourceNames.Any()) { return(false); } bool isEmpty = true; using (var templateResource = new CompositeResourceCollectionWithOverridden(resourceNames.Select(s => _finder.Find(s)).Where(s => s != null))) { if (templateResource.IsEmpty) { Logger.Log(LogLevel.Warning, $"No resource found for [{resourceNames.ToDelimitedString()}]."); } else { foreach (var pair in templateResource.GetResourceStreams(regexFilter)) { var outputPath = Path.Combine(outputDirectory, pair.Key); CopyResource(pair.Value, outputPath, overwrite); Logger.Log(LogLevel.Verbose, $"File {pair.Key} copied to {outputPath}."); isEmpty = false; } } return(!isEmpty); } }
private bool TryExportResourceFiles(IEnumerable<string> resourceNames, string outputDirectory, bool overwrite, string regexFilter = null) { if (string.IsNullOrEmpty(outputDirectory)) throw new ArgumentNullException(nameof(outputDirectory)); if (!resourceNames.Any()) return false; bool isEmpty = true; using (var templateResource = new CompositeResourceCollectionWithOverridden(resourceNames.Select(s => _finder.Find(s)).Where(s => s != null))) { if (templateResource.IsEmpty) { Logger.Log(LogLevel.Warning, $"No resource found for [{resourceNames.ToDelimitedString()}]."); } else { foreach (var pair in templateResource.GetResourceStreams(regexFilter)) { var outputPath = Path.Combine(outputDirectory, pair.Key); CopyResource(pair.Value, outputPath, overwrite); Logger.Log(LogLevel.Verbose, $"File {pair.Key} copied to {outputPath}."); isEmpty = false; } } return !isEmpty; } }
/// <summary> /// Template can contain a set of plugins to define the behavior of how to generate the output YAML data model /// The name of plugin folder is always "plugins" /// </summary> public IEnumerable <KeyValuePair <string, Stream> > GetTemplatePlugins() { using (var templateResource = new CompositeResourceCollectionWithOverridden(_templates.Select(s => _finder.Find(s)).Where(s => s != null))) { if (templateResource.IsEmpty) { yield break; } else { foreach (var pair in templateResource.GetResourceStreams(@"^plugins/.*")) { yield return(pair); } } } }
/// <summary> /// Template can contain a set of plugins to define the behavior of how to generate the output YAML data model /// The name of plugin folder is always "plugins" /// </summary> public IEnumerable<KeyValuePair<string, Stream>> GetTemplatePlugins() { using (var templateResource = new CompositeResourceCollectionWithOverridden(_templates.Select(s => _finder.Find(s)).Where(s => s != null))) { if (templateResource.IsEmpty) { yield break; } else { foreach (var pair in templateResource.GetResourceStreams(@"^plugins/.*")) { yield return pair; } } } }
private void ProcessTemplate(DocumentBuildContext context, string outputDirectory) { if (_templates == null || _templates.Count == 0) { Logger.Log(LogLevel.Info, "Template is not specified, files will not be transformed."); return; } using (var templateResource = new CompositeResourceCollectionWithOverridden(_templates.Select(s => _finder.Find(s)).Where(s => s != null))) { if (templateResource.IsEmpty) { Logger.Log(LogLevel.Warning, $"No template resource found for [{_templates.ToDelimitedString()}]."); } else { Logger.Log(LogLevel.Verbose, "Template resource found, starting applying template."); using (var processor = new TemplateProcessor(templateResource)) { processor.Process(context, outputDirectory); } } } }