Ejemplo n.º 1
0
        public void SettingEndpointSetsEndpointOnHttpContext()
        {
            var httpContext = new DefaultHttpContext();
            var ep          = new RouteEndpoint(
                TestConstants.EmptyRequestDelegate,
                RoutePatternFactory.Parse("/"),
                0,
                new EndpointMetadataCollection(),
                "test");

            new EndpointSelectorContext(httpContext)
            {
                Endpoint = ep,
            };

            // Assert
            var endpoint = httpContext.GetEndpoint();

            Assert.NotNull(endpoint);
            Assert.Same(ep, endpoint);
        }
Ejemplo n.º 2
0
        private TemplateBinder CreateTemplateBinder(RouteEndpoint endpoint)
        {
            // Now create the constraints and parameter transformers from the pattern
            var policies = new List <(string parameterName, IParameterPolicy policy)>();

            foreach (var kvp in endpoint.RoutePattern.ParameterPolicies)
            {
                var parameterName = kvp.Key;

                // It's possible that we don't have an actual route parameter, we need to support that case.
                var parameter = endpoint.RoutePattern.GetParameter(parameterName);

                // Use the first parameter transformer per parameter
                var foundTransformer = false;
                for (var i = 0; i < kvp.Value.Count; i++)
                {
                    var parameterPolicy = _parameterPolicyFactory.Create(parameter, kvp.Value[i]);
                    if (!foundTransformer && parameterPolicy is IOutboundParameterTransformer parameterTransformer)
                    {
                        policies.Add((parameterName, parameterTransformer));
                        foundTransformer = true;
                    }

                    if (parameterPolicy is IRouteConstraint constraint)
                    {
                        policies.Add((parameterName, constraint));
                    }
                }
            }

            return(new TemplateBinder(
                       UrlEncoder.Default,
                       _uriBuildingContextPool,
                       endpoint.RoutePattern,
                       new RouteValueDictionary(endpoint.RoutePattern.Defaults),
                       endpoint.RoutePattern.RequiredValues.Keys,
                       policies));
        }
Ejemplo n.º 3
0
 internal TemplateBinder GetTemplateBinder(RouteEndpoint endpoint) => _cache.EnsureInitialized().GetOrAdd(endpoint, _createTemplateBinder);
Ejemplo n.º 4
0
 private TemplateBinder CreateTemplateBinder(RouteEndpoint endpoint)
 {
     return(_binderFactory.Create(endpoint.RoutePattern));
 }
Ejemplo n.º 5
0
 // Internal for testing
 internal MatcherState GetMatcherState(RouteEndpoint endpoint) => _matcherCache.EnsureInitialized().GetOrAdd(endpoint, _createMatcher);
Ejemplo n.º 6
0
 // Internal for testing
 internal GlobalRouteValuesLinkGeneratorTemplateBinder GetTemplateBinder(RouteEndpoint endpoint) => _cache.EnsureInitialized().GetOrAdd(endpoint, _createTemplateBinder);
Ejemplo n.º 7
0
 private GlobalRouteValuesLinkGeneratorTemplateBinder CreateTemplateBinder(RouteEndpoint endpoint)
 {
     return(_binderFactory.Create(endpoint.RoutePattern));
 }
 /// <summary>
 /// Process the endpoint with the context.
 /// </summary>
 /// <param name="context">The <see cref="HttpContext"/>.</param>
 /// <param name="endpoint">The <see cref="RouteEndpoint"/>.</param>
 protected virtual void Process(HttpContext context, RouteEndpoint endpoint)
 {
 }