Files
Essentials/src/PepperDash.Essentials.Devices.Common/DeviceFactory.cs
Andrew Welker 5afdc2effa fix: remove Crestron.SimplSharp.Reflection
Ran into some odd exceptions loading on a VC-4 instance, and changing to System.Reflection solved them.
2024-05-24 16:11:20 -05:00

39 lines
1.1 KiB
C#

using System;
using System.Linq;
using System.Reflection;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Devices.Common
{
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)Activator.CreateInstance(type);
factory.LoadTypeFactories();
}
catch (Exception e)
{
Debug.LogMessage(LogEventLevel.Information, "Unable to load type: '{1}' DeviceFactory: {0}", e, type.Name);
}
}
}
}
}
}