示例#1
0
        /// <summary>
        /// Checks if a preset includes a given item
        /// </summary>
        protected virtual bool Includes(ITemplateTreeRoot 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));
        }
示例#2
0
        protected virtual bool ExcludeMatches(ITemplateTreeRoot entry, TemplateInfo itemData)
        {
            foreach (var exclude in entry.Exclusions)
            {
                var result = exclude.Evaluate(itemData.Path);

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

            return(true);
        }
示例#3
0
        protected virtual IPresetTreeExclusion CreateExcludeEntry(XmlElement excludeNode, ITemplateTreeRoot root)
        {
            if (excludeNode.HasAttribute("path"))
            {
                return(new PathBasedPresetTreeExclusion(excludeNode.GetExpectedAttribute("path"), root.Path));
            }

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

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

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

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