Server/Actions/ActionDisplayMessage.cs
author StephaneLenclud
Fri, 12 Aug 2016 20:25:05 +0200
changeset 231 4c706feaf706
parent 228 6a84d8282226
child 236 6ba20e02d04f
permissions -rw-r--r--
Events can now be instantiated.
Action editor is now a generic object editor.
     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     [AttributeObject(Id = "Display.Message", Name = "Display Message", Description = "Shows a message on your internal display.")]
    17     class ActionDisplayMessage : SharpLib.Ear.Action
    18     {
    19         [DataMember]
    20         [AttributeObjectProperty(
    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         [AttributeObjectProperty(
    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         [AttributeObjectProperty(
    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 }