-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeCoverageForm.vb
236 lines (212 loc) · 10 KB
/
CodeCoverageForm.vb
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
Imports System.ComponentModel
Imports CodeCoverage.Coverlet.Core
Public Class CodeCoverageForm
Private WithEvents BackgroundWorker1 As New BackgroundWorker
Private ReadOnly _documentList As New List(Of DirectoryClass)
Private ReadOnly _documentsStrLength As Integer = "Documents: ".Length
Private ReadOnly _methodArrayList As New List(Of MethodClass)
Private _dT As DataTable
Private _dV As DataView
Public Property CoverletResult As CoverletTreeView
Public Property Initializing As Boolean = True
Public Property RTFForm As Form1
Private Shared Function GetTable(MethodList As List(Of MethodClass)) As DataTable
' Create new DataTable instance.
Dim table As New DataTable
If MethodList Is Nothing Then
Return table
End If
' Create four typed columns in the DataTable.
table.Columns.Add("DocumentLongName", GetType(String))
table.Columns.Add("MethodLongName", GetType(String))
table.Columns.Add("MethodNode", GetType(TreeNode))
table.Columns.Add("MethodShortName", GetType(String))
table.Rows.Add("", "", Nothing, Nothing)
For Each m As MethodClass In MethodList
table.Rows.Add(m.DocumentLongName, m.MethodLongName, m.MethodNode, m.MethodShortName)
Next
Return table
End Function
Private Shared Sub GotoLine(RTF_Box As RichTextBox, WantedLine_One_Based As Integer)
Dim index As Integer = RTF_Box.GetFirstCharIndexFromLine(WantedLine_One_Based - 1)
While index < RTF_Box.TextLength - 1
If RTF_Box.Text.Substring(index, 1) <> " " Then
Exit While
End If
index += 1
End While
RTF_Box.HideSelection = False
RTF_Box.Select(index, 0)
RTF_Box.ScrollToCaret()
RTF_Box.Focus()
Application.DoEvents()
End Sub
Private Sub backgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
' Get the BackgroundWorker object that raised this event.
RTFForm.LoadDocument(CType(e.Argument, Form1))
End Sub
Private Sub CodeCoverageForm_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
_dT.Dispose()
_dV.Dispose()
End Sub
Private Sub CodeCoverageForm_Load(sender As Object, e As EventArgs) Handles Me.Load
If RTFForm Is Nothing Then
RTFForm = New Form1
End If
TopMost = True
Left = RTFForm.Right - (Width + 20)
Top = RTFForm.Top + RTFForm.ToolStripProgressBar1.Height + (RTFForm.Height - RTFForm.ClientRectangle.Height)
ToolStrip1.CanOverflow = True
ToolStripLabel1.Overflow = ToolStripItemOverflow.Never
ToolStripLabel2.Overflow = ToolStripItemOverflow.Never
DocumentToolStripComboBox.AutoCompleteMode = AutoCompleteMode.Append
MethodToolStripComboBox.AutoCompleteMode = AutoCompleteMode.Append
End Sub
Private Sub CodeCoverageForm_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged
RTFForm.mnuOptionsShowCodeCoverageJson.Checked = Visible
End Sub
Private Sub DocumentToolStripComboBox_DropDown(sender As Object, e As EventArgs) Handles DocumentToolStripComboBox.DropDown
Dim ToolStripCombo As ToolStripComboBox = CType(sender, ToolStripComboBox)
Using graphics As Graphics = CreateGraphics()
Dim maxWidth As Integer = 0
For Each drv As DirectoryClass In ToolStripCombo.Items
Dim area As SizeF = graphics.MeasureString(drv.ShortName, ToolStripCombo.Font)
maxWidth = Math.Max(CInt(Math.Round(area.Width + 1)), maxWidth)
Next drv
ToolStripCombo.DropDownWidth = maxWidth + SystemInformation.VerticalScrollBarWidth
End Using
End Sub
Private Sub DocumentToolStripComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DocumentToolStripComboBox.SelectedIndexChanged
If Initializing Then
Return
End If
Initializing = True
Dim SelectedItem As DirectoryClass = CType(DocumentToolStripComboBox.SelectedItem, DirectoryClass)
LoadDocumentIfNeeded(SelectedItem.FullPath)
TreeView1.HideSelection = False
TreeView1.SelectedNode = SelectedItem.DirectoryNode
If SelectedItem.DirectoryNode IsNot Nothing Then
TreeView1.SelectedNode.EnsureVisible()
_dV.RowFilter = $"DocumentLongName = '{SelectedItem.FullPath}'"
Else
_dV.RowFilter = ""
End If
MethodToolStripComboBox.ComboBox.DataSource = _dV
MethodToolStripComboBox.ComboBox.DisplayMember = "MethodShortName"
MethodToolStripComboBox.SelectedIndex = -1
Initializing = False
End Sub
Private Sub LoadDocumentIfNeeded(DocumentName As String)
If RTFForm.LoadedDocument <> DocumentName Then
RTFForm.LoadedDocument = DocumentName
If String.IsNullOrWhiteSpace(DocumentName) Then
RTFForm.Text = ""
Else
' Start the asynchronous operation.
BackgroundWorker1.RunWorkerAsync(RTFForm)
Cursor = Cursors.WaitCursor
While BackgroundWorker1.IsBusy
Application.DoEvents()
End While
Cursor = Cursors.Default
Application.DoEvents()
End If
End If
End Sub
Private Sub MethodToolStripComboBox_DropDown(sender As Object, e As EventArgs) Handles MethodToolStripComboBox.DropDown
Dim ToolStripCombo As ToolStripComboBox = CType(sender, ToolStripComboBox)
Using graphics As Graphics = CreateGraphics()
Dim maxWidth As Integer = 0
For Each SelectedItem As DataRowView In ToolStripCombo.Items
Dim area As SizeF = graphics.MeasureString(SelectedItem.Item("MethodShortName").ToString(), ToolStripCombo.Font)
Dim StringLength As Integer = CInt(Math.Round(area.Width + 1))
If StringLength > maxWidth Then
maxWidth = StringLength
End If
Next
ToolStripCombo.DropDownWidth = maxWidth + SystemInformation.VerticalScrollBarWidth
End Using
End Sub
Private Sub MethodToolStripComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles MethodToolStripComboBox.SelectedIndexChanged
If Initializing Then
Return
End If
Dim TB As ToolStripComboBox = DirectCast(sender, ToolStripComboBox)
If TB.SelectedIndex = -1 Then
Return
End If
Dim SelectedItem As DataRowView = CType(TB.SelectedItem, DataRowView)
If SelectedItem Is Nothing Then
Exit Sub
End If
Dim MethodLongName As String = SelectedItem("MethodLongName").ToString
TB.ToolTipText = MethodLongName
Dim Node As TreeNode = _methodArrayList.Find(Function(x As MethodClass) x?.MethodLongName = MethodLongName)?.MethodNode
If Node Is Nothing Then
Exit Sub
End If
TreeView1.HideSelection = False
TreeView1.SelectedNode = Node
TreeView1.SelectedNode.EnsureVisible()
LoadDocumentIfNeeded(Node.Parent.Parent.Text.Substring(_documentsStrLength))
Dim PossibleLineNode As String = Node.Nodes(0)?.Tag?.ToString.Trim
If PossibleLineNode = "Line:" Then
Dim OneBasedLine As String = Node.Nodes(0).Text.Split(","c)(0).Substring("Line: ".Length)
GotoLine(RTFForm.RichTextBoxSource, CInt(OneBasedLine))
End If
End Sub
Private Sub TreeView1_DoubleClick(sender As Object, e As EventArgs) Handles TreeView1.DoubleClick
If BackgroundWorker1.IsBusy Then
Return
End If
Dim Node As TreeNode = CType(sender, TreeView).SelectedNode
Select Case Node.Tag?.ToString.Trim
Case "Modules:"
' Ignore
Case "Documents:"
LoadDocumentIfNeeded(Node.Text.Substring(_documentsStrLength))
Case "Classes:"
LoadDocumentIfNeeded(Node.Parent.Text.Substring(_documentsStrLength))
Case "Methods:"
LoadDocumentIfNeeded(Node.Parent.Parent.Text.Substring(_documentsStrLength))
Case "Line:"
LoadDocumentIfNeeded(Node.Parent.Parent.Parent.Text.Substring(_documentsStrLength))
Dim OneBasedLine As String = Node.Text.Split(","c)(0).Substring("Line: ".Length)
GotoLine(RTFForm.RichTextBoxSource, CInt(OneBasedLine))
Case "Branches:"
' Ignore
Case "Branch Line:"
LoadDocumentIfNeeded(Node.Parent.Parent.Parent.Parent.Text.Substring(_documentsStrLength))
Dim OneBasedLine As String = Node.Parent.Text.Split(","c)(0).Substring("Line: ".Length)
GotoLine(RTFForm.RichTextBoxSource, CInt(OneBasedLine))
Case "Offset: "
' Ignore
Case "End Offset:"
' Ignore
Case "Path:"
' Ignore
Case "Ordinal:"
' Ignore
Case "Hits:"
' Ignore
Case Else
' Ignore
End Select
End Sub
Public Sub LoadJSONFile(FileWithPath As String)
CoverletResult = New CoverletTreeView(FileWithPath, TreeView1, _documentList, _methodArrayList)
DocumentToolStripComboBox.ComboBox.DisplayMember = "ShortName"
DocumentToolStripComboBox.ComboBox.ValueMember = "FullPath"
DocumentToolStripComboBox.ComboBox.DataSource = _documentList
MethodToolStripComboBox.ComboBox.DisplayMember = "MethodShortName"
MethodToolStripComboBox.ComboBox.ValueMember = "MethodNode"
_dT = GetTable(_methodArrayList)
_dV = New DataView(_dT) With {
.RowFilter = Nothing
}
DocumentToolStripComboBox.SelectedIndex = -1
MethodToolStripComboBox.ComboBox.DataSource = _dT
MethodToolStripComboBox.SelectedIndex = -1
Initializing = False
End Sub
End Class