Code cleanup.

This commit is contained in:
Riley McArdle
2011-06-06 17:49:55 -05:00
parent ee94b65fb0
commit 13ba0b2802
13 changed files with 132 additions and 97 deletions

View File

@@ -3,18 +3,23 @@ Imports mRemoteNG.App.Runtime
Namespace App
Public Class Announcement
#Region "Private Properties"
Private wCl As WebClient
Private wPr As WebProxy
Implements IDisposable
#Region "Private Variables"
Private webClient As WebClient
Private webProxy As WebProxy
#End Region
#Region "Public Properties"
Private _currentAnnouncementInfo As Info
Public ReadOnly Property CurrentAnnouncementInfo() As Info
Get
Return _currentAnnouncementInfo
End Get
End Property
#End Region
#Region "Public Methods"
Public Function IsAnnouncementAvailable() As Boolean
Try
Dim aI As Info = GetAnnouncementInfo()
@@ -80,7 +85,7 @@ Namespace App
Dim strTemp As String
Try
strTemp = wCl.DownloadString(App.Info.General.URLAnnouncement)
strTemp = webClient.DownloadString(App.Info.General.URLAnnouncement)
Catch ex As Exception
strTemp = ""
End Try
@@ -93,21 +98,22 @@ Namespace App
End Function
Private Sub CreateWebClient()
wCl = New WebClient()
webClient = New WebClient()
If My.Settings.UpdateUseProxy Then
wPr = New WebProxy(My.Settings.UpdateProxyAddress, My.Settings.UpdateProxyPort)
webProxy = New WebProxy(My.Settings.UpdateProxyAddress, My.Settings.UpdateProxyPort)
If My.Settings.UpdateProxyUseAuthentication Then
Dim cred As ICredentials
cred = New NetworkCredential(My.Settings.UpdateProxyAuthUser, Security.Crypt.Decrypt(My.Settings.UpdateProxyAuthPass, App.Info.General.EncryptionKey))
wPr.Credentials = cred
webProxy.Credentials = cred
End If
wCl.Proxy = wPr
webClient.Proxy = webProxy
End If
End Sub
#End Region
Public Class Info
Private _Name As String
@@ -140,5 +146,36 @@ Namespace App
End Set
End Property
End Class
#Region "IDisposable Support"
Private disposedValue As Boolean ' To detect redundant calls
' IDisposable
Protected Overridable Sub Dispose(disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
If webClient IsNot Nothing Then webClient.Dispose()
End If
' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
' TODO: set large fields to null.
End If
Me.disposedValue = True
End Sub
' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
'Protected Overrides Sub Finalize()
' ' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
' Dispose(False)
' MyBase.Finalize()
'End Sub
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class
End Namespace

View File

@@ -19,26 +19,6 @@ Namespace App
End Sub
#Region "Public Properties"
'Private Shared _settingsLoad As Config.Settings.Load
'Public Shared Property SettingsLoad() As Load
' Get
' Return _settingsLoad
' End Get
' Set(ByVal value As Load)
' _settingsLoad = value
' End Set
'End Property
'Private Shared _settingsSave As Config.Settings.Save
'Public Shared Property SettingsSave() As Save
' Get
' Return _settingsSave
' End Get
' Set(ByVal value As Save)
' _settingsSave = value
' End Set
'End Property
Private Shared _connectionList As Connection.List
Public Shared Property ConnectionList() As List
Get
@@ -1512,7 +1492,7 @@ Namespace App
End If
If newConnectionInfo.PreExtApp <> "" Then
Dim extA As Tools.ExternalApp = App.Runtime.GetExtAppByName(newConnectionInfo.PreExtApp)
Dim extA As Tools.ExternalTool = App.Runtime.GetExtAppByName(newConnectionInfo.PreExtApp)
If extA IsNot Nothing Then
extA.Start(newConnectionInfo)
End If
@@ -1621,7 +1601,7 @@ Namespace App
If newConnectionInfo.Protocol <> Connection.Protocol.Protocols.IntApp Then
Tree.Node.SetNodeImage(newConnectionInfo.TreeNode, Images.Enums.TreeImage.ConnectionOpen)
Else
Dim extApp As Tools.ExternalApp = GetExtAppByName(newConnectionInfo.ExtApp)
Dim extApp As Tools.ExternalTool = GetExtAppByName(newConnectionInfo.ExtApp)
If extApp IsNot Nothing Then
If extApp.TryIntegrate Then
If newConnectionInfo.TreeNode IsNot Nothing Then
@@ -1689,7 +1669,7 @@ Namespace App
End If
If Prot.InterfaceControl.Info.PostExtApp <> "" Then
Dim extA As Tools.ExternalApp = App.Runtime.GetExtAppByName(Prot.InterfaceControl.Info.PostExtApp)
Dim extA As Tools.ExternalTool = App.Runtime.GetExtAppByName(Prot.InterfaceControl.Info.PostExtApp)
If extA IsNot Nothing Then
extA.Start(Prot.InterfaceControl.Info)
End If
@@ -1730,7 +1710,7 @@ Namespace App
Dim i As Integer = 0
For Each extA As Tools.ExternalApp In ExternalTools
For Each extA As Tools.ExternalTool In ExternalTools
Tools.ExternalAppsTypeConverter.ExternalApps(i) = extA.DisplayName
i += 1
@@ -1739,8 +1719,8 @@ Namespace App
Tools.ExternalAppsTypeConverter.ExternalApps(i) = ""
End Sub
Public Shared Function GetExtAppByName(ByVal Name As String) As Tools.ExternalApp
For Each extA As Tools.ExternalApp In ExternalTools
Public Shared Function GetExtAppByName(ByVal Name As String) As Tools.ExternalTool
For Each extA As Tools.ExternalTool In ExternalTools
If extA.DisplayName = Name Then
Return extA
End If
@@ -1794,19 +1774,29 @@ Namespace App
End Sub
Public Shared Function SaveReport() As Boolean
Dim streamReader As StreamReader = Nothing
Dim streamWriter As StreamWriter = Nothing
Try
Dim sRd As New StreamReader(My.Application.Info.DirectoryPath & "\Report.log")
Dim Text As String = sRd.ReadToEnd
sRd.Close()
streamReader = New StreamReader(My.Application.Info.DirectoryPath & "\Report.log")
Dim text As String = streamReader.ReadToEnd
streamReader.Close()
Dim sWr As New StreamWriter(App.Info.General.ReportingFilePath, True)
sWr.Write(Text)
sWr.Close()
streamWriter = New StreamWriter(App.Info.General.ReportingFilePath, True)
streamWriter.Write(text)
Return True
Catch ex As Exception
MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, My.Resources.strLogWriteToFileFinalLocationFailed & vbNewLine & ex.Message, True)
Return False
Finally
If streamReader IsNot Nothing Then
streamReader.Close()
streamReader.Dispose()
End If
If streamWriter IsNot Nothing Then
streamWriter.Close()
streamWriter.Dispose()
End If
End Try
End Function

