Skip to content

Commit 696f082

Browse files
authored
Cleanup in the VB code (#12730)
1 parent 0cf1885 commit 696f082

File tree

10 files changed

+110
-82
lines changed

10 files changed

+110
-82
lines changed

Diff for: src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/ApplicationServices/SingleInstanceHelpers.vb

+12-16
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ Namespace Microsoft.VisualBasic.ApplicationServices
2121
Using stream As New MemoryStream
2222
While True
2323
Dim buffer As Byte() = New Byte(bufferLength - 1) {}
24-
Dim bytesRead As Integer = Await pipeServer.ReadAsync(
25-
buffer:=buffer.AsMemory(start:=0, length:=bufferLength),
26-
cancellationToken) _
27-
.ConfigureAwait(continueOnCapturedContext:=False)
24+
Dim bytesRead As Integer =
25+
Await pipeServer.ReadAsync(
26+
buffer:=buffer.AsMemory(start:=0, length:=bufferLength),
27+
cancellationToken).ConfigureAwait(continueOnCapturedContext:=False)
2828
If bytesRead = 0 Then
2929
Exit While
3030
End If
3131
Await stream.WriteAsync(
3232
buffer:=buffer.AsMemory(start:=0, length:=bytesRead),
33-
cancellationToken) _
34-
.ConfigureAwait(continueOnCapturedContext:=False)
33+
cancellationToken).ConfigureAwait(continueOnCapturedContext:=False)
3534
End While
3635
stream.Seek(0, SeekOrigin.Begin)
3736
Dim serializer As New DataContractSerializer(GetType(String()))
@@ -55,8 +54,8 @@ Namespace Microsoft.VisualBasic.ApplicationServices
5554
content = stream.ToArray()
5655
End Using
5756
Await pipeClient.WriteAsync(
58-
buffer:=content.AsMemory(start:=0, length:=content.Length), cancellationToken) _
59-
.ConfigureAwait(continueOnCapturedContext:=False)
57+
buffer:=content.AsMemory(start:=0, length:=content.Length),
58+
cancellationToken).ConfigureAwait(continueOnCapturedContext:=False)
6059
End Function
6160

6261
Friend Async Function SendSecondInstanceArgsAsync(
@@ -70,10 +69,8 @@ Namespace Microsoft.VisualBasic.ApplicationServices
7069
direction:=PipeDirection.Out,
7170
options:=NamedPipeOptions)
7271

73-
Await pipeClient.ConnectAsync(cancellationToken) _
74-
.ConfigureAwait(continueOnCapturedContext:=False)
75-
Await WriteArgsAsync(pipeClient, args, cancellationToken) _
76-
.ConfigureAwait(continueOnCapturedContext:=False)
72+
Await pipeClient.ConnectAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext:=False)
73+
Await WriteArgsAsync(pipeClient, args, cancellationToken).ConfigureAwait(continueOnCapturedContext:=False)
7774
End Using
7875
End Function
7976

@@ -102,11 +99,10 @@ Namespace Microsoft.VisualBasic.ApplicationServices
10299

103100
While True
104101
cancellationToken.ThrowIfCancellationRequested()
105-
Await pipeServer.WaitForConnectionAsync(cancellationToken) _
106-
.ConfigureAwait(continueOnCapturedContext:=False)
102+
Await pipeServer.WaitForConnectionAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext:=False)
107103
Try
108-
Dim args() As String = Await ReadArgsAsync(pipeServer, cancellationToken) _
109-
.ConfigureAwait(continueOnCapturedContext:=False)
104+
Dim args() As String =
105+
Await ReadArgsAsync(pipeServer, cancellationToken).ConfigureAwait(continueOnCapturedContext:=False)
110106
If args IsNot Nothing Then
111107
callback(args)
112108
End If

Diff for: src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/ApplicationServices/WindowsFormsApplicationBase.vb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
10821082
Dim awaitable As ConfiguredTaskAwaitable = SendSecondInstanceArgsAsync(
10831083
pipeName:=applicationInstanceID,
10841084
args:=commandLine,
1085-
cancellationToken:=tokenSource.Token) _
1086-
.ConfigureAwait(continueOnCapturedContext:=False)
1085+
cancellationToken:=tokenSource.Token).ConfigureAwait(continueOnCapturedContext:=False)
10871086

10881087
awaitable.GetAwaiter().GetResult()
10891088
Catch ex As Exception

Diff for: src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.DownloadFile.vb

+11-13
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ Namespace Microsoft.VisualBasic.Devices
286286
connectionTimeout,
287287
overwrite,
288288
UICancelOption.ThrowException)
289-
290289
End Sub
291290

