feat: modify plugin loading process

This commit is contained in:
Andrew Welker 2025-07-04 13:33:56 -05:00 committed by Neil Dorin
parent 04c4557528
commit aaa5b0532b
14 changed files with 147 additions and 189 deletions

View file

@ -1,27 +0,0 @@
using System;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Represents a ConfigSnippetAttribute
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class ConfigSnippetAttribute : Attribute
{
/// <summary>
/// Represents a configuration snippet for the device.
/// </summary>
/// <param name="configSnippet"></param>
public ConfigSnippetAttribute(string configSnippet)
{
ConfigSnippet = configSnippet;
}
/// <summary>
/// Gets the configuration snippet for the device.
/// This snippet can be used in the DeviceConfig to instantiate the device.
/// </summary>
public string ConfigSnippet { get; }
}
}

View file

@ -1,26 +0,0 @@
using System;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Represents a description attribute for a device.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class DescriptionAttribute : Attribute
{
/// <summary>
/// Represents a description attribute for a device.
/// </summary>
/// <param name="description"></param>
public DescriptionAttribute(string description)
{
Description = description;
}
/// <summary>
/// Gets the description for the device.
/// </summary>
public string Description { get; }
}
}

View file

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
using Serilog.Events;
namespace PepperDash.Essentials.Core
@ -100,4 +102,88 @@ namespace PepperDash.Essentials.Core
}
}
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class DescriptionAttribute : Attribute
{
private string _Description;
public DescriptionAttribute(string description)
{
//Debug.LogMessage(LogEventLevel.Verbose, "Setting Description: {0}", description);
_Description = description;
}
public string Description
{
get { return _Description; }
}
}
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class ConfigSnippetAttribute : Attribute
{
private string _ConfigSnippet;
public ConfigSnippetAttribute(string configSnippet)
{
//Debug.LogMessage(LogEventLevel.Verbose, "Setting Config Snippet {0}", configSnippet);
_ConfigSnippet = configSnippet;
}
public string ConfigSnippet
{
get { return _ConfigSnippet; }
}
}
/// <summary>
/// Represents a factory for creating processor extension devices.
/// </summary>
/// <typeparam name="T">The type of the processor extension device.</typeparam>
public abstract class ProcessorExtensionDeviceFactory<T> : IProcessorExtensionDeviceFactory where T : EssentialsDevice
{
#region IProcessorExtensionDeviceFactory Members
/// <summary>
/// A list of strings that can be used in the type property of a DeviceConfig object to build an instance of this device
/// </summary>
public List<string> TypeNames { get; protected set; }
/// <summary>
/// Loads an item to the ProcessorExtensionDeviceFactory.ProcessorExtensionFactoryMethods dictionary for each entry in the TypeNames list
/// </summary>
public void LoadFactories()
{
foreach (var typeName in TypeNames)
{
//Debug.LogMessage(LogEventLevel.Verbose, "Getting Description Attribute from class: '{0}'", typeof(T).FullName);
var descriptionAttribute = typeof(T).GetCustomAttributes(typeof(DescriptionAttribute), true) as DescriptionAttribute[];
string description = descriptionAttribute[0].Description;
var snippetAttribute = typeof(T).GetCustomAttributes(typeof(ConfigSnippetAttribute), true) as ConfigSnippetAttribute[];
ProcessorExtensionDeviceFactory.AddFactoryForType(typeName.ToLower(), description, typeof(T), BuildDevice);
}
}
/// <summary>
/// The method that will build the device
/// </summary>
/// <param name="dc">The device config</param>
/// <returns>An instance of the device</returns>
public abstract EssentialsDevice BuildDevice(DeviceConfig dc);
#endregion
}
/// <summary>
/// Devices the basic needs for a Device Factory
/// </summary>
public abstract class EssentialsPluginDeviceFactory<T> : EssentialsDeviceFactory<T>, IPluginDeviceFactory where T : EssentialsDevice
{
/// <summary>
/// Specifies the minimum version of Essentials required for a plugin to run. Must use the format Major.Minor.Build (ex. "1.4.33")
/// </summary>
public string MinimumEssentialsFrameworkVersion { get; protected set; }
}
}