View File

@@ -117,8 +117,8 @@ Namespace Config
With MainForm
ToolStripPanelFromString("top").Join(.tsQuickConnect, New Point(300, 0))
.tsQuickConnect.Visible = True
ToolStripPanelFromString("bottom").Join(.tsExtAppsToolbar, New Point(3, 0))
.tsExtAppsToolbar.Visible = False
ToolStripPanelFromString("bottom").Join(.tsExternalTools, New Point(3, 0))
.tsExternalTools.Visible = False
End With
End Sub
@@ -143,8 +143,8 @@ Namespace Config
Private Sub AddDynamicPanels()
With MainForm
ToolStripPanelFromString(My.Settings.ExtAppsTBParentDock).Join(.tsExtAppsToolbar, My.Settings.ExtAppsTBLocation)
.tsExtAppsToolbar.Visible = My.Settings.ExtAppsTBVisible
ToolStripPanelFromString(My.Settings.ExtAppsTBParentDock).Join(.tsExternalTools, My.Settings.ExtAppsTBLocation)
.tsExternalTools.Visible = My.Settings.ExtAppsTBVisible
End With
End Sub
@@ -210,7 +210,7 @@ Namespace Config
End If
For Each xEl As XmlElement In xDom.DocumentElement.ChildNodes
Dim extA As New Tools.ExternalApp
Dim extA As New Tools.ExternalTool
extA.DisplayName = xEl.Attributes("DisplayName").Value
extA.FileName = xEl.Attributes("FileName").Value
extA.Arguments = xEl.Attributes("Arguments").Value
@@ -230,7 +230,7 @@ Namespace Config
xDom = Nothing
frmMain.AddExtAppsToToolbar()
frmMain.AddExternalToolsToToolBar()
End Sub
#End Region

View File

