示例#1
0
        public static void Alter(IRouteDefinition route, string methodName, IEnumerable<string> properties,
            Action<string> log)
        {
            log("Method name interpreted by the MethodToUrlBuilder");
            var parts = AddHttpConstraints(route, methodName, log);

            for (var i = 0; i < parts.Count; i++)
            {
                var part = parts[i];
                if (properties.Contains(part))
                {
                    log(" - adding route input for property " + part);
                    parts[i] = "{" + part + "}";
                }
                else
                {
                    parts[i] = part.ToLower();
                }
            }

            if (parts.Any())
            {
                route.Append(parts.Join("/"));
            }
        }
        public void Given()
        {
            var graph = new BehaviorGraph();
            var chain = graph.AddActionFor("api/action1/{input}/", typeof(Action1));

            _route = chain.Route;
        }
 public void Setup()
 {
     _policy = new RouteConstraintPolicy();
     _routeDefinition = new RouteDefinition("something");
     _policy.AddHttpMethodFilter(x => x.Method.Name.StartsWith("Query"), "GET");
     _policy.AddHttpMethodFilter(x => x.Method.Name.EndsWith("Command"), "POST");
 }
示例#4
0
        public IRouteDefinition Build(ActionCall call)
        {
            IRouteDefinition route = call.ToRouteDefinition();

            if (!IgnoreControllerNamespaceEntirely)
            {
                addNamespace(route, call);
            }

            if (!IgnoreControllerNamesEntirely)
            {
                addClassName(route, call);
            }

            addMethodName(route, call);

            if (call.HasInput)
            {
                _routeInputPolicy.AlterRoute(route, call);
            }

            _modifications.Each(m =>
            {
                if (m.Filter(call))
                {
                    m.Modify(route);
                }
            });

            return(route);
        }
        public void Given()
        {
            var graph = new BehaviorGraph();
            var chain = graph.AddActionFor("api/action1/{input}/", typeof(Action1));

            _route = chain.Route;
        }
示例#6
0
 public void VisitRoute(IRouteDefinition route, BehaviorChain chain)
 {
     if (_behaviorFilters.MatchesAll(chain) && _routeFilters.MatchesAll(route))
     {
         _actions.Do(route, chain);
     }
 }
示例#7
0
 public void VisitRoute(IRouteDefinition route, BehaviorChain chain)
 {
     if (_behaviorFilters.MatchesAll(chain) && _routeFilters.MatchesAll(route))
     {
         _actions.Do(route, chain);
     }
 }
        public void Apply(BehaviorGraph graph, BehaviorChain chain)
        {
            // Don't override the route if it already exists
            if (chain.Route != null)
            {
                return;
            }

            var log = graph.Observer;

            ActionCall call = chain.Calls.FirstOrDefault();

            if (call == null)
            {
                return;
            }

            IUrlPolicy policy = _policies.FirstOrDefault(x => x.Matches(call, log)) ?? _defaultUrlPolicy;

            log.RecordCallStatus(call, "First matching UrlPolicy (or default): {0}".ToFormat(policy.GetType().Name));

            IRouteDefinition route = policy.Build(call);

            _constraintPolicy.Apply(call, route, log);

            log.RecordCallStatus(call, "Route definition determined by url policy: [{0}]".ToFormat(route.ToRoute().Url));
            graph.RegisterRoute(chain, route);
        }
示例#9
0
        public static void Alter(IRouteDefinition route, string methodName, IEnumerable<string> properties, Action<string> log)
        {
            log("Method name interpreted by the MethodToUrlBuilder");
            var parts = methodName.Split('_').ToList();

            var method = parts.First().ToUpper();
            if (RouteDefinition.VERBS.Contains(method))
            {
                log(" - adding Http method constraint {0}".ToFormat(method));
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }

            for (int i = 0; i < parts.Count; i++)
            {
                var part = parts[i];
                if (properties.Contains(part))
                {
                    log(" - adding route input for property " + part);
                    parts[i] = "{" + part + "}";
                }
                else
                {
                    parts[i] = part.ToLower();
                }

            }

            route.Append(parts.Join("/"));
        }
