using System; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; using PepperDash.Core; using PepperDash.Essentials.Core.DeviceTypeInterfaces; namespace PepperDash.Essentials.AppServer.Messengers { /// /// Represents a IProjectorScreenLiftControlMessenger /// public class IProjectorScreenLiftControlMessenger : MessengerBase { private readonly IProjectorScreenLiftControl device; /// /// Initializes a new instance of the class. /// /// message key /// message path /// screen lift device public IProjectorScreenLiftControlMessenger(string key, string messagePath, IProjectorScreenLiftControl screenLiftDevice) : base(key, messagePath, screenLiftDevice as IKeyName) { device = screenLiftDevice; } /// /// Registers the actions for the messenger. /// protected override void RegisterActions() { base.RegisterActions(); AddAction("/fullStatus", (id, content) => SendFullStatus(id)); AddAction("/screenliftStatus", (id, content) => SendFullStatus(id)); AddAction("/raise", (id, content) => { device.Raise(); }); AddAction("/lower", (id, content) => { device.Lower(); }); device.PositionChanged += Device_PositionChanged; } private void Device_PositionChanged(object sender, EventArgs e) { var state = new { inUpPosition = device.InUpPosition }; PostStatusMessage(JToken.FromObject(state)); } private void SendFullStatus(string id = null) { var state = new ScreenLiftStateMessage { InUpPosition = device.InUpPosition, Type = device.Type, DisplayDeviceKey = device.DisplayDeviceKey }; PostStatusMessage(state, id); } } /// /// Represents a ScreenLiftStateMessage /// public class ScreenLiftStateMessage : DeviceStateMessageBase { /// /// Gets or sets the InUpPosition /// [JsonProperty("inUpPosition", NullValueHandling = NullValueHandling.Ignore)] public bool? InUpPosition { get; set; } /// /// Gets or sets the DisplayDeviceKey /// [JsonProperty("displayDeviceKey", NullValueHandling = NullValueHandling.Ignore)] public string DisplayDeviceKey { get; set; } /// /// Gets or sets the Type /// [JsonConverter(typeof(StringEnumConverter))] [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)] public eScreenLiftControlType Type { get; set; } } }