summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/InternalExtensions.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-02-23 19:05:23 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-02-23 19:05:23 -0500
commit68528f7decadccb4c5ed62f3fff10aeff22dcd43 (patch)
treeeb73bbc7d1e808064bc7abc55946f9b650bd8c1a /src/SMAPI/Framework/InternalExtensions.cs
parentc8162c2fb624f1c963615d79b557d7df5a23ff09 (diff)
downloadSMAPI-68528f7decadccb4c5ed62f3fff10aeff22dcd43.tar.gz
SMAPI-68528f7decadccb4c5ed62f3fff10aeff22dcd43.tar.bz2
SMAPI-68528f7decadccb4c5ed62f3fff10aeff22dcd43.zip
overhaul events to track the mod which added each handler, and log errors under their name (#451)
Diffstat (limited to 'src/SMAPI/Framework/InternalExtensions.cs')
-rw-r--r--src/SMAPI/Framework/InternalExtensions.cs58
1 files changed, 0 insertions, 58 deletions
diff --git a/src/SMAPI/Framework/InternalExtensions.cs b/src/SMAPI/Framework/InternalExtensions.cs
index ce67ae18..bff4807c 100644
--- a/src/SMAPI/Framework/InternalExtensions.cs
+++ b/src/SMAPI/Framework/InternalExtensions.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json.Linq;
@@ -15,63 +14,6 @@ namespace StardewModdingAPI.Framework
/****
** IMonitor
****/
- /// <summary>Safely raise an <see cref="EventHandler"/> event, and intercept any exceptions thrown by its handlers.</summary>
- /// <param name="monitor">Encapsulates monitoring and logging.</param>
- /// <param name="name">The event name for error messages.</param>
- /// <param name="handlers">The event handlers.</param>
- /// <param name="sender">The event sender.</param>
- /// <param name="args">The event arguments (or <c>null</c> to pass <see cref="EventArgs.Empty"/>).</param>
- public static void SafelyRaisePlainEvent(this IMonitor monitor, string name, IEnumerable<Delegate> handlers, object sender = null, EventArgs args = null)
- {
- if (handlers == null)
- return;
-
- foreach (EventHandler handler in handlers.Cast<EventHandler>())
- {
- // handle SMAPI exiting
- if (monitor.IsExiting)
- {
- monitor.Log($"SMAPI shutting down: aborting {name} event.", LogLevel.Warn);
- return;
- }
-
- // raise event
- try
- {
- handler.Invoke(sender, args ?? EventArgs.Empty);
- }
- catch (Exception ex)
- {
- monitor.Log($"A mod failed handling the {name} event:\n{ex.GetLogSummary()}", LogLevel.Error);
- }
- }
- }
-
- /// <summary>Safely raise an <see cref="EventHandler{TEventArgs}"/> event, and intercept any exceptions thrown by its handlers.</summary>
- /// <typeparam name="TEventArgs">The event argument object type.</typeparam>
- /// <param name="monitor">Encapsulates monitoring and logging.</param>
- /// <param name="name">The event name for error messages.</param>
- /// <param name="handlers">The event handlers.</param>
- /// <param name="sender">The event sender.</param>
- /// <param name="args">The event arguments.</param>
- public static void SafelyRaiseGenericEvent<TEventArgs>(this IMonitor monitor, string name, IEnumerable<Delegate> handlers, object sender, TEventArgs args)
- {
- if (handlers == null)
- return;
-
- foreach (EventHandler<TEventArgs> handler in handlers.Cast<EventHandler<TEventArgs>>())
- {
- try
- {
- handler.Invoke(sender, args);
- }
- catch (Exception ex)
- {
- monitor.Log($"A mod failed handling the {name} event:\n{ex.GetLogSummary()}", LogLevel.Error);
- }
- }
- }
-
/// <summary>Log a message for the player or developer the first time it occurs.</summary>
/// <param name="monitor">The monitor through which to log the message.</param>
/// <param name="hash">The hash of logged messages.</param>