mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-21 16:34:48 +00:00
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Crestron.SimplSharp;
|
|
using Crestron.SimplSharp.CrestronIO;
|
|
using Crestron.SimplSharpPro;
|
|
using Crestron.SimplSharp.Reflection;
|
|
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using PepperDash.Core;
|
|
using PepperDash.Essentials.Core;
|
|
using PepperDash.Essentials.Core.Config;
|
|
|
|
namespace PepperDash.Essentials
|
|
{
|
|
/// <summary>
|
|
/// Responsible for loading all of the device types for this library
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|