Server/Actions/ActionDisplayMessage.cs
author StephaneLenclud
Wed, 31 Aug 2016 17:28:30 +0200
changeset 264 4a08e1b7ba64
parent 260 d44943088c67
permissions -rw-r--r--
EAR: Actions now support multiple iterations.
StephaneLenclud@236
     1
using Ear = SharpLib.Ear;
StephaneLenclud@236
     2
using SharpLib.Ear;
StephaneLenclud@225
     3
using System;
StephaneLenclud@225
     4
using System.Collections.Generic;
StephaneLenclud@225
     5
using System.Drawing;
StephaneLenclud@225
     6
using System.Linq;
StephaneLenclud@225
     7
using System.Runtime.Serialization;
StephaneLenclud@225
     8
using System.Text;
StephaneLenclud@225
     9
using System.Threading;
StephaneLenclud@225
    10
using System.Threading.Tasks;
StephaneLenclud@225
    11
StephaneLenclud@225
    12
namespace SharpDisplayManager
StephaneLenclud@225
    13
{
StephaneLenclud@225
    14
StephaneLenclud@225
    15
StephaneLenclud@225
    16
    [DataContract]
StephaneLenclud@231
    17
    [AttributeObject(Id = "Display.Message", Name = "Display Message", Description = "Shows a message on your internal display.")]
StephaneLenclud@236
    18
    class ActionDisplayMessage : Ear.Action
StephaneLenclud@225
    19
    {
StephaneLenclud@225
    20
        [DataMember]
StephaneLenclud@231
    21
        [AttributeObjectProperty(
StephaneLenclud@225
    22
            Id = "Display.Message.Duration",
StephaneLenclud@225
    23
            Name = "Duration (ms)",
StephaneLenclud@225
    24
            Description = "Specifies the number of milliseconds this message should be displayed.",
StephaneLenclud@225
    25
            Minimum = "1", //Otherwise time throws an exception
StephaneLenclud@225
    26
            Maximum = "30000",
StephaneLenclud@225
    27
            Increment = "1000"
StephaneLenclud@225
    28
            )]
StephaneLenclud@225
    29
        public int DurationInMilliseconds { get; set; } = 5000;
StephaneLenclud@225
    30
StephaneLenclud@225
    31
StephaneLenclud@225
    32
        [DataMember]
StephaneLenclud@231
    33
        [AttributeObjectProperty(
StephaneLenclud@225
    34
            Id = "Display.Message.PrimaryText",
StephaneLenclud@225
    35
            Name = "Primary Text",
StephaneLenclud@225
    36
            Description = "The primary text of this message."
StephaneLenclud@225
    37
            )]
StephaneLenclud@225
    38
        public string PrimaryText { get; set; } = "Your message";
StephaneLenclud@225
    39
StephaneLenclud@225
    40
        [DataMember]
StephaneLenclud@231
    41
        [AttributeObjectProperty(
StephaneLenclud@225
    42
            Id = "Display.Message.SecondaryText",
StephaneLenclud@225
    43
            Name = "Secondary Text",
StephaneLenclud@225
    44
            Description = "The secondary text of this message."
StephaneLenclud@225
    45
            )]
StephaneLenclud@225
    46
        public string SecondaryText { get; set; } = "";
StephaneLenclud@225
    47
StephaneLenclud@225
    48
StephaneLenclud@225
    49
        /// <summary>
StephaneLenclud@225
    50
        /// 
StephaneLenclud@225
    51
        /// </summary>
StephaneLenclud@225
    52
        /// <returns></returns>
StephaneLenclud@264
    53
        public override string BriefBase()
StephaneLenclud@225
    54
        {
StephaneLenclud@260
    55
            string brief = AttributeName + ": " + PrimaryText;
StephaneLenclud@225
    56
            if (!string.IsNullOrEmpty(SecondaryText))
StephaneLenclud@225
    57
            {
StephaneLenclud@225
    58
                brief += " - " + SecondaryText;
StephaneLenclud@225
    59
            }
StephaneLenclud@225
    60
StephaneLenclud@225
    61
            brief += " ( " + DurationInMilliseconds.ToString() + " ms )";
StephaneLenclud@225
    62
StephaneLenclud@225
    63
            return brief;
StephaneLenclud@225
    64
        }
StephaneLenclud@225
    65
StephaneLenclud@225
    66
        /// <summary>
StephaneLenclud@225
    67
        /// 
StephaneLenclud@225
    68
        /// </summary>
StephaneLenclud@258
    69
        protected override async Task DoExecute()
StephaneLenclud@225
    70
        {
StephaneLenclud@225
    71
            StartMessageClient();
StephaneLenclud@225
    72
        }
StephaneLenclud@225
    73
StephaneLenclud@225
    74
        /// <summary>
StephaneLenclud@225
    75
        /// Just launch our idle client.
StephaneLenclud@225
    76
        /// </summary>
StephaneLenclud@225
    77
        private void StartMessageClient()
StephaneLenclud@225
    78
        {
StephaneLenclud@225
    79
            Thread clientThread = new Thread(SharpDisplayClientMessage.Program.MainWithParams);
StephaneLenclud@225
    80
            SharpDisplayClientMessage.StartParams myParams =
StephaneLenclud@225
    81
                new SharpDisplayClientMessage.StartParams(PrimaryText, SecondaryText, DurationInMilliseconds);
StephaneLenclud@225
    82
            clientThread.Start(myParams);
StephaneLenclud@225
    83
        }
StephaneLenclud@225
    84
StephaneLenclud@225
    85
StephaneLenclud@225
    86
    }
StephaneLenclud@225
    87
StephaneLenclud@225
    88
}