SharpLibEar/ActionDelay.cs
author StephaneLenclud
Wed, 31 Aug 2016 17:28:30 +0200
changeset 264 4a08e1b7ba64
parent 263 3ab73a2a72d8
child 265 82e87f4956ea
permissions -rw-r--r--
EAR: Actions now support multiple iterations.
StephaneLenclud@263
     1
//
StephaneLenclud@263
     2
StephaneLenclud@263
     3
StephaneLenclud@263
     4
using System.Runtime.Serialization;
StephaneLenclud@263
     5
using System.Threading;
StephaneLenclud@263
     6
using System.Threading.Tasks;
StephaneLenclud@263
     7
StephaneLenclud@263
     8
namespace SharpLib.Ear
StephaneLenclud@263
     9
{
StephaneLenclud@263
    10
    [DataContract]
StephaneLenclud@263
    11
    [AttributeObject(Id = "Task.Delay", Name = "Delay", Description = "Delay the execution of the next task by the specified amount of milliseconds.")]
StephaneLenclud@263
    12
    public class ActionDelay : Action
StephaneLenclud@263
    13
    {
StephaneLenclud@263
    14
        [DataMember]
StephaneLenclud@263
    15
        [AttributeObjectProperty
StephaneLenclud@263
    16
            (
StephaneLenclud@263
    17
                Id = "Task.Delay.Milliseconds",
StephaneLenclud@263
    18
                Name = "Delay (ms)",
StephaneLenclud@263
    19
                Description = "Specifies our delay in milliseconds.",
StephaneLenclud@263
    20
                Minimum = "0",
StephaneLenclud@263
    21
                Maximum = "60000",
StephaneLenclud@263
    22
                Increment = "1000"
StephaneLenclud@263
    23
            )
StephaneLenclud@263
    24
        ]
StephaneLenclud@263
    25
        public int Milliseconds { get; set; }
StephaneLenclud@263
    26
StephaneLenclud@263
    27
        public ActionDelay()
StephaneLenclud@263
    28
        {
StephaneLenclud@263
    29
            Milliseconds = 1000;
StephaneLenclud@263
    30
        }
StephaneLenclud@263
    31
StephaneLenclud@263
    32
StephaneLenclud@263
    33
        public ActionDelay(int aMillisecondsTimeout)
StephaneLenclud@263
    34
        {
StephaneLenclud@263
    35
            Milliseconds = aMillisecondsTimeout;
StephaneLenclud@263
    36
        }
StephaneLenclud@263
    37
StephaneLenclud@264
    38
        public override string BriefBase()
StephaneLenclud@263
    39
        {
StephaneLenclud@263
    40
            return AttributeName + " for " + Milliseconds/1000.0 + " seconds";
StephaneLenclud@263
    41
        }
StephaneLenclud@263
    42
StephaneLenclud@263
    43
StephaneLenclud@263
    44
        protected override async Task DoExecute()
StephaneLenclud@263
    45
        {
StephaneLenclud@263
    46
            await Task.Delay(Milliseconds);
StephaneLenclud@263
    47
        }
StephaneLenclud@263
    48
StephaneLenclud@263
    49
    }
StephaneLenclud@263
    50
StephaneLenclud@263
    51
StephaneLenclud@263
    52
StephaneLenclud@263
    53
}