📄 frmmain.vb
字号:
' ' Visual Basic.Net COmpiler' Copyright (C) 2004 - 2006 Rolf Bjarne Kvinge, rbjarnek at users.sourceforge.net' ' This library is free software; you can redistribute it and/or' modify it under the terms of the GNU Lesser General Public' License as published by the Free Software Foundation; either' version 2.1 of the License, or (at your option) any later version.' ' This library is distributed in the hope that it will be useful,' but WITHOUT ANY WARRANTY; without even the implied warranty of' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU' Lesser General Public License for more details.' ' You should have received a copy of the GNU Lesser General Public' License along with this library; if not, write to the Free Software' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA' Class frmMain Inherits Windows.Forms.Form Private WithEvents m_Tests As Tests Private WithEvents m_TestExecutor As New TestExecutor Private m_TestView As New TestView(Me) Private m_TransparentIndex, m_RedIndex, m_YellowIndex, m_GreenIndex, m_BlueIndex, m_IndigoIndex As Integer Private m_TransparentIcon, m_RedIcon, m_YellowIcon, m_GreenIcon, m_BlueIcon, m_IndigoIcon As Icon Private Delegate Sub UpdateUIDelegate(ByVal test As Test, ByVal UpdateSummary As Boolean) Private Delegate Sub UpdateUIDelegate2() ReadOnly Property TransparentIconIndex() As Integer Get Return m_TransparentIndex End Get End Property ReadOnly Property RedIconIndex() As Integer Get Return m_RedIndex End Get End Property ReadOnly Property YellowIconIndex() As Integer Get Return m_YellowIndex End Get End Property ReadOnly Property GreenIconIndex() As Integer Get Return m_GreenIndex End Get End Property ReadOnly Property IndigoIconIndex() As Integer Get Return m_IndigoIndex End Get End Property ReadOnly Property BlueIconIndex() As Integer Get Return m_BlueIndex End Get End Property ReadOnly Property TestExecutor() As TestExecutor Get Return m_TestExecutor End Get End Property ReadOnly Property Tests() As Tests Get Return m_Tests End Get End Property Private Sub CreateImages() Dim imgTransparent, imgRed, imgYellow, imgGreen, imgBlue, imgIndigo As Bitmap imgTransparent = New Bitmap(16, 16, Imaging.PixelFormat.Format32bppArgb) imgRed = New Bitmap(16, 16, Imaging.PixelFormat.Format32bppArgb) imgYellow = New Bitmap(16, 16, Imaging.PixelFormat.Format32bppArgb) imgGreen = New Bitmap(16, 16, Imaging.PixelFormat.Format32bppArgb) imgBlue = New Bitmap(16, 16, Imaging.PixelFormat.Format32bppArgb) imgIndigo = New Bitmap(16, 16, Imaging.PixelFormat.Format32bppArgb) Dim bounds As New Rectangle(0, 0, 16, 16) Using gr As Graphics = Graphics.FromImage(imgTransparent) gr.FillEllipse(Brushes.Transparent, bounds) End Using Using gr As Graphics = Graphics.FromImage(imgRed) gr.FillEllipse(Brushes.Red, bounds) End Using Using gr As Graphics = Graphics.FromImage(imgGreen) gr.FillEllipse(Brushes.Green, bounds) End Using Using gr As Graphics = Graphics.FromImage(imgYellow) gr.FillEllipse(Brushes.Yellow, bounds) End Using Using gr As Graphics = Graphics.FromImage(imgBlue) gr.FillEllipse(Brushes.Blue, bounds) End Using Using gr As Graphics = Graphics.FromImage(imgIndigo) gr.FillEllipse(Brushes.Indigo, bounds) End Using m_TransparentIcon = System.Drawing.Icon.FromHandle(imgTransparent.GetHicon) m_RedIcon = System.Drawing.Icon.FromHandle(imgRed.GetHicon) m_YellowIcon = System.Drawing.Icon.FromHandle(imgYellow.GetHicon) m_GreenIcon = System.Drawing.Icon.FromHandle(imgGreen.GetHicon) m_BlueIcon = System.Drawing.Icon.FromHandle(imgBlue.GetHicon) m_IndigoIcon = System.Drawing.Icon.FromHandle(imgIndigo.GetHicon) lstImages.Images.Add(imgTransparent) m_TransparentIndex = lstImages.Images.Count - 1 lstImages.Images.Add(imgRed) m_RedIndex = lstImages.Images.Count - 1 lstImages.Images.Add(imgYellow) m_YellowIndex = lstImages.Images.Count - 1 lstImages.Images.Add(imgGreen) m_GreenIndex = lstImages.Images.Count - 1 lstImages.Images.Add(imgBlue) m_BlueIndex = lstImages.Images.Count - 1 lstImages.Images.Add(imgIndigo) m_IndigoIndex = lstImages.Images.Count - 1 End Sub Sub New() MyBase.new() InitializeComponent() CreateImages() lstTests.ListViewItemSorter = New ListViewItemComparer(lstTests) Dim tmp As String tmp = IO.Path.GetFullPath("..\..\vbnc\bin\vbnc.exe") If IO.File.Exists(tmp) Then cmbCompiler.Items.Add(tmp) tmp = IO.Path.GetFullPath("..\..\vbnc\tests") If IO.Directory.Exists(tmp) Then cmbBasepath.Items.Add(tmp) tmp = IO.Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "Microsoft.Net\Framework\v2.0.50727\vbc.exe") If IO.File.Exists(tmp) Then cmbVBCCompiler.Items.Add(tmp) colCompiler.Width = My.Settings.TestsListView_colCompiler_Width colDate.Width = My.Settings.TestsListView_colDate_Width colFailedVerification.Width = My.Settings.TestsListView_colFailedVerification_Width colName.Width = My.Settings.TestsListView_colName_Width colResult.Width = My.Settings.TestsListView_colResult_Width colPath.Width = My.Settings.TestsListView_colPath_Width If My.Settings.txtVBCCompiler_Text <> "" Then cmbCompiler.Text = My.Settings.txtVBCCompiler_Text ElseIf cmbCompiler.Text = "" AndAlso cmbCompiler.Items.Count = 1 Then cmbCompiler.SelectedIndex = 0 End If If My.Settings.txtVBNCCompiler_Text <> "" Then cmbVBCCompiler.Text = My.Settings.txtVBNCCompiler_Text ElseIf cmbVBCCompiler.Text = "" AndAlso cmbVBCCompiler.Items.Count = 1 Then cmbVBCCompiler.SelectedIndex = 0 End If If My.Settings.txtBasePath_Text <> "" Then cmbBasepath.Text = My.Settings.txtBasePath_Text ElseIf cmbBasepath.Text = "" AndAlso cmbBasepath.Items.Count = 1 Then cmbBasepath.SelectedIndex = 0 End If Me.EnhancedProgressBar1.Value(0).Color = Color.Red Me.EnhancedProgressBar1.Value(1).Color = Color.Yellow Me.EnhancedProgressBar1.Value(2).Color = Color.Green LoadTests() chkDontTestIfNothingHasChanged_CheckedChanged(Nothing, Nothing) End Sub Public Sub RunTests() cmdRun_Click(Nothing, Nothing) End Sub Private Sub RefreshTests() Try Dim index As Integer = -1 If lstTests.SelectedIndices.Count > 0 Then index = lstTests.SelectedIndices(0) End If If m_Tests IsNot Nothing Then m_Tests.Dispose() m_Tests = Nothing End If m_Tests = New Tests(cmbBasepath.Text, cmbCompiler.Text, cmbVBCCompiler.Text) For Each test As Test In m_Tests Dim item As ListViewItem item = lstTests.Items.Add(test.Name) item.SubItems.Add(test.IsMultiFile.ToString) item.Tag = test Next If index >= 0 Then lstTests.SelectedIndices.Add(index) lstTests.EnsureVisible(index) End If txtNumberOfTests.Text = lstTests.Items.Count.ToString txtAverageExecutionTime.Text = "0" txtExecutionTime.Text = "0" txtGreenTests.Text = "0" txtMessage.Text = "" txtRedTests.Text = "0" txtTestsRun.Text = "0" txtYellowTests.Text = "0" txtQueue.Text = "0" Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Sub LoadTests(Optional ByVal CheckForNewTestsOnly As Boolean = False) Try StopWork() If cmbBasepath.Text = "" OrElse cmbCompiler.Text = "" OrElse cmbVBCCompiler.Text = "" Then MsgBox("Invalid paths.") Exit Sub End If If m_Tests IsNot Nothing AndAlso CheckForNewTestsOnly Then m_Tests.Update() Else m_Tests = New Tests(cmbBasepath.Text, cmbCompiler.Text, cmbVBCCompiler.Text) 'm_Tests.WriteLinuxScript() End If Dim selectednodetext As String = Nothing If treeTests.SelectedNode IsNot Nothing Then selectednodetext = treeTests.SelectedNode.Text treeTests.Nodes.Clear() LoadTests(m_Tests, treeTests.Nodes) treeTests.Nodes(0).Expand() If selectednodetext IsNot Nothing Then For Each node As TreeNode In treeTests.Nodes(0).Nodes If node.Text = selectednodetext Then treeTests.SelectedNode = node Exit For End If Next End If LoadOldResults() Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Function LoadTests(ByVal tests As Tests, ByVal nodes As TreeNodeCollection) As TreeNode Dim baseNode As TreeNode baseNode = nodes.Add(IO.Path.GetFileName(tests.Path)) baseNode.Tag = tests For Each subtests As Tests In tests.ContainedTests LoadTests(subtests, baseNode.Nodes) Next Return baseNode End Function Private Sub lstTests_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lstTests.SelectedIndexChanged Try For Each item As Test In Me.GetSelectedTests item.LoadOldResults() Next If lstTests.SelectedItems.Count = 1 Then SelectTest(Me.GetSelectedTests(0)) Else SelectTest(Nothing) End If Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Sub lstTests_DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles lstTests.DoubleClick Try Me.tabMain.SelectedTab = pageTestResult Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub ''' <summary> ''' Thread-safe. ''' </summary> ''' <remarks></remarks> Private Sub DoTestOf(ByVal Test As Test) UpdateUITestRunning(Test) Test.DoTest() UpdateUI(Test) End Sub Private Sub UpdateUI() If Me.InvokeRequired Then Me.BeginInvoke(New UpdateUIDelegate2(AddressOf UpdateUI)) Else For Each t As Test In m_Tests UpdateUI(t, False) Next UpdateSummary() End If End Sub ''' <summary> ''' Thread-safe. ''' </summary> ''' <remarks></remarks> Private Sub UpdateSummary() Try If Me.InvokeRequired Then Me.BeginInvoke(New CrossAppDomainDelegate(AddressOf UpdateSummary)) Return End If Dim r, y, g, total, failed As Integer Dim runcount, notruncount As Integer Dim alltests As Tests alltests = Me.GetSelectedTestList If alltests Is Nothing Then alltests = m_Tests total = alltests.RecursiveCount r = alltests.GetRedRecursiveCount g = alltests.GetGreenRecursiveCount y = total - r - g
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -