Exemple #1
0
        protected override void OnMessageReceived(Envelope <ICommand> envelope)
        {
            var commandType       = envelope.Body.GetType();
            var traceInfo         = (TraceInfo)envelope.Items[StandardMetadata.TraceInfo];
            var handlerDescriptor = GetHandlerDescriptors(commandType).First();


            var methodInvocation = new MethodInvocation(handlerDescriptor.Target, handlerDescriptor.Method, CreateParameters(handlerDescriptor.HandlerStyle, commandType, envelope));

            methodInvocation.InvocationContext[StandardMetadata.TraceInfo] = traceInfo;
            methodInvocation.InvocationContext[StandardMetadata.MessageId] = envelope.MessageId;

            try {
                var methodReturn = _pipelineManager.GetPipeline(handlerDescriptor.Method).Invoke(methodInvocation,
                                                                                                 delegate(IMethodInvocation input, GetNextHandlerDelegate getNext) {
                    handlerDescriptor.Invode(input.Arguments.Cast <object>().ToArray());
                    if (handlerDescriptor.HandlerStyle == HandlerStyle.Special)
                    {
                        ((CommandContext)input.Arguments[0]).Commit();
                        return(input.CreateMethodReturn(CommandResult.CommandExecuted));
                    }
                    return(input.CreateMethodReturn(null));
                });
                NotifyResult(traceInfo, methodReturn.Exception ?? methodReturn.ReturnValue);
            }
            catch (Exception ex) {
                NotifyResult(traceInfo, ex);
            }
        }
Exemple #2
0
        private void ExecutingQuery(HandlerDescriptor handlerDescriptor, Envelope <IQuery> envelope)
        {
            var traceInfo = (TraceInfo)envelope.Items[StandardMetadata.TraceInfo];

            var methodInvocation = new MethodInvocation(handlerDescriptor.Target, handlerDescriptor.Method, envelope.Body);

            methodInvocation.InvocationContext[StandardMetadata.TraceInfo] = traceInfo;
            methodInvocation.InvocationContext[StandardMetadata.MessageId] = envelope.MessageId;

            try {
                var methodReturn = _pipelineManager.GetPipeline(handlerDescriptor.Method).Invoke(methodInvocation,
                                                                                                 delegate(IMethodInvocation input, GetNextHandlerDelegate getNext) {
                    var result = handlerDescriptor.Invode(input.Arguments.Cast <object>().ToArray());
                    return(input.CreateMethodReturn(result));
                });
                NotifyResult(traceInfo, methodReturn.Exception ?? methodReturn.ReturnValue);
            }
            catch (Exception ex) {
                NotifyResult(traceInfo, ex);
            }
        }