Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for plugins with config and secure config #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Delegate.Daxif.Scripts/Resources/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,27 @@ protected string ChildClassName {
/// Initializes a new instance of the <see cref="Plugin"/> class.
/// </summary>
/// <param name="childClassName">The <see cref="" cred="Type"/> of the derived class.</param>
internal Plugin(Type childClassName) {
internal Plugin(Type childClassName) : this(childClassName, null, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="Plugin"/> class.
/// </summary>
/// <param name="childClassName"></param>
/// <param name="unsecure"></param>
internal Plugin(Type childClassName, string unsecure) : this(childClassName, unsecure, null) { }

/// <summary>
/// Initializes a new instance of the <see cref="Plugin"/> class.
/// </summary>
/// <param name="childClassName"></param>
/// <param name="unsecure"></param>
/// <param name="secure"></param>
internal Plugin(Type childClassName, string unsecure, string secure) {
this.ChildClassName = childClassName.ToString();
}



/// <summary>
/// Executes the plug-in.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/Delegate.Daxif/Modules/Plugins/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@ type AssemblyRegistration = {
{
id = e.Id
hash = e.GetAttributeValue<string>("sourcehash")
}
}

type PluginConstructorType = Empty | Unsecure | Secure
33 changes: 26 additions & 7 deletions src/Delegate.Daxif/Modules/Plugins/PluginDetection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>|]) <> null, x.GetConstructor([|typeof<string>; typeof<string>|]) <> 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
Expand All @@ -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) *
Expand Down Expand Up @@ -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)
)

Expand Down