コード例 #1
0
ファイル: RouteCacher.cs プロジェクト: tryadiadi/ravendb
        private static HttpRouteInformation CacheRouteInternal(IHttpRoute route)
        {
            var httpRoute = route as HttpRoute;

            if (httpRoute == null)
            {
                throw new InvalidOperationException("Invalid route");
            }

            if (httpRoute.Handler != null)
            {
                throw new InvalidOperationException("Cannot copy route with handler: " + route.RouteTemplate);
            }

            var routeInformation = new HttpRouteInformation
            {
                Constraints   = httpRoute.Constraints.ToDictionary(x => x.Key, x => x.Value),
                DataTokens    = httpRoute.DataTokens.ToDictionary(x => x.Key, x => x.Value),
                Defaults      = httpRoute.Defaults.ToDictionary(x => x.Key, x => x.Value),
                RouteTemplate = httpRoute.RouteTemplate
            };

            object value;

            if (routeInformation.DataTokens.TryGetValue(ActionsDataTokenKey, out value))
            {
                var descriptors            = (HttpActionDescriptor[])value;
                var descriptorInformations = new HttpActionDescriptorInformation[descriptors.Length];
                for (var index = 0; index < descriptors.Length; index++)
                {
                    var descriptor     = (ReflectedHttpActionDescriptor)descriptors[index];
                    var methodInfo     = descriptor.MethodInfo;
                    var controllerName = descriptor.ControllerDescriptor.ControllerName;
                    var controllerType = descriptor.ControllerDescriptor.ControllerType;
                    var properties     = descriptor.Properties.ToDictionary(x => x.Key, x => x.Value);

                    descriptorInformations[index] = new HttpActionDescriptorInformation
                    {
                        MethodInfo     = methodInfo,
                        ControllerName = controllerName,
                        ControllerType = controllerType,
                        Properties     = properties
                    };
                }

                routeInformation.DataTokens.Remove(ActionsDataTokenKey);
                routeInformation.DataTokens[InfoDataTokenKey] = descriptorInformations;
            }

            return(routeInformation);
        }
コード例 #2
0
ファイル: RouteCacher.cs プロジェクト: j2jensen/ravendb
        private static IHttpRoute RebuildRoutes(HttpRouteInformation routeInformation, HttpConfiguration cfg, Dictionary<Type, HttpControllerDescriptor> controllerDescriptors)
        {
            var routeCollectionInformation = routeInformation as HttpRouteCollectionInformation;
            if (routeCollectionInformation != null)
            {
                var routes = routeCollectionInformation
                    .Routes
                    .Select(innerRoute => RebuildRouteInternal(innerRoute, cfg, controllerDescriptors))
                    .ToList();

                return new RavenRouteCollectionRoute(routes);
            }

            return RebuildRouteInternal(routeInformation, cfg, controllerDescriptors);
        }
コード例 #3
0
ファイル: RouteCacher.cs プロジェクト: tryadiadi/ravendb
        private static IHttpRoute RebuildRoutes(HttpRouteInformation routeInformation, HttpConfiguration cfg, Dictionary <Type, HttpControllerDescriptor> controllerDescriptors)
        {
            var routeCollectionInformation = routeInformation as HttpRouteCollectionInformation;

            if (routeCollectionInformation != null)
            {
                var routes = routeCollectionInformation
                             .Routes
                             .Select(innerRoute => RebuildRouteInternal(innerRoute, cfg, controllerDescriptors))
                             .ToList();

                return(new RavenRouteCollectionRoute(routes));
            }

            return(RebuildRouteInternal(routeInformation, cfg, controllerDescriptors));
        }
コード例 #4
0
ファイル: RouteCacher.cs プロジェクト: tryadiadi/ravendb
        private static IHttpRoute RebuildRouteInternal(HttpRouteInformation routeInformation, HttpConfiguration cfg, Dictionary <Type, HttpControllerDescriptor> controllerDescriptors)
        {
            var route = new HttpRoute(routeInformation.RouteTemplate, new HttpRouteValueDictionary(routeInformation.Defaults), new HttpRouteValueDictionary(routeInformation.Constraints), new HttpRouteValueDictionary(routeInformation.DataTokens), null);

            object value;

            if (route.DataTokens.TryGetValue(InfoDataTokenKey, out value))
            {
                var descriptorInformations = (HttpActionDescriptorInformation[])value;
                var descriptors            = new HttpActionDescriptor[descriptorInformations.Length];
                for (var index = 0; index < descriptorInformations.Length; index++)
                {
                    var descriptorInformation = descriptorInformations[index];

                    HttpControllerDescriptor controllerDescriptor;
                    if (controllerDescriptors.TryGetValue(descriptorInformation.ControllerType, out controllerDescriptor) == false)
                    {
                        controllerDescriptors[descriptorInformation.ControllerType] = controllerDescriptor = new HttpControllerDescriptor(cfg, descriptorInformation.ControllerName, descriptorInformation.ControllerType);
                    }

                    var descriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, descriptorInformation.MethodInfo);

                    foreach (var pair in descriptorInformation.Properties)
                    {
                        descriptor.Properties.AddOrUpdate(pair.Key, pair.Value, (_, __) => pair.Value);
                    }

                    descriptors[index] = descriptor;
                }

                route.DataTokens.Remove(InfoDataTokenKey);
                route.DataTokens[ActionsDataTokenKey] = descriptors;
            }

            return(route);
        }
