📄 frmmain.vb
字号:
failed = r runcount = r + g notruncount = y If r > 0 Then Me.Icon = m_RedIcon ElseIf g > 0 AndAlso y > 0 Then Me.Icon = m_BlueIcon ElseIf g = total Then Me.Icon = m_GreenIcon Else Me.Icon = m_YellowIcon End If Me.EnhancedProgressBar1.Value(0).PercentDone = r / total Me.EnhancedProgressBar1.Value(1).PercentDone = y / total Me.EnhancedProgressBar1.Value(2).PercentDone = g / total Me.EnhancedProgressBar1.Invalidate() If tabMain.SelectedTab Is pageSummary Then Dim COUNTERFORMAT As String = "{0} ({1:0.#%})" txtRedTests.Text = String.Format(COUNTERFORMAT, r, r / total) txtYellowTests.Text = String.Format(COUNTERFORMAT, y, y / total) txtGreenTests.Text = String.Format(COUNTERFORMAT, g, g / total) txtQueue.Text = m_TestExecutor.QueueCount.ToString txtNumberOfTests.Text = total.ToString txtTestsRun.Text = (r + g).ToString Text = String.Format("RT OK: {0} ({5:#0.0}%) / FAILED: {1} ({4:#0.0}%) / NOT RUN: {2}/{3} tests) / IN QUEUE: {6}", g, r, y, total, r * 100 / total, g * 100 / total, m_TestExecutor.QueueCount) Dim exectime As TimeSpan = alltests.ExecutionTimeRecursive txtExecutionTime.Text = String.Format("{0}", FormatTimespan(exectime)) If total > 0 Then txtAverageExecutionTime.Text = String.Format("{0}", FormatTimespan(New TimeSpan(exectime.Ticks \ CInt(IIf(runcount = 0, 1, runcount))))) Else txtAverageExecutionTime.Text = "0" End If End If UpdateTreeIcons() Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Sub UpdateTreeIcons() If Me.InvokeRequired Then Me.BeginInvoke(New CrossAppDomainDelegate(AddressOf UpdateTreeIcons)) Return End If For Each subnode As TreeNode In treeTests.Nodes UpdateTreeIcons(subnode) Next End Sub Private Sub UpdateTreeIcons(ByVal Node As TreeNode) Dim tests As Tests = TryCast(Node.Tag, Tests) If tests IsNot Nothing Then Dim g, r, t, i As Integer t = tests.RecursiveCount g = tests.GetGreenRecursiveCount r = tests.GetRedRecursiveCount i = tests.GetTestsCount(Test.Results.Regressed, Test.Results.Regressed) If g + r + i = 0 Then 'no tests run Node.ImageIndex = Me.YellowIconIndex ElseIf r > 0 Then 'at least one red test. Node.ImageIndex = Me.RedIconIndex ElseIf g = t Then 'only green tests (of the run tests). Node.ImageIndex = Me.GreenIconIndex ElseIf i > 0 Then 'at least one regressed test Node.ImageIndex = Me.IndigoIconIndex Else 'working, but no red tests yet. Node.ImageIndex = Me.BlueIconIndex End If Node.SelectedImageIndex = Node.ImageIndex '(not implemnted in winforms yet)'Node.StateImageIndex = Node.ImageIndex End If For Each subnode As TreeNode In Node.Nodes UpdateTreeIcons(subnode) Next End Sub ''' <summary> ''' Thread-safe. ''' </summary> ''' <param name="test"></param> ''' <remarks></remarks> Private Sub UpdateUI(ByVal test As Test, Optional ByVal UpdateSummary As Boolean = True) If test Is Nothing Then UpdateUI() If Me.InvokeRequired Then Me.BeginInvoke(New UpdateUIDelegate(AddressOf UpdateUI), New Object () {test, UpdateSummary}) Else If Me.Disposing OrElse Me.IsDisposed Then StopIfDebugging() : Return Dim item As ListViewItem = TryCast(test.Tag, ListViewItem) If item Is Nothing Then For Each item In lstTests.Items If item.Tag Is test Then Exit For Else item = Nothing End If Next End If Dim newStateImageIndex As Integer If test.Result = rt.Test.Results.NotRun Then newStateImageIndex = m_YellowIndex ElseIf test.Result >= rt.Test.Results.Success Then newStateImageIndex = m_GreenIndex Else newStateImageIndex = m_RedIndex End If If item.StateImageIndex <> newStateImageIndex Then '(not implemnted in winforms yet)'item.StateImageIndex = newStateImageIndex End If If UpdateSummary Then Me.UpdateSummary() If lstTests.SelectedItems.Count > 0 AndAlso lstTests.SelectedItems.Contains(item) Then lstTests_SelectedIndexChanged(lstTests, Nothing) End If txtQueue.Text = m_TestExecutor.QueueCount.ToString If lstTests.ListViewItemSorter IsNot Nothing Then lstTests.Sort() End If End Sub Private Function FormatTimespan(ByVal ts As TimeSpan) As String Return ts.Days.ToString("00") & ":" & ts.Hours.ToString("00") & ":" & ts.Minutes.ToString("00") & ":" & ts.Seconds.ToString("00") & ":" & ts.Milliseconds.ToString("000") 'Return ts.TotalMilliseconds.ToString("#,##") & " milliseconds" 'Return CInt(ts.TotalSeconds).ToString & ":" & ts.Milliseconds.ToString & " seconds" End Function ''' <summary> ''' Thread-safe. ''' </summary> ''' <param name="test"></param> ''' <remarks></remarks> Private Sub UpdateUITestRunning(ByVal test As Test, Optional ByVal UpdateSummary As Boolean = True) If Me.InvokeRequired Then Me.BeginInvoke(New UpdateUIDelegate(AddressOf UpdateUITestRunning), new Object() {test, UpdateSummary}) Else If Me.IsDisposed Then StopIfDebugging() : Return Dim item As ListViewItem = TryCast(test.Tag, ListViewItem) If item IsNot Nothing Then For Each item In lstTests.Items If item.Tag Is test Then Exit For Else item = Nothing End If Next End If Debug.Assert(item IsNot Nothing) item.SubItems(2).Text = "" item.SubItems(3).Text = "" item.SubItems(4).Text = "" item.SubItems(5).Text = "" '(not implemnted in winforms yet)'item.StateImageIndex = m_BlueIndex End If End Sub Private Sub UpdateState() txtQueue.Text = m_TestExecutor.QueueCount.ToString End Sub Private Sub cmdRun_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdRun.Click Try 'm_Tests.RunAsync() UpdateState() Catch ex As Exception MsgBox(String.Format("Error while executing tests: ") & ex.Message) End Try End Sub Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click Try Dim cmd As Button = TryCast(sender, Button) If cmd Is Nothing Then cmd = cmdPause If cmd.Text = "Pause" Then m_TestExecutor.Pause() cmd.Text = "Resume" ElseIf cmd.Text = "Resume" Then m_TestExecutor.Resume() cmd.Text = "Pause" Else End If Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Sub cmdBasepath_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdBasepath.Click Try dlgBasepath.SelectedPath = cmbBasepath.Text If dlgBasepath.ShowDialog = Windows.Forms.DialogResult.OK Then cmbBasepath.Text = dlgBasepath.SelectedPath LoadTests() End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub mnuToolsChangeOutputToVerified_Click(ByVal sender As Object, ByVal e As EventArgs) Handles mnuToolsChangeOutputToVerified.Click Try Dim result As MsgBoxResult result = MsgBox("Overwrite existing files?", MsgBoxStyle.YesNoCancel) If result = MsgBoxResult.Yes Then MainModule.ChangeOutputToVerified(cmbBasepath.Text, True, True) ElseIf result = MsgBoxResult.No Then MainModule.ChangeOutputToVerified(cmbBasepath.Text, False, True) Else Exit Sub End If MsgBox("Output xml files has sucessfully been changed to verified xml files.", MsgBoxStyle.Information) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub cmdCompiler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCompiler.Click Try dlgFile.FileName = cmbCompiler.Text If dlgFile.ShowDialog = Windows.Forms.DialogResult.OK Then cmbCompiler.Text = dlgFile.FileName End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub cmnuDebugTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmnuDebugTest.Click Try DebugTest(Me.GetSelectedTests) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub cmnuViewCode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuViewCode.Click, cmnuViewCode2.Click Try ViewCode(Me.GetSelectedTests) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub cmnuRunTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuRunTest.Click Try AddWork(GetSelectedTests, True) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub AddWork(ByVal Tests As Generic.IEnumerable(Of Test), ByVal Priority As Boolean) Try If Me.IsDisposed Then StopIfDebugging() : Return m_TestExecutor.RunAsync(Tests, Priority) txtQueue.Text = m_TestExecutor.QueueCount.ToString Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Sub AddWork(ByVal Test As Test, ByVal Priority As Boolean) Try If Me.IsDisposed Then StopIfDebugging() : Return m_TestExecutor.RunAsync(Test, Priority) txtQueue.Text = m_TestExecutor.QueueCount.ToString Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Sub StopWork() Try m_TestExecutor.Stop() Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Function GetSelectedTests() As Generic.List(Of Test) Dim result As New Generic.List(Of Test) For Each item As ListViewItem In lstTests.SelectedItems Dim test As Test = TryCast(item.Tag, Test) If test IsNot Nothing Then result.Add(test) Next Return result End Function Private Function GetSelectedTest() As Test If lstTests.SelectedItems.Count = 1 Then Return DirectCast(lstTests.SelectedItems(0).Tag, Test) Else Return Nothing End If End Function Private Sub cmnuOutputToVerified_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmnuOutputToVerified.Click Try Dim count As Integer For Each test As Test In GetSelectedTests() count += MainModule.ChangeOutputToVerified(test, True) Next MsgBox(String.Format("{0} output xml files has sucessfully been changed to verified xml files.", count), MsgBoxStyle.Information) Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Try LoadTests() lstTests.Focus() Catch ex As Exception MsgBox(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Protected Overrides Sub Dispose(ByVal disposing As Boolean)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -