Author:水如烟
Namespace
LzmTW.uSystem.uWindows.AddIns
Friend Delegate Sub ManagerActionHandler( ByVal assemblyFilesOrAddInsNames As String ())
End Namespace
Friend Delegate Sub ManagerActionHandler( ByVal assemblyFilesOrAddInsNames As String ())
End Namespace
Namespace
LzmTW.uSystem.uWindows.AddIns
' '' <summary>
' '' 本类实例须在主窗体调用 InitializeComponent后生成。为的是利用主窗体的Load事件安装有关插件。
' '' </summary>
Public Class AddInsManager
Private WithEvents gMainForm As Form
' 菜单控制
Private gMenuManager As New uForms.uMainForm.Menu.MenuManager
' 配置文件
Private gConfigManager As New AddInsConfig
' 当前已加载的插件
Private gPackages As New Dictionary( Of String , IPackage)
Private gAddInsForm As AddInsForm
Sub New ( ByVal mainForm As Form)
Me .gMainForm = mainForm
gMenuManager.SetMainFormMenuStrip(gMainForm)
End Sub
Private Sub ItemLoad( ByVal item As AddInsItem)
If item.IsLoad Then Return
Dim mAttribute As AddInsAttribute = AddInsAssemblyReader.Read(item.Location, item.Name)
Dim mAssembly As Reflection.Assembly = Reflection.Assembly.LoadFile(item.Location)
Dim mPackage As LzmTW.uSystem.uWindows.AddIns.IPackage = Nothing
mPackage = CType (mAssembly.CreateInstance(mAttribute.FullTypeName), LzmTW.uSystem.uWindows.AddIns.IPackage)
mPackage.Load(gMainForm)
gPackages.Add(item.Name, mPackage)
item.IsLoad = True
If gConfigManager.FindItem(item.Name) Is Nothing Then
gConfigManager.Add(item)
gConfigManager.Save()
End If
End Sub
Private Sub ItemUnLoad( ByVal item As AddInsItem)
If gPackages.ContainsKey(item.Name) Then
gPackages(item.Name).Unload()
gPackages.Remove(item.Name)
gConfigManager.FindItem(item.Name).IsLoad = False
gConfigManager.Save()
End If
End Sub
Private Sub ItemReLoad( ByVal item As AddInsItem)
ItemUnLoad(item)
ItemLoad(item)
End Sub
Private Sub ItemRemove( ByVal item As AddInsItem)
If gPackages.ContainsKey(item.Name) Then
gPackages(item.Name).Unload()
gPackages.Remove(item.Name)
End If
gConfigManager.Remove(item)
gConfigManager.Save()
End Sub
Private Sub gMainForm_Load( ByVal sender As Object , ByVal e As System.EventArgs) Handles gMainForm.Load
With gMenuManager
If .FindToolStripItem( " Tools " ) Is Nothing Then
.AddParentToolStripMenuItem(uForms.uMainForm.Menu.MenuManager.GetDefaultMenuItem( " Tools " ))
End If
If .FindToolStripItem( " AddIns " ) Is Nothing Then
.AddToolStripMenuItem( " Tools " , uForms.uMainForm.Menu.MenuManager.GetDefaultMenuItem( " AddIns " ))
End If
gMenuManager.AddClickHandler( " AddIns " , AddressOf OnAddInsToolStripMenuItemClick)
End With
If Not IO.File.Exists( Me .gConfigManager.FileName) Then
Me .gConfigManager.Save()
Else
Me .gConfigManager.Read()
Dim mItem As AddInsItem = Nothing
For i As Integer = Me .gConfigManager.Count - 1 To 0 Step - 1
mItem = Me .gConfigManager.Item(i)
mItem.IsLoad = False
Try
Me .ItemLoad(mItem)
Catch ex As Exception
Me .gConfigManager.Remove(mItem)
Me .gConfigManager.Save()
End Try
Next
End If
End Sub
Private Sub OnAddInsToolStripMenuItemClick( ByVal sender As Object , ByVal e As EventArgs)
gAddInsForm = New AddInsForm
Using gAddInsForm
gAddInsForm.ShowDialog(gMainForm, AddressOf OnWaitingForAdd, AddressOf OnWaitingForRemove, AddressOf OnWaitingForReLoad)
End Using
End Sub
Private Sub OnWaitingForAdd( ByVal files As String ())
Dim mHasValidItems As Boolean = False
Dim mNotValidFiles( - 1 ) As String
For Each file As String In files
Dim mInformation As AddInsAttribute() = AddInsAssemblyReader.Read(file)
If mInformation.Length = 0 Then ' 不是插件
uCollection.CommonFunction.Append( Of String )(mNotValidFiles, file)
Else
For Each a As AddInsAttribute In mInformation
If Me .gPackages.ContainsKey(a.Name) Then ' 已安装
uCollection.CommonFunction.Append( Of String )(mNotValidFiles, String .Format( " [{0}] " , a.Name) & file)
Else
Dim mItem As New AddInsItem(a.Name, file)
Try
Me .ItemLoad(mItem)
Me .gAddInsForm.Add(mItem)
Catch ex As Exception
uCollection.CommonFunction.Append( Of String )(mNotValidFiles, String .Format( " [{0}] " , a.Name) & file)
End Try
End If
Next
End If
Next
If mNotValidFiles.Length > 0 Then
gAddInsForm.ShowInValidForm(mNotValidFiles)
End If
End Sub
Private Sub OnWaitingForRemove( ByVal names As String ())
For Each itemName As String In names
Me .ItemRemove( Me .gConfigManager.FindItem(itemName))
Next
End Sub
Private Sub OnWaitingForReLoad( ByVal names As String ())
For Each itemName As String In names
Me .ItemReLoad( Me .gConfigManager.FindItem(itemName))
Next
End Sub
End Class
End Namespace
' '' <summary>
' '' 本类实例须在主窗体调用 InitializeComponent后生成。为的是利用主窗体的Load事件安装有关插件。
' '' </summary>
Public Class AddInsManager
Private WithEvents gMainForm As Form
' 菜单控制
Private gMenuManager As New uForms.uMainForm.Menu.MenuManager
' 配置文件
Private gConfigManager As New AddInsConfig
' 当前已加载的插件
Private gPackages As New Dictionary( Of String , IPackage)
Private gAddInsForm As AddInsForm
Sub New ( ByVal mainForm As Form)
Me .gMainForm = mainForm
gMenuManager.SetMainFormMenuStrip(gMainForm)
End Sub
Private Sub ItemLoad( ByVal item As AddInsItem)
If item.IsLoad Then Return
Dim mAttribute As AddInsAttribute = AddInsAssemblyReader.Read(item.Location, item.Name)
Dim mAssembly As Reflection.Assembly = Reflection.Assembly.LoadFile(item.Location)
Dim mPackage As LzmTW.uSystem.uWindows.AddIns.IPackage = Nothing
mPackage = CType (mAssembly.CreateInstance(mAttribute.FullTypeName), LzmTW.uSystem.uWindows.AddIns.IPackage)
mPackage.Load(gMainForm)
gPackages.Add(item.Name, mPackage)
item.IsLoad = True
If gConfigManager.FindItem(item.Name) Is Nothing Then
gConfigManager.Add(item)
gConfigManager.Save()
End If
End Sub
Private Sub ItemUnLoad( ByVal item As AddInsItem)
If gPackages.ContainsKey(item.Name) Then
gPackages(item.Name).Unload()
gPackages.Remove(item.Name)
gConfigManager.FindItem(item.Name).IsLoad = False
gConfigManager.Save()
End If
End Sub
Private Sub ItemReLoad( ByVal item As AddInsItem)
ItemUnLoad(item)
ItemLoad(item)
End Sub
Private Sub ItemRemove( ByVal item As AddInsItem)
If gPackages.ContainsKey(item.Name) Then
gPackages(item.Name).Unload()
gPackages.Remove(item.Name)
End If
gConfigManager.Remove(item)
gConfigManager.Save()
End Sub
Private Sub gMainForm_Load( ByVal sender As Object , ByVal e As System.EventArgs) Handles gMainForm.Load
With gMenuManager
If .FindToolStripItem( " Tools " ) Is Nothing Then
.AddParentToolStripMenuItem(uForms.uMainForm.Menu.MenuManager.GetDefaultMenuItem( " Tools " ))
End If
If .FindToolStripItem( " AddIns " ) Is Nothing Then
.AddToolStripMenuItem( " Tools " , uForms.uMainForm.Menu.MenuManager.GetDefaultMenuItem( " AddIns " ))
End If
gMenuManager.AddClickHandler( " AddIns " , AddressOf OnAddInsToolStripMenuItemClick)
End With
If Not IO.File.Exists( Me .gConfigManager.FileName) Then
Me .gConfigManager.Save()
Else
Me .gConfigManager.Read()
Dim mItem As AddInsItem = Nothing
For i As Integer = Me .gConfigManager.Count - 1 To 0 Step - 1
mItem = Me .gConfigManager.Item(i)
mItem.IsLoad = False
Try
Me .ItemLoad(mItem)
Catch ex As Exception
Me .gConfigManager.Remove(mItem)
Me .gConfigManager.Save()
End Try
Next
End If
End Sub
Private Sub OnAddInsToolStripMenuItemClick( ByVal sender As Object , ByVal e As EventArgs)
gAddInsForm = New AddInsForm
Using gAddInsForm
gAddInsForm.ShowDialog(gMainForm, AddressOf OnWaitingForAdd, AddressOf OnWaitingForRemove, AddressOf OnWaitingForReLoad)
End Using
End Sub
Private Sub OnWaitingForAdd( ByVal files As String ())
Dim mHasValidItems As Boolean = False
Dim mNotValidFiles( - 1 ) As String
For Each file As String In files
Dim mInformation As AddInsAttribute() = AddInsAssemblyReader.Read(file)
If mInformation.Length = 0 Then ' 不是插件
uCollection.CommonFunction.Append( Of String )(mNotValidFiles, file)
Else
For Each a As AddInsAttribute In mInformation
If Me .gPackages.ContainsKey(a.Name) Then ' 已安装
uCollection.CommonFunction.Append( Of String )(mNotValidFiles, String .Format( " [{0}] " , a.Name) & file)
Else
Dim mItem As New AddInsItem(a.Name, file)
Try
Me .ItemLoad(mItem)
Me .gAddInsForm.Add(mItem)
Catch ex As Exception
uCollection.CommonFunction.Append( Of String )(mNotValidFiles, String .Format( " [{0}] " , a.Name) & file)
End Try
End If
Next
End If
Next
If mNotValidFiles.Length > 0 Then
gAddInsForm.ShowInValidForm(mNotValidFiles)
End If
End Sub
Private Sub OnWaitingForRemove( ByVal names As String ())
For Each itemName As String In names
Me .ItemRemove( Me .gConfigManager.FindItem(itemName))
Next
End Sub
Private Sub OnWaitingForReLoad( ByVal names As String ())
For Each itemName As String In names
Me .ItemReLoad( Me .gConfigManager.FindItem(itemName))
Next
End Sub
End Class
End Namespace
Namespace
LzmTW.uSystem.uWindows.AddIns
Friend Class InValidAddInsForm
End Class
End Namespace
Friend Class InValidAddInsForm
End Class
End Namespace
Namespace
LzmTW.uSystem.uWindows.AddIns
< Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated() > _
Partial Class InValidAddInsForm
Inherits System.Windows.Forms.Form
' Form overrides dispose to clean up the component list.
< System.Diagnostics.DebuggerNonUserCode() > _
Protected Overrides Sub Dispose( ByVal disposing As Boolean )
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase .Dispose(disposing)
End Sub
' Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Windows Form Designer
' It can be modified using the Windows Form Designer.
' Do not modify it using the code editor.
< System.Diagnostics.DebuggerStepThrough() > _
Private Sub InitializeComponent()
Me .ListView = New System.Windows.Forms.ListView
Me .LocationColumnHeader = New System.Windows.Forms.ColumnHeader
Me .CloseButton = New System.Windows.Forms.Button
Me .Label1 = New System.Windows.Forms.Label
Me .SuspendLayout()
'
' ListView
'
Me .ListView.Anchor = CType ((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .ListView.Columns.AddRange( New System.Windows.Forms.ColumnHeader() { Me .LocationColumnHeader})
Me .ListView.Location = New System.Drawing.Point( 16 , 29 )
Me .ListView.Name = " ListView "
Me .ListView.Size = New System.Drawing.Size( 411 , 191 )
Me .ListView.TabIndex = 0
Me .ListView.UseCompatibleStateImageBehavior = False
Me .ListView.View = System.Windows.Forms.View.Details
'
' LocationColumnHeader
'
Me .LocationColumnHeader.Text = " 来源 "
Me .LocationColumnHeader.Width = 700
'
' CloseButton
'
Me .CloseButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .CloseButton.DialogResult = System.Windows.Forms.DialogResult.OK
Me .CloseButton.Location = New System.Drawing.Point( 351 , 234 )
Me .CloseButton.Name = " CloseButton "
Me .CloseButton.Size = New System.Drawing.Size( 76 , 27 )
Me .CloseButton.TabIndex = 1
Me .CloseButton.Text = " 返回(&C) "
Me .CloseButton.UseVisualStyleBackColor = True
'
' Label1
'
Me .Label1.AutoSize = True
Me .Label1.Location = New System.Drawing.Point( 19 , 5 )
Me .Label1.Name = " Label1 "
Me .Label1.Size = New System.Drawing.Size( 107 , 12 )
Me .Label1.TabIndex = 4
Me .Label1.Text = " 无法安装下列插件: "
'
' InValidAddInsForm
'
Me .AcceptButton = Me .CloseButton
Me .AutoScaleDimensions = New System.Drawing.SizeF( 6.0 !, 12.0 !)
Me .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me .CancelButton = Me .CloseButton
Me .ClientSize = New System.Drawing.Size( 439 , 273 )
Me .Controls.Add( Me .Label1)
Me .Controls.Add( Me .CloseButton)
Me .Controls.Add( Me .ListView)
Me .FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me .Name = " InValidAddInsForm "
Me .ShowInTaskbar = False
Me .StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me .Text = " 插件管理 "
Me .ResumeLayout( False )
Me .PerformLayout()
End Sub
Friend WithEvents ListView As System.Windows.Forms.ListView
Friend WithEvents LocationColumnHeader As System.Windows.Forms.ColumnHeader
Friend WithEvents CloseButton As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
End Class
End Namespace
< Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated() > _
Partial Class InValidAddInsForm
Inherits System.Windows.Forms.Form
' Form overrides dispose to clean up the component list.
< System.Diagnostics.DebuggerNonUserCode() > _
Protected Overrides Sub Dispose( ByVal disposing As Boolean )
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase .Dispose(disposing)
End Sub
' Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Windows Form Designer
' It can be modified using the Windows Form Designer.
' Do not modify it using the code editor.
< System.Diagnostics.DebuggerStepThrough() > _
Private Sub InitializeComponent()
Me .ListView = New System.Windows.Forms.ListView
Me .LocationColumnHeader = New System.Windows.Forms.ColumnHeader
Me .CloseButton = New System.Windows.Forms.Button
Me .Label1 = New System.Windows.Forms.Label
Me .SuspendLayout()
'
' ListView
'
Me .ListView.Anchor = CType ((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .ListView.Columns.AddRange( New System.Windows.Forms.ColumnHeader() { Me .LocationColumnHeader})
Me .ListView.Location = New System.Drawing.Point( 16 , 29 )
Me .ListView.Name = " ListView "
Me .ListView.Size = New System.Drawing.Size( 411 , 191 )
Me .ListView.TabIndex = 0
Me .ListView.UseCompatibleStateImageBehavior = False
Me .ListView.View = System.Windows.Forms.View.Details
'
' LocationColumnHeader
'
Me .LocationColumnHeader.Text = " 来源 "
Me .LocationColumnHeader.Width = 700
'
' CloseButton
'
Me .CloseButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .CloseButton.DialogResult = System.Windows.Forms.DialogResult.OK
Me .CloseButton.Location = New System.Drawing.Point( 351 , 234 )
Me .CloseButton.Name = " CloseButton "
Me .CloseButton.Size = New System.Drawing.Size( 76 , 27 )
Me .CloseButton.TabIndex = 1
Me .CloseButton.Text = " 返回(&C) "
Me .CloseButton.UseVisualStyleBackColor = True
'
' Label1
'
Me .Label1.AutoSize = True
Me .Label1.Location = New System.Drawing.Point( 19 , 5 )
Me .Label1.Name = " Label1 "
Me .Label1.Size = New System.Drawing.Size( 107 , 12 )
Me .Label1.TabIndex = 4
Me .Label1.Text = " 无法安装下列插件: "
'
' InValidAddInsForm
'
Me .AcceptButton = Me .CloseButton
Me .AutoScaleDimensions = New System.Drawing.SizeF( 6.0 !, 12.0 !)
Me .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me .CancelButton = Me .CloseButton
Me .ClientSize = New System.Drawing.Size( 439 , 273 )
Me .Controls.Add( Me .Label1)
Me .Controls.Add( Me .CloseButton)
Me .Controls.Add( Me .ListView)
Me .FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me .Name = " InValidAddInsForm "
Me .ShowInTaskbar = False
Me .StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me .Text = " 插件管理 "
Me .ResumeLayout( False )
Me .PerformLayout()
End Sub
Friend WithEvents ListView As System.Windows.Forms.ListView
Friend WithEvents LocationColumnHeader As System.Windows.Forms.ColumnHeader
Friend WithEvents CloseButton As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
End Class
End Namespace
Imports
System.Windows.Forms
Namespace LzmTW.uSystem.uWindows.AddIns
Friend Class AddInsForm
Public Event WaitingForAdd As ManagerActionHandler
Public Event WaitingForRemove As ManagerActionHandler
Public Event WaitingForReLoad As ManagerActionHandler
Public Shadows Sub ShowDialog( ByVal parent As Form, ByVal forAddAction As ManagerActionHandler, ByVal forRemoveAction As ManagerActionHandler, ByVal forReloadAction As ManagerActionHandler)
With Me
AddHandler .WaitingForAdd, forAddAction
AddHandler .WaitingForRemove, forRemoveAction
AddHandler .WaitingForReLoad, forReloadAction
MyBase .ShowDialog(parent)
RemoveHandler .WaitingForAdd, forAddAction
RemoveHandler .WaitingForRemove, forRemoveAction
RemoveHandler .WaitingForReLoad, forReloadAction
End With
End Sub
Public Sub Add( ByVal item As AddInsItem)
With item
Me .ListView.Items.Add( New ListViewItem( New String () {.Name, .IsLoad.ToString, .Location}))
End With
End Sub
Public Sub ShowInValidForm( ByVal inValidfiles As String ())
Using mInValidAddinsForm As New InValidAddInsForm
With mInValidAddinsForm
For Each file As String In inValidfiles
.ListView.Items.Add(file)
Next
.ShowDialog( Me )
End With
End Using
End Sub
Private Sub ShowAddinsDeclareInformation( ByVal isOneSelected As Boolean )
If isOneSelected Then
Dim mName As String = Me .ListView.SelectedItems( 0 ).Text
Dim mLocation As String = Me .ListView.SelectedItems( 0 ).SubItems( 2 ).Text
Me .InfoTextBox.Text = AddInsAssemblyReader.Read(mLocation, mName).ToString
Else
Me .InfoTextBox.Text = ""
End If
End Sub
Private Sub AddInsForm_Load( ByVal sender As Object , ByVal e As System.EventArgs) Handles Me .Load
Dim Items As New AddInsConfig
Items.Read()
Items.ForEach( AddressOf AddItem)
End Sub
Private Sub AddItem( ByVal item As AddInsItem)
Add(item)
End Sub
End Class
End Namespace
Namespace LzmTW.uSystem.uWindows.AddIns
Friend Class AddInsForm
Public Event WaitingForAdd As ManagerActionHandler
Public Event WaitingForRemove As ManagerActionHandler
Public Event WaitingForReLoad As ManagerActionHandler
Public Shadows Sub ShowDialog( ByVal parent As Form, ByVal forAddAction As ManagerActionHandler, ByVal forRemoveAction As ManagerActionHandler, ByVal forReloadAction As ManagerActionHandler)
With Me
AddHandler .WaitingForAdd, forAddAction
AddHandler .WaitingForRemove, forRemoveAction
AddHandler .WaitingForReLoad, forReloadAction
MyBase .ShowDialog(parent)
RemoveHandler .WaitingForAdd, forAddAction
RemoveHandler .WaitingForRemove, forRemoveAction
RemoveHandler .WaitingForReLoad, forReloadAction
End With
End Sub
Public Sub Add( ByVal item As AddInsItem)
With item
Me .ListView.Items.Add( New ListViewItem( New String () {.Name, .IsLoad.ToString, .Location}))
End With
End Sub
Public Sub ShowInValidForm( ByVal inValidfiles As String ())
Using mInValidAddinsForm As New InValidAddInsForm
With mInValidAddinsForm
For Each file As String In inValidfiles
.ListView.Items.Add(file)
Next
.ShowDialog( Me )
End With
End Using
End Sub
Private Sub ShowAddinsDeclareInformation( ByVal isOneSelected As Boolean )
If isOneSelected Then
Dim mName As String = Me .ListView.SelectedItems( 0 ).Text
Dim mLocation As String = Me .ListView.SelectedItems( 0 ).SubItems( 2 ).Text
Me .InfoTextBox.Text = AddInsAssemblyReader.Read(mLocation, mName).ToString
Else
Me .InfoTextBox.Text = ""
End If
End Sub
Private Sub AddInsForm_Load( ByVal sender As Object , ByVal e As System.EventArgs) Handles Me .Load
Dim Items As New AddInsConfig
Items.Read()
Items.ForEach( AddressOf AddItem)
End Sub
Private Sub AddItem( ByVal item As AddInsItem)
Add(item)
End Sub
End Class
End Namespace
Imports
System.Windows.Forms
Namespace LzmTW.uSystem.uWindows.AddIns
Partial Class AddInsForm
Private Sub AddButton_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
Dim mAssemblyFiles( - 1 ) As String
Using fd As New OpenFileDialog
With fd
.Title = " 添加插件 "
.Multiselect = True
.Filter = " Assembly文件(*.exe,*.dll)|*.dll;*.exe|所有文件|*.* "
If .ShowDialog = Windows.Forms.DialogResult.OK Then
mAssemblyFiles = .FileNames
End If
End With
End Using
If mAssemblyFiles.Length > 0 Then
RaiseEvent WaitingForAdd(mAssemblyFiles)
End If
End Sub
Private Sub RemoveButton_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveButton.Click
Dim mLength As Integer = ListView.SelectedItems.Count
If mLength = 0 Then Return
Dim mToRemoveAddInsNames(mLength - 1 ) As String
For i As Integer = mLength - 1 To 0 Step - 1
mToRemoveAddInsNames(i) = Me .ListView.SelectedItems(i).Text
Me .ListView.SelectedItems(i).Remove()
Next
RaiseEvent WaitingForRemove(mToRemoveAddInsNames)
End Sub
Private Sub ReloadButton_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReloadButton.Click
Dim mLength As Integer = ListView.SelectedItems.Count
If mLength = 0 Then Return
Dim mToReloadAddInsNames(mLength - 1 ) As String
For i As Integer = 0 To mLength - 1
mToReloadAddInsNames(i) = Me .ListView.SelectedItems(i).Text
Next
RaiseEvent WaitingForReLoad(mToReloadAddInsNames)
End Sub
Private Sub ListView_SelectedIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView.SelectedIndexChanged
Me .ReloadButton.Enabled = ( Me .ListView.SelectedItems.Count > 0 )
Me .RemoveButton.Enabled = ( Me .ListView.SelectedItems.Count > 0 )
ShowAddinsDeclareInformation( Me .ListView.SelectedItems.Count = 1 )
End Sub
End Class
End Namespace
Namespace LzmTW.uSystem.uWindows.AddIns
Partial Class AddInsForm
Private Sub AddButton_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
Dim mAssemblyFiles( - 1 ) As String
Using fd As New OpenFileDialog
With fd
.Title = " 添加插件 "
.Multiselect = True
.Filter = " Assembly文件(*.exe,*.dll)|*.dll;*.exe|所有文件|*.* "
If .ShowDialog = Windows.Forms.DialogResult.OK Then
mAssemblyFiles = .FileNames
End If
End With
End Using
If mAssemblyFiles.Length > 0 Then
RaiseEvent WaitingForAdd(mAssemblyFiles)
End If
End Sub
Private Sub RemoveButton_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveButton.Click
Dim mLength As Integer = ListView.SelectedItems.Count
If mLength = 0 Then Return
Dim mToRemoveAddInsNames(mLength - 1 ) As String
For i As Integer = mLength - 1 To 0 Step - 1
mToRemoveAddInsNames(i) = Me .ListView.SelectedItems(i).Text
Me .ListView.SelectedItems(i).Remove()
Next
RaiseEvent WaitingForRemove(mToRemoveAddInsNames)
End Sub
Private Sub ReloadButton_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReloadButton.Click
Dim mLength As Integer = ListView.SelectedItems.Count
If mLength = 0 Then Return
Dim mToReloadAddInsNames(mLength - 1 ) As String
For i As Integer = 0 To mLength - 1
mToReloadAddInsNames(i) = Me .ListView.SelectedItems(i).Text
Next
RaiseEvent WaitingForReLoad(mToReloadAddInsNames)
End Sub
Private Sub ListView_SelectedIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView.SelectedIndexChanged
Me .ReloadButton.Enabled = ( Me .ListView.SelectedItems.Count > 0 )
Me .RemoveButton.Enabled = ( Me .ListView.SelectedItems.Count > 0 )
ShowAddinsDeclareInformation( Me .ListView.SelectedItems.Count = 1 )
End Sub
End Class
End Namespace
Namespace
LzmTW.uSystem.uWindows.AddIns
< Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated() > _
Partial Class AddInsForm
Inherits System.Windows.Forms.Form
' Form overrides dispose to clean up the component list.
< System.Diagnostics.DebuggerNonUserCode() > _
Protected Overrides Sub Dispose( ByVal disposing As Boolean )
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase .Dispose(disposing)
End Sub
' Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Windows Form Designer
' It can be modified using the Windows Form Designer.
' Do not modify it using the code editor.
< System.Diagnostics.DebuggerStepThrough() > _
Private Sub InitializeComponent()
Me .ListView = New System.Windows.Forms.ListView
Me .NameColumnHeader = New System.Windows.Forms.ColumnHeader
Me .IsLoadColumnHeader = New System.Windows.Forms.ColumnHeader
Me .LocationColumnHeader = New System.Windows.Forms.ColumnHeader
Me .CloseButton = New System.Windows.Forms.Button
Me .AddButton = New System.Windows.Forms.Button
Me .RemoveButton = New System.Windows.Forms.Button
Me .Label1 = New System.Windows.Forms.Label
Me .Label2 = New System.Windows.Forms.Label
Me .ReloadButton = New System.Windows.Forms.Button
Me .InfoTextBox = New System.Windows.Forms.TextBox
Me .SuspendLayout()
'
' ListView
'
Me .ListView.Anchor = CType ((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .ListView.Columns.AddRange( New System.Windows.Forms.ColumnHeader() { Me .NameColumnHeader, Me .IsLoadColumnHeader, Me .LocationColumnHeader})
Me .ListView.FullRowSelect = True
Me .ListView.Location = New System.Drawing.Point( 16 , 29 )
Me .ListView.Name = " ListView "
Me .ListView.Size = New System.Drawing.Size( 338 , 144 )
Me .ListView.TabIndex = 0
Me .ListView.UseCompatibleStateImageBehavior = False
Me .ListView.View = System.Windows.Forms.View.Details
'
' NameColumnHeader
'
Me .NameColumnHeader.Text = " 名称 "
Me .NameColumnHeader.Width = 150
'
' IsLoadColumnHeader
'
Me .IsLoadColumnHeader.Text = " 已加载 "
Me .IsLoadColumnHeader.Width = 52
'
' LocationColumnHeader
'
Me .LocationColumnHeader.Text = " 来源 "
Me .LocationColumnHeader.Width = 700
'
' CloseButton
'
Me .CloseButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .CloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me .CloseButton.Location = New System.Drawing.Point( 360 , 146 )
Me .CloseButton.Name = " CloseButton "
Me .CloseButton.Size = New System.Drawing.Size( 76 , 27 )
Me .CloseButton.TabIndex = 1
Me .CloseButton.Text = " 关闭(&C) "
Me .CloseButton.UseVisualStyleBackColor = True
'
' AddButton
'
Me .AddButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .AddButton.Location = New System.Drawing.Point( 360 , 29 )
Me .AddButton.Name = " AddButton "
Me .AddButton.Size = New System.Drawing.Size( 76 , 27 )
Me .AddButton.TabIndex = 2
Me .AddButton.Text = " 添加(&A)... "
Me .AddButton.UseVisualStyleBackColor = True
'
' RemoveButton
'
Me .RemoveButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .RemoveButton.Enabled = False
Me .RemoveButton.Location = New System.Drawing.Point( 360 , 62 )
Me .RemoveButton.Name = " RemoveButton "
Me .RemoveButton.Size = New System.Drawing.Size( 76 , 27 )
Me .RemoveButton.TabIndex = 3
Me .RemoveButton.Text = " 移除(&M) "
Me .RemoveButton.UseVisualStyleBackColor = True
'
' Label1
'
Me .Label1.AutoSize = True
Me .Label1.Location = New System.Drawing.Point( 19 , 5 )
Me .Label1.Name = " Label1 "
Me .Label1.Size = New System.Drawing.Size( 59 , 12 )
Me .Label1.TabIndex = 4
Me .Label1.Text = " 当前插件: "
'
' Label2
'
Me .Label2.AutoSize = True
Me .Label2.Location = New System.Drawing.Point( 21 , 182 )
Me .Label2.Name = " Label2 "
Me .Label2.Size = New System.Drawing.Size( 35 , 12 )
Me .Label2.TabIndex = 6
Me .Label2.Text = " 描述: "
'
' ReloadButton
'
Me .ReloadButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .ReloadButton.Enabled = False
Me .ReloadButton.Location = New System.Drawing.Point( 360 , 95 )
Me .ReloadButton.Name = " ReloadButton "
Me .ReloadButton.Size = New System.Drawing.Size( 76 , 27 )
Me .ReloadButton.TabIndex = 7
Me .ReloadButton.Text = " 重载(&R) "
Me .ReloadButton.UseVisualStyleBackColor = True
'
' InfoTextBox
'
Me .InfoTextBox.Location = New System.Drawing.Point( 20 , 202 )
Me .InfoTextBox.Multiline = True
Me .InfoTextBox.Name = " InfoTextBox "
Me .InfoTextBox.ReadOnly = True
Me .InfoTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me .InfoTextBox.Size = New System.Drawing.Size( 416 , 59 )
Me .InfoTextBox.TabIndex = 8
'
' AddInsForm
'
Me .AcceptButton = Me .CloseButton
Me .AutoScaleDimensions = New System.Drawing.SizeF( 6.0 !, 12.0 !)
Me .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me .CancelButton = Me .CloseButton
Me .ClientSize = New System.Drawing.Size( 439 , 273 )
Me .Controls.Add( Me .InfoTextBox)
Me .Controls.Add( Me .ReloadButton)
Me .Controls.Add( Me .Label2)
Me .Controls.Add( Me .Label1)
Me .Controls.Add( Me .RemoveButton)
Me .Controls.Add( Me .AddButton)
Me .Controls.Add( Me .CloseButton)
Me .Controls.Add( Me .ListView)
Me .FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me .Name = " AddInsForm "
Me .ShowInTaskbar = False
Me .StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me .Text = " 插件管理 "
Me .ResumeLayout( False )
Me .PerformLayout()
End Sub
Friend WithEvents ListView As System.Windows.Forms.ListView
Friend WithEvents NameColumnHeader As System.Windows.Forms.ColumnHeader
Friend WithEvents LocationColumnHeader As System.Windows.Forms.ColumnHeader
Friend WithEvents CloseButton As System.Windows.Forms.Button
Friend WithEvents AddButton As System.Windows.Forms.Button
Friend WithEvents RemoveButton As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents IsLoadColumnHeader As System.Windows.Forms.ColumnHeader
Friend WithEvents ReloadButton As System.Windows.Forms.Button
Friend WithEvents InfoTextBox As System.Windows.Forms.TextBox
End Class
End Namespace
< Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated() > _
Partial Class AddInsForm
Inherits System.Windows.Forms.Form
' Form overrides dispose to clean up the component list.
< System.Diagnostics.DebuggerNonUserCode() > _
Protected Overrides Sub Dispose( ByVal disposing As Boolean )
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase .Dispose(disposing)
End Sub
' Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Windows Form Designer
' It can be modified using the Windows Form Designer.
' Do not modify it using the code editor.
< System.Diagnostics.DebuggerStepThrough() > _
Private Sub InitializeComponent()
Me .ListView = New System.Windows.Forms.ListView
Me .NameColumnHeader = New System.Windows.Forms.ColumnHeader
Me .IsLoadColumnHeader = New System.Windows.Forms.ColumnHeader
Me .LocationColumnHeader = New System.Windows.Forms.ColumnHeader
Me .CloseButton = New System.Windows.Forms.Button
Me .AddButton = New System.Windows.Forms.Button
Me .RemoveButton = New System.Windows.Forms.Button
Me .Label1 = New System.Windows.Forms.Label
Me .Label2 = New System.Windows.Forms.Label
Me .ReloadButton = New System.Windows.Forms.Button
Me .InfoTextBox = New System.Windows.Forms.TextBox
Me .SuspendLayout()
'
' ListView
'
Me .ListView.Anchor = CType ((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .ListView.Columns.AddRange( New System.Windows.Forms.ColumnHeader() { Me .NameColumnHeader, Me .IsLoadColumnHeader, Me .LocationColumnHeader})
Me .ListView.FullRowSelect = True
Me .ListView.Location = New System.Drawing.Point( 16 , 29 )
Me .ListView.Name = " ListView "
Me .ListView.Size = New System.Drawing.Size( 338 , 144 )
Me .ListView.TabIndex = 0
Me .ListView.UseCompatibleStateImageBehavior = False
Me .ListView.View = System.Windows.Forms.View.Details
'
' NameColumnHeader
'
Me .NameColumnHeader.Text = " 名称 "
Me .NameColumnHeader.Width = 150
'
' IsLoadColumnHeader
'
Me .IsLoadColumnHeader.Text = " 已加载 "
Me .IsLoadColumnHeader.Width = 52
'
' LocationColumnHeader
'
Me .LocationColumnHeader.Text = " 来源 "
Me .LocationColumnHeader.Width = 700
'
' CloseButton
'
Me .CloseButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .CloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me .CloseButton.Location = New System.Drawing.Point( 360 , 146 )
Me .CloseButton.Name = " CloseButton "
Me .CloseButton.Size = New System.Drawing.Size( 76 , 27 )
Me .CloseButton.TabIndex = 1
Me .CloseButton.Text = " 关闭(&C) "
Me .CloseButton.UseVisualStyleBackColor = True
'
' AddButton
'
Me .AddButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .AddButton.Location = New System.Drawing.Point( 360 , 29 )
Me .AddButton.Name = " AddButton "
Me .AddButton.Size = New System.Drawing.Size( 76 , 27 )
Me .AddButton.TabIndex = 2
Me .AddButton.Text = " 添加(&A)... "
Me .AddButton.UseVisualStyleBackColor = True
'
' RemoveButton
'
Me .RemoveButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .RemoveButton.Enabled = False
Me .RemoveButton.Location = New System.Drawing.Point( 360 , 62 )
Me .RemoveButton.Name = " RemoveButton "
Me .RemoveButton.Size = New System.Drawing.Size( 76 , 27 )
Me .RemoveButton.TabIndex = 3
Me .RemoveButton.Text = " 移除(&M) "
Me .RemoveButton.UseVisualStyleBackColor = True
'
' Label1
'
Me .Label1.AutoSize = True
Me .Label1.Location = New System.Drawing.Point( 19 , 5 )
Me .Label1.Name = " Label1 "
Me .Label1.Size = New System.Drawing.Size( 59 , 12 )
Me .Label1.TabIndex = 4
Me .Label1.Text = " 当前插件: "
'
' Label2
'
Me .Label2.AutoSize = True
Me .Label2.Location = New System.Drawing.Point( 21 , 182 )
Me .Label2.Name = " Label2 "
Me .Label2.Size = New System.Drawing.Size( 35 , 12 )
Me .Label2.TabIndex = 6
Me .Label2.Text = " 描述: "
'
' ReloadButton
'
Me .ReloadButton.Anchor = CType ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me .ReloadButton.Enabled = False
Me .ReloadButton.Location = New System.Drawing.Point( 360 , 95 )
Me .ReloadButton.Name = " ReloadButton "
Me .ReloadButton.Size = New System.Drawing.Size( 76 , 27 )
Me .ReloadButton.TabIndex = 7
Me .ReloadButton.Text = " 重载(&R) "
Me .ReloadButton.UseVisualStyleBackColor = True
'
' InfoTextBox
'
Me .InfoTextBox.Location = New System.Drawing.Point( 20 , 202 )
Me .InfoTextBox.Multiline = True
Me .InfoTextBox.Name = " InfoTextBox "
Me .InfoTextBox.ReadOnly = True
Me .InfoTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me .InfoTextBox.Size = New System.Drawing.Size( 416 , 59 )
Me .InfoTextBox.TabIndex = 8
'
' AddInsForm
'
Me .AcceptButton = Me .CloseButton
Me .AutoScaleDimensions = New System.Drawing.SizeF( 6.0 !, 12.0 !)
Me .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me .CancelButton = Me .CloseButton
Me .ClientSize = New System.Drawing.Size( 439 , 273 )
Me .Controls.Add( Me .InfoTextBox)
Me .Controls.Add( Me .ReloadButton)
Me .Controls.Add( Me .Label2)
Me .Controls.Add( Me .Label1)
Me .Controls.Add( Me .RemoveButton)
Me .Controls.Add( Me .AddButton)
Me .Controls.Add( Me .CloseButton)
Me .Controls.Add( Me .ListView)
Me .FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me .Name = " AddInsForm "
Me .ShowInTaskbar = False
Me .StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me .Text = " 插件管理 "
Me .ResumeLayout( False )
Me .PerformLayout()
End Sub
Friend WithEvents ListView As System.Windows.Forms.ListView
Friend WithEvents NameColumnHeader As System.Windows.Forms.ColumnHeader
Friend WithEvents LocationColumnHeader As System.Windows.Forms.ColumnHeader
Friend WithEvents CloseButton As System.Windows.Forms.Button
Friend WithEvents AddButton As System.Windows.Forms.Button
Friend WithEvents RemoveButton As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents IsLoadColumnHeader As System.Windows.Forms.ColumnHeader
Friend WithEvents ReloadButton As System.Windows.Forms.Button
Friend WithEvents InfoTextBox As System.Windows.Forms.TextBox
End Class
End Namespace