From cc84215d73dfab753d57382cabac60b7281bd4ae Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Tue, 23 Jan 2024 09:16:50 +0100 Subject: [PATCH] remove legacy plugin system --- .../Attributes/FuncWithCodeMethodAttribute.vb | 19 --- .../Attributes/LoadMethodAttribute.vb | 7 - .../Pilz.Reflection.PluginSystem.vbproj | 46 ------ Pilz.Reflection.PluginSystem/Plugin.vb | 127 ---------------- .../PluginFunction.vb | 73 --------- .../PluginLoadException.vb | 11 -- Pilz.Reflection.PluginSystem/PluginManager.vb | 139 ------------------ Pilz.sln | 12 +- 8 files changed, 1 insertion(+), 433 deletions(-) delete mode 100644 Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.vb delete mode 100644 Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.vb delete mode 100644 Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.vbproj delete mode 100644 Pilz.Reflection.PluginSystem/Plugin.vb delete mode 100644 Pilz.Reflection.PluginSystem/PluginFunction.vb delete mode 100644 Pilz.Reflection.PluginSystem/PluginLoadException.vb delete mode 100644 Pilz.Reflection.PluginSystem/PluginManager.vb diff --git a/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.vb b/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.vb deleted file mode 100644 index e3b1c1e..0000000 --- a/Pilz.Reflection.PluginSystem/Attributes/FuncWithCodeMethodAttribute.vb +++ /dev/null @@ -1,19 +0,0 @@ -Namespace Attributes - - Public Class PluginFunctionAttribute - Inherits Attribute - - Public ReadOnly Property FunctionCode As String - Public ReadOnly Property Params As Object() - - ''' - ''' The function code for this PluginFunction. - ''' The parameters for this PluginFunction. - Public Sub New(funcCode As String, ParamArray params As Object()) - Me.FunctionCode = funcCode - Me.Params = params - End Sub - - End Class - -End Namespace diff --git a/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.vb b/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.vb deleted file mode 100644 index d898afc..0000000 --- a/Pilz.Reflection.PluginSystem/Attributes/LoadMethodAttribute.vb +++ /dev/null @@ -1,7 +0,0 @@ -Namespace Attributes - - Public Class LoadMethodAttribute - Inherits Attribute - End Class - -End Namespace diff --git a/Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.vbproj b/Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.vbproj deleted file mode 100644 index a750396..0000000 --- a/Pilz.Reflection.PluginSystem/Pilz.Reflection.PluginSystem.vbproj +++ /dev/null @@ -1,46 +0,0 @@ - - - netstandard2.0;net8.0 - 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - Pilz.Reflection.PluginSystem.xml - true - - - true - - - false - - - On - - - Binary - - - Off - - - On - - - True - 2.0.0 - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Pilz.Reflection.PluginSystem/Plugin.vb b/Pilz.Reflection.PluginSystem/Plugin.vb deleted file mode 100644 index 0498da7..0000000 --- a/Pilz.Reflection.PluginSystem/Plugin.vb +++ /dev/null @@ -1,127 +0,0 @@ -Imports System.IO -Imports System.Reflection -Imports Pilz.Reflection.PluginSystem.Attributes - -Public Class Plugin - - ''' - ''' 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. - ''' - ''' - Public ReadOnly Property MainFunctions As IReadOnlyList(Of PluginFunction) - ''' - ''' A collection of Methods with a FunctionCode (excluding all PluginFunctions from MainFunctions). - ''' - ''' - Public ReadOnly Property PluginFunctions As IReadOnlyList(Of PluginFunction) - ''' - ''' Gets the assembly that contains the PluginFunctions of this Plugin - ''' - ''' - Public ReadOnly Property Assembly As Assembly - ''' - ''' Gets the main module that contains the PluginFunctions of this Plugin - ''' - ''' - Public ReadOnly Property MainModule As Type - - ''' - ''' Load a new Plugin and its PluginFunctions. - ''' - ''' - ''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. - ''' The name of the type where to search for Methods when loading a new Plugin. - 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 - - ''' - ''' Get all PluginFunctions that have one of the given function codes. - ''' - ''' - ''' - 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 - - ''' - ''' Get the first PluginFunction that have the one of the given function codes. - ''' - ''' - 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 diff --git a/Pilz.Reflection.PluginSystem/PluginFunction.vb b/Pilz.Reflection.PluginSystem/PluginFunction.vb deleted file mode 100644 index 28c0b3f..0000000 --- a/Pilz.Reflection.PluginSystem/PluginFunction.vb +++ /dev/null @@ -1,73 +0,0 @@ -Imports System.Reflection - -Public Class PluginFunction - - ''' - ''' Gets the method to invoke when invoking this PluginFunction. - ''' - ''' - Public ReadOnly Property Method As MethodInfo - - ''' - ''' Gets the refered Plugin for this PluginFunction, if it has one. - ''' - ''' - Public ReadOnly Property Plugin As Plugin - - ''' - ''' Gets the Parameters that was given by the attribute. - ''' - ''' - Public ReadOnly Property Params As Object() - - ''' - ''' Gets the function code for this PluginFunction. - ''' - ''' - Public ReadOnly Property FunctionCode As String - - ''' - ''' Creates a new instance of a PluginFunction. - ''' - ''' The Method to invoke when invoking this PluginFunction. - ''' The Plugin that is the Parent of this PluginFunction. This value can be NULL. - Public Sub New(method As MethodInfo, plugin As Plugin) - Me.Method = method - Me.Plugin = plugin - End Sub - - ''' - ''' Creates a new instance of a PluginFunction. - ''' - ''' The Method to invoke when invoking this PluginFunction.. - ''' The Plugin that is the Parent of this PluginFunction. This value can be NULL. - ''' The Parameters that was given by the attribute. - ''' The function code for this PluginFunction. - 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 - - ''' - ''' Invokes the Method of the PluginFunction. - ''' - Public Sub Invoke() - Method.Invoke(Nothing, Nothing) - End Sub - - ''' - ''' Invokes the Method of the PluginFunction. - ''' - Public Sub Invoke(ParamArray params As Object()) - Method.Invoke(Nothing, params) - End Sub - - ''' - ''' Invokes the Method of the PluginFunction and returns the return value. - ''' - Public Function InvokeGet(ParamArray params As Object()) As Object - Return Method.Invoke(Nothing, params) - End Function - -End Class diff --git a/Pilz.Reflection.PluginSystem/PluginLoadException.vb b/Pilz.Reflection.PluginSystem/PluginLoadException.vb deleted file mode 100644 index fef7f10..0000000 --- a/Pilz.Reflection.PluginSystem/PluginLoadException.vb +++ /dev/null @@ -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 diff --git a/Pilz.Reflection.PluginSystem/PluginManager.vb b/Pilz.Reflection.PluginSystem/PluginManager.vb deleted file mode 100644 index 9ec8df0..0000000 --- a/Pilz.Reflection.PluginSystem/PluginManager.vb +++ /dev/null @@ -1,139 +0,0 @@ -Imports System.IO - -Public Class PluginManager - - ''' - ''' Gets or sets an indicator if an exception should throw on error while loading a plugin. - ''' - ''' - Public Property ThrowOnError As Boolean = False - - ''' - ''' The name of the type where to search for Methods when loading a new Plugin. - ''' - ''' - Public Property EntryTypeName As String = "Plugin" - - ''' - ''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. - ''' - ''' - Public Property AutoCallMainFunctions As Boolean = True - - ''' - ''' A collection of all loaded Plugins. - ''' - ''' - Public ReadOnly Property Plugins As New Dictionary(Of String, Plugin) - - ''' - ''' Loads Plugins that can be found at the given path and adds them to the Plugins-List. - ''' - ''' The path where to search for Plugins to load. - Public Function LoadPlugins(pluginPath As String) As IEnumerable(Of Plugin) - Return LoadPlugins(pluginPath, True) - End Function - - ''' - ''' Loads Plugins that can be found at the given path and adds them to the Plugins-List. - ''' - ''' The path where to search for Plugins to load. - ''' If true, the Plugins will be added to Plugins-List after loading. - Public Function LoadPlugins(pluginPath As String, addToList As Boolean) As IEnumerable(Of Plugin) - Return LoadPlugins(pluginPath, addToList, AutoCallMainFunctions, EntryTypeName) - End Function - - ''' - ''' Loads Plugins that can be found at the given path and adds them to the Plugins-List. - ''' - ''' The path where to search for Plugins to load. - ''' If true, the Plugins will be added to Plugins-List after loading. - ''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. - ''' The name of the type where to search for Methods when loading a new Plugin. - 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 - - ''' - ''' Loads a Plugin and adds it to the Plugins-List. - ''' - ''' The path to the plugin to load. - ''' If true, the Plugin will be added to Plugins-List after loading. - Public Function LoadPlugin(filePath As String, addToList As Boolean) As Plugin - Return LoadPlugin(filePath, addToList, AutoCallMainFunctions, EntryTypeName) - End Function - - ''' - ''' Loads a Plugin and adds it to the Plugins-List. - ''' - ''' The path to the plugin to load. - ''' If true, the Plugin will be added to Plugins-List after loading. - ''' If true, all MainMethods of a Plugin will be called as soon as a Plugin is loaded. - ''' The name of the type where to search for Methods when loading a new Plugin. - 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 - - ''' - ''' Loads a Plugin and adds it to the Plugins-List. - ''' - ''' The path to the plugin to load. - Public Function LoadPlugin(filePath As String) As Plugin - Return LoadPlugin(filePath, True) - End Function - - ''' - ''' Get all PluginFunctions that have one of the given function codes. - ''' - ''' - ''' - 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 - - ''' - ''' Get the first PluginFunction that have the one of the given function codes. - ''' - ''' - 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 diff --git a/Pilz.sln b/Pilz.sln index 3698438..0048474 100644 --- a/Pilz.sln +++ b/Pilz.sln @@ -19,8 +19,6 @@ Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Pilz.Win32", "Pilz.Win32\Pi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Configuration", "Pilz.Configuration\Pilz.Configuration.csproj", "{1748E038-0A47-04E1-3C5E-FF9566DFFB7C}" 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}" EndProject 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 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Plugins.Advanced", "Pilz.Plugins.Advanced\Pilz.Plugins.Advanced.csproj", "{72153EC8-B297-4A94-80AA-3574544BE8CF}" 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 Global 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|x86.ActiveCfg = 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.Build.0 = Debug|Any CPU {5E9F0B0A-F7B8-49A9-80FC-6DFE0D44CC84}.Debug|x86.ActiveCfg = Debug|Any CPU