Exemplo n.º 1
0
        private void WriteResponse(HttpListenerContext context)
        {
            context.Response.ContentEncoding = Encoding.UTF8;

            var requestWrapper = new RequestWrapper(context.Request);

            IRouteTemplate route = _routeTable.FirstOrDefault(definition => definition.Matches(requestWrapper));

            if (route != null)
            {
                object returnValue;
                if (!route.TryInvocation(requestWrapper, out returnValue))
                {
                    returnValue = null;
                }

                string serializeObject = JsonConvert.SerializeObject(returnValue);
                WriteStringToResponse(context.Response, serializeObject);
            }
            else
            {
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                WriteStringToResponse(context.Response, "Not Found");
            }
        }
Exemplo n.º 2
0
        public bool TryInvocation(RequestWrapper request, out object returnValue)
        {
            foreach (var invationVsReturnValue in _invocationVsReturnValue)
            {
                if (invationVsReturnValue.Key.Matches(request))
                {
                    returnValue = invationVsReturnValue.Value.Produce(request.Request);
                    return(true);
                }
            }

            returnValue = null;
            return(false);
        }
Exemplo n.º 3
0
 public bool Matches(RequestWrapper request)
 {
     return(_bodyEvaluator(request.NegotiateAndDeserializeMethodBody()));
 }
 public bool Matches(RequestWrapper request)
 {
     return(_predicatesToCombine.All(predicate => predicate.Matches(request)));
 }
        public bool Matches(RequestWrapper request)
        {
            var parameterValue = _routeOwningUrl.Route.GetParameterValue <T>(request.Request, _parameterName, _parameterLocation);

            return(_predicate(parameterValue));
        }
Exemplo n.º 6
0
 public bool Matches(RequestWrapper request)
 {
     return(Route.Matches(request.Request.RawUrl));
 }
 public bool Matches(RequestWrapper request)
 {
     return _bodyEvaluator(request.NegotiateAndDeserializeMethodBody());
 }
Exemplo n.º 8
0
 public bool Matches(RequestWrapper request)
 {
     return _predicatesToCombine.All(predicate => predicate.Matches(request));
 }
 public CapturedRouteInvocation(RequestWrapper request, IRouteTemplate routeOwningUrl)
 {
     _request        = request;
     _routeOwningUrl = routeOwningUrl;
 }