New device loading methodology working via reflection

This commit is contained in:
Neil Dorin
2020-04-23 14:59:54 -06:00
parent 911bd8daba
commit a93ded8c79
12 changed files with 121 additions and 268 deletions

View File

@@ -86,47 +86,6 @@ namespace PepperDash.Essentials
GoWithLoad(); GoWithLoad();
} }
/// <summary>
/// Instantiates each of the device factories to load their device types
/// </summary>
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);
}
}
}
}
}
}
/// <summary> /// <summary>
/// Determines if the program is running on a processor (appliance) or server (VC-4). /// Determines if the program is running on a processor (appliance) or server (VC-4).
/// ///
@@ -205,7 +164,12 @@ namespace PepperDash.Essentials
{ {
Debug.SetDoNotLoadOnNextBoot(false); 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"); Debug.Console(0, Debug.ErrorLogLevel.Notice, "Starting Essentials load from configuration");

View File

@@ -4,6 +4,7 @@ using System.Linq;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharp.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@@ -18,26 +19,30 @@ namespace PepperDash.Essentials
/// Responsible for loading all of the device types for this library /// Responsible for loading all of the device types for this library
/// </summary> /// </summary>
public class DeviceFactory public class DeviceFactory
{ {
public DeviceFactory() public DeviceFactory()
{ {
var ampFactory = new AmplifierFactory() as IDeviceFactory; var assy = Assembly.GetExecutingAssembly();
ampFactory.LoadTypeFactories(); PluginLoader.SetEssentialsAssembly(assy.GetName().Name, assy);
var mockDisplayFactory = new MockDisplayFactory() as IDeviceFactory; var types = assy.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract);
mockDisplayFactory.LoadTypeFactories();
var consoleCommMockFactroy = new ConsoleCommMockDeviceFactory() as IDeviceFactory; if (types != null)
consoleCommMockFactroy.LoadTypeFactories(); {
foreach (var type in types)
var mcSystemControllerFactory = new MobileControlSystemControllerFactory() as IDeviceFactory; {
mcSystemControllerFactory.LoadTypeFactories(); try
{
var mcSIMPLRoomBridgeFactory = new MobileControlSIMPLRoomBridgeFactory() as IDeviceFactory; var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type);
mcSIMPLRoomBridgeFactory.LoadTypeFactories(); factory.LoadTypeFactories();
}
var roomOnToDefSourceWhenOcc = new RoomOnToDefaultSourceWhenOccupiedFactory() as IDeviceFactory; catch (Exception e)
roomOnToDefSourceWhenOcc.LoadTypeFactories(); {
Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load type: '{1}' DeviceFactory: {0}", e, type.Name);
}
}
}
} }
} }
} }

View File

@@ -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
{
/// <summary>
/// Responsible for loading all of the UI device types for this library
/// </summary>
public class UiDeviceFactory
{
public UiDeviceFactory()
{
var dgeControllerFactory = new DgeControllerFactory() as IDeviceFactory;
dgeControllerFactory.LoadTypeFactories();
var essentialsTouchpanelControllerFactory = new EssentialsTouchpanelControllerFactory() as IDeviceFactory;
essentialsTouchpanelControllerFactory.LoadTypeFactories();
}
}
}

View File

@@ -151,7 +151,6 @@
<Compile Include="Factory\DeviceFactory.cs" /> <Compile Include="Factory\DeviceFactory.cs" />
<Compile Include="Devices\Amplifier.cs" /> <Compile Include="Devices\Amplifier.cs" />
<Compile Include="ControlSystem.cs" /> <Compile Include="ControlSystem.cs" />
<Compile Include="Factory\UiDeviceFactory.cs" />
<Compile Include="Fusion\EssentialsHuddleVtc1FusionController.cs" /> <Compile Include="Fusion\EssentialsHuddleVtc1FusionController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Room\Config\EssentialsDualDisplayRoomPropertiesConfig.cs" /> <Compile Include="Room\Config\EssentialsDualDisplayRoomPropertiesConfig.cs" />

View File

@@ -9,7 +9,7 @@ using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
using PepperDash_Essentials_Core.Devices;
namespace PepperDash.Essentials.Core.CrestronIO namespace PepperDash.Essentials.Core.CrestronIO
{ {

View File

@@ -9,7 +9,6 @@ using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core.Bridges; using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
using PepperDash_Essentials_Core.Devices;
namespace PepperDash.Essentials.Core.CrestronIO namespace PepperDash.Essentials.Core.CrestronIO
{ {

View File

@@ -29,6 +29,30 @@ namespace PepperDash.Essentials.Core
public class DeviceFactory 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);
}
}
}
}
/// <summary> /// <summary>
/// A dictionary of factory methods, keyed by config types, added by plugins. /// A dictionary of factory methods, keyed by config types, added by plugins.
/// These methods are looked up and called by GetDevice in this class. /// These methods are looked up and called by GetDevice in this class.
@@ -122,28 +146,4 @@ namespace PepperDash.Essentials.Core
} }
} }
} }
/// <summary>
/// Responsible for loading all of the device types for this library
/// </summary>
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();
}
}
} }

View File

