public void Remove(RouteConfigElement url)
 {
     if (BaseIndexOf(url) >= 0)
     {
         BaseRemove(url.Name);
     }
 }
Example #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);
        }
Example #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);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #4
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));
 }
Example #5
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));
 }
Example #6
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));
 }
 public void Add(RouteConfigElement url)
 {
     BaseAdd(url);
 }
 public int IndexOf(RouteConfigElement url)
 {
     return(BaseIndexOf(url));
 }
 /// <summary>
 /// Gets the constraints.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <returns></returns>
 private static RouteValueDictionary GetConstraints(RouteConfigElement route)
 {
     return GetRouteValueDictionary(route.Constraints.Attributes);
 }
 /// <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);
 }
        /// <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;
        }
 /// <summary>
 /// Gets the defaults.
 /// </summary>
 /// <param name="route">The route.</param>
 /// <returns></returns>
 private static RouteValueDictionary GetDefaults(RouteConfigElement route)
 {
     return GetRouteValueDictionary(route.Defaults.Attributes);
 }
Example #13
0
 public void Remove(RouteConfigElement url)
 {
     if (BaseIndexOf(url) >= 0)
         BaseRemove(url.Name);
 }
Example #14
0
 public int IndexOf(RouteConfigElement url)
 {
     return BaseIndexOf(url);
 }
Example #15
0
 public void Add(RouteConfigElement url)
 {
     BaseAdd(url);
 }