remove legacy plugin system

This commit is contained in:
2024-01-23 09:16:50 +01:00
parent 1be6200c58
commit cc84215d73
8 changed files with 1 additions and 433 deletions

View File

@@ -1,19 +0,0 @@
Namespace Attributes
Public Class PluginFunctionAttribute
Inherits Attribute
Public ReadOnly Property FunctionCode As String
Public ReadOnly Property Params As Object()
''' <summary/>
''' <param name="funcCode">The function code for this PluginFunction.</param>
''' <param name="params">The parameters for this PluginFunction.</param>
Public Sub New(funcCode As String, ParamArray params As Object())
Me.FunctionCode = funcCode
Me.Params = params
End Sub
End Class
End Namespace

View File

@@ -1,7 +0,0 @@
Namespace Attributes
Public Class LoadMethodAttribute
Inherits Attribute
End Class
End Namespace

View File

@@ -1,46 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<DocumentationFile>Pilz.Reflection.PluginSystem.xml</DocumentationFile>
<DefineTrace>true</DefineTrace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineDebug>true</DefineDebug>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineDebug>false</DefineDebug>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<PropertyGroup>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
<Import Include="System.Threading.Tasks" />
</ItemGroup>
</Project>

View File

@@ -1,127 +0,0 @@
Imports System.IO
Imports System.Reflection
Imports Pilz.Reflection.PluginSystem.Attributes
Public Class Plugin
''' <summary>
''' A collection of Methods that contains PluginFunctions that will be called automatically when loading the Plugin, as long as the property AutoCallMainFunctions is set to True.
''' </summary>
''' <returns></returns>
Public ReadOnly Property MainFunctions As IReadOnlyList(Of PluginFunction)
''' <summary>
''' A collection of Methods with a FunctionCode (excluding all PluginFunctions from MainFunctions).
''' </summary>
''' <returns></returns>
Public ReadOnly Property PluginFunctions As IReadOnlyList(Of PluginFunction)
''' <summary>
''' Gets the assembly that contains the PluginFunctions of this Plugin
''' </summary>
''' <returns></returns>
Public ReadOnly Property Assembly As Assembly
''' <summary>
''' Gets the main module that contains the PluginFunctions of this Plugin
''' </summary>
''' <returns></returns>
Public ReadOnly Property MainModule As Type
''' <summary>
''' Load a new Plugin and its PluginFunctions.
''' </summary>
''' <param name="filePath"></param>
''' <param name="autoCallMainFunction">If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded.</param>
''' <param name="entryTypeName">The name of the type where to search for Methods when loading a new Plugin.</param>
Public Sub New(filePath As String, autoCallMainFunction As Boolean, entryTypeName As String)
Assembly = Assembly.LoadFile(filePath)
MainModule = Assembly.GetType(entryTypeName)
If MainModule Is Nothing Then
Throw New PluginLoadException("Plugin Modul not found!")
End If
'Define the attribute types to observe
Dim entryMethodType As Type = GetType(LoadMethodAttribute)
Dim implementMethodType As Type = GetType(PluginFunctionAttribute)
'Create the lists
Dim mainMethods As New List(Of PluginFunction)
Dim implementMethods As New List(Of PluginFunction)
'Search for PluginFunctions
For Each mi As MethodInfo In MainModule.GetMethods
Dim found As Boolean = False
'Check if the method has one of the defined attributes
For Each attr As Attribute In Attribute.GetCustomAttributes(mi)
If Not found Then
Dim t As Type = attr.GetType
Select Case t
Case entryMethodType
mainMethods.Add(New PluginFunction(mi, Me))
Case implementMethodType
With CType(attr, PluginFunctionAttribute)
implementMethods.Add(New PluginFunction(mi, Me, .Params, .FunctionCode))
End With
End Select
found = True
End If
Next
Next
'Set the collections
Me.MainFunctions = mainMethods
Me.PluginFunctions = implementMethods
'Call all PluginFunctions in MainFunctions
If autoCallMainFunction Then
For Each func As PluginFunction In mainMethods
Dim params As ParameterInfo() = func.Method.GetParameters
If params.Length = 1 Then
Dim startupExe As String = Assembly.GetEntryAssembly.Location
Dim args As String() = {startupExe, filePath}
func.Invoke({args})
ElseIf Not params.Any Then
func.Invoke()
End If
Next
End If
End Sub
''' <summary>
''' Get all PluginFunctions that have one of the given function codes.
''' </summary>
''' <param name="funcCodes"></param>
''' <returns></returns>
Public Function GetFunctions(ParamArray funcCodes As String()) As IEnumerable(Of PluginFunction)
Dim funcs As New List(Of PluginFunction)
For Each func As PluginFunction In PluginFunctions
If funcCodes.Contains(func.FunctionCode) Then
funcs.Add(func)
End If
Next
Return funcs
End Function
''' <summary>
''' Get the first PluginFunction that have the one of the given function codes.
''' </summary>
''' <returns></returns>
Public Function GetFunction(ParamArray funcCodes As String()) As PluginFunction
Dim f As PluginFunction = Nothing
For Each func As PluginFunction In PluginFunctions
If f Is Nothing AndAlso funcCodes.Contains(func.FunctionCode) Then
f = func
End If
Next
Return f
End Function
End Class

