예제 #1
0
        private PomonaResponse InvokeAndWrap(PomonaContext context,
                                             HttpStatusCode?statusCode = null)
        {
            var handler          = context.Session.GetInstance(Method.MethodInfo.ReflectedType);
            var result           = Invoke(handler, context);
            var resultAsResponse = result as PomonaResponse;

            if (resultAsResponse != null)
            {
                return(resultAsResponse);
            }

            var responseBody = result;

            if (ReturnType == typeof(void))
            {
                responseBody = PomonaResponse.NoBodyEntity;
            }

            if (responseBody == PomonaResponse.NoBodyEntity)
            {
                statusCode = HttpStatusCode.NoContent;
            }

            return(new PomonaResponse(context, responseBody, statusCode ?? HttpStatusCode.OK, context.ExpandedPaths));
        }
 internal HandlerMethodInvocationException(PomonaContext context,
                                           IHandlerMethodInvoker invoker,
                                           string message,
                                           Exception innerException)
     : base(message, innerException, HttpStatusCode.InternalServerError)
 {
 }
 internal HandlerMethodInvocationException(PomonaContext context,
                                           IHandlerMethodInvoker invoker,
                                           string message,
                                           Exception innerException)
     : base(message, innerException, HttpStatusCode.InternalServerError)
 {
 }
 protected override object OnGetArgument(HandlerParameter parameter, PomonaContext context, object state)
 {
     if (parameter == this.resourceParameter)
     {
         return(context.Node.Value);
     }
     return(base.OnGetArgument(parameter, context, state));
 }
예제 #5
0
 private PomonaResponse ProcessPatch(PomonaContext context, string ifMatch)
 {
     if (context.Method != HttpMethod.Patch)
     {
         return(null);
     }
     return(ValidateResourceEtag(ifMatch, context.Node));
 }
예제 #6
0
        public PomonaResponse Process(PomonaContext context)
        {
            string ifMatch = null;
            if ((ifMatch = GetIfMatchFromRequest(context)) == null)
                return null;

            return ProcessPatch(context, ifMatch) ?? ProcessPostToChildResourceRepository(context, ifMatch);
        }
예제 #7
0
 public HandledThing Post(HandledThing handledThing, PomonaContext context)
 {
     if (handledThing == null)
         throw new ArgumentNullException(nameof(handledThing));
     if (context == null)
         throw new ArgumentNullException(nameof(context));
     handledThing.Marker = "HANDLER WAS HERE!";
     return (HandledThing)this.repository.Post(handledThing);
 }
 public virtual PomonaResponse Process(PomonaContext context)
 {
     var routeActions = context.Session.GetRouteActions(context).ToList();
     return Before
         .Concat(routeActions.Where(x => x.CanProcess(context)))
         .Concat(After)
         .Where(x => x != null)
         .Select(x => x.Process(context))
         .FirstOrDefault(response => response != null);
 }
예제 #9
0
        public virtual PomonaResponse Process(PomonaContext context)
        {
            var routeActions = context.Session.GetRouteActions(context).ToList();

            return(Before
                   .Concat(routeActions.Where(x => x.CanProcess(context)))
                   .Concat(After)
                   .Where(x => x != null)
                   .Select(x => x.Process(context))
                   .FirstOrDefault(response => response != null));
        }
예제 #10
0
        public PomonaResponse Process(PomonaContext context)
        {
            string ifMatch = null;

            if ((ifMatch = GetIfMatchFromRequest(context)) == null)
            {
                return(null);
            }

            return(ProcessPatch(context, ifMatch) ?? ProcessPostToChildResourceRepository(context, ifMatch));
        }
예제 #11
0
        private PomonaResponse ProcessPostToChildResourceRepository(PomonaContext context, string ifMatch)
        {
            var node = context.Node;
            var collectionType = node.ResultType as EnumerableTypeSpec;
            if (context.Method != HttpMethod.Post || collectionType == null)
                return null;

            var parentNode = node.Parent;
            if (parentNode != null)
                return ValidateResourceEtag(ifMatch, parentNode);
            return null;
        }
 protected override object OnGetArgument(HandlerParameter parameter, PomonaContext context, InvokeState state)
 {
     if (parameter == this.targetResourceParameter)
     {
         return(context.Node.Value);
     }
     if (parameter == this.formParameter)
     {
         return(state.Form);
     }
     return(base.OnGetArgument(parameter, context, state));
 }
