public void AddRestRequestHandler(RestDigestibleUri uri, RestMethod method, RestRequestHandler handler)
        {
            if (uri.IsLastNode || this is WildCardUriRequestHandlerNode)
            {
                switch (method)
                {
                case RestMethod.GET:
                    if (HttpGetRequestHandler != null)
                    {
                        throw new Exception("Handler already defined");
                    }
                    HttpGetRequestHandler = handler;
                    return;

                case RestMethod.POST:
                    if (HttpPostRequestHandler != null)
                    {
                        throw new Exception("Handler already defined");
                    }
                    HttpPostRequestHandler = handler;
                    return;

                default:
                    throw new Exception("Unknown REST Method.");
                }
            }

            uri.NextNode();

            foreach (var childNode in ChildNodes)
            {
                if (childNode.MatchesUriPattern(uri) && ((childNode is ParameterUriRequestHandlerNode && uri.IsCurrentNodeParameterDefinition) ||
                                                         childNode is NamedUriRequestHandlerNode && !uri.IsCurrentNodeParameterDefinition))
                {
                    childNode.AddRestRequestHandler(uri, method, handler);
                    return;
                }
            }

            UriRequestHandlerNode newChildNode;

            if (uri.IsCurrentNodeParameterDefinition)
            {
                newChildNode = new ParameterUriRequestHandlerNode(uri, method, handler);
            }
            else if (uri.IsWildCardNodeDefinition)
            {
                newChildNode = new WildCardUriRequestHandlerNode(uri, method, handler);
            }
            else
            {
                newChildNode = new NamedUriRequestHandlerNode(uri, method, handler);
            }

            ChildNodes.Add(newChildNode);

            ChildNodes = ChildNodes.OrderBy(n => n.GetSearchPriority()).ToList();
        }
Exemple #2
0
        public void AddRequestHandler(string url, RestMethod method, RestRequestHandler handler)
        {
            var digestibleUrl = new RestDigestibleUri(url);

            foreach (var node in m_handlerNodes)
            {
                if (node.MatchesUriPattern(digestibleUrl))
                {
                    node.AddRestRequestHandler(digestibleUrl, method, handler);
                    return;
                }
            }

            var newNode = new NamedUriRequestHandlerNode(digestibleUrl, method, handler);

            m_handlerNodes.Add(newNode);
        }