示例#10
0
        public static void Alter(IRouteDefinition route, string methodName, IEnumerable <string> properties,
                                 Action <string> log)
        {
            log("Method name interpreted by the MethodToUrlBuilder");
            var parts = AddHttpConstraints(route, methodName, log);

            for (var i = 0; i < parts.Count; i++)
            {
                var part = parts[i];
                if (properties.Contains(part))
                {
                    log(" - adding route input for property " + part);
                    parts[i] = "{" + part + "}";
                }
                else
                {
                    parts[i] = part.ToLower();
                }
            }

            if (parts.Any())
            {
                route.Append(parts.Join("/"));
            }
        }
示例#11
0
        public static void Alter(IRouteDefinition route, string methodName, IEnumerable <string> properties, Action <string> log)
        {
            log("Method name interpreted by the MethodToUrlBuilder");
            var parts = methodName.Split('_').ToList();

            var method = parts.First().ToUpper();

            if (RouteDefinition.VERBS.Contains(method))
            {
                log(" - adding Http method constraint {0}".ToFormat(method));
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }

            for (int i = 0; i < parts.Count; i++)
            {
                var part = parts[i];
                if (properties.Contains(part))
                {
                    log(" - adding route input for property " + part);
                    parts[i] = "{" + part + "}";
                }
                else
                {
                    parts[i] = part.ToLower();
                }
            }

            route.Append(parts.Join("/"));
        }
示例#12
0
        public static Parameter createParameter(PropertyInfo propertyInfo, IRouteDefinition route)
        {
            var parameter = new Parameter
            {
                name            = propertyInfo.Name,
                dataType        = propertyInfo.PropertyType.Name,
                paramType       = "post",
                allowMultiple   = false,
                required        = propertyInfo.HasAttribute <RequiredAttribute>(),
                description     = propertyInfo.GetAttribute <DescriptionAttribute>(a => a.Description),
                defaultValue    = propertyInfo.GetAttribute <DefaultValueAttribute>(a => a.Value.ToString()),
                allowableValues = getAllowableValues(propertyInfo)
            };

            if (route.Input.RouteParameters.Any(r => r.Name == propertyInfo.Name))
            {
                parameter.paramType = "path";
            }

            if (route.Input.QueryParameters.Any(r => r.Name == propertyInfo.Name))
            {
                parameter.paramType = "query";
            }

            return(parameter);
        }
 public void Apply(ActionCall call, IRouteDefinition routeDefinition)
 {
     var httpMethods = _httpMethodFilters.Where(x => x.Filter(call)).Select(x => x.Method).ToArray();
     if (httpMethods.Length > 0)
     {
         routeDefinition.AddRouteConstraint(HTTP_METHOD_CONSTRAINT, new HttpMethodConstraint(httpMethods));
     }
 }
示例#14
0
 public void Setup()
 {
     _policy          = new RouteConstraintPolicy();
     _routeDefinition = new RouteDefinition("something");
     _observer        = new RecordingConfigurationObserver();
     _policy.AddHttpMethodFilter(x => x.Method.Name.StartsWith("Query"), "GET");
     _policy.AddHttpMethodFilter(x => x.Method.Name.EndsWith("Command"), "POST");
 }
示例#15
0
 private bool shouldBeClickable(IRouteDefinition routeDefinition)
 {
     if (routeDefinition == null || routeDefinition.Rank > 0) return false;
     if (routeDefinition is NulloRouteDefinition) return false;
     var httpConstraint = routeDefinition.Constraints.Select(c => c.Value).OfType<HttpMethodConstraint>().FirstOrDefault();
     if (httpConstraint != null && !httpConstraint.AllowedMethods.Any(m => m.Equals("GET", StringComparison.OrdinalIgnoreCase))) return false;
     return true;
 }
