/// <summary>
        /// Returns true and populates the route entry and path parameters if the key exists.
        /// </summary>
        public bool TryGetRouteEntry(RouteKey key, out RouteEntry entry, out PathParams parms)
        {
            parms = new PathParams();
            entry = Parse(key, parms);

            return(entry != null);
        }
        /// <summary>
        /// Parse the browser's path request and match it against the routes.
        /// If found, return the route entry (otherwise null).
        /// Also if found, the parms will be populated with any segment parameters.
        /// </summary>
        protected RouteEntry Parse(RouteKey key, PathParams parms)
        {
            RouteEntry entry = null;

            // First, check non-parameterized routes.
            // The most performant way to handle parameters is after the path,
            // rather than embedding parameters in the URL itself.
            if (!routes.TryGetValue(key, out entry))
            {
                string[] pathSegments = key.Path.Split('/');

                foreach (KeyValuePair <RouteKey, RouteEntry> route in routes)
                {
                    // Above all else, verbs and, if not wildcarded, content type must match.
                    if ((route.Key.Verb == key.Verb) && ((route.Key.ContentType == "*") || (route.Key.ContentType == key.ContentType)))
                    {
                        string[] routeSegments = route.Key.Path.Split('/');

                        // Then, segments must match
                        if (Match(pathSegments, routeSegments, parms))
                        {
                            entry = route.Value;
                            break;
                        }
                    }
                }
            }

            return(entry);
        }
        /// <summary>
        /// Get the route entry for the verb and path including any path parameters.
        /// Throws an exception if the route isn't found.
        /// </summary>
        public RouteEntry GetRouteEntry(RouteKey key, out PathParams parms)
        {
            parms = new PathParams();
            RouteEntry entry = Parse(key, parms);

            if (entry == null)
            {
                throw new ApplicationException("The route key " + key.ToString() + " does not exist.");
            }

            return(entry);
        }
Esempio n. 4
0
        public override bool Equals(object obj)
        {
            bool     ret = false;
            RouteKey key = (RouteKey)obj;

            if (contentType == "*")
            {
                ret = verb == key.verb && path == key.path;
            }
            else
            {
                ret = verb == key.verb && path == key.path && contentType == key.contentType;
            }

            return(ret);
        }
 /// <summary>
 /// Add a unique route.
 /// </summary>
 public void AddRoute(RouteKey key, RouteEntry route)
 {
     routes.ThrowIfKeyExists(key, "The route key " + key.ToString() + " already exists.")[key] = route;
 }
        /// <summary>
        /// True if the routing table contains the verb-path key.
        /// </summary>
        public bool ContainsKey(RouteKey key)
        {
            RouteEntry entry = Parse(key, new PathParams());

            return(entry != null);
        }
Esempio n. 7
0
 /// <summary>
 /// Get the route entry for the verb and path.
 /// </summary>
 public RouteEntry GetRouteEntry(RouteKey key)
 {
     return(routes.ThrowIfKeyDoesNotExist(key, "The route key " + key.ToString() + " does not exist.")[key]);
 }
Esempio n. 8
0
 /// <summary>
 /// True if the routing table contains the verb-path key.
 /// </summary>
 public bool ContainsKey(RouteKey key)
 {
     return(routes.ContainsKey(key));
 }
Esempio n. 9
0
 /// <summary>
 /// Returns true and populates the out entry parameter if the key exists.
 /// </summary>
 public bool TryGetRouteEntry(RouteKey key, out RouteEntry entry)
 {
     return(routes.TryGetValue(key, out entry));
 }