View file

@ -1,27 +1,32 @@
using System;
using System;
using System.Collections.Generic;
using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Provides the basic needs for a Device Factory
/// </summary>
public abstract class EssentialsDeviceFactory<T> : IDeviceFactory where T : EssentialsDevice
{
/// <inheritdoc />
public Type FactoryType => typeof(T);
/// <summary>
/// A list of strings that can be used in the type property of a DeviceConfig object to build an instance of this device
/// Devices the basic needs for a Device Factory
/// </summary>
public List<string> TypeNames { get; protected set; }
public abstract class EssentialsDeviceFactory<T> : IDeviceFactory where T:EssentialsDevice
{
#region IDeviceFactory Members
/// <inheritdoc />
public Type FactoryType => typeof(T);
/// <summary>
/// A list of strings that can be used in the type property of a DeviceConfig object to build an instance of this device
/// </summary>
public List<string> TypeNames { get; protected set; }
/// <summary>
/// The method that will build the device
/// </summary>
/// <param name="dc">The device config</param>
/// <returns>An instance of the device</returns>
public abstract EssentialsDevice BuildDevice(DeviceConfig dc);
#endregion
}
/// <summary>
/// Build the device using the configuration
/// </summary>
/// <param name="dc">The device config</param>
/// <returns>An instance of the device</returns>
public abstract EssentialsDevice BuildDevice(DeviceConfig dc);
}
}

View file

@ -1,22 +0,0 @@
using System.Collections.Generic;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// EssentialsPluginDevelopmentDeviceFactory class
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class EssentialsPluginDevelopmentDeviceFactory<T> : EssentialsDeviceFactory<T>, IPluginDevelopmentDeviceFactory where T : EssentialsDevice
{
/// <summary>
/// Specifies the minimum version of Essentials required for a plugin to run. Must use the format Major.Minor.Build (ex. "1.4.33")
/// </summary>
public string MinimumEssentialsFrameworkVersion { get; protected set; }
/// <summary>
/// Gets or sets the DevelopmentEssentialsFrameworkVersions
/// </summary>
public List<string> DevelopmentEssentialsFrameworkVersions { get; protected set; }
}
}

View file

@ -1,14 +0,0 @@
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Devices the basic needs for a Device Factory
/// </summary>
public abstract class EssentialsPluginDeviceFactory<T> : EssentialsDeviceFactory<T>, IPluginDeviceFactory where T : EssentialsDevice
{
/// <summary>
/// Specifies the minimum version of Essentials required for a plugin to run. Must use the format Major.Minor.Build (ex. "1.4.33")
/// </summary>
public string MinimumEssentialsFrameworkVersion { get; protected set; }
}
}

View file

@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Represents a factory for creating processor extension devices.
/// </summary>
/// <typeparam name="T">The type of the processor extension device.</typeparam>
[Obsolete("will be removed in a future version")]
public abstract class ProcessorExtensionDeviceFactory<T> : IProcessorExtensionDeviceFactory where T : EssentialsDevice
{
#region IProcessorExtensionDeviceFactory Members
/// <summary>
/// Gets or sets the TypeNames
/// </summary>
public List<string> TypeNames { get; protected set; }
/// <summary>
/// LoadFactories method
/// </summary>
public void LoadFactories()
{
foreach (var typeName in TypeNames)
{
string description = typeof(T).GetCustomAttributes(typeof(DescriptionAttribute), true) is DescriptionAttribute[] descriptionAttribute && descriptionAttribute.Length > 0
? descriptionAttribute[0].Description
: "No description available";
ProcessorExtensionDeviceFactory.AddFactoryForType(typeName.ToLower(), description, typeof(T), BuildDevice);
}
}
/// <summary>
/// The method that will build the device
/// </summary>
/// <param name="dc">The device config</param>
/// <returns>An instance of the device</returns>
public abstract EssentialsDevice BuildDevice(DeviceConfig dc);
#endregion
}
}