From 57297bfd43d4bbe6d475e36f0ea3af1ca5df7709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gether=20S=C3=B8rensen?= Date: Mon, 4 Dec 2023 05:17:13 +0100 Subject: [PATCH 1/2] Added support for plugins with config and secure config --- .../Resources/Plugin.cs | 20 +++++++++-- src/Delegate.Daxif/Modules/Plugins/Domain.fs | 4 ++- .../Modules/Plugins/PluginDetection.fs | 33 +++++++++++++++---- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/Delegate.Daxif.Scripts/Resources/Plugin.cs b/src/Delegate.Daxif.Scripts/Resources/Plugin.cs index c0a4c49..4f53701 100644 --- a/src/Delegate.Daxif.Scripts/Resources/Plugin.cs +++ b/src/Delegate.Daxif.Scripts/Resources/Plugin.cs @@ -124,9 +124,23 @@ protected string ChildClassName { /// Initializes a new instance of the class. /// /// The of the derived class. - internal Plugin(Type childClassName) { - this.ChildClassName = childClassName.ToString(); - } + internal Plugin(Type childClassName) : this(childClassName, null, null) { } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + internal Plugin(Type childClassName, string unsecure) : this(childClassName, unsecure, null) { } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + internal Plugin(Type childClassName, string unsecure, string secure) { } + /// diff --git a/src/Delegate.Daxif/Modules/Plugins/Domain.fs b/src/Delegate.Daxif/Modules/Plugins/Domain.fs index b0555ce..0415aab 100644 --- a/src/Delegate.Daxif/Modules/Plugins/Domain.fs +++ b/src/Delegate.Daxif/Modules/Plugins/Domain.fs @@ -157,4 +157,6 @@ type AssemblyRegistration = { { id = e.Id hash = e.GetAttributeValue("sourcehash") - } \ No newline at end of file + } + +type PluginConstructorType = Empty | Unsecure | Secure \ No newline at end of file diff --git a/src/Delegate.Daxif/Modules/Plugins/PluginDetection.fs b/src/Delegate.Daxif/Modules/Plugins/PluginDetection.fs index a250dc5..5e77fed 100644 --- a/src/Delegate.Daxif/Modules/Plugins/PluginDetection.fs +++ b/src/Delegate.Daxif/Modules/Plugins/PluginDetection.fs @@ -176,17 +176,30 @@ let getValidPlugins (types:Type[]) = let validTypes, invalidTypes = types |> Array.filter (fun (x:Type) -> x.IsSubclassOf(pluginType.Value)) - |> Array.partition (fun (x:Type) -> not x.IsAbstract && x.GetConstructor(Type.EmptyTypes) <> null) + |> Array.map (fun (x:Type) -> + let constructorType = + match x.GetConstructor(Type.EmptyTypes) <> null, x.GetConstructor([|typeof|]) <> null, x.GetConstructor([|typeof; typeof|]) <> null with + | true,_,_ -> Some PluginConstructorType.Empty + | _,true,_ -> Some PluginConstructorType.Unsecure + | _,_,true -> Some PluginConstructorType.Secure + | false,false,false -> None + + x,constructorType + ) + |> Array.partition (fun (x:Type, constructor: PluginConstructorType option) -> + not x.IsAbstract && constructor.IsSome + ) invalidTypes - |> Array.iter (fun (x:Type) -> + |> Array.iter (fun (x:Type, constructor: PluginConstructorType option) -> if x.IsAbstract then log.Warn "The plugin '%s' is an abstract type and is therefore not valid. The plugin will not be synchronized" (x.Name) - if x.GetConstructor(Type.EmptyTypes) = null - then log.Warn "The plugin '%s' does not contain an empty contructor and is therefore not valid. The plugin will not be synchronized" (x.Name) + if constructor.IsNone + then log.Warn "The plugin '%s' does not contain a valid contructor and is therefore not valid. The plugin will not be synchronized" (x.Name) ) validTypes + |> Array.map (fun (x: Type, constructor: PluginConstructorType option) -> x,constructor.Value) /// Calls "PluginProcessingStepConfigs" in the plugin assembly that returns a /// tuple containing the plugin information @@ -197,8 +210,14 @@ let getPluginsFromAssembly (asm: Assembly) = |> fun validPlugins -> validPlugins - |> Array.Parallel.map (fun (x:Type) -> - Activator.CreateInstance(x), x.GetMethod(@"PluginProcessingStepConfigs")) + |> Array.Parallel.map (fun (x:Type, constructorType: PluginConstructorType) -> + let instance = + match constructorType with + | Empty -> Activator.CreateInstance(x) + | Unsecure -> Activator.CreateInstance(x, [|null|]) + | Secure -> Activator.CreateInstance(x, [|null;null|]) + + instance, x.GetMethod(@"PluginProcessingStepConfigs")) |> Array.Parallel.map (fun (x, (y:MethodInfo)) -> y.Invoke(x, [||]) :?> ((string * int * string * string) * @@ -229,7 +248,7 @@ let getValidCustomAPIs(types:Type[]) = |> Array.iter (fun (x:Type) -> if x.IsAbstract then log.Warn "The custom api '%s' is an abstract type and is therefore not valid. The custom api will not be synchronized" (x.Name) - if x.GetConstructor(Type.EmptyTypes) = null + if x.GetConstructor(Type.EmptyTypes) = null then log.Warn "The custom api '%s' does not contain an empty contructor and is therefore not valid. The custom api will not be synchronized" (x.Name) ) From f3d51043a5fd2f86bd15f2c35d4dddbc2113a749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gether=20S=C3=B8rensen?= Date: Fri, 8 Dec 2023 12:19:02 +0100 Subject: [PATCH 2/2] Now set ChildClassName --- src/Delegate.Daxif.Scripts/Resources/Plugin.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Delegate.Daxif.Scripts/Resources/Plugin.cs b/src/Delegate.Daxif.Scripts/Resources/Plugin.cs index 4f53701..9876ccc 100644 --- a/src/Delegate.Daxif.Scripts/Resources/Plugin.cs +++ b/src/Delegate.Daxif.Scripts/Resources/Plugin.cs @@ -139,7 +139,9 @@ internal Plugin(Type childClassName, string unsecure) : this(childClassName, uns /// /// /// - internal Plugin(Type childClassName, string unsecure, string secure) { } + internal Plugin(Type childClassName, string unsecure, string secure) { + this.ChildClassName = childClassName.ToString(); + }