private IEnumerable <IValuesProvider> GetValuesProviders(XElement node, Dictionary <string, XmlInlineConfigurationValuesProvider> valuesGroups) { if (node.Element(ValuesSourceElementName) != null) { yield return(new XmlInlineConfigurationValuesProvider(node.Element(ValuesSourceElementName))); } var externalValuesFile = node.Attribute(ValuesSourceElementName)?.Value; if (string.IsNullOrWhiteSpace(externalValuesFile) == false) { var fileFullPath = UpdatePathWithRootPath(externalValuesFile, rootPath); if (fileSystem.FileExists(fileFullPath) == false) { throw InvalidConfigurationException.BecauseIncludedFileDoesNotExist(fileFullPath); } yield return(new XmlFileConfigurationValuesProvider(fileFullPath, xmlReader)); } var valuesGroupName = node.Attribute("valuesGroup")?.Value; if (string.IsNullOrWhiteSpace(valuesGroupName) == false) { if (valuesGroups.TryGetValue(valuesGroupName, out var group)) { yield return(group); } else { throw InvalidConfigurationException.BecauseUnknowValuesGroup(valuesGroupName); } } }
public XElement Read(string path) { using (var str = textFileReader.ReadFile(path)) { var doc = XDocument.Load(str, LoadOptions.PreserveWhitespace); if (doc.Root == null) { throw InvalidConfigurationException.BecauseMissingRoot(); } return(doc.Root); } }
public List <TransformConfiguration> ReadConfig(string path) { var doc = xmlReader.Read(path); var valuesGroups = ReadValuesGroups(doc); var rootPostTransformations = GetPostTransformation(doc, new List <IPostTransformation>()); var result = doc.Elements() .Where(x => x.IsElementWithName(TransformationGroupElementName)) .Select(x => { var groupPostTransformations = GetPostTransformation(x, rootPostTransformations); var pattern = x.Attribute(PatternSourceElementName)?.Value; if (string.IsNullOrWhiteSpace(pattern)) { throw InvalidConfigurationException.BecauseMissingPattern(); } var placeholderPattern = x.Attribute(PlaceholderPattern)?.Value; var transformations = x.Elements() .Where(y => y.IsElementWithName(TransformationElementName)) .Select(y => { var valuesProvider = CreateValuesProvider(y, valuesGroups); if (valuesProvider == null) { throw InvalidConfigurationException.BecauseMissingValuesSource(pattern); } var outputFilePath = y.Attribute(OutputPathElementName)?.Value; if (string.IsNullOrWhiteSpace(outputFilePath)) { throw InvalidConfigurationException.BecauseMissingOutput(pattern); } return(new TransformConfiguration { PlaceholderPattern = placeholderPattern, PatternFilePath = pattern, OutputFilePath = outputFilePath, OutputArchive = y.Attribute(OutputArchiveElementName)?.Value, ValuesProvider = valuesProvider, PostTransformations = GetPostTransformation(y, groupPostTransformations) }); }).ToList(); return(transformations); }); return(result.SelectMany(x => x).ToList()); }
private Dictionary <string, XmlInlineConfigurationValuesProvider> ReadValuesGroups(XElement rootElement) { return(rootElement.Elements() .Where(x => x.IsElementWithName(ValuesGroupElementName)) .Select(x => { var groupName = x.Attribute("name")?.Value; if (string.IsNullOrWhiteSpace(groupName)) { throw InvalidConfigurationException.BecauseMissingGroupName(); } var valuesProvider = new XmlInlineConfigurationValuesProvider(x); return new { groupName, valuesProvider }; }).ToDictionary(el => el.groupName, el => el.valuesProvider)); }
private List <IPostTransformationsConfigurationOperation> GetPostTransformationsConfiguration(XElement node) { try { var postTransformationsNode = node.Elements() .SingleOrDefault(x => x.IsElementWithName(PostTransformationElementName)); if (postTransformationsNode == null) { return(new List <IPostTransformationsConfigurationOperation>()); } return(postTransformationsNode.Elements() .Select(PostTransformationsConfigurationOperationFactory.Create) .ToList()); } catch (InvalidOperationException) { throw InvalidConfigurationException.BecauseDuplicatedPostTransformations(); } }