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