Example #1
0
 public UriToActionMatch(
     ControllerAction controllerAction,
     Func <HttpEntityManager, RequestParams> requestHandler)
 {
     ControllerAction = controllerAction;
     RequestHandler   = requestHandler;
 }
Example #2
0
        public void RegisterAction(ControllerAction action, Func<HttpEntityManager, UriTemplateMatch, RequestParams> handler)
        {
            Ensure.NotNull(action, "action");
            Ensure.NotNull(handler, "handler");

            var segments = new Uri("http://fake" + action.UriTemplate, UriKind.Absolute).Segments;
            RouterNode node = _root;
            foreach (var segm in segments)
            {
                var segment = Uri.UnescapeDataString(segm);
                string path = segment.StartsWith("{*") ? GreedyPlaceholder
                            : segment.StartsWith("{") ? Placeholder
                            : segment;

                RouterNode child;
                if (!node.Children.TryGetValue(path, out child))
                {
                    child = new RouterNode();
                    node.Children.Add(path, child);
                }
                node = child;
            }
            if (node.LeafRoutes.Contains(x => x.Action.Equals(action)))
                throw new ArgumentException("Duplicate route.");
            node.LeafRoutes.Add(new HttpRoute(action, handler));
        }
Example #3
0
        public void RegisterAction(ControllerAction action, Action <HttpEntityManager, UriTemplateMatch> handler)
        {
            Ensure.NotNull(action, "action");
            Ensure.NotNull(handler, "handler");

            _uriRouter.RegisterAction(action, handler);
        }
Example #4
0
        public void RegisterAction(ControllerAction action, Action <HttpEntityManager, UriTemplateMatch> handler)
        {
            Ensure.NotNull(action, "action");
            Ensure.NotNull(handler, "handler");

            var        segments = new Uri("http://fake" + action.UriTemplate, UriKind.Absolute).Segments;
            RouterNode node     = _root;

            foreach (var segm in segments)
            {
                var    segment = Uri.UnescapeDataString(segm);
                string path    = segment.StartsWith("{*") ? GreedyPlaceholder
                            : segment.StartsWith("{") ? Placeholder
                            : segment;

                RouterNode child;
                if (!node.Children.TryGetValue(path, out child))
                {
                    child = new RouterNode();
                    node.Children.Add(path, child);
                }
                node = child;
            }
            if (node.LeafRoutes.Contains(x => x.Action.Equals(action)))
            {
                throw new ArgumentException("Duplicate route.");
            }
            node.LeafRoutes.Add(new HttpRoute(action, handler));
        }
Example #5
0
        public void RegisterCustomAction(ControllerAction action, Func <HttpEntityManager, UriTemplateMatch, RequestParams> handler)
        {
            Ensure.NotNull(action, "action");
            Ensure.NotNull(handler, "handler");

            _uriRouter.RegisterAction(action, handler);
        }
Example #6
0
 public UriToActionMatch(UriTemplateMatch templateMatch,
                         ControllerAction controllerAction,
                         Action <HttpEntity, UriTemplateMatch> requestHandler)
 {
     TemplateMatch    = templateMatch;
     ControllerAction = controllerAction;
     RequestHandler   = requestHandler;
 }
 public UriToActionMatch(UriTemplateMatch templateMatch,
                         ControllerAction controllerAction,
                         Func <HttpEntityManager, UriTemplateMatch, RequestParams> requestHandler)
 {
     TemplateMatch    = templateMatch;
     ControllerAction = controllerAction;
     RequestHandler   = requestHandler;
 }
Example #8
0
 public void RegisterAction(ControllerAction action, Action <HttpEntityManager, UriTemplateMatch> handler)
 {
     if (_actions.Contains(x => x.Action.Equals(action)))
     {
         throw new ArgumentException("Duplicate route.");
     }
     _actions.Add(new HttpRoute(action, handler));
 }
 public UriToActionMatch(UriTemplateMatch templateMatch, 
                         ControllerAction controllerAction, 
                         Func<HttpEntityManager, UriTemplateMatch, RequestParams> requestHandler)
 {
     TemplateMatch = templateMatch;
     ControllerAction = controllerAction;
     RequestHandler = requestHandler;
 }
 public UriToActionMatch(UriTemplateMatch templateMatch, 
                         ControllerAction controllerAction, 
                         Action<HttpEntity, UriTemplateMatch> requestHandler)
 {
     TemplateMatch = templateMatch;
     ControllerAction = controllerAction;
     RequestHandler = requestHandler;
 }
