Nov 10, 2017 11:45 AM
(This post was last modified: Nov 10, 2017 11:47 AM by Barret.)
So i started with some side projects with plugin architecture and decided to write an entire new proper plugin model basis.
This base does all of the former projects (except remote assemblies for the time being) and makes use of jailing (sandboxed),
controlled read/write/ACL (https://msdn.microsoft.com/en-us/library...s.90).aspx),
and being able to import plugin(s) inside the domain from another plugin so they can interact with each other.
![[Image: AkOGMQp.png]](https://i.imgur.com/AkOGMQp.png)
In this demo one assembly containing the exported types (can be separate assemblies ofc), the first one tests the read/write on local folder and then on C:\
the second one attempts to import the first plugin that has a specific interface on it, and once its imported, invokes a method that is defined from
this specific interface, this is useful for plugin communications.
These interfaces don't need to be defined inside the assembly but can also be separate, the loader will load all assemblies found into the domain.
Keep in mind that interfaces work both ways of course.
Importing plugins from and to a plugin
Inside a plugin, one could import plugins with specific interfaces:
The interface used in this example
or if more then one is using that particular interface,
Setup the base
To setup and load plugins from a folder you would approach it like this
Plugin Base Structure
The IContainer is the basis for all plugins that want to be able to use the internal functions of the Loader , the base methods include:
Test to see if a plugin can read a specified filename or directory
Test to see if a plugin can write a specified filename or directory
Test to see if a plugin can do a specified action for that filename or directory
Access the parent (loader) that contains the Import/ImportAll methods and Assembly collection
Get the current base directory where the plugin resides in
Github: https://github.com/TheBarret/PluginLoader
Changes will be made along the way, for suggestions or questions post them in here.
This base does all of the former projects (except remote assemblies for the time being) and makes use of jailing (sandboxed),
controlled read/write/ACL (https://msdn.microsoft.com/en-us/library...s.90).aspx),
and being able to import plugin(s) inside the domain from another plugin so they can interact with each other.
![[Image: AkOGMQp.png]](https://i.imgur.com/AkOGMQp.png)
In this demo one assembly containing the exported types (can be separate assemblies ofc), the first one tests the read/write on local folder and then on C:\
the second one attempts to import the first plugin that has a specific interface on it, and once its imported, invokes a method that is defined from
this specific interface, this is useful for plugin communications.
These interfaces don't need to be defined inside the assembly but can also be separate, the loader will load all assemblies found into the domain.
Keep in mind that interfaces work both ways of course.
Importing plugins from and to a plugin
Inside a plugin, one could import plugins with specific interfaces:
Code
Dim plugin As CommunicationTest = Me.Parent.Import(Of CommunicationTest)()
If (plugin IsNot Nothing) Then
plugin.SayHello(Me.Name)
End IfThe interface used in this example
Code
Public Interface CommunicationTest
Sub SayHello(sender As String)
End Interfaceor if more then one is using that particular interface,
Code
For Each plug In Me.Parent.ImportAll(Of CommunicationTest)()
'...code....
NextSetup the base
To setup and load plugins from a folder you would approach it like this
Code
Dim plugins As String = Path.GetFullPath(".\Plugins\")
Using host As New Host("sandboxie", plugins)
If (host.Load) Then
Try
For Each container As Container(Of IContainer) In host.ImportAll(Of IContainer)()
Dim plugin As IContainer = container.RefObject
Console.WriteLine("+-----------------------------------------------+")
Console.WriteLine("Type: {0} {1}", plugin.Name, plugin.Version)
Console.WriteLine(String.Empty)
If (plugin.Initialize) Then
plugin.Run()
End If
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End If
End UsingPlugin Base Structure
The IContainer is the basis for all plugins that want to be able to use the internal functions of the Loader , the base methods include:
Test to see if a plugin can read a specified filename or directory
Code
Public Function CanRead(path As String) As Boolean Implements IContainer.CanReadTest to see if a plugin can write a specified filename or directory
Code
Public Function CanWrite(path As String) As Boolean Implements IContainer.CanWriteTest to see if a plugin can do a specified action for that filename or directory
Code
Public Function Access(path As String, rights As FileSystemRights) As Boolean Implements IContainer.AccessAccess the parent (loader) that contains the Import/ImportAll methods and Assembly collection
Code
Public ReadOnly Property Parent As ILoader Implements IContainer.ParentGet the current base directory where the plugin resides in
Code
Public ReadOnly Property BaseDirectory As String Implements IContainer.BaseDirectoryChanges will be made along the way, for suggestions or questions post them in here.

