SharpLibEar/Action.cs
author StephaneLenclud
Sun, 21 Aug 2016 19:31:08 +0200
changeset 251 f60cfcb98c9a
parent 238 c92587ddabcd
child 253 2dae7a163fff
permissions -rw-r--r--
Published v0.12.2.0
Adding setting for Logitech user name.
Improved event tree view update following Harmony connection.
Removed unneeded editable fields from Harmony command action.
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]
StephaneLenclud@238
    12
    public abstract class Action: Object
StephaneLenclud@210
    13
    {
StephaneLenclud@228
    14
        protected abstract void DoExecute();
StephaneLenclud@223
    15
StephaneLenclud@231
    16
        /// <summary>
StephaneLenclud@231
    17
        /// Allows testing from generic edit dialog.
StephaneLenclud@231
    18
        /// </summary>
StephaneLenclud@231
    19
        public void Test()
StephaneLenclud@231
    20
        {
StephaneLenclud@231
    21
            Console.WriteLine("Action test");
StephaneLenclud@231
    22
            Execute();
StephaneLenclud@231
    23
        }
StephaneLenclud@231
    24
StephaneLenclud@223
    25
        public void Execute()
StephaneLenclud@223
    26
        {
StephaneLenclud@229
    27
            Console.WriteLine("Action executing: " + Brief());
StephaneLenclud@239
    28
            if (!IsValid())
StephaneLenclud@239
    29
            {
StephaneLenclud@239
    30
                Console.WriteLine($"WARNING: action invalid, aborting execution.");
StephaneLenclud@239
    31
                return;
StephaneLenclud@239
    32
            }
StephaneLenclud@239
    33
            
StephaneLenclud@223
    34
            DoExecute();
StephaneLenclud@223
    35
        }
StephaneLenclud@210
    36
StephaneLenclud@210
    37
    }
StephaneLenclud@210
    38
StephaneLenclud@210
    39
StephaneLenclud@210
    40
}