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