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

View File

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

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="Devices\Amplifier.cs" />
<Compile Include="ControlSystem.cs" />
<Compile Include="Factory\UiDeviceFactory.cs" />
<Compile Include="Fusion\EssentialsHuddleVtc1FusionController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Room\Config\EssentialsDualDisplayRoomPropertiesConfig.cs" />