public override void AddEndpoint(MatcherEndpoint endpoint)
        {
            var handler = new RouteHandler(c =>
            {
                var feature      = c.Features.Get <IEndpointFeature>();
                feature.Endpoint = endpoint;
                feature.Invoker  = MatcherEndpoint.EmptyInvoker;

                return(Task.CompletedTask);
            });

            // MatcherEndpoint.Values contains the default values parsed from the template
            // as well as those specified with a literal. We need to separate those
            // for legacy cases.
            var defaults = endpoint.Defaults;

            for (var i = 0; i < endpoint.ParsedTemplate.Parameters.Count; i++)
            {
                var parameter = endpoint.ParsedTemplate.Parameters[i];
                if (parameter.DefaultValue == null && defaults.ContainsKey(parameter.Name))
                {
                    throw new InvalidOperationException(
                              "The TreeRouter does not support non-inline default values.");
                }
            }

            _inner.MapInbound(
                handler,
                endpoint.ParsedTemplate,
                routeName: null,
                order: endpoint.Order);
        }
        public override void AddEndpoint(MatcherEndpoint endpoint)
        {
            var handler = new RouteHandler(c =>
            {
                c.Features.Get <IEndpointFeature>().Endpoint = endpoint;
                return(Task.CompletedTask);
            });

            // MatcherEndpoint.Values contains the default values parsed from the template
            // as well as those specified with a literal. We need to separate those
            // for legacy cases.
            var defaults = endpoint.Defaults;

            for (var i = 0; i < endpoint.ParsedTemplate.Parameters.Count; i++)
            {
                var parameter = endpoint.ParsedTemplate.Parameters[i];
                if (parameter.DefaultValue != null)
                {
                    defaults.Remove(parameter.Name);
                }
            }

            _entries.Add(new Entry()
            {
                Endpoint = endpoint,
                Route    = new Route(
                    handler,
                    endpoint.Template,
                    defaults,
                    new Dictionary <string, object>(),
                    new RouteValueDictionary(),
                    _constraintResolver),
            });
        }
Пример #3
0
            public override void AddEntry(string pattern, MatcherEndpoint endpoint)
            {
                var handler = new RouteHandler(c =>
                {
                    c.Features.Get <IEndpointFeature>().Endpoint = endpoint;
                    return(Task.CompletedTask);
                });

                _routes.Add(new Route(handler, pattern, _constraintResolver));
            }
Пример #4
0
            public override void AddEntry(string template, MatcherEndpoint endpoint)
            {
                var handler = new RouteHandler(c =>
                {
                    c.Features.Get <IEndpointFeature>().Endpoint = endpoint;
                    return(Task.CompletedTask);
                });

                _inner.MapInbound(handler, TemplateParser.Parse(template), "default", 0);
            }
Пример #5
0
        private static Candidate CreateCandidate(MatcherEndpoint endpoint)
        {
            var parsed = TemplateParser.Parse(endpoint.Template);

            return(new Candidate()
            {
                Endpoint = endpoint,
                Parameters = parsed.Segments.Select(s => s.IsSimple && s.Parts[0].IsParameter ? s.Parts[0].Name : null).ToArray(),
            });
        }
        public override void AddEndpoint(MatcherEndpoint endpoint)
        {
            var parsed = TemplateParser.Parse(endpoint.Template);

            _entries.Add(new Entry()
            {
                Order      = 0,
                Pattern    = parsed,
                Precedence = RoutePrecedence.ComputeInbound(parsed),
                Endpoint   = endpoint,
            });
        }
 private void SetupEndpoints()
 {
     _endpoints    = new MatcherEndpoint[10];
     _endpoints[0] = CreateEndpoint("/another-really-cool-entry");
     _endpoints[1] = CreateEndpoint("/Some-Entry");
     _endpoints[2] = CreateEndpoint("/a/path/with/more/segments");
     _endpoints[3] = CreateEndpoint("/random/name");
     _endpoints[4] = CreateEndpoint("/random/name2");
     _endpoints[5] = CreateEndpoint("/random/name3");
     _endpoints[6] = CreateEndpoint("/random/name4");
     _endpoints[7] = CreateEndpoint("/plaintext1");
     _endpoints[8] = CreateEndpoint("/plaintext2");
     _endpoints[9] = CreateEndpoint("/plaintext");
 }
        public void Setup()
        {
            _endpoints    = new MatcherEndpoint[1];
            _endpoints[0] = CreateEndpoint("/plaintext");

            _requests    = new HttpContext[1];
            _requests[0] = new DefaultHttpContext();
            _requests[0].RequestServices = CreateServices();
            _requests[0].Request.Path    = "/plaintext";

            _minimal     = SetupMatcher(MinimalMatcher.CreateBuilder());
            _dfa         = SetupMatcher(DfaMatcher.CreateBuilder());
            _instruction = SetupMatcher(InstructionMatcher.CreateBuilder());
            _route       = SetupMatcher(RouteMatcher.CreateBuilder());
            _tree        = SetupMatcher(TreeRouterMatcher.CreateBuilder());

            _feature = new EndpointFeature();
        }
Пример #9
0
        internal override Matcher CreateMatcher(MatcherEndpoint endpoint)
        {
            var builder = new TreeRouteBuilder(
                NullLoggerFactory.Instance,
                new DefaultObjectPool <UriBuildingContext>(new UriBuilderContextPooledObjectPolicy()),
                new DefaultInlineConstraintResolver(Options.Create(new RouteOptions())));

            var handler = new RouteHandler(c =>
            {
                var feature      = c.Features.Get <IEndpointFeature>();
                feature.Endpoint = endpoint;
                feature.Invoker  = MatcherEndpoint.EmptyInvoker;

                return(Task.CompletedTask);
            });

            builder.MapInbound(handler, TemplateParser.Parse(endpoint.Template), "default", 0);

            return(new TreeRouterMatcher(builder.Build()));
        }
Пример #10
0
 public override void AddEndpoint(MatcherEndpoint endpoint)
 {
     _endpoints.Add(endpoint);
 }
Пример #11
0
 internal abstract Matcher CreateMatcher(MatcherEndpoint endpoint);
Пример #12
0
 public InnerMatcher(string[] segments, MatcherEndpoint endpoint)
 {
     _segments = segments;
     _endpoint = endpoint;
 }
Пример #13
0
 public TrivialMatcher(MatcherEndpoint endpoint)
 {
     _endpoint = endpoint;
 }
Пример #14
0
 public AcceptNode(int depth, MatcherEndpoint endpoint)
 {
     Depth    = depth;
     Endpoint = endpoint;
 }
Пример #15
0
 public int AddEndpoint(MatcherEndpoint endpoint)
 {
     _endpoints.Add(endpoint);
     return(_endpoints.Count - 1);
 }