SharpLibEar/ActionSleep.cs
author StephaneLenclud
Wed, 31 Aug 2016 17:28:30 +0200
changeset 264 4a08e1b7ba64
parent 263 3ab73a2a72d8
permissions -rw-r--r--
EAR: Actions now support multiple iterations.
StephaneLenclud@210
     1
//
StephaneLenclud@210
     2
StephaneLenclud@210
     3
StephaneLenclud@210
     4
using System.Runtime.Serialization;
StephaneLenclud@210
     5
using System.Threading;
StephaneLenclud@258
     6
using System.Threading.Tasks;
StephaneLenclud@210
     7
StephaneLenclud@210
     8
namespace SharpLib.Ear
StephaneLenclud@210
     9
{
StephaneLenclud@210
    10
    
StephaneLenclud@210
    11
StephaneLenclud@210
    12
    [DataContract]
StephaneLenclud@231
    13
    [AttributeObject(Id = "Thread.Sleep", Name = "Sleep", Description = "Have the current thread sleep for the specified amount of milliseconds.")]
StephaneLenclud@210
    14
    public class ActionSleep : Action
StephaneLenclud@210
    15
    {
Stephane@212
    16
        [DataMember]
StephaneLenclud@231
    17
        [AttributeObjectProperty
StephaneLenclud@220
    18
            (
StephaneLenclud@220
    19
                Id = "Thread.Sleep.Timeout",
StephaneLenclud@220
    20
                Name = "Timeout (ms)",
StephaneLenclud@220
    21
                Description = "Specifies the number of milliseconds this action will sleep for.",
StephaneLenclud@220
    22
                Minimum = "0",
StephaneLenclud@263
    23
                Maximum = "60000",
StephaneLenclud@263
    24
                Increment =  "1000"
StephaneLenclud@220
    25
            )
StephaneLenclud@220
    26
        ]
StephaneLenclud@219
    27
        public int TimeoutInMilliseconds { get; set; }
StephaneLenclud@210
    28
StephaneLenclud@210
    29
        public ActionSleep()
StephaneLenclud@210
    30
        {
StephaneLenclud@219
    31
            TimeoutInMilliseconds = 1000;
StephaneLenclud@210
    32
        }
StephaneLenclud@210
    33
StephaneLenclud@210
    34
StephaneLenclud@210
    35
        public ActionSleep(int aMillisecondsTimeout)
StephaneLenclud@210
    36
        {
StephaneLenclud@219
    37
            TimeoutInMilliseconds = aMillisecondsTimeout;
StephaneLenclud@210
    38
        }
StephaneLenclud@210
    39
StephaneLenclud@264
    40
        public override string BriefBase()
StephaneLenclud@220
    41
        {
StephaneLenclud@260
    42
            return AttributeName + " for " + TimeoutInMilliseconds + " ms";
StephaneLenclud@220
    43
        }
StephaneLenclud@220
    44
StephaneLenclud@220
    45
StephaneLenclud@258
    46
        protected override async Task DoExecute()
StephaneLenclud@210
    47
        {
StephaneLenclud@258
    48
            await Task.Delay(TimeoutInMilliseconds);
StephaneLenclud@210
    49
        }
StephaneLenclud@210
    50
StephaneLenclud@210
    51
    }
StephaneLenclud@210
    52
StephaneLenclud@210
    53
StephaneLenclud@210
    54
StephaneLenclud@210
    55
}