public RoutePatternBinder Create(string pattern)
        {
            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            return(Create(RoutePattern.Parse(pattern), new DispatcherValueCollection()));
        }
示例#2
0
        internal Cache CreateCache()
        {
            var endpoints = GetEndpoints();

            var groups = new Dictionary <Key, List <Endpoint> >();

            for (var i = 0; i < endpoints.Count; i++)
            {
                var endpoint = endpoints[i];

                var templateEndpoint = endpoint as IRoutePatternEndpoint;
                if (templateEndpoint == null)
                {
                    continue;
                }

                var order = endpoint.Metadata?.GetMetadata <IEndpointOrderMetadata>()?.Order ?? 0;
                if (!groups.TryGetValue(new Key(order, templateEndpoint.Pattern), out var group))
                {
                    group = new List <Endpoint>();
                    groups.Add(new Key(order, templateEndpoint.Pattern), group);
                }

                group.Add(endpoint);
            }

            var entries = new List <InboundRouteEntry>();

            foreach (var group in groups)
            {
                var routePattern = RoutePattern.Parse(group.Key.RoutePattern);
                var entryExists  = entries.Any(item => item.RoutePattern.RawText == routePattern.RawText);
                if (!entryExists)
                {
                    entries.Add(MapInbound(routePattern, group.Value.ToArray(), group.Key.Order));
                }
            }

            var trees = new List <UrlMatchingTree>();

            for (var i = 0; i < entries.Count; i++)
            {
                var entry = entries[i];

                while (trees.Count <= entry.Order)
                {
                    trees.Add(new UrlMatchingTree(entry.Order));
                }

                var tree = trees[entry.Order];

                UrlMatchingTree.AddEntryToTree(tree, entry);
            }

            return(new Cache(trees.ToArray()));
        }
示例#3
0
        public static RouteTemplate Parse(string routeTemplate)
        {
            if (routeTemplate == null)
            {
                throw new ArgumentNullException(routeTemplate);
            }

            try
            {
                var inner = RoutePattern.Parse(routeTemplate);
                return(new RouteTemplate(inner));
            }
            catch (ArgumentException ex) when(ex.InnerException is RoutePatternException)
            {
                throw new ArgumentException(ex.InnerException.Message, nameof(routeTemplate), ex.InnerException);
            }
        }