Ejemplo n.º 1
0
        protected virtual bool IsMatch(ITemplateSourceEntry entry, string pattern)
        {
            string rx = Regex.Escape(pattern);

            rx = rx.Replace("\\*", ".*").Replace("\\?", ".?");
            Regex r = new Regex(rx);

            return(r.IsMatch(entry.Name));
        }
Ejemplo n.º 2
0
        public string PathRelativeTo(ITemplateSourceEntry source)
        {
            //The path should be relative to either source itself (in the case that it's a folder) or the parent of source)
            ITemplateSourceFolder relTo = source as ITemplateSourceFolder ?? source.Parent;

            //If the thing to be relative to is the root (or a file in the root), just use the full path of the item
            if (relTo == null)
            {
                return(FullPath);
            }

            //Get all the path segments for the thing we're relative to
            Dictionary <ITemplateSourceFolder, int> sourceSegments = new Dictionary <ITemplateSourceFolder, int> {
                { relTo, 0 }
            };
            ITemplateSourceFolder current = relTo.Parent;
            int index = 0;

            while (current != null)
            {
                sourceSegments[current] = ++index;
                current = current.Parent;
            }

            current = Parent;
            List <string> segments = new List <string> {
                Name
            };

            //Walk back the set of parents of this item until one is contained by our source, building up a list as we go
            int revIndex = 0;

            while (current != null && !sourceSegments.TryGetValue(current, out revIndex))
            {
                segments.Insert(0, current.Name);
                current = current.Parent;
            }

            //Now that we've found our common point (and the index of the common segment _from the end_ of the source's parent chain)
            //  the number of levels up we need to go is the value of revIndex
            segments.InsertRange(0, Enumerable.Repeat("..", revIndex));
            return(string.Join("/", segments));
        }
 public EmbeddedTemplateSource(IConfiguredTemplateSource parent, ITemplateSourceEntry entry, ITemplateSource source)
 {
     _parent = parent;
     _entry  = entry;
     _source = source;
 }