1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
Private loader As Loader
Private pluginsDomain As AppDomain
Private PluginList As List(Of IPlugin)
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
PluginList = New List(Of IPlugin)
loader = New Loader()
LoadPlugins()
End Sub
Public Sub LoadPlugins()
Dim path As String = Application.StartupPath & "/Plugins/"
If Not Directory.Exists(Application.StartupPath & "/Plugins/") Then
Directory.CreateDirectory(Application.StartupPath & "/Plugins/")
End If
' Création du domaine d'application et chargement de la librairie de chargement
Dim setup As AppDomainSetup
setup = AppDomain.CurrentDomain.SetupInformation
setup.PrivateBinPath = path
setup.ShadowCopyFiles = "false"
Me.pluginsDomain = AppDomain.CreateDomain("pluginsDomain", Nothing, setup)
Me.loader = CType(Me.pluginsDomain.CreateInstanceFromAndUnwrap("AssemblyLoader.dll", "AssemblyLoader.Loader"), Loader)
Dim dir As DirectoryInfo = New DirectoryInfo(Path)
Dim iplugins As IPlugin
Dim i As Integer = 0
Dim file As FileInfo
Dim type As String
For Each file In dir.GetFiles("*.dll")
type = file.Name.Replace(file.Extension, "")
Me.loader.Load(type)
iplugins = CType(Me.loader.CreateInstanceOf(i, type & "." & type), IPlugin)
Me.PluginList.Add(iplugins)
Next
End Sub |
Partager