Example #11
0
 public void RegisterAction(ControllerAction action,
                            Func <HttpEntityManager, RequestParams> handler)
 {
     if (_actions.Contains(x => x.Action.Equals(action)))
     {
         throw new ArgumentException("Duplicate route.");
     }
     _actions.Add(new HttpRoute(action, handler));
 }
Example #12
0
        public void RegisterAction(ControllerAction action, Action <HttpEntityManager, UriTemplateMatch> handler)
        {
            Ensure.NotNull(action, "action");
            Ensure.NotNull(handler, "handler");

            UriRouter.RegisterAction(action, (man, match) => {
                handler(man, match);
                return(new RequestParams(ESConsts.HttpTimeout));
            });
        }
Example #13
0
        public void RegisterControllerAction(ControllerAction action, Action <HttpEntity, UriTemplateMatch> handler)
        {
            Ensure.NotNull(action, "action");
            Ensure.NotNull(handler, "handler");

            if (!_actions.ContainsKey(action))
            {
                _actions[action] = handler;
            }
        }
 public bool Equals(ControllerAction other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.UriTemplate, UriTemplate) && Equals(other.HttpMethod, HttpMethod));
 }
Example #15
0
        public void RegisterAction(ControllerAction action, Action <HttpEntityManager, UriTemplateMatch> handler)
        {
            Ensure.NotNull(action, "action");
            Ensure.NotNull(handler, "handler");

            _uriRouter.RegisterAction(action, (man, match) => {
                if (_disableAuthorization || Authorized(man.User, action.RequiredAuthorizationLevel))
                {
                    handler(man, match);
                }
                else
                {
                    man.ReplyStatus(EventStore.Transport.Http.HttpStatusCode.Unauthorized, "Unauthorized", (exc) => {
                        Log.Debug("Error while sending reply (http service): {exc}.", exc.Message);
                    });
                }
                return(new RequestParams(ESConsts.HttpTimeout));
            });
        }
Example #16
0
 public HttpRoute(ControllerAction action, Action<HttpEntityManager, UriTemplateMatch> handler)
 {
     Action = action;
     Handler = handler;
     UriTemplate = new UriTemplate(action.UriTemplate);
 }
Example #17
0
 public HttpRoute(ControllerAction action, Action <HttpEntityManager, UriTemplateMatch> handler)
 {
     Action      = action;
     Handler     = handler;
     UriTemplate = new UriTemplate(action.UriTemplate);
 }
Example #18
0
 public void RegisterAction(ControllerAction action, Func<HttpEntityManager, UriTemplateMatch, RequestParams> handler)
 {
     if (_actions.Contains(x => x.Action.Equals(action)))
         throw new ArgumentException("Duplicate route.");
     _actions.Add(new HttpRoute(action, handler));
 }
 public bool Equals(ControllerAction other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.UriTemplate, UriTemplate) && Equals(other.HttpMethod, HttpMethod);
 }
 public HttpRoute(ControllerAction action, Func <HttpEntityManager, UriTemplateMatch, RequestParams> handler)
 {
     Action      = action;
     Handler     = handler;
     UriTemplate = new UriTemplate(action.UriTemplate);
 }
Example #21
0
 public HttpRoute(ControllerAction action, Func<HttpEntityManager, UriTemplateMatch, RequestParams> handler)
 {
     Action = action;
     Handler = handler;
     UriTemplate = new UriTemplate(action.UriTemplate);
 }
Example #22
0
 public HttpRoute(ControllerAction action, Func <HttpEntityManager, RequestParams> handler)
 {
     Action  = action;
     Handler = handler;
 }