View File

@@ -1,73 +0,0 @@
Imports System.Reflection
Public Class PluginFunction
''' <summary>
''' Gets the method to invoke when invoking this PluginFunction.
''' </summary>
''' <returns></returns>
Public ReadOnly Property Method As MethodInfo
''' <summary>
''' Gets the refered Plugin for this PluginFunction, if it has one.
''' </summary>
''' <returns></returns>
Public ReadOnly Property Plugin As Plugin
''' <summary>
''' Gets the Parameters that was given by the attribute.
''' </summary>
''' <returns></returns>
Public ReadOnly Property Params As Object()
''' <summary>
''' Gets the function code for this PluginFunction.
''' </summary>
''' <returns></returns>
Public ReadOnly Property FunctionCode As String
''' <summary>
''' Creates a new instance of a PluginFunction.
''' </summary>
''' <param name="method">The Method to invoke when invoking this PluginFunction.</param>
''' <param name="plugin">The Plugin that is the Parent of this PluginFunction. This value can be NULL.</param>
Public Sub New(method As MethodInfo, plugin As Plugin)
Me.Method = method
Me.Plugin = plugin
End Sub
''' <summary>
''' Creates a new instance of a PluginFunction.
''' </summary>
''' <param name="method">The Method to invoke when invoking this PluginFunction..</param>
''' <param name="plugin">The Plugin that is the Parent of this PluginFunction. This value can be NULL.</param>
''' <param name="params">The Parameters that was given by the attribute.</param>
''' <param name="funcCode">The function code for this PluginFunction.</param>
Public Sub New(method As MethodInfo, plugin As Plugin, params As Object(), funcCode As String)
Me.New(method, plugin)
Me.Params = params
Me.FunctionCode = funcCode
End Sub
''' <summary>
''' Invokes the Method of the PluginFunction.
''' </summary>
Public Sub Invoke()
Method.Invoke(Nothing, Nothing)
End Sub
''' <summary>
''' Invokes the Method of the PluginFunction.
''' </summary>
Public Sub Invoke(ParamArray params As Object())
Method.Invoke(Nothing, params)
End Sub
''' <summary>
''' Invokes the Method of the PluginFunction and returns the return value.
''' </summary>
Public Function InvokeGet(ParamArray params As Object()) As Object
Return Method.Invoke(Nothing, params)
End Function
End Class

View File

@@ -1,11 +0,0 @@
Public Class PluginLoadException
Inherits Exception
Public Sub New()
MyBase.New
End Sub
Public Sub New(message As String)
MyBase.New(message)
End Sub
End Class

View File

@@ -1,139 +0,0 @@
Imports System.IO
Public Class PluginManager
''' <summary>
''' Gets or sets an indicator if an exception should throw on error while loading a plugin.
''' </summary>
''' <returns></returns>
Public Property ThrowOnError As Boolean = False
''' <summary>
''' The name of the type where to search for Methods when loading a new Plugin.
''' </summary>
''' <returns></returns>
Public Property EntryTypeName As String = "Plugin"
''' <summary>
''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded.
''' </summary>
''' <returns></returns>
Public Property AutoCallMainFunctions As Boolean = True
''' <summary>
''' A collection of all loaded Plugins.
''' </summary>
''' <returns></returns>
Public ReadOnly Property Plugins As New Dictionary(Of String, Plugin)
''' <summary>
''' Loads Plugins that can be found at the given path and adds them to the Plugins-List.
''' </summary>
''' <param name="pluginPath">The path where to search for Plugins to load.</param>
Public Function LoadPlugins(pluginPath As String) As IEnumerable(Of Plugin)
Return LoadPlugins(pluginPath, True)
End Function
''' <summary>
''' Loads Plugins that can be found at the given path and adds them to the Plugins-List.
''' </summary>
''' <param name="pluginPath">The path where to search for Plugins to load.</param>
''' <param name="addToList">If true, the Plugins will be added to Plugins-List after loading.</param>
Public Function LoadPlugins(pluginPath As String, addToList As Boolean) As IEnumerable(Of Plugin)
Return LoadPlugins(pluginPath, addToList, AutoCallMainFunctions, EntryTypeName)
End Function
''' <summary>
''' Loads Plugins that can be found at the given path and adds them to the Plugins-List.
''' </summary>
''' <param name="pluginPath">The path where to search for Plugins to load.</param>
''' <param name="addToList">If true, the Plugins will be added to Plugins-List after loading.</param>
''' <param name="autoCallMainFunction">If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded.</param>
''' <param name="entryTypeName">The name of the type where to search for Methods when loading a new Plugin.</param>
Public Function LoadPlugins(pluginPath As String, addToList As Boolean, autoCallMainFunction As Boolean, entryTypeName As String) As IEnumerable(Of Plugin)
Dim loaded As New List(Of Plugin)
For Each f As String In Directory.GetFiles(pluginPath, "*.dll", SearchOption.AllDirectories)
Dim p As Plugin = LoadPlugin(f, addToList)
If p IsNot Nothing Then
loaded.Add(p)
End If
Next
Return loaded
End Function
''' <summary>
''' Loads a Plugin and adds it to the Plugins-List.
''' </summary>
''' <param name="filePath">The path to the plugin to load.</param>
''' <param name="addToList">If true, the Plugin will be added to Plugins-List after loading.</param>
Public Function LoadPlugin(filePath As String, addToList As Boolean) As Plugin
Return LoadPlugin(filePath, addToList, AutoCallMainFunctions, EntryTypeName)
End Function
''' <summary>
''' Loads a Plugin and adds it to the Plugins-List.
''' </summary>
''' <param name="filePath">The path to the plugin to load.</param>
''' <param name="addToList">If true, the Plugin will be added to Plugins-List after loading.</param>
''' <param name="autoCallMainFunction">If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded.</param>
''' <param name="entryTypeName">The name of the type where to search for Methods when loading a new Plugin.</param>
Public Function LoadPlugin(filePath As String, addToList As Boolean, autoCallMainFunction As Boolean, entryTypeName As String) As Plugin
Try
Dim plugin As New Plugin(filePath, autoCallMainFunction, entryTypeName)
If addToList Then Plugins.Add(filePath, plugin)
Return plugin
Catch ex As Exception
If ThrowOnError Then
Throw
Else
Return Nothing
End If
End Try
End Function
''' <summary>
''' Loads a Plugin and adds it to the Plugins-List.
''' </summary>
''' <param name="filePath">The path to the plugin to load.</param>
Public Function LoadPlugin(filePath As String) As Plugin
Return LoadPlugin(filePath, True)
End Function
''' <summary>
''' Get all PluginFunctions that have one of the given function codes.
''' </summary>
''' <param name="funcCodes"></param>
''' <returns></returns>
Public Function GetFunctions(ParamArray funcCodes As String()) As IEnumerable(Of PluginFunction)
Dim list As New List(Of PluginFunction)
For Each kvp In Plugins
list.AddRange(kvp.Value.GetFunctions(funcCodes))
Next
Return list
End Function
''' <summary>
''' Get the first PluginFunction that have the one of the given function codes.
''' </summary>
''' <returns></returns>
Public Function GetFunction(ParamArray funcCodes As String()) As PluginFunction
Dim f As PluginFunction = Nothing
For Each kvp In Plugins
If f Is Nothing Then
For Each func As PluginFunction In kvp.Value.GetFunctions(funcCodes)
If f Is Nothing Then
f = func
End If
Next
End If
Next
Return f
End Function
End Class

View File

@@ -19,8 +19,6 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Pilz.Win32", "Pilz.Win32\Pi
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Configuration", "Pilz.Configuration\Pilz.Configuration.csproj", "{1748E038-0A47-04E1-3C5E-FF9566DFFB7C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Configuration", "Pilz.Configuration\Pilz.Configuration.csproj", "{1748E038-0A47-04E1-3C5E-FF9566DFFB7C}"
EndProject EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Pilz.Reflection.PluginSystem", "Pilz.Reflection.PluginSystem\Pilz.Reflection.PluginSystem.vbproj", "{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}"
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Pilz.Drawing.Drawing3D.OpenGLFactory", "Pilz.Drawing.Drawing3D.OpenGLRenderer\Pilz.Drawing.Drawing3D.OpenGLFactory.vbproj", "{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}" Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Pilz.Drawing.Drawing3D.OpenGLFactory", "Pilz.Drawing.Drawing3D.OpenGLRenderer\Pilz.Drawing.Drawing3D.OpenGLFactory.vbproj", "{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}"
EndProject EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Pilz.Simple3DFileParser", "Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.vbproj", "{AC955819-7910-450C-940C-7C1989483D4B}" Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Pilz.Simple3DFileParser", "Pilz.Simple3DFileParser\Pilz.Simple3DFileParser.vbproj", "{AC955819-7910-450C-940C-7C1989483D4B}"
@@ -41,7 +39,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Plugins", "Pilz.Plugin
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Plugins.Advanced", "Pilz.Plugins.Advanced\Pilz.Plugins.Advanced.csproj", "{72153EC8-B297-4A94-80AA-3574544BE8CF}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Plugins.Advanced", "Pilz.Plugins.Advanced\Pilz.Plugins.Advanced.csproj", "{72153EC8-B297-4A94-80AA-3574544BE8CF}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Gaming.Minecraft", "Pilz.Gaming.Minecraft\Pilz.Gaming.Minecraft.csproj", "{B285DA24-39C9-4BA2-AF3D-A1A05737268B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Gaming.Minecraft", "Pilz.Gaming.Minecraft\Pilz.Gaming.Minecraft.csproj", "{B285DA24-39C9-4BA2-AF3D-A1A05737268B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -115,14 +113,6 @@ Global
{1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|Any CPU.Build.0 = Release|Any CPU {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|Any CPU.Build.0 = Release|Any CPU
{1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|x86.ActiveCfg = Release|Any CPU {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|x86.ActiveCfg = Release|Any CPU
{1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|x86.Build.0 = Release|Any CPU {1748E038-0A47-04E1-3C5E-FF9566DFFB7C}.Release|x86.Build.0 = Release|Any CPU
{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Debug|x86.ActiveCfg = Debug|Any CPU
{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Debug|x86.Build.0 = Debug|Any CPU
{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Release|Any CPU.Build.0 = Release|Any CPU
{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Release|x86.ActiveCfg = Release|Any CPU
{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}.Release|x86.Build.0 = Release|Any CPU
{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|Any CPU.Build.0 = Debug|Any CPU {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|x86.ActiveCfg = Debug|Any CPU {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|x86.ActiveCfg = Debug|Any CPU