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) { }
protected override object OnGetArgument(HandlerParameter parameter, PomonaContext context, object state) { if (parameter == this.resourceParameter) { return(context.Node.Value); } return(base.OnGetArgument(parameter, context, state)); }
private PomonaResponse ProcessPatch(PomonaContext context, string ifMatch) { if (context.Method != HttpMethod.Patch) { return(null); } return(ValidateResourceEtag(ifMatch, context.Node)); }
public PomonaResponse Process(PomonaContext context) { string ifMatch = null; if ((ifMatch = GetIfMatchFromRequest(context)) == null) return null; return ProcessPatch(context, ifMatch) ?? ProcessPostToChildResourceRepository(context, ifMatch); }
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); }
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)); }
public PomonaResponse Process(PomonaContext context) { string ifMatch = null; if ((ifMatch = GetIfMatchFromRequest(context)) == null) { return(null); } return(ProcessPatch(context, ifMatch) ?? ProcessPostToChildResourceRepository(context, ifMatch)); }
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)); }
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)); }
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)); }
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; }
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); }
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)); }
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); }
public abstract PomonaResponse Process(PomonaContext context);
public abstract bool CanProcess(PomonaContext context);
internal HandlerMethodInvocationException(PomonaContext context, IHandlerMethodInvoker invoker, string message) : this(context, invoker, message, null) { }
public override PomonaResponse Process(PomonaContext context) { return this.func(context); }
public override bool CanProcess(PomonaContext context) { return this.condition == null || this.condition(context); }
protected override object OnInvoke(object target, PomonaContext context, InvokeState state) { state.Form = context.Bind(this.formParameter.TypeSpec); return(base.OnInvoke(target, context, state)); }
private PomonaResponse ProcessPatch(PomonaContext context, string ifMatch) { if (context.Method != HttpMethod.Patch) return null; return ValidateResourceEtag(ifMatch, context.Node); }
public virtual object Invoke(object target, PomonaContext context) { return(OnInvoke(target, context, new TInvokeState())); }
public override bool CanProcess(PomonaContext context) { return(true); }
public override PomonaResponse Process(PomonaContext context) { return(InvokeAndWrap(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)); }
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)); }
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); }