示例#16
0
        public static void ConstrainToHttpMethods(this IRouteDefinition routeDef, params string[] methods)
        {
            if (methods.Length == 0)
            {
                return;
            }

            routeDef.AddRouteConstraint(RouteConstraintPolicy.HTTP_METHOD_CONSTRAINT, new HttpMethodConstraint(methods));
        }
        public void Setup()
        {
            _policy = new RouteConstraintPolicy();
            _routeDefinition = MockRepository.GenerateMock<IRouteDefinition>();
            _policy.AddHttpMethodFilter(x => x.Method.Name.StartsWith("Query"), "GET");
            _policy.AddHttpMethodFilter(x => x.Method.Name.EndsWith("Command"), "POST");

            _argsToAddConstraint = _routeDefinition.CaptureArgumentsFor(r => r.AddRouteConstraint(null, null));
        }
示例#18
0
 public static void ApplyQueryStringAttributes(this IRouteDefinition routeDefinition, ActionCall call)
 {
     if (call.HasInput)
     {
         call
         .InputType()
         .PropertiesWhere(p => p.HasAttribute <QueryStringAttribute>())
         .Each(routeDefinition.Input.AddQueryInput);
     }
 }
示例#19
0
 public static void ApplyRouteInputAttributes(this IRouteDefinition routeDefinition, ActionCall call)
 {
     if (call.HasInput)
     {
         call
         .InputType()
         .PropertiesWhere(p => p.HasAttribute <RouteInputAttribute>())
         .Each(p => routeDefinition.Input.AddRouteInput(new RouteParameter(new SingleProperty(p)), true));
     }
 }
示例#20
0
        public void Apply(ActionCall call, IRouteDefinition routeDefinition)
        {
            _httpMethodFilters.Where(x => x.Filter(call)).Each(filter =>
            {
                routeDefinition.Trace("Adding route constraint {0} based on filter [{1}]", filter.Method,
                                      filter.Description);

                routeDefinition.AddHttpMethodConstraint(filter.Method);
            });
        }
        public void Given()
        {
            var graph = new BehaviorGraph();
            var chain = graph.AddActionFor("api/action1/{input}/", typeof (Action1));

            _route = chain.Route;
            _property = ReflectionHelper.GetProperty<ActionRequest>(a => a.redfish);

            _result = ActionCallMapper.createParameter(_property, _route);
        }
        public void SetUp()
        {
            graph = new FubuRegistry(x =>
            {
                x.Route("/area/sub/{Name}/{Age}")
                    .Calls<InputController>(c => c.DoSomething(null)).OutputToJson();
            }).BuildGraph();

            route = graph.Behaviors.Where(x => x.InputType() == typeof (Registration.InputModel)).First().Route;
        }
示例#23
0
        public RoutedChain(IRouteDefinition route)
        {
            if (route == null)
            {
                throw new ArgumentNullException("route");
            }

            UrlCategory = new UrlCategory();
            Route = route;
        }
        public void Apply(ActionCall call, IRouteDefinition routeDefinition)
        {
            _httpMethodFilters.Where(x => x.Filter(call)).Each(filter =>
            {
                routeDefinition.Trace("Adding route constraint {0} based on filter [{1}]", filter.Method,
                                      filter.Description);

                routeDefinition.AddHttpMethodConstraint(filter.Method);
            });
        }
示例#25
0
        public void AddMethodName(IRouteDefinition route, ActionCall call)
        {
            if (_ignoredMethodNames.Contains(call.Method.Name.ToLower())) return;

            var urlPart = _methodNameBuilder.Build(call.Method);
            if (urlPart.IsNotEmpty())
            {
                route.Append(urlPart.ToLower());
            }
        }
示例#26
0
        public RoutedChain(IRouteDefinition route)
        {
            if (route == null)
            {
                throw new ArgumentNullException("route");
            }


            Route = route;
        }
