public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); route.RestrictByMethods(_methods); }
public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); route.RestrictByUrlPorts(_ports); }
public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); route.RestrictByRefererUrlHostTypes(_hostTypes); }
public void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); _mapper.Map(route, container); }
public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); route.ResolveRelativeUrlsUsingFormatString(_format); }
public RouteMatchResult(Routing.Route route, MatchResult result) { route.ThrowIfNull("route"); result.ThrowIfNull("result"); _route = route; _matchResult = result; }
public Task MapAsync(Func <IContainer> container, Type type, MethodInfo method, Routing.Route route) { container.ThrowIfNull("container"); type.ThrowIfNull("type"); method.ThrowIfNull("method"); route.ThrowIfNull("route"); route.RespondWithNoContent(); return(Task.Factory.Empty()); }
public void Map(Type type, MethodInfo method, Routing.Route route, IContainer container) { type.ThrowIfNull("type"); method.ThrowIfNull("method"); route.ThrowIfNull("route"); IEnumerable <RestrictionAttribute> attributes = method.GetCustomAttributes <RestrictionAttribute>(false); foreach (RestrictionAttribute attribute in attributes) { attribute.Map(route, container); } }
public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); if (_comparer != null) { route.RestrictByUrlFragments(_fragments, GetComparer(_comparer.Value)); } else { route.RestrictByUrlFragments(_fragments); } }
public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); if (_comparer != null) { route.RestrictByRefererUrlQueries(_queries, GetComparer(_comparer.Value)); } else { route.RestrictByRefererUrlQueries(_queries); } }
public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); if (_fieldComparer != null && _valueComparer != null) { route.RestrictByUrlQueryString(_field, GetComparer(_fieldComparer.Value), _value, GetComparer(_valueComparer.Value)); } else { route.RestrictByUrlQueryString(_field, _value); } }
public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); if (_nameComparer != null && _valueComparer != null) { route.RestrictByCookie(_name, GetComparer(_nameComparer.Value), _value, GetComparer(_valueComparer.Value), _optional); } else { route.RestrictByCookie(_name, _value, _optional); } }
public void Map(Type type, MethodInfo method, Routing.Route route, IContainer container) { type.ThrowIfNull("type"); method.ThrowIfNull("method"); route.ThrowIfNull("route"); container.ThrowIfNull("container"); HttpMethod httpMethod; string methodName = method.Name.TrimEnd("Async"); if (Enum <HttpMethod> .TryParse(methodName, true, out httpMethod)) { route.RestrictByMethods(httpMethod); } }
public override void Map(Routing.Route route, IContainer container) { route.ThrowIfNull("route"); container.ThrowIfNull("container"); var httpRuntime = container.GetInstance <IHttpRuntime>(); if (_comparer != null) { route.RestrictByUrlRelativePaths(_relativePaths, GetComparer(_comparer.Value), httpRuntime); } else { route.RestrictByUrlRelativePaths(_relativePaths, httpRuntime); } }
public void Map(Type type, MethodInfo method, Routing.Route route, IContainer container) { type.ThrowIfNull("type"); method.ThrowIfNull("method"); route.ThrowIfNull("route"); container.ThrowIfNull("container"); if (!type.NamespaceStartsWith(_rootNamespace)) { return; } var pathParts = new List <string>(); string relativeNamespace = Regex.Replace(type.Namespace, String.Format(@"^{0}\.?(?<RelativeNamespace>.*)", Regex.Escape(_rootNamespace)), "${RelativeNamespace}"); pathParts.AddRange(ParseWords(relativeNamespace)); pathParts.AddRange(ParseWords(type.Name)); string relativeUrl = String.Join("/", pathParts); route.ResolveRelativeUrlsUsingString(relativeUrl); }
public void Map(Type type, MethodInfo method, Routing.Route route, IContainer container) { type.ThrowIfNull("type"); method.ThrowIfNull("method"); route.ThrowIfNull("route"); container.ThrowIfNull("container"); if (!type.NamespaceStartsWith(_rootNamespace)) { return; } var pathParts = new List <string>(); string relativeNamespace = Regex.Replace(type.Namespace, String.Format(@"^{0}\.?(?<RelativeNamespace>.*)", Regex.Escape(_rootNamespace)), "${RelativeNamespace}"); pathParts.AddRange(ParseWords(relativeNamespace)); pathParts.AddRange(ParseWords(type.Name)); string relativePath = String.Join("/", pathParts); var httpRuntime = container.GetInstance <IHttpRuntime>(); route.RestrictByUrlRelativePath(relativePath, _caseSensitive ? (IRequestValueComparer)CaseSensitivePlainComparer.Instance : CaseInsensitivePlainComparer.Instance, httpRuntime); }
public Task MapAsync(Func <IContainer> container, Type type, MethodInfo method, Routing.Route route) { container.ThrowIfNull("container"); type.ThrowIfNull("type"); method.ThrowIfNull("method"); route.ThrowIfNull("route"); bool methodReturnTypeImplementsIResponse = method.ReturnType.ImplementsInterface <IResponse>(); bool methodReturnTypeIsTaskT = method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task <>); bool methodReturnTypeIsVoid = method.ReturnType == typeof(void); if (methodReturnTypeImplementsIResponse) { ParameterInfo[] parameterInfos = method.GetParameters(); ParameterExpression instanceParameterExpression = Expression.Parameter(typeof(object), "instance"); ParameterExpression parametersParameterExpression = Expression.Parameter(typeof(object[]), "parameters"); UnaryExpression unaryExpression = Expression.Convert( Expression.Call( Expression.Convert(instanceParameterExpression, type), method, parameterInfos.Select((arg, index) => Expression.Convert( Expression.ArrayIndex(parametersParameterExpression, Expression.Constant(index)), arg.ParameterType))), typeof(IResponse)); Func <object, object[], IResponse> @delegate = Expression.Lambda <Func <object, object[], IResponse> >(unaryExpression, instanceParameterExpression, parametersParameterExpression).Compile(); route.RespondWith( async context => { object instance; try { instance = container().GetInstance(type); } catch (Exception exception) { throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName), exception); } if (instance == null) { throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName)); } var parameterValueRetriever = new ParameterValueRetriever(_parameterMappers); object[] parameterValues = (await parameterValueRetriever.GetParameterValuesAsync(context, type, method)).ToArray(); return(@delegate(instance, parameterValues)); }, method.ReturnType); } else if (methodReturnTypeIsTaskT) { ParameterInfo[] parameterInfos = method.GetParameters(); ParameterExpression instanceParameterExpression = Expression.Parameter(typeof(object), "instance"); ParameterExpression parametersParameterExpression = Expression.Parameter(typeof(object[]), "parameters"); Type methodGenericArgumentType = method.ReturnType.GetGenericArguments()[0]; MethodInfo upcastMethodInfo = typeof(TaskExtensions) .GetMethod("Upcast", BindingFlags.Static | BindingFlags.Public) .MakeGenericMethod(methodGenericArgumentType, typeof(IResponse)); UnaryExpression unaryExpression = Expression.Convert( Expression.Call( upcastMethodInfo, Expression.Call( Expression.Convert(instanceParameterExpression, type), method, parameterInfos.Select((arg, index) => Expression.Convert( Expression.ArrayIndex(parametersParameterExpression, Expression.Constant(index)), arg.ParameterType)))), upcastMethodInfo.ReturnType); Func <object, object[], Task <IResponse> > @delegate = Expression.Lambda <Func <object, object[], Task <IResponse> > >(unaryExpression, instanceParameterExpression, parametersParameterExpression).Compile(); route.RespondWith( async context => { object instance; try { instance = container().GetInstance(type); } catch (Exception exception) { throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName), exception); } if (instance == null) { throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName)); } var parameterValueRetriever = new ParameterValueRetriever(_parameterMappers); object[] parameterValues = (await parameterValueRetriever.GetParameterValuesAsync(context, type, method)).ToArray(); return(await @delegate(instance, parameterValues)); }, methodGenericArgumentType); } else if (methodReturnTypeIsVoid) { ParameterInfo[] parameterInfos = method.GetParameters(); ParameterExpression instanceParameterExpression = Expression.Parameter(typeof(object), "instance"); ParameterExpression parametersParameterExpression = Expression.Parameter(typeof(object[]), "parameters"); MethodCallExpression methodCallExpression = Expression.Call( Expression.Convert(instanceParameterExpression, type), method, parameterInfos.Select((arg, index) => Expression.Convert( Expression.ArrayIndex(parametersParameterExpression, Expression.Constant(index)), arg.ParameterType))); Action <object, object[]> @delegate = Expression.Lambda <Action <object, object[]> >(methodCallExpression, instanceParameterExpression, parametersParameterExpression).Compile(); route.RespondWithNoContent( async context => { object instance; try { instance = container().GetInstance(type); } catch (Exception exception) { throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName), exception); } if (instance == null) { throw new ApplicationException(String.Format("Unable to resolve instance of type {0}.", type.FullName)); } var parameterValueRetriever = new ParameterValueRetriever(_parameterMappers); object[] parameterValues = (await parameterValueRetriever.GetParameterValuesAsync(context, type, method)).ToArray(); @delegate(instance, parameterValues); }); } else { throw new ApplicationException(String.Format("The return type of {0}.{1} must implement {2} or be a {3} whose generic type argument implements {2}.", type.FullName, method.Name, typeof(IResponse).Name, typeof(Task <>))); } return(Task.Factory.Empty()); }