Exemple #1
0
        void DoHandler(Route r, HttpContext c, ParameterDictionary p)
        {
            HttpHandler h = r.Handler();

            h.Context      = c;
            h.RouteRequest = r;
            h.Method       = ConvertMethod(c.Request.HttpMethod);
            h.RouteID      = r.ID;
            h.RouteParams  = p;
            CallMethod(h);
        }
Exemple #2
0
        /**This method returns true(and populates Params) if the input string matches the Pattern string. **/
        public bool DoMatch(string input)
        {
            Params = new ParameterDictionary();
            string s = input;

            if (Groups.Count == 0)
            {
                throw new ApplicationException("Groups.Count==0 matches all. This shouldn't happen");
            }
            foreach (var g in Groups)
            {
                if (!g.IsParam)
                {
                    if (g.Text.Length >= s.Length)
                    {
                        if (Groups[Groups.Count - 1] == g)
                        {
                            return(g.Text == s);                          //to check for exact matches(but only for the last group)
                        }
                        else
                        {
                            if (g.Optional)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    string tmp = CutString(s, 0, g.Text.Length);
                    if (g.Text == tmp)
                    {
                        s = s.Substring(g.Text.Length);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    int end;
                    if (g.End == '\0')
                    {
                        end = s.Length;
                    }
                    else
                    {
                        end = s.IndexOf(g.End);
                        if (end == -1)
                        {
                            return(false);
                        }
                    }
                    if (g.MatchAll)
                    {
                        if (s.Substring(0, end) == "")
                        {
                            return(false);
                        }
                        int slash = s.IndexOf('/');
                        if (slash == -1 || g.Optional)
                        {
                            Params.Add(g.ParamName, s.Substring(0, end));
                            s = "";                           //doesn't matter.
                        }
                        else
                        {
                            Params.Add(g.ParamName, s.Substring(0, slash));
                            s = s.Substring(slash);                           //doesn't matter.
                        }
                    }
                    else
                    {
                        string t       = s.Substring(0, end);
                        bool   matched = false;
                        foreach (var match in g.ValidMatches)
                        {
                            if (match == t)
                            {
                                matched = true;
                                //break;
                            }
                        }
                        if (matched == false)
                        {
                            return(false);
                        }
                        Params.Add(g.ParamName, t);
                        s = s.Substring(end);
                    }
                }
            }
            if (s.Length != 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }