public ParameterUriRequestHandlerNode(RestDigestibleUri uri, RestMethod method, Action <Request, Response> 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 Action <Request, Response> 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); }
public void AddRequestHandler(string url, RestMethod method, Action <Request, Response> 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); }
public Action <Request, Response> 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); case RestMethod.PUT: return(HttpPutRequestHandler); case RestMethod.DELETE: return(HttpDeleteRequestHandler); case RestMethod.OPTIONS: return(HttpGetRequestHandler); 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 void AddRestRequestHandler(RestDigestibleUri uri, RestMethod method, Action <Request, Response> 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; case RestMethod.PUT: if (HttpPutRequestHandler != null) { throw new Exception("Handler already defined"); } HttpPutRequestHandler = handler; return; case RestMethod.OPTIONS: if (HttpPostRequestHandler != null) { throw new Exception("Handler already defined"); } HttpPostRequestHandler = handler; return; case RestMethod.DELETE: if (HttpDeleteRequestHandler != null) { throw new Exception("Handler already defined"); } HttpDeleteRequestHandler = 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(); }
protected abstract void HandleParameters(RestDigestibleUri uri, RestRequestParameters parameters);
public abstract bool MatchesUriPattern(RestDigestibleUri uri);
protected override void HandleParameters(RestDigestibleUri uri, RestRequestParameters parameters) { parameters[m_parameterName] = uri.GetCurrentNode(); }
protected override void HandleParameters(RestDigestibleUri uri, RestRequestParameters parameters) { }
public override bool MatchesUriPattern(RestDigestibleUri uri) { return(true); }
public WildCardUriRequestHandlerNode(RestDigestibleUri uri, RestMethod method, Action <Request, Response> handler) { AddRestRequestHandler(uri, method, handler); }
public override bool MatchesUriPattern(RestDigestibleUri uri) { return(uri.GetCurrentNode() == m_nodeName); }
public NamedUriRequestHandlerNode(RestDigestibleUri uri, RestMethod method, Action <Request, Response> handler) { m_nodeName = uri.GetCurrentNode(); AddRestRequestHandler(uri, method, handler); }