Пример #1
0
		public override void Map(Routing.Route route, IContainer container)
		{
			route.ThrowIfNull("route");
			container.ThrowIfNull("container");

			route.RestrictByUrlHostTypes(_hostTypes);
		}
        public override void Map(Routing.Route route, IContainer container)
        {
            route.ThrowIfNull("route");
            container.ThrowIfNull("container");

            route.ResolveRelativeUrlsUsingString(_relativeUrl);
        }
Пример #3
0
        public override void Map(Routing.Route route, IContainer container)
        {
            route.ThrowIfNull("route");
            container.ThrowIfNull("container");

            route.RestrictByMethods(_methods);
        }
        public void Map(Routing.Route route, IContainer container)
        {
            route.ThrowIfNull("route");
            container.ThrowIfNull("container");

            _mapper.Map(route, container);
        }
Пример #5
0
        public override void Map(Routing.Route route, IContainer container)
        {
            route.ThrowIfNull("route");
            container.ThrowIfNull("container");

            route.RestrictByRefererUrlPorts(_ports);
        }
Пример #6
0
        public RouteMatchResult(Routing.Route route, MatchResult result)
        {
            route.ThrowIfNull("route");
            result.ThrowIfNull("result");

            _route = route;
            _matchResult = result;
        }
Пример #7
0
        public void Map(Func<IContainer> container, Type type, MethodInfo method, Routing.Route route)
        {
            container.ThrowIfNull("container");
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");
            route.ThrowIfNull("route");

            route.RespondWithNoContent();
        }
Пример #8
0
        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();
        }
Пример #9
0
        public override void Map(Routing.Route route, IContainer container)
        {
            route.ThrowIfNull("route");
            container.ThrowIfNull("container");

            if (_comparer != null)
            {
                route.RestrictByUrlSchemes(_schemes, GetComparer(_comparer.Value));
            }
            else
            {
                route.RestrictByUrlSchemes(_schemes);
            }
        }
        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);
            }
        }
Пример #11
0
        public override void Map(Routing.Route route, IContainer container)
        {
            route.ThrowIfNull("route");
            container.ThrowIfNull("container");

            if (_valueComparer != null)
            {
                route.RestrictByHeader(_field, _value, GetComparer(_valueComparer.Value));
            }
            else
            {
                route.RestrictByHeader(_field, _value);
            }
        }
        public void Map(Type type, MethodInfo method, Routing.Route route, IContainer container)
        {
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");
            route.ThrowIfNull("route");
            container.ThrowIfNull("container");

            IEnumerable<RelativeUrlResolverAttribute> attributes = method.GetCustomAttributes<RelativeUrlResolverAttribute>(false);

            foreach (RelativeUrlResolverAttribute attribute in attributes)
            {
                attribute.Map(route, container);
            }
        }
        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), _optional);
            }
            else
            {
                route.RestrictByUrlQueryString(_field, _value, _optional);
            }
        }
Пример #14
0
		public override void Map(Routing.Route route, IContainer container)
		{
			route.ThrowIfNull("route");
			container.ThrowIfNull("container");

			if (_comparer != null)
			{
				route.RestrictByRefererUrlHosts(_hosts, GetComparer(_comparer.Value));
			}
			else
			{
				route.RestrictByRefererUrlHosts(_hosts);
			}
		}
        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;

            if (Enum<HttpMethod>.TryParse(method.Name, true, out httpMethod))
            {
                route.RestrictByMethods(httpMethod);
            }
        }
Пример #16
0
		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 Task MapAsync(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);
			}

			return Task.Factory.Empty();
		}
        public Task<AuthenticationResult> AuthenticateAsync(HttpRequestBase request, HttpResponseBase response, Routing.Route route)
        {
            request.ThrowIfNull("request");
            response.ThrowIfNull("response");
            route.ThrowIfNull("route");

            if (!_helper.IsTicketValid(request))
            {
                return AuthenticationResult.AuthenticationFailed.AsCompletedTask();
            }

            Cookie cookie = _helper.RenewTicket(request);

            response.Cookies.Remove(cookie.Name);
            response.Cookies.Add(cookie.GetHttpCookie());

            return AuthenticationResult.AuthenticationSucceeded.AsCompletedTask();
        }
        public void Map(Func<IContainer> container, Type type, MethodInfo method, Routing.Route route)
        {
            container.ThrowIfNull("container");
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");
            route.ThrowIfNull("route");

            if (method.ReturnType == typeof(void))
            {
                route.RespondWithNoContent();
                return;
            }
            if (!method.ReturnType.ImplementsInterface<IResponse>())
            {
                throw new ApplicationException(String.Format("The return type of '{0}.{1}' does not implement '{2}'.", type.FullName, method.Name, typeof(IResponse).Name));
            }

            route.RespondWith(
                request =>
                    {
                        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);
                        IEnumerable<object> parameterValues = parameterValueRetriever.GetParameterValues(request, type, method);

                        return (IResponse)method.Invoke(instance, parameterValues.ToArray());
                    },
                method.ReturnType);
        }
        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();
                        var mappedDelegateContexts = new List<IMappedDelegateContext>();

                        try
                        {
                            mappedDelegateContexts.AddRange(_contextFactories.Select(arg => arg.CreateContext(context, type, method)).Where(arg => arg != null));

                            IResponse response = @delegate(instance, parameterValues);

                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Complete();
                            }

                            return response;
                        }
                        finally
                        {
                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Dispose();
                            }
                        }
                    },
                    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();
                        var mappedDelegateContexts = new List<IMappedDelegateContext>();

                        try
                        {
                            mappedDelegateContexts.AddRange(_contextFactories.Select(arg => arg.CreateContext(context, type, method)).Where(arg => arg != null));

                            IResponse response = await @delegate(instance, parameterValues);

                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Complete();
                            }

                            return response;
                        }
                        finally
                        {
                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Dispose();
                            }
                        }
                    },
                    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();
                        var mappedDelegateContexts = new List<IMappedDelegateContext>();

                        try
                        {
                            mappedDelegateContexts.AddRange(_contextFactories.Select(arg => arg.CreateContext(context, type, method)).Where(arg => arg != null));

                            @delegate(instance, parameterValues);

                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Complete();
                            }
                        }
                        finally
                        {
                            foreach (IMappedDelegateContext mappedDelegateContext in mappedDelegateContexts)
                            {
                                mappedDelegateContext.Dispose();
                            }
                        }
                    });
            }
            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();
        }