Пример #1
0
        /// <summary>
        /// Evaluates the Routing tree and return at least one route.
        /// </summary>
        /// <param name="resourcePath">
        /// HTTP path to the requested resource.
        /// </param>
        /// <returns>
        /// Returns a route to execute.
        /// </returns>
        public RouteEvaluation Evaluate(BlackContext context)
        {
            if (this.RootRoute == null)
            {
                throw new BlackException("Router requires at least a root route", null);
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            RouteWalker walker = new RouteWalker();

            walker.router       = this;
            walker.ResourcePath = context.ResourcePath;
            walker.Context      = context;
            var finalRoute = walker.Walk();

            if (finalRoute.Route != null)
            {
                return(finalRoute);
            }
            return(new RouteEvaluation
            {
                Route = NotFoundRoute
            });
        }
Пример #2
0
        /// <summary>
        /// Evaluates the Routing tree and return at least one route.
        /// </summary>
        /// <param name="resourcePath">
        /// HTTP path to the requested resource.
        /// </param>
        /// <returns>
        /// Returns a route to execute.
        /// </returns>
        public RouteEvaluation Evaluate(BlackContext context)
        {
            if(this.RootRoute == null)
                throw new BlackException("Router requires at least a root route",null);

            if(context == null)
                throw new ArgumentNullException("context");

            RouteWalker walker = new RouteWalker();
            walker.router = this;
            walker.ResourcePath = context.ResourcePath;
            walker.Context = context;
            var finalRoute = walker.Walk();
            if(finalRoute.Route != null)
            {
                return finalRoute;
            }
            return new RouteEvaluation
            {
                Route = NotFoundRoute
            };
        }