Exemple #1
0
        private IList <PresetTreeRoot> ParsePreset(XmlNode configuration, string configurationName)
        {
            var fieldTransforms = GetOptionalAttribute(configuration, "fieldTransforms");
            FieldTransformsCollection filters = null;

            if (!string.IsNullOrEmpty(fieldTransforms))
            {
                filters = MagicTokenTransformer.GetFieldTransforms(fieldTransforms);
            }

            var presets = configuration.ChildNodes
                          .Cast <XmlNode>()
                          .Where(node => node.Name == "include")
                          .Select(x => CreateIncludeEntry(x, filters))
                          .ToList();

            var names = new HashSet <string>();

            foreach (var preset in presets)
            {
                if (!names.Contains(preset.Name))
                {
                    names.Add(preset.Name);
                    continue;
                }

                throw new InvalidOperationException($"Multiple predicate include nodes in configuration '{configurationName}' had the same name '{preset.Name}'. This is not allowed. Note that this can occur if you did not specify the name attribute and two include entries end in an item with the same name. Use the name attribute on the include tag to give a unique name.");
            }

            return(presets);
        }
Exemple #2
0
        protected virtual PresetTreeRoot CreateIncludeEntry(XmlNode configuration, FieldTransformsCollection predicateFieldFilterCollection)
        {
            string database = GetExpectedAttribute(configuration, "database");
            string path     = GetExpectedAttribute(configuration, "path");

            // ReSharper disable once PossibleNullReferenceException
            var    name      = configuration.Attributes["name"];
            string nameValue = name == null?path.Substring(path.LastIndexOf('/') + 1) : name.Value;

            var root = new PresetTreeRoot(nameValue, path, database);

            root.Exclusions = configuration.ChildNodes
                              .OfType <XmlElement>()
                              .Where(element => element.Name.Equals("exclude"))
                              .Select(excludeNode => CreateExcludeEntry(excludeNode, root))
                              .ToList();

            string fieldFilter = GetOptionalAttribute(configuration, "fieldTransforms");
            FieldTransformsCollection localFieldFilters = null;

            if (!string.IsNullOrEmpty(fieldFilter))
            {
                localFieldFilters = MagicTokenTransformer.GetFieldTransforms(fieldFilter);
            }

            FieldTransformsCollection finalFilters = null;

            if (localFieldFilters != null)
            {
                if (predicateFieldFilterCollection != null)
                {
                    finalFilters = predicateFieldFilterCollection.MergeFilters(localFieldFilters);
                }
                else
                {
                    finalFilters = localFieldFilters;
                }
            }
            else
            {
                finalFilters = predicateFieldFilterCollection;
            }

            if (finalFilters != null)
            {
                root.FieldValueManipulator = finalFilters;
            }

            return(root);
        }
        private IList <PresetTreeRoot> ParsePreset(XmlNode configuration, string configurationName)
        {
            var fieldTransforms = GetOptionalAttribute(configuration, "fieldTransforms");
            FieldTransformsCollection filters = null;

            if (!string.IsNullOrEmpty(fieldTransforms))
            {
                filters = MagicTokenTransformer.GetFieldTransforms(fieldTransforms);
            }

            List <XmlNode> predicatePresetNodes = new List <XmlNode>();

            if (_predicatePresetHandler != null)
            {
                var predicatePresetElements = configuration.ChildNodes
                                              .Cast <XmlNode>()
                                              .Where(node => node.Name == "preset")
                                              .Cast <XmlElement>()
                                              .ToList();

                foreach (var element in predicatePresetElements)
                {
                    var id = element.Attributes["id"]?.Value;
                    var predicatePreset = _predicatePresetHandler.GetPresetById(id);
                    if (predicatePreset == null)
                    {
                        if (string.IsNullOrWhiteSpace(id))
                        {
                            id = "blank/missing";
                        }

                        throw new InvalidOperationException($"Configuration '{configurationName}' referenced a Predicate Preset with id '{id}' that could not be located.");
                    }

                    predicatePresetNodes.AddRange(predicatePreset.ApplyPreset(element));
                }
            }

            var predicatePresets = predicatePresetNodes
                                   .Select(x => CreateIncludeEntry(x, filters))
                                   .ToList();

            var includePresets = configuration.ChildNodes
                                 .Cast <XmlNode>()
                                 .Where(node => node.Name == "include")
                                 .Select(x => CreateIncludeEntry(x, filters))
                                 .ToList();

            includePresets.AddRange(predicatePresets);

            var names = new HashSet <string>();

            foreach (var preset in includePresets)
            {
                if (!names.Contains(preset.Name))
                {
                    names.Add(preset.Name);
                    continue;
                }

                throw new InvalidOperationException($"Multiple predicate include nodes in configuration '{configurationName}' had the same name '{preset.Name}'. This is not allowed. Note that this can occur if you did not specify the name attribute and two include entries end in an item with the same name. Use the name attribute on the include tag to give a unique name.");
            }

            return(includePresets);
        }