/// <summary> /// <b>Defensively</b> invokes the supplied <paramref name="sink"/>, passing the /// supplied <paramref name="arguments"/> to the sink. /// </summary> /// <param name="sink">The sink to be invoked.</param> /// <param name="arguments">The arguments to the sink.</param> /// <param name="exceptions">the map of sink/exception entries to add any exception to</param> protected override void Invoke(Delegate sink, object[] arguments, EventExceptionsCollector exceptions) { try { sink.DynamicInvoke(arguments); } catch (Exception ex) { Log.Warn("Error during raising an event from " + new StackTrace(), ex); exceptions.Add(sink, ex); } }
/// <summary> /// <b>Defensively</b> invokes the supplied <paramref name="sink"/>, passing the /// supplied <paramref name="arguments"/> to the sink. /// </summary> /// <param name="sink">The sink to be invoked.</param> /// <param name="arguments">The arguments to the sink.</param> /// <param name="exceptions">the map of sink/exception entries to add any exception to</param> protected override void Invoke(Delegate sink, object[] arguments, EventExceptionsCollector exceptions) { try { sink.DynamicInvoke (arguments); } catch(Exception ex) { Log.Warn("Error during raising an event from " + new StackTrace(), ex); exceptions.Add(sink, ex); } }
/// <summary> /// Raises the event encapsulated by the supplied /// <paramref name="source"/>, passing the supplied <paramref name="arguments"/> /// to the event. /// </summary> /// <param name="source">The event to be raised.</param> /// <param name="arguments">The arguments to the event.</param> /// <returns>a map of sink/exception entries that occurred during event raising</returns> public virtual IEventExceptionsCollector Raise(Delegate source, params object[] arguments) { EventExceptionsCollector exceptions = new EventExceptionsCollector(); if (source != null) { Delegate [] delegates = source.GetInvocationList(); foreach (Delegate sink in delegates) { Invoke(sink, arguments, exceptions); } } return(exceptions); }
/// <summary> /// Invokes the supplied <paramref name="sink"/>, passing the supplied /// <paramref name="arguments"/> to the sink. /// </summary> /// <param name="sink">The sink to be invoked.</param> /// <param name="arguments">The arguments to the sink.</param> /// <param name="exceptions">the map of sink/exception entries to add any exception to</param> protected virtual void Invoke(Delegate sink, object[] arguments, EventExceptionsCollector exceptions) { try { sink.DynamicInvoke(arguments); } catch (TargetInvocationException ex) { // unwrap the exception that actually caused the TargetInvocationException and throw that... Exception cause = ReflectionUtils.UnwrapTargetInvocationException(ex); exceptions.Add(sink, cause); throw cause; } }
/// <summary> /// Raises the event encapsulated by the supplied /// <paramref name="source"/>, passing the supplied <paramref name="arguments"/> /// to the event. /// </summary> /// <param name="source">The event to be raised.</param> /// <param name="arguments">The arguments to the event.</param> /// <returns>a map of sink/exception entries that occurred during event raising</returns> public virtual IEventExceptionsCollector Raise(Delegate source, params object[] arguments) { EventExceptionsCollector exceptions = new EventExceptionsCollector(); if (source != null) { Delegate [] delegates = source.GetInvocationList (); foreach (Delegate sink in delegates) { Invoke (sink, arguments, exceptions); } } return exceptions; }
/// <summary> /// Invokes the supplied <paramref name="sink"/>, passing the supplied /// <paramref name="arguments"/> to the sink. /// </summary> /// <param name="sink">The sink to be invoked.</param> /// <param name="arguments">The arguments to the sink.</param> /// <param name="exceptions">the map of sink/exception entries to add any exception to</param> protected virtual void Invoke(Delegate sink, object[] arguments, EventExceptionsCollector exceptions) { try { sink.DynamicInvoke (arguments); } catch (TargetInvocationException ex) { // unwrap the exception that actually caused the TargetInvocationException and throw that... Exception cause = ReflectionUtils.UnwrapTargetInvocationException(ex); exceptions.Add(sink, cause); throw cause; } }