From 47675f12b45de3e9b8a77c003fb5ddbb6ce95498 Mon Sep 17 00:00:00 2001 From: Heath Volmer Date: Mon, 26 Nov 2018 09:03:23 -0700 Subject: [PATCH 1/7] Added CsmQmtdc2504CnController, incomplete --- essentials-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/essentials-framework b/essentials-framework index 98f2cfc6..f9747d73 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit 98f2cfc64a4f294cc8ed2b27134c34bb8405bde6 +Subproject commit f9747d73346cbc25c2107e9e8a5afd478935c2a6 From 44b72dcfe5504aa7386d8de9c15513f384fed8ed Mon Sep 17 00:00:00 2001 From: Heath Volmer Date: Thu, 16 May 2019 13:00:48 -0600 Subject: [PATCH 2/7] Volume control fix --- .../RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PepperDashEssentials/AppServer/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs b/PepperDashEssentials/AppServer/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs index 976cb484..525983fe 100644 --- a/PepperDashEssentials/AppServer/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs +++ b/PepperDashEssentials/AppServer/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs @@ -416,7 +416,7 @@ namespace PepperDash.Essentials if (rmVc != null) { var vc = rmVc.CurrentVolumeControls as IBasicVolumeWithFeedback; - if (rmVc != null) + if (vc != null) { volumes.Master = new Volume("master", vc.VolumeLevelFeedback.UShortValue, vc.MuteFeedback.BoolValue, "Volume", true, ""); } From 727367c0618ab7729da1e07054697131661e5b64 Mon Sep 17 00:00:00 2001 From: Heath Volmer Date: Thu, 16 May 2019 17:29:38 -0600 Subject: [PATCH 3/7] Changes for PoC plugin loading... --- PepperDashEssentials/ControlSystem.cs | 59 +++++++++++++++++++++++++-- essentials-framework | 2 +- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 8463390a..82d9d14b 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -1,14 +1,17 @@ using System; +using System.Collections.Generic; using System.Linq; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.CrestronThread; using Crestron.SimplSharpPro.Diagnostics; +using Crestron.SimplSharp.Reflection; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.Core.Factory; using PepperDash.Essentials.Devices.Common; using PepperDash.Essentials.DM; using PepperDash.Essentials.Fusion; @@ -21,6 +24,8 @@ namespace PepperDash.Essentials { HttpLogoServer LogoServer; + List FactoryObjects = new List(); + public ControlSystem() : base() { @@ -137,15 +142,14 @@ namespace PepperDash.Essentials { try { - CrestronConsole.AddNewConsoleCommand(EnablePortalSync, "portalsync", "Loads Portal Sync", - ConsoleAccessLevelEnum.AccessOperator); - - //PortalSync = new PepperDashPortalSyncClient(); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials load from configuration"); var filesReady = SetupFilesystem(); if (filesReady) { + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Checking for plugins"); + LoadPlugins(); + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Folder structure verified. Loading config..."); if (!ConfigReader.LoadConfig2()) return; @@ -181,6 +185,42 @@ namespace PepperDash.Essentials } + /// + /// Initial simple implementation. Reads user/programN/plugins folder and + /// use + /// + void LoadPlugins() + { + var dir = Global.FilePathPrefix + "plugins"; + if (Directory.Exists(dir)) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Plugins directory found, checking for factory plugins"); + var di = new DirectoryInfo(dir); + var files = di.GetFiles("*.dll"); + foreach (FileInfo fi in files) + { + Debug.Console(0, "Checking file '{0}' for factory", fi.Name); + var assy = Assembly.LoadFrom(fi.FullName); + //var types = assy.GetTypes(); + //foreach (var t in types) + //{ + // Debug.Console(0, "{0}", t.FullName); + //} + var type = assy.GetType("PepperDash.Essentials.Plugin.Factory"); + var factory = Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); + if (factory is PepperDash.Essentials.Core.Factory.IGetCrestronDevice) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loaded '{0}' for Crestron device(s)", fi.Name); + FactoryObjects.Add(factory); + } + else + { + Debug.Console(0, "Plugin '{0}' does not conform to any loadable types. Ignoring", fi.Name); + } + } + } + } + /// /// Verifies filesystem is set up. IR, SGD, and programX folders /// @@ -303,6 +343,17 @@ namespace PepperDash.Essentials newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf); if (newDev == null) newDev = PepperDash.Essentials.BridgeFactory.GetDevice(devConf); + // iterate plugin factories + foreach (var f in FactoryObjects) + { + var cresFactory = f as IGetCrestronDevice; + if (cresFactory != null) + { + newDev = cresFactory.GetDevice(devConf, this); + } + } + + if (newDev != null) DeviceManager.AddDevice(newDev); else diff --git a/essentials-framework b/essentials-framework index c40f3b40..7de16a18 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit c40f3b40d57a82b9191d4f8f6dbf89a4756af4e4 +Subproject commit 7de16a1826fa794d2c03361811033d4e38970a84 From 697b9109a37ba751f438b699bd13714d3be6dcd7 Mon Sep 17 00:00:00 2001 From: Heath Volmer Date: Fri, 17 May 2019 09:14:18 -0600 Subject: [PATCH 4/7] Modifications to plugin load and factories --- .../AppServer/CotijaSystemController.cs | 22 ++++++--- PepperDashEssentials/ControlSystem.cs | 45 +++++++++++-------- essentials-framework | 2 +- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/PepperDashEssentials/AppServer/CotijaSystemController.cs b/PepperDashEssentials/AppServer/CotijaSystemController.cs index 5fd5e958..1f5fa0ff 100644 --- a/PepperDashEssentials/AppServer/CotijaSystemController.cs +++ b/PepperDashEssentials/AppServer/CotijaSystemController.cs @@ -99,6 +99,8 @@ namespace PepperDash.Essentials CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler); CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler); + + } @@ -668,13 +670,14 @@ namespace PepperDash.Essentials if(string.IsNullOrEmpty(message)) return; - if (!message.Contains("/system/heartbeat")) - Debug.Console(1, this, "Message RX: {0}", message); - else - { - LastAckMessage = DateTime.Now; - //Debug.Console(1, this, "RX message contains /system/heartbeat"); - } + if (!message.Contains("/system/heartbeat")) + { + Debug.Console(1, this, "Message RX: {0}", message); + } + else + { + LastAckMessage = DateTime.Now; + } try { @@ -691,6 +694,11 @@ namespace PepperDash.Essentials { HandleHeartBeat(messageObj["content"]); } + else if (type == "raw") + { + var wrapper = messageObj["content"].ToObject(); + DeviceJsonApi.DoDeviceAction(wrapper); + } else if (type == "close") { Debug.Console(1, this, "Received close message from server."); diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 82d9d14b..ae2bdcd7 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -201,11 +201,6 @@ namespace PepperDash.Essentials { Debug.Console(0, "Checking file '{0}' for factory", fi.Name); var assy = Assembly.LoadFrom(fi.FullName); - //var types = assy.GetTypes(); - //foreach (var t in types) - //{ - // Debug.Console(0, "{0}", t.FullName); - //} var type = assy.GetType("PepperDash.Essentials.Plugin.Factory"); var factory = Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); if (factory is PepperDash.Essentials.Core.Factory.IGetCrestronDevice) @@ -215,7 +210,9 @@ namespace PepperDash.Essentials } else { - Debug.Console(0, "Plugin '{0}' does not conform to any loadable types. Ignoring", fi.Name); + Debug.Console(0, Debug.ErrorLogLevel.Warning, + "Plugin '{0}' does not conform to any loadable types. DLL should be removed from plugins folder. Ignoring", + fi.Name); } } } @@ -243,14 +240,21 @@ namespace PepperDash.Essentials return configExists; } - public void EnablePortalSync(string s) - { - if (s.ToLower() == "enable") - { - CrestronConsole.ConsoleCommandResponse("Portal Sync features enabled"); - } - } + ///// + ///// + ///// + ///// + //public void EnablePortalSync(string s) + //{ + // if (s.ToLower() == "enable") + // { + // CrestronConsole.ConsoleCommandResponse("Portal Sync features enabled"); + // } + //} + /// + /// + /// public void TearDown() { Debug.Console(0, "Tearing down existing system"); @@ -343,17 +347,20 @@ namespace PepperDash.Essentials newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf); if (newDev == null) newDev = PepperDash.Essentials.BridgeFactory.GetDevice(devConf); - // iterate plugin factories - foreach (var f in FactoryObjects) + + if (newDev == null) // might want to consider the ability to override an essentials "type" { - var cresFactory = f as IGetCrestronDevice; - if (cresFactory != null) + // iterate plugin factories + foreach (var f in FactoryObjects) { - newDev = cresFactory.GetDevice(devConf, this); + var cresFactory = f as IGetCrestronDevice; + if (cresFactory != null) + { + newDev = cresFactory.GetDevice(devConf, this); + } } } - if (newDev != null) DeviceManager.AddDevice(newDev); else diff --git a/essentials-framework b/essentials-framework index 7de16a18..adc687ef 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit 7de16a1826fa794d2c03361811033d4e38970a84 +Subproject commit adc687ef860c0f1d4a3e44c02cb76de12faaa5d3 From 95c0f570008be87d594267d71a664b7f03733951 Mon Sep 17 00:00:00 2001 From: Heath Volmer Date: Tue, 21 May 2019 13:58:57 -0600 Subject: [PATCH 5/7] Plugin loading! --- PepperDashEssentials/ControlSystem.cs | 63 +++++++++++-------- .../Properties/AssemblyInfo.cs | 2 +- essentials-framework | 2 +- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index ae2bdcd7..ebfd5f4a 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -11,7 +11,6 @@ using Crestron.SimplSharp.Reflection; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; -using PepperDash.Essentials.Core.Factory; using PepperDash.Essentials.Devices.Common; using PepperDash.Essentials.DM; using PepperDash.Essentials.Fusion; @@ -194,26 +193,38 @@ namespace PepperDash.Essentials var dir = Global.FilePathPrefix + "plugins"; if (Directory.Exists(dir)) { + // TODO Clear out or create localPlugins folder (maybe in program slot folder) + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Plugins directory found, checking for factory plugins"); var di = new DirectoryInfo(dir); var files = di.GetFiles("*.dll"); foreach (FileInfo fi in files) { - Debug.Console(0, "Checking file '{0}' for factory", fi.Name); + // TODO COPY plugin to loadedPlugins folder + + // TODO LOAD that loadedPlugins dll file + var assy = Assembly.LoadFrom(fi.FullName); - var type = assy.GetType("PepperDash.Essentials.Plugin.Factory"); - var factory = Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); - if (factory is PepperDash.Essentials.Core.Factory.IGetCrestronDevice) + var ver = assy.GetName().Version; + var verStr = string.Format("{0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision); + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loaded plugin file '{0}', version {1}", fi.FullName, verStr); + + // iteratate this assembly's classes, looking for "LoadPlugin()" methods + var types = assy.GetTypes(); + foreach (var type in types) { - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loaded '{0}' for Crestron device(s)", fi.Name); - FactoryObjects.Add(factory); - } - else - { - Debug.Console(0, Debug.ErrorLogLevel.Warning, - "Plugin '{0}' does not conform to any loadable types. DLL should be removed from plugins folder. Ignoring", - fi.Name); + var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static); + var loadPlugin = methods.FirstOrDefault(m => m.Name.Equals("LoadPlugin")); + if (loadPlugin != null) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Adding type {0}", fi.FullName, type.FullName); + loadPlugin.Invoke(null, null); + } + } + + // plugin dll will be loaded. Any classes in plugin should have a static constructor + // that registers that class with the Core.DeviceFactory } } } @@ -318,7 +329,7 @@ namespace PepperDash.Essentials try { - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Creating device '{0}'", devConf.Key); + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Creating device '{0}', type '{1}'", devConf.Key, devConf.Type); // Skip this to prevent unnecessary warnings if (devConf.Key == "processor") { @@ -348,18 +359,18 @@ namespace PepperDash.Essentials if (newDev == null) newDev = PepperDash.Essentials.BridgeFactory.GetDevice(devConf); - if (newDev == null) // might want to consider the ability to override an essentials "type" - { - // iterate plugin factories - foreach (var f in FactoryObjects) - { - var cresFactory = f as IGetCrestronDevice; - if (cresFactory != null) - { - newDev = cresFactory.GetDevice(devConf, this); - } - } - } + //if (newDev == null) // might want to consider the ability to override an essentials "type" + //{ + // // iterate plugin factories + // foreach (var f in FactoryObjects) + // { + // var cresFactory = f as IGetCrestronDevice; + // if (cresFactory != null) + // { + // newDev = cresFactory.GetDevice(devConf, this); + // } + // } + //} if (newDev != null) DeviceManager.AddDevice(newDev); diff --git a/PepperDashEssentials/Properties/AssemblyInfo.cs b/PepperDashEssentials/Properties/AssemblyInfo.cs index 97d14f56..83beada4 100644 --- a/PepperDashEssentials/Properties/AssemblyInfo.cs +++ b/PepperDashEssentials/Properties/AssemblyInfo.cs @@ -4,5 +4,5 @@ [assembly: AssemblyCompany("PepperDash Technology Corp")] [assembly: AssemblyProduct("PepperDashEssentials")] [assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2018")] -[assembly: AssemblyVersion("1.3.2.*")] +[assembly: AssemblyVersion("1.4.0.*")] diff --git a/essentials-framework b/essentials-framework index adc687ef..15205a78 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit adc687ef860c0f1d4a3e44c02cb76de12faaa5d3 +Subproject commit 15205a78cb051c9b18f03e816915e81d4c18b450 From ecce6e2be91d2bf76152528a54f2350eeb6da0d0 Mon Sep 17 00:00:00 2001 From: Heath Volmer Date: Tue, 21 May 2019 15:26:43 -0600 Subject: [PATCH 6/7] Framework... --- essentials-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/essentials-framework b/essentials-framework index 15205a78..e5c6a0a8 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit 15205a78cb051c9b18f03e816915e81d4c18b450 +Subproject commit e5c6a0a8621d3e206d056b9ee7ffb9d47036193e From d705525a45d1964c9176637ac4ec53e066ece9fc Mon Sep 17 00:00:00 2001 From: Heath Volmer Date: Wed, 22 May 2019 09:27:17 -0600 Subject: [PATCH 7/7] Framework at development after merges --- essentials-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/essentials-framework b/essentials-framework index e5c6a0a8..75c2bf81 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit e5c6a0a8621d3e206d056b9ee7ffb9d47036193e +Subproject commit 75c2bf819a3b7e6c37a3d6b0c7b11cc273043b12