@@ -68,25 +68,21 @@ namespace PepperDash.Essentials
case ("PepperDashEssentials.dll"): case ("PepperDashEssentials.dll"):
{ {
version = Global.AssemblyVersion; version = Global.AssemblyVersion;
assembly = Assembly.GetExecutingAssembly();
break; break;
} }
case ("PepperDash_Essential_Core.dll"): case ("PepperDash_Essentials_Core.dll"):
{ {
version = Global.AssemblyVersion; version = Global.AssemblyVersion;
assembly = System.Reflection
break; break;
} }
case ("PepperDash_Essentials_DM.dll"): case ("PepperDash_Essentials_DM.dll"):
{ {
version = Global.AssemblyVersion; version = Global.AssemblyVersion;
assembly = Assembly.GetExecutingAssembly();
break; break;
} }
case ("Essentials Devices Common.dll"): case ("Essentials Devices Common.dll"):
{ {
version = Global.AssemblyVersion; version = Global.AssemblyVersion;
assembly = Assembly.GetExecutingAssembly();
break; break;
} }
case ("PepperDash_Core.dll"): 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);
}
}
/// <summary> /// <summary>
/// Loads an assembly via Reflection and adds it to the list of loaded assemblies /// Loads an assembly via Reflection and adds it to the list of loaded assemblies
/// </summary> /// </summary>
@@ -503,5 +510,10 @@ namespace PepperDash.Essentials
Version = version; Version = version;
Assembly = assembly; Assembly = assembly;
} }
public void SetAssembly(Assembly assembly)
{
Assembly = assembly;
}
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
@@ -6,6 +7,7 @@ using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DM; using Crestron.SimplSharpPro.DM;
using Crestron.SimplSharpPro.DM.AirMedia; using Crestron.SimplSharpPro.DM.AirMedia;
using Crestron.SimplSharpPro.UI; using Crestron.SimplSharpPro.UI;
using Crestron.SimplSharp.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@@ -20,25 +22,30 @@ namespace PepperDash.Essentials.DM
/// <summary> /// <summary>
/// Responsible for loading the type factories for this library /// Responsible for loading the type factories for this library
/// </summary> /// </summary>
public class DmDeviceFactory public class DeviceFactory
{ {
public DmDeviceFactory() public DeviceFactory()
{ {
Debug.Console(1, "Essentials.DM Factory Adding Types..."); var assy = Assembly.GetExecutingAssembly();
PluginLoader.SetEssentialsAssembly(assy.GetName().Name, assy);
var dmChassisFactory = new DmChassisControllerFactory() as IDeviceFactory; var types = assy.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract);
dmChassisFactory.LoadTypeFactories();
var dmTxFactory = new DmTxControllerFactory() as IDeviceFactory; if (types != null)
dmTxFactory.LoadTypeFactories(); {
foreach (var type in types)
var dmRxFactory = new DmRmcControllerFactory() as IDeviceFactory; {
dmRxFactory.LoadTypeFactories(); try
{
var hdMdFactory = new HdMdxxxCEControllerFactory() as IDeviceFactory; var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type);
hdMdFactory.LoadTypeFactories(); factory.LoadTypeFactories();
}
catch (Exception e)
{
Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load type: '{1}' DeviceFactory: {0}", e, type.Name);
}
}
}
} }
}
}
} }

View File

@@ -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();
}
}
}

View File

@@ -132,7 +132,6 @@
<Compile Include="Display\AvocorVTFDisplay.cs" /> <Compile Include="Display\AvocorVTFDisplay.cs" />
<Compile Include="Display\InputInterfaces.cs" /> <Compile Include="Display\InputInterfaces.cs" />
<Compile Include="Display\SamsungMDCDisplay.cs" /> <Compile Include="Display\SamsungMDCDisplay.cs" />
<Compile Include="Display\DeviceFactory.cs" />
<Compile Include="Display\NecPaSeriesProjector.cs" /> <Compile Include="Display\NecPaSeriesProjector.cs" />
<Compile Include="Display\NECPSXMDisplay.cs" /> <Compile Include="Display\NECPSXMDisplay.cs" />
<Compile Include="DSP\BiampTesira\BiampTesiraForteDspLevel.cs" /> <Compile Include="DSP\BiampTesira\BiampTesiraForteDspLevel.cs" />

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.GeneralIO; using Crestron.SimplSharpPro.GeneralIO;
using Crestron.SimplSharp.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@@ -20,96 +22,31 @@ using PepperDash.Essentials.Devices.Common.Environment;
namespace PepperDash.Essentials.Devices.Common namespace PepperDash.Essentials.Devices.Common
{ {
public class DeviceFactory public class DeviceFactory
{ {
public DeviceFactory() public DeviceFactory()
{ {
var appleTVFactory = new AppleTVFactory() as IDeviceFactory; var assy = Assembly.GetExecutingAssembly();
appleTVFactory.LoadTypeFactories(); PluginLoader.SetEssentialsAssembly(assy.GetName().Name, assy);
var analogWayLCFactory = new AnalogWayLiveCoreFactory() as IDeviceFactory; var types = assy.GetTypes().Where(ct => typeof(IDeviceFactory).IsAssignableFrom(ct) && !ct.IsInterface && !ct.IsAbstract);
analogWayLCFactory.LoadTypeFactories();
var basicIrDisplayFactory = new BasicIrDisplayFactory() as IDeviceFactory; if (types != null)
basicIrDisplayFactory.LoadTypeFactories(); {
foreach (var type in types)
var biampTesiraFactory = new BiampTesiraForteDspFactory() as IDeviceFactory; {
biampTesiraFactory.LoadTypeFactories(); try
{
var cameraViscaFactory = new Cameras.CameraViscaFactory() as IDeviceFactory; var factory = (IDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type);
cameraViscaFactory.LoadTypeFactories(); factory.LoadTypeFactories();
}
var cenRfGwFactory = new CenRfgwControllerFactory() as IDeviceFactory; catch (Exception e)
cenRfGwFactory.LoadTypeFactories(); {
Debug.Console(0, Debug.ErrorLogLevel.Error, "Unable to load type: '{1}' DeviceFactory: {0}", e, type.Name);
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();
} }
} }
} }