3using System.Threading.Tasks;
40 #region Synchronous event handlers, non-communication-layers
48 public static bool Raise(
this EventHandler EventHandler,
object Sender)
50 return Raise(EventHandler, Sender, EventArgs.Empty,
false);
61 public static bool Raise(
this EventHandler EventHandler,
object Sender,
bool Decoupled)
63 return Raise(EventHandler, Sender, EventArgs.Empty, Decoupled);
73 public static bool Raise(
this EventHandler EventHandler,
object Sender, EventArgs e)
75 return EventHandler.Raise(Sender, e,
false);
87 public static bool Raise(
this EventHandler EventHandler,
object Sender, EventArgs e,
bool Decoupled)
89 if (!(EventHandler is
null))
97 EventHandler(Sender, e);
109 EventHandler(Sender, e);
129 public static bool Raise<T>(
this EventHandler<T> EventHandler,
object Sender, T e)
131 return EventHandler.Raise(Sender, e,
false);
143 public static bool Raise<T>(
this EventHandler<T> EventHandler,
object Sender, T e,
bool Decoupled)
145 if (!(EventHandler is
null))
153 EventHandler(Sender, e);
165 EventHandler(Sender, e);
180 #region Synchronous event handlers, communication layers
203 return Raise(EventHandler, Sender, EventArgs.Empty, Decoupled);
215 return EventHandler.Raise(Sender, e, Sender?.DecoupledEvents ??
false);
227 public static async Task<bool>
Raise(
this EventHandler EventHandler,
IObservableLayer Sender, EventArgs e,
bool Decoupled)
229 if (EventHandler is
null)
230 await Sender.NoEventHandlerWarning(e);
233 Task _ = Task.Run(async () =>
237 EventHandler(Sender, e);
243 if (!(Sender is
null))
249 catch (Exception ex2)
263 EventHandler(Sender, e);
269 if (!(Sender is
null))
284 private static Task NoEventHandlerWarning(
this IObservableLayer Sender,
object e)
287 return Task.CompletedTask;
289 StringBuilder sb =
new StringBuilder();
291 sb.Append(
"No event handler registered (");
294 sb.Append(
"null sender");
296 sb.Append(Sender.GetType().FullName);
299 sb.Append(e.GetType().FullName);
302 return Sender.
Warning(sb.ToString());
314 return EventHandler.Raise(Sender, e, Sender?.DecoupledEvents ??
false);
328 if (EventHandler is
null)
329 await Sender.NoEventHandlerWarning(e);
332 Task _ = Task.Run(async () =>
336 EventHandler(Sender, e);
342 if (!(Sender is
null))
348 catch (Exception ex2)
362 EventHandler(Sender, e);
368 if (!(Sender is
null))
380 #region Asynchronous event handlers, non-communication-layers
390 return Raise(EventHandler, Sender, EventArgs.Empty,
false);
403 return Raise(EventHandler, Sender, EventArgs.Empty, Decoupled);
415 return EventHandler.Raise(Sender, e,
false);
429 if (!(EventHandler is
null))
433 Task _ = Task.Run(async () =>
437 await EventHandler(Sender, e);
449 await EventHandler(Sender, e);
471 return EventHandler.Raise(Sender, e,
false);
485 if (!(EventHandler is
null))
489 Task _ = Task.Run(async () =>
493 await EventHandler(Sender, e);
505 await EventHandler(Sender, e);
520 #region Asynchronous event handlers, communication layers
543 return Raise(EventHandler, Sender, EventArgs.Empty, Decoupled);
555 return EventHandler.Raise(Sender, e, Sender?.DecoupledEvents ??
false);
569 if (EventHandler is
null)
570 await Sender.NoEventHandlerWarning(e);
573 Task _ = Task.Run(async () =>
577 await EventHandler(Sender, e);
583 if (!(Sender is
null))
589 catch (Exception ex2)
603 await EventHandler(Sender, e);
609 if (!(Sender is
null))
628 return EventHandler.Raise(Sender, e, Sender?.DecoupledEvents ??
false);
642 if (EventHandler is
null)
643 await Sender.NoEventHandlerWarning(e);
646 Task _ = Task.Run(async () =>
650 await EventHandler(Sender, e);
656 if (!(Sender is
null))
662 catch (Exception ex2)
676 await EventHandler(Sender, e);
682 if (!(Sender is
null))
694 #region Synchronous callback functions
703 if (!(Callback is
null))
718 #region Asynchronous callback functions
727 if (!(Callback is
null))
731 await Callback(Argument);
Static class with method extensions simplifying raising events.
static Task< bool > Raise(this EventHandlerAsync EventHandler, object Sender, EventArgs e)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static Task< bool > Raise(this EventHandlerAsync EventHandler, object Sender)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static bool Raise(this EventHandler EventHandler, object Sender, EventArgs e)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static Task< bool > Raise(this EventHandler EventHandler, IObservableLayer Sender)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static bool Raise< T >(this EventHandler< T > EventHandler, object Sender, T e)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static Task< bool > Raise(this EventHandlerAsync EventHandler, IObservableLayer Sender)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static async Task< bool > Raise(this EventHandlerAsync EventHandler, IObservableLayer Sender, EventArgs e, bool Decoupled)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static bool Raise(this EventHandler EventHandler, object Sender, EventArgs e, bool Decoupled)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static void Call< ArgT >(this Callback< ArgT > Callback, ArgT Argument)
Calls a callback function. Any exceptions are trapped and logged.
static Task< bool > Raise(this EventHandlerAsync EventHandler, IObservableLayer Sender, bool Decoupled)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static async Task< bool > Raise(this EventHandler EventHandler, IObservableLayer Sender, EventArgs e, bool Decoupled)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static async Task< bool > Raise(this EventHandlerAsync EventHandler, object Sender, EventArgs e, bool Decoupled)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static Task< bool > Raise(this EventHandler EventHandler, IObservableLayer Sender, bool Decoupled)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static Task< bool > Raise(this EventHandler EventHandler, IObservableLayer Sender, EventArgs e)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static Task< bool > Raise(this EventHandlerAsync EventHandler, object Sender, bool Decoupled)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static bool Raise(this EventHandler EventHandler, object Sender)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static bool Raise(this EventHandler EventHandler, object Sender, bool Decoupled)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
static Task< bool > Raise(this EventHandlerAsync EventHandler, IObservableLayer Sender, EventArgs e)
Raises an event, if handler is defined. Any exceptions are trapped and logged.
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Interface for classes that can be observed.
Task Warning(string Warning)
Called to inform the viewer of a warning state.
Task Exception(string Exception)
Called to inform the viewer of an exception state.
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
delegate Task EventHandlerAsync(object Sender, EventArgs e)
Asynchronous version of EventArgs.
delegate Task EventHandlerAsync< T >(object Sender, T e)
Asynchronous version of EventArgs with a typed event arguments.
delegate void Callback< ArgT >(ArgT Arg)
Callback function with one argument.
delegate Task CallbackAsync< ArgT >(ArgT Arg)
Asynchronous callback function with one argument.