Esempio n. 1
0
        /// <summary>
        /// 映射一个路由规则
        /// </summary>
        /// <param name="routeTable">简单路由表实例</param>
        /// <param name="name">路由规则名称</param>
        /// <param name="urlPattern">URL 模式</param>
        /// <param name="routeValues">默认/静态路由值</param>
        /// <param name="queryKeys">可用于 QueryString 的路由值</param>
        /// <returns>返回简单路由表实例,便于链式注册</returns>
        public static SimpleRouteTable MapRoute(this SimpleRouteTable routeTable, string name, string urlPattern, IDictionary <string, string> routeValues, string[] queryKeys = null)
        {
            if (routeTable == null)
            {
                throw new ArgumentNullException("routeTable");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (urlPattern == null)
            {
                throw new ArgumentNullException("urlPattern");
            }

            if (routeValues == null)
            {
                throw new ArgumentNullException("routeValues");
            }


            routeTable.AddRule(name, urlPattern, routeValues, queryKeys);
            return(routeTable);
        }
Esempio n. 2
0
 /// <summary>
 /// 映射一个 Action 路由
 /// </summary>
 /// <param name="routeTable">简单路由表实例</param>
 /// <param name="urlPattern">URL 模式</param>
 /// <param name="controller">Controller 名称</param>
 /// <param name="action">Action 名称</param>
 /// <param name="queryKeys">可用于 QueryString 的路由值</param>
 /// <returns>返回简单路由表实例,便于链式注册</returns>
 public static SimpleRouteTable MapAction(this SimpleRouteTable routeTable, string urlPattern, string controller, string action, string[] queryKeys = null)
 {
     return(routeTable.MapRoute(urlPattern, urlPattern, new Dictionary <string, string>()
     {
         { "action", action }, { "controller", controller }
     }, queryKeys));
 }
Esempio n. 3
0
        /// <summary>
        /// 获取内建的简单路由表实例,如果没有则创建一个。
        /// </summary>
        /// <param name="routes">系统路由集合</param>
        /// <returns>内建的简单路由表实例</returns>
        public static SimpleRouteTable SimpleRouteTable(this RouteCollection routes)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }

            lock ( routes )
            {
                var routeTable = routes.OfType <SimpleRouteTable>().FirstOrDefault(route => route.IsBuiltIn);
                if (routeTable == null)
                {
                    routes.RegisterSimpleRouteTable(routeTable = new SimpleRouteTable());
                }
                return(routeTable);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 映射一个路由规则
 /// </summary>
 /// <param name="routeTable">简单路由表实例</param>
 /// <param name="name">路由规则名称</param>
 /// <param name="urlPattern">URL 模式</param>
 /// <param name="routeValues">默认/静态路由值</param>
 /// <param name="queryKeys">可用于 QueryString 的路由值</param>
 /// <returns>返回简单路由表实例,便于链式注册</returns>
 public static SimpleRouteTable MapRoute(this SimpleRouteTable routeTable, string name, string urlPattern, object routeValues, string[] queryKeys = null)
 {
     return(MapRoute(routeTable, name, urlPattern, routeValues.ToPropertiesMap(), queryKeys));
 }
Esempio n. 5
0
 /// <summary>
 /// 映射一个路由规则
 /// </summary>
 /// <param name="routeTable">简单路由表实例</param>
 /// <param name="urlPattern">URL 模式</param>
 /// <param name="routeValues">默认/静态路由值</param>
 /// <param name="queryKeys">可用于 QueryString 的路由值</param>
 /// <returns>返回简单路由表实例,便于链式注册</returns>
 public static SimpleRouteTable MapRoute(this SimpleRouteTable routeTable, string urlPattern, IDictionary <string, string> routeValues, string[] queryKeys = null)
 {
     return(MapRoute(routeTable, urlPattern, urlPattern, routeValues, queryKeys));
 }
Esempio n. 6
0
        /// <summary>
        /// 向路由集合中注册一个简单路由表实例
        /// </summary>
        /// <param name="routes">路由集合</param>
        /// <param name="routeTable">简单路由表实例</param>
        /// <returns>路由集合</returns>
        public static RouteCollection RegisterSimpleRouteTable(this RouteCollection routes, SimpleRouteTable routeTable)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }

            if (routeTable == null)
            {
                throw new ArgumentNullException("routeTable");
            }


            lock ( routes )
            {
                if (routeTable.Routes == routes)
                {
                    return(routes);
                }

                routes.Add(routeTable);
                routeTable.Routes = routes;
            }

            return(routes);
        }