コード例 #1
0
        /// <summary>
        /// Calls a PathfinderEvent.
        /// </summary>
        /// <param name="pathfinderEvent">The PathfinderEvent to call.</param>
        public static Dictionary <string, Exception> CallEvent(PathfinderEvent pathfinderEvent)
        {
            var exceptionDict = new Dictionary <string, Exception>();

            if (pathfinderEvent.PreventCall)
            {
                return(exceptionDict);
            }
            var eventType = pathfinderEvent.GetType();
            var log       = !Logger.IgnoreEventTypes.Contains(eventType);

            if (log)
            {
                Logger.Verbose("Event Type contains check '[{0}] {1}'", Path.GetFileName(eventType.Assembly.Location), eventType.FullName);
            }
            if (eventListeners.ContainsKey(eventType))
            {
                if (log)
                {
                    Logger.Verbose("Attempting Event call '[{0}] {1}'", Path.GetFileName(eventType.Assembly.Location), eventType.FullName);
                }
                var cancelled = false;
                var thrown    = false;
                foreach (var listener in eventListeners[eventType])
                {
                    if (cancelled && listener.Options.ContinueOnCancel)
                    {
                        continue;
                    }
                    if (thrown && listener.Options.ContinueOnThrow)
                    {
                        continue;
                    }
                    try
                    {
                        if (log)
                        {
                            Logger.Verbose("Attempting Event Listener call '{0}'", listener.Options.DebugName);
                        }
                        Manager.CurrentMod = Manager.GetLoadedMod(listener.ModId);
                        listener.Func(null, pathfinderEvent);
                        Manager.CurrentMod = null;
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Event Listener Call Failed");
                        Logger.Error("Exception: {0}", ex);
                        exceptionDict[listener.Options.DebugName] = ex;
                        thrown = true;
                    }
                    cancelled |= pathfinderEvent.IsCancelled;
                }
            }
            return(exceptionDict);
        }
コード例 #2
0
        public static void CallEvent(PathfinderEvent pathfinderEvent)
        {
            Type eventType = pathfinderEvent.GetType();

            if (eventListeners.ContainsKey(eventType))
            {
                foreach (Action <PathfinderEvent> listener in eventListeners[eventType])
                {
                    listener(pathfinderEvent);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Calls a PathfinderEvent.
        /// </summary>
        /// <param name="pathfinderEvent">The PathfinderEvent to call.</param>
        public static void CallEvent(PathfinderEvent pathfinderEvent)
        {
            var eventType = pathfinderEvent.GetType();
            var log       = !Logger.IgnoreEventTypes.Contains(eventType);

            if (log)
            {
                Logger.Verbose("Event Type contains check '[{0}] {1}'", Path.GetFileName(eventType.Assembly.Location), eventType.FullName);
            }
            if (eventListeners.ContainsKey(eventType))
            {
                if (log)
                {
                    Logger.Verbose("Attempting Event call '[{0}] {1}'", Path.GetFileName(eventType.Assembly.Location), eventType.FullName);
                }
                foreach (var listener in eventListeners[eventType])
                {
                    try
                    {
                        if (log)
                        {
                            Logger.Verbose("Attempting Event Listener call '{0}'", listener.Item2);
                        }
                        Manager.CurrentMod = Manager.GetLoadedMod(listener.Item3);
                        listener.Item1(pathfinderEvent);
                        Manager.CurrentMod = null;
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Event Listener Call Failed");
                        Logger.Error("Exception: {0}", ex);
                    }
                    if (pathfinderEvent.IsCancelled)
                    {
                        break;
                    }
                }
            }
        }