Exemplo n.º 1
0
 public void Remove(RouteConfigElement url)
 {
     if (BaseIndexOf(url) >= 0)
     {
         BaseRemove(url.Name);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the instance of route handler.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns></returns>
        private static IRouteHandler GetInstanceOfRouteHandler(RouteConfigElement route)
        {
            IRouteHandler routeHandler;

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

            return(routeHandler);
        }
Exemplo n.º 3
0
        public static void RegisterRoutes(RouteCollection routes, string routeFile)
        {
            lock (routes)
            {
                RouteTableSection routesTableSection = GetRouteTableSection(routeFile);
                if (routesTableSection != null)
                {
                    //ignore route
                    if (routesTableSection.Ignores.Count > 0)
                    {
                        foreach (ConfigurationElement item in routesTableSection.Ignores)
                        {
                            var ignore = new IgnoreRouteInternal(((IgnoreRouteElement)item).Url)
                            {
                                Constraints = GetRouteValueDictionary(((IgnoreRouteElement)item).Constraints.Attributes)
                            };
                            routes.Add(ignore);
                        }
                    }

                    if (routesTableSection.Routes.Count > 0)
                    {
                        for (int routeIndex = 0; routeIndex < routesTableSection.Routes.Count; routeIndex++)
                        {
                            RouteConfigElement route = routesTableSection.Routes[routeIndex] as RouteConfigElement;
                            if (routes[route.Name] == null)
                            {
                                if (string.IsNullOrEmpty(route.RouteType))
                                {
                                    routes.Add(route.Name, new Route(
                                                   route.Url,
                                                   GetDefaults(route),
                                                   GetConstraints(route),
                                                   GetDataTokens(route),
                                                   GetInstanceOfRouteHandler(route)));
                                }
                                else
                                {
                                    var customRoute = (RouteBase)Activator.CreateInstance(Type.GetType(route.RouteType),
                                                                                          route.Url,
                                                                                          GetDefaults(route),
                                                                                          GetConstraints(route),
                                                                                          GetDataTokens(route),
                                                                                          GetInstanceOfRouteHandler(route));
                                    routes.Add(route.Name, customRoute);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the constraints.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <returns></returns>
 private static RouteValueDictionary GetConstraints(RouteConfigElement route)
 {
     return GetRouteValueDictionary(route.Constraints.Attributes);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the instance of route handler.
        /// </summary>
        /// <param name="route">The route.</param>
        /// <returns></returns>
        private static IRouteHandler GetInstanceOfRouteHandler(RouteConfigElement route)
        {
            IRouteHandler routeHandler;

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

            }

            return routeHandler;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the defaults.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <returns></returns>
 private static RouteValueDictionary GetDefaults(RouteConfigElement route)
 {
     return GetRouteValueDictionary(route.Defaults.Attributes);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the data tokens.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <returns></returns>
 private static RouteValueDictionary GetDataTokens(RouteConfigElement route)
 {
     return GetRouteValueDictionary(route.DataTokens.Attributes);
 }
Exemplo n.º 8
0
 public int IndexOf(RouteConfigElement url)
 {
     return(BaseIndexOf(url));
 }
Exemplo n.º 9
0
 public void Add(RouteConfigElement url)
 {
     BaseAdd(url);
 }
Exemplo n.º 10
0
 public void Add(RouteConfigElement url)
 {
     BaseAdd(url);
 }
Exemplo n.º 11
0
 public void Remove(RouteConfigElement url)
 {
     if (BaseIndexOf(url) >= 0)
         BaseRemove(url.Name);
 }
Exemplo n.º 12
0
 public int IndexOf(RouteConfigElement url)
 {
     return BaseIndexOf(url);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Gets the data tokens.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <returns></returns>
 private static RouteValueDictionary GetDataTokens(RouteConfigElement route)
 {
     return(GetRouteValueDictionary(route.DataTokens.Attributes));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Gets the defaults.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <returns></returns>
 private static RouteValueDictionary GetDefaults(RouteConfigElement route)
 {
     return(GetRouteValueDictionary(route.Defaults.Attributes));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Gets the constraints.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <returns></returns>
 private static RouteValueDictionary GetConstraints(RouteConfigElement route)
 {
     return(GetRouteValueDictionary(route.Constraints.Attributes));
 }