示例#27
0
        public void Given()
        {
            var graph = new BehaviorGraph();
            var chain = graph.AddActionFor("api/action1/{input}/", typeof(Action1));

            _route    = chain.Route;
            _property = ReflectionHelper.GetProperty <ActionRequest>(a => a.redfish);

            _result = ActionCallMapper.createParameter(_property, _route);
        }
示例#28
0
        private static void AppendMethod(IRouteDefinition route, ActionCallBase call, IEnumerable <PropertyInfo> properties, IEnumerable <Regex> ignore)
        {
            var part = RemovePattern(call.Method.Name, ignore);

            Append(route, properties, part);
            if (call.HasInput)
            {
                route.ApplyInputType(call.InputType());
            }
        }
示例#29
0
        public void Apply(ActionCall call, IRouteDefinition routeDefinition, IConfigurationObserver observer)
        {
            _httpMethodFilters.Where(x => x.Filter(call)).Each(filter =>
            {
                observer.RecordCallStatus(call,
                                          "Adding route constraint {0} based on filter [{1}]".ToFormat(filter.Method, filter.Description));

                routeDefinition.AddHttpMethodConstraint(filter.Method);
            });
        }
示例#30
0
        public void Setup()
        {
            _policy          = new RouteConstraintPolicy();
            _routeDefinition = MockRepository.GenerateMock <IRouteDefinition>();
            _observer        = new RecordingConfigurationObserver();
            _policy.AddHttpMethodFilter(x => x.Method.Name.StartsWith("Query"), "GET");
            _policy.AddHttpMethodFilter(x => x.Method.Name.EndsWith("Command"), "POST");

            _argsToAddConstraint = _routeDefinition.CaptureArgumentsFor(r => r.AddRouteConstraint(null, null));
        }
示例#31
0
        public void Apply(ActionCall call, IRouteDefinition routeDefinition, IConfigurationObserver observer)
        {
            _httpMethodFilters.Where(x => x.Filter(call)).Each(filter =>
            {
                observer.RecordCallStatus(call,
                    "Adding route constraint {0} based on filter [{1}]".ToFormat(filter.Method, filter.Description));

                routeDefinition.AddHttpMethodConstraint(filter.Method);
            });
        }
示例#32
0
        public void SetUp()
        {
            visitor = new RouteVisitor();
            route = MockRepository.GenerateMock<IRouteDefinition>();
            chain = new BehaviorChain();

            processor = MockRepository.GenerateMock<RouteProcessor>();

            visitor.Actions += (x, y) => processor.Got(x, y);
        }
示例#33
0
        private static void Append(IRouteDefinition route, IEnumerable <PropertyInfo> properties, params string[] parts)
        {
            var url = parts.Select(x => x.Split('_').Select(y => properties.Select(z => z.Name).Contains(y) ? "{" + y + "}" : y.ToLower()))
                      .Select(x => x.Where(y => !string.IsNullOrEmpty(y)).Join("/"))
                      .Where(x => !string.IsNullOrEmpty(x)).ToList();

            if (url.Any())
            {
                route.Append(url.Join("/"));
            }
        }
示例#34
0
        /// <summary>
        ///   Finds the matching BehaviorChain for the given IRouteDefinition.  If no
        ///   BehaviorChain exists, one is created and added to the BehaviorGraph
        /// </summary>
        /// <param name = "route"></param>
        /// <returns></returns>
        public BehaviorChain ChainFor(IRouteDefinition route)
        {
            var chain = _chains.OfType<RoutedChain>().FirstOrDefault(x => x.Route == route);
            if (chain == null)
            {
                chain = new RoutedChain(route);
                _chains.Fill(chain);
            }

            return chain;
        }
示例#35
0
        public static List<string> AddHttpConstraints(IRouteDefinition route, string methodName)
        {
            var parts = methodName.Replace("___", "-").Replace("__", "_^").Split('_').ToList();

            var method = parts.First().ToUpper();
            if (RouteDefinition.VERBS.Contains(method))
            {
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }
            return parts;
        }
