Published v0.10.2.0.
5 using System.Collections.Generic;
6 using System.ComponentModel;
8 using System.Reflection;
9 using System.Runtime.Serialization;
12 namespace SharpLib.Ear
14 [TypeConverter(typeof(TypeConverterJson<ManagerEventAction>))]
16 public class ManagerEventAction
18 public static ManagerEventAction Current = null;
19 public IDictionary<string, Type> ActionTypes;
20 public IDictionary<string, Event> Events;
22 public Dictionary<string, List<Action>> ActionsByEvents = new Dictionary<string, List<Action>>();
25 public ManagerEventAction()
35 //Create our list of supported actions
36 ActionTypes = Utils.Reflection.GetConcreteClassesDerivedFromByName<Action>();
37 //Create our list or support events
38 Events = Utils.Reflection.GetConcreteClassesInstanceDerivedFromByName<Event>();
40 if (ActionsByEvents == null)
42 ActionsByEvents = new Dictionary<string, List<Action>>();
45 //Hook in loaded actions with corresponding events
46 foreach (string key in Events.Keys)
48 Event e = Events[key];
49 if (ActionsByEvents.ContainsKey(key))
51 //We have actions for that event, hook them in then
52 e.Actions = ActionsByEvents[key];
56 //We do not have actions for that event yet, create empty action list
57 e.Actions = new List<Action>();
58 ActionsByEvents[key] = e.Actions;
64 /// Get and event instance from its type.
66 /// <typeparam name="T"></typeparam>
67 /// <returns></returns>
68 public Event GetEvent<T>() where T : class
70 return Events[typeof(T).Name];
76 /// <param name="aAction"></param>
77 public void RemoveAction(Action aAction)
79 foreach (string key in Events.Keys)
81 Event e = Events[key];
82 if (e.Actions.Remove(aAction))
84 //We removed our action, we are done here.