コード例 #5
0
ファイル: RouteCacher.cs プロジェクト: j2jensen/ravendb
        private static IHttpRoute RebuildRouteInternal(HttpRouteInformation routeInformation, HttpConfiguration cfg, Dictionary<Type, HttpControllerDescriptor> controllerDescriptors)
        {
            var route = new HttpRoute(routeInformation.RouteTemplate, new HttpRouteValueDictionary(routeInformation.Defaults), new HttpRouteValueDictionary(routeInformation.Constraints), new HttpRouteValueDictionary(routeInformation.DataTokens), null);

            object value;
            if (route.DataTokens.TryGetValue(InfoDataTokenKey, out value))
            {
                var descriptorInformations = (HttpActionDescriptorInformation[])value;
                var descriptors = new HttpActionDescriptor[descriptorInformations.Length];
                for (var index = 0; index < descriptorInformations.Length; index++)
                {
                    var descriptorInformation = descriptorInformations[index];

                    HttpControllerDescriptor controllerDescriptor;
                    if (controllerDescriptors.TryGetValue(descriptorInformation.ControllerType, out controllerDescriptor) == false)
                        controllerDescriptors[descriptorInformation.ControllerType] = controllerDescriptor = new HttpControllerDescriptor(cfg, descriptorInformation.ControllerName, descriptorInformation.ControllerType);

                    var descriptor = new ReflectedHttpActionDescriptor(controllerDescriptor, descriptorInformation.MethodInfo);

                    foreach (var pair in descriptorInformation.Properties)
                        descriptor.Properties.AddOrUpdate(pair.Key, pair.Value, (_, __) => pair.Value);

                    descriptors[index] = descriptor;
                }

                route.DataTokens.Remove(InfoDataTokenKey);
                route.DataTokens[ActionsDataTokenKey] = descriptors;
            }

            return route;
        }
コード例 #6
0
ファイル: RouteCacher.cs プロジェクト: j2jensen/ravendb
        private static HttpRouteInformation CacheRouteInternal(IHttpRoute route)
        {
            var httpRoute = route as HttpRoute;
            if (httpRoute == null)
                throw new InvalidOperationException("Invalid route");

            if (httpRoute.Handler != null)
                throw new InvalidOperationException("Cannot copy route with handler: " + route.RouteTemplate);

            var routeInformation = new HttpRouteInformation
            {
                Constraints = httpRoute.Constraints.ToDictionary(x => x.Key, x => x.Value),
                DataTokens = httpRoute.DataTokens.ToDictionary(x => x.Key, x => x.Value),
                Defaults = httpRoute.Defaults.ToDictionary(x => x.Key, x => x.Value),
                RouteTemplate = httpRoute.RouteTemplate
            };

            object value;
            if (routeInformation.DataTokens.TryGetValue(ActionsDataTokenKey, out value))
            {
                var descriptors = (HttpActionDescriptor[])value;
                var descriptorInformations = new HttpActionDescriptorInformation[descriptors.Length];
                for (var index = 0; index < descriptors.Length; index++)
                {
                    var descriptor = (ReflectedHttpActionDescriptor)descriptors[index];
                    var methodInfo = descriptor.MethodInfo;
                    var controllerName = descriptor.ControllerDescriptor.ControllerName;
                    var controllerType = descriptor.ControllerDescriptor.ControllerType;
                    var properties = descriptor.Properties.ToDictionary(x => x.Key, x => x.Value);

                    descriptorInformations[index] = new HttpActionDescriptorInformation
                    {
                        MethodInfo = methodInfo,
                        ControllerName = controllerName,
                        ControllerType = controllerType,
                        Properties = properties
                    };
                }

                routeInformation.DataTokens.Remove(ActionsDataTokenKey);
                routeInformation.DataTokens[InfoDataTokenKey] = descriptorInformations;
            }

            return routeInformation;
        }