示例#36
0
        public RoutedChain(IRouteDefinition route, Type inputType, Type resourceType) : this(route)
        {
            if (inputType != null)
            {
                route.ApplyInputType(inputType);
            }

            if (resourceType != null)
            {
                ResourceType(resourceType);
            }
        }
示例#37
0
        private void addNamespace(IRouteDefinition route, ActionCall call)
        {
            var ns = replace(call.HandlerType.Namespace, _ignoredNamespaces).TrimStart('.');

            ns = ns.Replace('.', '/');
            route.Append(ns);

            if (IgnoreControllerFolderName)
            {
                route.RemoveLastPatternPart();
            }
        }
示例#38
0
        private RouteBase buildRoute(IServiceFactory factory, SessionStateRequirement defaultSessionRequirement,
            BehaviorChain chain, IRouteDefinition routeDefinition)
        {
            var requiresSession = routeDefinition.SessionStateRequirement ?? defaultSessionRequirement;

            var route = routeDefinition.ToRoute();
            var handlerSource = DetermineHandlerSource(requiresSession, chain);
            var invoker = DetermineInvoker(factory, chain);

            route.RouteHandler = new FubuRouteHandler(invoker, handlerSource);

            return route;
        }
示例#39
0
        public static List<string> AddHttpConstraints(IRouteDefinition route, string methodName, Action<string> log)
        {
            var parts = methodName.Split('_').ToList();

            var method = parts.First().ToUpper();
            if (RouteDefinition.VERBS.Contains(method))
            {
                log(" - adding Http method constraint {0}".ToFormat(method));
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }
            return parts;
        }
示例#40
0
        public static List <string> AddHttpConstraints(IRouteDefinition route, string methodName)
        {
            var parts = methodName.Replace("___", "-").Replace("__", "_^").Split('_').ToList();

            var method = parts.First().ToUpper();

            if (RouteDefinition.VERBS.Contains(method))
            {
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }
            return(parts);
        }
        public void Apply(ActionCall call, IRouteDefinition routeDefinition, IConfigurationObserver observer)
        {
            var matchingFilters = _httpMethodFilters.Where(x => x.Filter(call));

            var httpMethods = matchingFilters.Select(x => x.Method).ToArray();
            if (httpMethods.Length > 0)
            {
                routeDefinition.AddRouteConstraint(HTTP_METHOD_CONSTRAINT, new HttpMethodConstraint(httpMethods));
                matchingFilters.Each(filter => observer.RecordCallStatus(call,
                    "Adding route constraint {0} based on filter [{1}]".ToFormat(filter.Method, filter.Description)));

            }
        }
示例#42
0
        public static void Alter(IRouteDefinition route, ActionCall call)
        {
            var properties = call.HasInput
                                 ? new TypeDescriptorCache().GetPropertiesFor(call.InputType()).Keys
                                 : new string[0];

            Alter(route, call.Method.Name, properties, text => call.Trace(text));

            if (call.HasInput)
            {
                route.ApplyInputType(call.InputType());
            }
        }
示例#43
0
        public static IEnumerable <string> getRouteVerbs(IRouteDefinition route)
        {
            var verbs = route.AllowedHttpMethods;

            //no constraints are presnt so we default to GET
            //Better than emitting operations for all known HTTP verbs?
            if (!verbs.Any())
            {
                verbs.Add("GET");
            }

            return(verbs);
        }
示例#44
0
        private void addMethodName(IRouteDefinition route, ActionCall call)
        {
            if (_ignoredMethodNames.Contains(call.Method.Name.ToLower()))
            {
                return;
            }
            string urlPart = _methodNameBuilder.Build(call.Method);

            if (urlPart.IsNotEmpty())
            {
                route.Append(urlPart.ToLower());
            }
        }
示例#45
0
        public static IEnumerable<string> getRouteVerbs(IRouteDefinition route)
        {
            var verbs = route.AllowedHttpMethods;

            //no constraints are presnt so we default to GET
            //Better than emitting operations for all known HTTP verbs?
            if (!verbs.Any())
            {
                verbs.Add("GET");
            }

            return verbs;
        }
