diff --git a/PepperDashEssentials/AppServer/CotijaSystemController.cs b/PepperDashEssentials/AppServer/CotijaSystemController.cs index 75592e38..1e74efe0 100644 --- a/PepperDashEssentials/AppServer/CotijaSystemController.cs +++ b/PepperDashEssentials/AppServer/CotijaSystemController.cs @@ -679,13 +679,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 { @@ -702,6 +703,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/AppServer/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs b/PepperDashEssentials/AppServer/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs index eef8e167..4fd75a36 100644 --- a/PepperDashEssentials/AppServer/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs +++ b/PepperDashEssentials/AppServer/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs @@ -417,7 +417,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, ""); } diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 4b75f046..8124beb7 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -1,10 +1,12 @@ 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; @@ -21,6 +23,8 @@ namespace PepperDash.Essentials { HttpLogoServer LogoServer; + List FactoryObjects = new List(); + public ControlSystem() : base() { @@ -137,15 +141,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 +184,51 @@ namespace PepperDash.Essentials } + /// + /// Initial simple implementation. Reads user/programN/plugins folder and + /// use + /// + void LoadPlugins() + { + 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) + { + // TODO COPY plugin to loadedPlugins folder + + // TODO LOAD that loadedPlugins dll file + + var assy = Assembly.LoadFrom(fi.FullName); + 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) + { + 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 + } + } + } + /// /// Verifies filesystem is set up. IR, SGD, and programX folders /// @@ -203,14 +251,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"); @@ -274,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") { @@ -303,6 +358,20 @@ namespace PepperDash.Essentials newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf); 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) DeviceManager.AddDevice(newDev); else 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 d2326163..75c2bf81 160000 --- a/essentials-framework +++ b/essentials-framework @@ -1 +1 @@ -Subproject commit d23261633943f87c4f8c7568f285f5de2a839667 +Subproject commit 75c2bf819a3b7e6c37a3d6b0c7b11cc273043b12