From 5a097e70573dac5662a23494a1233210bc40bec5 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 2 Nov 2023 23:31:15 -0600 Subject: [PATCH 01/31] feat: updates for web debugging --- .../PepperDash.Essentials.Core.csproj | 7 +- .../Plugins/PluginLoader.cs | 5 - ...ssemtialsWebApi.cs => EssentialsWebApi.cs} | 170 +++++++++--------- .../Web/EssentialsWebApiFactory.cs | 4 +- .../DevMethodsRequestHandler.cs | 76 ++++++++ .../RequestHandlers/DevPropsRequestHandler.cs | 94 +++++----- .../GetTypesByFilterRequestHandler.cs | 2 +- .../RequestHandlers/GetTypesRequestHandler.cs | 2 +- .../ReportVersionsRequestHandler.cs | 2 +- .../ShowConfigRequestHandler.cs | 2 +- ...epperDash.Essentials.Devices.Common.csproj | 2 +- src/PepperDash.Essentials/ControlSystem.cs | 74 +++----- .../PepperDash.Essentials.csproj | 3 +- 13 files changed, 240 insertions(+), 203 deletions(-) rename src/PepperDash.Essentials.Core/Web/{EssemtialsWebApi.cs => EssentialsWebApi.cs} (54%) create mode 100644 src/PepperDash.Essentials.Core/Web/RequestHandlers/DevMethodsRequestHandler.cs diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index db87a84d..7e9b53c8 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -16,11 +16,6 @@ pdbonly - - - - - @@ -31,7 +26,7 @@ Full - + diff --git a/src/PepperDash.Essentials.Core/Plugins/PluginLoader.cs b/src/PepperDash.Essentials.Core/Plugins/PluginLoader.cs index dcc492df..edfd65ef 100644 --- a/src/PepperDash.Essentials.Core/Plugins/PluginLoader.cs +++ b/src/PepperDash.Essentials.Core/Plugins/PluginLoader.cs @@ -75,11 +75,6 @@ namespace PepperDash.Essentials version = Global.AssemblyVersion; break; } - case ("PepperDash_Essentials_DM.dll"): - { - version = Global.AssemblyVersion; - break; - } case ("Essentials Devices Common.dll"): { version = Global.AssemblyVersion; diff --git a/src/PepperDash.Essentials.Core/Web/EssemtialsWebApi.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs similarity index 54% rename from src/PepperDash.Essentials.Core/Web/EssemtialsWebApi.cs rename to src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs index eb012378..35adbfe9 100644 --- a/src/PepperDash.Essentials.Core/Web/EssemtialsWebApi.cs +++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs @@ -9,7 +9,7 @@ using PepperDash.Essentials.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web { - public class EssemtialsWebApi : EssentialsDevice + public class EssentialsWebApi : EssentialsDevice { private readonly WebApiServer _server; @@ -43,7 +43,7 @@ namespace PepperDash.Essentials.Core.Web /// /// /// - public EssemtialsWebApi(string key, string name) + public EssentialsWebApi(string key, string name) : this(key, name, null) { } @@ -54,7 +54,7 @@ namespace PepperDash.Essentials.Core.Web /// /// /// - public EssemtialsWebApi(string key, string name, EssentialsWebApiPropertiesConfig config) + public EssentialsWebApi(string key, string name, EssentialsWebApiPropertiesConfig config) : base(key, name) { Key = key; @@ -65,91 +65,95 @@ namespace PepperDash.Essentials.Core.Web BasePath = string.IsNullOrEmpty(config.BasePath) ? _defaultBasePath : config.BasePath; _server = new WebApiServer(Key, Name, BasePath); + + SetupRoutes(); + + Initialize(); } - /// - /// Custom activate, add routes - /// - /// - public override bool CustomActivate() + private void SetupRoutes() { - var routes = new List - { - new HttpCwsRoute("reportversions") - { - Name = "ReportVersions", - RouteHandler = new ReportVersionsRequestHandler() - }, - new HttpCwsRoute("appdebug") - { - Name = "AppDebug", - RouteHandler = new AppDebugRequestHandler() - }, - new HttpCwsRoute("devlist") - { - Name = "DevList", - RouteHandler = new DevListRequestHandler() - }, - new HttpCwsRoute("devprops") - { - Name = "DevProps", - RouteHandler = new DevPropsRequestHandler() - }, - new HttpCwsRoute("devjson") - { - Name = "DevJson", - RouteHandler = new DevJsonRequestHandler() - }, - new HttpCwsRoute("setdevicestreamdebug") - { - Name = "SetDeviceStreamDebug", - RouteHandler = new SetDeviceStreamDebugRequestHandler() - }, - new HttpCwsRoute("disableallstreamdebug") - { - Name = "DisableAllStreamDebug", - RouteHandler = new DisableAllStreamDebugRequestHandler() - }, - new HttpCwsRoute("showconfig") - { - Name = "ShowConfig", - RouteHandler = new ShowConfigRequestHandler() - }, - new HttpCwsRoute("gettypes") - { - Name = "GetTypes", - RouteHandler = new GetTypesRequestHandler() - }, - new HttpCwsRoute("gettypes/{filter}") - { - Name = "GetTypesByFilter", - RouteHandler = new GetTypesByFilterRequestHandler() - }, - new HttpCwsRoute("getjoinmap/{bridgeKey}") - { - Name = "GetJoinMapsForBridgeKey", - RouteHandler = new GetJoinMapForBridgeKeyRequestHandler() - }, - new HttpCwsRoute("getjoinmap/{bridgeKey}/{deviceKey}") - { - Name = "GetJoinMapsForDeviceKey", - RouteHandler = new GetJoinMapForDeviceKeyRequestHandler() - }, - new HttpCwsRoute("feedbacks/{deviceKey}") - { - Name = "GetFeedbacksForDeviceKey", - RouteHandler = new GetFeedbacksForDeviceRequestHandler() - } - }; + var routes = new List + { + new HttpCwsRoute("versions") + { + Name = "ReportVersions", + RouteHandler = new ReportVersionsRequestHandler() + }, + new HttpCwsRoute("appdebug") + { + Name = "AppDebug", + RouteHandler = new AppDebugRequestHandler() + }, + new HttpCwsRoute("devices") + { + Name = "DevList", + RouteHandler = new DevListRequestHandler() + }, + new HttpCwsRoute("deviceCommands") + { + Name = "DevJson", + RouteHandler = new DevJsonRequestHandler() + }, + new HttpCwsRoute("deviceProperties/{deviceKey}") + { + Name = "DevProps", + RouteHandler = new DevPropsRequestHandler() + }, + new HttpCwsRoute("deviceMethods/{deviceKey}") + { + Name = "DevMethods", + RouteHandler = new DevMethodsRequestHandler() + }, + new HttpCwsRoute("deviceFeedbacks/{deviceKey}") + { + Name = "GetFeedbacksForDeviceKey", + RouteHandler = new GetFeedbacksForDeviceRequestHandler() + }, + new HttpCwsRoute("deviceStreamDebug") + { + Name = "SetDeviceStreamDebug", + RouteHandler = new SetDeviceStreamDebugRequestHandler() + }, + new HttpCwsRoute("disableAllStreamDebug") + { + Name = "DisableAllStreamDebug", + RouteHandler = new DisableAllStreamDebugRequestHandler() + }, + new HttpCwsRoute("config") + { + Name = "ShowConfig", + RouteHandler = new ShowConfigRequestHandler() + }, + new HttpCwsRoute("types") + { + Name = "GetTypes", + RouteHandler = new GetTypesRequestHandler() + }, + new HttpCwsRoute("types/{filter}") + { + Name = "GetTypesByFilter", + RouteHandler = new GetTypesByFilterRequestHandler() + }, + new HttpCwsRoute("joinMap/{bridgeKey}") + { + Name = "GetJoinMapsForBridgeKey", + RouteHandler = new GetJoinMapForBridgeKeyRequestHandler() + }, + new HttpCwsRoute("joinMap/{bridgeKey}/{deviceKey}") + { + Name = "GetJoinMapsForDeviceKey", + RouteHandler = new GetJoinMapForDeviceKeyRequestHandler() + }, - foreach (var route in routes.Where(route => route != null)) - { - var r = route; - _server.AddRoute(r); - } + }; - return base.CustomActivate(); - } + foreach (var route in routes.Where(route => route != null)) + { + var r = route; + _server.AddRoute(r); + } + } /// /// Initializes the CWS class diff --git a/src/PepperDash.Essentials.Core/Web/EssentialsWebApiFactory.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApiFactory.cs index 3e90808c..5c44d3b3 100644 --- a/src/PepperDash.Essentials.Core/Web/EssentialsWebApiFactory.cs +++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApiFactory.cs @@ -4,7 +4,7 @@ using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core.Web { - public class EssentialsWebApiFactory : EssentialsDeviceFactory + public class EssentialsWebApiFactory : EssentialsDeviceFactory { public EssentialsWebApiFactory() { @@ -16,7 +16,7 @@ namespace PepperDash.Essentials.Core.Web Debug.Console(1, "Factory Attempting to create new Essentials Web API Server"); var props = dc.Properties.ToObject(); - if (props != null) return new EssemtialsWebApi(dc.Key, dc.Name, props); + if (props != null) return new EssentialsWebApi(dc.Key, dc.Name, props); Debug.Console(1, "Factory failed to create new Essentials Web API Server"); return null; diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DevMethodsRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DevMethodsRequestHandler.cs new file mode 100644 index 00000000..c08544cb --- /dev/null +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DevMethodsRequestHandler.cs @@ -0,0 +1,76 @@ +using System.Text; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core.Web.RequestHandlers; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DevMethodsRequestHandler : WebApiBaseRequestHandler + { + /// + /// Constructor + /// + /// + /// base(true) enables CORS support by default + /// + public DevMethodsRequestHandler() + : base(true) + { + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + var routeData = context.Request.RouteData; + if (routeData == null) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + object deviceObj; + if (!routeData.Values.TryGetValue("deviceKey", out deviceObj)) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + var device = DeviceManager.GetDeviceForKey(deviceObj.ToString()); + + if (device == null) + { + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Device Not Found"; + context.Response.End(); + + return; + } + + var deviceMethods = DeviceJsonApi.GetMethods(device.Key); + if (deviceMethods == null || deviceMethods.ToLower().Contains("no device")) + { + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Not Found"; + context.Response.End(); + + return; + } + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.ContentType = "application/json"; + context.Response.ContentEncoding = Encoding.UTF8; + context.Response.Write(deviceMethods, false); + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DevPropsRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DevPropsRequestHandler.cs index 25fadbce..c00e47c2 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DevPropsRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DevPropsRequestHandler.cs @@ -18,59 +18,59 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { } - /// - /// Handles POST method requests - /// - /// - protected override void HandlePost(HttpCwsContext context) - { - if (context.Request.ContentLength < 0) - { - context.Response.StatusCode = 400; - context.Response.StatusDescription = "Bad Request"; - context.Response.End(); + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + var routeData = context.Request.RouteData; + if (routeData == null) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); - return; - } + return; + } - var data = EssentialsWebApiHelpers.GetRequestBody(context.Request); - if (string.IsNullOrEmpty(data)) - { - context.Response.StatusCode = 400; - context.Response.StatusDescription = "Bad Request"; - context.Response.End(); + object deviceObj; + if (!routeData.Values.TryGetValue("deviceKey", out deviceObj)) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); - return; - } + return; + } - var o = new DeviceActionWrapper(); - var body = JsonConvert.DeserializeAnonymousType(data, o); - - if (string.IsNullOrEmpty(body.DeviceKey)) - { - context.Response.StatusCode = 400; - context.Response.StatusDescription = "Bad Request"; - context.Response.End(); + var device = DeviceManager.GetDeviceForKey(deviceObj.ToString()); - return; - } + if (device == null) + { + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Device Not Found"; + context.Response.End(); - var deviceProps = DeviceJsonApi.GetProperties(body.DeviceKey); - if (deviceProps == null || deviceProps.ToLower().Contains("no device")) - { - context.Response.StatusCode = 404; - context.Response.StatusDescription = "Not Found"; - context.Response.End(); + return; + } - return; - } + var deviceProperties = DeviceJsonApi.GetProperties(device.Key); + if (deviceProperties == null || deviceProperties.ToLower().Contains("no device")) + { + context.Response.StatusCode = 404; + context.Response.StatusDescription = "Not Found"; + context.Response.End(); - context.Response.StatusCode = 200; - context.Response.StatusDescription = "OK"; - context.Response.ContentType = "application/json"; - context.Response.ContentEncoding = Encoding.UTF8; - context.Response.Write(deviceProps, false); - context.Response.End(); - } - } + return; + } + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.ContentType = "application/json"; + context.Response.ContentEncoding = Encoding.UTF8; + context.Response.Write(deviceProperties, false); + context.Response.End(); + } + } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs index 105d2419..13936925 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs @@ -1,4 +1,4 @@ -extern alias Full +extern alias Full; using System.Linq; using Crestron.SimplSharp.WebScripting; diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesRequestHandler.cs index a72fe7e4..42a8a2e2 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -1,4 +1,4 @@ -extern alias Full +extern alias Full; using System.Linq; using Crestron.SimplSharp.WebScripting; diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/ReportVersionsRequestHandler.cs index 925a95f0..968b011e 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -1,4 +1,4 @@ -extern alias Full +extern alias Full; using System.Linq; using Crestron.SimplSharp.WebScripting; diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/ShowConfigRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/ShowConfigRequestHandler.cs index b017627d..12e2c877 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/ShowConfigRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/ShowConfigRequestHandler.cs @@ -1,4 +1,4 @@ -extern alias Full +extern alias Full; using Crestron.SimplSharp.WebScripting; using Full.Newtonsoft.Json; diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 96ef4e5d..524f3f9e 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -31,6 +31,6 @@ Full - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 09c95323..53bdd678 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -5,18 +5,15 @@ using Crestron.SimplSharp.Reflection; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.CrestronThread; using Crestron.SimplSharpPro.Diagnostics; -using Full.Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.DeviceTypeInterfaces; -using PepperDash.Essentials.Core.Fusion; -using PepperDash.Essentials.Devices.Common; +using PepperDash.Essentials.Core.Web; using PepperDash.Essentials.Fusion; using PepperDash.Essentials.Room.Config; using System; -using System.Collections.Generic; using System.Linq; namespace PepperDash.Essentials @@ -118,6 +115,8 @@ namespace PepperDash.Essentials CrestronConsole.AddNewConsoleCommand(DeviceManager.GetRoutingPorts, "getroutingports", "Reports all routing ports, if any. Requires a device key", ConsoleAccessLevelEnum.AccessOperator); + DeviceManager.AddDevice(new EssentialsWebApi("essentialsWebApi", "Essentials Web API")); + if (!Debug.DoNotLoadOnNextBoot) { GoWithLoad(); @@ -149,11 +148,22 @@ namespace PepperDash.Essentials directoryPrefix = Crestron.SimplSharp.CrestronIO.Directory.GetApplicationRootDirectory(); - var fullVersion = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false); + //var assembly = Assembly.GetExecutingAssembly(); - AssemblyInformationalVersionAttribute fullVersionAtt = fullVersion[0] as AssemblyInformationalVersionAttribute; + //Debug.Console(0, "Assembly Name: ", assembly.FullName); - Global.SetAssemblyVersion(fullVersionAtt.InformationalVersion); + //var fullVersion = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false); + + //if (fullVersion.Length == 0) + //{ + // Debug.Console(0, "***********************Unable to determine version.***********************"); + //} + + //AssemblyInformationalVersionAttribute fullVersionAtt = fullVersion[0] as AssemblyInformationalVersionAttribute; + + //Debug.Console(0, "Full Version: {0}", fullVersionAtt.InformationalVersion); + + //Global.SetAssemblyVersion(fullVersionAtt.InformationalVersion); if (CrestronEnvironment.DevicePlatform != eDevicePlatform.Server) // Handles 3-series running Windows CE OS { @@ -202,7 +212,7 @@ namespace PepperDash.Essentials } else // Handles Linux OS (Virtual Control) { - Debug.SetDebugLevel(2); + //Debug.SetDebugLevel(2); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials v{0} on Virtual Control Server", Global.AssemblyVersion); @@ -290,6 +300,8 @@ namespace PepperDash.Essentials { Debug.Console(0, "Verifying and/or creating folder structure"); var configDir = Global.FilePathPrefix; + + Debug.Console(0, "FilePathPrefix: {0}", configDir); var configExists = Directory.Exists(configDir); if (!configExists) Directory.Create(configDir); @@ -358,7 +370,6 @@ namespace PepperDash.Essentials // Build the processor wrapper class DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor")); - // DeviceManager.AddDevice(new EssemtialsWebApi("essentialsWebApi","Essentials Web API")); // Add global System Monitor device if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance) @@ -387,51 +398,6 @@ namespace PepperDash.Essentials "WARNING: Config file defines processor type as '{0}' but actual processor is '{1}'! Some ports may not be available", devConf.Type.ToUpper(), Global.ControlSystem.ControllerPrompt.ToUpper()); - //if (newDev == null) - // newDev = PepperDash.Essentials.Core.ProcessorExtensionDeviceFactory.GetExtensionDevice(devConf); - - //if (newDev != null) - //{ - // DeviceManager.AddDevice(newDev); - - // continue; - //} - - // Check if the processor is a DMPS model - //if (this.ControllerPrompt.IndexOf("dmps", StringComparison.OrdinalIgnoreCase) > -1) - //{ - // Debug.Console(2, "Adding DmpsRoutingController for {0} to Device Manager.", this.ControllerPrompt); - - // var propertiesConfig = JsonConvert.DeserializeObject(devConf.Properties.ToString()); - - // if(propertiesConfig == null) - // propertiesConfig = new DM.Config.DmpsRoutingPropertiesConfig(); - - // DeviceManager.AddDevice(DmpsRoutingController.GetDmpsRoutingController("processor-avRouting", this.ControllerPrompt, propertiesConfig)); - //} - //else - - //if (this.ControllerPrompt.IndexOf("mpc3", StringComparison.OrdinalIgnoreCase) > -1) - //{ - // Debug.Console(2, "MPC3 processor type detected. Adding Mpc3TouchpanelController."); - - // var butToken = devConf.Properties["buttons"]; - // if (butToken != null) - // { - // var buttons = butToken.ToObject>(); - // var tpController = new Essentials.Core.Touchpanels.Mpc3TouchpanelController(devConf.Key, devConf.Name, Global.ControlSystem, buttons); - // DeviceManager.AddDevice(tpController); - // } - // else - // { - // Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: Unable to deserialize buttons collection for device: {0}", devConf.Key); - // } - - //} - //else - //{ - // Debug.Console(2, "************Processor is not DMPS type***************"); - //} continue; } diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index bcc0e152..725aaa31 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -10,6 +10,7 @@ bin\$(Configuration)\ PepperDash Essentials PepperDashEssentials + $(Version) full @@ -50,7 +51,7 @@ Full - + From 1727e81e33c29187dc6d4f9b70ba296176b0beea Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Fri, 3 Nov 2023 13:00:21 -0600 Subject: [PATCH 02/31] Adds handler for getting a debug session --- .../Web/EssentialsWebApi.cs | 5 ++ .../DebugSessionRequestHandler.cs | 57 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs diff --git a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs index 35adbfe9..091ada27 100644 --- a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs +++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs @@ -145,6 +145,11 @@ namespace PepperDash.Essentials.Core.Web Name = "GetJoinMapsForDeviceKey", RouteHandler = new GetJoinMapForDeviceKeyRequestHandler() }, + new HttpCwsRoute("debugSession") + { + Name = "DebugSession", + RouteHandler = new DebugSessionRequestHandler() + } }; diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs new file mode 100644 index 00000000..b024208d --- /dev/null +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs @@ -0,0 +1,57 @@ +using Crestron.SimplSharp; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DebugSessionRequestHandler : WebApiBaseRequestHandler + { + public DebugSessionRequestHandler() + : base(true) + { + } + + protected override void HandleGet(Crestron.SimplSharp.WebScripting.HttpCwsContext context) + { + var routeData = context.Request.RouteData; + if (routeData == null) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + // Generate a random port within a specified range + + // Start the WS Server + + // Return the port number with the full url of the WS Server + + var ip = CrestronEthernetHelper.GetEthernetParameter( + CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); + + var port = new Random().Next(65435, 65535); + + object data = new { + url = string.Format(@"ws://{ip}:{port}", ip, port) + }; + + var res = JsonConvert.SerializeObject(data); + + context.Response.Write(res, false); + context.Response.ContentType = "application/json"; + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.End(); + } + + } +} From b263c7421b357f733e3b2e1a1b4f748db04358b6 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Mon, 6 Nov 2023 21:50:30 -0700 Subject: [PATCH 03/31] feat: updates to DebugSessionRequestHandler --- .../PepperDash.Essentials.Core.csproj | 2 +- .../DebugSessionRequestHandler.cs | 64 +++++++++++++++---- ...epperDash.Essentials.Devices.Common.csproj | 2 +- .../PepperDash.Essentials.csproj | 2 +- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index 7e9b53c8..c90612d9 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -26,7 +26,7 @@ Full - + diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs index b024208d..725d9fb1 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs @@ -1,4 +1,6 @@ using Crestron.SimplSharp; +using Crestron.SimplSharp.WebScripting; +using Crestron.SimplSharpPro.EthernetCommunication; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; @@ -17,6 +19,10 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { } + /// + /// Gets details for a debug session + /// + /// protected override void HandleGet(Crestron.SimplSharp.WebScripting.HttpCwsContext context) { var routeData = context.Request.RouteData; @@ -29,29 +35,61 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers return; } - // Generate a random port within a specified range + try + { + var ip = CrestronEthernetHelper.GetEthernetParameter( + CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); - // Start the WS Server + var port = 0; - // Return the port number with the full url of the WS Server + if(Debug.WebsocketSink == null) + { + Debug.Console(0, "WebsocketSink is null"); + } - var ip = CrestronEthernetHelper.GetEthernetParameter( - CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0); + if (!Debug.WebsocketSink.IsListening) + { + Debug.Console(0, "Starting WS Server"); + // Generate a random port within a specified range + port = new Random().Next(65435, 65535); + // Start the WS Server + Debug.WebsocketSink.StartServerAndSetPort(port); + } - var port = new Random().Next(65435, 65535); + object data = new + { + url = string.Format(@"wss://{0}:{1}", ip, Debug.WebsocketSink.Port) + }; - object data = new { - url = string.Format(@"ws://{ip}:{port}", ip, port) - }; + // Return the port number with the full url of the WS Server + var res = JsonConvert.SerializeObject(data); - var res = JsonConvert.SerializeObject(data); + context.Response.ContentType = "application/json"; + context.Response.ContentEncoding = Encoding.UTF8; + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.Write(res, false); + context.Response.End(); + } + catch (Exception e) + { + Debug.Console(0, "Error: {0}", e); + } + } - context.Response.Write(res, false); - context.Response.ContentType = "application/json"; + /// + /// Stops a debug session + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + Debug.WebsocketSink.StopServer(); + + context.Response.StatusDescription = "Ending Debug Session"; context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; context.Response.End(); - } + } } } diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 524f3f9e..5ffd68fa 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -31,6 +31,6 @@ Full - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index 725aaa31..aaf9b878 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -51,7 +51,7 @@ Full - + From 3eaa86905fee7eec6afee9ad80932943a00f2466 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Mon, 20 Nov 2023 19:21:30 -0700 Subject: [PATCH 04/31] feat: working websocket debug server --- src/Directory.Build.props | 1 + .../PepperDash.Essentials.Core.csproj | 2 +- .../RequestHandlers/DebugSessionRequestHandler.cs | 13 ++++++------- .../PepperDash.Essentials.Devices.Common.csproj | 2 +- .../PepperDash.Essentials.csproj | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 698a159f..9c82b403 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,7 @@ 2.0.0-local + $(Version) PepperDash Technologies PepperDash Technologies PepperDash Essentials diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index c90612d9..ab2751d8 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -26,7 +26,7 @@ Full - + diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs index 725d9fb1..f97ed31d 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs @@ -42,12 +42,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var port = 0; - if(Debug.WebsocketSink == null) - { - Debug.Console(0, "WebsocketSink is null"); - } - - if (!Debug.WebsocketSink.IsListening) + if (!Debug.WebsocketSink.IsRunning) { Debug.Console(0, "Starting WS Server"); // Generate a random port within a specified range @@ -56,11 +51,15 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers Debug.WebsocketSink.StartServerAndSetPort(port); } + var url = Debug.WebsocketSink.Url; + object data = new { - url = string.Format(@"wss://{0}:{1}", ip, Debug.WebsocketSink.Port) + url = Debug.WebsocketSink.Url }; + Debug.Console(0, "Debug Session URL: {0}", url); + // Return the port number with the full url of the WS Server var res = JsonConvert.SerializeObject(data); diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 5ffd68fa..5d269def 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -31,6 +31,6 @@ Full - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index aaf9b878..023a0911 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -51,7 +51,7 @@ Full - + From d2877f2cec2407dc05ca41213123e8dc1cf7fa55 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 23 Nov 2023 23:11:36 -0700 Subject: [PATCH 05/31] feat: more debug testing --- .../Bridges/BridgeBase.cs | 3 +- .../Factory/DeviceFactory.cs | 2 +- .../PepperDash.Essentials.Core.csproj | 2 +- .../UI/TouchpanelBase.cs | 3 +- .../Web/EssentialsWebApi.cs | 17 +++- .../RequestHandlers/AppDebugRequestHandler.cs | 10 +-- .../DebugSessionRequestHandler.cs | 4 +- ...DoNotLoadConfigOnNextBootRequestHandler.cs | 84 +++++++++++++++++++ .../LoadConfigRequestHandler.cs | 37 ++++++++ .../RestartProgramRequestHandler.cs | 38 +++++++++ ...epperDash.Essentials.Devices.Common.csproj | 2 +- src/PepperDash.Essentials/ControlSystem.cs | 6 +- .../PepperDash.Essentials.csproj | 2 +- 13 files changed, 192 insertions(+), 18 deletions(-) create mode 100644 src/PepperDash.Essentials.Core/Web/RequestHandlers/DoNotLoadConfigOnNextBootRequestHandler.cs create mode 100644 src/PepperDash.Essentials.Core/Web/RequestHandlers/LoadConfigRequestHandler.cs create mode 100644 src/PepperDash.Essentials.Core/Web/RequestHandlers/RestartProgramRequestHandler.cs diff --git a/src/PepperDash.Essentials.Core/Bridges/BridgeBase.cs b/src/PepperDash.Essentials.Core/Bridges/BridgeBase.cs index 58917199..0800f79f 100644 --- a/src/PepperDash.Essentials.Core/Bridges/BridgeBase.cs +++ b/src/PepperDash.Essentials.Core/Bridges/BridgeBase.cs @@ -375,8 +375,7 @@ namespace PepperDash.Essentials.Core.Bridges { try { - if (Debug.Level >= 1) - Debug.Console(1, this, "EiscApiAdvanced change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); + Debug.Console(2, this, "EiscApiAdvanced change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); var uo = args.Sig.UserObject; if (uo == null) return; diff --git a/src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs b/src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs index bfc32661..87dc54b6 100644 --- a/src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs +++ b/src/PepperDash.Essentials.Core/Factory/DeviceFactory.cs @@ -189,7 +189,7 @@ namespace PepperDash.Essentials.Core CrestronConsole.ConsoleCommandResponse( @"Type: '{0}' CType: '{1}' - Description: {2}", type.Key, cType, description); + Description: {2}{3}", type.Key, cType, description, CrestronEnvironment.NewLine); } } diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index ab2751d8..7ff80505 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -26,7 +26,7 @@ Full - + diff --git a/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs b/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs index c7be5048..1ffec438 100644 --- a/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs +++ b/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs @@ -154,8 +154,7 @@ namespace PepperDash.Essentials.Core.UI private void Panel_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args) { - if (Debug.Level == 2) - Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); + Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); var uo = args.Sig.UserObject; if (uo is Action) (uo as Action)(args.Sig.BoolValue); diff --git a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs index 091ada27..dac1dd19 100644 --- a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs +++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs @@ -149,7 +149,22 @@ namespace PepperDash.Essentials.Core.Web { Name = "DebugSession", RouteHandler = new DebugSessionRequestHandler() - } + }, + new HttpCwsRoute("doNotLoadConfigOnNextBoot") + { + Name = "DoNotLoadConfigOnNextBoot", + RouteHandler = new DoNotLoadConfigOnNextBootRequestHandler() + }, + new HttpCwsRoute("restartProgram") + { + Name = "Restart Program", + RouteHandler = new RestartProgramRequestHandler() + }, + new HttpCwsRoute("loadConfig") + { + Name = "Load Config", + RouteHandler = new RestartProgramRequestHandler() + } }; diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs index 46a0f980..280e03da 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -24,7 +24,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers /// protected override void HandleGet(HttpCwsContext context) { - var appDebug = new AppDebug { Level = Debug.Level }; + var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel }; var body = JsonConvert.SerializeObject(appDebug, Formatting.Indented); @@ -62,9 +62,9 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers var appDebug = new AppDebug(); var requestBody = JsonConvert.DeserializeAnonymousType(data, appDebug); - Debug.SetDebugLevel(requestBody.Level); + Debug.SetWebSocketMinimumDebugLevel(requestBody.MinimumLevel); - appDebug.Level = Debug.Level; + appDebug.MinimumLevel = Debug.WebsocketMinimumLogLevel; var responseBody = JsonConvert.SerializeObject(appDebug, Formatting.Indented); context.Response.StatusCode = 200; @@ -76,7 +76,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers public class AppDebug { - [JsonProperty("level", NullValueHandling = NullValueHandling.Ignore)] - public int Level { get; set; } + [JsonProperty("minimumLevel", NullValueHandling = NullValueHandling.Ignore)] + public Serilog.Events.LogEventLevel MinimumLevel { get; set; } } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs index f97ed31d..9de58657 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DebugSessionRequestHandler.cs @@ -49,6 +49,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers port = new Random().Next(65435, 65535); // Start the WS Server Debug.WebsocketSink.StartServerAndSetPort(port); + Debug.SetWebSocketMinimumDebugLevel(Serilog.Events.LogEventLevel.Verbose); } var url = Debug.WebsocketSink.Url; @@ -84,10 +85,11 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { Debug.WebsocketSink.StopServer(); - context.Response.StatusDescription = "Ending Debug Session"; context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; context.Response.End(); + + Debug.Console(0, "Websocket Debug Session Stopped"); } } diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/DoNotLoadConfigOnNextBootRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DoNotLoadConfigOnNextBootRequestHandler.cs new file mode 100644 index 00000000..4ec3bc97 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/DoNotLoadConfigOnNextBootRequestHandler.cs @@ -0,0 +1,84 @@ +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class DoNotLoadConfigOnNextBootRequestHandler : WebApiBaseRequestHandler + { + /// + /// Constructor + /// + /// + /// base(true) enables CORS support by default + /// + public DoNotLoadConfigOnNextBootRequestHandler() + : base(true) + { + } + + /// + /// Handles GET method requests + /// + /// + protected override void HandleGet(HttpCwsContext context) + { + var data = new Data + { + DoNotLoadConfigOnNextBoot = Debug.DoNotLoadConfigOnNextBoot + }; + + var body = JsonConvert.SerializeObject(data, Formatting.Indented); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.Write(body, false); + context.Response.End(); + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + if (context.Request.ContentLength < 0) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + var data = EssentialsWebApiHelpers.GetRequestBody(context.Request); + if (string.IsNullOrEmpty(data)) + { + context.Response.StatusCode = 400; + context.Response.StatusDescription = "Bad Request"; + context.Response.End(); + + return; + } + + var d = new Data(); + var requestBody = JsonConvert.DeserializeAnonymousType(data, d); + + Debug.SetDoNotLoadConfigOnNextBoot(requestBody.DoNotLoadConfigOnNextBoot); + + var responseBody = JsonConvert.SerializeObject(d, Formatting.Indented); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.Write(responseBody, false); + context.Response.End(); + } + } + + public class Data + { + [JsonProperty("doNotLoadConfigOnNextBoot", NullValueHandling = NullValueHandling.Ignore)] + public bool DoNotLoadConfigOnNextBoot { get; set; } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/LoadConfigRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/LoadConfigRequestHandler.cs new file mode 100644 index 00000000..6975d478 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/LoadConfigRequestHandler.cs @@ -0,0 +1,37 @@ +using Crestron.SimplSharp; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class LoadConfigRequestHandler : WebApiBaseRequestHandler + { + /// + /// Constructor + /// + /// + /// base(true) enables CORS support by default + /// + public LoadConfigRequestHandler() + : base(true) + { + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + var message = ""; + //Global.ControlSystem.GoWithLoad(); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.Write(message, false); + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/RestartProgramRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/RestartProgramRequestHandler.cs new file mode 100644 index 00000000..0bb568f6 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/RestartProgramRequestHandler.cs @@ -0,0 +1,38 @@ +using Crestron.SimplSharp; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Core.Web.RequestHandlers; + +namespace PepperDash.Essentials.Core.Web.RequestHandlers +{ + public class RestartProgramRequestHandler : WebApiBaseRequestHandler + { + /// + /// Constructor + /// + /// + /// base(true) enables CORS support by default + /// + public RestartProgramRequestHandler() + : base(true) + { + } + + /// + /// Handles POST method requests + /// + /// + protected override void HandlePost(HttpCwsContext context) + { + var message = ""; + if(CrestronEnvironment.DevicePlatform == eDevicePlatform.Appliance) + CrestronConsole.SendControlSystemCommand($"progres -p:{InitialParametersClass.ApplicationNumber}", ref message); + + context.Response.StatusCode = 200; + context.Response.StatusDescription = "OK"; + context.Response.Write(message, false); + context.Response.End(); + } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 5d269def..906b53ea 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -31,6 +31,6 @@ Full - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 53bdd678..026c5085 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -67,7 +67,7 @@ namespace PepperDash.Essentials { DeterminePlatform(); - if (Debug.DoNotLoadOnNextBoot) + if (Debug.DoNotLoadConfigOnNextBoot) { CrestronConsole.AddNewConsoleCommand(s => CrestronInvoke.BeginInvoke((o) => GoWithLoad()), "go", "Loads configuration file", ConsoleAccessLevelEnum.AccessOperator); @@ -117,7 +117,7 @@ namespace PepperDash.Essentials DeviceManager.AddDevice(new EssentialsWebApi("essentialsWebApi", "Essentials Web API")); - if (!Debug.DoNotLoadOnNextBoot) + if (!Debug.DoNotLoadConfigOnNextBoot) { GoWithLoad(); return; @@ -235,7 +235,7 @@ namespace PepperDash.Essentials { try { - Debug.SetDoNotLoadOnNextBoot(false); + Debug.SetDoNotLoadConfigOnNextBoot(false); PluginLoader.AddProgramAssemblies(); diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index 023a0911..0ff8faab 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -51,7 +51,7 @@ Full - + From a2c628145d609757b566d370d1a95c1bcfa7f4ef Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Fri, 24 Nov 2023 18:58:11 -0700 Subject: [PATCH 06/31] feat: adds more api handlers to load config and get/set min log level --- .../Config/ILoadConfig.cs | 13 +++++++++++++ .../PepperDash.Essentials.Core.csproj | 2 +- .../Web/EssentialsWebApi.cs | 2 +- .../Web/RequestHandlers/AppDebugRequestHandler.cs | 8 +++++--- .../Web/RequestHandlers/LoadConfigRequestHandler.cs | 6 ++++-- .../PepperDash.Essentials.Devices.Common.csproj | 2 +- src/PepperDash.Essentials/ControlSystem.cs | 2 +- .../PepperDash.Essentials.csproj | 2 +- 8 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 src/PepperDash.Essentials.Core/Config/ILoadConfig.cs diff --git a/src/PepperDash.Essentials.Core/Config/ILoadConfig.cs b/src/PepperDash.Essentials.Core/Config/ILoadConfig.cs new file mode 100644 index 00000000..00bbf5f6 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Config/ILoadConfig.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PepperDash.Essentials.Core +{ + public interface ILoadConfig + { + void GoWithLoad(); + } +} diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index 7ff80505..9372f0bf 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -26,7 +26,7 @@ Full - + diff --git a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs index dac1dd19..3030cd81 100644 --- a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs +++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs @@ -163,7 +163,7 @@ namespace PepperDash.Essentials.Core.Web new HttpCwsRoute("loadConfig") { Name = "Load Config", - RouteHandler = new RestartProgramRequestHandler() + RouteHandler = new LoadConfigRequestHandler() } }; diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs index 280e03da..a375bbf2 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -2,6 +2,8 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; +using System; +using Serilog.Events; namespace PepperDash.Essentials.Core.Web.RequestHandlers { @@ -26,7 +28,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel }; - var body = JsonConvert.SerializeObject(appDebug, Formatting.Indented); + var body = JsonConvert.SerializeObject((appDebug, Formatting.Indented, new JsonSerializerSettings( )); context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; @@ -60,7 +62,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers } var appDebug = new AppDebug(); - var requestBody = JsonConvert.DeserializeAnonymousType(data, appDebug); + var requestBody = JsonConvert.DeserializeObject(data); Debug.SetWebSocketMinimumDebugLevel(requestBody.MinimumLevel); @@ -77,6 +79,6 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers public class AppDebug { [JsonProperty("minimumLevel", NullValueHandling = NullValueHandling.Ignore)] - public Serilog.Events.LogEventLevel MinimumLevel { get; set; } + public LogEventLevel MinimumLevel { get; set; } } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/LoadConfigRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/LoadConfigRequestHandler.cs index 6975d478..61932f30 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/LoadConfigRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/LoadConfigRequestHandler.cs @@ -26,8 +26,10 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers protected override void HandlePost(HttpCwsContext context) { var message = ""; - //Global.ControlSystem.GoWithLoad(); - + var cs = Global.ControlSystem as ILoadConfig; + if(cs != null) + cs.GoWithLoad(); + context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; context.Response.Write(message, false); diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 906b53ea..206ac337 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -31,6 +31,6 @@ Full - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 026c5085..aeb30ee2 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -18,7 +18,7 @@ using System.Linq; namespace PepperDash.Essentials { - public class ControlSystem : CrestronControlSystem + public class ControlSystem : CrestronControlSystem, ILoadConfig { HttpLogoServer LogoServer; diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index 0ff8faab..b47c5a3b 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -51,7 +51,7 @@ Full - + From 876689fdfe9f3b8e995f2d8b5fd5725a561ff508 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Mon, 15 Jan 2024 13:30:14 -0700 Subject: [PATCH 07/31] fix: minor updates to debug levels --- .../PepperDash.Essentials.Core.csproj | 2 +- src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs | 2 +- .../Web/RequestHandlers/AppDebugRequestHandler.cs | 6 ++++-- .../PepperDash.Essentials.Devices.Common.csproj | 2 +- src/PepperDash.Essentials/PepperDash.Essentials.csproj | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index 9372f0bf..345289eb 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -26,7 +26,7 @@ Full - + diff --git a/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs b/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs index 1ffec438..00cdc28e 100644 --- a/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs +++ b/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs @@ -154,7 +154,7 @@ namespace PepperDash.Essentials.Core.UI private void Panel_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args) { - Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); + Debug.Console(5, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); var uo = args.Sig.UserObject; if (uo is Action) (uo as Action)(args.Sig.BoolValue); diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs index a375bbf2..1157c5e1 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/AppDebugRequestHandler.cs @@ -4,6 +4,7 @@ using PepperDash.Core; using PepperDash.Core.Web.RequestHandlers; using System; using Serilog.Events; +using Newtonsoft.Json.Converters; namespace PepperDash.Essentials.Core.Web.RequestHandlers { @@ -28,7 +29,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers { var appDebug = new AppDebug { MinimumLevel = Debug.WebsocketMinimumLogLevel }; - var body = JsonConvert.SerializeObject((appDebug, Formatting.Indented, new JsonSerializerSettings( )); + var body = JsonConvert.SerializeObject(appDebug, Formatting.Indented); context.Response.StatusCode = 200; context.Response.StatusDescription = "OK"; @@ -79,6 +80,7 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers public class AppDebug { [JsonProperty("minimumLevel", NullValueHandling = NullValueHandling.Ignore)] - public LogEventLevel MinimumLevel { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public LogEventLevel MinimumLevel { get; set; } } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 206ac337..5b4ecbe6 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -31,6 +31,6 @@ Full - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index b47c5a3b..a4cddfe2 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -51,7 +51,7 @@ Full - + From 610fae972df1d1f1f9e6b8954d3873cc9a2e151c Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Mon, 15 Jan 2024 13:34:51 -0700 Subject: [PATCH 08/31] feat: updates to IMobileControl3 and adds IMobileControlResponseMessage --- .../DeviceTypeInterfaces/IMobileControl.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index bb800b44..8af3acf2 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -1,4 +1,5 @@ using System; +using Newtonsoft.Json; using PepperDash.Core; namespace PepperDash.Essentials.Core.DeviceTypeInterfaces @@ -19,6 +20,25 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces public interface IMobileControl3 : IMobileControl { void CreateMobileControlRoomBridge(IEssentialsRoom room, IMobileControl parent); + + void SendMessageObject(object o); + + void AddAction(string key, object action); + + void RemoveAction(string key); + } + + public interface IMobileControlResponseMessage + { + [JsonProperty("type")] + string Type { get; } + + [JsonProperty("clientId")] + object ClientId { get; } + + [JsonProperty("content")] + object Content { get; } + } /// From ab6f1f36f0cdf13bf96f615dd41e0cb5ad4233f8 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Mon, 15 Jan 2024 14:31:24 -0700 Subject: [PATCH 09/31] feat: Updates IMobileControl3 and adds IMobileControlMessenger --- .../DeviceTypeInterfaces/IMobileControl.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index 8af3acf2..ae2826fd 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -26,6 +26,20 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces void AddAction(string key, object action); void RemoveAction(string key); + + void AddDeviceMessenger(IMobileControlMessenger messenger); + + bool CheckForDeviceMessenger(string key); + } + + /// + /// Describes a mobile control messenger + /// + public interface IMobileControlMessenger: IKeyed + { + IMobileControl3 AppServerController { get; } + string MessagePath { get; } + void RegisterWithAppServer(IMobileControl3 appServerController); } public interface IMobileControlResponseMessage From 8883fc329e73a7cf96787db95addeafd70933b42 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 30 Jan 2024 08:56:43 -0600 Subject: [PATCH 10/31] feat: use `Action` instead of `object` for MC handlers --- .../DeviceTypeInterfaces/IMobileControl.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index ae2826fd..a3d59538 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -1,5 +1,6 @@ using System; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using PepperDash.Core; namespace PepperDash.Essentials.Core.DeviceTypeInterfaces @@ -18,12 +19,10 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces /// Describes a MobileSystemController that accepts IEssentialsRoom /// public interface IMobileControl3 : IMobileControl - { - void CreateMobileControlRoomBridge(IEssentialsRoom room, IMobileControl parent); - + { void SendMessageObject(object o); - void AddAction(string key, object action); + void AddAction(string key, Action action); void RemoveAction(string key); From d6b32f48c7ff1c673d6e0f6ddbe8f5790ed3651e Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 30 Jan 2024 13:24:27 -0600 Subject: [PATCH 11/31] refactor: change Content type to JToken for MC --- .../DeviceTypeInterfaces/IMobileControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index a3d59538..f967f877 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -50,7 +50,7 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces object ClientId { get; } [JsonProperty("content")] - object Content { get; } + JToken Content { get; } } From f9d3607072f70bb7efd844a8b2855396187c124b Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 31 Jan 2024 09:48:46 -0600 Subject: [PATCH 12/31] feat: rename MC Message interface --- .../DeviceTypeInterfaces/IMobileControl.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index f967f877..cd921e3b 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -20,7 +20,7 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces /// public interface IMobileControl3 : IMobileControl { - void SendMessageObject(object o); + void SendMessageObject(IMobileControlMessage o); void AddAction(string key, Action action); @@ -41,15 +41,15 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces void RegisterWithAppServer(IMobileControl3 appServerController); } - public interface IMobileControlResponseMessage + public interface IMobileControlMessage { [JsonProperty("type")] string Type { get; } - [JsonProperty("clientId")] - object ClientId { get; } + [JsonProperty("clientId", NullValueHandling = NullValueHandling.Ignore)] + string ClientId { get; } - [JsonProperty("content")] + [JsonProperty("content", NullValueHandling = NullValueHandling.Ignore)] JToken Content { get; } } From 3eefd1ce369b7e8c8186cb137dc3cd7e84d99ff8 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 5 Feb 2024 13:49:58 -0600 Subject: [PATCH 13/31] fix: Web API is now correctly included, along with debug updates from PD Core --- .../PepperDash.Essentials.Core.csproj | 2 +- .../Web/RequestHandlers/GetTypesByFilterRequestHandler.cs | 6 ++---- .../Web/RequestHandlers/GetTypesRequestHandler.cs | 6 ++---- .../Web/RequestHandlers/ReportVersionsRequestHandler.cs | 6 ++---- .../Web/RequestHandlers/ShowConfigRequestHandler.cs | 6 ++---- .../PepperDash.Essentials.Devices.Common.csproj | 2 +- src/PepperDash.Essentials/ControlSystem.cs | 2 -- src/PepperDash.Essentials/PepperDash.Essentials.csproj | 2 +- 8 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index 26cf6583..c9ede78c 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs index 13936925..637c533c 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesByFilterRequestHandler.cs @@ -1,8 +1,6 @@ -extern alias Full; - -using System.Linq; +using System.Linq; using Crestron.SimplSharp.WebScripting; -using Full.Newtonsoft.Json; +using Newtonsoft.Json; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesRequestHandler.cs index 42a8a2e2..564cb00d 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/GetTypesRequestHandler.cs @@ -1,8 +1,6 @@ -extern alias Full; - -using System.Linq; +using System.Linq; using Crestron.SimplSharp.WebScripting; -using Full.Newtonsoft.Json; +using Newtonsoft.Json; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/ReportVersionsRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/ReportVersionsRequestHandler.cs index 968b011e..3447a1eb 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/ReportVersionsRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/ReportVersionsRequestHandler.cs @@ -1,8 +1,6 @@ -extern alias Full; - -using System.Linq; +using System.Linq; using Crestron.SimplSharp.WebScripting; -using Full.Newtonsoft.Json; +using Newtonsoft.Json; using PepperDash.Core.Web.RequestHandlers; namespace PepperDash.Essentials.Core.Web.RequestHandlers diff --git a/src/PepperDash.Essentials.Core/Web/RequestHandlers/ShowConfigRequestHandler.cs b/src/PepperDash.Essentials.Core/Web/RequestHandlers/ShowConfigRequestHandler.cs index 12e2c877..65af1d06 100644 --- a/src/PepperDash.Essentials.Core/Web/RequestHandlers/ShowConfigRequestHandler.cs +++ b/src/PepperDash.Essentials.Core/Web/RequestHandlers/ShowConfigRequestHandler.cs @@ -1,7 +1,5 @@ -extern alias Full; - -using Crestron.SimplSharp.WebScripting; -using Full.Newtonsoft.Json; +using Crestron.SimplSharp.WebScripting; +using Newtonsoft.Json; using PepperDash.Core.Web.RequestHandlers; using PepperDash.Essentials.Core.Config; diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 1378b836..87d4c76c 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -27,6 +27,6 @@ - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 0a246d5e..d9836aba 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -11,8 +11,6 @@ using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.DeviceTypeInterfaces; using PepperDash.Essentials.Core.Web; -using PepperDash.Essentials.Fusion; -using PepperDash.Essentials.Room.Config; using System; using System.Linq; diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index 48eb9be9..f7a72689 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -47,7 +47,7 @@ - + From 35e9e54564e480bb6b1eba5f77fe0df35f5d92ef Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 6 Feb 2024 08:10:02 -0600 Subject: [PATCH 14/31] feat: RKST-130 add `IRoomEventSchedule` interface --- .../Room/IRoomEventSchedule.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs diff --git a/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs b/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs new file mode 100644 index 00000000..9165d1f9 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs @@ -0,0 +1,12 @@ +using PepperDash.Essentials.Room.Config; +using System.Collections.Generic; + +namespace PepperDash.Essentials.Core.Room +{ + public interface IRoomEventSchedule + { + void AddOrUpdateScheduledEvent(ScheduledEventConfig eventConfig); + + List GetScheduledEvents(); + } +} From b80b827217969498cfcb150e21754c8fb912181f Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 6 Feb 2024 08:14:39 -0600 Subject: [PATCH 15/31] chore: fix namespace for IRoomEventSchedule interface --- src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs b/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs index 9165d1f9..b4d8a70a 100644 --- a/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs +++ b/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs @@ -1,7 +1,7 @@ using PepperDash.Essentials.Room.Config; using System.Collections.Generic; -namespace PepperDash.Essentials.Core.Room +namespace PepperDash.Essentials.Core { public interface IRoomEventSchedule { From 9f49a7faefceef83a3035337902203e871a26620 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 6 Feb 2024 08:28:13 -0600 Subject: [PATCH 16/31] feat: RKST-130 add missing event --- src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs b/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs index b4d8a70a..c2595151 100644 --- a/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs +++ b/src/PepperDash.Essentials.Core/Room/IRoomEventSchedule.cs @@ -1,4 +1,5 @@ using PepperDash.Essentials.Room.Config; +using System; using System.Collections.Generic; namespace PepperDash.Essentials.Core @@ -8,5 +9,12 @@ namespace PepperDash.Essentials.Core void AddOrUpdateScheduledEvent(ScheduledEventConfig eventConfig); List GetScheduledEvents(); + + event EventHandler ScheduledEventsChanged; + } + + public class ScheduledEventEventArgs : EventArgs + { + public List ScheduledEvents; } } From 56280428418aadf5b9df2ff482aa01110c6e487a Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 6 Feb 2024 10:51:25 -0600 Subject: [PATCH 17/31] feat: move room aggregate interfaces back into Essentials --- .../Room/IEssentialsHuddleSpaceRoom.cs | 19 ++++++++++++++ .../Room/IEssentialsHuddleVtc1Room.cs | 25 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs create mode 100644 src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs diff --git a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs new file mode 100644 index 00000000..975c8661 --- /dev/null +++ b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs @@ -0,0 +1,19 @@ +using System; +using PepperDash.Essentials.Core; + +namespace PDT.Plugins.Essentials.Rooms +{ + public interface IEssentialsHuddleSpaceRoom : IEssentialsRoom, IHasCurrentSourceInfoChange, IRunRouteAction, IHasDefaultDisplay, IHasCurrentVolumeControls, IRoomOccupancy, + IEmergency, IMicrophonePrivacy + { + bool ExcludeFromGlobalFunctions { get; } + + void RunRouteAction(string routeKey); + + // EssentialsHuddleRoomPropertiesConfig PropertiesConfig { get; } + + IBasicVolumeControls CurrentVolumeControls { get; } + + event EventHandler CurrentVolumeDeviceChange; + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs new file mode 100644 index 00000000..65e2e357 --- /dev/null +++ b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs @@ -0,0 +1,25 @@ +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Devices.Common.AudioCodec; +using PepperDash.Essentials.Devices.Common.Codec; +using PepperDash.Essentials.Devices.Common.VideoCodec; + +namespace PDT.Plugins.Essentials.Rooms +{ + public interface IEssentialsHuddleVtc1Room : IEssentialsRoom, IHasCurrentSourceInfoChange, IHasCurrentVolumeControls, IRunRouteAction, IRunDefaultCallRoute, IHasVideoCodec, IHasAudioCodec, IHasDefaultDisplay, IHasInCallFeedback, + IRoomOccupancy, IEmergency, IMicrophonePrivacy + { + // EssentialsHuddleVtc1PropertiesConfig PropertiesConfig { get; } + + bool ExcludeFromGlobalFunctions { get; } + + void RunRouteAction(string routeKey); + + IHasScheduleAwareness ScheduleSource { get; } + + new BoolFeedback InCallFeedback { get; } + + new BoolFeedback PrivacyModeIsOnFeedback { get; } + + string DefaultCodecRouteString { get; } + } +} \ No newline at end of file From 8d34b73cdf9692dd3fa4f2d659a8207333d46014 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Tue, 6 Feb 2024 10:51:53 -0600 Subject: [PATCH 18/31] feat: add property to send ID to handlers for MC --- .../DeviceTypeInterfaces/IMobileControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index 28befce8..944e4a50 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -22,7 +22,7 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces { void SendMessageObject(IMobileControlMessage o); - void AddAction(string key, Action action); + void AddAction(string key, Action action); void RemoveAction(string key); From 8af0cf270281fac774136aa085f8556841db9d76 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 07:46:16 -0600 Subject: [PATCH 19/31] chore: add room configs back in At the moment, MC relies on some of these classes, so they are necessary in Essentials for now. We can explore how to remove them at a later date --- ...sentialsDualDisplayRoomPropertiesConfig.cs | 8 + .../EssentialsHuddleRoomPropertiesConfig.cs | 34 ++ .../EssentialsHuddleVtc1PropertiesConfig.cs | 13 + .../EssentialsNDisplayRoomPropertiesConfig.cs | 34 ++ .../EssentialsPresentationPropertiesConfig.cs | 22 + .../Room/Config/EssentialsRoomConfig.cs | 406 ++++++++++++++++++ .../Config/EssentialsRoomEmergencyConfig.cs | 30 ++ .../Room/Config/EssentialsTechRoomConfig.cs | 77 ++++ .../Room/Config/SimplRoomPropertiesConfig.cs | 25 ++ 9 files changed, 649 insertions(+) create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsDualDisplayRoomPropertiesConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleRoomPropertiesConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleVtc1PropertiesConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsNDisplayRoomPropertiesConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsPresentationPropertiesConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomEmergencyConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsTechRoomConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/Config/SimplRoomPropertiesConfig.cs diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsDualDisplayRoomPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsDualDisplayRoomPropertiesConfig.cs new file mode 100644 index 00000000..3b3489bf --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsDualDisplayRoomPropertiesConfig.cs @@ -0,0 +1,8 @@ + +namespace PDT.Plugins.Essentials.Rooms.Config +{ + public class EssentialsDualDisplayRoomPropertiesConfig : EssentialsNDisplayRoomPropertiesConfig + { + + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleRoomPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleRoomPropertiesConfig.cs new file mode 100644 index 00000000..76a35689 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleRoomPropertiesConfig.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace PDT.Plugins.Essentials.Rooms.Config +{ + /// + /// + /// + public class EssentialsHuddleRoomPropertiesConfig : EssentialsRoomPropertiesConfig + { + /// + /// The key of the default display device + /// + [JsonProperty("defaultDisplayKey")] + public string DefaultDisplayKey { get; set; } + + /// + /// The key of the default audio device + /// + [JsonProperty("defaultAudioKey")] + public string DefaultAudioKey { get; set; } + + /// + /// The key of the source list for the room + /// + [JsonProperty("sourceListKey")] + public string SourceListKey { get; set; } + + /// + /// The key of the default source item from the source list + /// + [JsonProperty("defaultSourceItem")] + public string DefaultSourceItem { get; set; } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleVtc1PropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleVtc1PropertiesConfig.cs new file mode 100644 index 00000000..0071d9ee --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleVtc1PropertiesConfig.cs @@ -0,0 +1,13 @@ + +using Newtonsoft.Json; + +namespace PDT.Plugins.Essentials.Rooms.Config +{ + + public class EssentialsHuddleVtc1PropertiesConfig : EssentialsConferenceRoomPropertiesConfig + { + [JsonProperty("defaultDisplayKey")] + public string DefaultDisplayKey { get; set; } + + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsNDisplayRoomPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsNDisplayRoomPropertiesConfig.cs new file mode 100644 index 00000000..7d4d2bc4 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsNDisplayRoomPropertiesConfig.cs @@ -0,0 +1,34 @@ + +using System.Collections.Generic; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Essentials.Core; + +namespace PDT.Plugins.Essentials.Rooms.Config +{ + /// + /// + /// + public class EssentialsNDisplayRoomPropertiesConfig : EssentialsConferenceRoomPropertiesConfig + { + [JsonProperty("defaultAudioBehavior")] + public string DefaultAudioBehavior { get; set; } + [JsonProperty("defaultVideoBehavior")] + public string DefaultVideoBehavior { get; set; } + [JsonProperty("displays")] + public Dictionary Displays { get; set; } + + public EssentialsNDisplayRoomPropertiesConfig() + { + Displays = new Dictionary(); + } + + } + + public class DisplayItem : IKeyName + { + public string Key { get; set; } + public string Name { get; set; } + } + +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsPresentationPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsPresentationPropertiesConfig.cs new file mode 100644 index 00000000..125a818f --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsPresentationPropertiesConfig.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace PDT.Plugins.Essentials.Rooms.Config +{ + /// + /// + /// + public class EssentialsPresentationRoomPropertiesConfig : EssentialsRoomPropertiesConfig + { + public string DefaultAudioBehavior { get; set; } + public string DefaultAudioKey { get; set; } + public string DefaultVideoBehavior { get; set; } + public List DisplayKeys { get; set; } + public string SourceListKey { get; set; } + public bool HasDsp { get; set; } + + public EssentialsPresentationRoomPropertiesConfig() + { + DisplayKeys = new List(); + } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomConfig.cs new file mode 100644 index 00000000..ac5f7b10 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomConfig.cs @@ -0,0 +1,406 @@ +using System; +using System.Collections.Generic; +using Crestron.SimplSharp; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.Core.Privacy; + +namespace PDT.Plugins.Essentials.Rooms.Config +{ + public class EssentialsRoomConfigHelper + { + /// + /// Returns a room object from this config data + /// + /// + public static IKeyed GetRoomObject(DeviceConfig roomConfig) + { + var typeName = roomConfig.Type.ToLower(); + + switch (typeName) + { + case "huddle" : + { + return new EssentialsHuddleSpaceRoom(roomConfig); + } + case "huddlevtc1" : + { + return new EssentialsHuddleVtc1Room(roomConfig); + } + case "ddvc01bridge" : + { + return new Device(roomConfig.Key, roomConfig.Name); // placeholder device that does nothing. + } + case "dualdisplay" : + { + return new EssentialsDualDisplayRoom(roomConfig); + } + case "combinedhuddlevtc1" : + { + return new EssentialsCombinedHuddleVtc1Room(roomConfig); + } + case "techroom" : + { + return new EssentialsTechRoom(roomConfig); + } + default : + { + return DeviceFactory.GetDevice(roomConfig); + } + } + } + + /// + /// Gets and operating, standalone emergegncy object that can be plugged into a room. + /// Returns null if there is no emergency defined + /// + public static EssentialsRoomEmergencyBase GetEmergency(EssentialsRoomPropertiesConfig props, IEssentialsRoom room) + { + // This emergency + var emergency = props.Emergency; + if (emergency != null) + { + //switch on emergency type here. Right now only contact and shutdown + var e = new EssentialsRoomEmergencyContactClosure(room.Key + "-emergency", props.Emergency, room); + DeviceManager.AddDevice(e); + } + return null; + } + + /// + /// + /// + /// + /// + /// + public static MicrophonePrivacyController GetMicrophonePrivacy( + EssentialsRoomPropertiesConfig props, IPrivacy room) + { + var microphonePrivacy = props.MicrophonePrivacy; + if (microphonePrivacy == null) + { + Debug.Console(0, "Cannot create microphone privacy with null properties"); + return null; + } + // Get the MicrophonePrivacy device from the device manager + var mP = (DeviceManager.GetDeviceForKey(props.MicrophonePrivacy.DeviceKey) as MicrophonePrivacyController); + // Set this room as the IPrivacy device + if (mP == null) + { + Debug.Console(0, "ERROR: Selected device {0} is not MicrophonePrivacyController", props.MicrophonePrivacy.DeviceKey); + return null; + } + mP.SetPrivacyDevice(room); + + var behaviour = props.MicrophonePrivacy.Behaviour.ToLower(); + + if (behaviour == null) + { + Debug.Console(0, "WARNING: No behaviour defined for MicrophonePrivacyController"); + return null; + } + if (behaviour == "trackroomstate") + { + // Tie LED enable to room power state + var essRoom = room as IEssentialsRoom; + essRoom.OnFeedback.OutputChange += (o, a) => + { + if (essRoom.OnFeedback.BoolValue) + mP.EnableLeds = true; + else + mP.EnableLeds = false; + }; + + mP.EnableLeds = essRoom.OnFeedback.BoolValue; + } + else if (behaviour == "trackcallstate") + { + // Tie LED enable to room power state + var inCallRoom = room as IHasInCallFeedback; + inCallRoom.InCallFeedback.OutputChange += (o, a) => + { + if (inCallRoom.InCallFeedback.BoolValue) + mP.EnableLeds = true; + else + mP.EnableLeds = false; + }; + + mP.EnableLeds = inCallRoom.InCallFeedback.BoolValue; + } + + return mP; + } + + } + + /// + /// + /// + public class EssentialsRoomPropertiesConfig + { + [JsonProperty("addresses")] + public EssentialsRoomAddressPropertiesConfig Addresses { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("emergency")] + public EssentialsRoomEmergencyConfig Emergency { get; set; } + + [JsonProperty("help")] + public EssentialsHelpPropertiesConfig Help { get; set; } + + [JsonProperty("helpMessage")] + public string HelpMessage { get; set; } + + /// + /// Read this value to get the help message. It checks for the old and new config format. + /// + public string HelpMessageForDisplay + { + get + { + if(Help != null && !string.IsNullOrEmpty(Help.Message)) + { + return Help.Message; + } + else + { + return HelpMessage; + } + } + } + + [JsonProperty("environment")] + public EssentialsEnvironmentPropertiesConfig Environment { get; set; } + + [JsonProperty("logo")] + public EssentialsLogoPropertiesConfig LogoLight { get; set; } + + [JsonProperty("logoDark")] + public EssentialsLogoPropertiesConfig LogoDark { get; set; } + + [JsonProperty("microphonePrivacy")] + public EssentialsRoomMicrophonePrivacyConfig MicrophonePrivacy { get; set; } + + [JsonProperty("occupancy")] + public EssentialsRoomOccSensorConfig Occupancy { get; set; } + + [JsonProperty("oneButtonMeeting")] + public EssentialsOneButtonMeetingPropertiesConfig OneButtonMeeting { get; set; } + + [JsonProperty("shutdownVacancySeconds")] + public int ShutdownVacancySeconds { get; set; } + + [JsonProperty("shutdownPromptSeconds")] + public int ShutdownPromptSeconds { get; set; } + + [JsonProperty("tech")] + public EssentialsRoomTechConfig Tech { get; set; } + + [JsonProperty("volumes")] + public EssentialsRoomVolumesConfig Volumes { get; set; } + + [JsonProperty("fusion")] + public EssentialsRoomFusionConfig Fusion { get; set; } + + [JsonProperty("essentialsRoomUiBehaviorConfig", NullValueHandling=NullValueHandling.Ignore)] + public EssentialsRoomUiBehaviorConfig UiBehavior { get; set; } + + [JsonProperty("zeroVolumeWhenSwtichingVolumeDevices")] + public bool ZeroVolumeWhenSwtichingVolumeDevices { get; set; } + + /// + /// Indicates if this room represents a combination of other rooms + /// + [JsonProperty("isRoomCombinationScenario")] + public bool IsRoomCombinationScenario { get; set; } + + public EssentialsRoomPropertiesConfig() + { + LogoLight = new EssentialsLogoPropertiesConfig(); + LogoDark = new EssentialsLogoPropertiesConfig(); + } + } + + public class EssentialsRoomUiBehaviorConfig + { + [JsonProperty("disableActivityButtonsWhileWarmingCooling")] + public bool DisableActivityButtonsWhileWarmingCooling { get; set; } + } + + public class EssentialsAvRoomPropertiesConfig : EssentialsRoomPropertiesConfig + { + [JsonProperty("defaultAudioKey")] + public string DefaultAudioKey { get; set; } + [JsonProperty("sourceListKey")] + public string SourceListKey { get; set; } + [JsonProperty("destinationListKey")] + public string DestinationListKey { get; set; } + [JsonProperty("defaultSourceItem")] + public string DefaultSourceItem { get; set; } + /// + /// Indicates if the room supports advanced sharing + /// + [JsonProperty("supportsAdvancedSharing")] + public bool SupportsAdvancedSharing { get; set; } + /// + /// Indicates if non-tech users can change the share mode + /// + [JsonProperty("userCanChangeShareMode")] + public bool UserCanChangeShareMode { get; set; } + } + + public class EssentialsConferenceRoomPropertiesConfig : EssentialsAvRoomPropertiesConfig + { + [JsonProperty("videoCodecKey")] + public string VideoCodecKey { get; set; } + [JsonProperty("audioCodecKey")] + public string AudioCodecKey { get; set; } + } + + public class EssentialsEnvironmentPropertiesConfig + { + public bool Enabled { get; set; } + + [JsonProperty("deviceKeys")] + public List DeviceKeys { get; set; } + + public EssentialsEnvironmentPropertiesConfig() + { + DeviceKeys = new List(); + } + + } + + public class EssentialsRoomFusionConfig + { + public uint IpIdInt + { + get + { + try + { + return Convert.ToUInt32(IpId, 16); + } + catch (Exception) + { + throw new FormatException(string.Format("ERROR:Unable to convert IP ID: {0} to hex. Error:\n{1}", IpId)); + } + + } + } + + [JsonProperty("ipId")] + public string IpId { get; set; } + + [JsonProperty("joinMapKey")] + public string JoinMapKey { get; set; } + + } + + public class EssentialsRoomMicrophonePrivacyConfig + { + [JsonProperty("deviceKey")] + public string DeviceKey { get; set; } + + [JsonProperty("behaviour")] + public string Behaviour { get; set; } + } + + /// + /// Properties for the help text box + /// + public class EssentialsHelpPropertiesConfig + { + [JsonProperty("message")] + public string Message { get; set; } + + [JsonProperty("showCallButton")] + public bool ShowCallButton { get; set; } + + /// + /// Defaults to "Call Help Desk" + /// + [JsonProperty("callButtonText")] + public string CallButtonText { get; set; } + + public EssentialsHelpPropertiesConfig() + { + CallButtonText = "Call Help Desk"; + } + } + + /// + /// + /// + public class EssentialsOneButtonMeetingPropertiesConfig + { + [JsonProperty("enable")] + public bool Enable { get; set; } + } + + public class EssentialsRoomAddressPropertiesConfig + { + [JsonProperty("phoneNumber")] + public string PhoneNumber { get; set; } + + [JsonProperty("sipAddress")] + public string SipAddress { get; set; } + } + + + /// + /// Properties for the room's logo on panels + /// + public class EssentialsLogoPropertiesConfig + { + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("url")] + public string Url { get; set; } + /// + /// Gets either the custom URL, a local-to-processor URL, or null if it's a default logo + /// + public string GetLogoUrlLight() + { + if (Type == "url") + return Url; + if (Type == "system") + return string.Format("http://{0}:8080/logo.png", + CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)); + return null; + } + + public string GetLogoUrlDark() + { + if (Type == "url") + return Url; + if (Type == "system") + return string.Format("http://{0}:8080/logo-dark.png", + CrestronEthernetHelper.GetEthernetParameter(CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0)); + return null; + } + } + + /// + /// Represents occupancy sensor(s) setup for a room + /// + public class EssentialsRoomOccSensorConfig + { + [JsonProperty("deviceKey")] + public string DeviceKey { get; set; } + + [JsonProperty("timeoutMinutes")] + public int TimeoutMinutes { get; set; } + } + + public class EssentialsRoomTechConfig + { + [JsonProperty("password")] + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomEmergencyConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomEmergencyConfig.cs new file mode 100644 index 00000000..0100f006 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomEmergencyConfig.cs @@ -0,0 +1,30 @@ +namespace PDT.Plugins.Essentials.Rooms.Config +{ + /// + /// + /// + public class EssentialsRoomEmergencyConfig + { + public EssentialsRoomEmergencyTriggerConfig Trigger { get; set; } + + public string Behavior { get; set; } + } + + /// + /// + /// + public class EssentialsRoomEmergencyTriggerConfig + { + /// + /// contact, + /// + public string Type { get; set; } + /// + /// Input number if contact + /// + public int Number { get; set; } + + public bool TriggerOnClose { get; set; } + + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsTechRoomConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsTechRoomConfig.cs new file mode 100644 index 00000000..1de4128d --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsTechRoomConfig.cs @@ -0,0 +1,77 @@ + +using System.Collections.Generic; +using Newtonsoft.Json; +using PepperDash.Essentials.Room.Config; + +namespace PDT.Plugins.Essentials.Rooms.Config +{ + public class EssentialsTechRoomConfig + { + /// + /// The key of the dummy device used to enable routing + /// + [JsonProperty("dummySourceKey")] + public string DummySourceKey { get; set; } + + /// + /// The keys of the displays assigned to this room + /// + [JsonProperty("displays")] + public List Displays { get; set; } + + /// + /// The keys of the tuners assinged to this room + /// + [JsonProperty("tuners")] + public List Tuners { get; set; } + + /// + /// PIN to access the room as a normal user + /// + [JsonProperty("userPin")] + public string UserPin { get; set; } + + /// + /// PIN to access the room as a tech user + /// + [JsonProperty("techPin")] + public string TechPin { get; set; } + + /// + /// Name of the presets file. Path prefix is assumed to be /html/presets/lists/ + /// + [JsonProperty("presetsFileName")] + public string PresetsFileName { get; set; } + + [JsonProperty("scheduledEvents")] + public List ScheduledEvents { get; set; } + + /// + /// Indicates that the room is the primary when true + /// + [JsonProperty("isPrimary")] + public bool IsPrimary { get; set; } + + /// + /// Indicates which tuners should mirror preset recall when two rooms are configured in a primary->secondary scenario + /// + [JsonProperty("mirroredTuners")] + public Dictionary MirroredTuners { get; set; } + + [JsonProperty("helpMessage")] + public string HelpMessage { get; set; } + + /// + /// Indicates the room + /// + [JsonProperty("isTvPresetsProvider")] + public bool IsTvPresetsProvider; + + public EssentialsTechRoomConfig() + { + Displays = new List(); + Tuners = new List(); + ScheduledEvents = new List(); + } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/SimplRoomPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/SimplRoomPropertiesConfig.cs new file mode 100644 index 00000000..52aac362 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/SimplRoomPropertiesConfig.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace PDT.Plugins.Essentials.Rooms.Config +{ + public class SimplRoomPropertiesConfig : EssentialsHuddleVtc1PropertiesConfig + { + [JsonProperty("roomPhoneNumber")] + public string RoomPhoneNumber { get; set; } + [JsonProperty("roomURI")] + public string RoomURI { get; set; } + [JsonProperty("speedDials")] + public List SpeedDials { get; set; } + [JsonProperty("volumeSliderNames")] + public List VolumeSliderNames { get; set; } + } + + public class SimplSpeedDial + { + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("number")] + public string Number { get; set; } + } +} \ No newline at end of file From 49b7faa40060e6510e0caabb7c6845c18efe286c Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 08:42:22 -0600 Subject: [PATCH 20/31] chore: add back in config classes Mobile Control (for the moment) relies on these classes, so they are necessary in Essentials until we determine a better solution. --- ...sentialsDualDisplayRoomPropertiesConfig.cs | 2 +- .../EssentialsHuddleRoomPropertiesConfig.cs | 2 +- .../EssentialsHuddleVtc1PropertiesConfig.cs | 2 +- .../EssentialsNDisplayRoomPropertiesConfig.cs | 2 +- .../EssentialsPresentationPropertiesConfig.cs | 2 +- .../Room/Config/EssentialsRoomConfig.cs | 44 +-------- .../Config/EssentialsRoomEmergencyConfig.cs | 2 +- .../Room/Config/EssentialsTechRoomConfig.cs | 2 +- .../Config/EssentialsVolumeLevelConfig.cs | 91 +++++++++++++++++++ .../Room/Config/SimplRoomPropertiesConfig.cs | 2 +- .../EsentialsRoomEmergencyContactClosure.cs | 47 ++++++++++ .../Room/IEssentialsHuddleSpaceRoom.cs | 12 +-- .../Room/IEssentialsHuddleVtc1Room.cs | 5 +- .../Room/IEssentialsTechRoom.cs | 22 +++++ 14 files changed, 176 insertions(+), 61 deletions(-) create mode 100644 src/PepperDash.Essentials.Core/Room/Config/EssentialsVolumeLevelConfig.cs create mode 100644 src/PepperDash.Essentials.Core/Room/EsentialsRoomEmergencyContactClosure.cs create mode 100644 src/PepperDash.Essentials.Devices.Common/Room/IEssentialsTechRoom.cs diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsDualDisplayRoomPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsDualDisplayRoomPropertiesConfig.cs index 3b3489bf..2eb56fd3 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/EssentialsDualDisplayRoomPropertiesConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsDualDisplayRoomPropertiesConfig.cs @@ -1,5 +1,5 @@  -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { public class EssentialsDualDisplayRoomPropertiesConfig : EssentialsNDisplayRoomPropertiesConfig { diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleRoomPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleRoomPropertiesConfig.cs index 76a35689..a0b3499f 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleRoomPropertiesConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleRoomPropertiesConfig.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { /// /// diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleVtc1PropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleVtc1PropertiesConfig.cs index 0071d9ee..27164f57 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleVtc1PropertiesConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsHuddleVtc1PropertiesConfig.cs @@ -1,7 +1,7 @@  using Newtonsoft.Json; -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { public class EssentialsHuddleVtc1PropertiesConfig : EssentialsConferenceRoomPropertiesConfig diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsNDisplayRoomPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsNDisplayRoomPropertiesConfig.cs index 7d4d2bc4..6d8762fa 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/EssentialsNDisplayRoomPropertiesConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsNDisplayRoomPropertiesConfig.cs @@ -4,7 +4,7 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { /// /// diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsPresentationPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsPresentationPropertiesConfig.cs index 125a818f..53333f07 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/EssentialsPresentationPropertiesConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsPresentationPropertiesConfig.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { /// /// diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomConfig.cs index ac5f7b10..ebb0f84b 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomConfig.cs @@ -4,54 +4,12 @@ using Crestron.SimplSharp; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; -using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Privacy; -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { public class EssentialsRoomConfigHelper { - /// - /// Returns a room object from this config data - /// - /// - public static IKeyed GetRoomObject(DeviceConfig roomConfig) - { - var typeName = roomConfig.Type.ToLower(); - - switch (typeName) - { - case "huddle" : - { - return new EssentialsHuddleSpaceRoom(roomConfig); - } - case "huddlevtc1" : - { - return new EssentialsHuddleVtc1Room(roomConfig); - } - case "ddvc01bridge" : - { - return new Device(roomConfig.Key, roomConfig.Name); // placeholder device that does nothing. - } - case "dualdisplay" : - { - return new EssentialsDualDisplayRoom(roomConfig); - } - case "combinedhuddlevtc1" : - { - return new EssentialsCombinedHuddleVtc1Room(roomConfig); - } - case "techroom" : - { - return new EssentialsTechRoom(roomConfig); - } - default : - { - return DeviceFactory.GetDevice(roomConfig); - } - } - } - /// /// Gets and operating, standalone emergegncy object that can be plugged into a room. /// Returns null if there is no emergency defined diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomEmergencyConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomEmergencyConfig.cs index 0100f006..76199a91 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomEmergencyConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsRoomEmergencyConfig.cs @@ -1,4 +1,4 @@ -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { /// /// diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsTechRoomConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsTechRoomConfig.cs index 1de4128d..507bac5e 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/EssentialsTechRoomConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsTechRoomConfig.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using Newtonsoft.Json; using PepperDash.Essentials.Room.Config; -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { public class EssentialsTechRoomConfig { diff --git a/src/PepperDash.Essentials.Core/Room/Config/EssentialsVolumeLevelConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/EssentialsVolumeLevelConfig.cs new file mode 100644 index 00000000..5b9450f2 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/Config/EssentialsVolumeLevelConfig.cs @@ -0,0 +1,91 @@ +using System; +using PepperDash.Essentials.Core; + +namespace PepperDash.Essentials.Room.Config +{ + /// + /// + /// + public class EssentialsRoomVolumesConfig + { + public EssentialsVolumeLevelConfig Master { get; set; } + public EssentialsVolumeLevelConfig Program { get; set; } + public EssentialsVolumeLevelConfig AudioCallRx { get; set; } + public EssentialsVolumeLevelConfig AudioCallTx { get; set; } + } + + /// + /// + /// + public class EssentialsVolumeLevelConfig + { + public string DeviceKey { get; set; } + public string Label { get; set; } + public int Level { get; set; } + + /// + /// Helper to get the device associated with key - one timer. + /// + public IBasicVolumeWithFeedback GetDevice() + { + throw new NotImplementedException("This method references DM CHASSIS Directly"); + /* + // DM output card format: deviceKey--output~number, dm8x8-1--output~4 + var match = Regex.Match(DeviceKey, @"([-_\w]+)--(\w+)~(\d+)"); + if (match.Success) + { + var devKey = match.Groups[1].Value; + var chassis = DeviceManager.GetDeviceForKey(devKey) as DmChassisController; + if (chassis != null) + { + var outputNum = Convert.ToUInt32(match.Groups[3].Value); + if (chassis.VolumeControls.ContainsKey(outputNum)) // should always... + return chassis.VolumeControls[outputNum]; + } + // No volume for some reason. We have failed as developers + return null; + } + + // DSP/DMPS format: deviceKey--levelName, biampTesira-1--master + match = Regex.Match(DeviceKey, @"([-_\w]+)--(.+)"); + if (match.Success) + { + var devKey = match.Groups[1].Value; + var dsp = DeviceManager.GetDeviceForKey(devKey) as BiampTesiraForteDsp; + if (dsp != null) + { + var levelTag = match.Groups[2].Value; + if (dsp.LevelControlPoints.ContainsKey(levelTag)) // should always... + return dsp.LevelControlPoints[levelTag]; + } + + var dmps = DeviceManager.GetDeviceForKey(devKey) as DmpsAudioOutputController; + if (dmps != null) + { + var levelTag = match.Groups[2].Value; + switch (levelTag) + { + case "master": + return dmps.MasterVolumeLevel; + case "source": + return dmps.SourceVolumeLevel; + case "micsmaster": + return dmps.MicsMasterVolumeLevel; + case "codec1": + return dmps.Codec1VolumeLevel; + case "codec2": + return dmps.Codec2VolumeLevel; + default: + return dmps.MasterVolumeLevel; + } + } + // No volume for some reason. We have failed as developers + return null; + } + + return null; + } + * */ + } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/Config/SimplRoomPropertiesConfig.cs b/src/PepperDash.Essentials.Core/Room/Config/SimplRoomPropertiesConfig.cs index 52aac362..fdd9b857 100644 --- a/src/PepperDash.Essentials.Core/Room/Config/SimplRoomPropertiesConfig.cs +++ b/src/PepperDash.Essentials.Core/Room/Config/SimplRoomPropertiesConfig.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using Newtonsoft.Json; -namespace PDT.Plugins.Essentials.Rooms.Config +namespace PepperDash.Essentials.Room.Config { public class SimplRoomPropertiesConfig : EssentialsHuddleVtc1PropertiesConfig { diff --git a/src/PepperDash.Essentials.Core/Room/EsentialsRoomEmergencyContactClosure.cs b/src/PepperDash.Essentials.Core/Room/EsentialsRoomEmergencyContactClosure.cs new file mode 100644 index 00000000..7ad7f700 --- /dev/null +++ b/src/PepperDash.Essentials.Core/Room/EsentialsRoomEmergencyContactClosure.cs @@ -0,0 +1,47 @@ +using System; +using Crestron.SimplSharpPro; +using PepperDash.Essentials.Room.Config; + +namespace PepperDash.Essentials.Core +{ + public class EssentialsRoomEmergencyContactClosure : EssentialsRoomEmergencyBase + { + IEssentialsRoom Room; + string Behavior; + bool TriggerOnClose; + + public EssentialsRoomEmergencyContactClosure(string key, EssentialsRoomEmergencyConfig config, IEssentialsRoom room) : + base(key) + { + Room = room; + var cs = Global.ControlSystem; + + if (config.Trigger.Type.Equals("contact", StringComparison.OrdinalIgnoreCase)) + { + var portNum = (uint)config.Trigger.Number; + if (portNum <= cs.NumberOfDigitalInputPorts) + { + cs.DigitalInputPorts[portNum].Register(); + cs.DigitalInputPorts[portNum].StateChange += EsentialsRoomEmergencyContactClosure_StateChange; + } + } + Behavior = config.Behavior; + TriggerOnClose = config.Trigger.TriggerOnClose; + } + + void EsentialsRoomEmergencyContactClosure_StateChange(DigitalInput digitalInput, DigitalInputEventArgs args) + { + if (args.State && TriggerOnClose || !args.State && !TriggerOnClose) + RunEmergencyBehavior(); + } + + /// + /// + /// + public void RunEmergencyBehavior() + { + if (Behavior.Equals("shutdown")) + Room.Shutdown(); + } + } +} \ No newline at end of file diff --git a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs index 975c8661..5cba101d 100644 --- a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs +++ b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs @@ -1,7 +1,7 @@ -using System; -using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Room.Config; -namespace PDT.Plugins.Essentials.Rooms +namespace PepperDash.Essentials.Devices.Common.Rooms { public interface IEssentialsHuddleSpaceRoom : IEssentialsRoom, IHasCurrentSourceInfoChange, IRunRouteAction, IHasDefaultDisplay, IHasCurrentVolumeControls, IRoomOccupancy, IEmergency, IMicrophonePrivacy @@ -10,10 +10,6 @@ namespace PDT.Plugins.Essentials.Rooms void RunRouteAction(string routeKey); - // EssentialsHuddleRoomPropertiesConfig PropertiesConfig { get; } - - IBasicVolumeControls CurrentVolumeControls { get; } - - event EventHandler CurrentVolumeDeviceChange; + EssentialsHuddleRoomPropertiesConfig PropertiesConfig { get; } } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs index 65e2e357..9fe5db73 100644 --- a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs +++ b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs @@ -2,13 +2,14 @@ using PepperDash.Essentials.Devices.Common.AudioCodec; using PepperDash.Essentials.Devices.Common.Codec; using PepperDash.Essentials.Devices.Common.VideoCodec; +using PepperDash.Essentials.Room.Config; -namespace PDT.Plugins.Essentials.Rooms +namespace PepperDash.Essentials.Devices.Common.Rooms { public interface IEssentialsHuddleVtc1Room : IEssentialsRoom, IHasCurrentSourceInfoChange, IHasCurrentVolumeControls, IRunRouteAction, IRunDefaultCallRoute, IHasVideoCodec, IHasAudioCodec, IHasDefaultDisplay, IHasInCallFeedback, IRoomOccupancy, IEmergency, IMicrophonePrivacy { - // EssentialsHuddleVtc1PropertiesConfig PropertiesConfig { get; } + EssentialsHuddleVtc1PropertiesConfig PropertiesConfig { get; } bool ExcludeFromGlobalFunctions { get; } diff --git a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsTechRoom.cs b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsTechRoom.cs new file mode 100644 index 00000000..7f80c894 --- /dev/null +++ b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsTechRoom.cs @@ -0,0 +1,22 @@ +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.DeviceTypeInterfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PepperDash.Essentials.Devices.Common.Room +{ + public interface IEssentialsTechRoom:IEssentialsRoom, ITvPresetsProvider,IBridgeAdvanced,IRunDirectRouteAction + { + Dictionary Tuners { get; } + + Dictionary Displays { get; } + + void RoomPowerOn(); + + void RoomPowerOff(); + } +} From 4d608eef0642da82e0e10e343a3a086541f0b57e Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 08:44:58 -0600 Subject: [PATCH 21/31] feat: refactor LoadRooms method In order to facilitate using custom messengers, I added an interface, `IStandardMobileControl` that devices or rooms can implement if they should use the standard/existing MobileControl messengers. If a room or device wants to implement non-standard messengers, or is a new type of device that doesn't yet have a corresponding messenger in the Mobile Control plugin, do NOT implement this interface and MC won't attempt to build a messenger for it. --- .../DeviceTypeInterfaces/IMobileControl.cs | 7 ++ src/PepperDash.Essentials/ControlSystem.cs | 100 +++++------------- 2 files changed, 31 insertions(+), 76 deletions(-) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index 944e4a50..80e9cc8c 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -5,6 +5,13 @@ using PepperDash.Core; namespace PepperDash.Essentials.Core.DeviceTypeInterfaces { + /// + /// Use this interface on a device or room if it should use default Mobile Control messengers + /// + public interface IStandardMobileControl : IKeyed + { + } + /// /// Describes a MobileControlSystemController /// diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index d9836aba..7d4281bd 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -11,6 +11,9 @@ using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.DeviceTypeInterfaces; using PepperDash.Essentials.Core.Web; +using PepperDash.Essentials.Devices.Common.Room; +using PepperDash.Essentials.Devices.Common.Rooms; +using PepperDash.Essentials.Room.Config; using System; using System.Linq; @@ -468,103 +471,48 @@ namespace PepperDash.Essentials return; } - // uint fusionIpId = 0xf1; - foreach (var roomConfig in ConfigReader.ConfigObject.Rooms) { - /* - var room = EssentialsRoomConfigHelper.GetRoomObject(roomConfig) as IEssentialsRoom; - if (room != null) - { - // default to no join map key - string fusionJoinMapKey = string.Empty; + var room = Core.DeviceFactory.GetDevice(roomConfig); - if (room.Config.Properties["fusion"] != null) - { - Debug.Console(2, "Custom Fusion config found. Using custom values"); + DeviceManager.AddDevice(room); + if (!(room is IStandardMobileControl)) + { + continue; + } - var fusionConfig = room.Config.Properties["fusion"].ToObject(); - - if (fusionConfig != null) - { - fusionIpId = fusionConfig.IpIdInt; - fusionJoinMapKey = fusionConfig.JoinMapKey; - } - } - - AddRoomAndBuildMC(room); - - if (room is IEssentialsHuddleSpaceRoom) - { - - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Room is EssentialsHuddleSpaceRoom, attempting to add to DeviceManager with Fusion with IP-ID {0:X2}", fusionIpId); - DeviceManager.AddDevice(new Core.Fusion.EssentialsHuddleSpaceFusionSystemControllerBase(room, fusionIpId, fusionJoinMapKey)); - - } - else if (room is IEssentialsHuddleVtc1Room) - { - - if (!(room is EssentialsCombinedHuddleVtc1Room)) - { - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Room is EssentialsHuddleVtc1Room, attempting to add to DeviceManager with Fusion with IP-ID {0:X2}", fusionIpId); - DeviceManager.AddDevice(new EssentialsHuddleVtc1FusionController((IEssentialsHuddleVtc1Room)room, fusionIpId, fusionJoinMapKey)); - } - - } - else if (room is EssentialsTechRoom) - { - - Debug.Console(0, Debug.ErrorLogLevel.Notice, - "Room is EssentialsTechRoom, Attempting to add to DeviceManager with Fusion with IP-ID {0:X2}", fusionIpId); - DeviceManager.AddDevice(new EssentialsTechRoomFusionSystemController((EssentialsTechRoom)room, fusionIpId, fusionJoinMapKey)); - - } - fusionIpId += 1; - } - else - { - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Notice: Cannot create room from config, key '{0}' - Is this intentional? This may be a valid configuration.", roomConfig.Key); - - } - */ + BuildMC(room as IStandardMobileControl); } Debug.Console(0, Debug.ErrorLogLevel.Notice, "All Rooms Loaded."); } - private static void AddRoomAndBuildMC(IEssentialsRoom room) - { - DeviceManager.AddDevice(room); + private static void BuildMC(IStandardMobileControl room) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to build Mobile Control Bridge for "); - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to build Mobile Control Bridge"); - - CreateMobileControlBridge(room); + CreateMobileControlBridge(room as IEssentialsRoom); } - private static void CreateMobileControlBridge(object room) + private static void CreateMobileControlBridge(IEssentialsRoom room) { + if(room == null) + { + Debug.Console(0, Debug.ErrorLogLevel.Warning, $"Room does not implement IEssentialsRoom"); + return; + } + var mobileControl = GetMobileControlDevice(); - if (mobileControl == null) return; - - var mobileControl3 = mobileControl as IMobileControl3; - - if (mobileControl3 != null) - { - mobileControl3.CreateMobileControlRoomBridge(room as IEssentialsRoom, mobileControl); - } - else - { - mobileControl.CreateMobileControlRoomBridge(room as EssentialsRoomBase, mobileControl); - } + mobileControl?.CreateMobileControlRoomBridge(room, mobileControl); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Mobile Control Bridge Added..."); } - private static IMobileControl GetMobileControlDevice() + private static IMobileControl3 GetMobileControlDevice() { - var mobileControlList = DeviceManager.AllDevices.OfType().ToList(); + var mobileControlList = DeviceManager.AllDevices.OfType().ToList(); if (mobileControlList.Count > 1) { From b689c847fb1afe6653d5c0f6e2e68705325dbe0b Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 11:14:54 -0600 Subject: [PATCH 22/31] fix: invert interface to be custom instead of default This way, existing rooms and devices will build messengers by default, while new plugins can implement their own messengers --- .../DeviceTypeInterfaces/IMobileControl.cs | 4 ++-- .../Devices/EssentialsDevice.cs | 14 ++++++++++++++ src/PepperDash.Essentials/ControlSystem.cs | 10 +++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index 80e9cc8c..5e46f17f 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -6,9 +6,9 @@ using PepperDash.Core; namespace PepperDash.Essentials.Core.DeviceTypeInterfaces { /// - /// Use this interface on a device or room if it should use default Mobile Control messengers + /// Use this interface on a device or room if it uses custom Mobile Control messengers /// - public interface IStandardMobileControl : IKeyed + public interface ICustomMobileControl : IKeyed { } diff --git a/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs b/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs index 1846a512..cd9e3923 100644 --- a/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs +++ b/src/PepperDash.Essentials.Core/Devices/EssentialsDevice.cs @@ -48,6 +48,20 @@ namespace PepperDash.Essentials.Core } }); } + + public override bool CustomActivate() + { + CreateMobileControlMessengers(); + + return base.CustomActivate(); + } + + /// + /// Override this method to build and create custom Mobile Control Messengers during the Activation phase + /// + protected virtual void CreateMobileControlMessengers() { + + } } [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)] diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 7d4281bd..18cee177 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -476,23 +476,23 @@ namespace PepperDash.Essentials var room = Core.DeviceFactory.GetDevice(roomConfig); DeviceManager.AddDevice(room); - if (!(room is IStandardMobileControl)) + if (room is ICustomMobileControl) { continue; } - BuildMC(room as IStandardMobileControl); + BuildMC(room as IEssentialsRoom); } Debug.Console(0, Debug.ErrorLogLevel.Notice, "All Rooms Loaded."); } - private static void BuildMC(IStandardMobileControl room) + private static void BuildMC(IEssentialsRoom room) { - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Attempting to build Mobile Control Bridge for "); + Debug.Console(0, Debug.ErrorLogLevel.Notice, $"Attempting to build Mobile Control Bridge for {room?.Key}"); - CreateMobileControlBridge(room as IEssentialsRoom); + CreateMobileControlBridge(room); } private static void CreateMobileControlBridge(IEssentialsRoom room) From 9e7239b219a816fe355b993bb01247d1c393158e Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 12:32:45 -0600 Subject: [PATCH 23/31] chore: fix bad namespace Namespaces were not correct BREAKING_CHANGE: Namespaces changed --- .../Bridges/JoinMaps/GenericIrControllerJoinMap.cs | 2 +- .../Bridges/JoinMaps/HdPsXxxControllerJoinMap.cs | 2 +- .../Devices/GenericIRController.cs | 2 +- src/PepperDash.Essentials.Core/Devices/PduInterfaces.cs | 8 +++----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Bridges/JoinMaps/GenericIrControllerJoinMap.cs b/src/PepperDash.Essentials.Core/Bridges/JoinMaps/GenericIrControllerJoinMap.cs index 288141bb..388e6ac1 100644 --- a/src/PepperDash.Essentials.Core/Bridges/JoinMaps/GenericIrControllerJoinMap.cs +++ b/src/PepperDash.Essentials.Core/Bridges/JoinMaps/GenericIrControllerJoinMap.cs @@ -1,6 +1,6 @@ using PepperDash.Essentials.Core; -namespace PepperDash_Essentials_Core.Bridges.JoinMaps +namespace PepperDash.Essentials.Core.Bridges.JoinMaps { public sealed class GenericIrControllerJoinMap : JoinMapBaseAdvanced { diff --git a/src/PepperDash.Essentials.Core/Bridges/JoinMaps/HdPsXxxControllerJoinMap.cs b/src/PepperDash.Essentials.Core/Bridges/JoinMaps/HdPsXxxControllerJoinMap.cs index 3f2901c9..04d75d41 100644 --- a/src/PepperDash.Essentials.Core/Bridges/JoinMaps/HdPsXxxControllerJoinMap.cs +++ b/src/PepperDash.Essentials.Core/Bridges/JoinMaps/HdPsXxxControllerJoinMap.cs @@ -1,7 +1,7 @@ using System; using PepperDash.Essentials.Core; -namespace PepperDash_Essentials_Core.Bridges +namespace PepperDash.Essentials.Core.Bridges { public class HdPsXxxControllerJoinMap : JoinMapBaseAdvanced { diff --git a/src/PepperDash.Essentials.Core/Devices/GenericIRController.cs b/src/PepperDash.Essentials.Core/Devices/GenericIRController.cs index b7c15fce..d0c6a61b 100644 --- a/src/PepperDash.Essentials.Core/Devices/GenericIRController.cs +++ b/src/PepperDash.Essentials.Core/Devices/GenericIRController.cs @@ -8,7 +8,7 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Config; -using PepperDash_Essentials_Core.Bridges.JoinMaps; +using PepperDash.Essentials.Core.Bridges.JoinMaps; namespace PepperDash.Essentials.Core.Devices { diff --git a/src/PepperDash.Essentials.Core/Devices/PduInterfaces.cs b/src/PepperDash.Essentials.Core/Devices/PduInterfaces.cs index 94aa71ac..1c0431b5 100644 --- a/src/PepperDash.Essentials.Core/Devices/PduInterfaces.cs +++ b/src/PepperDash.Essentials.Core/Devices/PduInterfaces.cs @@ -4,12 +4,11 @@ using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; -namespace PepperDash_Essentials_Core.Devices +namespace PepperDash.Essentials.Core.Devices { /// /// Interface for any device that is able to control it'spower and has a configurable reboot time - /// - [Obsolete("PepperDash_Essentials_Core.Devices is Deprecated - use PepperDash.Essentials.Core")] + /// public interface IHasPowerCycle : IKeyName, IHasPowerControlWithFeedback { /// @@ -25,8 +24,7 @@ namespace PepperDash_Essentials_Core.Devices /// /// Interface for any device that contains a collection of IHasPowerReboot Devices - /// - [Obsolete("PepperDash_Essentials_Core.Devices is Deprecated - use PepperDash.Essentials.Core")] + /// public interface IHasControlledPowerOutlets : IKeyName { /// From 4d20cd7e80aa576aababedcd1e9125ce0ebc751d Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 12:32:59 -0600 Subject: [PATCH 24/31] chore: fix namespaces for room interfaces to be consistent --- .../Room/IEssentialsHuddleSpaceRoom.cs | 2 +- .../Room/IEssentialsHuddleVtc1Room.cs | 2 +- .../Room/IEssentialsTechRoom.cs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs index 5cba101d..1af09f1c 100644 --- a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs +++ b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleSpaceRoom.cs @@ -1,7 +1,7 @@ using PepperDash.Essentials.Core; using PepperDash.Essentials.Room.Config; -namespace PepperDash.Essentials.Devices.Common.Rooms +namespace PepperDash.Essentials.Devices.Common.Room { public interface IEssentialsHuddleSpaceRoom : IEssentialsRoom, IHasCurrentSourceInfoChange, IRunRouteAction, IHasDefaultDisplay, IHasCurrentVolumeControls, IRoomOccupancy, IEmergency, IMicrophonePrivacy diff --git a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs index 9fe5db73..b7f1a619 100644 --- a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs +++ b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsHuddleVtc1Room.cs @@ -4,7 +4,7 @@ using PepperDash.Essentials.Devices.Common.Codec; using PepperDash.Essentials.Devices.Common.VideoCodec; using PepperDash.Essentials.Room.Config; -namespace PepperDash.Essentials.Devices.Common.Rooms +namespace PepperDash.Essentials.Devices.Common.Room { public interface IEssentialsHuddleVtc1Room : IEssentialsRoom, IHasCurrentSourceInfoChange, IHasCurrentVolumeControls, IRunRouteAction, IRunDefaultCallRoute, IHasVideoCodec, IHasAudioCodec, IHasDefaultDisplay, IHasInCallFeedback, IRoomOccupancy, IEmergency, IMicrophonePrivacy diff --git a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsTechRoom.cs b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsTechRoom.cs index 7f80c894..947be5d9 100644 --- a/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsTechRoom.cs +++ b/src/PepperDash.Essentials.Devices.Common/Room/IEssentialsTechRoom.cs @@ -1,16 +1,16 @@ using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.DeviceTypeInterfaces; -using System; +using PepperDash.Essentials.Room.Config; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using TwoWayDisplayBase = PepperDash.Essentials.Devices.Common.Displays.TwoWayDisplayBase; + namespace PepperDash.Essentials.Devices.Common.Room { public interface IEssentialsTechRoom:IEssentialsRoom, ITvPresetsProvider,IBridgeAdvanced,IRunDirectRouteAction { + EssentialsTechRoomConfig PropertiesConfig { get; } Dictionary Tuners { get; } Dictionary Displays { get; } From 5ce82f03b4bdcb8aaa287c6eb0207451e4e4e19a Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 12:43:13 -0600 Subject: [PATCH 25/31] feat: move LightingBase to Devices Common --- .../Lighting/LightingBase.cs | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 src/PepperDash.Essentials.Devices.Common/Lighting/LightingBase.cs diff --git a/src/PepperDash.Essentials.Devices.Common/Lighting/LightingBase.cs b/src/PepperDash.Essentials.Devices.Common/Lighting/LightingBase.cs new file mode 100644 index 00000000..12b027b3 --- /dev/null +++ b/src/PepperDash.Essentials.Devices.Common/Lighting/LightingBase.cs @@ -0,0 +1,142 @@ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro.DeviceSupport; +using Newtonsoft.Json; +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Lighting; + +namespace PepperDash.Essentials.Devices.Common.Lighting +{ + [Obsolete("Please use PepperDash.Essentials.Devices.Common, this will be removed in 2.1")] + public abstract class LightingBase : EssentialsBridgeableDevice, ILightingScenes + { + #region ILightingScenes Members + + public event EventHandler LightingSceneChange; + + public List LightingScenes { get; protected set; } + + public LightingScene CurrentLightingScene { get; protected set; } + + public IntFeedback CurrentLightingSceneFeedback { get; protected set; } + + #endregion + + protected LightingBase(string key, string name) + : base(key, name) + { + LightingScenes = new List(); + + CurrentLightingScene = new LightingScene(); + //CurrentLightingSceneFeedback = new IntFeedback(() => { return int.Parse(this.CurrentLightingScene.ID); }); + } + + public abstract void SelectScene(LightingScene scene); + + public void SimulateSceneSelect(string sceneName) + { + Debug.Console(1, this, "Simulating selection of scene '{0}'", sceneName); + + var scene = LightingScenes.FirstOrDefault(s => s.Name.Equals(sceneName)); + + if (scene != null) + { + CurrentLightingScene = scene; + OnLightingSceneChange(); + } + } + + /// + /// Sets the IsActive property on each scene and fires the LightingSceneChange event + /// + protected void OnLightingSceneChange() + { + foreach (var scene in LightingScenes) + { + if (scene == CurrentLightingScene) + scene.IsActive = true; + + else + scene.IsActive = false; + } + + var handler = LightingSceneChange; + if (handler != null) + { + handler(this, new LightingSceneChangeEventArgs(CurrentLightingScene)); + } + } + + protected GenericLightingJoinMap LinkLightingToApi(LightingBase lightingDevice, BasicTriList trilist, uint joinStart, + string joinMapKey, EiscApiAdvanced bridge) + { + var joinMap = new GenericLightingJoinMap(joinStart); + + var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey); + + if (!string.IsNullOrEmpty(joinMapSerialized)) + joinMap = JsonConvert.DeserializeObject(joinMapSerialized); + + if (bridge != null) + { + bridge.AddJoinMap(Key, joinMap); + } + else + { + Debug.Console(0, this, "Please update config to use 'eiscapiadvanced' to get all join map features for this device."); + } + + return LinkLightingToApi(lightingDevice, trilist, joinMap); + } + + protected GenericLightingJoinMap LinkLightingToApi(LightingBase lightingDevice, BasicTriList trilist, GenericLightingJoinMap joinMap) + { + Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X")); + + Debug.Console(0, "Linking to Lighting Type {0}", lightingDevice.GetType().Name.ToString()); + + // GenericLighitng Actions & FeedBack + trilist.SetUShortSigAction(joinMap.SelectScene.JoinNumber, u => lightingDevice.SelectScene(lightingDevice.LightingScenes[u])); + + var sceneIndex = 0; + foreach (var scene in lightingDevice.LightingScenes) + { + var index = sceneIndex; + + trilist.SetSigTrueAction((uint)(joinMap.SelectSceneDirect.JoinNumber + index), () => lightingDevice.SelectScene(lightingDevice.LightingScenes[index])); + scene.IsActiveFeedback.LinkInputSig(trilist.BooleanInput[(uint)(joinMap.SelectSceneDirect.JoinNumber + index)]); + trilist.StringInput[(uint)(joinMap.SelectSceneDirect.JoinNumber + index)].StringValue = scene.Name; + trilist.BooleanInput[(uint)(joinMap.ButtonVisibility.JoinNumber + index)].BoolValue = true; + + sceneIndex++; + } + + trilist.OnlineStatusChange += (sender, args) => + { + if (!args.DeviceOnLine) return; + + sceneIndex = 0; + foreach (var scene in lightingDevice.LightingScenes) + { + var index = sceneIndex; + + trilist.StringInput[(uint) (joinMap.SelectSceneDirect.JoinNumber + index)].StringValue = scene.Name; + trilist.BooleanInput[(uint) (joinMap.ButtonVisibility.JoinNumber + index)].BoolValue = true; + scene.IsActiveFeedback.FireUpdate(); + + sceneIndex++; + } + }; + + return joinMap; + } + } +} \ No newline at end of file From f7cf85496574809fd3cc220bbae992424b1d6cd5 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 7 Feb 2024 12:43:30 -0600 Subject: [PATCH 26/31] fix: remove incorrect using statement --- src/PepperDash.Essentials/ControlSystem.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PepperDash.Essentials/ControlSystem.cs b/src/PepperDash.Essentials/ControlSystem.cs index 18cee177..34bd30d9 100644 --- a/src/PepperDash.Essentials/ControlSystem.cs +++ b/src/PepperDash.Essentials/ControlSystem.cs @@ -12,7 +12,6 @@ using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.DeviceTypeInterfaces; using PepperDash.Essentials.Core.Web; using PepperDash.Essentials.Devices.Common.Room; -using PepperDash.Essentials.Devices.Common.Rooms; using PepperDash.Essentials.Room.Config; using System; using System.Linq; From 420ae8c7decc69ed6ddff0b863ca0bdba1de0f0f Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 8 Feb 2024 09:26:29 -0600 Subject: [PATCH 27/31] refactor: add UpdateAppUrl method to RoomMessenger interface Also renamed the interface to more accurately represent what it is for --- .../DeviceTypeInterfaces/IMobileControl.cs | 4 +++- src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs | 4 ++-- src/PepperDash.Essentials.Core/Room/IEssentialsRoom.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs index 5e46f17f..1ca53f67 100644 --- a/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs +++ b/src/PepperDash.Essentials.Core/DeviceTypeInterfaces/IMobileControl.cs @@ -64,7 +64,7 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces /// /// Describes a MobileControl Room Bridge /// - public interface IMobileControlRoomBridge : IKeyed + public interface IMobileControlRoomMessenger : IKeyed { event EventHandler UserCodeChanged; @@ -85,5 +85,7 @@ namespace PepperDash.Essentials.Core.DeviceTypeInterfaces string RoomName { get; } string AppUrl { get; } + + void UpdateAppUrl(string url); } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs b/src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs index abfc34b8..d3b78112 100644 --- a/src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs +++ b/src/PepperDash.Essentials.Core/Room/EssentialsRoomBase.cs @@ -58,7 +58,7 @@ namespace PepperDash.Essentials.Core /// /// The bridge for this room if Mobile Control is enabled /// - public IMobileControlRoomBridge MobileControlRoomBridge { get; private set; } + public IMobileControlRoomMessenger MobileControlRoomBridge { get; private set; } /// /// The config name of the source list @@ -209,7 +209,7 @@ namespace PepperDash.Essentials.Core } else { - MobileControlRoomBridge = mcBridge as IMobileControlRoomBridge; + MobileControlRoomBridge = mcBridge as IMobileControlRoomMessenger; Debug.Console(1, this, "*********************Mobile Control Bridge found and enabled for this room"); IsMobileControlEnabled = true; } diff --git a/src/PepperDash.Essentials.Core/Room/IEssentialsRoom.cs b/src/PepperDash.Essentials.Core/Room/IEssentialsRoom.cs index 9a70f980..d14a46be 100644 --- a/src/PepperDash.Essentials.Core/Room/IEssentialsRoom.cs +++ b/src/PepperDash.Essentials.Core/Room/IEssentialsRoom.cs @@ -23,7 +23,7 @@ namespace PepperDash.Essentials.Core BoolFeedback IsCoolingDownFeedback { get; } bool IsMobileControlEnabled { get; } - IMobileControlRoomBridge MobileControlRoomBridge { get; } + IMobileControlRoomMessenger MobileControlRoomBridge { get; } string SourceListKey { get; } From e0e08ba22c4fea94fe42c8922293f83c0768156d Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 14 Feb 2024 13:02:09 -0600 Subject: [PATCH 28/31] feat: add methods to add routes to API --- .../Web/EssentialsWebApi.cs | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs index 3030cd81..06d5f6c0 100644 --- a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs +++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs @@ -11,7 +11,7 @@ namespace PepperDash.Essentials.Core.Web { public class EssentialsWebApi : EssentialsDevice { - private readonly WebApiServer _server; + private readonly WebApiServer _server; /// /// http(s)://{ipaddress}/cws/{basePath} @@ -67,8 +67,6 @@ namespace PepperDash.Essentials.Core.Web _server = new WebApiServer(Key, Name, BasePath); SetupRoutes(); - - Initialize(); } private void SetupRoutes() @@ -175,6 +173,27 @@ namespace PepperDash.Essentials.Core.Web } } + /// + /// Add a single route to the API. MUST be done during the activation phase + /// + /// + public void AddRoute(HttpCwsRoute route) + { + _server.AddRoute(route); + } + + /// + /// Add a collection of routes to the API. MUST be done during the activation phase + /// + /// + public void AddRoute(List routes) + { + foreach (var route in routes) + { + AddRoute(route); + } + } + /// /// Initializes the CWS class /// From b213262cdddc0a532e1150049975ebf040f3443a Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 14 Feb 2024 13:04:36 -0600 Subject: [PATCH 29/31] refactor: use new method by default --- src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs index 06d5f6c0..165b9c21 100644 --- a/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs +++ b/src/PepperDash.Essentials.Core/Web/EssentialsWebApi.cs @@ -166,11 +166,7 @@ namespace PepperDash.Essentials.Core.Web }; - foreach (var route in routes.Where(route => route != null)) - { - var r = route; - _server.AddRoute(r); - } + AddRoute(routes); } /// From 06244b8a18386a9c57c03713fa18af63c49ec9dc Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 14 Feb 2024 15:54:42 -0600 Subject: [PATCH 30/31] build: update PepperDash Core --- .../PepperDash.Essentials.Core.csproj | 2 +- .../PepperDash.Essentials.Devices.Common.csproj | 2 +- src/PepperDash.Essentials/PepperDash.Essentials.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index c9ede78c..940d7289 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 87d4c76c..5c410a23 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -27,6 +27,6 @@ - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index f7a72689..ae3645ec 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -47,7 +47,7 @@ - + From 6c2ef7b63bdd2cfbe0b54ef2b634bd651dc13111 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 15 Feb 2024 16:40:25 -0600 Subject: [PATCH 31/31] chore: update PepperDash Core version --- .../PepperDash.Essentials.Core.csproj | 2 +- .../PepperDash.Essentials.Devices.Common.csproj | 2 +- src/PepperDash.Essentials/PepperDash.Essentials.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj index 940d7289..cae9e659 100644 --- a/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj +++ b/src/PepperDash.Essentials.Core/PepperDash.Essentials.Core.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj index 5c410a23..12370935 100644 --- a/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj +++ b/src/PepperDash.Essentials.Devices.Common/PepperDash.Essentials.Devices.Common.csproj @@ -27,6 +27,6 @@ - + \ No newline at end of file diff --git a/src/PepperDash.Essentials/PepperDash.Essentials.csproj b/src/PepperDash.Essentials/PepperDash.Essentials.csproj index ae3645ec..f8e6108f 100644 --- a/src/PepperDash.Essentials/PepperDash.Essentials.csproj +++ b/src/PepperDash.Essentials/PepperDash.Essentials.csproj @@ -47,7 +47,7 @@ - +