Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f2d1dec
Modernize ExceptionUtils
paul1956 Aug 24, 2024
8d1e1b4
Fix broken Time Tests
paul1956 Aug 24, 2024
9ea27ee
Fix broken Time Tests
paul1956 Aug 24, 2024
41ad20a
Fix GetArgumentExceptionWithArgNameTest_Succeed
paul1956 Aug 24, 2024
18ff68f
Apply using to FileLogTraceListener
paul1956 Aug 25, 2024
b792c71
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Aug 25, 2024
f978352
Remove usage of CompilerServices.Utils
paul1956 Aug 25, 2024
8a328d5
Sort Imports in Interaction.VB
paul1956 Aug 25, 2024
226de1d
Remove space on blank lines in MissingPropertySerializationConfigura…
paul1956 Aug 26, 2024
1158c07
Merge Master
paul1956 Aug 27, 2024
8d1455e
Add Collection("Sequential") Attribute to ControlTests
paul1956 Aug 27, 2024
03f815f
Remove Collection("Sequential") from ControlTests
paul1956 Aug 27, 2024
5440751
Rename ControlTests.vb to ControlInvokeTests.vb
paul1956 Aug 27, 2024
46c55b2
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Aug 27, 2024
f06c19c
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Aug 28, 2024
c93df87
Fix casing in MissingPropertySerializationConfigurationAnalyzerTest
paul1956 Aug 28, 2024
4963673
Fix comment is ControlInvokeTests
paul1956 Aug 29, 2024
9f3335d
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Aug 29, 2024
75fbba5
Fix Screen to be System.Windows.Forms.Screen
paul1956 Aug 30, 2024
f86d3d8
Clean up Computer Screen
paul1956 Aug 30, 2024
cb3fb7b
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Sep 2, 2024
218f428
Correct StackFrame in Comments
paul1956 Sep 3, 2024
1079c61
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Sep 5, 2024
ef56409
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Sep 5, 2024
5c2e5c8
Respond to PR feedback
paul1956 Sep 5, 2024
5dfec82
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Sep 5, 2024
a66e137
Correct Test Name
paul1956 Sep 5, 2024
0eb12aa
Improve Time tests
paul1956 Sep 5, 2024
369729b
Wrap long lines
paul1956 Sep 6, 2024
e275c6c
Shorted long lines in FileSystemProxy
paul1956 Sep 6, 2024
8072238
Sort FileSystemProxy
paul1956 Sep 6, 2024
308a127
Minor cleanup
paul1956 Sep 6, 2024
d44d99c
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Sep 6, 2024
d9c7312
Update src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows…
paul1956 Sep 6, 2024
081d039
Respond to PR Feedback
paul1956 Sep 6, 2024
d8e68b5
Fix Merge Conflict
paul1956 Sep 6, 2024
246f911
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Sep 9, 2024
3ff50cc
Merge branch 'master' into Modernize-ExceptionUtils
paul1956 Sep 10, 2024
a831f48
Revert TimeTestData based on PR Feedback
paul1956 Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

Imports System.Diagnostics.CodeAnalysis

<Assembly: SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification:="Compat", Scope:="member", Target:="~M:Microsoft.VisualBasic.CompilerServices.ExceptionUtils.BuildException(System.Int32,System.String,System.Boolean@)~System.Exception")>
<Assembly: SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification:="Compat", Scope:="member", Target:="~M:Microsoft.VisualBasic.CompilerServices.ExceptionUtils.VbMakeException(System.Int32)~System.Exception")>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.

Imports System.Runtime.CompilerServices

