From 563f690277674b19e90f94697ad1c7c0ef9332ef Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Mon, 20 Apr 2020 12:21:18 -0600 Subject: [PATCH 01/10] adds try/catch for Null Reference Exceptions --- PepperDashEssentials/Bridges/EiscBridge.cs | 11 ++++++++++- .../PepperDashEssentialsBase/Plugins/PluginLoader.cs | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/PepperDashEssentials/Bridges/EiscBridge.cs b/PepperDashEssentials/Bridges/EiscBridge.cs index ed28bbfe..fe592e45 100644 --- a/PepperDashEssentials/Bridges/EiscBridge.cs +++ b/PepperDashEssentials/Bridges/EiscBridge.cs @@ -56,7 +56,16 @@ namespace PepperDash.Essentials.Bridges Debug.Console(2, this, "'{0}' is IBridgeAdvanced", device.Key); var advDev = device as IBridgeAdvanced; - advDev.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, null); + + try + { + advDev.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, null); + } + catch (NullReferenceException) + { + Debug.ConsoleWithLog(0, this, + "Please update the bridge config to use EiscBridgeAdvanced with this device: {0}", device.Key); + } //if (device.GetType().GetCType().IsAssignableFrom(typeof (IBridge))) //{ // var bridge = device as IBridge; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs index c0d84714..3e08d698 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs @@ -360,7 +360,8 @@ namespace PepperDash.Essentials } catch (Exception e) { - Debug.Console(2, "Load Plugin not found. {0} is not a plugin assembly. Exception: {1}", loadedAssembly.Name, e); + Debug.Console(2, "Load Plugin not found. {0}.{2} is not a plugin factory. Exception: {1}", + loadedAssembly.Name, e, type.Name); continue; } From c5232ca6b8ae992e65e2ffe85abfbaecbbad3343 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Wed, 15 Apr 2020 18:07:22 -0600 Subject: [PATCH 02/10] Updates device factory methodology for Essentials Core and Essential DM libraries --- PepperDashEssentials/ControlSystem.cs | 3 +- .../Crestron IO/C2nRts/C2nRthsController.cs | 25 +++++- .../Inputs/CenIoDigIn104Controller.cs | 23 ++++- .../StatusSign/StatusSignController.cs | 22 ++++- .../Devices/EssentialsDevice.cs | 2 +- .../Factory/DeviceFactory.cs | 44 +++------ .../AirMedia/AirMediaController.cs | 25 ++++++ .../Chassis/DmChassisController.cs | 40 ++++++++- .../Essentials_DM/Config/DeviceFactory.cs | 90 ++++--------------- .../DmLite/HdMdxxxCEController.cs | 37 ++++++++ .../Endpoints/Receivers/DmRmcHelper.cs | 22 +++++ .../Endpoints/Transmitters/DmTxHelpers.cs | 33 +++++-- 12 files changed, 242 insertions(+), 124 deletions(-) diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 3357a464..db10c959 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -365,10 +365,9 @@ namespace PepperDash.Essentials // Then associated library factories if (newDev == null) newDev = PepperDash.Essentials.Core.DeviceFactory.GetDevice(devConf); + if (newDev == null) newDev = PepperDash.Essentials.Devices.Common.DeviceFactory.GetDevice(devConf); - if (newDev == null) - newDev = PepperDash.Essentials.DM.DeviceFactory.GetDevice(devConf); if (newDev == null) newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs index d090c3bf..c764a5f7 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs @@ -1,13 +1,16 @@ -using Crestron.SimplSharpPro; +using System.Collections.Generic; +using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.GeneralIO; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; + namespace PepperDash.Essentials.Core.CrestronIO { - public class C2nRthsController:CrestronGenericBridgeableBaseDevice + public class C2nRthsController : CrestronGenericBridgeableBaseDevice { private readonly C2nRths _device; @@ -65,4 +68,22 @@ namespace PepperDash.Essentials.Core.CrestronIO trilist.StringInput[joinMap.Name].StringValue = Name; } } + + public class C2nRthsControllerFactory : EssentialsDeviceFactory + { + public C2nRthsControllerFactory() + { + TypeNames = new List() { "c2nrths" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new C2N-RTHS Device"); + + var control = CommFactory.GetControlPropertiesConfig(dc); + var cresnetId = control.CresnetIdInt; + + return new C2nRthsController(dc.Key, dc.Name, new C2nRths(cresnetId, Global.ControlSystem)); + } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs index 6bdfc25c..1ac8d0e3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs @@ -5,6 +5,8 @@ using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.GeneralIO; +using PepperDash.Essentials.Core.Config; + using PepperDash.Core; @@ -13,7 +15,7 @@ namespace PepperDash.Essentials.Core /// /// Wrapper class for CEN-IO-DIGIN-104 digital input module /// - public class CenIoDigIn104Controller : Device, IDigitalInputPorts + public class CenIoDigIn104Controller : EssentialsDevice, IDigitalInputPorts { public CenIoDi104 Di104 { get; private set; } @@ -37,4 +39,23 @@ namespace PepperDash.Essentials.Core #endregion } + + public class CenIoDigIn104ControllerFactory : EssentialsDeviceFactory + { + public CenIoDigIn104ControllerFactory() + { + TypeNames = new List() { "ceniodigin104" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new CEN-DIGIN-104 Device"); + + var control = CommFactory.GetControlPropertiesConfig(dc); + var ipid = control.IpIdInt; + + return new CenIoDigIn104Controller(dc.Key, dc.Name, new Crestron.SimplSharpPro.GeneralIO.CenIoDi104(ipid, Global.ControlSystem)); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs index 75e24d34..efdf9b7d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs @@ -1,14 +1,16 @@ using System; +using System.Collections.Generic; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.GeneralIO; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core.CrestronIO { - public class StatusSignController:CrestronGenericBridgeableBaseDevice + public class StatusSignController : CrestronGenericBridgeableBaseDevice { private readonly StatusSign _device; @@ -158,4 +160,22 @@ namespace PepperDash.Essentials.Core.CrestronIO device.SetColor(redBrightness, greenBrightness, blueBrightness); } } + + public class StatusSignControllerFactory : EssentialsDeviceFactory + { + public StatusSignControllerFactory() + { + TypeNames = new List() { "statussign" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new StatusSign Device"); + + var control = CommFactory.GetControlPropertiesConfig(dc); + var cresnetId = control.CresnetIdInt; + + return new StatusSignController(dc.Key, dc.Name, new StatusSign(cresnetId, Global.ControlSystem)); + } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/EssentialsDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/EssentialsDevice.cs index 18b187b7..4e144ff0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/EssentialsDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/EssentialsDevice.cs @@ -46,7 +46,7 @@ namespace PepperDash.Essentials.Core { foreach (var typeName in TypeNames) { - DeviceFactory.AddFactoryForType(typeName, BuildDevice); + DeviceFactory.AddFactoryForType(typeName.ToLower(), BuildDevice); } } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs index 201675d0..c4698736 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs @@ -55,34 +55,6 @@ namespace PepperDash.Essentials.Core return FactoryMethods[typeName](dc); } - // Check "core" types - //if (typeName == "genericcomm") - //{ - // Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); - // return new GenericComm(dc); - //} - if (typeName == "ceniodigin104") - { - var control = CommFactory.GetControlPropertiesConfig(dc); - var ipid = control.IpIdInt; - - return new CenIoDigIn104Controller(key, name, new Crestron.SimplSharpPro.GeneralIO.CenIoDi104(ipid, Global.ControlSystem)); - } - if (typeName == "statussign") - { - var control = CommFactory.GetControlPropertiesConfig(dc); - var cresnetId = control.CresnetIdInt; - - return new StatusSignController(key, name, new StatusSign(cresnetId, Global.ControlSystem)); - } - if (typeName == "c2nrths") - { - var control = CommFactory.GetControlPropertiesConfig(dc); - var cresnetId = control.CresnetIdInt; - - return new C2nRthsController(key, name, new C2nRths(cresnetId, Global.ControlSystem)); - } - return null; } @@ -112,16 +84,24 @@ namespace PepperDash.Essentials.Core } } - /// - /// Responsible for loading all of the device types + /// Responsible for loading all of the device types for this library /// public class CoreDeviceFactory { public CoreDeviceFactory() { - var genComm = new GenericCommFactory() as IDeviceFactory; - genComm.LoadTypeFactories(); + var genCommFactory = new GenericCommFactory() as IDeviceFactory; + genCommFactory.LoadTypeFactories(); + + var c2nRthsFactory = new C2nRthsControllerFactory() as IDeviceFactory; + c2nRthsFactory.LoadTypeFactories(); + + var statusSignFactory = new StatusSignControllerFactory() as IDeviceFactory; + statusSignFactory.LoadTypeFactories(); + + var cenIoControllerFactory = new CenIoDigIn104ControllerFactory() as IDeviceFactory; + cenIoControllerFactory.LoadTypeFactories(); } } } \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs b/essentials-framework/Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs index 1e795857..0108c65f 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs @@ -260,4 +260,29 @@ namespace PepperDash.Essentials.DM.AirMedia } + + public class AirMediaControllerFactory : EssentialsDeviceFactory + { + public AirMediaControllerFactory() + { + TypeNames = new List() { "am200", "am300" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + var type = dc.Type.ToLower(); + + Debug.Console(1, "Factory Attempting to create new AirMedia Device"); + + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + AmX00 amDevice = null; + if (type == "am200") + amDevice = new Crestron.SimplSharpPro.DM.AirMedia.Am200(props.Control.IpIdInt, Global.ControlSystem); + else if (type == "am300") + amDevice = new Crestron.SimplSharpPro.DM.AirMedia.Am300(props.Control.IpIdInt, Global.ControlSystem); + + return new AirMediaController(dc.Key, dc.Name, amDevice, dc, props); + + } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs index 745cdda5..8fa8696f 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs @@ -11,6 +11,7 @@ using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.DM.Config; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.DM { @@ -1275,4 +1276,41 @@ namespace PepperDash.Essentials.DM } } -} \ No newline at end of file + public class DmChassisControllerFactory : EssentialsDeviceFactory + { + public DmChassisControllerFactory() + { + TypeNames = new List() { "dmmd8x8", "dmmd8x8rps", "dmmd8x8cpu3", "dmmd8x8cpu3rps", + "dmmd16x16", "dmmd16x16rps", "dmmd16x16cpu3", "dmmd16x16cpu3rps", + "dmmd32x32", "dmmd32x32rps", "dmmd32x32cpu3", "dmmd32x32cpu3rps", + "dmmd64x64", "dmmd128x128" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + var type = dc.Type.ToLower(); + + Debug.Console(1, "Factory Attempting to create new DmChassisController Device"); + + if (type.StartsWith("dmmd8x") || type.StartsWith("dmmd16x") || type.StartsWith("dmmd32x")) + { + + var props = JsonConvert.DeserializeObject + (dc.Properties.ToString()); + return PepperDash.Essentials.DM.DmChassisController. + GetDmChassisController(dc.Key, dc.Name, type, props); + } + else if (type.StartsWith("dmmd128x") || type.StartsWith("dmmd64x")) + { + var props = JsonConvert.DeserializeObject + (dc.Properties.ToString()); + return PepperDash.Essentials.DM.DmBladeChassisController. + GetDmChassisController(dc.Key, dc.Name, type, props); + } + + return null; + } + } + +} + diff --git a/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs b/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs index 2417ce7e..3dcfb6b6 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs @@ -17,85 +17,25 @@ using PepperDash.Essentials.DM.Endpoints.DGEs; namespace PepperDash.Essentials.DM { - public class DeviceFactory + /// + /// Responsible for loading the type factories for this library + /// + public class DmDeviceFactory { - public static IKeyed GetDevice(DeviceConfig dc) - { - var key = dc.Key; - var name = dc.Name; - var type = dc.Type; - var properties = dc.Properties; + public DmDeviceFactory() + { + var dmChassisFactory = new DmChassisControllerFactory() as IDeviceFactory; + dmChassisFactory.LoadTypeFactories(); - var typeName = dc.Type.ToLower(); + var dmTxFactory = new DmTxControllerFactory() as IDeviceFactory; + dmTxFactory.LoadTypeFactories(); - if (typeName.StartsWith("am")) - { - if (typeName == "am200" || typeName == "am300") - { - var props = JsonConvert.DeserializeObject(properties.ToString()); - AmX00 amDevice = null; - if (typeName == "am200") - amDevice = new Crestron.SimplSharpPro.DM.AirMedia.Am200(props.Control.IpIdInt, Global.ControlSystem); - else if (typeName == "am300") - amDevice = new Crestron.SimplSharpPro.DM.AirMedia.Am300(props.Control.IpIdInt, Global.ControlSystem); - - return new AirMediaController(key, name, amDevice, dc, props); - } - } - else if (typeName.StartsWith("dmmd8x") || typeName.StartsWith("dmmd16x") || typeName.StartsWith("dmmd32x")) - { - var props = JsonConvert.DeserializeObject - (properties.ToString()); - return PepperDash.Essentials.DM.DmChassisController. - GetDmChassisController(key, name, type, props); - } - else if (typeName.StartsWith("dmmd128x") || typeName.StartsWith("dmmd64x")) { - var props = JsonConvert.DeserializeObject - (properties.ToString()); - return PepperDash.Essentials.DM.DmBladeChassisController. - GetDmChassisController(key, name, type, props); - } - // Hand off to DmTxHelper class - else if (typeName.StartsWith("dmtx")) { - var props = JsonConvert.DeserializeObject - (properties.ToString()); - return PepperDash.Essentials.DM.DmTxHelper.GetDmTxController(key, name, type, props); - } - - // Hand off to DmRmcHelper class - else if (typeName.StartsWith("dmrmc")) { - var props = JsonConvert.DeserializeObject - (properties.ToString()); - return PepperDash.Essentials.DM.DmRmcHelper.GetDmRmcController(key, name, type, props); - } - - else if (typeName.Equals("hdmd4x14ke")) { - var props = JsonConvert.DeserializeObject - (properties.ToString()); - return PepperDash.Essentials.DM.Chassis.HdMdNxM4kEController.GetController(key, name, type, props); - } - - else if (typeName.Equals("hdmd400ce") || typeName.Equals("hdmd300ce") || typeName.Equals("hdmd200ce") || typeName.Equals("hdmd200c1ge")) { - var props = JsonConvert.DeserializeObject - (properties.ToString()); - - if (typeName.Equals("hdmd400ce")) - return new PepperDash.Essentials.DM.HdMdxxxCEController(key, name, - new HdMd400CE(props.Control.IpIdInt, props.Control.TcpSshProperties.Address, Global.ControlSystem)); - else if (typeName.Equals("hdmd300ce")) - return new PepperDash.Essentials.DM.HdMdxxxCEController(key, name, - new HdMd300CE(props.Control.IpIdInt, props.Control.TcpSshProperties.Address, Global.ControlSystem)); - else if (typeName.Equals("hdmd200ce")) - return new PepperDash.Essentials.DM.HdMdxxxCEController(key, name, - new HdMd200CE(props.Control.IpIdInt, props.Control.TcpSshProperties.Address, Global.ControlSystem)); - else if (typeName.Equals("hdmd200c1ge")) - return new PepperDash.Essentials.DM.HdMdxxxCEController(key, name, - new HdMd200C1GE(props.Control.IpIdInt, props.Control.TcpSshProperties.Address, Global.ControlSystem)); - } - - return null; - } + var dmRxFactory = new DmRmcControllerFactory() as IDeviceFactory; + dmRxFactory.LoadTypeFactories(); + var hdMdFactory = new HdMdxxxCEControllerFactory() as IDeviceFactory; + hdMdFactory.LoadTypeFactories(); + } } diff --git a/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs b/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs index 48074ab9..63929938 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs @@ -12,6 +12,7 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.DM { @@ -268,4 +269,40 @@ namespace PepperDash.Essentials.DM { public ControlPropertiesConfig Control { get; set; } } + + public class HdMdxxxCEControllerFactory : EssentialsDeviceFactory + { + public HdMdxxxCEControllerFactory() + { + TypeNames = new List() { "hdmd400ce", "hdmd300ce", "hdmd200ce", "hdmd200c1ge"}; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + var typeName = dc.Type.ToLower(); + var key = dc.Key; + var name = dc.Name; + + Debug.Console(1, "Factory Attempting to create new HD-MD Device"); + + var props = JsonConvert.DeserializeObject + (dc.Properties.ToString()); + + if (typeName.Equals("hdmd400ce")) + return new PepperDash.Essentials.DM.HdMdxxxCEController(key, name, + new HdMd400CE(props.Control.IpIdInt, props.Control.TcpSshProperties.Address, Global.ControlSystem)); + else if (typeName.Equals("hdmd300ce")) + return new PepperDash.Essentials.DM.HdMdxxxCEController(key, name, + new HdMd300CE(props.Control.IpIdInt, props.Control.TcpSshProperties.Address, Global.ControlSystem)); + else if (typeName.Equals("hdmd200ce")) + return new PepperDash.Essentials.DM.HdMdxxxCEController(key, name, + new HdMd200CE(props.Control.IpIdInt, props.Control.TcpSshProperties.Address, Global.ControlSystem)); + else if (typeName.Equals("hdmd200c1ge")) + return new PepperDash.Essentials.DM.HdMdxxxCEController(key, name, + new HdMd200C1GE(props.Control.IpIdInt, props.Control.TcpSshProperties.Address, Global.ControlSystem)); + else + return null; + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs index 582234b3..08708d97 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs @@ -13,6 +13,7 @@ using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.DM.Config; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.DM { @@ -281,4 +282,25 @@ namespace PepperDash.Essentials.DM } } + public class DmRmcControllerFactory : EssentialsDeviceFactory + { + public DmRmcControllerFactory() + { + TypeNames = new List() { "hdbasetrx", "dmrmc4k100c1g", "dmrmc100c", "dmrmc100s", "dmrmc4k100c", "dmrmc150s", + "dmrmc200c", "dmrmc200s", "dmrmc200s2", "dmrmcscalerc", "dmrmcscalers", "dmrmcscalers2", "dmrmc4kscalerc", "dmrmc4kscalercdsp" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + var type = dc.Type.ToLower(); + + Debug.Console(1, "Factory Attempting to create new DM-RMC Device"); + + var props = JsonConvert.DeserializeObject + (dc.Properties.ToString()); + return PepperDash.Essentials.DM.DmRmcHelper.GetDmRmcController(dc.Key, dc.Name, type, props); + + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs index ed90ba7f..b741dfe5 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs @@ -13,6 +13,8 @@ using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.DM.Config; +using PepperDash.Essentials.Core.Config; + namespace PepperDash.Essentials.DM { @@ -319,12 +321,25 @@ namespace PepperDash.Essentials.DM } } } - //public enum ePdtHdcpSupport - //{ - // HdcpOff = 0, - // Hdcp1 = 1, - // Hdcp2 = 2, - // Hdcp2_2= 3, - // Auto = 99 - //} -} \ No newline at end of file + + public class DmTxControllerFactory : EssentialsDeviceFactory + { + public DmTxControllerFactory() + { + TypeNames = new List() { "dmtx200c", "dmtx201c", "dmtx201s", "dmtx4k100c", "dmtx4k202c", "dmtx4kz202c", "dmtx4k302c", "dmtx4kz302c", "dmtx401c", "dmtx401s" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + var type = dc.Type.ToLower(); + + Debug.Console(1, "Factory Attempting to create new DM-TX Device"); + + var props = JsonConvert.DeserializeObject + (dc.Properties.ToString()); + return PepperDash.Essentials.DM.DmTxHelper.GetDmTxController(dc.Key, dc.Name, type, props); + } + } + +} + From ae23eec005d74c128f14fbf4c27a11e4ed95d05f Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 16 Apr 2020 21:10:45 -0600 Subject: [PATCH 03/10] Progress on adding Description attribute and printing types at runtime --- PepperDashEssentials/ControlSystem.cs | 15 ++++- .../Config/Comm and IR/GenericComm.cs | 1 + .../Crestron IO/C2nRts/C2nRthsController.cs | 1 + .../Inputs/CenIoDigIn104Controller.cs | 1 + .../StatusSign/StatusSignController.cs | 1 + .../Devices/EssentialsDevice.cs | 41 +++++++++++- .../Factory/DeviceFactory.cs | 65 +++++++++++++++---- .../Factory/IDeviceFactory.cs | 3 +- .../Chassis/DmChassisController.cs | 1 + .../Essentials_DM/Config/DeviceFactory.cs | 2 + .../DmLite/HdMdxxxCEController.cs | 1 + .../Endpoints/Receivers/DmRmcHelper.cs | 1 + .../Endpoints/Transmitters/DmTxHelpers.cs | 1 + 13 files changed, 117 insertions(+), 17 deletions(-) diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index db10c959..04f60378 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -81,10 +81,22 @@ namespace PepperDash.Essentials "Template URL: {1}", ConfigReader.ConfigObject.SystemUrl, ConfigReader.ConfigObject.TemplateUrl); }, "portalinfo", "Shows portal URLS from configuration", ConsoleAccessLevelEnum.AccessOperator); + LoadDeviceTypesFromFactories(); + if (!Debug.DoNotLoadOnNextBoot) GoWithLoad(); } + /// + /// Instantiates each of the device factories to load thier device types + /// + void LoadDeviceTypesFromFactories() + { + // Instantiate the Device Factories + new CoreDeviceFactory(); + new DmDeviceFactory(); + } + /// @@ -291,9 +303,6 @@ namespace PepperDash.Essentials /// public void LoadDevices() { - // Instantiate the Device Factories - new CoreDeviceFactory(); - // Build the processor wrapper class DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor")); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/GenericComm.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/GenericComm.cs index 0b33e619..41438832 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/GenericComm.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/GenericComm.cs @@ -15,6 +15,7 @@ namespace PepperDash.Essentials.Core /// /// Serves as a generic wrapper class for all styles of IBasicCommuncation ports /// + [Description("Generic communication wrapper class for any IBasicCommunication type")] public class GenericComm : ReconfigurableBridgableDevice { EssentialsControlPropertiesConfig PropertiesConfig; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs index c764a5f7..214c5ecf 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs @@ -10,6 +10,7 @@ using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core.CrestronIO { + [Description("Wrapper class for the C2N-RTHS sensor")] public class C2nRthsController : CrestronGenericBridgeableBaseDevice { private readonly C2nRths _device; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs index 1ac8d0e3..8510dd9d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs @@ -15,6 +15,7 @@ namespace PepperDash.Essentials.Core /// /// Wrapper class for CEN-IO-DIGIN-104 digital input module /// + [Description("Wrapper class for the CEN-IO-DIGIN-104 diginal input module")] public class CenIoDigIn104Controller : EssentialsDevice, IDigitalInputPorts { public CenIoDi104 Di104 { get; private set; } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs index efdf9b7d..10a18372 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs @@ -10,6 +10,7 @@ using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core.CrestronIO { + [Description("Wrapper class for the Crestron StatusSign device")] public class StatusSignController : CrestronGenericBridgeableBaseDevice { private readonly StatusSign _device; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/EssentialsDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/EssentialsDevice.cs index 4e144ff0..410c7a48 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/EssentialsDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/EssentialsDevice.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; +using Crestron.SimplSharp.Reflection; using PepperDash.Core; using PepperDash.Essentials.Core.Config; @@ -12,6 +13,7 @@ namespace PepperDash.Essentials.Core /// /// Defines the basic needs for an EssentialsDevice to enable it to be build by an IDeviceFactory class /// + [Description("The base Essentials Device Class")] public abstract class EssentialsDevice : Device { protected EssentialsDevice(string key) @@ -27,6 +29,40 @@ namespace PepperDash.Essentials.Core } } + [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)] + public class DescriptionAttribute : Attribute + { + private string _Description; + + public DescriptionAttribute(string description) + { + Debug.Console(2, "Setting Description: {0}", description); + _Description = description; + } + + public string Description + { + get { return _Description; } + } + } + + [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)] + public class ConfigSnippetAttribute : Attribute + { + private string _ConfigSnippet; + + public ConfigSnippetAttribute(string configSnippet) + { + Debug.Console(2, "Setting Description {0}", configSnippet); + _ConfigSnippet = configSnippet; + } + + public string ConfigSnippet + { + get { return _ConfigSnippet; } + } + } + /// /// Devices the basic needs for a Device Factory /// @@ -46,7 +82,10 @@ namespace PepperDash.Essentials.Core { foreach (var typeName in TypeNames) { - DeviceFactory.AddFactoryForType(typeName.ToLower(), BuildDevice); + Debug.Console(2, "Getting Description Attribute from class: '{0}'", typeof(T).FullName); + var attributes = typeof(T).GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[]; + string description = attributes[0].Description; + DeviceFactory.AddFactoryForType(typeName.ToLower(), description, typeof(T), BuildDevice); } } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs index c4698736..15188965 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs @@ -5,6 +5,7 @@ using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.GeneralIO; +using Crestron.SimplSharp.Reflection; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; @@ -13,26 +14,53 @@ using PepperDash.Essentials.Core.Touchpanels; namespace PepperDash.Essentials.Core { + public class DeviceFactoryWrapper + { + public CType CType { get; set; } + public string Description { get; set; } + public Func FactoryMethod { get; set; } + + public DeviceFactoryWrapper() + { + CType = null; + Description = "Not Available"; + } + } + public class DeviceFactory { /// /// A dictionary of factory methods, keyed by config types, added by plugins. /// These methods are looked up and called by GetDevice in this class. /// - static Dictionary> FactoryMethods = - new Dictionary>(StringComparer.OrdinalIgnoreCase); + static Dictionary FactoryMethods = + new Dictionary(StringComparer.OrdinalIgnoreCase); /// /// Adds a plugin factory method /// /// /// - public static void AddFactoryForType(string type, Func method) + public static void AddFactoryForType(string typeName, Func method) { - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Adding factory method for type '{0}'", type); - DeviceFactory.FactoryMethods.Add(type, method); + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Adding factory method for type '{0}'", typeName); + DeviceFactory.FactoryMethods.Add(typeName, new DeviceFactoryWrapper() { FactoryMethod = method}); } + public static void AddFactoryForType(string typeName, string description, CType cType, Func method) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Adding factory method for type '{0}'", typeName); + + if(FactoryMethods.ContainsKey(typeName)) + { + Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to add type: '{0}'. Already exists in DeviceFactory", typeName); + return; + } + + var wrapper = new DeviceFactoryWrapper() { CType = cType, Description = description, FactoryMethod = method }; + DeviceFactory.FactoryMethods.Add(typeName, wrapper); + } + /// /// The factory method for Core "things". Also iterates the Factory methods that have /// been loaded from plugins @@ -52,34 +80,45 @@ namespace PepperDash.Essentials.Core if (FactoryMethods.ContainsKey(typeName)) { Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading '{0}' from plugin", dc.Type); - return FactoryMethods[typeName](dc); + return FactoryMethods[typeName].FactoryMethod(dc); } return null; } /// - /// Prints the type names fromt the FactoryMethods collection. + /// Prints the type names and associated metadata from the FactoryMethods collection. /// /// public static void GetDeviceFactoryTypes(string filter) { - List typeNames = new List(); + Dictionary types = new Dictionary(); if (!string.IsNullOrEmpty(filter)) { - typeNames = FactoryMethods.Keys.Where(k => k.Contains(filter)).ToList(); + types = FactoryMethods.Where(k => k.Key.Contains(filter)).ToDictionary(k => k.Key, k => k.Value); } else { - typeNames = FactoryMethods.Keys.ToList(); + types = FactoryMethods; } Debug.Console(0, "Device Types:"); - foreach (var type in typeNames) + foreach (var type in types) { - Debug.Console(0, "type: '{0}'", type); + var description = type.Value.Description; + var cType = "Not Specified by Plugin"; + + if(type.Value.CType != null) + { + cType = type.Value.CType.FullName; + } + + Debug.Console(0, + @"Type: '{0}' + CType: '{1}' + Description: {2}", type.Key, cType, description); } } } @@ -91,6 +130,8 @@ namespace PepperDash.Essentials.Core { public CoreDeviceFactory() { + Debug.Console(1, "Essentials.Core Factory Adding Types..."); + var genCommFactory = new GenericCommFactory() as IDeviceFactory; genCommFactory.LoadTypeFactories(); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/IDeviceFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/IDeviceFactory.cs index ef792868..91e073f2 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/IDeviceFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/IDeviceFactory.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; +using Crestron.SimplSharp.Reflection; using PepperDash.Core; using PepperDash.Essentials.Core.Config; @@ -15,7 +16,7 @@ namespace PepperDash.Essentials.Core public interface IDeviceFactory { /// - /// Will be called when the plugin is loaded by Essentials. Must add any new types to the DeviceFactory using DeviceFactory.AddFactoryForType() for each new type + /// Loads all the types to the DeviceFactory /// void LoadTypeFactories(); } diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs index 8fa8696f..bc39e51a 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs @@ -19,6 +19,7 @@ namespace PepperDash.Essentials.DM /// Builds a controller for basic DM-RMCs with Com and IR ports and no control functions /// /// + [Description("Wrapper class for all DM-MD chassis variants from 8x8 to 128x128")] public class DmChassisController : CrestronGenericBridgeableBaseDevice, IDmSwitch, IRoutingInputsOutputs, IRouting, IHasFeedback { public DMChassisPropertiesConfig PropertiesConfig { get; set; } diff --git a/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs b/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs index 3dcfb6b6..6e10ae61 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs @@ -24,6 +24,8 @@ namespace PepperDash.Essentials.DM { public DmDeviceFactory() { + Debug.Console(1, "Essentials.DM Factory Adding Types..."); + var dmChassisFactory = new DmChassisControllerFactory() as IDeviceFactory; dmChassisFactory.LoadTypeFactories(); diff --git a/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs b/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs index 63929938..000202dc 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs @@ -19,6 +19,7 @@ namespace PepperDash.Essentials.DM /// /// Represent both a transmitter and receiver pair of the HD-MD-400-C-E / HD-MD-300-C-E / HD-MD-200-C-E kits /// + [Description("Wrapper class for all HD-MD variants")] public class HdMdxxxCEController : CrestronGenericBridgeableBaseDevice, IRouting//, IComPorts { /// diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs index 08708d97..f36b513e 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs @@ -17,6 +17,7 @@ using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.DM { + [Description("Wrapper class for all DM-RMC variants")] public abstract class DmRmcControllerBase : CrestronGenericBridgeableBaseDevice { public virtual StringFeedback VideoOutputResolutionFeedback { get; protected set; } diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs index b741dfe5..f5d59354 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs @@ -148,6 +148,7 @@ namespace PepperDash.Essentials.DM /// /// /// + [Description("Wrapper class for all DM-TX variants")] public abstract class DmTxControllerBase : CrestronGenericBridgeableBaseDevice { public virtual void SetPortHdcpCapability(eHdcpCapabilityType hdcpMode, uint port) { } From e55a647854050c92698192d9123b709b018a41cc Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 17 Apr 2020 09:24:09 -0600 Subject: [PATCH 04/10] fixes types for base device Generic types --- .../Crestron IO/C2nRts/C2nRthsController.cs | 2 +- .../Crestron IO/Inputs/CenIoDigIn104Controller.cs | 2 +- .../Crestron IO/StatusSign/StatusSignController.cs | 2 +- .../PepperDashEssentialsBase/Factory/DeviceFactory.cs | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs index 214c5ecf..0bc48d80 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/C2nRts/C2nRthsController.cs @@ -70,7 +70,7 @@ namespace PepperDash.Essentials.Core.CrestronIO } } - public class C2nRthsControllerFactory : EssentialsDeviceFactory + public class C2nRthsControllerFactory : EssentialsDeviceFactory { public C2nRthsControllerFactory() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs index 8510dd9d..5112f3aa 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/CenIoDigIn104Controller.cs @@ -41,7 +41,7 @@ namespace PepperDash.Essentials.Core #endregion } - public class CenIoDigIn104ControllerFactory : EssentialsDeviceFactory + public class CenIoDigIn104ControllerFactory : EssentialsDeviceFactory { public CenIoDigIn104ControllerFactory() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs index 10a18372..ca679bce 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/StatusSign/StatusSignController.cs @@ -162,7 +162,7 @@ namespace PepperDash.Essentials.Core.CrestronIO } } - public class StatusSignControllerFactory : EssentialsDeviceFactory + public class StatusSignControllerFactory : EssentialsDeviceFactory { public StatusSignControllerFactory() { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs index 15188965..80725cc3 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs @@ -132,6 +132,7 @@ namespace PepperDash.Essentials.Core { Debug.Console(1, "Essentials.Core Factory Adding Types..."); + //cast to IDeviceFactory isn't explicitly required here...but will be when instantiating using reflection, which I'm assuming is the next step var genCommFactory = new GenericCommFactory() as IDeviceFactory; genCommFactory.LoadTypeFactories(); From 902a94a82cd8109b5f1a963c6d29203603d3cf62 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Mon, 20 Apr 2020 10:32:25 -0600 Subject: [PATCH 05/10] fixes incorrect type definitions in Device Factories. --- .../Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs | 2 +- .../Essentials DM/Essentials_DM/Chassis/DmChassisController.cs | 2 +- .../Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs | 2 +- .../Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs | 2 +- .../Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/essentials-framework/Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs b/essentials-framework/Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs index 0108c65f..8823ae75 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/AirMedia/AirMediaController.cs @@ -261,7 +261,7 @@ namespace PepperDash.Essentials.DM.AirMedia } - public class AirMediaControllerFactory : EssentialsDeviceFactory + public class AirMediaControllerFactory : EssentialsDeviceFactory { public AirMediaControllerFactory() { diff --git a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs index bc39e51a..7313aece 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Chassis/DmChassisController.cs @@ -1277,7 +1277,7 @@ namespace PepperDash.Essentials.DM } } - public class DmChassisControllerFactory : EssentialsDeviceFactory + public class DmChassisControllerFactory : EssentialsDeviceFactory { public DmChassisControllerFactory() { diff --git a/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs b/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs index 000202dc..59a318cd 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/DmLite/HdMdxxxCEController.cs @@ -271,7 +271,7 @@ namespace PepperDash.Essentials.DM public ControlPropertiesConfig Control { get; set; } } - public class HdMdxxxCEControllerFactory : EssentialsDeviceFactory + public class HdMdxxxCEControllerFactory : EssentialsDeviceFactory { public HdMdxxxCEControllerFactory() { diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs index f36b513e..da3e587a 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Receivers/DmRmcHelper.cs @@ -283,7 +283,7 @@ namespace PepperDash.Essentials.DM } } - public class DmRmcControllerFactory : EssentialsDeviceFactory + public class DmRmcControllerFactory : EssentialsDeviceFactory { public DmRmcControllerFactory() { diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs index f5d59354..81a56008 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/Transmitters/DmTxHelpers.cs @@ -323,7 +323,7 @@ namespace PepperDash.Essentials.DM } } - public class DmTxControllerFactory : EssentialsDeviceFactory + public class DmTxControllerFactory : EssentialsDeviceFactory { public DmTxControllerFactory() { From 2170a793993bc20eac281442cc2c0e639d6380fa Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Mon, 20 Apr 2020 23:12:27 -0600 Subject: [PATCH 06/10] Updating more device factories in Essentials and Devices.Common --- .../MobileControlSystemController.cs | 18 +- .../RoomBridges/MobileControlBridgeBase.cs | 2 +- .../MobileControlSIMPLRoomBridge.cs | 31 ++++ PepperDashEssentials/Bridges/BridgeFactory.cs | 21 +-- PepperDashEssentials/Bridges/EiscBridge.cs | 137 ++------------ PepperDashEssentials/ControlSystem.cs | 30 +-- PepperDashEssentials/Devices/Amplifier.cs | 17 +- PepperDashEssentials/Factory/DeviceFactory.cs | 94 ++-------- .../Factory/UiDeviceFactory.cs | 171 +----------------- .../UI/EssentialsTouchpanelController.cs | 131 +++++++++++++- .../Bridges/BridgeBase.cs | 154 +++------------- .../Comm and IR/ConsoleCommMockDevice.cs | 21 ++- .../Devices/PC/InRoomPc.cs | 18 +- .../Devices/PC/Laptop.cs | 17 +- .../Display/BasicIrDisplay.cs | 24 +++ .../Display/MockDisplay.cs | 17 +- .../RoomOnToDefaultSourceWhenOccupied.cs | 15 ++ .../Endpoints/DGEs/DgeController.cs | 33 ++++ .../Audio/GenericAudioOut.cs | 20 +- .../Cameras/CameraVisca.cs | 19 ++ .../Crestron/Gateways/CenRfgwController.cs | 18 ++ .../DSP/BiampTesira/BiampTesiraForteDsp.cs | 19 ++ .../Essentials Devices Common/DSP/DspBase.cs | 2 +- .../DiscPlayer/IRDiscPlayerBase.cs | 33 +++- .../Factory/DeviceFactory.cs | 139 +++++--------- .../Generic/GenericSource.cs | 18 +- .../AnalogWay/AnalongWayLiveCore.cs | 21 ++- .../Power Controllers/Digitallogger.cs | 17 ++ .../Streaming/AppleTV.cs | 17 ++ 29 files changed, 645 insertions(+), 629 deletions(-) diff --git a/PepperDashEssentials/AppServer/MobileControlSystemController.cs b/PepperDashEssentials/AppServer/MobileControlSystemController.cs index b29ca61d..cc18ba55 100644 --- a/PepperDashEssentials/AppServer/MobileControlSystemController.cs +++ b/PepperDashEssentials/AppServer/MobileControlSystemController.cs @@ -21,7 +21,7 @@ using PepperDash.Essentials.AppServer.Messengers; namespace PepperDash.Essentials { - public class MobileControlSystemController : Device + public class MobileControlSystemController : EssentialsDevice { WebSocketClient WSClient; @@ -865,4 +865,20 @@ namespace PepperDash.Essentials CrestronConsole.ConsoleCommandResponse("Usage: mobilehttprequest:N get/post url\r"); } } + + public class MobileControlSystemControllerFactory : EssentialsDeviceFactory + { + public MobileControlSystemControllerFactory() + { + TypeNames = new List() { "appserver" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new MobileControlSystemController Device"); + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + return new MobileControlSystemController(dc.Key, dc.Name, props); + } + } + } \ No newline at end of file diff --git a/PepperDashEssentials/AppServer/RoomBridges/MobileControlBridgeBase.cs b/PepperDashEssentials/AppServer/RoomBridges/MobileControlBridgeBase.cs index d7258070..fa5cb93d 100644 --- a/PepperDashEssentials/AppServer/RoomBridges/MobileControlBridgeBase.cs +++ b/PepperDashEssentials/AppServer/RoomBridges/MobileControlBridgeBase.cs @@ -12,7 +12,7 @@ namespace PepperDash.Essentials /// /// /// - public abstract class MobileControlBridgeBase: Device + public abstract class MobileControlBridgeBase: EssentialsDevice { public MobileControlSystemController Parent { get; private set; } diff --git a/PepperDashEssentials/AppServer/RoomBridges/MobileControlSIMPLRoomBridge.cs b/PepperDashEssentials/AppServer/RoomBridges/MobileControlSIMPLRoomBridge.cs index a8589b92..25eebf42 100644 --- a/PepperDashEssentials/AppServer/RoomBridges/MobileControlSIMPLRoomBridge.cs +++ b/PepperDashEssentials/AppServer/RoomBridges/MobileControlSIMPLRoomBridge.cs @@ -825,4 +825,35 @@ namespace PepperDash.Essentials.Room.MobileControl EISC.StringInput[JoinMap.ServerUrl.JoinNumber].StringValue = Parent.Config.ClientAppUrl; } } + + public class MobileControlSIMPLRoomBridgeFactory : EssentialsDeviceFactory + { + public MobileControlSIMPLRoomBridgeFactory() + { + TypeNames = new List() { "mobilecontrolbridge-ddvc01", "mobilecontrolbridge-simpl" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new MobileControlSIMPLRoomBridge Device"); + + var comm = CommFactory.GetControlPropertiesConfig(dc); + + var bridge = new PepperDash.Essentials.Room.MobileControl.MobileControlSIMPLRoomBridge(dc.Key, dc.Name, comm.IpIdInt); + bridge.AddPreActivationAction(() => + { + var parent = DeviceManager.AllDevices.FirstOrDefault(d => d.Key == "appServer") as MobileControlSystemController; + if (parent == null) + { + Debug.Console(0, bridge, "ERROR: Cannot connect bridge. System controller not present"); + } + Debug.Console(0, bridge, "Linking to parent controller"); + bridge.AddParent(parent); + parent.AddBridge(bridge); + }); + + return bridge; + } + } + } \ No newline at end of file diff --git a/PepperDashEssentials/Bridges/BridgeFactory.cs b/PepperDashEssentials/Bridges/BridgeFactory.cs index e3fc14f3..21d3a346 100644 --- a/PepperDashEssentials/Bridges/BridgeFactory.cs +++ b/PepperDashEssentials/Bridges/BridgeFactory.cs @@ -16,23 +16,20 @@ using Crestron.SimplSharpPro.EthernetCommunication; namespace PepperDash.Essentials { + /// + /// Responsible for loading all of the device types for this library + /// public class BridgeFactory { - public static IKeyed GetDevice(DeviceConfig dc) + public BridgeFactory() { - // ? why is this static JTA 2018-06-13? + var eiscApiAdvancedFactory = new EiscApiAdvancedFactory() as IDeviceFactory; + eiscApiAdvancedFactory.LoadTypeFactories(); - var typeName = dc.Type.ToLower(); - - //Debug.Console(2, "Name {0}, Key {1}, Type {2}, Properties {3}", name, key, type, properties.ToString()); - - if (typeName == "eiscapiadv" || typeName == "eiscapiadvanced") - { - return new EiscApiAdvanced(dc); - } - - return typeName == "eiscapi" ? new EiscApi(dc) : null; + var eiscApiFactory = new EiscApiFactory() as IDeviceFactory; + eiscApiFactory.LoadTypeFactories(); } + } diff --git a/PepperDashEssentials/Bridges/EiscBridge.cs b/PepperDashEssentials/Bridges/EiscBridge.cs index fe592e45..4c999f20 100644 --- a/PepperDashEssentials/Bridges/EiscBridge.cs +++ b/PepperDashEssentials/Bridges/EiscBridge.cs @@ -66,129 +66,10 @@ namespace PepperDash.Essentials.Bridges Debug.ConsoleWithLog(0, this, "Please update the bridge config to use EiscBridgeAdvanced with this device: {0}", device.Key); } - //if (device.GetType().GetCType().IsAssignableFrom(typeof (IBridge))) - //{ - // var bridge = device as IBridge; - // if (bridge == null) - // continue; - // Debug.Console(2, this, "Linking device {0} as IBridge"); - // bridge.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - - //if (!device.GetType().GetCType().IsAssignableFrom(typeof (IBridgeAdvanced))) continue; - - //var bridgeAdvanced = device as IBridgeAdvanced; - - //if (bridgeAdvanced == null) continue; - //Debug.Console(2, this, "Linking device {0} as IBridgeAdvanced"); - //bridgeAdvanced.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this); } Debug.Console(1, this, "Devices Linked."); - // - //else if (device is PepperDash.Essentials.Core.Monitoring.SystemMonitorController) - //{ - // (device as PepperDash.Essentials.Core.Monitoring.SystemMonitorController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is GenericComm) - //{ - // (device as GenericComm).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is CameraBase) - //{ - // (device as CameraBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this); - // continue; - //} - //else if (device is PepperDash.Essentials.Core.DisplayBase) - //{ - // (device as DisplayBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmChassisController) - //{ - // (device as DmChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmBladeChassisController) - //{ - // (device as DmBladeChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmpsRoutingController) - //{ - // (device as DmpsRoutingController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmpsAudioOutputController) - //{ - // (device as DmpsAudioOutputController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmTxControllerBase) - //{ - // (device as DmTxControllerBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmRmcControllerBase) - //{ - // (device as DmRmcControllerBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is GenericRelayDevice) - //{ - // (device as GenericRelayDevice).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is IRSetTopBoxBase) - //{ - // (device as IRSetTopBoxBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is IDigitalInput) - //{ - // (device as IDigitalInput).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is AppleTV) - //{ - // (device as AppleTV).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is HdMdxxxCEController) - //{ - // (device as HdMdxxxCEController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is LightingBase) - //{ - // (device as LightingBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DigitalLogger) - //{ - // (device as DigitalLogger).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is PepperDash.Essentials.Devices.Common.Occupancy.GlsOccupancySensorBaseController) - //{ - // (device as PepperDash.Essentials.Devices.Common.Occupancy.GlsOccupancySensorBaseController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is StatusSignController) - //{ - // (device as StatusSignController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is C2nRthsController) - //{ - // (device as C2nRthsController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //} - + }); } @@ -332,4 +213,20 @@ namespace PepperDash.Essentials.Bridges } } } + + public class EiscApiFactory : EssentialsDeviceFactory + { + public EiscApiFactory() + { + TypeNames = new List() { "eiscapi" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new EiscApi Device"); + + return new EiscApi(dc); + } + } + } \ No newline at end of file diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 04f60378..3e6654b2 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -95,6 +95,13 @@ namespace PepperDash.Essentials // Instantiate the Device Factories new CoreDeviceFactory(); new DmDeviceFactory(); + new UiDeviceFactory(); + + new DeviceFactory(); + new BridgeFactory(); + + new PepperDash.Essentials.Devices.Common.DeviceFactory(); + } @@ -366,32 +373,15 @@ namespace PepperDash.Essentials } // Try local factories first - var newDev = DeviceFactory.GetDevice(devConf); + IKeyed newDev = null; - if (newDev == null) - newDev = BridgeFactory.GetDevice(devConf); - - // Then associated library factories if (newDev == null) newDev = PepperDash.Essentials.Core.DeviceFactory.GetDevice(devConf); - if (newDev == null) - newDev = PepperDash.Essentials.Devices.Common.DeviceFactory.GetDevice(devConf); + // if (newDev == null) newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.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); diff --git a/PepperDashEssentials/Devices/Amplifier.cs b/PepperDashEssentials/Devices/Amplifier.cs index 20d8efa0..b2725109 100644 --- a/PepperDashEssentials/Devices/Amplifier.cs +++ b/PepperDashEssentials/Devices/Amplifier.cs @@ -6,11 +6,12 @@ using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Routing; namespace PepperDash.Essentials { - public class Amplifier : Device, IRoutingSinkNoSwitching + public class Amplifier : EssentialsDevice, IRoutingSinkNoSwitching { public event SourceInfoChangeHandler CurrentSourceChange; @@ -54,4 +55,18 @@ namespace PepperDash.Essentials #endregion } + + public class AmplifierFactory : EssentialsDeviceFactory + { + public AmplifierFactory() + { + TypeNames = new List() { "amplifier" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Amplifier Device"); + return new Amplifier(dc.Key, dc.Name); + } + } } \ No newline at end of file diff --git a/PepperDashEssentials/Factory/DeviceFactory.cs b/PepperDashEssentials/Factory/DeviceFactory.cs index 1e0e8ffb..944a9b2f 100644 --- a/PepperDashEssentials/Factory/DeviceFactory.cs +++ b/PepperDashEssentials/Factory/DeviceFactory.cs @@ -10,88 +10,34 @@ using Newtonsoft.Json.Linq; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.Room.MobileControl; namespace PepperDash.Essentials { - public class DeviceFactory + /// + /// Responsible for loading all of the device types for this library + /// + public class DeviceFactory { - public static IKeyed GetDevice(DeviceConfig dc) - { - var key = dc.Key; - var name = dc.Name; - var type = dc.Type; - var properties = dc.Properties; + public DeviceFactory() + { + var ampFactory = new AmplifierFactory() as IDeviceFactory; + ampFactory.LoadTypeFactories(); - var typeName = dc.Type.ToLower(); + var mockDisplayFactory = new MockDisplayFactory() as IDeviceFactory; + mockDisplayFactory.LoadTypeFactories(); - if (typeName == "amplifier") - { - return new Amplifier(dc.Key, dc.Name); - } - else if (dc.Group.ToLower() == "touchpanel") // typeName.StartsWith("tsw")) - { - return UiDeviceFactory.GetUiDevice(dc); - } + var consoleCommMockFactroy = new ConsoleCommMockDeviceFactory() as IDeviceFactory; + consoleCommMockFactroy.LoadTypeFactories(); - else if (typeName == "mockdisplay") - { - return new MockDisplay(key, name); - } + var mcSystemControllerFactory = new MobileControlSystemControllerFactory() as IDeviceFactory; + mcSystemControllerFactory.LoadTypeFactories(); - else if (typeName == "generic") - { - return new Device(key, name); - } + var mcSIMPLRoomBridgeFactory = new MobileControlSIMPLRoomBridgeFactory() as IDeviceFactory; + mcSIMPLRoomBridgeFactory.LoadTypeFactories(); - //// MOVE into something else??? - //else if (typeName == "basicirdisplay") - //{ - // var ir = IRPortHelper.GetIrPort(properties); - // if (ir != null) - // return new BasicIrDisplay(key, name, ir.Port, ir.FileName); - //} - - else if (typeName == "commmock") - { - var comm = CommFactory.CreateCommForDevice(dc); - var props = JsonConvert.DeserializeObject( - properties.ToString()); - return new ConsoleCommMockDevice(key, name, props, comm); - } - - else if (typeName == "appserver") - { - var props = JsonConvert.DeserializeObject(properties.ToString()); - return new MobileControlSystemController(key, name, props); - } - - else if (typeName == "mobilecontrolbridge-ddvc01") - { - var comm = CommFactory.GetControlPropertiesConfig(dc); - - var bridge = new PepperDash.Essentials.Room.MobileControl.MobileControlSIMPLRoomBridge(key, name, comm.IpIdInt); - bridge.AddPreActivationAction(() => - { - var parent = DeviceManager.AllDevices.FirstOrDefault(d => d.Key == "appServer") as MobileControlSystemController; - if (parent == null) - { - Debug.Console(0, bridge, "ERROR: Cannot connect bridge. System controller not present"); - } - Debug.Console(0, bridge, "Linking to parent controller"); - bridge.AddParent(parent); - parent.AddBridge(bridge); - }); - - return bridge; - } - - else if (typeName == "roomonwhenoccupancydetectedfeature") - { - return new RoomOnToDefaultSourceWhenOccupied(dc); - } - - return null; - } + var roomOnToDefSourceWhenOcc = new RoomOnToDefaultSourceWhenOccupiedFactory() as IDeviceFactory; + roomOnToDefSourceWhenOcc.LoadTypeFactories(); + } } - } diff --git a/PepperDashEssentials/Factory/UiDeviceFactory.cs b/PepperDashEssentials/Factory/UiDeviceFactory.cs index 6176b6d1..fad8026f 100644 --- a/PepperDashEssentials/Factory/UiDeviceFactory.cs +++ b/PepperDashEssentials/Factory/UiDeviceFactory.cs @@ -18,173 +18,18 @@ using PepperDash.Essentials.DM.Endpoints.DGEs; namespace PepperDash.Essentials { + /// + /// Responsible for loading all of the UI device types for this library + /// public class UiDeviceFactory { - public static IKeyed GetUiDevice(DeviceConfig config) + public UiDeviceFactory() { - var comm = CommFactory.GetControlPropertiesConfig(config); + var dgeControllerFactory = new DgeControllerFactory() as IDeviceFactory; + dgeControllerFactory.LoadTypeFactories(); - var typeName = config.Type.ToLower(); - - EssentialsTouchpanelController panelController = null; - - var props = JsonConvert.DeserializeObject(config.Properties.ToString()); - - if (typeName.Contains("dge")) - { - Dge100 dgeDevice = null; - if (typeName == "dge100") - dgeDevice = new Dge100(comm.IpIdInt, Global.ControlSystem); - else if (typeName == "dmdge200c") - dgeDevice = new DmDge200C(comm.IpIdInt, Global.ControlSystem); - - if (dgeDevice == null) - { - Debug.Console(1, "Unable to create DGE device"); - return null; - } - - var dgeController = new DgeController(config.Key + "-comPorts", config.Name, dgeDevice, config, props); - - DeviceManager.AddDevice(dgeController); - - panelController = new EssentialsTouchpanelController(config.Key, config.Name, dgeController.DigitalGraphicsEngine, - props.ProjectName, props.SgdFile); - } - else - { - panelController = new EssentialsTouchpanelController(config.Key, config.Name, config.Type, props, comm.IpIdInt); - } - - panelController.AddPostActivationAction(() => - { - var mainDriver = new EssentialsPanelMainInterfaceDriver(panelController.Panel, props); - // Then the sub drivers - - // spin up different room drivers depending on room type - var room = DeviceManager.GetDeviceForKey(props.DefaultRoomKey); - if (room is EssentialsHuddleSpaceRoom) - { - - // Header Driver - Debug.Console(0, panelController, "Adding header driver"); - mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, props); - - // AV Driver - Debug.Console(0, panelController, "Adding huddle space AV driver"); - var avDriver = new EssentialsHuddlePanelAvFunctionsDriver(mainDriver, props); - avDriver.DefaultRoomKey = props.DefaultRoomKey; - mainDriver.AvDriver = avDriver; - avDriver.CurrentRoom = room as EssentialsHuddleSpaceRoom; - - // Environment Driver - if (avDriver.CurrentRoom.PropertiesConfig.Environment != null && avDriver.CurrentRoom.PropertiesConfig.Environment.DeviceKeys.Count > 0) - { - Debug.Console(0, panelController, "Adding environment driver"); - mainDriver.EnvironmentDriver = new EssentialsEnvironmentDriver(mainDriver, props); - - mainDriver.EnvironmentDriver.GetDevicesFromConfig(avDriver.CurrentRoom.PropertiesConfig.Environment); - } - - mainDriver.HeaderDriver.SetupHeaderButtons(avDriver, avDriver.CurrentRoom); - - panelController.LoadAndShowDriver(mainDriver); // This is a little convoluted. - - if (panelController.Panel is TswFt5ButtonSystem) - { - var tsw = panelController.Panel as TswFt5ButtonSystem; - // Wire up hard keys - tsw.Power.UserObject = new Action(b => { if (!b) avDriver.PowerButtonPressed(); }); - //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); - if(mainDriver.EnvironmentDriver != null) - tsw.Lights.UserObject = new Action(b => - { - if (!b) - { - //mainDriver.AvDriver.PopupInterlock.ShowInterlockedWithToggle(mainDriver.EnvironmentDriver.BackgroundSubpageJoin); - mainDriver.EnvironmentDriver.Toggle(); - } - }); - tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); - tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); - } - } - //else if (room is EssentialsPresentationRoom) - //{ - // Debug.Console(0, panelController, "Adding presentation room driver"); - // var avDriver = new EssentialsPresentationPanelAvFunctionsDriver(mainDriver, props); - // avDriver.CurrentRoom = room as EssentialsPresentationRoom; - // avDriver.DefaultRoomKey = props.DefaultRoomKey; - // mainDriver.AvDriver = avDriver ; - // mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, props); - // panelController.LoadAndShowDriver(mainDriver); - - // if (panelController.Panel is TswFt5ButtonSystem) - // { - // var tsw = panelController.Panel as TswFt5ButtonSystem; - // // Wire up hard keys - // tsw.Power.UserObject = new Action(b => { if (!b) avDriver.PowerButtonPressed(); }); - // //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); - // tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); - // tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); - // } - //} - else if (room is EssentialsHuddleVtc1Room) - { - Debug.Console(0, panelController, "Adding huddle space VTC AV driver"); - - // Header Driver - mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, props); - - // AV Driver - var avDriver = new EssentialsHuddleVtc1PanelAvFunctionsDriver(mainDriver, props); - - var codecDriver = new PepperDash.Essentials.UIDrivers.VC.EssentialsVideoCodecUiDriver(panelController.Panel, avDriver, - (room as EssentialsHuddleVtc1Room).VideoCodec, mainDriver.HeaderDriver); - avDriver.SetVideoCodecDriver(codecDriver); - avDriver.DefaultRoomKey = props.DefaultRoomKey; - mainDriver.AvDriver = avDriver; - avDriver.CurrentRoom = room as EssentialsHuddleVtc1Room; - - // Environment Driver - if (avDriver.CurrentRoom.PropertiesConfig.Environment != null && avDriver.CurrentRoom.PropertiesConfig.Environment.DeviceKeys.Count > 0) - { - Debug.Console(0, panelController, "Adding environment driver"); - mainDriver.EnvironmentDriver = new EssentialsEnvironmentDriver(mainDriver, props); - - mainDriver.EnvironmentDriver.GetDevicesFromConfig(avDriver.CurrentRoom.PropertiesConfig.Environment); - } - - mainDriver.HeaderDriver.SetupHeaderButtons(avDriver, avDriver.CurrentRoom); - - panelController.LoadAndShowDriver(mainDriver); // This is a little convoluted. - - if (panelController.Panel is TswFt5ButtonSystem) - { - var tsw = panelController.Panel as TswFt5ButtonSystem; - // Wire up hard keys - tsw.Power.UserObject = new Action(b => { if (!b) avDriver.EndMeetingPress(); }); - //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); - if (mainDriver.EnvironmentDriver != null) - tsw.Lights.UserObject = new Action(b => - { - if (!b) - { - //mainDriver.AvDriver.PopupInterlock.ShowInterlockedWithToggle(mainDriver.EnvironmentDriver.BackgroundSubpageJoin); - mainDriver.EnvironmentDriver.Toggle(); - } - }); - tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); - tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); - } - } - else - { - Debug.Console(0, panelController, "ERROR: Cannot load AvFunctionsDriver for room '{0}'", props.DefaultRoomKey); - } - }); - - return panelController; + var essentialsTouchpanelControllerFactory = new EssentialsTouchpanelControllerFactory() as IDeviceFactory; + essentialsTouchpanelControllerFactory.LoadTypeFactories(); } } diff --git a/PepperDashEssentials/UI/EssentialsTouchpanelController.cs b/PepperDashEssentials/UI/EssentialsTouchpanelController.cs index df1ecdce..d008eee0 100644 --- a/PepperDashEssentials/UI/EssentialsTouchpanelController.cs +++ b/PepperDashEssentials/UI/EssentialsTouchpanelController.cs @@ -9,11 +9,12 @@ using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.UI; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.PageManagers; namespace PepperDash.Essentials { - public class EssentialsTouchpanelController : Device, IHasBasicTriListWithSmartObject + public class EssentialsTouchpanelController : EssentialsDevice, IHasBasicTriListWithSmartObject { public BasicTriListWithSmartObject Panel { get; private set; } @@ -197,4 +198,132 @@ namespace PepperDash.Essentials (uo as Action)(args.Button.State == eButtonState.Pressed); } } + + public class EssentialsTouchpanelControllerFactory : EssentialsDeviceFactory + { + public EssentialsTouchpanelControllerFactory() + { + TypeNames = new List() { "tsw550", "tsw750", "tsw1050", "tsw560", "tsw760", "tsw1060", "xpanel" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + var comm = CommFactory.GetControlPropertiesConfig(dc); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject(dc.Properties.ToString()); + + Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); + + var panelController = new EssentialsTouchpanelController(dc.Key, dc.Name, dc.Type, props, comm.IpIdInt); + + panelController.AddPostActivationAction(() => + { + var mainDriver = new EssentialsPanelMainInterfaceDriver(panelController.Panel, props); + // Then the sub drivers + + // spin up different room drivers depending on room type + var room = DeviceManager.GetDeviceForKey(props.DefaultRoomKey); + if (room is EssentialsHuddleSpaceRoom) + { + + // Header Driver + Debug.Console(0, panelController, "Adding header driver"); + mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, props); + + // AV Driver + Debug.Console(0, panelController, "Adding huddle space AV driver"); + var avDriver = new EssentialsHuddlePanelAvFunctionsDriver(mainDriver, props); + avDriver.DefaultRoomKey = props.DefaultRoomKey; + mainDriver.AvDriver = avDriver; + avDriver.CurrentRoom = room as EssentialsHuddleSpaceRoom; + + // Environment Driver + if (avDriver.CurrentRoom.PropertiesConfig.Environment != null && avDriver.CurrentRoom.PropertiesConfig.Environment.DeviceKeys.Count > 0) + { + Debug.Console(0, panelController, "Adding environment driver"); + mainDriver.EnvironmentDriver = new EssentialsEnvironmentDriver(mainDriver, props); + + mainDriver.EnvironmentDriver.GetDevicesFromConfig(avDriver.CurrentRoom.PropertiesConfig.Environment); + } + + mainDriver.HeaderDriver.SetupHeaderButtons(avDriver, avDriver.CurrentRoom); + + panelController.LoadAndShowDriver(mainDriver); // This is a little convoluted. + + if (panelController.Panel is TswFt5ButtonSystem) + { + var tsw = panelController.Panel as TswFt5ButtonSystem; + // Wire up hard keys + tsw.Power.UserObject = new Action(b => { if (!b) avDriver.PowerButtonPressed(); }); + //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); + if (mainDriver.EnvironmentDriver != null) + tsw.Lights.UserObject = new Action(b => + { + if (!b) + { + //mainDriver.AvDriver.PopupInterlock.ShowInterlockedWithToggle(mainDriver.EnvironmentDriver.BackgroundSubpageJoin); + mainDriver.EnvironmentDriver.Toggle(); + } + }); + tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); + tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); + } + } + else if (room is EssentialsHuddleVtc1Room) + { + Debug.Console(0, panelController, "Adding huddle space VTC AV driver"); + + // Header Driver + mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, props); + + // AV Driver + var avDriver = new EssentialsHuddleVtc1PanelAvFunctionsDriver(mainDriver, props); + + var codecDriver = new PepperDash.Essentials.UIDrivers.VC.EssentialsVideoCodecUiDriver(panelController.Panel, avDriver, + (room as EssentialsHuddleVtc1Room).VideoCodec, mainDriver.HeaderDriver); + avDriver.SetVideoCodecDriver(codecDriver); + avDriver.DefaultRoomKey = props.DefaultRoomKey; + mainDriver.AvDriver = avDriver; + avDriver.CurrentRoom = room as EssentialsHuddleVtc1Room; + + // Environment Driver + if (avDriver.CurrentRoom.PropertiesConfig.Environment != null && avDriver.CurrentRoom.PropertiesConfig.Environment.DeviceKeys.Count > 0) + { + Debug.Console(0, panelController, "Adding environment driver"); + mainDriver.EnvironmentDriver = new EssentialsEnvironmentDriver(mainDriver, props); + + mainDriver.EnvironmentDriver.GetDevicesFromConfig(avDriver.CurrentRoom.PropertiesConfig.Environment); + } + + mainDriver.HeaderDriver.SetupHeaderButtons(avDriver, avDriver.CurrentRoom); + + panelController.LoadAndShowDriver(mainDriver); // This is a little convoluted. + + if (panelController.Panel is TswFt5ButtonSystem) + { + var tsw = panelController.Panel as TswFt5ButtonSystem; + // Wire up hard keys + tsw.Power.UserObject = new Action(b => { if (!b) avDriver.EndMeetingPress(); }); + //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); + if (mainDriver.EnvironmentDriver != null) + tsw.Lights.UserObject = new Action(b => + { + if (!b) + { + //mainDriver.AvDriver.PopupInterlock.ShowInterlockedWithToggle(mainDriver.EnvironmentDriver.BackgroundSubpageJoin); + mainDriver.EnvironmentDriver.Toggle(); + } + }); + tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); + tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); + } + } + else + { + Debug.Console(0, panelController, "ERROR: Cannot load AvFunctionsDriver for room '{0}'", props.DefaultRoomKey); + } + }); + + return panelController; + } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/BridgeBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/BridgeBase.cs index 60781e38..ecb53ffc 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/BridgeBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Bridges/BridgeBase.cs @@ -110,139 +110,16 @@ namespace PepperDash.Essentials.Core.Bridges if (device == null) continue; Debug.Console(1, this, "Linking Device: '{0}'", device.Key); - /*if (device is IBridge) // Check for this first to allow bridges in plugins to override existing bridges that apply to the same type. + //if (device is IBridge) // Check for this first to allow bridges in plugins to override existing bridges that apply to the same type. + //{ + // Debug.Console(2, this, "'{0}' is IBridge", device.Key); + //} + if (device.GetType().GetCType().IsAssignableFrom(typeof (IBridgeAdvanced))) { - Debug.Console(2, this, "'{0}' is IBridge", device.Key); - - var dev = device as IBridge; - - dev.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - }*/ - if (!(device is IBridgeAdvanced)) continue; - Debug.Console(2, this, "'{0}' is IBridgeAdvanced", device.Key); - (device as IBridgeAdvanced).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this); - //if (device.GetType().GetCType().IsAssignableFrom(typeof (IBridge))) - //{ - // var bridge = device as IBridge; - - // if (bridge == null) - // continue; - // Debug.Console(2, this, "Linking device {0} as IBridge"); - // bridge.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - - //if (!device.GetType().GetCType().IsAssignableFrom(typeof (IBridgeAdvanced))) continue; - - //var bridgeAdvanced = device as IBridgeAdvanced; - - //if (bridgeAdvanced == null) continue; - //Debug.Console(2, this, "Linking device {0} as IBridgeAdvanced"); - //bridgeAdvanced.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this); + var bridge = device as IBridgeAdvanced; + if (bridge != null) bridge.LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this); + } } - Debug.Console(1, this, "Devices Linked."); - // - //else if (device is PepperDash.Essentials.Core.Monitoring.SystemMonitorController) - //{ - // (device as PepperDash.Essentials.Core.Monitoring.SystemMonitorController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is GenericComm) - //{ - // (device as GenericComm).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is CameraBase) - //{ - // (device as CameraBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey, this); - // continue; - //} - //else if (device is PepperDash.Essentials.Core.DisplayBase) - //{ - // (device as DisplayBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmChassisController) - //{ - // (device as DmChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmBladeChassisController) - //{ - // (device as DmBladeChassisController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmpsRoutingController) - //{ - // (device as DmpsRoutingController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmpsAudioOutputController) - //{ - // (device as DmpsAudioOutputController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmTxControllerBase) - //{ - // (device as DmTxControllerBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DmRmcControllerBase) - //{ - // (device as DmRmcControllerBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is GenericRelayDevice) - //{ - // (device as GenericRelayDevice).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is IRSetTopBoxBase) - //{ - // (device as IRSetTopBoxBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is IDigitalInput) - //{ - // (device as IDigitalInput).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is AppleTV) - //{ - // (device as AppleTV).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is HdMdxxxCEController) - //{ - // (device as HdMdxxxCEController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is LightingBase) - //{ - // (device as LightingBase).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is DigitalLogger) - //{ - // (device as DigitalLogger).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is PepperDash.Essentials.Devices.Common.Occupancy.GlsOccupancySensorBaseController) - //{ - // (device as PepperDash.Essentials.Devices.Common.Occupancy.GlsOccupancySensorBaseController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is StatusSignController) - //{ - // (device as StatusSignController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //else if (device is C2nRthsController) - //{ - // (device as C2nRthsController).LinkToApi(Eisc, d.JoinStart, d.JoinMapKey); - // continue; - //} - //} }); @@ -411,5 +288,20 @@ namespace PepperDash.Essentials.Core.Bridges } + public class EiscApiAdvancedFactory : EssentialsDeviceFactory + { + public EiscApiAdvancedFactory() + { + TypeNames = new List() { "eiscapiadv", "eiscapiadvanced" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new EiscApiAdvanced Device"); + + return new EiscApiAdvanced(dc); + + } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/ConsoleCommMockDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/ConsoleCommMockDevice.cs index d833aafa..f360e52b 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/ConsoleCommMockDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Comm and IR/ConsoleCommMockDevice.cs @@ -5,10 +5,12 @@ using System.Text; using Crestron.SimplSharp; using PepperDash.Core; +using PepperDash.Essentials.Core.Config; + namespace PepperDash.Essentials.Core { - public class ConsoleCommMockDevice : Device, ICommunicationMonitor + public class ConsoleCommMockDevice : EssentialsDevice, ICommunicationMonitor { public IBasicCommunication Communication { get; private set; } public CommunicationGather PortGather { get; private set; } @@ -71,4 +73,21 @@ namespace PepperDash.Essentials.Core } } + public class ConsoleCommMockDeviceFactory : EssentialsDeviceFactory + { + public ConsoleCommMockDeviceFactory() + { + TypeNames = new List() { "commmock" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Comm Mock Device"); + var comm = CommFactory.CreateCommForDevice(dc); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject( + dc.Properties.ToString()); + return new ConsoleCommMockDevice(dc.Key, dc.Name, props, comm); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/PC/InRoomPc.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/PC/InRoomPc.cs index 9a13106f..03e884f0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/PC/InRoomPc.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/PC/InRoomPc.cs @@ -4,6 +4,7 @@ using System.Linq; using Crestron.SimplSharpPro; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Routing; using PepperDash.Core; @@ -12,7 +13,7 @@ namespace PepperDash.Essentials.Core.Devices /// /// This DVD class should cover most IR, one-way DVD and Bluray fuctions /// - public class InRoomPc : Device, IHasFeedback, IRoutingOutputs, IAttachVideoStatus, IUiDisplayInfo, IUsageTracking + public class InRoomPc : EssentialsDevice, IHasFeedback, IRoutingOutputs, IAttachVideoStatus, IUiDisplayInfo, IUsageTracking { public uint DisplayUiType { get { return DisplayUiConstants.TypeLaptop; } } public string IconName { get; set; } @@ -63,4 +64,19 @@ namespace PepperDash.Essentials.Core.Devices #endregion } + + public class InRoomPcFactory : EssentialsDeviceFactory + { + public InRoomPcFactory() + { + TypeNames = new List() { "inroompc" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new InRoomPc Device"); + return new InRoomPc(dc.Key, dc.Name); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/PC/Laptop.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/PC/Laptop.cs index a1a8b30b..a2864d77 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/PC/Laptop.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/PC/Laptop.cs @@ -4,6 +4,7 @@ using System.Linq; using Crestron.SimplSharpPro; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Routing; using PepperDash.Core; @@ -12,7 +13,7 @@ namespace PepperDash.Essentials.Core.Devices /// /// This DVD class should cover most IR, one-way DVD and Bluray fuctions /// - public class Laptop : Device, IHasFeedback, IRoutingOutputs, IAttachVideoStatus, IUiDisplayInfo, IUsageTracking + public class Laptop : EssentialsDevice, IHasFeedback, IRoutingOutputs, IAttachVideoStatus, IUiDisplayInfo, IUsageTracking { public uint DisplayUiType { get { return DisplayUiConstants.TypeLaptop; } } public string IconName { get; set; } @@ -63,4 +64,18 @@ namespace PepperDash.Essentials.Core.Devices #endregion } + + public class LaptopFactory : EssentialsDeviceFactory + { + public LaptopFactory() + { + TypeNames = new List() { "laptop" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Laptop Device"); + return new Core.Devices.Laptop(dc.Key, dc.Name); + } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Display/BasicIrDisplay.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Display/BasicIrDisplay.cs index 29dcdd55..95628e4e 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Display/BasicIrDisplay.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Display/BasicIrDisplay.cs @@ -8,6 +8,7 @@ using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Routing; @@ -208,4 +209,27 @@ namespace PepperDash.Essentials.Core LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge); } } + + public class BasicIrDisplayFactory : EssentialsDeviceFactory + { + public BasicIrDisplayFactory() + { + TypeNames = new List() { "basicirdisplay" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new BasicIrDisplay Device"); + var ir = IRPortHelper.GetIrPort(dc.Properties); + if (ir != null) + { + var display = new BasicIrDisplay(dc.Key, dc.Name, ir.Port, ir.FileName); + display.IrPulseTime = 200; // Set default pulse time for IR commands. + return display; + } + + return null; + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Display/MockDisplay.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Display/MockDisplay.cs index 8c188997..e6db4316 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Display/MockDisplay.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Display/MockDisplay.cs @@ -12,7 +12,7 @@ using Crestron.SimplSharpPro.DM.Endpoints.Transmitters; using PepperDash.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Routing; - +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core { @@ -182,4 +182,19 @@ namespace PepperDash.Essentials.Core LinkDisplayToApi(this, trilist, joinStart, joinMapKey, bridge); } } + + public class MockDisplayFactory : EssentialsDeviceFactory + { + public MockDisplayFactory() + { + TypeNames = new List() { "mockdisplay" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Mock Display Device"); + return new MockDisplay(dc.Key, dc.Name); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Room/Behaviours/RoomOnToDefaultSourceWhenOccupied.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Room/Behaviours/RoomOnToDefaultSourceWhenOccupied.cs index fcb04420..11debb03 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Room/Behaviours/RoomOnToDefaultSourceWhenOccupied.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Room/Behaviours/RoomOnToDefaultSourceWhenOccupied.cs @@ -522,4 +522,19 @@ namespace PepperDash.Essentials.Core [JsonProperty("enableSaturday")] public bool EnableSaturday { get; set; } } + + public class RoomOnToDefaultSourceWhenOccupiedFactory : EssentialsDeviceFactory + { + public RoomOnToDefaultSourceWhenOccupiedFactory() + { + TypeNames = new List() { "roomonwhenoccupancydetectedfeature" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new RoomOnToDefaultSourceWhenOccupied Device"); + return new RoomOnToDefaultSourceWhenOccupied(dc); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/DGEs/DgeController.cs b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/DGEs/DgeController.cs index 0fc00323..6b586ac3 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Endpoints/DGEs/DgeController.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Endpoints/DGEs/DgeController.cs @@ -63,4 +63,37 @@ namespace PepperDash.Essentials.DM.Endpoints.DGEs #endregion } + + public class DgeControllerFactory : EssentialsDeviceFactory + { + public DgeControllerFactory() + { + TypeNames = new List() { "dge100", "dmdge200c" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + var typeName = dc.Type.ToLower(); + var comm = CommFactory.GetControlPropertiesConfig(dc); + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + Debug.Console(1, "Factory Attempting to create new DgeControllerm Device"); + + Dge100 dgeDevice = null; + if (typeName == "dge100") + dgeDevice = new Dge100(comm.IpIdInt, Global.ControlSystem); + else if (typeName == "dmdge200c") + dgeDevice = new DmDge200C(comm.IpIdInt, Global.ControlSystem); + + if (dgeDevice == null) + { + Debug.Console(1, "Unable to create DGE device"); + return null; + } + + var dgeController = new DgeController(dc.Key + "-comPorts", dc.Name, dgeDevice, dc, props); + + return dgeController; + } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Audio/GenericAudioOut.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Audio/GenericAudioOut.cs index d89a36fc..70596904 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Audio/GenericAudioOut.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Audio/GenericAudioOut.cs @@ -6,6 +6,8 @@ using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; + using PepperDash.Essentials.Core.Routing; namespace PepperDash.Essentials.Devices.Common @@ -13,7 +15,7 @@ namespace PepperDash.Essentials.Devices.Common /// /// Represents and audio endpoint /// - public class GenericAudioOut : Device, IRoutingSinkNoSwitching + public class GenericAudioOut : EssentialsDevice, IRoutingSinkNoSwitching { public event SourceInfoChangeHandler CurrentSourceChange; @@ -98,4 +100,20 @@ namespace PepperDash.Essentials.Devices.Common } + public class GenericAudioOutWithVolumeFactory : EssentialsDeviceFactory + { + public GenericAudioOutWithVolumeFactory() + { + TypeNames = new List() { "genericaudiooutwithvolume" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new GenericAudioOutWithVolumeFactory Device"); + var zone = dc.Properties.Value("zone"); + return new GenericAudioOutWithVolume(dc.Key, dc.Name, + dc.Properties.Value("volumeDeviceKey"), zone); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Cameras/CameraVisca.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Cameras/CameraVisca.cs index d95a14cc..bb6758b6 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Cameras/CameraVisca.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Cameras/CameraVisca.cs @@ -7,6 +7,7 @@ using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Devices.Common.Codec; using System.Text.RegularExpressions; using Crestron.SimplSharp.Reflection; @@ -244,4 +245,22 @@ namespace PepperDash.Essentials.Devices.Common.Cameras #endregion } + + public class CameraViscaFactory : EssentialsDeviceFactory + { + public CameraViscaFactory() + { + TypeNames = new List() { "cameravisca" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new CameraVisca Device"); + var comm = CommFactory.CreateCommForDevice(dc); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject( + dc.Properties.ToString()); + return new Cameras.CameraVisca(dc.Key, dc.Name, comm, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Crestron/Gateways/CenRfgwController.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Crestron/Gateways/CenRfgwController.cs index ee37674a..04f6eb17 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Crestron/Gateways/CenRfgwController.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Crestron/Gateways/CenRfgwController.cs @@ -8,6 +8,8 @@ using Crestron.SimplSharpPro.Gateways; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; + namespace PepperDash.Essentials.Devices.Common { @@ -112,4 +114,20 @@ namespace PepperDash.Essentials.Devices.Common { Ethernet, EthernetShared, Cresnet } + + public class CenRfgwControllerFactory : EssentialsDeviceFactory + { + public CenRfgwControllerFactory() + { + TypeNames = new List() { "cenrfgwex", "cenerfgwpoe" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new CEN-GWEXER Device"); + return CenRfgwController.GetNewExGatewayController(dc.Key, dc.Name, + dc.Properties.Value("id"), dc.Properties.Value("gatewayType")); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/DSP/BiampTesira/BiampTesiraForteDsp.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/DSP/BiampTesira/BiampTesiraForteDsp.cs index 27a29145..86850fea 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/DSP/BiampTesira/BiampTesiraForteDsp.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/DSP/BiampTesira/BiampTesiraForteDsp.cs @@ -5,6 +5,7 @@ using System.Text; using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using System.Text.RegularExpressions; @@ -373,4 +374,22 @@ namespace PepperDash.Essentials.Devices.Common.DSP public TesiraForteControlPoint ControlPoint { get; set; } } } + + public class BiampTesiraForteDspFactory : EssentialsDeviceFactory + { + public BiampTesiraForteDspFactory() + { + TypeNames = new List() { "biamptesira" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new BiampTesira Device"); + var comm = CommFactory.CreateCommForDevice(dc); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject( + dc.Properties.ToString()); + return new BiampTesiraForteDsp(dc.Key, dc.Name, comm, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/DSP/DspBase.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/DSP/DspBase.cs index 0f572642..cad57761 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/DSP/DspBase.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/DSP/DspBase.cs @@ -9,7 +9,7 @@ using PepperDash.Essentials.Core; namespace PepperDash.Essentials.Devices.Common.DSP { - public abstract class DspBase : Device + public abstract class DspBase : EssentialsDevice { public Dictionary LevelControlPoints { get; private set; } diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/DiscPlayer/IRDiscPlayerBase.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/DiscPlayer/IRDiscPlayerBase.cs index 0f4a65ac..581ea3b5 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/DiscPlayer/IRDiscPlayerBase.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/DiscPlayer/IRDiscPlayerBase.cs @@ -5,13 +5,18 @@ using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + + using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Routing; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Devices.Common { - public class IRBlurayBase : Device, IDiscPlayerControls, IUiDisplayInfo, IRoutingOutputs, IUsageTracking + public class IRBlurayBase : EssentialsDevice, IDiscPlayerControls, IUiDisplayInfo, IRoutingOutputs, IUsageTracking { public IrOutputPortController IrPort { get; private set; } @@ -311,4 +316,30 @@ namespace PepperDash.Essentials.Devices.Common #endregion } + + public class IRBlurayBaseFactory : EssentialsDeviceFactory + { + public IRBlurayBaseFactory() + { + TypeNames = new List() { "discplayer", "bluray" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new IRBlurayPlayer Device"); + + if (dc.Properties["control"]["method"].Value() == "ir") + { + var irCont = IRPortHelper.GetIrOutputPortController(dc); + return new IRBlurayBase(dc.Key, dc.Name, irCont); + } + else if (dc.Properties["control"]["method"].Value() == "com") + { + Debug.Console(0, "[{0}] COM Device type not implemented YET!", dc.Key); + } + + return null; + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs index 58f97b03..fc07a6dc 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs @@ -18,12 +18,51 @@ using PepperDash.Essentials.Devices.Common.VideoCodec; using PepperDash.Essentials.Devices.Common.Occupancy; using PepperDash.Essentials.Devices.Common.Environment; - - namespace PepperDash.Essentials.Devices.Common { public class DeviceFactory { + public DeviceFactory() + { + var appleTVFactory = new AppleTVFactory() as IDeviceFactory; + appleTVFactory.LoadTypeFactories(); + + var analogWayLCFactory = new AnalogWayLiveCoreFactory() as IDeviceFactory; + analogWayLCFactory.LoadTypeFactories(); + + var basicIrDisplayFactory = new BasicIrDisplayFactory() as IDeviceFactory; + basicIrDisplayFactory.LoadTypeFactories(); + + var biampTesiraFactory = new BiampTesiraForteDspFactory() as IDeviceFactory; + biampTesiraFactory.LoadTypeFactories(); + + var cameraViscaFactory = new Cameras.CameraViscaFactory() as IDeviceFactory; + cameraViscaFactory.LoadTypeFactories(); + + var cenRfGwFactory = new CenRfgwControllerFactory() as IDeviceFactory; + cenRfGwFactory.LoadTypeFactories(); + + var irBlurayFactory = new IRBlurayBaseFactory() as IDeviceFactory; + irBlurayFactory.LoadTypeFactories(); + + var digitalLoggerFactory = new DigitalLoggerFactory() as IDeviceFactory; + digitalLoggerFactory.LoadTypeFactories(); + + var genericAudioOutFactory = new GenericAudioOutWithVolumeFactory() as IDeviceFactory; + genericAudioOutFactory.LoadTypeFactories(); + + var genericSourceFactory = new GenericSourceFactory() as IDeviceFactory; + genericSourceFactory.LoadTypeFactories(); + + var inRoomPcFactory = new Core.Devices.InRoomPcFactory() as IDeviceFactory; + inRoomPcFactory.LoadTypeFactories(); + + var laptopFactory = new Core.Devices.LaptopFactory() as IDeviceFactory; + laptopFactory.LoadTypeFactories(); + + + } + public static IKeyed GetDevice(DeviceConfig dc) { var key = dc.Key; @@ -36,100 +75,8 @@ namespace PepperDash.Essentials.Devices.Common var typeName = dc.Type.ToLower(); var groupName = dc.Group.ToLower(); - if (typeName == "appletv") - { - var irCont = IRPortHelper.GetIrOutputPortController(dc); - return new AppleTV(key, name, irCont); - } - else if (typeName == "analogwaylivecore") - { - var comm = CommFactory.CreateCommForDevice(dc); - var props = JsonConvert.DeserializeObject( - properties.ToString()); - return new AnalogWayLiveCore(key, name, comm, props); - } - else if (typeName == "basicirdisplay") - { - var ir = IRPortHelper.GetIrPort(properties); - if (ir != null) - { - var display = new BasicIrDisplay(key, name, ir.Port, ir.FileName); - display.IrPulseTime = 200; // Set default pulse time for IR commands. - return display; - } - } - - else if (typeName == "biamptesira") - { - var comm = CommFactory.CreateCommForDevice(dc); - var props = JsonConvert.DeserializeObject( - properties.ToString()); - return new BiampTesiraForteDsp(key, name, comm, props); - } - - - else if (typeName == "cameravisca") - { - var comm = CommFactory.CreateCommForDevice(dc); - var props = JsonConvert.DeserializeObject( - properties.ToString()); - return new Cameras.CameraVisca(key, name, comm, props); - } - - else if (typeName == "cenrfgwex") - { - return CenRfgwController.GetNewExGatewayController(key, name, - properties.Value("id"), properties.Value("gatewayType")); - } - - else if (typeName == "cenerfgwpoe") - { - return CenRfgwController.GetNewErGatewayController(key, name, - properties.Value("id"), properties.Value("gatewayType")); - } - - else if (groupName == "discplayer") // (typeName == "irbluray") - { - if (properties["control"]["method"].Value() == "ir") - { - var irCont = IRPortHelper.GetIrOutputPortController(dc); - return new IRBlurayBase(key, name, irCont); - } - else if (properties["control"]["method"].Value() == "com") - { - Debug.Console(0, "[{0}] COM Device type not implemented YET!", key); - } - } - else if (typeName == "digitallogger") - { - // var comm = CommFactory.CreateCommForDevice(dc); - var props = JsonConvert.DeserializeObject( - properties.ToString()); - return new DigitalLogger(key, name, props); - } - else if (typeName == "genericaudiooutwithvolume") - { - var zone = dc.Properties.Value("zone"); - return new GenericAudioOutWithVolume(key, name, - dc.Properties.Value("volumeDeviceKey"), zone); - } - - else if (groupName == "genericsource") - { - return new GenericSource(key, name); - } - - else if (typeName == "inroompc") - { - return new Core.Devices.InRoomPc(key, name); - } - - else if (typeName == "laptop") - { - return new Core.Devices.Laptop(key, name); - } - - else if (typeName == "bluejeanspc") + // TODO: Continue from here + if (typeName == "bluejeanspc") { return new SoftCodec.BlueJeansPc(key, name); } diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Generic/GenericSource.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Generic/GenericSource.cs index 4627fd7b..697639e5 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Generic/GenericSource.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Generic/GenericSource.cs @@ -8,11 +8,12 @@ using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Routing; namespace PepperDash.Essentials.Devices.Common { - public class GenericSource : Device, IUiDisplayInfo, IRoutingOutputs, IUsageTracking + public class GenericSource : EssentialsDevice, IUiDisplayInfo, IRoutingOutputs, IUsageTracking { public uint DisplayUiType { get { return DisplayUiConstants.TypeNoControls; } } @@ -39,4 +40,19 @@ namespace PepperDash.Essentials.Devices.Common #endregion } + + public class GenericSourceFactory : EssentialsDeviceFactory + { + public GenericSourceFactory() + { + TypeNames = new List() { "genericsource" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic Source Device"); + return new GenericSource(dc.Key, dc.Name); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/ImageProcessors/AnalogWay/AnalongWayLiveCore.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/ImageProcessors/AnalogWay/AnalongWayLiveCore.cs index c2178bdb..97d8a8dd 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/ImageProcessors/AnalogWay/AnalongWayLiveCore.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/ImageProcessors/AnalogWay/AnalongWayLiveCore.cs @@ -5,13 +5,14 @@ using System.Text; using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using System.Text.RegularExpressions; namespace PepperDash.Essentials.Devices.Common { - public class AnalogWayLiveCore : Device + public class AnalogWayLiveCore : EssentialsDevice { public IBasicCommunication Communication { get; private set; } public CommunicationGather PortGather { get; private set; } @@ -238,4 +239,22 @@ namespace PepperDash.Essentials.Devices.Common // public QscDspControlPoint ControlPoint { get; set; } } } + + public class AnalogWayLiveCoreFactory : EssentialsDeviceFactory + { + public AnalogWayLiveCoreFactory() + { + TypeNames = new List() { "analogwaylivecore" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new AnalogWayLiveCore Device"); + var comm = CommFactory.CreateCommForDevice(dc); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject( + dc.Properties.ToString()); + return new AnalogWayLiveCore(dc.Key, dc.Name, comm, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Power Controllers/Digitallogger.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Power Controllers/Digitallogger.cs index 42666045..11a96537 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Power Controllers/Digitallogger.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Power Controllers/Digitallogger.cs @@ -11,6 +11,7 @@ using Crestron.SimplSharp.Net.Http; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Devices.Common @@ -337,4 +338,20 @@ namespace PepperDash.Essentials.Devices.Common } } + + public class DigitalLoggerFactory : EssentialsDeviceFactory + { + public DigitalLoggerFactory() + { + TypeNames = new List() { "digitallogger" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new DigitalLogger Device"); + var props = JsonConvert.DeserializeObject( + dc.Properties.ToString()); + return new DigitalLogger(dc.Key, dc.Name, props); + } + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Streaming/AppleTV.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Streaming/AppleTV.cs index db729ce7..1182d312 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Streaming/AppleTV.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Streaming/AppleTV.cs @@ -8,6 +8,7 @@ using Crestron.SimplSharpPro.DeviceSupport; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Routing; @@ -166,4 +167,20 @@ namespace PepperDash.Essentials.Devices.Common trilist.SetBoolSigAction(joinMap.PlayPause, Play); } } + + public class AppleTVFactory : EssentialsDeviceFactory + { + public AppleTVFactory() + { + TypeNames = new List() { "appletv" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new AppleTV Device"); + var irCont = IRPortHelper.GetIrOutputPortController(dc); + return new AppleTV(dc.Key, dc.Name, irCont); + } + } + } \ No newline at end of file From 4f6ae386b4009047eab90d879e639dc86d1a1903 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Wed, 22 Apr 2020 16:17:07 -0600 Subject: [PATCH 07/10] Finishes converting all existing types to new DeviceFactory mechanism. #106 --- PepperDashEssentials/Bridges/BridgeFactory.cs | 1 - PepperDashEssentials/ControlSystem.cs | 6 +- .../Inputs/GenericDigitalInputDevice.cs | 93 +++++ .../Inputs/GenericVersiportInputDevice.cs | 2 +- .../Crestron IO/Relay/GenericRelayDevice.cs | 72 ++++ .../Factory/DeviceFactory.cs | 2 +- .../MicrophonePrivacyController.cs | 20 +- .../Shades/ShadeBase.cs | 2 +- .../Shades/ShadeController.cs | 20 +- .../AudioCodec/AudioCodecBase.cs | 2 +- .../AudioCodec/MockAC/MockAC.cs | 17 + .../Display/AvocorVTFDisplay.cs | 21 ++ .../Display/DeviceFactory.cs | 55 +-- .../Display/NECPSXMDisplay.cs | 20 ++ .../Display/PanasonicThDisplay.cs | 30 +- .../Display/SamsungMDCDisplay.cs | 22 ++ .../Environment/Crestron Lighting/Din8sw8.cs | 20 +- .../Environment/Lutron/LutronQuantum.cs | 20 ++ .../Environment/Somfy/RelayControlledShade.cs | 18 + .../Factory/DeviceFactory.cs | 322 +++--------------- .../ImageProcessors/TVOneCorio.cs | 21 +- .../GlsOccupancySensorBaseController.cs | 35 ++ .../GlsOdtOccupancySensorController.cs | 34 ++ .../SetTopBox/IRSetTopBoxBase.cs | 24 ++ .../SoftCodec/BlueJeansPc.cs | 15 + .../Streaming/Roku.cs | 20 +- .../VideoCodec/CiscoCodec/CiscoSparkCodec.cs | 15 + .../VideoCodec/MockVC/MockVC.cs | 15 + .../VideoCodec/ZoomRoom/ZoomRoom.cs | 16 + 29 files changed, 626 insertions(+), 334 deletions(-) diff --git a/PepperDashEssentials/Bridges/BridgeFactory.cs b/PepperDashEssentials/Bridges/BridgeFactory.cs index 21d3a346..c17d4642 100644 --- a/PepperDashEssentials/Bridges/BridgeFactory.cs +++ b/PepperDashEssentials/Bridges/BridgeFactory.cs @@ -32,7 +32,6 @@ namespace PepperDash.Essentials } - public class CommBridge : Device { public CommBridgeProperties Properties { get; private set; } diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index 3e6654b2..b7ce9288 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -101,7 +101,7 @@ namespace PepperDash.Essentials new BridgeFactory(); new PepperDash.Essentials.Devices.Common.DeviceFactory(); - + new PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory(); } @@ -379,8 +379,8 @@ namespace PepperDash.Essentials newDev = PepperDash.Essentials.Core.DeviceFactory.GetDevice(devConf); // - if (newDev == null) - newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf); + //if (newDev == null) + // newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf); // if (newDev != null) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericDigitalInputDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericDigitalInputDevice.cs index 70921314..33cb0ae6 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericDigitalInputDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericDigitalInputDevice.cs @@ -8,6 +8,8 @@ using Crestron.SimplSharpPro.DeviceSupport; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; +using PepperDash_Essentials_Core.Devices; namespace PepperDash.Essentials.Core.CrestronIO { @@ -66,4 +68,95 @@ namespace PepperDash.Essentials.Core.CrestronIO } } } + + public class GenericDigitalInputDeviceFactory : EssentialsDeviceFactory + { + public GenericDigitalInputDeviceFactory() + { + TypeNames = new List() { "digitalinput" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Digtal Input Device"); + + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + IDigitalInputPorts portDevice; + + if (props.PortDeviceKey == "processor") + portDevice = Global.ControlSystem as IDigitalInputPorts; + else + portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IDigitalInputPorts; + + if (portDevice == null) + Debug.Console(0, "ERROR: Unable to add digital input device with key '{0}'. Port Device does not support digital inputs", dc.Key); + else + { + var cs = (portDevice as CrestronControlSystem); + if (cs == null) + { + Debug.Console(0, "ERROR: Port device for [{0}] is not control system", props.PortDeviceKey); + return null; + } + + if (cs.SupportsVersiport) + { + Debug.Console(1, "Attempting to add Digital Input device to Versiport port '{0}'", props.PortNumber); + + if (props.PortNumber > cs.NumberOfVersiPorts) + { + Debug.Console(0, "WARNING: Cannot add Vesiport {0} on {1}. Out of range", + props.PortNumber, props.PortDeviceKey); + return null; + } + + Versiport vp = cs.VersiPorts[props.PortNumber]; + + if (!vp.Registered) + { + var regSuccess = vp.Register(); + if (regSuccess == eDeviceRegistrationUnRegistrationResponse.Success) + { + Debug.Console(1, "Successfully Created Digital Input Device on Versiport"); + return new GenericVersiportDigitalInputDevice(dc.Key, vp, props); + } + else + { + Debug.Console(0, "WARNING: Attempt to register versiport {0} on device with key '{1}' failed: {2}", + props.PortNumber, props.PortDeviceKey, regSuccess); + return null; + } + } + } + else if (cs.SupportsDigitalInput) + { + Debug.Console(1, "Attempting to add Digital Input device to Digital Input port '{0}'", props.PortNumber); + + if (props.PortNumber > cs.NumberOfDigitalInputPorts) + { + Debug.Console(0, "WARNING: Cannot register DIO port {0} on {1}. Out of range", + props.PortNumber, props.PortDeviceKey); + return null; + } + + DigitalInput digitalInput = cs.DigitalInputPorts[props.PortNumber]; + + if (!digitalInput.Registered) + { + if (digitalInput.Register() == eDeviceRegistrationUnRegistrationResponse.Success) + { + Debug.Console(1, "Successfully Created Digital Input Device on Digital Input"); + return new GenericDigitalInputDevice(dc.Key, digitalInput); + } + else + Debug.Console(0, "WARNING: Attempt to register digital input {0} on device with key '{1}' failed.", + props.PortNumber, props.PortDeviceKey); + } + } + } + return null; + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericVersiportInputDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericVersiportInputDevice.cs index 4c5359b9..90ff4fa0 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericVersiportInputDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericVersiportInputDevice.cs @@ -12,7 +12,7 @@ namespace PepperDash.Essentials.Core.CrestronIO /// /// Represents a generic digital input deviced tied to a versiport /// - public class GenericVersiportDigitalInputDevice : Device, IDigitalInput + public class GenericVersiportDigitalInputDevice : EssentialsDevice, IDigitalInput { public Versiport InputPort { get; private set; } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs index 39a6786b..3e3b0576 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs @@ -8,6 +8,8 @@ using Crestron.SimplSharpPro.DeviceSupport; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; +using PepperDash_Essentials_Core.Devices; namespace PepperDash.Essentials.Core.CrestronIO { @@ -100,4 +102,74 @@ namespace PepperDash.Essentials.Core.CrestronIO OutputIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.Relay]); } } + + public class GenericRelayDeviceFactory : EssentialsDeviceFactory + { + public GenericRelayDeviceFactory() + { + TypeNames = new List() { "relayoutput" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic Relay Device"); + + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + var key = dc.Key; + + IRelayPorts portDevice; + + if (props.PortDeviceKey == "processor") + portDevice = Global.ControlSystem as IRelayPorts; + else + portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IRelayPorts; + + if (portDevice == null) + Debug.Console(0, "Unable to add relay device with key '{0}'. Port Device does not support relays", key); + else + { + var cs = (portDevice as CrestronControlSystem); + + if (cs != null) + { + // The relay is on a control system processor + if (!cs.SupportsRelay || props.PortNumber > cs.NumberOfRelayPorts) + { + Debug.Console(0, "Port Device: {0} does not support relays or does not have enough relays"); + return null; + } + } + else + { + // The relay is on another device type + + if (props.PortNumber > portDevice.NumberOfRelayPorts) + { + Debug.Console(0, "Port Device: {0} does not have enough relays"); + return null; + } + } + + Relay relay = portDevice.RelayPorts[props.PortNumber]; + + if (!relay.Registered) + { + if (relay.Register() == eDeviceRegistrationUnRegistrationResponse.Success) + return new GenericRelayDevice(key, relay); + else + Debug.Console(0, "Attempt to register relay {0} on device with key '{1}' failed.", props.PortNumber, props.PortDeviceKey); + } + else + { + return new GenericRelayDevice(key, relay); + } + + // Future: Check if portDevice is 3-series card or other non control system that supports versiports + } + + return null; + + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs index 80725cc3..4e12ab05 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs @@ -105,7 +105,7 @@ namespace PepperDash.Essentials.Core Debug.Console(0, "Device Types:"); - foreach (var type in types) + foreach (var type in types.OrderBy(t => t.Key)) { var description = type.Value.Description; var cType = "Not Specified by Plugin"; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Microphone Privacy/MicrophonePrivacyController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Microphone Privacy/MicrophonePrivacyController.cs index e238c40e..ece2c65f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Microphone Privacy/MicrophonePrivacyController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Microphone Privacy/MicrophonePrivacyController.cs @@ -6,6 +6,7 @@ using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.CrestronIO; @@ -15,7 +16,7 @@ namespace PepperDash.Essentials.Core.Privacy /// Used for applications where one or more microphones with momentary contact closure outputs are used to /// toggle the privacy state of the room. Privacy state feedback is represented /// - public class MicrophonePrivacyController : Device + public class MicrophonePrivacyController : EssentialsDevice { MicrophonePrivacyControllerConfig Config; @@ -225,4 +226,21 @@ namespace PepperDash.Essentials.Core.Privacy } } } + + public class MicrophonePrivacyControllerFactory : EssentialsDeviceFactory + { + public MicrophonePrivacyControllerFactory() + { + TypeNames = new List() { "microphoneprivacycontroller" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new MIcrophonePrivacyController Device"); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject(dc.Properties.ToString()); + + return new Core.Privacy.MicrophonePrivacyController(dc.Key, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Shades/ShadeBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Shades/ShadeBase.cs index 636a5440..d30b716a 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Shades/ShadeBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Shades/ShadeBase.cs @@ -12,7 +12,7 @@ namespace PepperDash.Essentials.Core.Shades /// /// Base class for a shade device /// - public abstract class ShadeBase : Device, IShadesOpenClose + public abstract class ShadeBase : EssentialsDevice, IShadesOpenClose { public ShadeBase(string key, string name) : base(key, name) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Shades/ShadeController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Shades/ShadeController.cs index b226af05..fc50f631 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Shades/ShadeController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Shades/ShadeController.cs @@ -5,13 +5,14 @@ using System.Text; using Crestron.SimplSharp; using PepperDash.Core; +using PepperDash.Essentials.Core.Config; namespace PepperDash.Essentials.Core.Shades { /// /// Class that contains the shades to be controlled in a room /// - public class ShadeController : Device, IShades + public class ShadeController : EssentialsDevice, IShades { ShadeControllerConfigProperties Config; @@ -55,4 +56,21 @@ namespace PepperDash.Essentials.Core.Shades public string Key { get; set; } } } + + public class ShadeControllerFactory : EssentialsDeviceFactory + { + public ShadeControllerFactory() + { + TypeNames = new List() { "shadecontroller" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new ShadeController Device"); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject(dc.Properties.ToString()); + + return new Core.Shades.ShadeController(dc.Key, dc.Name, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/AudioCodec/AudioCodecBase.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/AudioCodec/AudioCodecBase.cs index 15a998a4..56998d46 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/AudioCodec/AudioCodecBase.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/AudioCodec/AudioCodecBase.cs @@ -10,7 +10,7 @@ using PepperDash.Essentials.Devices.Common.Codec; namespace PepperDash.Essentials.Devices.Common.AudioCodec { - public abstract class AudioCodecBase : Device, IHasDialer, IUsageTracking, IAudioCodecInfo + public abstract class AudioCodecBase : EssentialsDevice, IHasDialer, IUsageTracking, IAudioCodecInfo { public event EventHandler CallStatusChange; diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/AudioCodec/MockAC/MockAC.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/AudioCodec/MockAC/MockAC.cs index e0645624..84880654 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/AudioCodec/MockAC/MockAC.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/AudioCodec/MockAC/MockAC.cs @@ -6,6 +6,7 @@ using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Devices.Common.Codec; namespace PepperDash.Essentials.Devices.Common.AudioCodec @@ -111,4 +112,20 @@ namespace PepperDash.Essentials.Devices.Common.AudioCodec } } } + + public class MockACFactory : EssentialsDeviceFactory + { + public MockACFactory() + { + TypeNames = new List() { "mockac" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new MockAc Device"); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject(dc.Properties.ToString()); + return new AudioCodec.MockAC(dc.Key, dc.Name, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/AvocorVTFDisplay.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/AvocorVTFDisplay.cs index 71d8e149..19482029 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/AvocorVTFDisplay.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/AvocorVTFDisplay.cs @@ -9,6 +9,7 @@ using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Routing; using Feedback = PepperDash.Essentials.Core.Feedback; @@ -725,4 +726,24 @@ namespace PepperDash.Essentials.Devices.Displays #endregion } + + public class AvocorDisplayFactory : EssentialsDeviceFactory + { + public AvocorDisplayFactory() + { + TypeNames = new List() { "avocorvtf" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); + var comm = CommFactory.CreateCommForDevice(dc); + if (comm != null) + return new AvocorDisplay(dc.Key, dc.Name, comm, null); + else + return null; + + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/DeviceFactory.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/DeviceFactory.cs index 8b4941d7..099e1204 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/DeviceFactory.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/DeviceFactory.cs @@ -14,51 +14,20 @@ namespace PepperDash.Essentials.Devices.Displays { public class DisplayDeviceFactory { - public static IKeyed GetDevice(DeviceConfig dc) - { - var key = dc.Key; - var name = dc.Name; - var type = dc.Type; - var properties = dc.Properties; + public DisplayDeviceFactory() + { + var necFactory = new NecPSXMDisplayFactory() as IDeviceFactory; + necFactory.LoadTypeFactories(); - var typeName = dc.Type.ToLower(); + var panasonicThFactory = new PanasonicThDisplayFactory() as IDeviceFactory; + panasonicThFactory.LoadTypeFactories(); - try - { - if (typeName == "necmpsx") - { - var comm = CommFactory.CreateCommForDevice(dc); - if (comm != null) - return new NecPSXMDisplay(dc.Key, dc.Name, comm); - } - if (typeName == "panasonicthef") - { - var comm = CommFactory.CreateCommForDevice(dc); - if (comm != null) - return new PanasonicThefDisplay(dc.Key, dc.Name, comm); - } - else if(typeName == "samsungmdc") - { - var comm = CommFactory.CreateCommForDevice(dc); - if (comm != null) - return new SamsungMDC(dc.Key, dc.Name, comm, dc.Properties["id"].Value()); - } - if (typeName == "avocorvtf") - { - var comm = CommFactory.CreateCommForDevice(dc); - if (comm != null) - return new AvocorDisplay(dc.Key, dc.Name, comm, null); - } - - } - catch (Exception e) - { - Debug.Console(0, "Displays factory: Exception creating device type {0}, key {1}: \nCONFIG JSON: {2} \nERROR: {3}\n\n", - dc.Type, dc.Key, JsonConvert.SerializeObject(dc), e); - return null; - } + var samsungMdcFactory = new SamsungMDCFactory() as IDeviceFactory; + samsungMdcFactory.LoadTypeFactories(); + + var avocorFactory = new AvocorDisplayFactory() as IDeviceFactory; + avocorFactory.LoadTypeFactories(); + } - return null; - } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/NECPSXMDisplay.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/NECPSXMDisplay.cs index b147dcc1..72311c7e 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/NECPSXMDisplay.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/NECPSXMDisplay.cs @@ -7,6 +7,7 @@ using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Routing; using Feedback = PepperDash.Essentials.Core.Feedback; @@ -361,4 +362,23 @@ namespace PepperDash.Essentials.Devices.Displays #endregion } + + public class NecPSXMDisplayFactory : EssentialsDeviceFactory + { + public NecPSXMDisplayFactory() + { + TypeNames = new List() { "necmpsx" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); + var comm = CommFactory.CreateCommForDevice(dc); + if (comm != null) + return new NecPSXMDisplay(dc.Key, dc.Name, comm); + else + return null; + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/PanasonicThDisplay.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/PanasonicThDisplay.cs index 24ea0841..3ac01d66 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/PanasonicThDisplay.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/PanasonicThDisplay.cs @@ -7,6 +7,7 @@ using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Routing; using Feedback = PepperDash.Essentials.Core.Feedback; @@ -16,7 +17,7 @@ namespace PepperDash.Essentials.Devices.Displays /// /// /// - public class PanasonicThefDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor + public class PanasonicThDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor { public IBasicCommunication Communication { get; private set; } public CommunicationGather PortGather { get; private set; } @@ -73,7 +74,7 @@ namespace PepperDash.Essentials.Devices.Displays /// /// Constructor for IBasicCommunication /// - public PanasonicThefDisplay(string key, string name, IBasicCommunication comm) + public PanasonicThDisplay(string key, string name, IBasicCommunication comm) : base(key, name) { Communication = comm; @@ -82,7 +83,7 @@ namespace PepperDash.Essentials.Devices.Displays /// /// Constructor for TCP /// - public PanasonicThefDisplay(string key, string name, string hostname, int port) + public PanasonicThDisplay(string key, string name, string hostname, int port) : base(key, name) { Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000); @@ -93,7 +94,7 @@ namespace PepperDash.Essentials.Devices.Displays /// /// Constructor for COM /// - public PanasonicThefDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec) + public PanasonicThDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec) : base(key, name) { Communication = new ComPortController(key + "-com", port, spec); @@ -132,7 +133,7 @@ namespace PepperDash.Essentials.Devices.Displays //}; } - ~PanasonicThefDisplay() + ~PanasonicThDisplay() { PortGather = null; } @@ -343,4 +344,23 @@ namespace PepperDash.Essentials.Devices.Displays #endregion } + + public class PanasonicThDisplayFactory : EssentialsDeviceFactory + { + public PanasonicThDisplayFactory() + { + TypeNames = new List() { "panasonicthef" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); + var comm = CommFactory.CreateCommForDevice(dc); + if (comm != null) + return new PanasonicThDisplay(dc.Key, dc.Name, comm); + else + return null; + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/SamsungMDCDisplay.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/SamsungMDCDisplay.cs index 111e119e..d56360f5 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/SamsungMDCDisplay.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/SamsungMDCDisplay.cs @@ -9,9 +9,12 @@ using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Routing; using Feedback = PepperDash.Essentials.Core.Feedback; +using Newtonsoft.Json.Linq; + namespace PepperDash.Essentials.Devices.Displays { /// @@ -637,4 +640,23 @@ namespace PepperDash.Essentials.Devices.Displays #endregion } + + public class SamsungMDCFactory : EssentialsDeviceFactory + { + public SamsungMDCFactory() + { + TypeNames = new List() { "samsungmdc" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); + var comm = CommFactory.CreateCommForDevice(dc); + if (comm != null) + return new SamsungMDC(dc.Key, dc.Name, comm, dc.Properties["id"].Value()); + else + return null; + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Crestron Lighting/Din8sw8.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Crestron Lighting/Din8sw8.cs index e371d2d1..b262ef84 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Crestron Lighting/Din8sw8.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Crestron Lighting/Din8sw8.cs @@ -9,11 +9,12 @@ using Crestron.SimplSharpPro.Lighting; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.CrestronIO; namespace PepperDash.Essentials.Devices.Common.Environment.Lighting { - public class Din8sw8Controller : Device, ISwitchedOutputCollection + public class Din8sw8Controller : EssentialsDevice, ISwitchedOutputCollection { // Need to figure out some sort of interface to make these switched outputs behave like processor relays so they can be used interchangably @@ -85,4 +86,21 @@ namespace PepperDash.Essentials.Devices.Common.Environment.Lighting } } + public class Din8sw8ControllerFactory : EssentialsDeviceFactory + { + public Din8sw8ControllerFactory() + { + TypeNames = new List() { "din8sw8" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Din8sw8Controller Device"); + var comm = CommFactory.GetControlPropertiesConfig(dc); + + return new Din8sw8Controller(dc.Key, comm.CresnetIdInt); + + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Lutron/LutronQuantum.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Lutron/LutronQuantum.cs index 9facbf56..84cf46c2 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Lutron/LutronQuantum.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Lutron/LutronQuantum.cs @@ -6,6 +6,7 @@ using Crestron.SimplSharp; using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Lighting; using LightingBase = PepperDash.Essentials.Core.Lighting.LightingBase; @@ -264,4 +265,23 @@ namespace PepperDash.Essentials.Devices.Common.Environment.Lutron // public string Username { get; set; } // public string Password { get; set; } } + + public class LutronQuantumAreaFactory : EssentialsDeviceFactory + { + public LutronQuantumAreaFactory() + { + TypeNames = new List() { "lutronqs" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new LutronQuantumArea Device"); + var comm = CommFactory.CreateCommForDevice(dc); + + var props = Newtonsoft.Json.JsonConvert.DeserializeObject(dc.Properties.ToString()); + + return new LutronQuantumArea(dc.Key, dc.Name, comm, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Somfy/RelayControlledShade.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Somfy/RelayControlledShade.cs index 22e06d03..a78e5045 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Somfy/RelayControlledShade.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Environment/Somfy/RelayControlledShade.cs @@ -6,6 +6,7 @@ using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.CrestronIO; using PepperDash.Essentials.Core.Shades; @@ -110,4 +111,21 @@ namespace PepperDash.Essentials.Devices.Common.Environment.Somfy public IOPortConfig Close { get; set; } } } + + public class RelayControlledShadeFactory : EssentialsDeviceFactory + { + public RelayControlledShadeFactory() + { + TypeNames = new List() { "relaycontrolledshade" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Generic Comm Device"); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject(dc.Properties.ToString()); + + return new Environment.Somfy.RelayControlledShade(dc.Key, dc.Name, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs index fc07a6dc..8904b8c3 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs @@ -60,280 +60,56 @@ namespace PepperDash.Essentials.Devices.Common var laptopFactory = new Core.Devices.LaptopFactory() as IDeviceFactory; laptopFactory.LoadTypeFactories(); + var blueJeansPcFactory = new SoftCodec.BlueJeansPcFactory() as IDeviceFactory; + blueJeansPcFactory.LoadTypeFactories(); + var mockAcFactory = new AudioCodec.MockACFactory() as IDeviceFactory; + mockAcFactory.LoadTypeFactories(); + + var mockVcFactory = new VideoCodec.MockVCFactory() as IDeviceFactory; + mockVcFactory.LoadTypeFactories(); + + var ciscoCodecFactory = new VideoCodec.Cisco.CiscoSparkCodecFactory() as IDeviceFactory; + ciscoCodecFactory.LoadTypeFactories(); + + var zoomRoomFactory = new VideoCodec.ZoomRoom.ZoomRoomFactory() as IDeviceFactory; + zoomRoomFactory.LoadTypeFactories(); + + var digitalInputFactory = new GenericDigitalInputDeviceFactory() as IDeviceFactory; + digitalInputFactory.LoadTypeFactories(); + + var relayFactory = new GenericRelayDeviceFactory() as IDeviceFactory; + relayFactory.LoadTypeFactories(); + + var micPrivacyFactory = new Core.Privacy.MicrophonePrivacyControllerFactory() as IDeviceFactory; + micPrivacyFactory.LoadTypeFactories(); + + var rokuFactory = new Roku2Factory() as IDeviceFactory; + rokuFactory.LoadTypeFactories(); + + var setTopBoxFactory = new IRSetTopBoxBaseFactory() as IDeviceFactory; + setTopBoxFactory.LoadTypeFactories(); + + var tvOneCorioFactory = new TVOneCorioFactory() as IDeviceFactory; + tvOneCorioFactory.LoadTypeFactories(); + + var glsOccSensorBaseFactory = new GlsOccupancySensorBaseControllerFactory() as IDeviceFactory; + glsOccSensorBaseFactory.LoadTypeFactories(); + + var glsOdtOccSensorFactory = new GlsOdtOccupancySensorControllerFactory() as IDeviceFactory; + glsOdtOccSensorFactory.LoadTypeFactories(); + + var lutronQuantumFactory = new Environment.Lutron.LutronQuantumAreaFactory() as IDeviceFactory; + lutronQuantumFactory.LoadTypeFactories(); + + var din8sw8ControllerFactory = new Environment.Lighting.Din8sw8ControllerFactory() as IDeviceFactory; + din8sw8ControllerFactory.LoadTypeFactories(); + + var shadeControllerFactory = new Core.Shades.ShadeControllerFactory() as IDeviceFactory; + shadeControllerFactory.LoadTypeFactories(); + + var relayControlledShadeFactory = new Environment.Somfy.RelayControlledShadeFactory() as IDeviceFactory; + relayControlledShadeFactory.LoadTypeFactories(); } - - public static IKeyed GetDevice(DeviceConfig dc) - { - var key = dc.Key; - var name = dc.Name; - var type = dc.Type; - var properties = dc.Properties; - var propAnon = new {}; - JsonConvert.DeserializeAnonymousType(dc.Properties.ToString(), propAnon); - - var typeName = dc.Type.ToLower(); - var groupName = dc.Group.ToLower(); - - // TODO: Continue from here - if (typeName == "bluejeanspc") - { - return new SoftCodec.BlueJeansPc(key, name); - } - - else if (typeName == "mockvc") - { - return new VideoCodec.MockVC(dc); - } - - else if (typeName == "mockac") - { - var props = JsonConvert.DeserializeObject(properties.ToString()); - return new AudioCodec.MockAC(key, name, props); - } - - else if (typeName.StartsWith("ciscospark")) - { - var comm = CommFactory.CreateCommForDevice(dc); - return new VideoCodec.Cisco.CiscoSparkCodec(dc, comm); - } - - else if (typeName == "zoomroom") - { - var comm = CommFactory.CreateCommForDevice(dc); - return new VideoCodec.ZoomRoom.ZoomRoom(dc, comm); - } - - else if (typeName == "digitalinput") - { - var props = JsonConvert.DeserializeObject(properties.ToString()); - - IDigitalInputPorts portDevice; - - if (props.PortDeviceKey == "processor") - portDevice = Global.ControlSystem as IDigitalInputPorts; - else - portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IDigitalInputPorts; - - if (portDevice == null) - Debug.Console(0, "ERROR: Unable to add digital input device with key '{0}'. Port Device does not support digital inputs", key); - else - { - var cs = (portDevice as CrestronControlSystem); - if (cs == null) - { - Debug.Console(0, "ERROR: Port device for [{0}] is not control system", props.PortDeviceKey); - return null; - } - - if (cs.SupportsVersiport) - { - Debug.Console(1, "Attempting to add Digital Input device to Versiport port '{0}'", props.PortNumber); - - if (props.PortNumber > cs.NumberOfVersiPorts) - { - Debug.Console(0, "WARNING: Cannot add Vesiport {0} on {1}. Out of range", - props.PortNumber, props.PortDeviceKey); - return null; - } - - Versiport vp = cs.VersiPorts[props.PortNumber]; - - if (!vp.Registered) - { - var regSuccess = vp.Register(); - if (regSuccess == eDeviceRegistrationUnRegistrationResponse.Success) - { - Debug.Console(1, "Successfully Created Digital Input Device on Versiport"); - return new GenericVersiportDigitalInputDevice(key, vp, props); - } - else - { - Debug.Console(0, "WARNING: Attempt to register versiport {0} on device with key '{1}' failed: {2}", - props.PortNumber, props.PortDeviceKey, regSuccess); - return null; - } - } - } - else if (cs.SupportsDigitalInput) - { - Debug.Console(1, "Attempting to add Digital Input device to Digital Input port '{0}'", props.PortNumber); - - if (props.PortNumber > cs.NumberOfDigitalInputPorts) - { - Debug.Console(0, "WARNING: Cannot register DIO port {0} on {1}. Out of range", - props.PortNumber, props.PortDeviceKey); - return null; - } - - DigitalInput digitalInput = cs.DigitalInputPorts[props.PortNumber]; - - if (!digitalInput.Registered) - { - if (digitalInput.Register() == eDeviceRegistrationUnRegistrationResponse.Success) - { - Debug.Console(1, "Successfully Created Digital Input Device on Digital Input"); - return new GenericDigitalInputDevice(key, digitalInput); - } - else - Debug.Console(0, "WARNING: Attempt to register digital input {0} on device with key '{1}' failed.", - props.PortNumber, props.PortDeviceKey); - } - } - } - } - - else if (typeName == "relayoutput") - { - var props = JsonConvert.DeserializeObject(properties.ToString()); - - IRelayPorts portDevice; - - if (props.PortDeviceKey == "processor") - portDevice = Global.ControlSystem as IRelayPorts; - else - portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IRelayPorts; - - if (portDevice == null) - Debug.Console(0, "Unable to add relay device with key '{0}'. Port Device does not support relays", key); - else - { - var cs = (portDevice as CrestronControlSystem); - - if (cs != null) - { - // The relay is on a control system processor - if (!cs.SupportsRelay || props.PortNumber > cs.NumberOfRelayPorts) - { - Debug.Console(0, "Port Device: {0} does not support relays or does not have enough relays"); - return null; - } - } - else - { - // The relay is on another device type - - if (props.PortNumber > portDevice.NumberOfRelayPorts) - { - Debug.Console(0, "Port Device: {0} does not have enough relays"); - return null; - } - } - - Relay relay = portDevice.RelayPorts[props.PortNumber]; - - if (!relay.Registered) - { - if (relay.Register() == eDeviceRegistrationUnRegistrationResponse.Success) - return new GenericRelayDevice(key, relay); - else - Debug.Console(0, "Attempt to register relay {0} on device with key '{1}' failed.", props.PortNumber, props.PortDeviceKey); - } - else - { - return new GenericRelayDevice(key, relay); - } - - // Future: Check if portDevice is 3-series card or other non control system that supports versiports - } - } - - else if (typeName == "microphoneprivacycontroller") - { - var props = JsonConvert.DeserializeObject(properties.ToString()); - - return new Core.Privacy.MicrophonePrivacyController(key, props); - } - else if (typeName == "roku") - { - var irCont = IRPortHelper.GetIrOutputPortController(dc); - return new Roku2(key, name, irCont); - } - - else if (groupName == "settopbox") //(typeName == "irstbbase") - { - var irCont = IRPortHelper.GetIrOutputPortController(dc); - var config = dc.Properties.ToObject(); - var stb = new IRSetTopBoxBase(key, name, irCont, config); - - //stb.HasDvr = properties.Value("hasDvr"); - var listName = properties.Value("presetsList"); - if (listName != null) - stb.LoadPresets(listName); - return stb; - } - else if (typeName == "tvonecorio") - { - var comm = CommFactory.CreateCommForDevice(dc); - var props = JsonConvert.DeserializeObject( - properties.ToString()); - return new TVOneCorio(key, name, comm, props); - } - - - else if (typeName == "glsoirccn") - { - var comm = CommFactory.GetControlPropertiesConfig(dc); - - GlsOccupancySensorBase occSensor = null; - - occSensor = new GlsOirCCn(comm.CresnetIdInt, Global.ControlSystem); - - if (occSensor != null) - return new GlsOccupancySensorBaseController(key, name, occSensor); - else - Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key); - } - - else if (typeName == "glsodtccn") - { - var comm = CommFactory.GetControlPropertiesConfig(dc); - - var occSensor = new GlsOdtCCn(comm.CresnetIdInt, Global.ControlSystem); - - if (occSensor != null) - return new GlsOdtOccupancySensorController(key, name, occSensor); - else - Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key); - } - - else if (groupName == "lighting") - { - if (typeName == "lutronqs") - { - var comm = CommFactory.CreateCommForDevice(dc); - - var props = JsonConvert.DeserializeObject(properties.ToString()); - - return new Environment.Lutron.LutronQuantumArea(key, name, comm, props); - } - else if (typeName == "din8sw8") - { - var comm = CommFactory.GetControlPropertiesConfig(dc); - - return new Environment.Lighting.Din8sw8Controller(key, comm.CresnetIdInt); - } - - } - - else if (groupName == "environment") - { - if (typeName == "shadecontroller") - { - var props = JsonConvert.DeserializeObject(properties.ToString()); - - return new Core.Shades.ShadeController(key, name, props); - } - else if (typeName == "relaycontrolledshade") - { - var props = JsonConvert.DeserializeObject(properties.ToString()); - - return new Environment.Somfy.RelayControlledShade(key, name, props); - } - - } - - return null; - } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/ImageProcessors/TVOneCorio.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/ImageProcessors/TVOneCorio.cs index a3dd9745..b5a1004f 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/ImageProcessors/TVOneCorio.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/ImageProcessors/TVOneCorio.cs @@ -5,13 +5,14 @@ using System.Text; using Crestron.SimplSharp; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using System.Text.RegularExpressions; namespace PepperDash.Essentials.Devices.Common { - public class TVOneCorio : Device + public class TVOneCorio : EssentialsDevice { public IBasicCommunication Communication { get; private set; } public CommunicationGather PortGather { get; private set; } @@ -238,4 +239,22 @@ namespace PepperDash.Essentials.Devices.Common // public QscDspControlPoint ControlPoint { get; set; } } } + + public class TVOneCorioFactory : EssentialsDeviceFactory + { + public TVOneCorioFactory() + { + TypeNames = new List() { "tvonecorio" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new TVOneCorio Device"); + var comm = CommFactory.CreateCommForDevice(dc); + var props = Newtonsoft.Json.JsonConvert.DeserializeObject( + dc.Properties.ToString()); + return new TVOneCorio(dc.Key, dc.Name, comm, props); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOccupancySensorBaseController.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOccupancySensorBaseController.cs index 5bf35247..18bdb1be 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOccupancySensorBaseController.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOccupancySensorBaseController.cs @@ -8,6 +8,7 @@ using Crestron.SimplSharpPro.GeneralIO; using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; namespace PepperDash.Essentials.Devices.Common.Occupancy @@ -365,4 +366,38 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge); } } + + public class GlsOccupancySensorBaseControllerFactory : EssentialsDeviceFactory + { + public GlsOccupancySensorBaseControllerFactory() + { + TypeNames = new List() { "glsoirccn" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device"); + + var typeName = dc.Type.ToLower(); + var key = dc.Key; + var name = dc.Name; + var comm = CommFactory.GetControlPropertiesConfig(dc); + + GlsOccupancySensorBase occSensor = null; + + occSensor = new GlsOirCCn(comm.CresnetIdInt, Global.ControlSystem); + + if (occSensor != null) + { + return new GlsOccupancySensorBaseController(key, name, occSensor); + } + else + { + Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key); + return null; + } + + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOdtOccupancySensorController.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOdtOccupancySensorController.cs index 0134a3d4..f7d9943a 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOdtOccupancySensorController.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Occupancy/GlsOdtOccupancySensorController.cs @@ -8,6 +8,7 @@ using Crestron.SimplSharpPro.GeneralIO; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Bridges; namespace PepperDash.Essentials.Devices.Common.Occupancy @@ -159,4 +160,37 @@ namespace PepperDash.Essentials.Devices.Common.Occupancy LinkOccSensorToApi(this, trilist, joinStart, joinMapKey, bridge); } } + + public class GlsOdtOccupancySensorControllerFactory : EssentialsDeviceFactory + { + public GlsOdtOccupancySensorControllerFactory() + { + TypeNames = new List() { "glsodtccn" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new GlsOccupancySensorBaseController Device"); + + var typeName = dc.Type.ToLower(); + var key = dc.Key; + var name = dc.Name; + var comm = CommFactory.GetControlPropertiesConfig(dc); + + var occSensor = new GlsOdtCCn(comm.CresnetIdInt, Global.ControlSystem); + + if (occSensor != null) + { + return new GlsOdtOccupancySensorController(key, name, occSensor); + } + else + { + Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key); + return null; + } + + + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/SetTopBox/IRSetTopBoxBase.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/SetTopBox/IRSetTopBoxBase.cs index e5678620..25d17eb4 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/SetTopBox/IRSetTopBoxBase.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/SetTopBox/IRSetTopBoxBase.cs @@ -9,6 +9,7 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Bridges; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Presets; using PepperDash.Essentials.Core.Routing; @@ -461,4 +462,27 @@ namespace PepperDash.Essentials.Devices.Common trilist.SetBoolSigAction(joinMap.Record, stbTransport.Record); } } + + public class IRSetTopBoxBaseFactory : EssentialsDeviceFactory + { + public IRSetTopBoxBaseFactory() + { + TypeNames = new List() { "settopbox" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new SetTopBox Device"); + var irCont = IRPortHelper.GetIrOutputPortController(dc); + var config = dc.Properties.ToObject(); + var stb = new IRSetTopBoxBase(dc.Key, dc.Name, irCont, config); + + var listName = dc.Properties.Value("presetsList"); + if (listName != null) + stb.LoadPresets(listName); + return stb; + + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/SoftCodec/BlueJeansPc.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/SoftCodec/BlueJeansPc.cs index 462ae5cb..78043111 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/SoftCodec/BlueJeansPc.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/SoftCodec/BlueJeansPc.cs @@ -161,4 +161,19 @@ namespace PepperDash.Essentials.Devices.Common.SoftCodec #endregion } + + public class BlueJeansPcFactory : EssentialsDeviceFactory + { + public BlueJeansPcFactory() + { + TypeNames = new List() { "mockvc" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new BlueJeansPc Device"); + return new SoftCodec.BlueJeansPc(dc.Key, dc.Name); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Streaming/Roku.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Streaming/Roku.cs index 1c162040..49f96c31 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Streaming/Roku.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Streaming/Roku.cs @@ -8,11 +8,12 @@ using Crestron.SimplSharpPro.DeviceSupport; using PepperDash.Core; using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Routing; namespace PepperDash.Essentials.Devices.Common { - public class Roku2 : Device, IDPad, ITransport, IUiDisplayInfo, IRoutingOutputs + public class Roku2 : EssentialsDevice, IDPad, ITransport, IUiDisplayInfo, IRoutingOutputs { [Api] public IrOutputPortController IrPort { get; private set; } @@ -145,4 +146,21 @@ namespace PepperDash.Essentials.Devices.Common #endregion } + + public class Roku2Factory : EssentialsDeviceFactory + { + public Roku2Factory() + { + TypeNames = new List() { "roku" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Roku Device"); + var irCont = IRPortHelper.GetIrOutputPortController(dc); + return new Roku2(dc.Key, dc.Name, irCont); + + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs index f8f7b298..cad7a18c 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoSparkCodec.cs @@ -1843,4 +1843,19 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco } } + public class CiscoSparkCodecFactory : EssentialsDeviceFactory + { + public CiscoSparkCodecFactory() + { + TypeNames = new List() { "ciscospark", "ciscowebex", "ciscowebexpro", "ciscoroomkit" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new Cisco Codec Device"); + var comm = CommFactory.CreateCommForDevice(dc); + return new VideoCodec.Cisco.CiscoSparkCodec(dc, comm); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/MockVC/MockVC.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/MockVC/MockVC.cs index d6580b67..dc32ecd8 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/MockVC/MockVC.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/MockVC/MockVC.cs @@ -770,4 +770,19 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec _AutoAnswerEnabled = value; } } + + public class MockVCFactory : EssentialsDeviceFactory + { + public MockVCFactory() + { + TypeNames = new List() { "mockvc" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new MockVC Device"); + return new VideoCodec.MockVC(dc); + } + } + } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs index 84881df3..13fa895d 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/VideoCodec/ZoomRoom/ZoomRoom.cs @@ -1676,4 +1676,20 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.ZoomRoom InitialSyncComplete = false; } } + + public class ZoomRoomFactory : EssentialsDeviceFactory + { + public ZoomRoomFactory() + { + TypeNames = new List() { "zoomroom" }; + } + + public override EssentialsDevice BuildDevice(DeviceConfig dc) + { + Debug.Console(1, "Factory Attempting to create new ZoomRoom Device"); + var comm = CommFactory.CreateCommForDevice(dc); + return new VideoCodec.ZoomRoom.ZoomRoom(dc, comm); + } + } + } \ No newline at end of file From 911bd8daba787e98da28143a41823fab5cf86c66 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Wed, 22 Apr 2020 17:20:29 -0600 Subject: [PATCH 08/10] Moves to reflection based mechanism for loading device factories at boot (not working) --- PepperDashEssentials/ControlSystem.cs | 49 +++++++++++++------ .../Plugins/PluginLoader.cs | 17 ++++++- .../SoftCodec/BlueJeansPc.cs | 2 +- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index b7ce9288..e4d4cbc0 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -81,31 +81,52 @@ namespace PepperDash.Essentials "Template URL: {1}", ConfigReader.ConfigObject.SystemUrl, ConfigReader.ConfigObject.TemplateUrl); }, "portalinfo", "Shows portal URLS from configuration", ConsoleAccessLevelEnum.AccessOperator); - LoadDeviceTypesFromFactories(); if (!Debug.DoNotLoadOnNextBoot) GoWithLoad(); } /// - /// Instantiates each of the device factories to load thier device types + /// Instantiates each of the device factories to load their device types /// void LoadDeviceTypesFromFactories() { - // Instantiate the Device Factories - new CoreDeviceFactory(); - new DmDeviceFactory(); - new UiDeviceFactory(); + PluginLoader.AddProgramAssemblies(); - new DeviceFactory(); - new BridgeFactory(); - new PepperDash.Essentials.Devices.Common.DeviceFactory(); - new PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory(); + foreach (var assembly in PluginLoader.LoadedAssemblies) + { + if (!assembly.Name.Contains("Essentials")) + { + continue; + } + else + { + var assy = assembly.Assembly; + var types = assy.GetTypes(); + + if (types != null) + { + foreach (var type in types) + { + try + { + if (typeof(IDeviceFactory).IsAssignableFrom(type)) + { + var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); + factory.LoadTypeFactories(); + } + } + catch (Exception e) + { + Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load DeviceFactory: {0}", e); + } + } + } + } + } } - - /// /// Determines if the program is running on a processor (appliance) or server (VC-4). /// @@ -184,9 +205,9 @@ namespace PepperDash.Essentials { Debug.SetDoNotLoadOnNextBoot(false); - Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials load from configuration"); + LoadDeviceTypesFromFactories(); - PluginLoader.AddProgramAssemblies(); + Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials load from configuration"); var filesReady = SetupFilesystem(); if (filesReady) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs index 3e08d698..d32e9efa 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs @@ -71,9 +71,22 @@ namespace PepperDash.Essentials assembly = Assembly.GetExecutingAssembly(); break; } - case ("PepperDashEssentialsBase.dll"): + case ("PepperDash_Essential_Core.dll"): { - + version = Global.AssemblyVersion; + assembly = System.Reflection + break; + } + case ("PepperDash_Essentials_DM.dll"): + { + version = Global.AssemblyVersion; + assembly = Assembly.GetExecutingAssembly(); + break; + } + case ("Essentials Devices Common.dll"): + { + version = Global.AssemblyVersion; + assembly = Assembly.GetExecutingAssembly(); break; } case ("PepperDash_Core.dll"): diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/SoftCodec/BlueJeansPc.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/SoftCodec/BlueJeansPc.cs index 78043111..735df48c 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/SoftCodec/BlueJeansPc.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/SoftCodec/BlueJeansPc.cs @@ -166,7 +166,7 @@ namespace PepperDash.Essentials.Devices.Common.SoftCodec { public BlueJeansPcFactory() { - TypeNames = new List() { "mockvc" }; + TypeNames = new List() { "bluejeanspc" }; } public override EssentialsDevice BuildDevice(DeviceConfig dc) From 96adbdb76a8fff0df93fb9a4498de22b6b692977 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 23 Apr 2020 09:55:33 -0600 Subject: [PATCH 09/10] Adds Template UI submodule --- .gitmodules | 3 +++ Essentials-Template-UI | 1 + 2 files changed, 4 insertions(+) create mode 160000 Essentials-Template-UI diff --git a/.gitmodules b/.gitmodules index 2ce66ffc..0abbfb4e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "essentials-framework/pepperdashcore-builds"] path = essentials-framework/pepperdashcore-builds url = https://github.com/ndorin/PepperDashCore-Builds.git +[submodule "Essentials-Template-UI"] + path = Essentials-Template-UI + url = https://github.com/PepperDash/Essentials-Template-UI.git diff --git a/Essentials-Template-UI b/Essentials-Template-UI new file mode 160000 index 00000000..8eaf8879 --- /dev/null +++ b/Essentials-Template-UI @@ -0,0 +1 @@ +Subproject commit 8eaf88791b42318fbe7c64402af46d747516e4fa From a93ded8c7940374491be549507bb3c5d172acc42 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 23 Apr 2020 14:59:54 -0600 Subject: [PATCH 10/10] New device loading methodology working via reflection --- PepperDashEssentials/ControlSystem.cs | 50 ++------ PepperDashEssentials/Factory/DeviceFactory.cs | 39 +++--- .../Factory/UiDeviceFactory.cs | 36 ------ .../PepperDashEssentials.csproj | 1 - .../Inputs/GenericDigitalInputDevice.cs | 2 +- .../Crestron IO/Relay/GenericRelayDevice.cs | 1 - .../Factory/DeviceFactory.cs | 48 ++++---- .../Plugins/PluginLoader.cs | 22 +++- .../Essentials_DM/Config/DeviceFactory.cs | 43 ++++--- .../Display/DeviceFactory.cs | 33 ----- .../Essentials Devices Common.csproj | 1 - .../Factory/DeviceFactory.cs | 113 ++++-------------- 12 files changed, 121 insertions(+), 268 deletions(-) delete mode 100644 PepperDashEssentials/Factory/UiDeviceFactory.cs delete mode 100644 essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/DeviceFactory.cs diff --git a/PepperDashEssentials/ControlSystem.cs b/PepperDashEssentials/ControlSystem.cs index e4d4cbc0..f0cdc9d5 100644 --- a/PepperDashEssentials/ControlSystem.cs +++ b/PepperDashEssentials/ControlSystem.cs @@ -86,47 +86,6 @@ namespace PepperDash.Essentials GoWithLoad(); } - /// - /// Instantiates each of the device factories to load their device types - /// - void LoadDeviceTypesFromFactories() - { - PluginLoader.AddProgramAssemblies(); - - - foreach (var assembly in PluginLoader.LoadedAssemblies) - { - if (!assembly.Name.Contains("Essentials")) - { - continue; - } - else - { - var assy = assembly.Assembly; - var types = assy.GetTypes(); - - if (types != null) - { - foreach (var type in types) - { - try - { - if (typeof(IDeviceFactory).IsAssignableFrom(type)) - { - var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); - factory.LoadTypeFactories(); - } - } - catch (Exception e) - { - Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load DeviceFactory: {0}", e); - } - } - } - } - } - } - /// /// Determines if the program is running on a processor (appliance) or server (VC-4). /// @@ -202,10 +161,15 @@ namespace PepperDash.Essentials public void GoWithLoad() { try - { + { Debug.SetDoNotLoadOnNextBoot(false); - LoadDeviceTypesFromFactories(); + PluginLoader.AddProgramAssemblies(); + + new Core.DeviceFactory(); + new Devices.Common.DeviceFactory(); + new DM.DeviceFactory(); + new DeviceFactory(); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials load from configuration"); diff --git a/PepperDashEssentials/Factory/DeviceFactory.cs b/PepperDashEssentials/Factory/DeviceFactory.cs index 944a9b2f..5b15f28c 100644 --- a/PepperDashEssentials/Factory/DeviceFactory.cs +++ b/PepperDashEssentials/Factory/DeviceFactory.cs @@ -4,6 +4,7 @@ using System.Linq; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharpPro; +using Crestron.SimplSharp.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -18,26 +19,30 @@ namespace PepperDash.Essentials /// Responsible for loading all of the device types for this library /// public class DeviceFactory - { + { + public DeviceFactory() { - var ampFactory = new AmplifierFactory() as IDeviceFactory; - ampFactory.LoadTypeFactories(); + var assy = Assembly.GetExecutingAssembly(); + PluginLoader.SetEssentialsAssembly(assy.GetName().Name, assy); - var mockDisplayFactory = new MockDisplayFactory() as IDeviceFactory; - mockDisplayFactory.LoadTypeFactories(); + var types = assy.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract); - var consoleCommMockFactroy = new ConsoleCommMockDeviceFactory() as IDeviceFactory; - consoleCommMockFactroy.LoadTypeFactories(); - - var mcSystemControllerFactory = new MobileControlSystemControllerFactory() as IDeviceFactory; - mcSystemControllerFactory.LoadTypeFactories(); - - var mcSIMPLRoomBridgeFactory = new MobileControlSIMPLRoomBridgeFactory() as IDeviceFactory; - mcSIMPLRoomBridgeFactory.LoadTypeFactories(); - - var roomOnToDefSourceWhenOcc = new RoomOnToDefaultSourceWhenOccupiedFactory() as IDeviceFactory; - roomOnToDefSourceWhenOcc.LoadTypeFactories(); + if (types != null) + { + foreach (var type in types) + { + try + { + var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); + factory.LoadTypeFactories(); + } + catch (Exception e) + { + Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load type: '{1}' DeviceFactory: {0}", e, type.Name); + } + } + } } - } + } } diff --git a/PepperDashEssentials/Factory/UiDeviceFactory.cs b/PepperDashEssentials/Factory/UiDeviceFactory.cs deleted file mode 100644 index fad8026f..00000000 --- a/PepperDashEssentials/Factory/UiDeviceFactory.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; -using Crestron.SimplSharpPro; -using Crestron.SimplSharpPro.DeviceSupport; -using Crestron.SimplSharpPro.UI; - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using PepperDash.Core; -using PepperDash.Essentials.Core; -using PepperDash.Essentials.Core.Config; -using PepperDash.Essentials.Core.PageManagers; -using PepperDash.Essentials.DM.Endpoints.DGEs; - - -namespace PepperDash.Essentials -{ - /// - /// Responsible for loading all of the UI device types for this library - /// - public class UiDeviceFactory - { - public UiDeviceFactory() - { - var dgeControllerFactory = new DgeControllerFactory() as IDeviceFactory; - dgeControllerFactory.LoadTypeFactories(); - - var essentialsTouchpanelControllerFactory = new EssentialsTouchpanelControllerFactory() as IDeviceFactory; - essentialsTouchpanelControllerFactory.LoadTypeFactories(); - } - - } -} \ No newline at end of file diff --git a/PepperDashEssentials/PepperDashEssentials.csproj b/PepperDashEssentials/PepperDashEssentials.csproj index 62cae03f..6c606273 100644 --- a/PepperDashEssentials/PepperDashEssentials.csproj +++ b/PepperDashEssentials/PepperDashEssentials.csproj @@ -151,7 +151,6 @@ - diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericDigitalInputDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericDigitalInputDevice.cs index 33cb0ae6..3d3383e9 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericDigitalInputDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Inputs/GenericDigitalInputDevice.cs @@ -9,7 +9,7 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Config; -using PepperDash_Essentials_Core.Devices; + namespace PepperDash.Essentials.Core.CrestronIO { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs index 3e3b0576..aac9de44 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Crestron IO/Relay/GenericRelayDevice.cs @@ -9,7 +9,6 @@ using Newtonsoft.Json; using PepperDash.Core; using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Config; -using PepperDash_Essentials_Core.Devices; namespace PepperDash.Essentials.Core.CrestronIO { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs index 4e12ab05..1904867d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Factory/DeviceFactory.cs @@ -29,6 +29,30 @@ namespace PepperDash.Essentials.Core public class DeviceFactory { + public DeviceFactory() + { + var assy = Assembly.GetExecutingAssembly(); + PluginLoader.SetEssentialsAssembly(assy.GetName().Name, assy); + + var types = assy.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract); + + if (types != null) + { + foreach (var type in types) + { + try + { + var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); + factory.LoadTypeFactories(); + } + catch (Exception e) + { + Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load type: '{1}' DeviceFactory: {0}", e, type.Name); + } + } + } + } + /// /// A dictionary of factory methods, keyed by config types, added by plugins. /// These methods are looked up and called by GetDevice in this class. @@ -122,28 +146,4 @@ namespace PepperDash.Essentials.Core } } } - - /// - /// Responsible for loading all of the device types for this library - /// - public class CoreDeviceFactory - { - public CoreDeviceFactory() - { - Debug.Console(1, "Essentials.Core Factory Adding Types..."); - - //cast to IDeviceFactory isn't explicitly required here...but will be when instantiating using reflection, which I'm assuming is the next step - var genCommFactory = new GenericCommFactory() as IDeviceFactory; - genCommFactory.LoadTypeFactories(); - - var c2nRthsFactory = new C2nRthsControllerFactory() as IDeviceFactory; - c2nRthsFactory.LoadTypeFactories(); - - var statusSignFactory = new StatusSignControllerFactory() as IDeviceFactory; - statusSignFactory.LoadTypeFactories(); - - var cenIoControllerFactory = new CenIoDigIn104ControllerFactory() as IDeviceFactory; - cenIoControllerFactory.LoadTypeFactories(); - } - } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs index d32e9efa..5c66ab8f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs @@ -68,25 +68,21 @@ namespace PepperDash.Essentials case ("PepperDashEssentials.dll"): { version = Global.AssemblyVersion; - assembly = Assembly.GetExecutingAssembly(); break; } - case ("PepperDash_Essential_Core.dll"): + case ("PepperDash_Essentials_Core.dll"): { version = Global.AssemblyVersion; - assembly = System.Reflection break; } case ("PepperDash_Essentials_DM.dll"): { version = Global.AssemblyVersion; - assembly = Assembly.GetExecutingAssembly(); break; } case ("Essentials Devices Common.dll"): { version = Global.AssemblyVersion; - assembly = Assembly.GetExecutingAssembly(); break; } case ("PepperDash_Core.dll"): @@ -110,6 +106,17 @@ namespace PepperDash.Essentials } } + + public static void SetEssentialsAssembly(string name, Assembly assembly) + { + var loadedAssembly = LoadedAssemblies.FirstOrDefault(la => la.Name.Equals(name)); + + if (loadedAssembly != null) + { + loadedAssembly.SetAssembly(assembly); + } + } + /// /// Loads an assembly via Reflection and adds it to the list of loaded assemblies /// @@ -503,5 +510,10 @@ namespace PepperDash.Essentials Version = version; Assembly = assembly; } + + public void SetAssembly(Assembly assembly) + { + Assembly = assembly; + } } } \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs b/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs index 6e10ae61..5c532ac5 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs +++ b/essentials-framework/Essentials DM/Essentials_DM/Config/DeviceFactory.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; @@ -6,6 +7,7 @@ using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.DM; using Crestron.SimplSharpPro.DM.AirMedia; using Crestron.SimplSharpPro.UI; +using Crestron.SimplSharp.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -20,25 +22,30 @@ namespace PepperDash.Essentials.DM /// /// Responsible for loading the type factories for this library /// - public class DmDeviceFactory - { - public DmDeviceFactory() + public class DeviceFactory + { + public DeviceFactory() { - Debug.Console(1, "Essentials.DM Factory Adding Types..."); + var assy = Assembly.GetExecutingAssembly(); + PluginLoader.SetEssentialsAssembly(assy.GetName().Name, assy); + + var types = assy.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract); - var dmChassisFactory = new DmChassisControllerFactory() as IDeviceFactory; - dmChassisFactory.LoadTypeFactories(); - - var dmTxFactory = new DmTxControllerFactory() as IDeviceFactory; - dmTxFactory.LoadTypeFactories(); - - var dmRxFactory = new DmRmcControllerFactory() as IDeviceFactory; - dmRxFactory.LoadTypeFactories(); - - var hdMdFactory = new HdMdxxxCEControllerFactory() as IDeviceFactory; - hdMdFactory.LoadTypeFactories(); + if (types != null) + { + foreach (var type in types) + { + try + { + var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); + factory.LoadTypeFactories(); + } + catch (Exception e) + { + Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load type: '{1}' DeviceFactory: {0}", e, type.Name); + } + } + } } - - } - + } } \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/DeviceFactory.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/DeviceFactory.cs deleted file mode 100644 index 099e1204..00000000 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/DeviceFactory.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using Crestron.SimplSharp; -using Crestron.SimplSharp.CrestronIO; -using Crestron.SimplSharpPro; - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using PepperDash.Core; -using PepperDash.Essentials.Core; -using PepperDash.Essentials.Core.Config; - -namespace PepperDash.Essentials.Devices.Displays -{ - public class DisplayDeviceFactory - { - public DisplayDeviceFactory() - { - var necFactory = new NecPSXMDisplayFactory() as IDeviceFactory; - necFactory.LoadTypeFactories(); - - var panasonicThFactory = new PanasonicThDisplayFactory() as IDeviceFactory; - panasonicThFactory.LoadTypeFactories(); - - var samsungMdcFactory = new SamsungMDCFactory() as IDeviceFactory; - samsungMdcFactory.LoadTypeFactories(); - - var avocorFactory = new AvocorDisplayFactory() as IDeviceFactory; - avocorFactory.LoadTypeFactories(); - } - - } -} \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj index 6585b074..147ace5b 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj @@ -132,7 +132,6 @@ - diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs index 8904b8c3..c860d0cb 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Factory/DeviceFactory.cs @@ -1,9 +1,11 @@ using System; +using System.Linq; using System.Collections.Generic; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.GeneralIO; +using Crestron.SimplSharp.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -20,96 +22,31 @@ using PepperDash.Essentials.Devices.Common.Environment; namespace PepperDash.Essentials.Devices.Common { - public class DeviceFactory - { + public class DeviceFactory + { + public DeviceFactory() { - var appleTVFactory = new AppleTVFactory() as IDeviceFactory; - appleTVFactory.LoadTypeFactories(); + var assy = Assembly.GetExecutingAssembly(); + PluginLoader.SetEssentialsAssembly(assy.GetName().Name, assy); + + var types = assy.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract); - var analogWayLCFactory = new AnalogWayLiveCoreFactory() as IDeviceFactory; - analogWayLCFactory.LoadTypeFactories(); - - var basicIrDisplayFactory = new BasicIrDisplayFactory() as IDeviceFactory; - basicIrDisplayFactory.LoadTypeFactories(); - - var biampTesiraFactory = new BiampTesiraForteDspFactory() as IDeviceFactory; - biampTesiraFactory.LoadTypeFactories(); - - var cameraViscaFactory = new Cameras.CameraViscaFactory() as IDeviceFactory; - cameraViscaFactory.LoadTypeFactories(); - - var cenRfGwFactory = new CenRfgwControllerFactory() as IDeviceFactory; - cenRfGwFactory.LoadTypeFactories(); - - var irBlurayFactory = new IRBlurayBaseFactory() as IDeviceFactory; - irBlurayFactory.LoadTypeFactories(); - - var digitalLoggerFactory = new DigitalLoggerFactory() as IDeviceFactory; - digitalLoggerFactory.LoadTypeFactories(); - - var genericAudioOutFactory = new GenericAudioOutWithVolumeFactory() as IDeviceFactory; - genericAudioOutFactory.LoadTypeFactories(); - - var genericSourceFactory = new GenericSourceFactory() as IDeviceFactory; - genericSourceFactory.LoadTypeFactories(); - - var inRoomPcFactory = new Core.Devices.InRoomPcFactory() as IDeviceFactory; - inRoomPcFactory.LoadTypeFactories(); - - var laptopFactory = new Core.Devices.LaptopFactory() as IDeviceFactory; - laptopFactory.LoadTypeFactories(); - - var blueJeansPcFactory = new SoftCodec.BlueJeansPcFactory() as IDeviceFactory; - blueJeansPcFactory.LoadTypeFactories(); - - var mockAcFactory = new AudioCodec.MockACFactory() as IDeviceFactory; - mockAcFactory.LoadTypeFactories(); - - var mockVcFactory = new VideoCodec.MockVCFactory() as IDeviceFactory; - mockVcFactory.LoadTypeFactories(); - - var ciscoCodecFactory = new VideoCodec.Cisco.CiscoSparkCodecFactory() as IDeviceFactory; - ciscoCodecFactory.LoadTypeFactories(); - - var zoomRoomFactory = new VideoCodec.ZoomRoom.ZoomRoomFactory() as IDeviceFactory; - zoomRoomFactory.LoadTypeFactories(); - - var digitalInputFactory = new GenericDigitalInputDeviceFactory() as IDeviceFactory; - digitalInputFactory.LoadTypeFactories(); - - var relayFactory = new GenericRelayDeviceFactory() as IDeviceFactory; - relayFactory.LoadTypeFactories(); - - var micPrivacyFactory = new Core.Privacy.MicrophonePrivacyControllerFactory() as IDeviceFactory; - micPrivacyFactory.LoadTypeFactories(); - - var rokuFactory = new Roku2Factory() as IDeviceFactory; - rokuFactory.LoadTypeFactories(); - - var setTopBoxFactory = new IRSetTopBoxBaseFactory() as IDeviceFactory; - setTopBoxFactory.LoadTypeFactories(); - - var tvOneCorioFactory = new TVOneCorioFactory() as IDeviceFactory; - tvOneCorioFactory.LoadTypeFactories(); - - var glsOccSensorBaseFactory = new GlsOccupancySensorBaseControllerFactory() as IDeviceFactory; - glsOccSensorBaseFactory.LoadTypeFactories(); - - var glsOdtOccSensorFactory = new GlsOdtOccupancySensorControllerFactory() as IDeviceFactory; - glsOdtOccSensorFactory.LoadTypeFactories(); - - var lutronQuantumFactory = new Environment.Lutron.LutronQuantumAreaFactory() as IDeviceFactory; - lutronQuantumFactory.LoadTypeFactories(); - - var din8sw8ControllerFactory = new Environment.Lighting.Din8sw8ControllerFactory() as IDeviceFactory; - din8sw8ControllerFactory.LoadTypeFactories(); - - var shadeControllerFactory = new Core.Shades.ShadeControllerFactory() as IDeviceFactory; - shadeControllerFactory.LoadTypeFactories(); - - var relayControlledShadeFactory = new Environment.Somfy.RelayControlledShadeFactory() as IDeviceFactory; - relayControlledShadeFactory.LoadTypeFactories(); + if (types != null) + { + foreach (var type in types) + { + try + { + var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); + factory.LoadTypeFactories(); + } + catch (Exception e) + { + Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load type: '{1}' DeviceFactory: {0}", e, type.Name); + } + } + } } - } + } } \ No newline at end of file