Ejemplo n.º 1
0
        private void AddRoute(Route route, Queue <string> path, RouteCallback callback, RouteAttribute attribute)
        {
            if (path.Count == 0)
            {
                route.Attribute = attribute;
                route.Callback.Add(callback);
                return;
            }

            string name = path.Dequeue();

            if (!route.Routes.ContainsKey(name))
            {
                route.Routes.Add(name, new Route());
            }

            AddRoute(route.Routes[name], path, callback, attribute);
        }
Ejemplo n.º 2
0
        public bool TryInvokeRoute(string path, HttpListenerRequest request, HttpListenerResponse response, out RouteAttribute attribute)
        {
            var route = Find(_root, new Queue <string>(path.Split('/')));

            if (route == null)
            {
                attribute = null;
                return(false);
            }

            foreach (var callback in route.Callback)
            {
                callback.Invoke(request, response);
            }

            attribute = route.Attribute;
            return(true);
        }
Ejemplo n.º 3
0
 private void AddRoute(string path, RouteCallback callback, RouteAttribute attribute)
 {
     AddRoute(_root, new Queue <string>(path.Split('/')), callback, attribute);
 }