Esempio n. 1
0
        /// <summary>
        /// Checks if a preset includes a given item
        /// </summary>
        protected virtual bool Includes(TemplateTreeRoot entry, TemplateInfo itemData)
        {
            // check for path match
            var unescapedPath = entry.Path.Replace(@"\*", "*");

            if (!itemData.Path.StartsWith(unescapedPath + "/", StringComparison.OrdinalIgnoreCase) && !itemData.Path.Equals(unescapedPath, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // check excludes
            return(ExcludeMatches(entry, itemData));
        }
Esempio n. 2
0
        protected virtual bool ExcludeMatches(TemplateTreeRoot entry, TemplateInfo itemData)
        {
            foreach (var exclude in entry.Exclusions)
            {
                var result = exclude.Evaluate(itemData.Path);

                if (!result)
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        protected virtual TemplateTreeRoot CreateIncludeEntry(XmlNode configuration)
        {
            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 TemplateTreeRoot(nameValue, path);

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

            return(root);
        }
Esempio n. 4
0
        protected virtual IPresetTreeExclusion CreateExcludeEntry(XmlElement excludeNode, TemplateTreeRoot root)
        {
            if (excludeNode.HasAttribute("path"))
            {
                return(new PathBasedPresetTreeExclusion(GetExpectedAttribute(excludeNode, "path"), root));
            }

            var exclusions = excludeNode.ChildNodes
                             .OfType <XmlElement>()
                             .Where(element => element.Name.Equals("except") && element.HasAttribute("name"))
                             .Select(element => GetExpectedAttribute(element, "name"))
                             .ToArray();

            if (excludeNode.HasAttribute("children"))
            {
                return(new ChildrenOfPathBasedPresetTreeExclusion(root.Path, exclusions, root));
            }

            if (excludeNode.HasAttribute("childrenOfPath"))
            {
                return(new ChildrenOfPathBasedPresetTreeExclusion(GetExpectedAttribute(excludeNode, "childrenOfPath"), exclusions, root));
            }

            throw new InvalidOperationException($"Unable to parse invalid exclusion value: {excludeNode.OuterXml}");
        }