mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-11 10:45:00 +00:00
New device loading methodology working via reflection
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads an assembly via Reflection and adds it to the list of loaded assemblies
|
||||
/// </summary>
|
||||
@@ -503,5 +510,10 @@ namespace PepperDash.Essentials
|
||||
Version = version;
|
||||
Assembly = assembly;
|
||||
}
|
||||
|
||||
public void SetAssembly(Assembly assembly)
|
||||
{
|
||||
Assembly = assembly;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
/// <summary>
|
||||
/// Responsible for loading the type factories for this library
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,6 @@
|
||||
<Compile Include="Display\AvocorVTFDisplay.cs" />
|
||||
<Compile Include="Display\InputInterfaces.cs" />
|
||||
<Compile Include="Display\SamsungMDCDisplay.cs" />
|
||||
<Compile Include="Display\DeviceFactory.cs" />
|
||||
<Compile Include="Display\NecPaSeriesProjector.cs" />
|
||||
<Compile Include="Display\NECPSXMDisplay.cs" />
|
||||
<Compile Include="DSP\BiampTesira\BiampTesiraForteDspLevel.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user