コード例 #1
0
        private static IRouteHandler GetInstanceOfRouteHandler(RouteElement route)
        {
            IRouteHandler routeHandler;

            if (string.IsNullOrEmpty(route.RouteHandlerType))
            {
                return(new MvcRouteHandler());
            }

            try
            {
                Type routeHandlerType = Type.GetType(route.RouteHandlerType);
                routeHandler = Activator.CreateInstance(routeHandlerType) as IRouteHandler;
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                          string.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType),
                          ex);
            }

            return(routeHandler);
        }
コード例 #2
0
        /// <summary>
        /// Registers the routes in the web.config file.
        /// </summary>
        /// <param name="routes">The <see cref="RouteCollection"/> to add routes to.</param>
        /// <param name="forceLowercase">Forces the routes to be lower case.</param>
        public static void RegisterRoutes(RouteCollection routes, bool forceLowercase)
        {
            RouteTableSection routesTableSection = GetRouteTableConfigurationSection();

            if (routesTableSection == null || routesTableSection.Routes.Count < 1)
            {
                return;
            }

            for (int i = 0; i < routesTableSection.Routes.Count; i++)
            {
                RouteElement routeElement = routesTableSection.Routes[i];

                Route route;

                if (forceLowercase)
                {
                    route = new LowercaseRoute(
                        routeElement.Url,
                        GetDefaults(routeElement),
                        GetConstraints(routeElement),
                        GetDataTokens(routeElement),
                        GetInstanceOfRouteHandler(routeElement));
                }
                else
                {
                    route = new Route(
                        routeElement.Url,
                        GetDefaults(routeElement),
                        GetConstraints(routeElement),
                        GetDataTokens(routeElement),
                        GetInstanceOfRouteHandler(routeElement));
                }

                routes.Add(routeElement.Name, route);
            }
        }
コード例 #3
0
 private static RouteValueDictionary GetDefaults(RouteElement route)
 {
     return(GetDictionary(route.Defaults.Attributes));
 }
コード例 #4
0
 private static RouteValueDictionary GetDataTokens(RouteElement route)
 {
     return(GetDictionary(route.DataTokens.Attributes));
 }
コード例 #5
0
 /// <summary>
 /// Adds the specified route.
 /// </summary>
 /// <param name="route">The route.</param>
 public void Add(RouteElement route)
 {
     BaseAdd(route);
 }
コード例 #6
0
 private static RouteValueDictionary GetConstraints(RouteElement route)
 {
     return(GetDictionary(route.Constraints.Attributes));
 }
コード例 #7
0
        private static IRouteHandler GetInstanceOfRouteHandler(RouteElement route)
        {
            IRouteHandler routeHandler;

            if (string.IsNullOrEmpty(route.RouteHandlerType))
                return new MvcRouteHandler();

            try
            {
                Type routeHandlerType = Type.GetType(route.RouteHandlerType);
                routeHandler = Activator.CreateInstance(routeHandlerType) as IRouteHandler;
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                    string.Format("Can't create an instance of IRouteHandler {0}", route.RouteHandlerType),
                    ex);
            }

            return routeHandler;
        }
コード例 #8
0
 private static RouteValueDictionary GetDataTokens(RouteElement route)
 {
     return GetDictionary(route.DataTokens.Attributes);
 }
コード例 #9
0
 private static RouteValueDictionary GetDefaults(RouteElement route)
 {
     return GetDictionary(route.Defaults.Attributes);
 }
コード例 #10
0
 private static RouteValueDictionary GetConstraints(RouteElement route)
 {
     return GetDictionary(route.Constraints.Attributes);
 }
コード例 #11
0
 /// <summary>
 /// Adds the specified route.
 /// </summary>
 /// <param name="route">The route.</param>
 public void Add(RouteElement route)
 {
     BaseAdd(route);
 }