Stephane@212: // Stephane@212: Stephane@212: Stephane@212: using System; Stephane@212: using System.Collections.Generic; Stephane@212: using System.ComponentModel; Stephane@212: using System.Linq; Stephane@212: using System.Reflection; Stephane@212: using System.Runtime.Serialization; Stephane@212: using SharpLib.Utils; Stephane@212: Stephane@212: namespace SharpLib.Ear Stephane@212: { Stephane@212: [TypeConverter(typeof(TypeConverterJson))] Stephane@212: [DataContract] Stephane@212: public class ManagerEventAction Stephane@212: { Stephane@212: public static ManagerEventAction Current = null; StephaneLenclud@231: //public IDictionary ActionTypes; StephaneLenclud@231: //public IDictionary EventTypes; StephaneLenclud@231: StephaneLenclud@231: /// StephaneLenclud@231: /// Our events instances. StephaneLenclud@231: /// Stephane@212: [DataMember] StephaneLenclud@231: public List Events; StephaneLenclud@231: StephaneLenclud@231: Stephane@212: Stephane@212: Stephane@212: public ManagerEventAction() Stephane@212: { Stephane@212: Init(); Stephane@212: } Stephane@212: Stephane@212: /// StephaneLenclud@231: /// Executes after internalization took place. Stephane@212: /// Stephane@212: public void Init() Stephane@212: { StephaneLenclud@231: if (Events == null) StephaneLenclud@231: { StephaneLenclud@231: Events = new List(); StephaneLenclud@231: } StephaneLenclud@231: StephaneLenclud@231: } Stephane@212: StephaneLenclud@231: /// StephaneLenclud@231: /// StephaneLenclud@231: /// StephaneLenclud@231: /// StephaneLenclud@231: public void TriggerEvent() where T: class StephaneLenclud@231: { StephaneLenclud@231: //Only trigger enabled events matching the desired type StephaneLenclud@231: foreach (Event e in Events.Where(e => e.GetType() == typeof(T) && e.Enabled)) Stephane@212: { StephaneLenclud@231: e.Trigger(); Stephane@212: } Stephane@212: } Stephane@212: Stephane@212: StephaneLenclud@214: /// StephaneLenclud@214: /// StephaneLenclud@214: /// StephaneLenclud@214: /// StephaneLenclud@214: public void RemoveAction(Action aAction) StephaneLenclud@214: { StephaneLenclud@231: foreach (Event e in Events) StephaneLenclud@214: { StephaneLenclud@214: if (e.Actions.Remove(aAction)) StephaneLenclud@214: { StephaneLenclud@214: //We removed our action, we are done here. StephaneLenclud@214: return; StephaneLenclud@214: } StephaneLenclud@214: } StephaneLenclud@214: } Stephane@212: } Stephane@212: }