internal RouteCallback_A CreateCallback(RouteCallback cb)
        {
            RoutePatternMatch This     = this;
            RouteCallback_A   callback = cb.Callback;

            return((Request req) =>
            {
                RoutePatternMatchResult result = This.Compare(req.cw.Route);
                req.Parameters = new NameValueCollection(result.Parameters.Length);
                foreach ((string name, string value) in result.Parameters)
                {
                    req.Parameters.Add(name, value);
                }
                return (result.Match) ? callback(req) : PassThrough.Skip;
            });
        }
Beispiel #2
0
 public static void Route(RoutePatternMatch route, RouteCallback_A callback) => Routing.AddHandler(route, callback);
Beispiel #3
0
 public static void Delete(RoutePatternMatch route, Response res) => Routing.AddHandler(HTTPMethod.DELETE, route, res);
Beispiel #4
0
 public static void Delete(RoutePatternMatch route, RouteCallback_D callback) => Routing.AddHandler(HTTPMethod.DELETE, route, callback);
Beispiel #5
0
 public static void Put(RoutePatternMatch route, Response res) => Routing.AddHandler(HTTPMethod.PUT, route, res);
Beispiel #6
0
 public static void Put(RoutePatternMatch route, RouteCallback_D callback) => Routing.AddHandler(HTTPMethod.PUT, route, callback);
Beispiel #7
0
 public static void Patch(RoutePatternMatch route, RouteCallback_C callback) => Routing.AddHandler(HTTPMethod.PATCH, route, callback);
Beispiel #8
0
 public Controller(string method, RoutePatternMatch route, Response res) :                                   this(method, route, route.CreateCallback(res))
 {
 }
Beispiel #9
0
 public static void Route(HTTPMethod method, RoutePatternMatch route, Response res) => Routing.AddHandler(method, route, res);
Beispiel #10
0
 public static void Route(HTTPMethod method, RoutePatternMatch route, RouteCallback_D callback) => Routing.AddHandler(method, route, callback);
Beispiel #11
0
 public static void Route(string method, RoutePatternMatch route, Response res) => Routing.AddHandler((MethodArg)method, route, res);
Beispiel #12
0
 public static void Route(string method, RoutePatternMatch route, RouteCallback_D callback) => Routing.AddHandler((MethodArg)method, route, callback);
Beispiel #13
0
 public static void Route(RoutePatternMatch route, Response res) => Routing.AddHandler(route, res);
Beispiel #14
0
 public Controller(HTTPMethod method, RoutePatternMatch route, Response res) :                               this(method.ToString(), route, route.CreateCallback(res))
 {
 }
Beispiel #15
0
 public Controller(HTTPMethod method, RoutePatternMatch route, RouteCallback_D callback) :                   this(method.ToString(), route, route.CreateCallback(callback))
 {
 }
        private RoutePatternMatchResult Compare(string reqUrl)
        {
            reqUrl = Normalize(reqUrl);
            List <(string, string)> par  = new List <(string, string)>(20);
            RoutePatternMatch       This = this;
            int inputStrPosition         = 0;

            for (int i = 0; i < this.Specifier.Length; i++)
            {
                char current = this.Specifier[i];
                char next    = this.Specifier[i + 1];
                switch (current)
                {
                case '*':
                    if (i == this.Specifier.Length - 1)
                    {
                        return(Result(true));
                    }
                    inputStrPosition = reqUrl.IndexOf(next, inputStrPosition);
                    int nextWild = reqUrl.IndexOf(next, '*');
                    if (inputStrPosition == -1 || nextWild < inputStrPosition)
                    {
                        return(Result(false));
                    }
                    break;

                case ':':
                    int pValueEnd = reqUrl.IndexOf('/', inputStrPosition);
                    int pNameEnd  = this.Specifier.IndexOf('/', i);
                    if (pNameEnd == -1)
                    {
                        pNameEnd = this.Specifier.Length - 1;
                    }
                    if (pValueEnd == -1)
                    {
                        pValueEnd = reqUrl.Length - 1;
                    }
                    string name  = this.Specifier.Substring(i + 1, (pNameEnd - i));
                    string value = reqUrl.Substring(inputStrPosition, (pValueEnd - inputStrPosition + 1));
                    par.Add((name, value));
                    inputStrPosition = pValueEnd + 1;
                    if (inputStrPosition >= reqUrl.Length)
                    {
                        return(Result(true));
                    }
                    break;

                default:
                    if (inputStrPosition == reqUrl.Length - 1 && reqUrl[inputStrPosition] == current)
                    {
                        return(Result(true));
                    }
                    if (inputStrPosition >= reqUrl.Length || reqUrl[inputStrPosition] != current)
                    {
                        return(Result(false));
                    }
                    inputStrPosition++;
                    break;
                }
            }

            return(Result(false));

            RoutePatternMatchResult Result(bool match) => new RoutePatternMatchResult(reqUrl, This, match, par.ToArray());
        }
Beispiel #17
0
 public static void Get(RoutePatternMatch route, RouteCallback_B callback) => Routing.AddHandler(HTTPMethod.GET, route, callback);
Beispiel #18
0
 public Controller(string method, RoutePatternMatch route, RouteCallback_D callback) :                       this(method, route, route.CreateCallback(callback))
 {
 }