コード例 #1
0
ファイル: RubyRoutes.cs プロジェクト: plus3x/ironrubymvc
        public void IgnoreRoute(string url, IDictionary constraints)
        {
            var route = new IgnoreRouteInternal(url)
            {
                Constraints = constraints.ToRouteDictionary()
            };

            _routes.Add(route);
        }
コード例 #2
0
ファイル: RubyRoutes.cs プロジェクト: jschementi/ironrubymvc
        public void IgnoreRoute(string url, IDictionary constraints)
        {
            var route = new IgnoreRouteInternal(url)
                            {
                                Constraints = constraints.ToRouteDictionary()
                            };

            _routes.Add(route);
        }
コード例 #3
0
ファイル: RouteTableRegister.cs プロジェクト: Epitomy/CMS
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #4
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);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        public void Ignore(string url, object constraints)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            IgnoreRouteInternal item = new IgnoreRouteInternal(url)
            {
                Constraints = new RouteValueDictionary(constraints)
            };

            base.Add(item);
        }
コード例 #6
0
        public static void IgnoreRoute(this RouteCollection routes, string url, object constraints) {
            if (routes == null) {
                throw new ArgumentNullException("routes");
            }
            if (url == null) {
                throw new ArgumentNullException("url");
            }

            IgnoreRouteInternal route = new IgnoreRouteInternal(url) {
                Constraints = new RouteValueDictionary(constraints)
            };

            routes.Add(route);
        }
コード例 #7
0
        public static void IgnoreRoute(this RouteCollection routes, string url, object constraints) {
            if (routes == null) {
                throw new ArgumentNullException("routes");
            }
            if (url == null) {
                throw new ArgumentNullException("url");
            }

            IgnoreRouteInternal route = new IgnoreRouteInternal(url) {
                Constraints = new RouteValueDictionary(constraints)
            };

            routes.Add(route);
        }
コード例 #8
0
        public static void IgnoreRoute(this IDictionary <string, RouteBase> routes, string url, object constraints)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            IgnoreRouteInternal route = new IgnoreRouteInternal(url)
            {
                Constraints = new RouteValueDictionary(constraints)
            };

            routes.Add(Guid.NewGuid().ToString(), route);
        }
コード例 #9
0
        public static void IgnoreRoute(this IDictionary<string, RouteBase> routes, string url, object constraints)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            IgnoreRouteInternal route = new IgnoreRouteInternal(url)
            {
                Constraints = new RouteValueDictionary(constraints)
            };

            routes.Add(Guid.NewGuid().ToString(), route);
        }
        protected override void RefreshUnknownLines(ref IList<string> lines)
        {
            var routes = RouteTable.Routes;

            // remove all the current routes
            // TODO: find a way to remove just the routes from the current ruleset not all of them
            routes.Clear();

            string groupAreaName = null;
            string areaName = null;
            IList<string> unknownLines = new List<string>();
            IDictionary<string, object> defaults = new Dictionary<string, object>();
            IDictionary<string, object> constraints = new Dictionary<string, object>();
            IDictionary<string, object> dataTokens = new Dictionary<string, object>();
            IList<string> namespaces = new List<string>();
            var groupRoutes = new RouteCollection();

            foreach (var line in lines) {
                if (RouteUrlLine.IsMatch(line)) {
                    Match match = RouteUrlLine.Match(line);
                    string url = match.Groups["url"].Value;
                    string name = match.Groups["name"].Value;
                    string[] flags = (match.Groups["flags"].Value ?? "").Split(',').Select(x => x.Trim()).ToArray();

                    var defaultsDictionary = new RouteValueDictionary(defaults);
                    var constraintsDictionary = new RouteValueDictionary(constraints);
                    var dataTokensDictionary = new RouteValueDictionary(dataTokens);

                    var route = new ApacheRoute(url, flags, defaultsDictionary, constraintsDictionary, dataTokensDictionary, new MvcRouteHandler());

                    if (namespaces.Count > 0)
                        route.DataTokens["Namespaces"] = namespaces.ToArray();

                    if (areaName != null && areaName.Trim().Length > 0) {
                        route.DataTokens["area"] = areaName;

                        // disabling the namespace lookup fallback mechanism keeps this areas from accidentally picking up
                        // controllers belonging to other areas
                        bool useNamespaceFallback = (namespaces.Count == 0);
                        route.DataTokens["UseNamespaceFallback"] = useNamespaceFallback;
                    }

                    if (String.IsNullOrEmpty(name))
                        groupRoutes.Add(route);
                    else
                        groupRoutes.Add(name, route);

                    areaName = null;
                    defaults.Clear();
                    constraints.Clear();
                    namespaces.Clear();
                } else if (RouteGroupLine.IsMatch(line)) {
                    Match match = RouteGroupLine.Match(line);
                    string pattern = match.Groups["pattern"].Value;

                    RegexOptions patternOptions = Manager.RuleOptions;

                    var flags = match.Groups["flags"] != null ? SplitConditionFlags(match.Groups["flags"].Value) : new ConditionFlagProcessor();

                    // check to see if the pattern should ignore the case when testing
                    if (ConditionFlagsProcessor.HasNoCase(flags))
                        patternOptions |= RegexOptions.IgnoreCase;

                    var route = new ApacheGroupRoute(pattern, patternOptions, groupRoutes, groupAreaName);

                    routes.Add(route);

                    groupAreaName = null;
                    groupRoutes = new RouteCollection();
                } else if (RouteIgnoreUrlLine.IsMatch(line)) {
                    Match match = RouteIgnoreUrlLine.Match(line);
                    string url = match.Groups["url"].Value;

                    Route route = new IgnoreRouteInternal(url) {
                        Constraints = new RouteValueDictionary(constraints)
                    };

                    routes.Add(route);

                    defaults.Clear();
                    constraints.Clear();
                    namespaces.Clear();
                } else if (RouteDefaultLine.IsMatch(line)) {
                    Match match = RouteDefaultLine.Match(line);
                    string name = match.Groups["name"].Value;
                    object value = match.Groups["value"].Value;

                    if ((string)value == "?")
                        value = UrlParameter.Optional;

                    defaults.Add(name, value);
                } else if (RouteConstraintLine.IsMatch(line)) {
                    Match match = RouteConstraintLine.Match(line);
                    string name = match.Groups["name"].Value;
                    string value = match.Groups["value"].Value;

                    constraints.Add(name, value);
                } else if (RouteDataTokenLine.IsMatch(line)) {
                    Match match = RouteDataTokenLine.Match(line);
                    string name = match.Groups["name"].Value;
                    string value = match.Groups["value"].Value;

                    dataTokens.Add(name, value);
                } else if (RouteNamespaceLine.IsMatch(line)) {
                    Match match = RouteNamespaceLine.Match(line);
                    string ns = match.Groups["namespace"].Value;

                    namespaces.Add(ns);
                } else if (RouteAreaLine.IsMatch(line)) {
                    Match match = RouteAreaLine.Match(line);
                    areaName = match.Groups["area"].Value;
                } else if (RouteGroupAreaLine.IsMatch(line)) {
                    Match match = RouteGroupAreaLine.Match(line);
                    groupAreaName = match.Groups["area"].Value;
                } else {
                    unknownLines.Add(line);
                }
            }

            // add all routes that weren't part of a group to the route table
            foreach (var route in groupRoutes)
                routes.Add(route);

            lines = unknownLines;
        }
