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; }
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; }
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); }
/// <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); }
private static Func<Task> InvokeActionWithActionFilters(EventHandlerContext context, CancellationToken cancellationToken, IEventHandlerFilter[] filters, Func<ActionInvoker, Task> innerAction, ActionInvoker state) { return InvokeHandlerWithHandlerFiltersAsync(context, cancellationToken, filters, () => innerAction(state)); }