@@ -32,11 +32,11 @@ Namespace Config
My.Settings.ResetToolbars = False
My.Settings.NoReconnect = False
My.Settings.ExtAppsTBLocation = .tsExtAppsToolbar.Location
If .tsExtAppsToolbar.Parent IsNot Nothing Then
My.Settings.ExtAppsTBParentDock = .tsExtAppsToolbar.Parent.Dock.ToString
My.Settings.ExtAppsTBLocation = .tsExternalTools.Location
If .tsExternalTools.Parent IsNot Nothing Then
My.Settings.ExtAppsTBParentDock = .tsExternalTools.Parent.Dock.ToString
End If
My.Settings.ExtAppsTBVisible = .tsExtAppsToolbar.Visible
My.Settings.ExtAppsTBVisible = .tsExternalTools.Visible
My.Settings.ExtAppsTBShowText = .cMenToolbarShowText.Checked
My.Settings.QuickyTBLocation = .tsQuickConnect.Location
@@ -82,7 +82,7 @@ Namespace Config
xmlTextWriter.WriteStartDocument()
xmlTextWriter.WriteStartElement("Apps")
For Each extA As Tools.ExternalApp In ExternalTools
For Each extA As Tools.ExternalTool In ExternalTools
xmlTextWriter.WriteStartElement("App")
xmlTextWriter.WriteAttributeString("DisplayName", "", extA.DisplayName)
xmlTextWriter.WriteAttributeString("FileName", "", extA.FileName)

View File

@@ -10,7 +10,7 @@ Namespace Connection
#Region "Private Properties"
Private IntAppProcessStartInfo As New ProcessStartInfo()
Private Arguments As String
Private ExtApp As Tools.ExternalApp
Private ExtApp As Tools.ExternalTool
#End Region
#Region "Public Properties"

View File

@@ -107,7 +107,7 @@ Partial Class frmMain
Me.lblQuickConnect = New System.Windows.Forms.ToolStripLabel
Me.cmbQuickConnect = New System.Windows.Forms.ToolStripComboBox
Me.tsContainer = New System.Windows.Forms.ToolStripContainer
Me.tsExtAppsToolbar = New System.Windows.Forms.ToolStrip
Me.tsExternalTools = New System.Windows.Forms.ToolStrip
Me.cMenExtAppsToolbar = New System.Windows.Forms.ContextMenuStrip(Me.components)
Me.cMenToolbarShowText = New System.Windows.Forms.ToolStripMenuItem
Me.tsQuickConnect = New System.Windows.Forms.ToolStrip
@@ -678,18 +678,18 @@ Partial Class frmMain
'
Me.tsContainer.TopToolStripPanel.Controls.Add(Me.msMain)
Me.tsContainer.TopToolStripPanel.Controls.Add(Me.tsQuickConnect)
Me.tsContainer.TopToolStripPanel.Controls.Add(Me.tsExtAppsToolbar)
Me.tsContainer.TopToolStripPanel.Controls.Add(Me.tsExternalTools)
Me.tsContainer.TopToolStripPanel.Controls.Add(Me.ToolStrip1)
Me.tsContainer.TopToolStripPanel.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional
'
'tsExtAppsToolbar
'
Me.tsExtAppsToolbar.ContextMenuStrip = Me.cMenExtAppsToolbar
Me.tsExtAppsToolbar.Dock = System.Windows.Forms.DockStyle.None
Me.tsExtAppsToolbar.Location = New System.Drawing.Point(39, 49)
Me.tsExtAppsToolbar.Name = "tsExtAppsToolbar"
Me.tsExtAppsToolbar.Size = New System.Drawing.Size(111, 25)
Me.tsExtAppsToolbar.TabIndex = 17
Me.tsExternalTools.ContextMenuStrip = Me.cMenExtAppsToolbar
Me.tsExternalTools.Dock = System.Windows.Forms.DockStyle.None
Me.tsExternalTools.Location = New System.Drawing.Point(39, 49)
Me.tsExternalTools.Name = "tsExtAppsToolbar"
Me.tsExternalTools.Size = New System.Drawing.Size(111, 25)
Me.tsExternalTools.TabIndex = 17
'
'cMenExtAppsToolbar
'
@@ -860,7 +860,7 @@ Partial Class frmMain
Friend WithEvents tmrShowUpdate As System.Windows.Forms.Timer
Friend WithEvents mMenToolsExternalApps As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents tmrAutoSave As System.Windows.Forms.Timer
Friend WithEvents tsExtAppsToolbar As System.Windows.Forms.ToolStrip
Friend WithEvents tsExternalTools As System.Windows.Forms.ToolStrip
Friend WithEvents mMenViewExtAppsToolbar As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents cMenExtAppsToolbar As System.Windows.Forms.ContextMenuStrip
Friend WithEvents cMenToolbarShowText As System.Windows.Forms.ToolStripMenuItem