<Assembly: InternalsVisibleTo("Microsoft.VisualBasic.Forms.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor Author

@paul1956 paul1956 Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean the public key, it does not work without it. Possibly because there are 2 project namespaces with the same name, 1 in VB and another in C#. I opened an issue #11031 about this last year and it’s still open.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, @KlausLoeffelmann could you provide guidance on whether this is the preferred approach for writing tests which need visibility?

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Imports System.ComponentModel

Imports VbUtils = Microsoft.VisualBasic.CompilerServices.Utils
Imports VbUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils

Namespace Microsoft.VisualBasic.ApplicationServices

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Imports System.ComponentModel

Imports VbUtils = Microsoft.VisualBasic.CompilerServices.Utils
Imports VbUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils

Namespace Microsoft.VisualBasic.ApplicationServices

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Imports System.Threading
Imports System.Windows.Forms
Imports System.Windows.Forms.Analyzers.Diagnostics

Imports Utils = Microsoft.VisualBasic.CompilerServices.Utils
Imports VbUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils

Namespace Microsoft.VisualBasic.ApplicationServices
Expand Down Expand Up @@ -310,7 +309,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices

' Allow for the case where they set splash screen = nothing and mainForm is currently nothing.
If value IsNot Nothing AndAlso value Is _appContext.MainForm Then
Throw New ArgumentException(Utils.GetResourceString(SR.AppModel_SplashAndMainFormTheSame))
Throw New ArgumentException(VbUtils.GetResourceString(SR.AppModel_SplashAndMainFormTheSame))
End If

_splashScreen = value
Expand All @@ -329,7 +328,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
Throw VbUtils.GetArgumentNullException("MainForm", SR.General_PropertyNothing, "MainForm")
End If
If value Is _splashScreen Then
Throw New ArgumentException(Utils.GetResourceString(SR.AppModel_SplashAndMainFormTheSame))
Throw New ArgumentException(VbUtils.GetResourceString(SR.AppModel_SplashAndMainFormTheSame))
End If
_appContext.MainForm = value
End Set
Expand Down Expand Up @@ -803,7 +802,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices

RaiseEvent ApplyApplicationDefaults(Me, applicationDefaultsEventArgs)

If (applicationDefaultsEventArgs.Font IsNot Nothing) Then
If applicationDefaultsEventArgs.Font IsNot Nothing Then
Application.SetDefaultFont(applicationDefaultsEventArgs.Font)
End If

Expand All @@ -828,7 +827,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
Debug.Assert(dpiSetResult, "We could net set the HighDpiMode.")

' Now, let's set VisualStyles and ColorMode:
If (_enableVisualStyles) Then
If _enableVisualStyles Then
Application.EnableVisualStyles()
End If

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,13 @@
' The .NET Foundation licenses this file to you under the MIT license.

Imports System.Runtime.InteropServices
Imports VbUtils = Microsoft.VisualBasic.CompilerServices.Utils
Imports System.Threading

Namespace Microsoft.VisualBasic.CompilerServices

' Implements error utilities for Basic
Friend Module ExceptionUtils

Friend Function BuildException(
resourceId As Integer,
description As String,
ByRef vbDefinedError As Boolean) As Exception

vbDefinedError = True

Select Case resourceId

Case VbErrors.None

Case VbErrors.FileNotFound
Return New IO.FileNotFoundException(description)

Case VbErrors.PermissionDenied
Return New IO.IOException(description)

Case Else
'Fall below to default
vbDefinedError = False
Return New Exception(description)
End Select

vbDefinedError = False
Return New Exception(description)

End Function

''' <summary>
''' Returns a new instance of <see cref="ArgumentException"/> with the message from resource file and the Exception.ArgumentName property set.
''' </summary>
Expand All @@ -50,7 +22,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
resourceID As String,
ParamArray placeHolders() As String) As ArgumentException

Return New ArgumentException(VbUtils.GetResourceString(resourceID, placeHolders), argumentName)
Return New ArgumentException(GetResourceString(resourceID, placeHolders), argumentName)
End Function

''' <summary>
Expand All @@ -60,7 +32,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
''' <returns>A new instance of <see cref="ArgumentNullException"/>.</returns>
Friend Function GetArgumentNullException(argumentName As String) As ArgumentNullException

Return New ArgumentNullException(argumentName, VbUtils.GetResourceString(SR.General_ArgumentNullException))
Return New ArgumentNullException(argumentName, GetResourceString(SR.General_ArgumentNullException))
End Function

''' <summary>
Expand All @@ -75,7 +47,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
resourceID As String,
ParamArray placeHolders() As String) As ArgumentNullException

Return New ArgumentNullException(argumentName, VbUtils.GetResourceString(resourceID, placeHolders))
Return New ArgumentNullException(argumentName, GetResourceString(resourceID, placeHolders))
End Function