コード例 #11
0
        /// <summary>
        /// RouteCollection 에 Route 정보를 등록합니다.
        /// </summary>
        /// <param name="routes">RouteCollection</param>
        /// <param name="routeFile">Route Config 파일 경로</param>
        public static void RegisterRoutes(RouteCollection routes, string routeFile)
        {
            lock(routes)
            {
                var routesTableSection = GetRouteTableSection(routeFile);
                if(routesTableSection == null) return;

                //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) return;

                for(int routeIndex = 0; routeIndex < routesTableSection.Routes.Count; routeIndex++)
                {
                    var route = routesTableSection.Routes[routeIndex] as RouteConfigElement;

                    if(IsDebugEnabled)
                        log.Debug("route={0}", route);

                    if(routes[route.Name] != null) continue;

                    if(route.RouteType.IsWhiteSpace())
                    {
                        routes.Add(route.Name, new Route(
                                                   route.Url,
                                                   GetDefaults(route),
                                                   GetConstraints(route),
                                                   GetDataTokens(route),
                                                   GetInstanceOfRouteHandler(route)));
                    }
                    else if(route.RouteType.Equals("System.Web.Mvc.MvcRouteHandler"))
                    {
                        routes.MapRoute(route.Name, route.Url, GetDefaults(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);
                    }
                }

                if(IsDebugEnabled)
                    log.Debug("등록된 route collection={0}", routes.CollectionToString());
            }
        }
コード例 #12
0
        public static void IgnoreRoute(this RouteCollection routes, string url, object constraints)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            IgnoreRouteInternal route = new IgnoreRouteInternal(url)
            {
                Constraints = CreateRouteValueDictionaryUncached(constraints)
            };

            // 校验约束是否是正确的类型,不正确则抛出异常
            ConstraintValidation.Validate(route);

            routes.Add(route);
        }
コード例 #13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param serviceDispatcherName="cfg"></param>
        /// <param serviceDispatcherName="url"></param>
        /// <param serviceDispatcherName="constraints"></param>
        public static void IgnoreRoute(this Configuration cfg, string url, object constraints)
        {
            Guard.NotNull(cfg, "cfg");
            Guard.NotNull(url, "url");

            IgnoreRouteInternal item = new IgnoreRouteInternal(url)
            {
                Constraints = new RouteValueDictionary(constraints)
            };

            RouteTable.Routes.Add(item);
        }
コード例 #14
0
        /// <summary>
        /// RouteCollection 에 Route 정보를 등록합니다.
        /// </summary>
        /// <param name="routes">RouteCollection</param>
        /// <param name="routeFile">Route Config 파일 경로</param>
        public static void RegisterRoutes(RouteCollection routes, string routeFile)
        {
            lock (routes)
            {
                var routesTableSection = GetRouteTableSection(routeFile);
                if (routesTableSection == null)
                {
                    return;
                }

                //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)
                {
                    return;
                }

                for (int routeIndex = 0; routeIndex < routesTableSection.Routes.Count; routeIndex++)
                {
                    var route = routesTableSection.Routes[routeIndex] as RouteConfigElement;

                    if (IsDebugEnabled)
                    {
                        log.Debug("route={0}", route);
                    }

                    if (routes[route.Name] != null)
                    {
                        continue;
                    }

                    if (route.RouteType.IsWhiteSpace())
                    {
                        routes.Add(route.Name, new Route(
                                       route.Url,
                                       GetDefaults(route),
                                       GetConstraints(route),
                                       GetDataTokens(route),
                                       GetInstanceOfRouteHandler(route)));
                    }
                    else if (route.RouteType.Equals("System.Web.Mvc.MvcRouteHandler"))
                    {
                        routes.MapRoute(route.Name, route.Url, GetDefaults(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);
                    }
                }

                if (IsDebugEnabled)
                {
                    log.Debug("등록된 route collection={0}", routes.CollectionToString());
                }
            }
        }