View File

@@ -207,40 +207,36 @@ Public Class frmMain
SwitchToolBarText(Not cMenToolbarShowText.Checked)
End Sub
Public Sub AddExtAppsToToolbar()
Public Sub AddExternalToolsToToolBar()
Try
'clean up
tsExtAppsToolbar.Items.Clear()
For Each item As ToolStripItem In tsExternalTools.Items
item.Dispose()
Next
tsExternalTools.Items.Clear()
'add ext apps
For Each extA As Tools.ExternalApp In ExternalTools
Dim nItem As New ToolStripButton
nItem.Text = extA.DisplayName
nItem.Image = extA.Image
Dim button As ToolStripButton
For Each tool As Tools.ExternalTool In ExternalTools
button = tsExternalTools.Items.Add(tool.DisplayName, tool.Image, AddressOf tsExtAppEntry_Click)
If cMenToolbarShowText.Checked = True Then
nItem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
Else
If nItem.Image IsNot Nothing Then
nItem.DisplayStyle = ToolStripItemDisplayStyle.Image
If button.Image IsNot Nothing Then
button.DisplayStyle = ToolStripItemDisplayStyle.Image
Else
nItem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
End If
End If
nItem.Tag = extA
AddHandler nItem.Click, AddressOf tsExtAppEntry_Click
tsExtAppsToolbar.Items.Add(nItem)
button.Tag = tool
Next
Catch ex As Exception
MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, "AddExtAppsToToolbar failed (frmMain)" & vbNewLine & ex.Message, True)
MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, String.Format(My.Resources.strErrorAddExternalToolsToToolBarFailed, ex.Message), True)
End Try
End Sub
Private Sub tsExtAppEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim extA As Tools.ExternalApp = sender.Tag
Dim extA As Tools.ExternalTool = sender.Tag
If Tree.Node.GetNodeType(Tree.Node.SelectedNode) = Tree.Node.Type.Connection Then
extA.Start(Tree.Node.SelectedNode.Tag)
@@ -250,7 +246,7 @@ Public Class frmMain
End Sub
Public Sub SwitchToolBarText(ByVal show As Boolean)
For Each tItem As ToolStripButton In tsExtAppsToolbar.Items
For Each tItem As ToolStripButton In tsExternalTools.Items
If show = True Then
tItem.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
Else
@@ -373,7 +369,7 @@ Public Class frmMain
Me.mMenViewSessions.Checked = Not Windows.sessionsForm.IsHidden
Me.mMenViewScreenshotManager.Checked = Not Windows.screenshotForm.IsHidden
Me.mMenViewExtAppsToolbar.Checked = tsExtAppsToolbar.Visible
Me.mMenViewExtAppsToolbar.Checked = tsExternalTools.Visible
Me.mMenViewQuickConnectToolbar.Checked = tsQuickConnect.Visible
Me.mMenViewConnectionPanels.DropDownItems.Clear()
@@ -479,10 +475,10 @@ Public Class frmMain
Private Sub mMenViewExtAppsToolbar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mMenViewExtAppsToolbar.Click
If mMenViewExtAppsToolbar.Checked = False Then
tsExtAppsToolbar.Visible = True
tsExternalTools.Visible = True
mMenViewExtAppsToolbar.Checked = True
Else
tsExtAppsToolbar.Visible = False
tsExternalTools.Visible = False
mMenViewExtAppsToolbar.Checked = False
End If
End Sub

View File

@@ -2150,6 +2150,15 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to AddExternalToolsToToolBar (frmMain) failed. {0}.
'''</summary>
Friend ReadOnly Property strErrorAddExternalToolsToToolBarFailed() As String
Get
Return ResourceManager.GetString("strErrorAddExternalToolsToToolBarFailed", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to AddFolder (UI.Window.Tree) failed. {0}.
'''</summary>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
@@ -2352,4 +2352,7 @@ Error Description: {1}</value>
<data name="strErrorBadDatabaseVersion" xml:space="preserve">
<value>The database version {0} is not compatible with this version of {1}.</value>
</data>
<data name="strErrorAddExternalToolsToToolBarFailed" xml:space="preserve">
<value>AddExternalToolsToToolBar (frmMain) failed. {0}</value>
</data>
</root>