''' <summary>
Expand All @@ -88,7 +60,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
resourceID As String,
ParamArray placeHolders() As String) As IO.DirectoryNotFoundException

Return New IO.DirectoryNotFoundException(VbUtils.GetResourceString(resourceID, placeHolders))
Return New IO.DirectoryNotFoundException(GetResourceString(resourceID, placeHolders))
End Function

''' <summary>
Expand All @@ -103,7 +75,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
resourceID As String,
ParamArray placeHolders() As String) As IO.FileNotFoundException

Return New IO.FileNotFoundException(VbUtils.GetResourceString(resourceID, placeHolders), fileName)
Return New IO.FileNotFoundException(GetResourceString(resourceID, placeHolders), fileName)
End Function

''' <summary>
Expand All @@ -116,7 +88,7 @@ Namespace Microsoft.VisualBasic.CompilerServices
resourceID As String,
ParamArray placeHolders() As String) As InvalidOperationException

Return New InvalidOperationException(VbUtils.GetResourceString(resourceID, placeHolders))
Return New InvalidOperationException(GetResourceString(resourceID, placeHolders))
End Function

''' <summary>
Expand All @@ -129,7 +101,19 @@ Namespace Microsoft.VisualBasic.CompilerServices
resourceID As String,
ParamArray placeHolders() As String) As IO.IOException

Return New IO.IOException(VbUtils.GetResourceString(resourceID, placeHolders))
Return New IO.IOException(GetResourceString(resourceID, placeHolders))
End Function

Friend Function GetResourceString(
resourceKey As String,
ParamArray args() As String) As String

Return String.Format(Thread.CurrentThread.CurrentCulture, resourceKey, args)
End Function

Friend Function GetResourceString(resourceId As VbErrors) As String
Dim id As String = $"ID{CStr(resourceId)}"
Return SR.GetResourceString(id, id)
End Function

''' <summary>
Expand All @@ -143,29 +127,27 @@ Namespace Microsoft.VisualBasic.CompilerServices
resourceID As String,
ParamArray placeHolders() As String) As ComponentModel.Win32Exception

Return New ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), VbUtils.GetResourceString(resourceID, placeHolders))
Return New ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), GetResourceString(resourceID, placeHolders))
End Function

Friend Function VbMakeException(hr As Integer) As Exception
Dim sMsg As String
Friend Function VbMakeException(resourceId As Integer) As Exception
Dim description As String = String.Empty

If hr > 0 AndAlso hr <= &HFFFFI Then
sMsg = VbUtils.GetResourceString(CType(hr, VbErrors))
Else
sMsg = String.Empty
If resourceId > 0 AndAlso resourceId <= &HFFFFI Then
description = GetResourceString(DirectCast(resourceId, VbErrors))
End If
VbMakeException = VbMakeExceptionEx(hr, sMsg)
End Function

Friend Function VbMakeExceptionEx(number As Integer, sMsg As String) As Exception
Dim vBDefinedError As Boolean
Select Case resourceId

VbMakeExceptionEx = BuildException(number, sMsg, vBDefinedError)
Case VbErrors.FileNotFound
Return New IO.FileNotFoundException(description)

If vBDefinedError Then
' .NET Framework implementation calls:
' Err().SetUnmappedError(number)
End If
Case VbErrors.PermissionDenied
Return New IO.IOException(description)

Case Else
Return New Exception(description)
End Select

End Function

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
' The .NET Foundation licenses this file to you under the MIT license.

Namespace Microsoft.VisualBasic

''' <summary>
''' Enum for three ways to play a .wav file.
''' </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Namespace Microsoft.VisualBasic.Devices
Private _sound As Media.SoundPlayer

''' <summary>
''' Creates a new Audio object.
''' Creates a new <see cref="Audio"/> object.
''' </summary>
Public Sub New()
End Sub
Expand All @@ -32,10 +32,13 @@ Namespace Microsoft.VisualBasic.Devices
End Sub