292291
''' <summary>
@@ -328,7 +327,7 @@ Namespace Microsoft.VisualBasic.Devices
328327
' Don't use passive mode if we're showing UI
329328
client.UseNonPassiveFtp = showUI
330329

331-
'Construct the local file. This will validate the full name and path
330+
' Construct the local file. This will validate the full name and path
332331
Dim fullFilename As String = FileSystemUtils.NormalizeFilePath(destinationFileName, NameOf(destinationFileName))
333332

334333
' Sometime a path that can't be parsed is normalized to the current directory. This makes sure we really
@@ -337,7 +336,7 @@ Namespace Microsoft.VisualBasic.Devices
337336
Throw VbUtils.GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
338337
End If
339338

340-
'Throw if the file exists and the user doesn't want to overwrite
339+
' Throw if the file exists and the user doesn't want to overwrite
341340
If IO.File.Exists(fullFilename) And Not overwrite Then
342341
Throw New IO.IOException(VbUtils.GetResourceString(SR.IO_FileExists_Path, destinationFileName))
343342
End If
@@ -349,7 +348,7 @@ Namespace Microsoft.VisualBasic.Devices
349348

350349
Dim dialog As ProgressDialog = GetProgressDialog(address.AbsolutePath, fullFilename, showUI)
351350

352-
'Check to see if the target directory exists. If it doesn't, create it
351+
' Check to see if the target directory exists. If it doesn't, create it
353352
Dim targetDirectory As String = IO.Path.GetDirectoryName(fullFilename)
354353

355354
' Make sure we have a meaningful directory. If we don't, the destinationFileName is suspect
@@ -361,21 +360,20 @@ Namespace Microsoft.VisualBasic.Devices
361360
IO.Directory.CreateDirectory(targetDirectory)
362361
End If
363362

364-
'Create the copier
363+
' Create the copier
365364
Dim copier As New WebClientCopy(client, dialog)
366365

367-
'Download the file
366+
' Download the file
368367
copier.DownloadFile(address, fullFilename)
369368

370-
'Handle a dialog cancel
371-
If showUI AndAlso Environment.UserInteractive Then
372-
If onUserCancel = UICancelOption.ThrowException And dialog.UserCanceledTheDialog Then
373-
Throw New OperationCanceledException()
374-
End If
369+
' Handle a dialog cancel
370+
If showUI _
371+
AndAlso Environment.UserInteractive _
372+
AndAlso onUserCancel = UICancelOption.ThrowException _
373+
AndAlso dialog.UserCanceledTheDialog Then
374+
Throw New OperationCanceledException()
375375
End If
376-
377376
End Using
378-
379377
End Sub
380378

381379
End Class

Diff for: src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.UploadFile.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Namespace Microsoft.VisualBasic.Devices
289289
End If
290290

291291
Dim dialog As ProgressDialog = Nothing
292-
If showUI AndAlso Environment.UserInteractive Then
292+
If InteractiveEnvironment(showUI) Then
293293
dialog = New ProgressDialog With {
294294
.Text = GetResourceString(SR.ProgressDialogUploadingTitle, sourceFileName),
295295
.LabelText = GetResourceString(
@@ -306,7 +306,7 @@ Namespace Microsoft.VisualBasic.Devices
306306
copier.UploadFile(sourceFileName, address)
307307

308308
' Handle a dialog cancel
309-
If showUI AndAlso Environment.UserInteractive Then
309+
If InteractiveEnvironment(showUI) Then
310310
If onUserCancel = UICancelOption.ThrowException And dialog.UserCanceledTheDialog Then
311311
Throw New OperationCanceledException()
312312
End If

Diff for: src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/NetworkUtilities.vb

+9-2
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,16 @@ Namespace Microsoft.VisualBasic.Devices
5656
''' <param name="address">Address to the remote file, http, ftp etc...</param>
5757
''' <param name="destinationFileName">Name and path of file where download is saved.</param>
5858
''' <param name="showUI">Indicates whether or not to show a progress bar.</param>
59-
''' <returns><see langword="New"/> <see cref="ProgressDialog"/>.</returns>
59+
''' <returns>
60+
''' <see langword="New"/> <see cref="ProgressDialog"/> if InteractiveEnvironment <see langword="True"/>
61+
''' otherwise return <see langword="Nothing"/>.
62+
''' </returns>
6063
Friend Function GetProgressDialog(
6164
address As String,
6265
destinationFileName As String,
6366
showUI As Boolean) As ProgressDialog
6467

65-
If showUI AndAlso Environment.UserInteractive Then
68+
If InteractiveEnvironment(showUI) Then
6669
'Construct the local file. This will validate the full name and path
6770
Dim fullFilename As String = FileSystemUtils.NormalizeFilePath(
6871
path:=destinationFileName,
@@ -98,5 +101,9 @@ Namespace Microsoft.VisualBasic.Devices
98101
End Try
99102
End Function
100103

104+
Friend Function InteractiveEnvironment(showUI As Boolean) As Boolean
105+
Return showUI AndAlso Environment.UserInteractive
106+
End Function
107+
101108
End Module
102109
End Namespace

Diff for: src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Interaction.vb

+2-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ Namespace Microsoft.VisualBasic
250250
'Low-order 4 bits (0x000f), legal values: 0, 1, 2, 3, 4, 5
251251
' next 4 bits (0x00f0), legal values: 0, &H10, &H20, &H30, &H40
252252
' next 4 bits (0x0f00), legal values: 0, &H100, &H200
253-
If ((Buttons And &HFI) > MsgBoxStyle.RetryCancel) OrElse ((Buttons And &HF0I) > MsgBoxStyle.Information) _
253+
If ((Buttons And &HFI) > MsgBoxStyle.RetryCancel) _
254+
OrElse ((Buttons And &HF0I) > MsgBoxStyle.Information) _
254255
OrElse ((Buttons And &HF00I) > MsgBoxStyle.DefaultButton3) Then
255256
Buttons = MsgBoxStyle.OkOnly
256257
End If

Diff for: src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/MyServices/ClipboardProxy.vb

+18-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Imports System.Runtime.InteropServices
1212
Namespace Microsoft.VisualBasic.MyServices
1313

1414
''' <summary>
15-
''' A class that wraps System.Windows.Forms.Clipboard so that
15+
''' A class that wraps <see cref="Clipboard"/> so that
1616
''' a clipboard can be instanced.
1717
''' </summary>
1818
<EditorBrowsable(EditorBrowsableState.Never)>
@@ -25,22 +25,23 @@ Namespace Microsoft.VisualBasic.MyServices
2525
End Sub
2626

