SharpLibEar/Action.cs
author StephaneLenclud
Thu, 28 Jul 2016 19:32:40 +0200
changeset 225 6ccaa430aa23
parent 220 e5910d7b6a81
child 228 6a84d8282226
permissions -rw-r--r--
Adding support for Display Messages.
StephaneLenclud@210
     1
//
StephaneLenclud@210
     2
StephaneLenclud@210
     3
StephaneLenclud@210
     4
using System;
Stephane@212
     5
using System.Collections.Generic;
StephaneLenclud@210
     6
using System.Runtime.Serialization;
StephaneLenclud@210
     7
using System.Threading;
StephaneLenclud@210
     8
StephaneLenclud@210
     9
namespace SharpLib.Ear
StephaneLenclud@210
    10
{
StephaneLenclud@210
    11
    [DataContract]
Stephane@212
    12
    [KnownType("DerivedTypes")]
StephaneLenclud@210
    13
    public abstract class Action: IComparable
StephaneLenclud@210
    14
    {
StephaneLenclud@223
    15
        public abstract void DoExecute();
StephaneLenclud@223
    16
StephaneLenclud@223
    17
        public void Execute()
StephaneLenclud@223
    18
        {
StephaneLenclud@223
    19
            Console.WriteLine("Executing action: " + Brief());
StephaneLenclud@223
    20
            DoExecute();
StephaneLenclud@223
    21
        }
StephaneLenclud@210
    22
StephaneLenclud@211
    23
        public string Name {
StephaneLenclud@211
    24
            //Get the name of this object action attribute
StephaneLenclud@211
    25
            get { return Utils.Reflection.GetAttribute<AttributeAction>(GetType()).Name; }
StephaneLenclud@211
    26
            private set { }
StephaneLenclud@211
    27
        }
StephaneLenclud@211
    28
StephaneLenclud@220
    29
        public virtual string Brief()
StephaneLenclud@220
    30
        {
StephaneLenclud@220
    31
            return Name;
StephaneLenclud@220
    32
        }
StephaneLenclud@220
    33
StephaneLenclud@210
    34
        public int CompareTo(object obj)
StephaneLenclud@210
    35
        {
StephaneLenclud@210
    36
            //Sort by action name
StephaneLenclud@210
    37
            return Utils.Reflection.GetAttribute<AttributeAction>(GetType()).Name.CompareTo(obj.GetType());            
StephaneLenclud@210
    38
        }
Stephane@212
    39
Stephane@212
    40
        private static IEnumerable<Type> DerivedTypes()
Stephane@212
    41
        {
Stephane@212
    42
            return SharpLib.Utils.Reflection.GetDerivedTypes<Action>();
Stephane@212
    43
        }
Stephane@212
    44
StephaneLenclud@210
    45
    }
StephaneLenclud@210
    46
StephaneLenclud@210
    47
StephaneLenclud@210
    48
}