Ejemplo n.º 1
0
        CommandHandlerDescriptor ICommandHandlerSelector.SelectHandler(CommandHandlerRequest request)
        {
            CommandHandlerDescriptor handlerDescriptor = null;

            this.traceWriter.TraceBeginEnd(
                request,
                TraceCategories.HandlersCategory,
                TraceLevel.Info,
                this.innerSelector.GetType().Name,
                SelectActionMethodName,
                beginTrace: null,
                execute: () => handlerDescriptor = this.innerSelector.SelectHandler(request),
                endTrace: tr =>
            {
                tr.Message = Error.Format(
                    Resources.TraceHandlerSelectedMessage,
                    FormattingUtilities.HandlerDescriptorToString(handlerDescriptor));
            },
                errorTrace: null);

            // Intercept returned HttpActionDescriptor with a tracing version
            if (handlerDescriptor != null && !(handlerDescriptor is CommandHandlerDescriptorTracer))
            {
                return(new CommandHandlerDescriptorTracer(handlerDescriptor, this.traceWriter));
            }

            return(handlerDescriptor);
        }
        public override Task <object> ExecuteAsync(CommandHandlerContext context, CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            return(this.traceWriter.TraceBeginEndAsync(
                       context.Request,
                       TraceCategories.HandlersCategory,
                       TraceLevel.Info,
                       this.innerDescriptor.GetType().Name,
                       ExecuteAsyncMethodName,
                       beginTrace: null,
                       execute: () => this.innerDescriptor.ExecuteAsync(context, cancellationToken),
                       endTrace: (tr, value) =>
            {
                tr.Message = Error.Format("Handler returnd '{0}'.", FormattingUtilities.ValueToString(value, CultureInfo.CurrentCulture));
            },
                       errorTrace: null));
        }
        /// <summary>
        /// The on command executing.
        /// </summary>
        /// <param name="handlerContext">
        /// The handler context.
        /// </param>
        public override void OnCommandExecuting(CommandHandlerContext handlerContext)
        {
            if (handlerContext == null)
            {
                throw Error.ArgumentNull("handlerContext");
            }

            this.traceWriter.TraceBeginEnd(
                handlerContext.Request,
                TraceCategories.FiltersCategory,
                TraceLevel.Info,
                this.innerFilter.GetType().Name,
                OnCommandExecutingMethodName,
                beginTrace: tr =>
            {
                tr.Message = Error.Format(Resources.TraceActionFilterMessage, FormattingUtilities.HandlerDescriptorToString(handlerContext.Descriptor));
            },
                execute: () => this.innerFilter.OnCommandExecuting(handlerContext),
                endTrace: null,
                errorTrace: null);
        }
Ejemplo n.º 4
0
        EventHandlersDescriptor IEventHandlerSelector.SelectHandlers(EventHandlerRequest request)
        {
            EventHandlersDescriptor eventDescriptor = null;

            this.traceWriter.TraceBeginEnd(
                request,
                TraceCategories.HandlersCategory,
                TraceLevel.Info,
                this.innerSelector.GetType().Name,
                SelectActionMethodName,
                beginTrace: null,
                execute: () => eventDescriptor = this.innerSelector.SelectHandlers(request),
                endTrace: tr =>
            {
                tr.Message = Error.Format(
                    Resources.TraceHandlerSelectedMessage,
                    FormattingUtilities.EventHandlerDescriptorsToString(eventDescriptor.EventHandlerDescriptors));
            },
                errorTrace: null);

            Collection <EventHandlerDescriptor> handlerDescriptors = new Collection <EventHandlerDescriptor>();

            foreach (var handlerDescriptor in eventDescriptor.EventHandlerDescriptors)
            {
                // Intercept returned EventHandlerDescriptor with a tracing version
                if (handlerDescriptor != null && !(handlerDescriptor is EventHandlerDescriptorTracer))
                {
                    handlerDescriptors.Add(new EventHandlerDescriptorTracer(handlerDescriptor, this.traceWriter));
                }
                else
                {
                    handlerDescriptors.Add(handlerDescriptor);
                }
            }

            return(new EventHandlersDescriptor(eventDescriptor.EventName, handlerDescriptors));
        }