StephaneLenclud@210: // StephaneLenclud@210: StephaneLenclud@210: StephaneLenclud@210: using System; StephaneLenclud@210: using System.Collections.Generic; StephaneLenclud@210: using System.Runtime.Serialization; StephaneLenclud@210: StephaneLenclud@210: namespace SharpLib.Ear StephaneLenclud@210: { StephaneLenclud@210: [DataContract] StephaneLenclud@231: [KnownType("DerivedTypes")] StephaneLenclud@231: public abstract class Event StephaneLenclud@210: { StephaneLenclud@231: [DataMember] StephaneLenclud@231: [AttributeObjectProperty StephaneLenclud@231: ( StephaneLenclud@231: Id = "Event.Enabled", StephaneLenclud@231: Name = "Enabled", StephaneLenclud@231: Description = "When enabled an event instance can be triggered." StephaneLenclud@231: ) StephaneLenclud@231: ] StephaneLenclud@231: public bool Enabled { get; set; } StephaneLenclud@210: Stephane@212: [DataMember] Stephane@212: public List Actions = new List(); StephaneLenclud@210: StephaneLenclud@231: public string Name StephaneLenclud@231: { StephaneLenclud@231: //Get the name of this object attribute StephaneLenclud@231: get { return Utils.Reflection.GetAttribute(GetType()).Name; } StephaneLenclud@231: private set { } StephaneLenclud@231: } StephaneLenclud@231: StephaneLenclud@231: public string Description StephaneLenclud@231: { StephaneLenclud@231: //Get the description of this object attribute StephaneLenclud@231: get { return Utils.Reflection.GetAttribute(GetType()).Description; } StephaneLenclud@231: private set { } StephaneLenclud@231: } StephaneLenclud@231: StephaneLenclud@231: StephaneLenclud@210: protected Event() StephaneLenclud@210: { StephaneLenclud@231: Enabled = true; StephaneLenclud@210: } StephaneLenclud@210: StephaneLenclud@231: StephaneLenclud@231: /// StephaneLenclud@231: /// Allows testing from generic edit dialog. StephaneLenclud@231: /// StephaneLenclud@231: public void Test() StephaneLenclud@231: { StephaneLenclud@231: Console.WriteLine("Event test"); StephaneLenclud@231: Trigger(); StephaneLenclud@231: } StephaneLenclud@231: StephaneLenclud@231: StephaneLenclud@231: public void Trigger() StephaneLenclud@210: { StephaneLenclud@229: Console.WriteLine("Event triggered: " + Name); StephaneLenclud@210: foreach (Action action in Actions) StephaneLenclud@210: { StephaneLenclud@210: action.Execute(); StephaneLenclud@210: } StephaneLenclud@210: } StephaneLenclud@231: StephaneLenclud@231: /// StephaneLenclud@231: /// So that data contract knows all our types. StephaneLenclud@231: /// StephaneLenclud@231: /// StephaneLenclud@231: private static IEnumerable DerivedTypes() StephaneLenclud@231: { StephaneLenclud@231: return SharpLib.Utils.Reflection.GetDerivedTypes(); StephaneLenclud@231: } StephaneLenclud@231: }; StephaneLenclud@210: StephaneLenclud@210: }