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