mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 13:15:03 +00:00
Adds back the correct PluginLoader version that supports loading with the new plugin methodology
This commit is contained in:
@@ -18,7 +18,6 @@ namespace PepperDash.Essentials.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class GenericComm : ReconfigurableDevice
|
public class GenericComm : ReconfigurableDevice
|
||||||
{
|
{
|
||||||
|
|
||||||
EssentialsControlPropertiesConfig PropertiesConfig;
|
EssentialsControlPropertiesConfig PropertiesConfig;
|
||||||
|
|
||||||
public IBasicCommunication CommPort { get; private set; }
|
public IBasicCommunication CommPort { get; private set; }
|
||||||
@@ -30,7 +29,6 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
CommPort = CommFactory.CreateCommForDevice(config);
|
CommPort = CommFactory.CreateCommForDevice(config);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IKeyed BuildDevice(DeviceConfig dc)
|
public static IKeyed BuildDevice(DeviceConfig dc)
|
||||||
@@ -59,20 +57,19 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
ConfigWriter.UpdateDeviceConfig(config);
|
ConfigWriter.UpdateDeviceConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GenericCommFactory : Essentials.Core.EssentialsDeviceFactory<GenericComm>
|
public class GenericCommFactory : Essentials.Core.EssentialsDeviceFactory<GenericComm>
|
||||||
{
|
{
|
||||||
|
public GenericCommFactory()
|
||||||
|
{
|
||||||
|
TypeNames = new List<string>() { "genericComm" };
|
||||||
|
}
|
||||||
|
|
||||||
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
public override EssentialsDevice BuildDevice(DeviceConfig dc)
|
||||||
{
|
{
|
||||||
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
Debug.Console(1, "Factory Attempting to create new Generic Comm Device");
|
||||||
return new GenericComm(dc);
|
return new GenericComm(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericCommFactory()
|
|
||||||
{
|
|
||||||
TypeNames = new List<string>() { "genericComm" };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
public List<string> TypeNames { get; protected set; }
|
public List<string> TypeNames { get; protected set; }
|
||||||
|
|
||||||
public virtual void LoadTypeFactories()
|
public void LoadTypeFactories()
|
||||||
{
|
{
|
||||||
foreach (var typeName in TypeNames)
|
foreach (var typeName in TypeNames)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Crestron.SimplSharp.Reflection;
|
|||||||
|
|
||||||
using PepperDash.Core;
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
|
using PepperDash.Essentials.Core.Plugins;
|
||||||
|
|
||||||
namespace PepperDash.Essentials
|
namespace PepperDash.Essentials
|
||||||
{
|
{
|
||||||
@@ -69,6 +70,11 @@ namespace PepperDash.Essentials
|
|||||||
{
|
{
|
||||||
version = Global.AssemblyVersion;
|
version = Global.AssemblyVersion;
|
||||||
assembly = Assembly.GetExecutingAssembly();
|
assembly = Assembly.GetExecutingAssembly();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ("PepperDashEssentialsBase.dll"):
|
||||||
|
{
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ("PepperDash_Core.dll"):
|
case ("PepperDash_Core.dll"):
|
||||||
@@ -337,48 +343,20 @@ namespace PepperDash.Essentials
|
|||||||
foreach (var type in types)
|
foreach (var type in types)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
if (typeof(IPluginDeviceFactory).IsAssignableFrom(type))
|
||||||
|
{
|
||||||
|
var plugin = (IPluginDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type);
|
||||||
|
LoadCustomPlugin(plugin, loadedAssembly);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static);
|
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static);
|
||||||
var loadPlugin = methods.FirstOrDefault(m => m.Name.Equals("LoadPlugin"));
|
var loadPlugin = methods.FirstOrDefault(m => m.Name.Equals("LoadPlugin"));
|
||||||
if (loadPlugin != null)
|
if (loadPlugin != null)
|
||||||
{
|
{
|
||||||
Debug.Console(2, "LoadPlugin method found in {0}", type.Name);
|
LoadCustomLegacyPlugin(type, loadPlugin, loadedAssembly);
|
||||||
|
|
||||||
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);
|
|
||||||
|
|
||||||
var minimumVersion = fields.FirstOrDefault(p => p.Name.Equals("MinimumEssentialsFrameworkVersion"));
|
|
||||||
if (minimumVersion != null)
|
|
||||||
{
|
|
||||||
Debug.Console(2, "MinimumEssentialsFrameworkVersion found");
|
|
||||||
|
|
||||||
var minimumVersionString = minimumVersion.GetValue(null) as string;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(minimumVersionString))
|
|
||||||
{
|
|
||||||
var passed = Global.IsRunningMinimumVersionOrHigher(minimumVersionString);
|
|
||||||
|
|
||||||
if (!passed)
|
|
||||||
{
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Error, "Plugin indicates minimum Essentials version {0}. Dependency check failed. Skipping Plugin", minimumVersionString);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Passed plugin passed dependency check (required version {0})", minimumVersionString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Warning, "MinimumEssentialsFrameworkVersion found but not set. Loading plugin, but your mileage may vary.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Warning, "MinimumEssentialsFrameworkVersion not found. Loading plugin, but your mileage may vary.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Adding plugin: {0}", loadedAssembly.Name);
|
|
||||||
loadPlugin.Invoke(null, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -400,6 +378,75 @@ namespace PepperDash.Essentials
|
|||||||
Debug.Console(0, "Done Loading Custom Plugin Types.");
|
Debug.Console(0, "Done Loading Custom Plugin Types.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads a
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plugin"></param>
|
||||||
|
static void LoadCustomPlugin(IPluginDeviceFactory plugin, LoadedAssembly loadedAssembly)
|
||||||
|
{
|
||||||
|
var passed = Global.IsRunningMinimumVersionOrHigher(plugin.MinimumEssentialsFrameworkVersion);
|
||||||
|
|
||||||
|
if (!passed)
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Plugin indicates minimum Essentials version {0}. Dependency check failed. Skipping Plugin", plugin.MinimumEssentialsFrameworkVersion);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Passed plugin passed dependency check (required version {0})", plugin.MinimumEssentialsFrameworkVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading plugin: {0}", loadedAssembly.Name);
|
||||||
|
plugin.LoadTypeFactories();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads a a custom plugin via the legacy method
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="loadPlugin"></param>
|
||||||
|
static void LoadCustomLegacyPlugin(CType type, MethodInfo loadPlugin, LoadedAssembly loadedAssembly)
|
||||||
|
{
|
||||||
|
Debug.Console(2, "LoadPlugin method found in {0}", type.Name);
|
||||||
|
|
||||||
|
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);
|
||||||
|
|
||||||
|
var minimumVersion = fields.FirstOrDefault(p => p.Name.Equals("MinimumEssentialsFrameworkVersion"));
|
||||||
|
if (minimumVersion != null)
|
||||||
|
{
|
||||||
|
Debug.Console(2, "MinimumEssentialsFrameworkVersion found");
|
||||||
|
|
||||||
|
var minimumVersionString = minimumVersion.GetValue(null) as string;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(minimumVersionString))
|
||||||
|
{
|
||||||
|
var passed = Global.IsRunningMinimumVersionOrHigher(minimumVersionString);
|
||||||
|
|
||||||
|
if (!passed)
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Error, "Plugin indicates minimum Essentials version {0}. Dependency check failed. Skipping Plugin", minimumVersionString);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Passed plugin passed dependency check (required version {0})", minimumVersionString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Warning, "MinimumEssentialsFrameworkVersion found but not set. Loading plugin, but your mileage may vary.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Warning, "MinimumEssentialsFrameworkVersion not found. Loading plugin, but your mileage may vary.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading legacy plugin: {0}", loadedAssembly.Name);
|
||||||
|
loadPlugin.Invoke(null, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads plugins
|
/// Loads plugins
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -415,7 +462,8 @@ namespace PepperDash.Essentials
|
|||||||
// Deal with any .cplz files
|
// Deal with any .cplz files
|
||||||
UnzipAndMoveCplzArchives();
|
UnzipAndMoveCplzArchives();
|
||||||
|
|
||||||
if(Directory.Exists(_loadedPluginsDirectoryPath)) {
|
if (Directory.Exists(_loadedPluginsDirectoryPath))
|
||||||
|
{
|
||||||
// Load the assemblies from the loadedPlugins folder into the AppDomain
|
// Load the assemblies from the loadedPlugins folder into the AppDomain
|
||||||
LoadPluginAssemblies();
|
LoadPluginAssemblies();
|
||||||
|
|
||||||
@@ -424,6 +472,7 @@ namespace PepperDash.Essentials
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user