/// <summary>
        /// Processes one attribute route
        /// </summary>
        /// <param name="action">Action to process</param>
        /// <returns>Route information</returns>
        private AttributeRouteInfo ProcessAttributeRoute(ControllerActionDescriptor action)
        {
            string constraint;

            action.RouteValues.TryGetValue(TreeRouter.RouteGroupKey, out constraint);
            if (string.IsNullOrEmpty(constraint))
            {
                // This can happen if an ActionDescriptor has a route template, but doesn't have one of our
                // special route group constraints. This is a good indication that the user is using a 3rd party
                // routing system, or has customized their ADs in a way that we can no longer understand them.
                //
                // We just treat this case as an 'opt-out' of our attribute routing system.
                return(null);
            }

            var template = TemplateParser.Parse(action.AttributeRouteInfo.Template);

            var info = new AttributeRouteInfo
            {
                Constraints = GetConstraints(action.AttributeRouteInfo.Template, template),
                Defaults    = GetDefaults(action, template),
                Optional    = new List <string>(),
                Order       = action.AttributeRouteInfo.Order,
                Precedence  = RoutePrecedence.ComputeOutbound(template),
            };

            _parser.Parse(template, info);

            return(info);
        }
Exemple #2
0
        public static void LogTo(this Route route, TextWriter writer)
        {
            string name = route is IAttributeRoute
                ? ((IAttributeRoute)route).RouteName : null;

            LogWriter.LogRoute(writer, name, AttributeRouteInfo.GetRouteInfo(route.Url, route.Defaults, route.Constraints, route.DataTokens));
        }
 private static IEnumerable <AttributeRouteInfo> GetRouteInfo()
 {
     return
         (RouteTable.Routes.Cast <Route>().Select(
              route =>
              AttributeRouteInfo.GetRouteInfo(route.Url, route.Defaults, route.Constraints, route.DataTokens)));
 }
Exemple #4
0
 private static IEnumerable <object> GetRouteInfo()
 {
     return(from r in RouteTable.Routes.OfType <Route>()
            let routeInfo = AttributeRouteInfo.GetRouteInfo(r.Url, r.Defaults, r.Constraints, r.DataTokens)
                            select new
     {
         methods = routeInfo.HttpMethods,
         url = routeInfo.Url,
         defaults = routeInfo.Defaults.Select(kvp => new { key = kvp.Key, value = kvp.Value }),
         constraints = routeInfo.Constraints.Select(kvp => new { key = kvp.Key, value = kvp.Value }),
         dataTokens = routeInfo.DataTokens.Select(kvp => new { key = kvp.Key, value = kvp.Value })
     });
 }
        /// <summary>
        /// Processes one attribute route
        /// </summary>
        /// <param name="action">Action to process</param>
        /// <returns>Route information</returns>
        private AttributeRouteInfo ProcessAttributeRoute(ControllerActionDescriptor action)
        {
            var template = TemplateParser.Parse(action.AttributeRouteInfo.Template);

            var info = new AttributeRouteInfo
            {
                Constraints = GetConstraints(action.AttributeRouteInfo.Template, template),
                Defaults    = GetDefaults(action, template),
                Optional    = new List <string>(),
                Order       = action.AttributeRouteInfo.Order,
                Precedence  = RoutePrecedence.ComputeOutbound(template),
            };

            _parser.Parse(template, info);

            return(info);
        }
        public HttpMethodEnricherTests()
        {
            request = LinkRequestBuilder.CreateWithRouteName(TestRouteName);
            context = new LinkFactoryContext();
            writer  = new LinkDataWriter(context);

            endpointMetadata = new List <object> {
                new HttpMethodMetadata(new string[] { TestHttpMethod })
            };
            attributeRouteInfo = new AttributeRouteInfo {
                Name = TestRouteName
            };

            mockProvider = new Mock <IActionDescriptorCollectionProvider>();
            SetupProvider();

            sut = new HttpMethodEnricher(mockProvider.Object);
        }
        static ControllerActionDescriptor Clone(ControllerActionDescriptor action, AttributeRouteInfo attributeRouteInfo)
        {
            var clone = new ControllerActionDescriptor()
            {
                ActionConstraints  = action.ActionConstraints,
                ActionName         = action.ActionName,
                AttributeRouteInfo = attributeRouteInfo,
                BoundProperties    = action.BoundProperties,
                ControllerName     = action.ControllerName,
                ControllerTypeInfo = action.ControllerTypeInfo,
                DisplayName        = action.DisplayName,
                FilterDescriptors  = action.FilterDescriptors,
                MethodInfo         = action.MethodInfo,
                Parameters         = action.Parameters,
                Properties         = action.Properties,
                RouteValues        = action.RouteValues,
            };

            return(clone);
        }
Exemple #8
0
 public AttributeRouteInfoValues(AttributeRouteInfo inner)
 {
     Template = inner?.Template;
     Order    = inner?.Order;
     Name     = inner?.Name;
 }