public virtual Task OnEventOccurredAsync(EventHandlerOccurredContext eventOccurredContext, CancellationToken cancellationToken) { try { this.OnEventOccurred(eventOccurredContext); } catch (Exception ex) { return(TaskHelpers.FromError(ex)); } return(TaskHelpers.Completed()); }
/// <summary> /// The on event occured. /// </summary> /// <param name="handlerContext"> /// The handler context. /// </param> public override void OnEventOccurred(EventHandlerOccurredContext handlerContext) { if (handlerContext == null) { throw Error.ArgumentNull("handlerContext"); } this.traceWriter.TraceBeginEnd( handlerContext.Request, TraceCategories.FiltersCategory, TraceLevel.Info, this.innerFilter.GetType().Name, OnEventOccurredMethodName, beginTrace: tr => { tr.Message = Error.Format(Resources.TraceActionFilterMessage, FormattingUtilities.HandlerDescriptorToString(handlerContext.HandlerContext.Descriptor)); }, execute: () => this.innerFilter.OnEventOccurred(handlerContext), endTrace: null, errorTrace: null); }
private async Task CallOnHandlerOccurrededAsync(EventHandlerContext handlerContext, CancellationToken cancellationToken, Func <Task> continuation) { cancellationToken.ThrowIfCancellationRequested(); ExceptionDispatchInfo exceptionInfo = null; try { await continuation(); } catch (Exception e) { exceptionInfo = ExceptionDispatchInfo.Capture(e); } EventHandlerOccurredContext occurredContext = new EventHandlerOccurredContext(handlerContext, exceptionInfo); await this.OnEventOccurredAsync(occurredContext, cancellationToken); if (occurredContext.ExceptionInfo != null) { if (exceptionInfo == null) { occurredContext.ExceptionInfo.Throw(); } else { Exception exception = exceptionInfo.SourceException; Exception newException = occurredContext.ExceptionInfo.SourceException; if (newException == exception) { exceptionInfo.Throw(); } else { occurredContext.ExceptionInfo.Throw(); } } } }
/// <summary> /// Occurs after the handle method is invoked. /// </summary> /// <param name="eventOccurredContext">The handler executed context.</param> /// <remarks> /// Overrides this method to add a behaviour after an event in a non-asynchronous way. /// </remarks> public virtual void OnEventOccurred(EventHandlerOccurredContext eventOccurredContext) { }