public object ExecuteListeners(ActionCallInfo callInfo) { object[] actionListeners = _resolvingService.ResolveAll(typeof (IActionListener)); IEnumerable<IActionListener> handlers = actionListeners.Cast<IActionListener>().Where(h => h.CanHandle(callInfo)); var context = new ActionListenerContext(callInfo); bool wasHandled = handlers.Any(actionListener => actionListener.Handle(context)); if (!wasHandled) throw new InvalidOperationException("No handler for call"); return context.Result; }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var callInfo = new ActionCallInfo { NamedArguments = binder.CallInfo .ArgumentNames .Reverse() .Zip(args.Reverse(), (x, y) => new Tuple<string, object>(x, y)) .ToList(), UnnamedArguments = args.Take(binder.CallInfo.ArgumentCount - binder.CallInfo.ArgumentNames.Count).ToList(), MethodName = binder.Name }; result = binder.ResultDiscarded() ? ExecuteListeners(callInfo) : new ServiceAgent(_resolvingService) {CallInfo = callInfo}; return true; }
public bool CanHandle(ActionCallInfo callInfo) { return callInfo.NamedArguments.Any(x => x.Item1.Equals("log", StringComparison.OrdinalIgnoreCase)); }
public bool CanHandle(ActionCallInfo callInfo) { return callInfo.UnnamedArguments.Any(x => x is string); }
public bool CanHandle(ActionCallInfo callInfo) { return true; }