Ejemplo n.º 1
0
        /// <summary>
        /// Validates the specified route, producing a <see cref="RouteValidationResult"/> indicating 
        /// what the error (if any) was.
        /// </summary>
        /// <param name="route">The route to validate.</param>
        /// <returns>An object indicating the success of the validation attempt, and details about any error 
        /// encountered.</returns>
        public virtual RouteValidationResult Validate(ParsedRoute route)
        {
            var segments = route.Segments;

            // Shortcut - no need to check any rules for an empty route
            if (segments.Length == 0)
            {
                return RouteValidationResult.Successful();
            }

            return Rules.Select(rule => rule(segments, route.Defaults, route.Constraints))
                .FirstOrDefault(x => !x.Success) 
                ?? RouteValidationResult.Successful();
        }
        /// <summary>
        /// Validates the specified route, producing a <see cref="RouteValidationResult"/> indicating
        /// what the error (if any) was.
        /// </summary>
        /// <param name="route">The route to validate.</param>
        /// <returns>An object indicating the success of the validation attempt, and details about any error
        /// encountered.</returns>
        public virtual RouteValidationResult Validate(ParsedRoute route)
        {
            var segments = route.Segments;

            // Shortcut - no need to check any rules for an empty route
            if (segments.Length == 0)
            {
                return(RouteValidationResult.Successful());
            }

            return(Rules.Select(rule => rule(segments, route.Defaults, route.Constraints))
                   .FirstOrDefault(x => !x.Success)
                   ?? RouteValidationResult.Successful());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gives the route a chance to inialize itself. This method is called when the route is registered
 /// in a route collection. It should be used for any pre-compilation, caching or validation tasks.
 /// </summary>
 public void Validate()
 {
     if (parsedRoute == null)
     {
         parsedRoute = parser.Parse(this, pathSpecification, defaults, constraints);
         var result = validator.Validate(parsedRoute);
         if (!result.Success)
         {
             throw new InvalidRouteException(
                       this,
                       result,
                       string.Format("The route with specification '{0}' is invalid: {1}", pathSpecification, string.Join("", result.Errors.Select(x => Environment.NewLine + " - " + x).ToArray()))
                       );
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Gives the route a chance to inialize itself. This method is called when the route is registered
 /// in a route collection. It should be used for any pre-compilation, caching or validation tasks.
 /// </summary>
 public void Validate()
 {
     if (parsedRoute == null)
     {
         parsedRoute = parser.Parse(this, pathSpecification, defaults, constraints);
         var result = validator.Validate(parsedRoute);
         if (!result.Success)
         {
             throw new InvalidRouteException(
                 this,
                 result,
                 string.Format("The route with specification '{0}' is invalid: {1}", pathSpecification, string.Join("", result.Errors.Select(x => Environment.NewLine + " - " + x).ToArray()))
                 );
         }
     }
 }