public RestRequestHandler GetRestRequestHandler(RestDigestibleUri uri, RestMethod method, RestRequestParameters parameters)
        {
            HandleParameters(uri, parameters);

            if (uri.IsLastNode || this is WildCardUriRequestHandlerNode)
            {
                switch (method)
                {
                case RestMethod.GET:
                    return(HttpGetRequestHandler);

                case RestMethod.POST:
                    return(HttpPostRequestHandler);

                default:
                    throw new ApplicationException("Unknown REST method.");
                }
            }

            uri.NextNode();

            foreach (var childNode in ChildNodes)
            {
                if (childNode.MatchesUriPattern(uri))
                {
                    return(childNode.GetRestRequestHandler(uri, method, parameters));
                }
            }

            return(null);
        }
        public ParameterUriRequestHandlerNode(RestDigestibleUri uri, RestMethod method, RestRequestHandler handler)
        {
            m_parameterPattern = uri.GetCurrentNode();
            m_parameterName    = m_parameterPattern.Replace("]", string.Empty).Replace("[", string.Empty);

            AddRestRequestHandler(uri, method, handler);
        }
 public override bool MatchesUriPattern(RestDigestibleUri uri)
 {
     if (uri.GetCurrentNode().Length != 0)
     {
         return(true);
     }
     return(false);
 }
        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 #5
0
        public RestRequestHandler GetRequestHandler(string url, RestMethod method, out RestRequestParameters parameters)
        {
            var digestibleUrl = new RestDigestibleUri(url);

            parameters = new RestRequestParameters();

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

            return(null);
        }
Exemple #6
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);
        }
 protected override void HandleParameters(RestDigestibleUri uri, RestRequestParameters parameters)
 {
 }
 public override bool MatchesUriPattern(RestDigestibleUri uri)
 {
     return(uri.GetCurrentNode() == m_nodeName);
 }
        public NamedUriRequestHandlerNode(RestDigestibleUri uri, RestMethod method, RestRequestHandler handler)
        {
            m_nodeName = uri.GetCurrentNode();

            AddRestRequestHandler(uri, method, handler);
        }
 protected override void HandleParameters(RestDigestibleUri uri, RestRequestParameters parameters)
 {
     parameters[m_parameterName] = uri.GetCurrentNode();
 }
 protected abstract void HandleParameters(RestDigestibleUri uri, RestRequestParameters parameters);
 public abstract bool MatchesUriPattern(RestDigestibleUri uri);
 public override bool MatchesUriPattern(RestDigestibleUri uri)
 {
     return(true);
 }
 public WildCardUriRequestHandlerNode(RestDigestibleUri uri, RestMethod method, RestRequestHandler handler)
 {
     AddRestRequestHandler(uri, method, handler);
 }