示例#46
0
        public static void Alter(IRouteDefinition route, ActionCall call, IConfigurationObserver observer)
        {
            var properties = call.HasInput
                                 ? new TypeDescriptorCache().GetPropertiesFor(call.InputType()).Keys
                                 : new string[0];

            Alter(route, call.Method.Name, properties, text => observer.RecordCallStatus(call, text));

            if (call.HasInput)
            {
                route.ApplyInputType(call.InputType());
            }
        }
示例#47
0
        private RouteBase buildRoute(IServiceFactory factory, SessionStateRequirement defaultSessionRequirement,
                                     BehaviorChain chain, IRouteDefinition routeDefinition)
        {
            var requiresSession = routeDefinition.SessionStateRequirement ?? defaultSessionRequirement;

            var route         = routeDefinition.ToRoute();
            var handlerSource = DetermineHandlerSource(requiresSession, chain);
            var invoker       = DetermineInvoker(factory, chain);

            route.RouteHandler = new FubuRouteHandler(invoker, handlerSource);

            return(route);
        }
示例#48
0
        public void Apply(ActionCall call, IRouteDefinition routeDefinition, IConfigurationObserver observer)
        {
            var matchingFilters = _httpMethodFilters.Where(x => x.Filter(call));

            var httpMethods = matchingFilters.Select(x => x.Method).ToArray();

            if (httpMethods.Length > 0)
            {
                routeDefinition.AddRouteConstraint(HTTP_METHOD_CONSTRAINT, new HttpMethodConstraint(httpMethods));
                matchingFilters.Each(filter => observer.RecordCallStatus(call,
                                                                         "Adding route constraint {0} based on filter [{1}]".ToFormat(filter.Method, filter.Description)));
            }
        }
示例#49
0
        public static void Alter(IRouteDefinition route, ActionCall call)
        {
            var properties = call.HasInput
                                 ? new TypeDescriptorCache().GetPropertiesFor(call.InputType()).Keys
                                 : new string[0];

            Alter(route, call.Method.Name, properties, text => call.Trace(text));

            if (call.HasInput)
            {
                route.ApplyInputType(call.InputType());
            }
        }
示例#50
0
        public static void Alter(IRouteDefinition route, ActionCall call, IConfigurationObserver observer)
        {
            var properties = call.HasInput
                                 ? new TypeDescriptorCache().GetPropertiesFor(call.InputType()).Keys
                                 : new string[0];

            Alter(route, call.Method.Name, properties, text => observer.RecordCallStatus(call, text));

            if (call.HasInput)
            {
                route.ApplyInputType(call.InputType());
            }
        }
示例#51
0
        /// <summary>
        ///   Finds the matching BehaviorChain for the given IRouteDefinition.  If no
        ///   BehaviorChain exists, one is created and added to the BehaviorGraph
        /// </summary>
        /// <param name = "route"></param>
        /// <returns></returns>
        public BehaviorChain BehaviorFor(IRouteDefinition route)
        {
            var chain = _behaviors.FirstOrDefault(x => x.Route == route);

            if (chain == null)
            {
                chain = new BehaviorChain {
                    Route = route
                };
                _behaviors.Fill(chain);
            }

            return(chain);
        }