2727
''' <summary>
28-
''' Removes everything from the clipboard.
28+
''' Removes everything from the <see cref="Clipboard"/>.
2929
''' </summary>
3030
Public Sub Clear()
3131
Clipboard.Clear()
3232
End Sub
3333

3434
''' <summary>
35-
''' Indicates whether or not there's an audio stream saved to the clipboard.
35+
''' Indicates whether or not there's an audio stream saved to the <see cref="Clipboard"/>.
3636
''' </summary>
3737
''' <returns><see langword="True"/> if an audio stream is available, otherwise <see langword="False"/>.</returns>
3838
Public Function ContainsAudio() As Boolean
3939
Return Clipboard.ContainsAudio()
4040
End Function
4141

4242
''' <summary>
43-
''' Indicates whether or not there is data on the clipboard in the passed in format.
43+
''' Indicates whether or not there is data on the <see cref="Clipboard"/> in the passed in format.
44+
''' or can be converted to that format.
4445
''' </summary>
4546
''' <param name="format"></param>
4647
''' <returns><see langword="True"/> if there's data in the passed in format, otherwise <see langword="False"/>.</returns>
@@ -57,23 +58,23 @@ Namespace Microsoft.VisualBasic.MyServices
5758
End Function
5859

5960
''' <summary>
60-
''' Indicate whether or not an image has been saved to the clipboard.
61+
''' Indicate whether or not an image has been saved to the <see cref="Clipboard"/>.
6162
''' </summary>
6263
''' <returns><see langword="True"/> if an image is available, otherwise <see langword="False"/>.</returns>
6364
Public Function ContainsImage() As Boolean
6465
Return Clipboard.ContainsImage()
6566
End Function
6667

6768
''' <summary>
68-
''' Indicates whether or not text is available on the clipboard.
69+
''' Indicates whether or not text is available on the <see cref="Clipboard"/>.
6970
''' </summary>
7071
''' <returns><see langword="True"/> if text is available, otherwise <see langword="False"/>.</returns>
7172
Public Function ContainsText() As Boolean
7273
Return Clipboard.ContainsText
7374
End Function
7475

7576
''' <summary>
76-
''' Indicates whether or not text is available on the clipboard in
77+
''' Indicates whether or not text is available on the <see cref="Clipboard"/> in
7778
''' the passed in format.
7879
''' </summary>
7980
''' <param name="format">The type of text being checked for.</param>
@@ -83,15 +84,15 @@ Namespace Microsoft.VisualBasic.MyServices
8384
End Function
8485

