diff --git a/Pilz.Plugins.Advanced/Pilz.Plugins.Advanced.csproj b/Pilz.Plugins.Advanced/Pilz.Plugins.Advanced.csproj index 652ff13..46d765a 100644 --- a/Pilz.Plugins.Advanced/Pilz.Plugins.Advanced.csproj +++ b/Pilz.Plugins.Advanced/Pilz.Plugins.Advanced.csproj @@ -9,7 +9,7 @@ True - 2.0.0 + 2.1.0 diff --git a/Pilz.Plugins.Advanced/PluginFeature.cs b/Pilz.Plugins.Advanced/PluginFeature.cs new file mode 100644 index 0000000..4864206 --- /dev/null +++ b/Pilz.Plugins.Advanced/PluginFeature.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Telerik.WinControls; + +namespace Pilz.Plugins.Advanced +{ + public abstract class PluginFeature + { + public string Type { get; init; } + public virtual string? Name { get; init; } + public virtual RadSvgImage? Icon { get; set; } + public virtual bool Enabled { get; set; } = true; + + protected PluginFeature(string functionType) + { + Type = functionType; + } + + protected PluginFeature(string functionType, string? functionName) : this(functionType) + { + Name = functionName; + } + } +} diff --git a/Pilz.Plugins.Advanced/PluginFeatureController.cs b/Pilz.Plugins.Advanced/PluginFeatureController.cs new file mode 100644 index 0000000..c301a13 --- /dev/null +++ b/Pilz.Plugins.Advanced/PluginFeatureController.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Pilz.Plugins.Advanced +{ + public sealed class PluginFeatureController + { + /// + /// The default public instance that can be used by plugins and the interface providing software. + /// + public static PluginFeatureController Instance { get; private set; } = new(); + + private readonly List features = new(); + + /// + /// Returns a collection of all registred instances. + /// + public IReadOnlyList Features => features.AsReadOnly(); + + /// + /// A wrapper for all registred instances. + /// + public ModuleController Modules { get; init; } + /// + /// A wrapper for all registred instances. + /// + public FunctionController Functions { get; init; } + + public PluginFeatureController() + { + Functions = new(this); + Modules = new(this); + } + + public void Register(PluginFeature module) + { + if (!features.Contains(module)) + features.Add(module); + } + + public void Unregister(PluginFeature module) + { + features.Remove(module); + } + + public class ModuleController + { + private readonly PluginFeatureController controller; + + public ModuleController(PluginFeatureController controller) + { + this.controller = controller; + } + + public IEnumerable GetAll() + { + return controller.features.OfType(); + } + + public IEnumerable Get(string moduleType) + { + return GetAll().Where(n => n.Type == moduleType); + } + } + + public class FunctionController + { + private readonly PluginFeatureController controller; + + public FunctionController(PluginFeatureController controller) + { + this.controller = controller; + } + + public IEnumerable GetAll() + { + return controller.features.OfType(); + } + + public IEnumerable Get(string functionType) + { + return GetAll().Where(n => n.Type == functionType); + } + + public void ExecuteAll(string functionType) + { + foreach (var function in Get(functionType)) + function.Execute(); + } + + public void ExecuteAll(string functionType, params object?[]? @params) + { + foreach (var function in Get(functionType)) + function.Execute(@params); + } + + public void ExecuteAll(string functionType, PluginFunctionParameter @params) + { + foreach (var function in Get(functionType)) + function.Execute(@params); + } + + public IEnumerable ExcuteAndGetResults(string functionType) + { + return Get(functionType).Select(n => n.Execute()); + } + + public IEnumerable ExcuteAndGetResults(string functionType, params object?[]? @params) + { + return Get(functionType).Select(n => n.Execute(@params)); + } + + public IEnumerable ExcuteAndGetResults(string functionType, PluginFunctionParameter @params) + { + return Get(functionType).Select(n => n.Execute(@params)); + } + } + } +} diff --git a/Pilz.Plugins.Advanced/PluginFunction.cs b/Pilz.Plugins.Advanced/PluginFunction.cs index d964f7f..5bc6953 100644 --- a/Pilz.Plugins.Advanced/PluginFunction.cs +++ b/Pilz.Plugins.Advanced/PluginFunction.cs @@ -7,59 +7,41 @@ using Telerik.WinControls; namespace Pilz.Plugins.Advanced { - public abstract class PluginFunction + public abstract class PluginFunction : PluginFeature { - public string Type { get; init; } - public string? Name { get; init; } - public RadSvgImage? Icon { get; set; } - public bool Enabled { get; set; } = true; - - protected PluginFunction(string functionType) + protected PluginFunction(string functionType) : base(functionType) { - Type = functionType; } - protected PluginFunction(string functionType, string functionName) : this(functionType) + protected PluginFunction(string functionType, string? functionName) : base(functionType, functionName) { - Name = functionName; } - public object? Execute() + public virtual object? Execute() { return Execute((PluginFunctionParameter?)null); } - public T? Execute(params object?[]? @params) + public virtual T? Execute(params object?[]? @params) { return Execute(new PluginFunctionSimpleParamter(@params)); } - public object? Execute(params object?[]? @params) + public virtual object? Execute(params object?[]? @params) { return Execute(new PluginFunctionSimpleParamter(@params)); } - public T? Execute(PluginFunctionSimpleParamter? @params) + public virtual T? Execute(PluginFunctionSimpleParamter? @params) { if (Execute(@params) is T result) return result; return default; } - public object? Execute(PluginFunctionParameter? @params) + public virtual object? Execute(PluginFunctionParameter? @params) { -#if !DEBUG - try - { -#endif - return ExecuteFunction(@params); -#if !DEBUG - } - catch (Exception) - { - return null; - } -#endif + return ExecuteFunction(@params); } protected abstract object? ExecuteFunction(PluginFunctionParameter? @params); diff --git a/Pilz.Plugins.Advanced/PluginFunctionController.cs b/Pilz.Plugins.Advanced/PluginFunctionController.cs deleted file mode 100644 index 8891810..0000000 --- a/Pilz.Plugins.Advanced/PluginFunctionController.cs +++ /dev/null @@ -1,60 +0,0 @@ -namespace Pilz.Plugins.Advanced -{ - public sealed class PluginFunctionController - { - public static PluginFunctionController Instance { get; private set; } = new(); - - private readonly List functions = new(); - - public IReadOnlyCollection Functions => functions.AsReadOnly(); - - public void RegisterFunction(PluginFunction function) - { - if (!functions.Contains(function)) - functions.Add(function); - } - - public void UnregisterFunction(PluginFunction function) - { - functions.Remove(function); - } - - public IEnumerable GetFunctions(string functionType) - { - return functions.Where(n => n.Type == functionType); - } - - public void ExecuteAll(string functionType) - { - foreach (var function in GetFunctions(functionType)) - function.Execute(); - } - - public void ExecuteAll(string functionType, params object?[]? @params) - { - foreach (var function in GetFunctions(functionType)) - function.Execute(@params); - } - - public void ExecuteAll(string functionType, PluginFunctionParameter @params) - { - foreach (var function in GetFunctions(functionType)) - function.Execute(@params); - } - - public IEnumerable ExcuteAndGetResults(string functionType) - { - return GetFunctions(functionType).Select(n => n.Execute()); - } - - public IEnumerable ExcuteAndGetResults(string functionType, params object?[]? @params) - { - return GetFunctions(functionType).Select(n => n.Execute(@params)); - } - - public IEnumerable ExcuteAndGetResults(string functionType, PluginFunctionParameter @params) - { - return GetFunctions(functionType).Select(n => n.Execute(@params)); - } - } -} \ No newline at end of file diff --git a/Pilz.Plugins.Advanced/PluginModule.cs b/Pilz.Plugins.Advanced/PluginModule.cs index 3ea2101..d51043e 100644 --- a/Pilz.Plugins.Advanced/PluginModule.cs +++ b/Pilz.Plugins.Advanced/PluginModule.cs @@ -6,19 +6,13 @@ using Telerik.WinControls; namespace Pilz.Plugins.Advanced { - public abstract class PluginModule + public abstract class PluginModule : PluginFeature { - public string Type { get; init; } - public string Name { get; init; } - public RadSvgImage? Icon { get; set; } public bool Visible { get; set; } = true; - public bool RequiresRomManager { get; set; } = true; public bool AllowEmbedding { get; set; } = true; - protected PluginModule(string moduleType, string moduleName) + protected PluginModule(string moduleType, string moduleName) : base(moduleType, moduleName) { - Type = moduleType; - Name = moduleName; } public virtual void ShowUI() @@ -26,11 +20,11 @@ namespace Pilz.Plugins.Advanced if (CreateNewUI() is PluginModuleUI ui) { ui.BackColor = Color.Transparent; - DialogBaseForm.Show(ui, Name, Icon!.ToImage().ToIcon()!); + DialogBaseForm.Show(ui, Name!, Icon!.ToImage().ToIcon()!); } } - public PluginModuleUI CreateUI() + public virtual PluginModuleUI CreateUI() { return CreateNewUI(); } diff --git a/Pilz.Plugins.Advanced/PluginModuleController.cs b/Pilz.Plugins.Advanced/PluginModuleController.cs deleted file mode 100644 index 820f68d..0000000 --- a/Pilz.Plugins.Advanced/PluginModuleController.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Pilz.Plugins.Advanced -{ - public sealed class PluginModuleController - { - public static PluginModuleController Instance { get; private set; } = new(); - - private readonly List modules = new(); - - public IReadOnlyList Modules => modules.AsReadOnly(); - - public void RegisterModule(PluginModule module) - { - if (!modules.Contains(module)) - modules.Add(module); - } - - public void UnregisterModule(PluginModule module) - { - modules.Remove(module); - } - } -}