mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-29 04:15:00 +00:00
Attempt at modifying device factory mechanism
This commit is contained in:
@@ -70,6 +70,11 @@ namespace PepperDash.Essentials
|
||||
{
|
||||
version = Global.AssemblyVersion;
|
||||
assembly = Assembly.GetExecutingAssembly();
|
||||
break;
|
||||
}
|
||||
case ("PepperDashEssentialsBase.dll"):
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
case ("PepperDash_Core.dll"):
|
||||
@@ -339,9 +344,9 @@ namespace PepperDash.Essentials
|
||||
{
|
||||
try
|
||||
{
|
||||
if (typeof(IPluginDeviceConfig).IsAssignableFrom(type))
|
||||
if (typeof(IPluginDeviceFactory).IsAssignableFrom(type))
|
||||
{
|
||||
var plugin = (IPluginDeviceConfig)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type);
|
||||
var plugin = (IPluginDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type);
|
||||
LoadCustomPlugin(plugin, loadedAssembly);
|
||||
}
|
||||
else
|
||||
@@ -377,7 +382,7 @@ namespace PepperDash.Essentials
|
||||
/// Loads a
|
||||
/// </summary>
|
||||
/// <param name="plugin"></param>
|
||||
static void LoadCustomPlugin(IPluginDeviceConfig plugin, LoadedAssembly loadedAssembly)
|
||||
static void LoadCustomPlugin(IPluginDeviceFactory plugin, LoadedAssembly loadedAssembly)
|
||||
{
|
||||
var passed = Global.IsRunningMinimumVersionOrHigher(plugin.MinimumEssentialsFrameworkVersion);
|
||||
|
||||
@@ -392,7 +397,7 @@ namespace PepperDash.Essentials
|
||||
}
|
||||
|
||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading plugin: {0}", loadedAssembly.Name);
|
||||
plugin.LoadPlugin();
|
||||
plugin.LoadTypeFactories();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -13,12 +13,14 @@ using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Serves as a generic wrapper class for all styles of IBasicCommuncation ports
|
||||
/// </summary>
|
||||
public class
|
||||
GenericComm : ReconfigurableDevice
|
||||
public class GenericComm : ReconfigurableDevice
|
||||
{
|
||||
|
||||
EssentialsControlPropertiesConfig PropertiesConfig;
|
||||
|
||||
public IBasicCommunication CommPort { get; private set; }
|
||||
@@ -29,6 +31,14 @@ namespace PepperDash.Essentials.Core
|
||||
PropertiesConfig = CommFactory.GetControlPropertiesConfig(config);
|
||||
|
||||
CommPort = CommFactory.CreateCommForDevice(config);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static IKeyed BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
||||
return new GenericComm(dc);
|
||||
}
|
||||
|
||||
public void SetPortConfig(string portConfig)
|
||||
@@ -51,6 +61,22 @@ namespace PepperDash.Essentials.Core
|
||||
|
||||
ConfigWriter.UpdateDeviceConfig(config);
|
||||
}
|
||||
|
||||
|
||||
public class Factory : EssentialsDevice.Factory
|
||||
{
|
||||
#region IDeviceFactory Members
|
||||
|
||||
List<string> TypeNames = new List<string>() { "genericComm" };
|
||||
|
||||
#endregion
|
||||
|
||||
public override IKeyed BuildDevice(DeviceConfig dc)
|
||||
{
|
||||
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
||||
return new GenericComm(dc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the basic needs for an EssentialsDevice to enable it to be build by an IDeviceFactory class
|
||||
/// </summary>
|
||||
public abstract class EssentialsDevice : Device
|
||||
{
|
||||
public EssentialsDevice(string key)
|
||||
: base(key)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public abstract class Factory : IDeviceFactory
|
||||
{
|
||||
#region IDeviceFactory Members
|
||||
|
||||
public List<string> TypeNames { get; protected set; }
|
||||
|
||||
public virtual void LoadTypeFactories()
|
||||
{
|
||||
foreach (var typeName in TypeNames)
|
||||
{
|
||||
DeviceFactory.AddFactoryForType(typeName, BuildDevice);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public abstract IKeyed BuildDevice(DeviceConfig dc);
|
||||
|
||||
public Factory()
|
||||
{
|
||||
TypeNames = new List<string>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace PepperDash.Essentials.Core.Devices
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public abstract class ReconfigurableDevice : Device
|
||||
public abstract class ReconfigurableDevice : EssentialsDevice
|
||||
{
|
||||
public event EventHandler<EventArgs> ConfigChanged;
|
||||
|
||||
|
||||
@@ -87,4 +87,17 @@ namespace PepperDash.Essentials.Core
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Responsible for loading all of the device types
|
||||
/// </summary>
|
||||
public class CoreDeviceFactory
|
||||
{
|
||||
public CoreDeviceFactory()
|
||||
{
|
||||
var genComm = new GenericComm.Factory() as IDeviceFactory;
|
||||
genComm.LoadTypeFactories();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,7 @@
|
||||
<Compile Include="Devices\CrestronProcessor.cs" />
|
||||
<Compile Include="Devices\DeviceApiBase.cs" />
|
||||
<Compile Include="Devices\DeviceFeedbackExtensions.cs" />
|
||||
<Compile Include="Devices\EssentialsDevice.cs" />
|
||||
<Compile Include="Devices\PC\InRoomPc.cs" />
|
||||
<Compile Include="Devices\PC\Laptop.cs" />
|
||||
<Compile Include="Devices\ReconfigurableDevice.cs" />
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
using PepperDash.Core;
|
||||
using PepperDash.Essentials.Core.Config;
|
||||
|
||||
namespace PepperDash.Essentials.Core.Plugins
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a class that is capable of loading custom plugin device types
|
||||
/// </summary>
|
||||
public interface IPluginDeviceConfig
|
||||
public interface IPluginDeviceFactory : IDeviceFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Required to define the minimum version for Essentials in the format xx.yy.zz
|
||||
/// </summary>
|
||||
string MinimumEssentialsFrameworkVersion { get; }
|
||||
void LoadPlugin();
|
||||
IKeyed BuildDevice(DeviceConfig dc);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines a class that is capable of loading device types
|
||||
/// </summary>
|
||||
public interface IDeviceFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Will be called when the plugin is loaded by Essentials. Must add any new types to the DeviceFactory using DeviceFactory.AddFactoryForType() for each new type
|
||||
/// </summary>
|
||||
void LoadTypeFactories();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user