Пример #1
0
        public EventHandlerFilterResult(EventHandlerContext context, ServicesContainer services, IEventHandlerFilter[] filters)
        {
            Contract.Requires(context != null);
            Contract.Requires(services != null);
            Contract.Requires(filters != null);

            this.context = context;
            this.services = services;
            this.filters = filters;
        }
Пример #2
0
        public static Func<Task> InvokeHandlerWithHandlerFiltersAsync(EventHandlerContext context, CancellationToken cancellationToken, IEventHandlerFilter[] filters, Func<Task> innerAction)
        {
            Contract.Requires(context != null);
            Contract.Requires(filters != null);
            Contract.Requires(innerAction != null);

            Func<Task> result = innerAction;
            for (int i = filters.Length - 1; i >= 0; i--)
            {
                IEventHandlerFilter commandFilter = filters[i];
                Func<Func<Task>, IEventHandlerFilter, Func<Task>> chainContinuation = (continuation, innerFilter) => () => innerFilter.ExecuteHandlerFilterAsync(context, cancellationToken, continuation);

                result = chainContinuation(result, commandFilter);
            }

            return result;
        }
Пример #3
0
        public static Func <Task> InvokeHandlerWithHandlerFiltersAsync(EventHandlerContext context, CancellationToken cancellationToken, IEventHandlerFilter[] filters, Func <Task> innerAction)
        {
            Contract.Requires(context != null);
            Contract.Requires(filters != null);
            Contract.Requires(innerAction != null);

            Func <Task> result = innerAction;

            for (int i = filters.Length - 1; i >= 0; i--)
            {
                IEventHandlerFilter commandFilter = filters[i];
                Func <Func <Task>, IEventHandlerFilter, Func <Task> > chainContinuation = (continuation, innerFilter) => () => innerFilter.ExecuteHandlerFilterAsync(context, cancellationToken, continuation);

                result = chainContinuation(result, commandFilter);
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// The create filter tracers.
        /// </summary>
        /// <param name="filter">
        /// The filter.
        /// </param>
        /// <param name="traceWriter">
        /// The trace writer.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable"/>.
        /// </returns>
        public static IEnumerable <IFilter> CreateFilterTracers(IFilter filter, ITraceWriter traceWriter)
        {
            List <IFilter> filters = new List <IFilter>();
            bool           addedCommandHandlerAttributeTracer = false;
            bool           addedExceptionAttributeTracer      = false;
            bool           addedEventHandlerAttributeTracer   = false;

            CommandHandlerFilterAttribute commandHandlerFilterAttribute = filter as CommandHandlerFilterAttribute;

            if (commandHandlerFilterAttribute != null)
            {
                filters.Add(new CommandHandlerFilterAttributeTracer(commandHandlerFilterAttribute, traceWriter));
                addedCommandHandlerAttributeTracer = true;
            }

            ExceptionFilterAttribute exceptionFilterAttribute = filter as ExceptionFilterAttribute;

            if (exceptionFilterAttribute != null)
            {
                filters.Add(new ExceptionFilterAttributeTracer(exceptionFilterAttribute, traceWriter));
                addedExceptionAttributeTracer = true;
            }

            EventHandlerFilterAttribute eventHandlerFilterAttribute = filter as EventHandlerFilterAttribute;

            if (eventHandlerFilterAttribute != null)
            {
                filters.Add(new EventHandlerFilterAttributeTracer(eventHandlerFilterAttribute, traceWriter));
                addedEventHandlerAttributeTracer = true;
            }

            // Do not add an IHandlerFilter tracer if we already added an HandlerFilterAttribute tracer
            ICommandHandlerFilter commandHandlerFilter = filter as ICommandHandlerFilter;

            if (commandHandlerFilter != null && !addedCommandHandlerAttributeTracer)
            {
                filters.Add(new CommandHandlerFilterTracer(commandHandlerFilter, traceWriter));
            }

            // Do not add an IExceptionFilter tracer if we already added an ExceptoinFilterAttribute tracer
            IExceptionFilter exceptionFilter = filter as IExceptionFilter;

            if (exceptionFilter != null && !addedExceptionAttributeTracer)
            {
                filters.Add(new ExceptionFilterTracer(exceptionFilter, traceWriter));
            }

            // Do not add an IEventHandlerFilter tracer if we already added an EventHandlerFilterAttribute tracer
            IEventHandlerFilter eventHandlerFilter = filter as IEventHandlerFilter;

            if (eventHandlerFilter != null && !addedEventHandlerAttributeTracer)
            {
                filters.Add(new EventHandlerFilterTracer(eventHandlerFilter, traceWriter));
            }

            if (filters.Count == 0)
            {
                filters.Add(new FilterTracer(filter, traceWriter));
            }

            return(filters);
        }
Пример #5
0
 private static Func<Task> InvokeActionWithActionFilters(EventHandlerContext context, CancellationToken cancellationToken, IEventHandlerFilter[] filters, Func<ActionInvoker, Task> innerAction, ActionInvoker state)
 {
     return InvokeHandlerWithHandlerFiltersAsync(context, cancellationToken, filters, () => innerAction(state));
 }