Esempio n. 1
0
        public List <TransformConfiguration> ReadFromFile(string path, string rootPath = "")
        {
            using (var str = FileReader.ReadFile(path))
            {
                var doc = XDocument.Load(str);
                if (doc.Root == null)
                {
                    throw InvalidConfigurationFile.BecauseMissingRoot(path);
                }

                var rootPostTransformations = GetPostTransformation(doc.Root, new List <IPostTransformation>(), path);
                var result = doc.Root.Elements()
                             .Where(x => x.IsElementWithName(TransformationGroupElementName))
                             .Select(x =>
                {
                    var groupPostTransformations = GetPostTransformation(x, rootPostTransformations, path);
                    var pattern = x.Attribute(PatternSourceElementName)?.Value;

                    if (string.IsNullOrWhiteSpace(pattern))
                    {
                        throw InvalidConfigurationFile.BecauseMissingPattern(path);
                    }

                    var placeholderPattern = x.Attribute(PlaceholderPattern)?.Value;

                    var transformations = x.Elements()
                                          .Where(y => y.IsElementWithName(TransformationElementName))
                                          .Select(y =>
                    {
                        var valuesProvider = CreateValuesProvider(y, rootPath);
                        if (valuesProvider == null)
                        {
                            throw InvalidConfigurationFile.BecauseMissingValuesSource(path, pattern);
                        }

                        var outputFilePath = y.Attribute(OutputPathElementName)?.Value;

                        if (string.IsNullOrWhiteSpace(outputFilePath))
                        {
                            throw InvalidConfigurationFile.BecauseMissingOutput(path, pattern);
                        }

                        return(new TransformConfiguration
                        {
                            PlaceholderPattern = placeholderPattern,
                            PatternFilePath = pattern,
                            OutputFilePath = outputFilePath,
                            OutputArchive = y.Attribute(OutputArchiveElementName)?.Value,
                            ValuesProvider = valuesProvider,
                            PostTransformations = GetPostTransformation(y, groupPostTransformations, path)
                        });
                    }).ToList();
                    return(transformations);
                });
                return(result.SelectMany(x => x).ToList());
            }
        }
Esempio n. 2
0
        private List <IPostTransformationsConfigurationOperation> GetPostTransformationsConfiguration(XElement node, string path)
        {
            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 InvalidConfigurationFile.BecauseDuplicatedPostTransformations(path);
            }
        }