SharpLibEar/Event.cs
author StephaneLenclud
Thu, 25 Aug 2016 13:34:05 +0200
changeset 255 c57b8ac80fc6
parent 243 cc2251d065db
child 258 e237c2e33545
permissions -rw-r--r--
Published v1.0.2.0.
Fixed Harmony async issue prevent the config to be fetched.
     1 //
     2 
     3 
     4 using System;
     5 using System.Collections.Generic;
     6 using System.Diagnostics;
     7 using System.Runtime.Serialization;
     8 
     9 namespace SharpLib.Ear
    10 {
    11     [DataContract]
    12     public abstract class Event : Object
    13     {
    14         [DataMember]
    15         [AttributeObjectProperty
    16             (
    17                 Id = "Event.Enabled",
    18                 Name = "Enabled",
    19                 Description = "When enabled an event instance can be triggered."
    20             )
    21         ]
    22         public bool Enabled { get; set; } = true;
    23 
    24         [DataMember]
    25         public List<Action> Actions = new List<Action>();
    26 
    27 
    28         protected override void DoConstruct()
    29         {
    30             base.DoConstruct();
    31 
    32             // TODO: Construct properties too
    33             foreach (Action a in Actions)
    34             {
    35                 a.Construct();
    36             }
    37 
    38         }
    39 
    40 
    41         /// <summary>
    42         /// Allows testing from generic edit dialog.
    43         /// </summary>
    44         public void Test()
    45         {
    46             Trace.WriteLine("Event test");
    47             Trigger();
    48         }
    49 
    50 
    51         public void Trigger()
    52         {
    53             Trace.WriteLine("Event triggered: " + Name);
    54             foreach (Action action in Actions)
    55             {
    56                 action.Execute();
    57             }
    58         }
    59 
    60         //
    61         public override bool Equals(object obj)
    62         {
    63             //Default implementation assumes event are the same if types are the same
    64             bool res=  obj.GetType() == GetType();
    65             return res;
    66         }
    67     };
    68 
    69 }