예제 #13
0
 public HandledThing Post(HandledThing handledThing, PomonaContext context)
 {
     if (handledThing == null)
     {
         throw new ArgumentNullException(nameof(handledThing));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     handledThing.Marker = "HANDLER WAS HERE!";
     return((HandledThing)this.repository.Post(handledThing));
 }
예제 #14
0
        protected virtual object OnInvoke(object target, PomonaContext context, TInvokeState state)
        {
            var args = new object[Parameters.Count];

            for (var i = 0; i < Parameters.Count; i++)
            {
                //else if (resourceIdArg != null && p.Type == resourceIdArg.GetType())
                //    args[i] = resourceIdArg;
                //else
                args[i] = OnGetArgument(Parameters[i], context, state);
            }

            return(Method.MethodInfo.Invoke(target, args));
        }
예제 #15
0
        private string GetIfMatchFromRequest(PomonaContext context)
        {
            var ifMatch = context.Headers.IfMatch.FirstOrDefault();
            if (ifMatch != null)
            {
                ifMatch = ifMatch.Trim();
                if (ifMatch.Length < 2 || ifMatch[0] != '"' || ifMatch[ifMatch.Length - 1] != '"')
                {
                    throw new NotImplementedException(
                        "Only recognized If-Match with quotes around, * not yet supported (TODO).");
                }

                ifMatch = ifMatch.Substring(1, ifMatch.Length - 2);
            }
            return ifMatch;
        }
예제 #16
0
        private string GetIfMatchFromRequest(PomonaContext context)
        {
            var ifMatch = context.Headers.IfMatch.FirstOrDefault();

            if (ifMatch != null)
            {
                ifMatch = ifMatch.Trim();
                if (ifMatch.Length < 2 || ifMatch[0] != '"' || ifMatch[ifMatch.Length - 1] != '"')
                {
                    throw new NotImplementedException(
                              "Only recognized If-Match with quotes around, * not yet supported (TODO).");
                }

                ifMatch = ifMatch.Substring(1, ifMatch.Length - 2);
            }
            return(ifMatch);
        }
예제 #17
0
        private PomonaResponse ProcessPostToChildResourceRepository(PomonaContext context, string ifMatch)
        {
            var node           = context.Node;
            var collectionType = node.ResultType as EnumerableTypeSpec;

            if (context.Method != HttpMethod.Post || collectionType == null)
            {
                return(null);
            }

            var parentNode = node.Parent;

            if (parentNode != null)
            {
                return(ValidateResourceEtag(ifMatch, parentNode));
            }
            return(null);
        }
        protected override object OnGetArgument(HandlerParameter parameter, PomonaContext context, object state)
        {
            var node = context.Node;
            var resourceResultType = node.Route.ResultItemType as ResourceType;

            if (resourceResultType != null)
            {
                var primaryIdType = resourceResultType.PrimaryId.PropertyType;
                if (parameter.Type == primaryIdType)
                {
                    object parsedId;
                    if (!node.PathSegment.TryParse(primaryIdType, out parsedId))
                    {
                        throw new HandlerMethodInvocationException(context, this, "Unable to parse id from url segment");
                    }
                    return(parsedId);
                }
            }
            return(base.OnGetArgument(parameter, context, state));
        }
예제 #19
0
        protected virtual object OnGetArgument(HandlerParameter parameter, PomonaContext context, TInvokeState state)
        {
            if (parameter.IsResource)
            {
                var parentNode = context
                                 .Node
                                 .Ascendants()
                                 .FirstOrDefault(x => x.ResultType == parameter.TypeSpec);
                if (parentNode != null)
                {
                    return(parentNode.Value);
                }
            }

            if (parameter.Type == typeof(PomonaContext))
            {
                return(context);
            }

            Exception innerEx = null;

            try
            {
                // Never get value of transformed type parameter from IOC container
                if (!parameter.Type.IsValueType && !parameter.IsTransformedType)
                {
                    return(context.Session.GetInstance(parameter.Type));
                }
            }
            catch (Exception ex)
            {
                innerEx = ex;
            }
            throw new HandlerMethodInvocationException(context,
                                                       this,
                                                       $"Unable to invoke handler {Method.MethodInfo.ReflectedType}.{Method.Name}, don't know how to provide value for parameter {parameter.Name}",
                                                       innerEx);
        }
예제 #20
0
 public abstract PomonaResponse Process(PomonaContext context);
예제 #21
0
 public abstract bool CanProcess(PomonaContext context);
예제 #22
0
 public abstract bool CanProcess(PomonaContext context);
 internal HandlerMethodInvocationException(PomonaContext context, IHandlerMethodInvoker invoker, string message)
     : this(context, invoker, message, null)
 {
 }
예제 #24
0
 public override PomonaResponse Process(PomonaContext context)
 {
     return this.func(context);
 }
예제 #25
0
 public override bool CanProcess(PomonaContext context)
 {
     return this.condition == null || this.condition(context);
 }
 internal HandlerMethodInvocationException(PomonaContext context, IHandlerMethodInvoker invoker, string message)
     : this(context, invoker, message, null)
 {
 }
 protected override object OnInvoke(object target, PomonaContext context, InvokeState state)
 {
     state.Form = context.Bind(this.formParameter.TypeSpec);
     return(base.OnInvoke(target, context, state));
 }
예제 #28
0
 private PomonaResponse ProcessPatch(PomonaContext context, string ifMatch)
 {
     if (context.Method != HttpMethod.Patch)
         return null;
     return ValidateResourceEtag(ifMatch, context.Node);
 }
예제 #29
0
 public virtual object Invoke(object target, PomonaContext context)
 {
     return(OnInvoke(target, context, new TInvokeState()));
 }
예제 #30
0
 public override bool CanProcess(PomonaContext context)
 {
     return(true);
 }
예제 #31
0
 public override PomonaResponse Process(PomonaContext context)
 {
     return(InvokeAndWrap(context));
 }
예제 #32
0
 protected override object OnInvoke(object target, PomonaContext context, object state)
 {
     context.Bind(context.Node.ActualResultType, context.Node.Value);
     return(base.OnInvoke(target, context, state));
 }
예제 #33
0
 public abstract PomonaResponse Process(PomonaContext context);
예제 #34
0
 public override PomonaResponse Process(PomonaContext context)
 {
     return(this.func(context));
 }
        public override bool CanProcess(PomonaContext context)
        {
            object form;

            return(context.TryBindAsType(this.formParameter.TypeSpec, out form));
        }
예제 #36
0
 public override bool CanProcess(PomonaContext context)
 {
     return(this.condition == null || this.condition(context));
 }
 protected override object OnInvoke(object target, PomonaContext context, object state)
 {
     context.Bind(context.Node.ActualResultType, context.Node.Value);
     return base.OnInvoke(target, context, state);
 }