Exemplo n.º 1
0
        public TemplateRoute(
            IRouter target,
            string routeName,
            string routeTemplate,
            IDictionary <string, object> defaults,
            IDictionary <string, object> constraints,
            IDictionary <string, object> dataTokens,
            IInlineConstraintResolver inlineConstraintResolver)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            _target        = target;
            _routeTemplate = routeTemplate ?? string.Empty;
            Name           = routeName;

            _dataTokens = dataTokens == null ? RouteValueDictionary.Empty : new RouteValueDictionary(dataTokens);

            // Data we parse from the template will be used to fill in the rest of the constraints or
            // defaults. The parser will throw for invalid routes.
            _parsedTemplate = TemplateParser.Parse(RouteTemplate);

            _constraints = GetConstraints(inlineConstraintResolver, RouteTemplate, _parsedTemplate, constraints);
            _defaults    = GetDefaults(_parsedTemplate, defaults);

            _matcher = new TemplateMatcher(_parsedTemplate, Defaults);
            _binder  = new TemplateBinder(_parsedTemplate, Defaults);
        }
Exemplo n.º 2
0
        public TemplateRoute(
            IRouter target,
            string routeName,
            string routeTemplate,
            IDictionary<string, object> defaults,
            IDictionary<string, object> constraints,
            IDictionary<string, object> dataTokens,
            IInlineConstraintResolver inlineConstraintResolver)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            _target = target;
            _routeTemplate = routeTemplate ?? string.Empty;
            Name = routeName;

            _dataTokens = dataTokens == null ? RouteValueDictionary.Empty : new RouteValueDictionary(dataTokens);

            // Data we parse from the template will be used to fill in the rest of the constraints or
            // defaults. The parser will throw for invalid routes.
            _parsedTemplate = TemplateParser.Parse(RouteTemplate);

            _constraints = GetConstraints(inlineConstraintResolver, RouteTemplate, _parsedTemplate, constraints);
            _defaults = GetDefaults(_parsedTemplate, defaults);

            _matcher = new TemplateMatcher(_parsedTemplate, Defaults);
            _binder = new TemplateBinder(_parsedTemplate, Defaults);
        }
        public SubdomainTemplateRoute(IRouter target, string routeName, string subdomainTemplate, string routeTemplate, IDictionary<string, object> defaults, IDictionary<string, object> constraints, IDictionary<string, object> dataTokens, IInlineConstraintResolver inlineConstraintResolver) {
            _innerRoute = new TemplateRoute(target, routeName, routeTemplate, defaults, constraints, dataTokens, inlineConstraintResolver);
            _subdomainTemplate = subdomainTemplate;
            _target = target;

            _matcher = new TemplateMatcher(TemplateParser.Parse(subdomainTemplate), Defaults);

            Name = routeName;
        }
Exemplo n.º 4
0
 public RedirectMiddleware(
     RequestDelegate next,
     string fromPath,
     string toPath)
 {
     _next = next;
     _toPath = toPath;
     _requestMatcher = new TemplateMatcher(TemplateParser.Parse(fromPath), new RouteValueDictionary());
 }
Exemplo n.º 5
0
        public SwaggerUiMiddleware(
            RequestDelegate next,
            SwaggerPathHelper swaggerPathHelper,
            string routeTemplate)
        {
            _next = next;
            _swaggerPathHelper = swaggerPathHelper;

            _requestMatcher = new TemplateMatcher(TemplateParser.Parse(routeTemplate), null);
            _resourceAssembly = GetType().GetTypeInfo().Assembly;
        }
Exemplo n.º 6
0
 public SwaggerUiMiddleware(
     RequestDelegate next,
     string baseRoute,
     string swaggerUrl
 )
 {
     _next = next;
     _requestMatcher = new TemplateMatcher(TemplateParser.Parse(baseRoute), new RouteValueDictionary());
     _swaggerUrl = swaggerUrl;
     _resourceAssembly = GetType().GetTypeInfo().Assembly;
 }
Exemplo n.º 7
0
        public SwaggerUiMiddleware(
            RequestDelegate next,
            string routePrefix,
            string swaggerUrl)
        {
            _next = next;

            var indexPath = routePrefix.Trim('/') + "/index.html";
            _requestMatcher = new TemplateMatcher(TemplateParser.Parse(indexPath), null);
            _resourceAssembly = GetType().GetTypeInfo().Assembly;

            _swaggerUrl = swaggerUrl;
        }
Exemplo n.º 8
0
 public SwaggerDocsMiddleware(
     RequestDelegate next,
     ISwaggerProvider swaggerProvider,
     string routeTemplate)
 {
     _next = next;
     _swaggerProvider = swaggerProvider;
     _requestMatcher = new TemplateMatcher(TemplateParser.Parse(routeTemplate), new RouteValueDictionary());
     _swaggerSerializer = new JsonSerializer
     {
         NullValueHandling = NullValueHandling.Ignore,
         ContractResolver = new SwaggerDocsContractResolver()
     };
 }
Exemplo n.º 9
0
        public TemplateRoute([NotNull] IRouter target,
                             string routeName,
                             string routeTemplate,
                             IDictionary <string, object> defaults,
                             IDictionary <string, object> constraints,
                             IDictionary <string, object> dataTokens,
                             IInlineConstraintResolver inlineConstraintResolver)
        {
            _target        = target;
            _routeTemplate = routeTemplate ?? string.Empty;
            Name           = routeName;
            _defaults      = defaults ?? new RouteValueDictionary();
            _constraints   = RouteConstraintBuilder.BuildConstraints(constraints, _routeTemplate) ??
                             new Dictionary <string, IRouteConstraint>();
            _dataTokens = dataTokens ?? new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            // The parser will throw for invalid routes.
            _parsedTemplate = TemplateParser.Parse(RouteTemplate, inlineConstraintResolver);
            UpdateInlineDefaultValuesAndConstraints();

            _matcher = new TemplateMatcher(_parsedTemplate);
            _binder  = new TemplateBinder(_parsedTemplate, _defaults);
        }
Exemplo n.º 10
0
 private void EnsureMatcher()
 {
     if (_matcher == null)
     {
         _matcher = new TemplateMatcher(ParsedTemplate, Defaults);
     }
 }