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

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