View File

@@ -3,7 +3,7 @@ Imports System.IO
Imports System.ComponentModel
Namespace Tools
Public Class ExternalApp
Public Class ExternalTool
#Region "Properties"
Private _DisplayName As String
Public Property DisplayName() As String

View File

@@ -706,7 +706,7 @@ Namespace UI
cmenTabExternalApps.DropDownItems.Clear()
'add ext apps
For Each extA As Tools.ExternalApp In ExternalTools
For Each extA As Tools.ExternalTool In ExternalTools
Dim nItem As New ToolStripMenuItem
nItem.Text = extA.DisplayName
nItem.Tag = extA
@@ -722,7 +722,7 @@ Namespace UI
End Try
End Sub
Private Sub StartExternalApp(ByVal ExtA As Tools.ExternalApp)
Private Sub StartExternalApp(ByVal ExtA As Tools.ExternalTool)
Try
If Me.TabController.SelectedTab IsNot Nothing Then
If TypeOf Me.TabController.SelectedTab.Tag Is mRemoteNG.Connection.InterfaceControl Then

View File

@@ -294,7 +294,7 @@ Namespace UI
#End Region
#Region "Private Properties"
Private _SelApp As Tools.ExternalApp
Private _SelApp As Tools.ExternalTool
#End Region
#Region "Private Methods"
@@ -302,7 +302,7 @@ Namespace UI
Try
lvApps.Items.Clear()
For Each extA As Tools.ExternalApp In ExternalTools
For Each extA As Tools.ExternalTool In ExternalTools
Dim lvItem As New ListViewItem
lvItem.Text = extA.DisplayName
lvItem.SubItems.Add(extA.FileName)
@@ -326,7 +326,7 @@ Namespace UI
End Try
End Sub
Private Sub GetAppProperties(ByVal SelApp As Tools.ExternalApp)
Private Sub GetAppProperties(ByVal SelApp As Tools.ExternalTool)
Try
If SelApp IsNot Nothing Then
txtDisplayName.Text = SelApp.DisplayName
@@ -341,7 +341,7 @@ Namespace UI
End Try
End Sub
Private Sub SetAppProperties(ByVal SelApp As Tools.ExternalApp)
Private Sub SetAppProperties(ByVal SelApp As Tools.ExternalTool)
Try
If SelApp IsNot Nothing Then
SelApp.DisplayName = txtDisplayName.Text
@@ -359,7 +359,7 @@ Namespace UI
Private Sub AddNewApp()
Try
Dim nExtA As New Tools.ExternalApp("New Application")
Dim nExtA As New Tools.ExternalTool("New Application")
ExternalTools.Add(nExtA)
LoadApps()
lvApps.SelectedItems.Clear()
@@ -405,7 +405,7 @@ Namespace UI
Private Sub StartApp()
Try
For Each lvItem As ListViewItem In lvApps.SelectedItems
TryCast(lvItem.Tag, mRemoteNG.Tools.ExternalApp).Start()
TryCast(lvItem.Tag, mRemoteNG.Tools.ExternalTool).Start()
Next
Catch ex As Exception
MessageCollector.AddMessage(Messages.MessageClass.WarningMsg, "StartApp failed (UI.Window.ExternalApps" & vbNewLine & ex.Message, True)
@@ -413,7 +413,7 @@ Namespace UI
End Sub
Private Sub RefreshToolbar()
frmMain.AddExtAppsToToolbar()
frmMain.AddExternalToolsToToolBar()
App.Runtime.GetExtApps()
End Sub
#End Region

View File

@@ -1153,7 +1153,7 @@ Namespace UI
cMenTreeToolsExternalApps.DropDownItems.Clear()
'add ext apps
For Each extA As Tools.ExternalApp In ExternalTools
For Each extA As Tools.ExternalTool In ExternalTools
Dim nItem As New ToolStripMenuItem
nItem.Text = extA.DisplayName
nItem.Tag = extA
@@ -1169,7 +1169,7 @@ Namespace UI
End Try
End Sub
Private Sub StartExternalApp(ByVal ExtA As Tools.ExternalApp)
Private Sub StartExternalApp(ByVal ExtA As Tools.ExternalTool)
Try
If mRemoteNG.Tree.Node.GetNodeType(mRemoteNG.Tree.Node.SelectedNode) = mRemoteNG.Tree.Node.Type.Connection Then
ExtA.Start(mRemoteNG.Tree.Node.SelectedNode.Tag)