8586
''' <summary>
86-
''' Gets an audio stream from the clipboard.
87+
''' Gets an audio stream from the <see cref="Clipboard"/>.
8788
''' </summary>
88-
''' <returns>The audio stream as a Stream.</returns>
89+
''' <returns>The audio stream as a <see cref="Stream"/>.</returns>
8990
Public Function GetAudioStream() As Stream
9091
Return Clipboard.GetAudioStream()
9192
End Function
9293

9394
''' <summary>
94-
''' Gets data from the clipboard that's been saved in the passed in format.
95+
''' Gets data from the <see cref="Clipboard"/> that's been saved in the passed in format.
9596
''' </summary>
9697
''' <param name="format">The type of data being sought.</param>
9798
''' <returns>The data.</returns>
@@ -125,15 +126,15 @@ Namespace Microsoft.VisualBasic.MyServices
125126
End Function
126127

127128
''' <summary>
128-
''' Gets an Image from the clipboard.
129+
''' Retrieves an <see cref="Image"/> from the <see cref="Clipboard"/>.
129130
''' </summary>
130131
''' <returns>The image.</returns>
131132
Public Function GetImage() As Image
132133
Return Clipboard.GetImage()
133134
End Function
134135

135136
''' <summary>
136-
''' Gets text from the clipboard.
137+
''' Gets text from the <see cref="Clipboard"/>.
137138
''' </summary>
138139
''' <returns>The text as a String.</returns>
139140
Public Function GetText() As String
@@ -150,23 +151,23 @@ Namespace Microsoft.VisualBasic.MyServices
150151
End Function
151152

152153
''' <summary>
153-
''' Saves the passed in audio byte array to the clipboard.
154+
''' Saves the passed in audio byte array to the <see cref="Clipboard"/>.
154155
''' </summary>
155156
''' <param name="audioBytes">The byte array to be saved.</param>
156157
Public Sub SetAudio(audioBytes As Byte())
157158
Clipboard.SetAudio(audioBytes)
158159
End Sub
159160

160161
''' <summary>
161-
''' Saves the passed in audio stream to the clipboard.
162+
''' Saves the passed in audio stream to the <see cref="Clipboard"/>.
162163
''' </summary>
163-
''' <param name="audioStream">The stream to be saved.</param>
164+
''' <param name="audioStream">The <see cref="Stream"/> to be saved.</param>
164165
Public Sub SetAudio(audioStream As Stream)
165166
Clipboard.SetAudio(audioStream)
166167
End Sub
167168

168169
''' <summary>
169-
''' Saves the passed in data to the clipboard in the passed in format.
170+
''' Saves the passed in data to the <see cref="Clipboard"/> in the passed in format.
170171
''' </summary>
171172
''' <param name="format">The format in which to save the data.</param>
172173
''' <param name="data">The data to be saved.</param>
@@ -185,7 +186,7 @@ Namespace Microsoft.VisualBasic.MyServices
185186
End Sub
186187

187188
''' <summary>
188-
''' Saves the passed in file drop list to the clipboard.
189+
''' Saves the passed in file drop list to the <see cref="Clipboard"/>.
189190
''' </summary>
190191
''' <param name="filePaths">The file drop list as a <see cref="StringCollection"/>.</param>
191192
Public Sub SetFileDropList(filePaths As StringCollection)

Diff for: src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/TestUtilitiesTests.vb

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ Namespace Microsoft.VisualBasic.Forms.Tests
2323
testClass.Any.Should.BeTrue()
2424
End Sub
2525

26+
<WinFormsFact>
27+
Public Sub PathSeparatorDataIteratorTests()
28+
Dim testClass As New PathSeparatorTestData
29+
testClass.IEnumerable_GetEnumerator.Should.NotBeNull()
30+
testClass.Any.Should.BeTrue()
31+
End Sub
32+
2633
<WinFormsFact>
2734
Public Sub TimeTestDataIteratorTests()
2835
Dim testClass As New TimeTestData
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
' Licensed to the .NET Foundation under one or more agreements.
2+
' The .NET Foundation licenses this file to you under the MIT license.
3+
4+
Namespace Microsoft.VisualBasic.Forms.Tests
5+
6+
Public Class PathSeparatorTestData
7+
Implements IEnumerable(Of Object())
8+
9+
Public Iterator Function GetEnumerator() As IEnumerator(Of Object()) Implements IEnumerable(Of Object()).GetEnumerator
10+
Yield {IO.Path.DirectorySeparatorChar}
11+
Yield {IO.Path.AltDirectorySeparatorChar}
12+
End Function
13+
14+
Public Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
15+
Return GetEnumerator()
16+
End Function
17+
18+
End Class
19+
End Namespace

0 commit comments

Comments
 (0)