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