예제 #1
0
        protected void ForVerbAsync(RequestVerb verb, RouteSpecification route, IEnumerable <RouteHandlerAsync> handler)
        {
            if (verb == RequestVerb.Options || verb == RequestVerb.Head)
            {
                throw new ArgumentException(String.Format("Cannot register specific handlers for verb \"{0}\"", verb), "verb");
            }

            _routes.Add(CreateRouteEntry(new RouteMatcher(verb, route), handler));
        }
예제 #2
0
        public RouteMatcher(RequestVerb verb, RouteSpecification route)
        {
            if (route == null)
            {
                throw new ArgumentNullException("route");
            }

            this.Verb         = verb;
            _routeString      = SanatizeRoute(route.ResourceRoute);
            _resourceRegex    = new Regex(BuildRouteRegex(_routeString), RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled);
            _paramMatches     = route.UrlParameters;
            _hasUrlParameters = _paramMatches != null && _paramMatches.Length > 0;

            this.SortOrder = (_routeString.Split('/').Length + 1) + (_hasUrlParameters ? _paramMatches.Length * 3 : 0);
        }
예제 #3
0
 protected void Delete(RouteSpecification route, params RouteHandler[] handler)
 {
     this.ForVerb(RequestVerb.Delete, route, handler);
 }
예제 #4
0
 protected void PostAsync(RouteSpecification route, params RouteHandlerAsync[] handler)
 {
     this.ForVerbAsync(RequestVerb.Post, route, handler);
 }
예제 #5
0
        protected void ForVerb(RequestVerb verb, RouteSpecification route, IEnumerable <RouteHandler> handlers)
        {
            var asyncHandlers = handlers.Select(h => new RouteHandlerAsync((r, d) => Task.FromResult <TResponse>(h(r, d))));

            _routes.Add(CreateRouteEntry(new RouteMatcher(verb, route), asyncHandlers));
        }
예제 #6
0
 protected void Patch(RouteSpecification route, params RouteHandler[] handler)
 {
     this.ForVerb(RequestVerb.Patch, route, handler);
 }