Ejemplo n.º 1
0
        //public RouteResult Route(string path, string query)
        //{
        //    RouteResult result = DoSubRoute(path, query, null);

        //    if (result == null)
        //        return s_EmptyRouteResult;

        //    return result;
        //}

        public RouteResult Route(UrlScheme urlScheme)
        {
            RouteResult result = DoSubRoute(urlScheme, null);

            if (result == null)
            {
                return(s_EmptyRouteResult);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private RouteResult DoSubRoute(UrlScheme urlScheme, MatchChainNode previousMatch)
        {
            RouteResult result = null;

            int startIndex = 0;

            if (previousMatch != null)
            {
                startIndex = previousMatch.Match.Index + previousMatch.Match.Length;
            }

            if (Childs != null)
            {
                if (m_BasePathPatternRegex != null)
                {
                    Match match = m_BasePathPatternRegex.Match(urlScheme.Main, startIndex);

                    if (match.Success && match.Index + match.Length < urlScheme.Main.Length)
                    {
                        MatchChainNode matchWrap = new MatchChainNode(previousMatch, m_BasePathPatternRegex, match);

                        foreach (RouteTable child in Childs)
                        {
                            result = child.DoSubRoute(urlScheme, matchWrap);

                            if (result != null)
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    foreach (RouteTable child in Childs)
                    {
                        result = child.Route(urlScheme);

                        if (result.Succeed)
                        {
                            break;
                        }
                    }
                }
            }
            else if (m_FriendlyPathPatternRegex != null)
            {
                Match match = m_FriendlyPathPatternRegex.Match(urlScheme.Main, startIndex);

                if (match.Success)
                {
                    MatchChainNode matchWrap = new MatchChainNode(previousMatch, m_FriendlyPathPatternRegex, match);

                    string originalPath = CreateOriginalPath(urlScheme.Main, urlScheme.QueryString, matchWrap);

                    result = new RouteResult(originalPath);
                }
            }
            else
            {
                string resultString = OriginalPathBuilder(urlScheme);

                if (string.IsNullOrEmpty(resultString))
                {
                    return(new RouteResult());
                }
                else
                {
                    return(new RouteResult(resultString));
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private RouteResult DoSubRoute(UrlScheme urlScheme, MatchChainNode previousMatch)
        {
            RouteResult result = null;

            int startIndex = 0;

            if (previousMatch != null)
                startIndex = previousMatch.Match.Index + previousMatch.Match.Length;

            if (Childs != null)
            {
                if (m_BasePathPatternRegex != null)
                {
                    Match match = m_BasePathPatternRegex.Match(urlScheme.Main, startIndex);

                    if (match.Success && match.Index + match.Length < urlScheme.Main.Length)
                    {
                        MatchChainNode matchWrap = new MatchChainNode(previousMatch, m_BasePathPatternRegex, match);

                        foreach (RouteTable child in Childs)
                        {
                            result = child.DoSubRoute(urlScheme, matchWrap);

                            if (result != null)
                                break;
                        }
                    }
                }
                else
                {
                    foreach (RouteTable child in Childs)
                    {
                        result = child.Route(urlScheme);

                        if (result.Succeed)
                            break;
                    }
                }
            }
            else if (m_FriendlyPathPatternRegex != null)
            {
                Match match = m_FriendlyPathPatternRegex.Match(urlScheme.Main, startIndex);

                if (match.Success)
                {
                    MatchChainNode matchWrap = new MatchChainNode(previousMatch, m_FriendlyPathPatternRegex, match);

                    string originalPath = CreateOriginalPath(urlScheme.Main, urlScheme.QueryString, matchWrap);

                    result = new RouteResult(originalPath);
                }
            }
            else
            {
                string resultString = OriginalPathBuilder(urlScheme);

                if (string.IsNullOrEmpty(resultString))
                    return new RouteResult();
                else
                    return new RouteResult(resultString);
            }

            return result;
        }