Projektdateien hinzufügen.

This commit is contained in:
2019-04-02 18:47:41 +02:00
parent 2ce6f5f16d
commit ef15e45df7
138 changed files with 8675 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
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

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

View File

@@ -0,0 +1,13 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>false</MySubMain>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<ApplicationType>1</ApplicationType>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>

View File

@@ -0,0 +1,35 @@
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices
' Allgemeine Informationen über eine Assembly werden über die folgenden
' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
' die einer Assembly zugeordnet sind.
' Werte der Assemblyattribute überprüfen
<Assembly: AssemblyTitle("Pilz.Reflection.PluginSystem")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Pascal Schedel")>
<Assembly: AssemblyProduct("Pilz.Reflection.PluginSystem")>
<Assembly: AssemblyCopyright("Copyright © Pascal Schedel 2019")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>
'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
<Assembly: Guid("71d06604-a99f-4aa7-9dec-a2fe0d6b63d3")>
' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
'
' Hauptversion
' Nebenversion
' Buildnummer
' Revision
'
' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

View File

@@ -0,0 +1,62 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My.Resources
'This class was auto-generated by the StronglyTypedResourceBuilder
'class via a tool like ResGen or Visual Studio.
'To add or remove a member, edit your .ResX file then rerun ResGen
'with the /str option, or rebuild your VS project.
'''<summary>
''' A strongly-typed resource class, for looking up localized strings, etc.
'''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Friend Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Returns the cached ResourceManager instance used by this class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If Object.ReferenceEquals(resourceMan, Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Reflection.PluginSystem.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
'''<summary>
''' Overrides the current thread's CurrentUICulture property for all
''' resource lookups using this strongly typed resource class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Friend Property Culture() As Global.System.Globalization.CultureInfo
Get
Return resourceCulture
End Get
Set(ByVal value As Global.System.Globalization.CultureInfo)
resourceCulture = value
End Set
End Property
End Module
End Namespace

View File

@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,73 @@
'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings)
#Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean
Private Shared addedHandlerLockObject As New Object
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region
Public Shared ReadOnly Property [Default]() As MySettings
Get
#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property
End Class
End Namespace
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
Friend ReadOnly Property Settings() As Global.Pilz.Reflection.PluginSystem.My.MySettings
Get
Return Global.Pilz.Reflection.PluginSystem.My.MySettings.Default
End Get
End Property
End Module
End Namespace

View File

@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View File

@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F7975470-4CA3-4FAB-BB6A-A3AF3978ABB7}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Pilz.Reflection.PluginSystem</RootNamespace>
<AssemblyName>Pilz.Reflection.PluginSystem</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Windows</MyType>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>Pilz.Reflection.PluginSystem.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>Pilz.Reflection.PluginSystem.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
</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>
<ItemGroup>
<Compile Include="Attributes\FuncWithCodeMethodAttribute.vb" />
<Compile Include="Attributes\LoadMethodAttribute.vb" />
<Compile Include="Plugin.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="PluginFunction.vb" />
<Compile Include="PluginLoadException.vb" />
<Compile Include="PluginManager.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application.Designer.vb</LastGenOutput>
</None>
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<CustomToolNamespace>My</CustomToolNamespace>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>

View File

@@ -0,0 +1,118 @@
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>
''' 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)
Dim asm As Assembly = Assembly.LoadFile(filePath)
Dim modul As Type = asm.GetType(entryTypeName)
If modul 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 modul.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

@@ -0,0 +1,73 @@
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

@@ -0,0 +1,11 @@
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

@@ -0,0 +1,129 @@
Imports System.IO
Public Class PluginManager
''' <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
Return Nothing
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