Exemplo n.º 1
0
        public IMatcher Add(string[] parts, int index, int priority)
        {
            _totalPriority = priority + _priority;
            if (index >= parts.Length)
            {
                return(this);
            }
            IMatcher matcher;

            if (!_statics.TryGetValue(parts[index], out matcher))
            {
                if (_matchers.Contains(parts[index]))
                {
                    matcher = _matchers[parts[index]];
                }
                else
                {
                    matcher = MatcherFactory.Create(parts[index]);
                    if (matcher is StaticMatcher)
                    {
                        _statics.Add(parts[index], matcher);
                    }
                    else
                    {
                        _matchers.Add(matcher);
                    }
                }
            }
            return(matcher.Add(parts, index + 1, _totalPriority));
        }
Exemplo n.º 2
0
        public void Add(string template, HandlerTypeInfo type)
        {
            var matchers = _matchers;
            var parts    = template.Trim('/').Split(new[] { '/' });

            if (parts.Length == 0)
            {
                return;
            }
            IMatcher matcher;

            if (_statics.ContainsKey(parts[0]))
            {
                matcher = _statics[parts[0]];
            }
            else if (matchers.Contains(parts[0]))
            {
                matcher = matchers[parts[0]];
            }
            else
            {
                matcher = MatcherFactory.Create(parts[0]);
                if (matcher is StaticMatcher)
                {
                    _statics.Add(parts[0], matcher);
                }
                else
                {
                    matchers.Add(matcher);
                }
            }

            if (parts.Length == 1)
            {
                matcher.AddTypeInfo(type);
                return;
            }

            matcher.Add(parts, 1, 0).AddTypeInfo(type);
        }