示例#52
0
        public static List <string> AddHttpConstraints(IRouteDefinition route, string methodName, Action <string> log)
        {
            var parts = methodName.Split('_').ToList();

            var method = parts.First().ToUpper();

            if (RouteDefinition.VERBS.Contains(method))
            {
                log(" - adding Http method constraint {0}".ToFormat(method));
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }
            return(parts);
        }
 private static void ConstrainToHttpMethod(
     IRouteDefinition route, ActionCallBase call, IEnumerable<Configuration.HttpConstraintPattern> patterns)
 {
     Func<Configuration.Segment, string> getName = s =>
     {
         switch (s)
         {
             case Configuration.Segment.Namespace: return call.HandlerType.Namespace;
             case Configuration.Segment.Class: return call.HandlerType.Name;
             case Configuration.Segment.Method: return call.Method.Name;
         } return null;
     };
     patterns.Where(x => x.Regex.IsMatch(getName(x.Type))).ToList().
                 ForEach(x => route.AddHttpMethodConstraint(x.Method));
 }
        public void VisitRoute(IRouteDefinition route, BehaviorChain chain)
        {
            ActionCall action = chain.FirstCall();
            if (action == null) return;

            if (action.HasInput)
            {
                // TODO:  throw if route is null;
                var model = (IModelUrl) route;
                _registration.AddModel(model);
            }

            var actionUrl = new ActionUrl(route, action);
            _registration.AddAction(actionUrl);
        }
示例#55
0
        public static void Alter(IRouteDefinition route, ActionCall call)
        {
            var properties = call.HasInput
                ? new TypeDescriptorCache().GetPropertiesFor(call.InputType()).Keys
                : new string[0];

            Alter(route, call.Method.Name, properties);

            if (call.HasInput)
            {
                route.ApplyInputType(call.InputType());

                if (call.InputType().CanBeCastTo<ResourcePath>())
                {

                     ResourcePath.AddResourcePathInputs(route);
                }
            }
        }
示例#56
0
        public static Parameter createParameter(PropertyInfo propertyInfo, IRouteDefinition route)
        {
            var parameter = new Parameter
                                {
                                    name = propertyInfo.Name,
                                    dataType = propertyInfo.PropertyType.Name,
                                    paramType = "post",
                                    allowMultiple = false,
                                    required = propertyInfo.HasAttribute<RequiredAttribute>(),
                                    description = propertyInfo.GetAttribute<DescriptionAttribute>(a => a.Description),
                                    defaultValue = propertyInfo.GetAttribute<DefaultValueAttribute>(a => a.Value.ToString()),
                                    allowableValues = getAllowableValues(propertyInfo)
                                };

            if (route.Input.RouteParameters.Any(r => r.Name == propertyInfo.Name))
                parameter.paramType = "path";

            if (route.Input.QueryParameters.Any(r => r.Name == propertyInfo.Name))
                parameter.paramType = "query";

            return parameter;
        }
示例#57
0
        public static void Alter(IRouteDefinition route, string methodName, IEnumerable<string> properties)
        {
            var parts = AddHttpConstraints(route, methodName);

            for (var i = 0; i < parts.Count; i++)
            {
                var part = parts[i];
                if (properties.Contains(part))
                {
                    parts[i] = "{" + part + "}";
                }
                else
                {
                    parts[i] = part.ToLower();
                }
            }

            if (parts.Any())
            {
                route.Append(parts.Join("/").Replace('^', '_'));
            }
        }
示例#58
0
        public static void AddResourcePathInputs(IRouteDefinition route)
        {
            route.Append(UrlSuffix);


            route.RegisterRouteCustomization(r =>
            {
                if (r.Defaults == null)
                {
                    r.Defaults = new RouteValueDictionary();
                }

                r.Defaults.Add("Part0", null);
                r.Defaults.Add("Part1", null);
                r.Defaults.Add("Part2", null);
                r.Defaults.Add("Part3", null);
                r.Defaults.Add("Part4", null);
                r.Defaults.Add("Part5", null);
                r.Defaults.Add("Part6", null);
                r.Defaults.Add("Part7", null);
                r.Defaults.Add("Part8", null);
                r.Defaults.Add("Part9", null);
            });
        }
示例#59
0
 protected virtual void visit(IRouteDefinition routeDefinition)
 {
     // no-op
 }
示例#60
0
        private void addNamespace(IRouteDefinition route, ActionCall call)
        {
            string ns = replace(call.HandlerType.Namespace, _ignoredNamespaces).TrimStart('.');
            ns = ns.Replace('.', '/');
            route.Append(ns);

            if (IgnoreControllerFolderName)
            {
                route.RemoveLastPatternPart();
            }
        }