''' <summary>
''' Gets the full name and path for the file. Throws if unable to get full name and path.
''' Gets the full name and path for the file.
''' </summary>
''' <param name="location">The filename being tested.</param>
''' <returns>A full name and path of the file.</returns>
''' <exception cref="ArgumentNullException">
''' If location is <see langword="Nothing"/> or <see cref="String.Empty"/>.
''' </exception>
Private Shared Function ValidateFilename(location As String) As String
If String.IsNullOrEmpty(location) Then
Throw VbUtils.GetArgumentNullException(NameOf(location))
Expand All @@ -45,7 +48,7 @@ Namespace Microsoft.VisualBasic.Devices
End Function

''' <summary>
''' Plays the passed in SoundPlayer in the passed in mode.
''' Plays the passed in <see cref="Media.SoundPlayer"/> in the passed in <see cref="AudioPlayMode"/>.
''' </summary>
''' <param name="sound">The SoundPlayer to play.</param>
''' <param name="mode">The mode in which to play the sound.</param>
Expand Down Expand Up @@ -106,8 +109,9 @@ Namespace Microsoft.VisualBasic.Devices
''' <summary>
''' Plays a Byte array representation of a .wav file in the passed in mode.
''' </summary>
''' <param name="data">The array representing the .wav file.</param>
''' <param name="data">The <see langword="Byte"/> array representing the .wav file.</param>
''' <param name="playMode">The mode in which the array should be played.</param>
''' <exception cref="ArgumentNullException">if data is <see langword="Nothing"/>.</exception>
Public Sub Play(data() As Byte, playMode As AudioPlayMode)
If data Is Nothing Then
Throw VbUtils.GetArgumentNullException(NameOf(data))
Expand All @@ -120,10 +124,11 @@ Namespace Microsoft.VisualBasic.Devices
End Sub

''' <summary>
''' Plays a stream representation of a .wav file in the passed in mode.
''' Plays a <see cref="Stream"/> representation of a .wav file in the passed in <see cref="AudioPlayMode"/>.
''' </summary>
''' <param name="stream">The stream representing the .wav file.</param>
''' <param name="playMode">The mode in which the stream should be played.</param>
''' <exception cref="ArgumentNullException">if stream is <see langword="Nothing"/>.</exception>
Public Sub Play(stream As Stream, playMode As AudioPlayMode)
ValidateAudioPlayModeEnum(playMode, NameOf(playMode))
If stream Is Nothing Then
Expand All @@ -134,10 +139,11 @@ Namespace Microsoft.VisualBasic.Devices
End Sub

''' <summary>
''' Plays a system messageBeep sound.
''' Plays a system sound.
''' </summary>
''' <param name="systemSound">The sound to be played.</param>
''' <remarks>Plays the sound asynchronously.</remarks>
''' <exception cref="ArgumentNullException">if systemSound is <see langword="Nothing"/>.</exception>
Public Sub PlaySystemSound(systemSound As Media.SystemSound)
If systemSound Is Nothing Then
Throw VbUtils.GetArgumentNullException(NameOf(systemSound))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.

Imports System.Windows.Forms
Imports Microsoft.VisualBasic.MyServices

Namespace Microsoft.VisualBasic.Devices
Expand Down Expand Up @@ -29,10 +28,13 @@ Namespace Microsoft.VisualBasic.Devices

'Lazy initialized cache for the clipboard class. (proxies can be shared - they have no state)
Private Shared s_clipboard As ClipboardProxy

'Lazy initialized cache for the Keyboard class. SHARED because Keyboard behaves as a ReadOnly singleton class
Private Shared s_keyboardInstance As Keyboard

'Lazy initialized cache for the Mouse class. SHARED because Mouse behaves as a ReadOnly singleton class
Private Shared s_mouse As Mouse

'Lazy initialized cache for the Audio class.
Private _audio As Audio

Expand Down Expand Up @@ -92,12 +94,12 @@ Namespace Microsoft.VisualBasic.Devices
''' This property returns the primary display screen.
''' </summary>
''' <value>A <see cref="System.Windows.Forms.Screen"/> object as the primary screen.</value>
Public ReadOnly Property Screen() As Screen
Public ReadOnly Property Screen() As System.Windows.Forms.Screen
Get
'Don't cache this. The Screen class responds to display resolution changes by nulling out AllScreens, which
'PrimaryScreen relies on to find the primary. So we always need to access the latest PrimaryScreen so we
'will get the current resolution reported.
Return Screen.PrimaryScreen
Return System.Windows.Forms.Screen.PrimaryScreen
End Get
End Property

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
' The .NET Foundation licenses this file to you under the MIT license.

Namespace Microsoft.VisualBasic.Devices

Partial Public Class ComputerInfo

''' <summary>
Expand Down
Loading