diff --git a/Winforms.sln b/Winforms.sln
index f668280e9ee..d44bd5ea14b 100644
--- a/Winforms.sln
+++ b/Winforms.sln
@@ -111,7 +111,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesignSurfaceExt", "src\Sys
EndProject
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Microsoft.VisualBasic.Forms.Tests", "src\Microsoft.VisualBasic.Forms\tests\UnitTests\Microsoft.VisualBasic.Forms.Tests.vbproj", "{FC75CB54-D8D0-4B41-9A4D-9F862F34A02D}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Common.TestUtilities", "src\Common\tests\TestUtilities\System.Windows.Forms.Common.TestUtilities.csproj", "{05FD23CE-60AE-44A8-8DD6-1688F04BE385}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.Windows.Core.TestUtilities", "src\Common\tests\TestUtilities\System.Private.Windows.Core.TestUtilities.csproj", "{05FD23CE-60AE-44A8-8DD6-1688F04BE385}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Windows.Forms.Analyzers", "src\System.Windows.Forms.Analyzers\src\System.Windows.Forms.Analyzers.csproj", "{3596BDE6-B211-4BE7-810D-DC7A4315E296}"
EndProject
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index fbb38a9782e..cc9407397c1 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -7,213 +7,213 @@ Note: if the Uri is a new place, you will need to add a subscription from that p
-->
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/runtime
- 3648d836eb2e8ef6aadd3b8b06f90ed130e787c9
+ a9ca41321284c0d1e423bfc240e9c9f8be970b8b
-
+
https://github.com/dotnet/arcade
- ee7a468d815a3401b842e23ee336dd9d679d973d
+ 1818ed2babf890a1cd62fa96a1f03abdada2d003
-
+
https://github.com/dotnet/arcade
- ee7a468d815a3401b842e23ee336dd9d679d973d
+ 1818ed2babf890a1cd62fa96a1f03abdada2d003
-
+
https://github.com/dotnet/arcade
- ee7a468d815a3401b842e23ee336dd9d679d973d
+ 1818ed2babf890a1cd62fa96a1f03abdada2d003
-
+
https://github.com/dotnet/arcade
- ee7a468d815a3401b842e23ee336dd9d679d973d
+ 1818ed2babf890a1cd62fa96a1f03abdada2d003
-
+
https://github.com/dotnet/arcade
- ee7a468d815a3401b842e23ee336dd9d679d973d
+ 1818ed2babf890a1cd62fa96a1f03abdada2d003
-
+
https://github.com/dotnet/arcade
- ee7a468d815a3401b842e23ee336dd9d679d973d
+ 1818ed2babf890a1cd62fa96a1f03abdada2d003
diff --git a/eng/Versions.props b/eng/Versions.props
index f829c131aaf..5da27a99a12 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -13,37 +13,37 @@
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
5.0.0-preview.7.20320.5
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
6.1.0-preview.1.24511.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
- 10.0.0-alpha.1.24526.1
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
+ 10.0.0-alpha.1.24551.5
@@ -56,9 +56,9 @@
- 10.0.0-beta.24525.3
- 10.0.0-beta.24525.3
- 10.0.0-beta.24525.3
+ 10.0.0-beta.24551.1
+ 10.0.0-beta.24551.1
+ 10.0.0-beta.24551.1
17.4.0-preview-20220707-01
diff --git a/global.json b/global.json
index 6067bba3cb2..d67e89bed74 100644
--- a/global.json
+++ b/global.json
@@ -14,11 +14,11 @@
"version": "9.0.100-rc.2.24474.12"
},
"msbuild-sdks": {
- "Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.24525.3",
- "Microsoft.DotNet.CMake.Sdk": "10.0.0-beta.24525.3",
- "Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.24525.3",
+ "Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.24551.1",
+ "Microsoft.DotNet.CMake.Sdk": "10.0.0-beta.24551.1",
+ "Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.24551.1",
"FIX-85B6-MERGE-9C38-CONFLICT": "1.0.0",
- "Microsoft.NET.Sdk.IL": "10.0.0-alpha.1.24526.1"
+ "Microsoft.NET.Sdk.IL": "10.0.0-alpha.1.24551.5"
},
"native-tools": {
"cmake": "latest"
diff --git a/pkg/Microsoft.Private.Winforms/Microsoft.Private.Winforms.csproj b/pkg/Microsoft.Private.Winforms/Microsoft.Private.Winforms.csproj
index afbc33ac246..af01e8c7b11 100644
--- a/pkg/Microsoft.Private.Winforms/Microsoft.Private.Winforms.csproj
+++ b/pkg/Microsoft.Private.Winforms/Microsoft.Private.Winforms.csproj
@@ -82,7 +82,7 @@
-
+
diff --git a/src/Common/tests/TestUtilities/AppContextSwitchNames.cs b/src/Common/tests/TestUtilities/AppContextSwitchNames.cs
index 376f932e891..a6592b061b0 100644
--- a/src/Common/tests/TestUtilities/AppContextSwitchNames.cs
+++ b/src/Common/tests/TestUtilities/AppContextSwitchNames.cs
@@ -7,26 +7,6 @@ namespace System;
public static class AppContextSwitchNames
{
- ///
- /// The switch that controls whether AnchorLayoutV2 feature is enabled.
- ///
- public const string AnchorLayoutV2
- = "System.Windows.Forms.AnchorLayoutV2";
-
- ///
- /// The switch that controls whether the parent font
- /// (as set by
- /// or by the parent control or form's font) is applied to menus.
- ///
- public const string ApplyParentFontToMenus
- = "System.Windows.Forms.ApplyParentFontToMenus";
-
- ///
- /// The switch that controls whether or not the DataGridView starts its UI row count at zero.
- ///
- public const string DataGridViewUIAStartRowCountAtZero
- = "System.Windows.Forms.DataGridViewUIAStartRowCountAtZero";
-
///
/// The switch that controls whether or not the is enabled.
///
@@ -38,30 +18,4 @@ public const string EnableUnsafeBinaryFormatterSerialization
///
public const string LocalAppContext_DisableCaching
= "TestSwitch.LocalAppContext.DisableCaching";
-
- ///
- /// The switch that controls whether UIA notifications are raised.
- ///
- public const string NoClientNotifications
- = "Switch.System.Windows.Forms.AccessibleObject.NoClientNotifications";
-
- ///
- /// The switch that controls whether to scale the top level form min/max size for dpi.
- ///
- public const string ScaleTopLevelFormMinMaxSizeForDpi
- = "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi";
-
- ///
- /// The switch that controls whether certificates are checked against the certificate authority revocation list.
- /// If true, revoked certificates will not be accepted by WebRequests and WebClients as valid.
- /// Otherwise, revoked certificates will be accepted as valid.
- ///
- public const string ServicePointManagerCheckCrl
- = "System.Windows.Forms.ServicePointManagerCheckCrl";
-
- ///
- /// The switch that controls whether the TreeNodeCollection will insert nodes in the sorted order.
- ///
- public const string TreeNodeCollectionAddRangeRespectsSortOrder
- = "System.Windows.Forms.ApplyParentFontToMenus";
}
diff --git a/src/Common/tests/TestUtilities/BinarySerialization.cs b/src/Common/tests/TestUtilities/BinarySerialization.cs
index 4bf86304b5d..cbc0fa3e6b4 100644
--- a/src/Common/tests/TestUtilities/BinarySerialization.cs
+++ b/src/Common/tests/TestUtilities/BinarySerialization.cs
@@ -10,6 +10,10 @@ namespace System;
public static class BinarySerialization
{
+ ///
+ /// Ensures the list of types marked as serializable under matches .
+ /// If not, is thrown.
+ ///
public static void EnsureSerializableAttribute(Assembly assemblyUnderTest, HashSet serializableTypes)
{
foreach (Type type in assemblyUnderTest.GetTypes())
@@ -50,22 +54,24 @@ public static void EnsureSerializableAttribute(Assembly assemblyUnderTest, HashS
}
}
+ ///
+ /// Binary deserializes a base 64 string to . is binary
+ /// deserialized with with taken into account.
+ ///
#pragma warning disable SYSLIB0050 // Type or member is obsolete
- public static T EnsureDeserialize(string blob)
+ public static T EnsureDeserialize(string blob, FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
{
- object @object = FromBase64String(blob);
+ object @object = FromBase64String(blob, assemblyStyle);
Assert.NotNull(@object);
return Assert.IsType(@object);
- static object FromBase64String(string base64String,
- FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
+ static object FromBase64String(string base64String, FormatterAssemblyStyle assemblyStyle)
{
byte[] raw = Convert.FromBase64String(base64String);
return FromByteArray(raw, assemblyStyle);
}
- static object FromByteArray(byte[] raw,
- FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
+ static object FromByteArray(byte[] raw, FormatterAssemblyStyle assemblyStyle)
{
#pragma warning disable SYSLIB0011 // Type or member is obsolete
// cs/binary-formatter-without-binder
@@ -82,14 +88,18 @@ static object FromByteArray(byte[] raw,
}
}
+ ///
+ /// Returns a base 64 string of the binary serialized .
+ /// is binary serialized using
+ /// with taken into account.
+ ///
public static string ToBase64String(object @object,
FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
{
byte[] raw = ToByteArray(@object, assemblyStyle);
return Convert.ToBase64String(raw);
- static byte[] ToByteArray(object obj,
- FormatterAssemblyStyle assemblyStyle = FormatterAssemblyStyle.Simple)
+ static byte[] ToByteArray(object obj, FormatterAssemblyStyle assemblyStyle)
{
#pragma warning disable SYSLIB0011 // Type or member is obsolete
// cs/binary-formatter-without-binder
diff --git a/src/Common/tests/TestUtilities/CommonTestHelper.cs b/src/Common/tests/TestUtilities/CommonTestHelper.cs
index 355678ea0a8..1225f3c538d 100644
--- a/src/Common/tests/TestUtilities/CommonTestHelper.cs
+++ b/src/Common/tests/TestUtilities/CommonTestHelper.cs
@@ -4,7 +4,7 @@
using System.ComponentModel.Design.Serialization;
using System.Drawing;
-namespace System.Windows.Forms.TestUtilities;
+namespace System.Private.Windows.Core.TestUtilities;
public static class CommonTestHelper
{
diff --git a/src/Common/tests/TestUtilities/FileCleanupTestBase.cs b/src/Common/tests/TestUtilities/FileCleanupTestBase.cs
index a3b36d5f5a0..c54cc8a011e 100644
--- a/src/Common/tests/TestUtilities/FileCleanupTestBase.cs
+++ b/src/Common/tests/TestUtilities/FileCleanupTestBase.cs
@@ -3,6 +3,9 @@
namespace System;
+///
+/// Creates a test directory path and cleans it up when test class finishes execution.
+///
public abstract class FileCleanupTestBase : IDisposable
{
private string? _testDirectory;
diff --git a/src/Common/tests/TestUtilities/System.Windows.Forms.Common.TestUtilities.csproj b/src/Common/tests/TestUtilities/System.Private.Windows.Core.TestUtilities.csproj
similarity index 81%
rename from src/Common/tests/TestUtilities/System.Windows.Forms.Common.TestUtilities.csproj
rename to src/Common/tests/TestUtilities/System.Private.Windows.Core.TestUtilities.csproj
index 191fd09b2ad..2585fb96851 100644
--- a/src/Common/tests/TestUtilities/System.Windows.Forms.Common.TestUtilities.csproj
+++ b/src/Common/tests/TestUtilities/System.Private.Windows.Core.TestUtilities.csproj
@@ -1,9 +1,11 @@
- System.Windows.Forms.Common.TestUtilities
+ System.Private.Windows.Core.TestUtilities
true
System
enable
+ true
+ false
diff --git a/src/Common/tests/TestUtilities/TempFile.cs b/src/Common/tests/TestUtilities/TempFile.cs
index c8f6368779c..d8bff758fbe 100644
--- a/src/Common/tests/TestUtilities/TempFile.cs
+++ b/src/Common/tests/TestUtilities/TempFile.cs
@@ -6,8 +6,8 @@
namespace System.IO;
///
-/// Represents a temporary file. Creating an instance creates a file at the specified path,
-/// and disposing the instance deletes the file.
+/// Represents a temporary file. Creating an instance creates a file at the specified path,
+/// and disposing the instance deletes the file.
///
///
///
diff --git a/src/Common/tests/TestUtilities/TestIncludeType.cs b/src/Common/tests/TestUtilities/TestIncludeType.cs
index f65421e8124..1291be5d380 100644
--- a/src/Common/tests/TestUtilities/TestIncludeType.cs
+++ b/src/Common/tests/TestUtilities/TestIncludeType.cs
@@ -1,8 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-namespace System.Windows.Forms.TestUtilities;
+namespace System.Private.Windows.Core.TestUtilities;
+///
+/// Specifies what type of test data to include in the . This is
+/// used in
+///
[Flags]
public enum TestIncludeType
{
diff --git a/src/Common/tests/TestUtilities/ThreadCultureChange.cs b/src/Common/tests/TestUtilities/ThreadCultureChange.cs
index 715586673af..57d02d3a1b8 100644
--- a/src/Common/tests/TestUtilities/ThreadCultureChange.cs
+++ b/src/Common/tests/TestUtilities/ThreadCultureChange.cs
@@ -5,6 +5,9 @@
namespace System;
+///
+/// Facilitates temporarily changing the and .
+///
public sealed class ThreadCultureChange : IDisposable
{
private readonly CultureInfo _origCulture = CultureInfo.CurrentCulture;
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.Availability.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.Availability.vb
new file mode 100644
index 00000000000..40c6d50fd5b
--- /dev/null
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.Availability.vb
@@ -0,0 +1,155 @@
+' Licensed to the .NET Foundation under one or more agreements.
+' The .NET Foundation licenses this file to you under the MIT license.
+
+Imports System.ComponentModel
+Imports System.Security
+Imports System.Threading
+
+Imports NetInfoAlias = System.Net.NetworkInformation
+
+Namespace Microsoft.VisualBasic.Devices
+
+
+ Public Delegate Sub NetworkAvailableEventHandler(sender As Object, e As NetworkAvailableEventArgs)
+
+ Partial Public Class Network
+
+ ' Object for syncing
+ Private ReadOnly _syncObject As New Object()
+
+ ' Indicates last known connection state
+ Private _connected As Boolean
+
+ ' Used for marshalling the network address changed event to the foreground thread
+ Private _networkAvailabilityChangedCallback As SendOrPostCallback
+
+ ' Holds the listeners to our NetworkAvailability changed event
+ Private _networkAvailabilityEventHandlers As List(Of NetworkAvailableEventHandler)
+
+ Private _synchronizationContext As SynchronizationContext
+
+ '''
+ ''' Indicates whether or not the local machine is connected to an IP network.
+ '''
+ '''
+ ''' if connected,
+ ''' otherwise .
+ '''
+ Public ReadOnly Property IsAvailable() As Boolean
+ Get
+ Return NetInfoAlias.NetworkInterface.GetIsNetworkAvailable()
+ End Get
+ End Property
+
+ '''
+ ''' fired when connected to the network.
+ '''
+ ''' Has no meaning for this event.
+ ''' Has no meaning for this event.
+ Public Custom Event NetworkAvailabilityChanged As NetworkAvailableEventHandler
+ ' This is a custom event because we want to hook up
+ ' the NetworkAvailabilityChanged event only if the user writes a handler for it.
+ ' The reason being that it is very expensive to handle and kills our application startup perf.
+ AddHandler(handler As NetworkAvailableEventHandler)
+
+ ' Set the current state of connectedness, swallow known exceptions
+ ' since user won't be able to correct problem
+ Try
+ _connected = IsAvailable
+ Catch ex As SecurityException
+ Return
+ Catch ex As PlatformNotSupportedException
+ Return
+ End Try
+ ' We don't want our event firing before we've finished setting up the infrastructure.
+ ' Also, need to assure there are no races in here so we don't hook up the OS listener twice, etc.
+ SyncLock _syncObject
+ If _networkAvailabilityEventHandlers Is Nothing Then
+ _networkAvailabilityEventHandlers = New List(Of NetworkAvailableEventHandler)
+ End If
+ _networkAvailabilityEventHandlers.Add(handler)
+
+ ' Only setup the event Marshalling infrastructure once
+ If _networkAvailabilityEventHandlers.Count = 1 Then
+ ' The async operation posts to this delegate
+ _networkAvailabilityChangedCallback = New SendOrPostCallback(
+ AddressOf NetworkAvailabilityChangedHandler)
+
+ If AsyncOperationManager.SynchronizationContext IsNot Nothing Then
+ ' We need to hang on to the synchronization context associated
+ ' with the thread the network object is created on
+ _synchronizationContext = AsyncOperationManager.SynchronizationContext
+ Try
+ ' Exceptions are thrown if the user isn't an admin.
+ ' Listen to the OS event
+ AddHandler NetInfoAlias.NetworkChange.NetworkAddressChanged,
+ New NetInfoAlias.NetworkAddressChangedEventHandler(
+ AddressOf OS_NetworkAvailabilityChangedListener)
+ Catch ex As PlatformNotSupportedException
+ Catch ex As NetInfoAlias.NetworkInformationException
+ End Try
+ End If
+ End If
+ End SyncLock
+ End AddHandler
+
+ RemoveHandler(handler As NetworkAvailableEventHandler)
+ If _networkAvailabilityEventHandlers IsNot Nothing AndAlso
+ _networkAvailabilityEventHandlers.Count > 0 Then
+
+ _networkAvailabilityEventHandlers.Remove(handler)
+ ' Last one to leave, turn out the lights...
+ If _networkAvailabilityEventHandlers.Count = 0 Then
+ ' Listen to the OS event
+ RemoveHandler NetInfoAlias.NetworkChange.NetworkAddressChanged,
+ New NetInfoAlias.NetworkAddressChangedEventHandler(
+ AddressOf OS_NetworkAvailabilityChangedListener)
+
+ ' Stop listening to network change events since nobody is listening to us anymore
+ DisconnectListener()
+ End If
+ End If
+ End RemoveHandler
+
+ RaiseEvent(sender As Object, e As NetworkAvailableEventArgs)
+ If _networkAvailabilityEventHandlers IsNot Nothing Then
+ For Each handler As NetworkAvailableEventHandler In _networkAvailabilityEventHandlers
+ If handler IsNot Nothing Then handler.Invoke(sender, e)
+ Next
+ End If
+ End RaiseEvent
+ End Event
+
+ ' Listens to the AddressChanged event which will come on the same thread that this
+ ' class was created on (AsyncEventManager is responsible for getting the event here)
+ Private Sub NetworkAvailabilityChangedHandler(state As Object)
+ Dim connected As Boolean = IsAvailable
+ ' Fire an event only if the connected state has changed
+ If _connected <> connected Then
+ _connected = connected
+ RaiseEvent NetworkAvailabilityChanged(Me, New NetworkAvailableEventArgs(connected))
+ End If
+ End Sub
+
+ ' Listens to the AddressChanged event from the OS which comes in on an arbitrary thread
+ Private Sub OS_NetworkAvailabilityChangedListener(sender As Object, e As EventArgs)
+ SyncLock _syncObject
+ ' Ensure we don't handle events until after we've finished setting up the event
+ ' marshalling infrastructure. Don't call AsyncOperationManager.OperationSynchronizationContext.Post.
+ ' The reason we want to go through _synchronizationContext is that the
+ ' OperationSynchronizationContext is thread static. Since we are getting called on some random thread,
+ ' the context that was in place when the Network object was created won't be available
+ ' (it is on the original thread). To hang on to the original context associated with the thread
+ ' that the network object is created on, I use _synchronizationContext.
+ _synchronizationContext.Post(_networkAvailabilityChangedCallback, Nothing)
+ End SyncLock
+ End Sub
+
+ Friend Sub DisconnectListener()
+ RemoveHandler NetInfoAlias.NetworkChange.NetworkAddressChanged,
+ New NetInfoAlias.NetworkAddressChangedEventHandler(
+ AddressOf OS_NetworkAvailabilityChangedListener)
+ End Sub
+
+ End Class
+End Namespace
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.DownloadFile.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.DownloadFile.vb
new file mode 100644
index 00000000000..37b4776aa91
--- /dev/null
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.DownloadFile.vb
@@ -0,0 +1,382 @@
+' Licensed to the .NET Foundation under one or more agreements.
+' The .NET Foundation licenses this file to you under the MIT license.
+
+Imports System.Net
+Imports Microsoft.VisualBasic.CompilerServices
+Imports Microsoft.VisualBasic.FileIO
+Imports Microsoft.VisualBasic.MyServices.Internal
+
+Imports VbUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils
+
+Namespace Microsoft.VisualBasic.Devices
+
+ '''
+ ''' An object that allows easy access to some simple network properties and functionality.
+ '''
+ Partial Public Class Network
+
+ Public Sub New()
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' Address to the remote file, http, ftp etc...
+ ''' Name and path of file where download is saved.
+ Public Sub DownloadFile(address As String, destinationFileName As String)
+ DownloadFile(
+ address,
+ destinationFileName,
+ userName:=DEFAULT_USERNAME,
+ password:=DEFAULT_PASSWORD,
+ showUI:=False,
+ connectionTimeout:=DEFAULT_TIMEOUT,
+ overwrite:=False)
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' to the remote file.
+ ''' Name and path of file where download is saved.
+ Public Sub DownloadFile(address As Uri, destinationFileName As String)
+ DownloadFile(
+ address,
+ destinationFileName,
+ userName:=DEFAULT_USERNAME,
+ password:=DEFAULT_PASSWORD,
+ showUI:=False,
+ connectionTimeout:=DEFAULT_TIMEOUT,
+ overwrite:=False)
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' Address to the remote file, http, ftp etc...
+ ''' Name and path of file where download is saved.
+ ''' The name of the user performing the download.
+ ''' The user's password
+ Public Sub DownloadFile(
+ address As String,
+ destinationFileName As String,
+ userName As String,
+ password As String)
+
+ DownloadFile(
+ address,
+ destinationFileName,
+ userName,
+ password,
+ showUI:=False,
+ connectionTimeout:=DEFAULT_TIMEOUT,
+ overwrite:=False)
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' to the remote file.
+ ''' Name and path of file where download is saved.
+ ''' The name of the user performing the download.
+ ''' The user's password.
+ Public Sub DownloadFile(
+ address As Uri,
+ destinationFileName As String,
+ userName As String,
+ password As String)
+
+ DownloadFile(
+ address,
+ destinationFileName,
+ userName,
+ password,
+ showUI:=False,
+ connectionTimeout:=DEFAULT_TIMEOUT,
+ overwrite:=False)
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' Address to the remote file, http, ftp etc...
+ ''' Name and path of file where download is saved.
+ ''' The name of the user performing the download.
+ ''' The user's password.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ '''
+ ''' Indicates whether or not the file should be overwritten if local file already exists.
+ '''
+ Public Sub DownloadFile(
+ address As String,
+ destinationFileName As String,
+ userName As String,
+ password As String,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ overwrite As Boolean)
+
+ DownloadFile(
+ address,
+ destinationFileName,
+ userName,
+ password,
+ showUI,
+ connectionTimeout,
+ overwrite,
+ UICancelOption.ThrowException)
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' Address to the remote file, http, ftp etc...
+ ''' Name and path of file where download is saved.
+ ''' The name of the user performing the download.
+ ''' The user's password.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ '''
+ ''' Indicates whether or not the file should be overwritten
+ ''' if local file already exists.
+ '''
+ '''
+ ''' Indicates what to do if user cancels dialog (either or do nothing).
+ '''
+ Public Sub DownloadFile(
+ address As String,
+ destinationFileName As String,
+ userName As String,
+ password As String,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ overwrite As Boolean,
+ onUserCancel As UICancelOption)
+
+ ' We're safe from DownloadFile(Nothing, ...) due to overload failure (DownloadFile(String,...)
+ ' vs. DownloadFile(Uri,...)).
+ ' However, it is good practice to verify address before calling Trim.
+ If String.IsNullOrWhiteSpace(address) Then
+ Throw VbUtils.GetArgumentNullException(NameOf(address))
+ End If
+
+ Dim addressUri As Uri = GetUri(address.Trim())
+
+ ' Get network credentials
+ Dim networkCredentials As ICredentials = GetNetworkCredentials(userName, password)
+
+ DownloadFile(
+ address:=addressUri,
+ destinationFileName,
+ networkCredentials,
+ showUI,
+ connectionTimeout,
+ overwrite,
+ onUserCancel)
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' to the remote file,
+ '''
+ ''' Name and path of file where download is saved.
+ '''
+ ''' The name of the user performing the download.
+ ''' The user's password.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ '''
+ ''' Indicates whether or not the file should be overwritten if local file already exists.
+ '''
+ Public Sub DownloadFile(
+ address As Uri,
+ destinationFileName As String,
+ userName As String,
+ password As String,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ overwrite As Boolean)
+
+ DownloadFile(
+ address,
+ destinationFileName,
+ userName,
+ password,
+ showUI,
+ connectionTimeout,
+ overwrite,
+ UICancelOption.ThrowException)
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' to the remote file.
+ '''
+ ''' Name and path of file where download is saved.
+ '''
+ ''' The name of the user performing the download.
+ ''' The user's password.
+ ''' Indicates whether or not to show a progress bar.
+ '''
+ ''' Time allotted before giving up on a connection.
+ '''
+ '''
+ ''' Indicates whether or not the file should be overwritten
+ ''' if local file already exists.
+ '''
+ '''
+ ''' Indicates what to do if user cancels dialog (either or do nothing).
+ '''
+ Public Sub DownloadFile(
+ address As Uri,
+ destinationFileName As String,
+ userName As String,
+ password As String,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ overwrite As Boolean,
+ onUserCancel As UICancelOption)
+
+ ' Get network credentials
+ Dim networkCredentials As ICredentials = GetNetworkCredentials(userName, password)
+
+ DownloadFile(
+ address,
+ destinationFileName,
+ networkCredentials,
+ showUI,
+ connectionTimeout,
+ overwrite,
+ onUserCancel)
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' to the remote file.
+ '''
+ ''' Name and path of file where download is saved.
+ '''
+ '''
+ ''' The credentials of the user performing the download.
+ '''
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ '''
+ ''' Indicates whether or not the file should be overwritten
+ ''' if local file already exists.
+ '''
+ ''' Calls to all the other overloads will come through here.
+ Public Sub DownloadFile(
+ address As Uri,
+ destinationFileName As String,
+ networkCredentials As ICredentials,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ overwrite As Boolean)
+
+ DownloadFile(
+ address,
+ destinationFileName,
+ networkCredentials,
+ showUI,
+ connectionTimeout,
+ overwrite,
+ UICancelOption.ThrowException)
+
+ End Sub
+
+ '''
+ ''' Downloads a file from the network to the specified path.
+ '''
+ ''' to the remote file.
+ ''' Name and path of file where download is saved.
+ ''' The of the user performing the download.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ '''
+ ''' Indicates whether or not the file should be overwritten
+ ''' if local file already exists.
+ '''
+ '''
+ ''' Indicates what to do if user cancels dialog (either or do nothing).
+ '''
+ ''' Calls to all the other overloads will come through here.
+ Public Sub DownloadFile(
+ address As Uri,
+ destinationFileName As String,
+ networkCredentials As ICredentials,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ overwrite As Boolean,
+ onUserCancel As UICancelOption)
+
+ If connectionTimeout <= 0 Then
+ Throw VbUtils.GetArgumentExceptionWithArgName(NameOf(connectionTimeout), SR.Network_BadConnectionTimeout)
+ End If
+
+ If address Is Nothing Then
+ Throw VbUtils.GetArgumentNullException(NameOf(address))
+ End If
+
+ Using client As New WebClientExtended
+ client.Timeout = connectionTimeout
+
+ ' Don't use passive mode if we're showing UI
+ client.UseNonPassiveFtp = showUI
+
+ 'Construct the local file. This will validate the full name and path
+ Dim fullFilename As String = FileSystemUtils.NormalizeFilePath(destinationFileName, NameOf(destinationFileName))
+
+ ' Sometime a path that can't be parsed is normalized to the current directory. This makes sure we really
+ ' have a file and path
+ If IO.Directory.Exists(fullFilename) Then
+ Throw VbUtils.GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
+ End If
+
+ 'Throw if the file exists and the user doesn't want to overwrite
+ If IO.File.Exists(fullFilename) And Not overwrite Then
+ Throw New IO.IOException(VbUtils.GetResourceString(SR.IO_FileExists_Path, destinationFileName))
+ End If
+
+ ' Set credentials if we have any
+ If networkCredentials IsNot Nothing Then
+ client.Credentials = networkCredentials
+ End If
+
+ Dim dialog As ProgressDialog = GetProgressDialog(address.AbsolutePath, fullFilename, showUI)
+
+ 'Check to see if the target directory exists. If it doesn't, create it
+ Dim targetDirectory As String = IO.Path.GetDirectoryName(fullFilename)
+
+ ' Make sure we have a meaningful directory. If we don't, the destinationFileName is suspect
+ If String.IsNullOrEmpty(targetDirectory) Then
+ Throw VbUtils.GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
+ End If
+
+ If Not IO.Directory.Exists(targetDirectory) Then
+ IO.Directory.CreateDirectory(targetDirectory)
+ End If
+
+ 'Create the copier
+ Dim copier As New WebClientCopy(client, dialog)
+
+ 'Download the file
+ copier.DownloadFile(address, fullFilename)
+
+ 'Handle a dialog cancel
+ If showUI AndAlso Environment.UserInteractive Then
+ If onUserCancel = UICancelOption.ThrowException And dialog.UserCanceledTheDialog Then
+ Throw New OperationCanceledException()
+ End If
+ End If
+
+ End Using
+
+ End Sub
+
+ End Class
+End Namespace
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.Ping.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.Ping.vb
new file mode 100644
index 00000000000..2d149593d59
--- /dev/null
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.Ping.vb
@@ -0,0 +1,102 @@
+' Licensed to the .NET Foundation under one or more agreements.
+' The .NET Foundation licenses this file to you under the MIT license.
+
+Imports NetInfoAlias = System.Net.NetworkInformation
+Imports VbUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils
+
+Namespace Microsoft.VisualBasic.Devices
+
+ Partial Public Class Network
+
+ 'Size of Ping.exe buffer
+ Private Const BUFFER_SIZE As Integer = 32
+
+ ' Default timeout for Ping
+ Private Const DEFAULT_PING_TIMEOUT As Integer = 1000
+
+ 'Holds the buffer for pinging. We lazy initialize on first use
+ Private _pingBuffer() As Byte
+
+ '''
+ ''' A buffer for pinging. This imitates the buffer used by Ping.Exe.
+ '''
+ ''' A buffer.
+ Private ReadOnly Property PingBuffer() As Byte()
+ Get
+ If _pingBuffer Is Nothing Then
+ ReDim _pingBuffer(BUFFER_SIZE - 1)
+ For i As Integer = 0 To BUFFER_SIZE - 1
+ 'This is the same logic Ping.exe uses to fill it's buffer
+ Dim provider As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture
+ _pingBuffer(i) = Convert.ToByte(Asc("a"c) + (i Mod 23), provider)
+ Next
+ End If
+
+ Return _pingBuffer
+ End Get
+ End Property
+
+ '''
+ ''' Sends and receives a packet to and from the passed in address.
+ '''
+ '''
+ ''' True if ping was successful, otherwise False.
+ Public Function Ping(hostNameOrAddress As String) As Boolean
+ Return Ping(hostNameOrAddress, DEFAULT_PING_TIMEOUT)
+ End Function
+
+ '''
+ ''' Sends and receives a packet to and from the passed in Uri.
+ '''
+ ''' A Uri representing the host.
+ ''' True if ping was successful, otherwise False.
+ Public Function Ping(address As Uri) As Boolean
+ ' We're safe from Ping(Nothing, ...) due to overload failure (Ping(String,...) vs. Ping(Uri,...)).
+ ' However, it is good practice to verify address before calling address.Host.
+ If address Is Nothing Then
+ Throw VbUtils.GetArgumentNullException(NameOf(address))
+ End If
+ Return Ping(address.Host, DEFAULT_PING_TIMEOUT)
+ End Function
+
+ '''
+ ''' Sends and receives a packet to and from the passed in address.
+ '''
+ ''' The name of the host as a Url or IP Address.
+ ''' Time to wait before aborting ping.
+ ''' True if ping was successful, otherwise False.
+ Public Function Ping(hostNameOrAddress As String, timeout As Integer) As Boolean
+
+ ' Make sure a network is available
+ If Not IsAvailable Then
+ Throw VbUtils.GetInvalidOperationException(SR.Network_NetworkNotAvailable)
+ End If
+
+ Dim pingMaker As New NetInfoAlias.Ping
+ Dim reply As NetInfoAlias.PingReply = pingMaker.Send(
+ hostNameOrAddress,
+ timeout,
+ PingBuffer)
+ If reply.Status = NetInfoAlias.IPStatus.Success Then
+ Return True
+ End If
+ Return False
+ End Function
+
+ '''
+ ''' Sends and receives a packet to and from the passed in Uri.
+ '''
+ ''' A Uri representing the host.
+ ''' Time to wait before aborting ping.
+ ''' True if ping was successful, otherwise False.
+ Public Function Ping(address As Uri, timeout As Integer) As Boolean
+ ' We're safe from Ping(Nothing, ...) due to overload failure (Ping(String,...) vs. Ping(Uri,...)).
+ ' However, it is good practice to verify address before calling address.Host.
+ If address Is Nothing Then
+ Throw VbUtils.GetArgumentNullException(NameOf(address))
+ End If
+ Return Ping(address.Host, timeout)
+ End Function
+
+ End Class
+End Namespace
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.UploadFile.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.UploadFile.vb
new file mode 100644
index 00000000000..f012efecd59
--- /dev/null
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.UploadFile.vb
@@ -0,0 +1,319 @@
+' Licensed to the .NET Foundation under one or more agreements.
+' The .NET Foundation licenses this file to you under the MIT license.
+
+Imports System.Net
+Imports Microsoft.VisualBasic.CompilerServices
+Imports Microsoft.VisualBasic.FileIO
+Imports Microsoft.VisualBasic.MyServices.Internal
+
+Namespace Microsoft.VisualBasic.Devices
+
+ Partial Public Class Network
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' The full name and path of the host destination.
+ Public Sub UploadFile(sourceFileName As String, address As String)
+ UploadFile(
+ sourceFileName,
+ address,
+ userName:=DEFAULT_USERNAME,
+ password:=DEFAULT_PASSWORD,
+ showUI:=False,
+ connectionTimeout:=DEFAULT_TIMEOUT)
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' Uri representing the destination.
+ Public Sub UploadFile(sourceFileName As String, address As Uri)
+ UploadFile(
+ sourceFileName,
+ address,
+ userName:=DEFAULT_USERNAME,
+ password:=DEFAULT_PASSWORD,
+ showUI:=False,
+ connectionTimeout:=DEFAULT_TIMEOUT)
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' The full name and path of the host destination.
+ ''' The name of the user performing the upload.
+ ''' The user's password.
+ Public Sub UploadFile(
+ sourceFileName As String,
+ address As String,
+ userName As String,
+ password As String)
+
+ UploadFile(
+ sourceFileName,
+ address,
+ userName,
+ password,
+ showUI:=False,
+ connectionTimeout:=DEFAULT_TIMEOUT)
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' Uri representing the destination.
+ ''' The name of the user performing the upload.
+ ''' The user's password.
+ Public Sub UploadFile(
+ sourceFileName As String,
+ address As Uri,
+ userName As String,
+ password As String)
+
+ UploadFile(
+ sourceFileName,
+ address,
+ userName,
+ password,
+ showUI:=False,
+ connectionTimeout:=DEFAULT_TIMEOUT)
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' The full name and path of the host destination.
+ ''' The name of the user performing the upload.
+ ''' The user's password.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ Public Sub UploadFile(
+ sourceFileName As String,
+ address As String,
+ userName As String,
+ password As String,
+ showUI As Boolean,
+ connectionTimeout As Integer)
+
+ UploadFile(
+ sourceFileName,
+ address,
+ userName,
+ password,
+ showUI,
+ connectionTimeout,
+ onUserCancel:=UICancelOption.ThrowException)
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' The full name and path of the host destination.
+ ''' The name of the user performing the upload.
+ ''' The user's password.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ '''
+ ''' Indicates what to do if user cancels dialog (either throw or do nothing).
+ '''
+ Public Sub UploadFile(
+ sourceFileName As String,
+ address As String,
+ userName As String,
+ password As String,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ onUserCancel As UICancelOption)
+
+ ' We're safe from UploadFile(Nothing, ...) due to overload failure (UploadFile(String,...)
+ ' vs. UploadFile(Uri,...)).
+ ' However, it is good practice to verify address before calling address.Trim.
+ If String.IsNullOrWhiteSpace(address) Then
+ Throw GetArgumentNullException(NameOf(address))
+ End If
+
+ ' Getting a uri will validate the form of the host address
+ Dim addressUri As Uri = GetUri(address.Trim())
+
+ ' For uploads, we need to make sure the address includes the filename
+ If String.IsNullOrEmpty(IO.Path.GetFileName(addressUri.AbsolutePath)) Then
+ Throw GetInvalidOperationException(SR.Network_UploadAddressNeedsFilename)
+ End If
+
+ UploadFile(
+ sourceFileName,
+ address:=addressUri,
+ userName,
+ password,
+ showUI,
+ connectionTimeout,
+ onUserCancel)
+
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' Uri representing the destination.
+ ''' The name of the user performing the upload.
+ ''' The user's password.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ Public Sub UploadFile(
+ sourceFileName As String,
+ address As Uri,
+ userName As String,
+ password As String,
+ showUI As Boolean,
+ connectionTimeout As Integer)
+
+ UploadFile(
+ sourceFileName,
+ address,
+ userName,
+ password,
+ showUI,
+ connectionTimeout,
+ onUserCancel:=UICancelOption.ThrowException)
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' Uri representing the destination.
+ ''' The name of the user performing the upload.
+ ''' The user's password.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ '''
+ ''' Indicates what to do if user cancels dialog (either throw or do nothing).
+ '''
+ Public Sub UploadFile(
+ sourceFileName As String,
+ address As Uri,
+ userName As String,
+ password As String,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ onUserCancel As UICancelOption)
+
+ ' Get network credentials
+ Dim networkCredentials As ICredentials = GetNetworkCredentials(userName, password)
+
+ UploadFile(
+ sourceFileName,
+ address,
+ networkCredentials,
+ showUI,
+ connectionTimeout,
+ onUserCancel)
+
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' Uri representing the destination.
+ ''' The credentials of the user performing the upload.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ Public Sub UploadFile(
+ sourceFileName As String,
+ address As Uri,
+ networkCredentials As ICredentials,
+ showUI As Boolean,
+ connectionTimeout As Integer)
+
+ UploadFile(
+ sourceFileName,
+ address,
+ networkCredentials,
+ showUI,
+ connectionTimeout,
+ onUserCancel:=UICancelOption.ThrowException)
+ End Sub
+
+ '''
+ ''' Uploads a file from the local machine to the specified host.
+ '''
+ ''' The file to be uploaded.
+ ''' Uri representing the destination.
+ ''' The credentials of the user performing the upload.
+ ''' Indicates whether or not to show a progress bar.
+ ''' Time allotted before giving up on a connection.
+ '''
+ ''' Indicates what to do if user cancels dialog (either throw or do nothing).
+ '''
+ Public Sub UploadFile(
+ sourceFileName As String,
+ address As Uri,
+ networkCredentials As ICredentials,
+ showUI As Boolean,
+ connectionTimeout As Integer,
+ onUserCancel As UICancelOption)
+
+ sourceFileName = FileSystemUtils.NormalizeFilePath(sourceFileName, NameOf(sourceFileName))
+
+ 'Make sure the file exists
+ If Not IO.File.Exists(sourceFileName) Then
+ Dim message As String = GetResourceString(SR.IO_FileNotFound_Path, sourceFileName)
+ Throw New IO.FileNotFoundException(message)
+ End If
+
+ If connectionTimeout <= 0 Then
+ Throw GetArgumentExceptionWithArgName(
+ argumentName:=NameOf(connectionTimeout),
+ resourceKey:=SR.Network_BadConnectionTimeout)
+ End If
+
+ If address Is Nothing Then
+ Throw GetArgumentNullException(NameOf(address))
+ End If
+
+ Using client As New WebClientExtended()
+ client.Timeout = connectionTimeout
+
+ ' Set credentials if we have any
+ If networkCredentials IsNot Nothing Then
+ client.Credentials = networkCredentials
+ End If
+
+ Dim dialog As ProgressDialog = Nothing
+ If showUI AndAlso Environment.UserInteractive Then
+ dialog = New ProgressDialog With {
+ .Text = GetResourceString(SR.ProgressDialogUploadingTitle, sourceFileName),
+ .LabelText = GetResourceString(
+ resourceKey:=SR.ProgressDialogUploadingLabel,
+ sourceFileName,
+ address.AbsolutePath)
+ }
+ End If
+
+ 'Create the copier
+ Dim copier As New WebClientCopy(client, dialog)
+
+ 'Download the file
+ copier.UploadFile(sourceFileName, address)
+
+ 'Handle a dialog cancel
+ If showUI AndAlso Environment.UserInteractive Then
+ If onUserCancel = UICancelOption.ThrowException And dialog.UserCanceledTheDialog Then
+ Throw New OperationCanceledException()
+ End If
+ End If
+ End Using
+
+ End Sub
+
+ End Class
+End Namespace
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.vb
deleted file mode 100644
index 785930dc581..00000000000
--- a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/Network.vb
+++ /dev/null
@@ -1,818 +0,0 @@
-' Licensed to the .NET Foundation under one or more agreements.
-' The .NET Foundation licenses this file to you under the MIT license.
-
-Imports System.ComponentModel
-Imports System.Net
-Imports System.Security
-Imports System.Threading
-Imports Microsoft.VisualBasic.CompilerServices
-Imports Microsoft.VisualBasic.FileIO
-Imports Microsoft.VisualBasic.MyServices.Internal
-Imports NetInfoAlias = System.Net.NetworkInformation
-
-Imports VbUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils
-
-Namespace Microsoft.VisualBasic.Devices
-
- '''
- ''' Used to pass network connectivity status.
- '''
- Public Class NetworkAvailableEventArgs
- Inherits EventArgs
- Public Sub New(networkAvailable As Boolean)
- IsNetworkAvailable = networkAvailable
- End Sub
-
- Public ReadOnly Property IsNetworkAvailable() As Boolean
- End Class
-
-
- Public Delegate Sub NetworkAvailableEventHandler(sender As Object, e As NetworkAvailableEventArgs)
-
- '''
- ''' An object that allows easy access to some simple network properties and functionality.
- '''
- Public Class Network
-
- '''
- ''' Event fired when connected to the network
- '''
- ''' Has no meaning for this event
- ''' Has no meaning for this event
- Public Custom Event NetworkAvailabilityChanged As NetworkAvailableEventHandler
- 'This is a custom event because we want to hook up the NetworkAvailabilityChanged event only if the user writes a handler for it.
- 'The reason being that it is very expensive to handle and kills our application startup perf.
- AddHandler(handler As NetworkAvailableEventHandler)
-
- ' Set the current state of connectedness, swallow known exceptions since user won't be able to correct problem
- Try
- _connected = IsAvailable
- Catch ex As SecurityException
- Return
- Catch ex As PlatformNotSupportedException
- Return
- End Try
- SyncLock _syncObject 'we don't want our event firing before we've finished setting up the infrastructure. Also, need to assure there are no races in here so we don't hook up the OS listener twice, etc.
- If _networkAvailabilityEventHandlers Is Nothing Then _networkAvailabilityEventHandlers = New List(Of NetworkAvailableEventHandler)
- _networkAvailabilityEventHandlers.Add(handler)
-
- 'Only setup the event Marshalling infrastructure once
- If _networkAvailabilityEventHandlers.Count = 1 Then
- _networkAvailabilityChangedCallback = New SendOrPostCallback(AddressOf NetworkAvailabilityChangedHandler) 'the async operation posts to this delegate
- If AsyncOperationManager.SynchronizationContext IsNot Nothing Then
- _synchronizationContext = AsyncOperationManager.SynchronizationContext 'We need to hang on to the synchronization context associated with the thread the network object is created on
- Try ' Exceptions are thrown if the user isn't an admin.
- AddHandler NetInfoAlias.NetworkChange.NetworkAddressChanged, New NetInfoAlias.NetworkAddressChangedEventHandler(AddressOf OS_NetworkAvailabilityChangedListener) 'listen to the OS event
- Catch ex As PlatformNotSupportedException
- Catch ex As NetInfoAlias.NetworkInformationException
- End Try
- End If
- End If
- End SyncLock
- End AddHandler
-
- RemoveHandler(handler As NetworkAvailableEventHandler)
- If _networkAvailabilityEventHandlers IsNot Nothing AndAlso _networkAvailabilityEventHandlers.Count > 0 Then
- _networkAvailabilityEventHandlers.Remove(handler)
- 'Last one to leave, turn out the lights...
- If _networkAvailabilityEventHandlers.Count = 0 Then
- RemoveHandler NetInfoAlias.NetworkChange.NetworkAddressChanged, New NetInfoAlias.NetworkAddressChangedEventHandler(AddressOf OS_NetworkAvailabilityChangedListener) 'listen to the OS event
- DisconnectListener() 'Stop listening to network change events since nobody is listening to us anymore
- End If
- End If
- End RemoveHandler
-
- RaiseEvent(sender As Object, e As NetworkAvailableEventArgs)
- If _networkAvailabilityEventHandlers IsNot Nothing Then
- For Each handler As NetworkAvailableEventHandler In _networkAvailabilityEventHandlers
- If handler IsNot Nothing Then handler.Invoke(sender, e)
- Next
- End If
- End RaiseEvent
- End Event
-
- '''
- ''' Creates class and hooks up events
- '''
- Public Sub New()
- End Sub
-
- '''
- ''' Indicates whether or not the local machine is connected to an IP network.
- '''
- ''' True if connected, otherwise False
- Public ReadOnly Property IsAvailable() As Boolean
- Get
-
- Return NetInfoAlias.NetworkInterface.GetIsNetworkAvailable()
-
- End Get
- End Property
-
- '''
- ''' Sends and receives a packet to and from the passed in address.
- '''
- '''
- ''' True if ping was successful, otherwise False
- Public Function Ping(hostNameOrAddress As String) As Boolean
- Return Ping(hostNameOrAddress, DEFAULT_PING_TIMEOUT)
- End Function
-
- '''
- ''' Sends and receives a packet to and from the passed in Uri.
- '''
- ''' A Uri representing the host
- ''' True if ping was successful, otherwise False
- Public Function Ping(address As Uri) As Boolean
- ' We're safe from Ping(Nothing, ...) due to overload failure (Ping(String,...) vs. Ping(Uri,...)).
- ' However, it is good practice to verify address before calling address.Host.
- If address Is Nothing Then
- Throw GetArgumentNullException("address")
- End If
- Return Ping(address.Host, DEFAULT_PING_TIMEOUT)
- End Function
-
- '''
- ''' Sends and receives a packet to and from the passed in address.
- '''
- ''' The name of the host as a Url or IP Address
- ''' Time to wait before aborting ping
- ''' True if ping was successful, otherwise False
- Public Function Ping(hostNameOrAddress As String, timeout As Integer) As Boolean
-
- ' Make sure a network is available
- If Not IsAvailable Then
- Throw GetInvalidOperationException(SR.Network_NetworkNotAvailable)
- End If
-
- Dim PingMaker As New NetInfoAlias.Ping
- Dim Reply As NetInfoAlias.PingReply = PingMaker.Send(hostNameOrAddress, timeout, PingBuffer)
- If Reply.Status = NetInfoAlias.IPStatus.Success Then
- Return True
- End If
- Return False
- End Function
-
- '''
- ''' Sends and receives a packet to and from the passed in Uri.
- '''
- ''' A Uri representing the host
- ''' Time to wait before aborting ping
- ''' True if ping was successful, otherwise False
- Public Function Ping(address As Uri, timeout As Integer) As Boolean
- ' We're safe from Ping(Nothing, ...) due to overload failure (Ping(String,...) vs. Ping(Uri,...)).
- ' However, it is good practice to verify address before calling address.Host.
- If address Is Nothing Then
- Throw GetArgumentNullException("address")
- End If
- Return Ping(address.Host, timeout)
- End Function
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Address to the remote file, http, ftp etc...
- ''' Name and path of file where download is saved
- Public Sub DownloadFile(address As String, destinationFileName As String)
- DownloadFile(address, destinationFileName, DEFAULT_USERNAME, DEFAULT_PASSWORD, False, DEFAULT_TIMEOUT, False)
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Uri to the remote file
- ''' Name and path of file where download is saved
- Public Sub DownloadFile(address As Uri, destinationFileName As String)
- DownloadFile(address, destinationFileName, DEFAULT_USERNAME, DEFAULT_PASSWORD, False, DEFAULT_TIMEOUT, False)
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Address to the remote file, http, ftp etc...
- ''' Name and path of file where download is saved
- ''' The name of the user performing the download
- ''' The user's password
- Public Sub DownloadFile(address As String, destinationFileName As String, userName As String, password As String)
- DownloadFile(address, destinationFileName, userName, password, False, DEFAULT_TIMEOUT, False)
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Uri to the remote file
- ''' Name and path of file where download is saved
- ''' The name of the user performing the download
- ''' The user's password
- Public Sub DownloadFile(address As Uri, destinationFileName As String, userName As String, password As String)
- DownloadFile(address, destinationFileName, userName, password, False, DEFAULT_TIMEOUT, False)
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Address to the remote file, http, ftp etc...
- ''' Name and path of file where download is saved
- ''' The name of the user performing the download
- ''' The user's password
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates whether or not the file should be overwritten if local file already exists
- Public Sub DownloadFile(address As String,
- destinationFileName As String,
- userName As String,
- password As String,
- showUI As Boolean,
- connectionTimeout As Integer,
- overwrite As Boolean)
-
- DownloadFile(address, destinationFileName, userName, password, showUI, connectionTimeout, overwrite, UICancelOption.ThrowException)
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Address to the remote file, http, ftp etc...
- ''' Name and path of file where download is saved
- ''' The name of the user performing the download
- ''' The user's password
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates whether or not the file should be overwritten if local file already exists
- ''' Indicates what to do if user cancels dialog (either throw or do nothing)
- Public Sub DownloadFile(address As String,
- destinationFileName As String,
- userName As String,
- password As String,
- showUI As Boolean,
- connectionTimeout As Integer,
- overwrite As Boolean,
- onUserCancel As UICancelOption)
-
- ' We're safe from DownloadFile(Nothing, ...) due to overload failure (DownloadFile(String,...) vs. DownloadFile(Uri,...)).
- ' However, it is good practice to verify address before calling Trim.
- If String.IsNullOrWhiteSpace(address) Then
- Throw GetArgumentNullException("address")
- End If
-
- Dim addressUri As Uri = GetUri(address.Trim())
-
- ' Get network credentials
- Dim networkCredentials As ICredentials = GetNetworkCredentials(userName, password)
-
- DownloadFile(addressUri, destinationFileName, networkCredentials, showUI, connectionTimeout, overwrite, onUserCancel)
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Uri to the remote file
- ''' Name and path of file where download is saved
- ''' The name of the user performing the download
- ''' The user's password
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates whether or not the file should be overwritten if local file already exists
- Public Sub DownloadFile(address As Uri,
- destinationFileName As String,
- userName As String,
- password As String,
- showUI As Boolean,
- connectionTimeout As Integer,
- overwrite As Boolean)
-
- DownloadFile(address, destinationFileName, userName, password, showUI, connectionTimeout, overwrite, UICancelOption.ThrowException)
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Uri to the remote file
- ''' Name and path of file where download is saved
- ''' The name of the user performing the download
- ''' The user's password
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates whether or not the file should be overwritten if local file already exists
- ''' Indicates what to do if user cancels dialog (either throw or do nothing)
- Public Sub DownloadFile(address As Uri,
- destinationFileName As String,
- userName As String,
- password As String,
- showUI As Boolean,
- connectionTimeout As Integer,
- overwrite As Boolean,
- onUserCancel As UICancelOption)
-
- ' Get network credentials
- Dim networkCredentials As ICredentials = GetNetworkCredentials(userName, password)
-
- DownloadFile(address, destinationFileName, networkCredentials, showUI, connectionTimeout, overwrite, onUserCancel)
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Uri to the remote file
- ''' Name and path of file where download is saved
- ''' The credentials of the user performing the download
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates whether or not the file should be overwritten if local file already exists
- ''' Calls to all the other overloads will come through here
- Public Sub DownloadFile(address As Uri,
- destinationFileName As String,
- networkCredentials As ICredentials,
- showUI As Boolean,
- connectionTimeout As Integer,
- overwrite As Boolean)
-
- DownloadFile(address, destinationFileName, networkCredentials, showUI, connectionTimeout, overwrite, UICancelOption.ThrowException)
-
- End Sub
-
- '''
- ''' Downloads a file from the network to the specified path
- '''
- ''' Uri to the remote file
- ''' Name and path of file where download is saved
- ''' The credentials of the user performing the download
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates whether or not the file should be overwritten if local file already exists
- ''' Indicates what to do if user cancels dialog (either throw or do nothing)
- ''' Calls to all the other overloads will come through here
- Public Sub DownloadFile(address As Uri,
- destinationFileName As String,
- networkCredentials As ICredentials,
- showUI As Boolean,
- connectionTimeout As Integer,
- overwrite As Boolean,
- onUserCancel As UICancelOption)
- If connectionTimeout <= 0 Then
- Throw GetArgumentExceptionWithArgName("connectionTimeOut", SR.Network_BadConnectionTimeout)
- End If
-
- If address Is Nothing Then
- Throw GetArgumentNullException("address")
- End If
-
- Using client As New WebClientExtended
- client.Timeout = connectionTimeout
-
- ' Don't use passive mode if we're showing UI
- client.UseNonPassiveFtp = showUI
-
- 'Construct the local file. This will validate the full name and path
- Dim fullFilename As String = FileSystemUtils.NormalizeFilePath(destinationFileName, NameOf(destinationFileName))
-
- ' Sometime a path that can't be parsed is normalized to the current directory. This makes sure we really
- ' have a file and path
- If IO.Directory.Exists(fullFilename) Then
- Throw GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
- End If
-
- 'Throw if the file exists and the user doesn't want to overwrite
- If IO.File.Exists(fullFilename) And Not overwrite Then
- Throw New IO.IOException(VbUtils.GetResourceString(SR.IO_FileExists_Path, destinationFileName))
- End If
-
- ' Set credentials if we have any
- If networkCredentials IsNot Nothing Then
- client.Credentials = networkCredentials
- End If
-
- Dim dialog As ProgressDialog = Nothing
- If showUI AndAlso Environment.UserInteractive Then
- dialog = New ProgressDialog With {
- .Text = VbUtils.GetResourceString(SR.ProgressDialogDownloadingTitle, address.AbsolutePath),
- .LabelText = VbUtils.GetResourceString(SR.ProgressDialogDownloadingLabel, address.AbsolutePath, fullFilename)
- }
- End If
-
- 'Check to see if the target directory exists. If it doesn't, create it
- Dim targetDirectory As String = IO.Path.GetDirectoryName(fullFilename)
-
- ' Make sure we have a meaningful directory. If we don't, the destinationFileName is suspect
- If String.IsNullOrEmpty(targetDirectory) Then
- Throw GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
- End If
-
- If Not IO.Directory.Exists(targetDirectory) Then
- IO.Directory.CreateDirectory(targetDirectory)
- End If
-
- 'Create the copier
- Dim copier As New WebClientCopy(client, dialog)
-
- 'Download the file
- copier.DownloadFile(address, fullFilename)
-
- 'Handle a dialog cancel
- If showUI AndAlso Environment.UserInteractive Then
- If onUserCancel = UICancelOption.ThrowException And dialog.UserCanceledTheDialog Then
- Throw New OperationCanceledException()
- End If
- End If
-
- End Using
-
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' The full name and path of the host destination
- Public Sub UploadFile(sourceFileName As String, address As String)
- UploadFile(sourceFileName, address, DEFAULT_USERNAME, DEFAULT_PASSWORD, False, DEFAULT_TIMEOUT)
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' Uri representing the destination
- Public Sub UploadFile(sourceFileName As String, address As Uri)
- UploadFile(sourceFileName, address, DEFAULT_USERNAME, DEFAULT_PASSWORD, False, DEFAULT_TIMEOUT)
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' The full name and path of the host destination
- ''' The name of the user performing the upload
- ''' The user's password
- Public Sub UploadFile(sourceFileName As String, address As String, userName As String, password As String)
- UploadFile(sourceFileName, address, userName, password, False, DEFAULT_TIMEOUT)
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' Uri representing the destination
- ''' The name of the user performing the upload
- ''' The user's password
- Public Sub UploadFile(sourceFileName As String, address As Uri, userName As String, password As String)
- UploadFile(sourceFileName, address, userName, password, False, DEFAULT_TIMEOUT)
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' The full name and path of the host destination
- ''' The name of the user performing the upload
- ''' The user's password
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- Public Sub UploadFile(sourceFileName As String,
- address As String,
- userName As String,
- password As String,
- showUI As Boolean,
- connectionTimeout As Integer)
-
- UploadFile(sourceFileName, address, userName, password, showUI, connectionTimeout, UICancelOption.ThrowException)
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' The full name and path of the host destination
- ''' The name of the user performing the upload
- ''' The user's password
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates what to do if user cancels dialog (either throw or do nothing)
- Public Sub UploadFile(sourceFileName As String,
- address As String,
- userName As String,
- password As String,
- showUI As Boolean,
- connectionTimeout As Integer,
- onUserCancel As UICancelOption)
-
- ' We're safe from UploadFile(Nothing, ...) due to overload failure (UploadFile(String,...) vs. UploadFile(Uri,...)).
- ' However, it is good practice to verify address before calling address.Trim.
- If String.IsNullOrWhiteSpace(address) Then
- Throw GetArgumentNullException("address")
- End If
-
- ' Getting a uri will validate the form of the host address
- Dim addressUri As Uri = GetUri(address.Trim())
-
- ' For uploads, we need to make sure the address includes the filename
- If String.IsNullOrEmpty(IO.Path.GetFileName(addressUri.AbsolutePath)) Then
- Throw GetInvalidOperationException(SR.Network_UploadAddressNeedsFilename)
- End If
-
- UploadFile(sourceFileName, addressUri, userName, password, showUI, connectionTimeout, onUserCancel)
-
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' Uri representing the destination
- ''' The name of the user performing the upload
- ''' The user's password
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- Public Sub UploadFile(sourceFileName As String,
- address As Uri,
- userName As String,
- password As String,
- showUI As Boolean,
- connectionTimeout As Integer)
-
- UploadFile(sourceFileName, address, userName, password, showUI, connectionTimeout, UICancelOption.ThrowException)
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' Uri representing the destination
- ''' The name of the user performing the upload
- ''' The user's password
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates what to do if user cancels dialog (either throw or do nothing)
- Public Sub UploadFile(sourceFileName As String,
- address As Uri,
- userName As String,
- password As String,
- showUI As Boolean,
- connectionTimeout As Integer,
- onUserCancel As UICancelOption)
-
- ' Get network credentials
- Dim networkCredentials As ICredentials = GetNetworkCredentials(userName, password)
-
- UploadFile(sourceFileName, address, networkCredentials, showUI, connectionTimeout, onUserCancel)
-
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' Uri representing the destination
- ''' The credentials of the user performing the upload
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- Public Sub UploadFile(sourceFileName As String,
- address As Uri,
- networkCredentials As ICredentials,
- showUI As Boolean,
- connectionTimeout As Integer)
-
- UploadFile(sourceFileName, address, networkCredentials, showUI, connectionTimeout, UICancelOption.ThrowException)
- End Sub
-
- '''
- ''' Uploads a file from the local machine to the specified host
- '''
- ''' The file to be uploaded
- ''' Uri representing the destination
- ''' The credentials of the user performing the upload
- ''' Indicates whether or not to show a progress bar
- ''' Time allotted before giving up on a connection
- ''' Indicates what to do if user cancels dialog (either throw or do nothing)
- Public Sub UploadFile(sourceFileName As String,
- address As Uri,
- networkCredentials As ICredentials,
- showUI As Boolean,
- connectionTimeout As Integer,
- onUserCancel As UICancelOption)
- sourceFileName = FileSystemUtils.NormalizeFilePath(sourceFileName, NameOf(sourceFileName))
-
- 'Make sure the file exists
- If Not IO.File.Exists(sourceFileName) Then
- Throw New IO.FileNotFoundException(VbUtils.GetResourceString(SR.IO_FileNotFound_Path, sourceFileName))
- End If
-
- If connectionTimeout <= 0 Then
- Throw GetArgumentExceptionWithArgName("connectionTimeout", SR.Network_BadConnectionTimeout)
- End If
-
- If address Is Nothing Then
- Throw GetArgumentNullException("address")
- End If
-
- Using client As New WebClientExtended()
- client.Timeout = connectionTimeout
-
- ' Set credentials if we have any
- If networkCredentials IsNot Nothing Then
- client.Credentials = networkCredentials
- End If
-
- Dim Dialog As ProgressDialog = Nothing
- If showUI AndAlso Environment.UserInteractive Then
- Dialog = New ProgressDialog With {
- .Text = VbUtils.GetResourceString(SR.ProgressDialogUploadingTitle, sourceFileName),
- .LabelText = VbUtils.GetResourceString(SR.ProgressDialogUploadingLabel, sourceFileName, address.AbsolutePath)
- }
- End If
-
- 'Create the copier
- Dim copier As New WebClientCopy(client, Dialog)
-
- 'Download the file
- copier.UploadFile(sourceFileName, address)
-
- 'Handle a dialog cancel
- If showUI AndAlso Environment.UserInteractive Then
- If onUserCancel = UICancelOption.ThrowException And Dialog.UserCanceledTheDialog Then
- Throw New OperationCanceledException()
- End If
- End If
- End Using
-
- End Sub
-
- Friend Sub DisconnectListener()
- RemoveHandler NetInfoAlias.NetworkChange.NetworkAddressChanged, New NetInfoAlias.NetworkAddressChangedEventHandler(AddressOf OS_NetworkAvailabilityChangedListener)
- End Sub
-
- 'Listens to the AddressChanged event from the OS which comes in on an arbitrary thread
- Private Sub OS_NetworkAvailabilityChangedListener(sender As Object, e As EventArgs)
- SyncLock _syncObject 'Ensure we don't handle events until after we've finished setting up the event marshalling infrastructure
- 'Don't call AsyncOperationManager.OperationSynchronizationContext.Post. The reason we want to go through m_SynchronizationContext is that
- 'the OperationSynchronizationContext is thread static. Since we are getting called on some random thread, the context that was
- 'in place when the Network object was created won't be available (it is on the original thread). To hang on to the original
- 'context associated with the thread that the network object is created on, I use m_SynchronizationContext.
- _synchronizationContext.Post(_networkAvailabilityChangedCallback, Nothing)
- End SyncLock
- End Sub
-
- 'Listens to the AddressChanged event which will come on the same thread that this class was created on (AsyncEventManager is responsible for getting the event here)
- Private Sub NetworkAvailabilityChangedHandler(state As Object)
- Dim Connected As Boolean = IsAvailable
- ' Fire an event only if the connected state has changed
- If _connected <> Connected Then
- _connected = Connected
- RaiseEvent NetworkAvailabilityChanged(Me, New NetworkAvailableEventArgs(Connected))
- End If
- End Sub
-
- '''
- ''' A buffer for pinging. This imitates the buffer used by Ping.Exe
- '''
- ''' A buffer
- Private ReadOnly Property PingBuffer() As Byte()
- Get
- If _pingBuffer Is Nothing Then
- ReDim _pingBuffer(BUFFER_SIZE - 1)
- For i As Integer = 0 To BUFFER_SIZE - 1
- 'This is the same logic Ping.exe uses to fill it's buffer
- _pingBuffer(i) = Convert.ToByte(Asc("a"c) + i Mod 23, Globalization.CultureInfo.InvariantCulture)
- Next
- End If
-
- Return _pingBuffer
- End Get
- End Property
-
- '''
- ''' Gets a Uri from a uri string. We also use this function to validate the UriString (remote file address)
- '''
- ''' The remote file address
- ''' A Uri if successful, otherwise it throws an exception
- Private Shared Function GetUri(address As String) As Uri
- Try
- Return New Uri(address)
- Catch ex As UriFormatException
- 'Throw an exception with an error message more appropriate to our API
- Throw GetArgumentExceptionWithArgName("address", SR.Network_InvalidUriString, address)
- End Try
- End Function
-
- '''
- ''' Gets network credentials from a userName and password
- '''
- ''' The name of the user
- ''' The password of the user
- ''' A NetworkCredentials
- Private Shared Function GetNetworkCredentials(userName As String, password As String) As ICredentials
-
- ' Make sure all nulls are empty strings
- If userName Is Nothing Then
- userName = String.Empty
- End If
-
- If password Is Nothing Then
- password = String.Empty
- End If
-
- If userName.Length = 0 And password.Length = 0 Then
- Return Nothing
- End If
-
- Return New NetworkCredential(userName, password)
- End Function
-
- 'Holds the buffer for pinging. We lazy initialize on first use
- Private _pingBuffer() As Byte
-
- 'Size of Ping.exe buffer
- Private Const BUFFER_SIZE As Integer = 32
-
- ' Default timeout value
- Private Const DEFAULT_TIMEOUT As Integer = 100000
-
- ' Default timeout for Ping
- Private Const DEFAULT_PING_TIMEOUT As Integer = 1000
-
- ' UserName used in overloads where there is no userName parameter
- Private Const DEFAULT_USERNAME As String = ""
-
- ' Password used in overloads where there is no password parameter
- Private Const DEFAULT_PASSWORD As String = ""
-
- ' Indicates last known connection state
- Private _connected As Boolean
-
- ' Object for syncing
- Private ReadOnly _syncObject As New Object()
-
- Private _networkAvailabilityEventHandlers As List(Of NetworkAvailableEventHandler) 'Holds the listeners to our NetworkAvailability changed event
-
- Private _synchronizationContext As SynchronizationContext
- Private _networkAvailabilityChangedCallback As SendOrPostCallback 'Used for marshalling the network address changed event to the foreground thread
- End Class
-
- '''
- ''' Temporary class used to provide WebClient with a timeout property.
- '''
- ''' This class will be deleted when Timeout is added to WebClient
- Friend NotInheritable Class WebClientExtended
- Inherits WebClient
-
- '''
- ''' Sets or indicates the timeout used by WebRequest used by WebClient
- '''
- Public WriteOnly Property Timeout() As Integer
- Set(value As Integer)
- Debug.Assert(value > 0, "illegal value for timeout")
- _timeout = value
- End Set
- End Property
-
- '''
- ''' Enables switching the server to non passive mode.
- '''
- ''' We need this in order for the progress UI on a download to work
- Public WriteOnly Property UseNonPassiveFtp() As Boolean
- Set(value As Boolean)
- _useNonPassiveFtp = value
- End Set
- End Property
-
- '''
- ''' Makes sure that the timeout value for WebRequests (used for all Download and Upload methods) is set
- ''' to the Timeout value
- '''
- '''
- Protected Overrides Function GetWebRequest(address As Uri) As WebRequest
- Dim request As WebRequest = MyBase.GetWebRequest(address)
-
- Debug.Assert(request IsNot Nothing, "Unable to get WebRequest from base class")
- If request IsNot Nothing Then
- request.Timeout = _timeout
- If _useNonPassiveFtp Then
- Dim ftpRequest As FtpWebRequest = TryCast(request, FtpWebRequest)
- If ftpRequest IsNot Nothing Then
- ftpRequest.UsePassive = False
- End If
- End If
-
- Dim httpRequest As HttpWebRequest = TryCast(request, HttpWebRequest)
- If httpRequest IsNot Nothing Then
- httpRequest.AllowAutoRedirect = False
- End If
-
- End If
-
- Return request
- End Function
-
-#Disable Warning BC41004 ' First statement of this 'Sub New' should be an explicit call to 'MyBase.New' or 'MyClass.New' because the constructor in the base class is marked obsolete
- Friend Sub New()
- End Sub
-#Enable Warning BC41004 ' First statement of this 'Sub New' should be an explicit call to 'MyBase.New' or 'MyClass.New' because the constructor in the base class is marked obsolete
-
- ' The Timeout value to be used by WebClient's WebRequest for Downloading or Uploading a file
- Private _timeout As Integer = 100000
-
- ' Flag used to indicate whether or not we should use passive mode when ftp downloading
- Private _useNonPassiveFtp As Boolean
- End Class
-
-End Namespace
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/NetworkAvailableEventArgs.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/NetworkAvailableEventArgs.vb
new file mode 100644
index 00000000000..7f2d99827f2
--- /dev/null
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/NetworkAvailableEventArgs.vb
@@ -0,0 +1,19 @@
+' Licensed to the .NET Foundation under one or more agreements.
+' The .NET Foundation licenses this file to you under the MIT license.
+
+Namespace Microsoft.VisualBasic.Devices
+
+ '''
+ ''' Used to pass network connectivity status.
+ '''
+ Public Class NetworkAvailableEventArgs
+ Inherits EventArgs
+
+ Public Sub New(networkAvailable As Boolean)
+ IsNetworkAvailable = networkAvailable
+ End Sub
+
+ Public ReadOnly Property IsNetworkAvailable() As Boolean
+
+ End Class
+End Namespace
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/NetworkUtilities.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/NetworkUtilities.vb
new file mode 100644
index 00000000000..fec0451ee24
--- /dev/null
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/NetworkUtilities.vb
@@ -0,0 +1,100 @@
+' Licensed to the .NET Foundation under one or more agreements.
+' The .NET Foundation licenses this file to you under the MIT license.
+
+Imports System.Net
+Imports System.Windows.Forms
+Imports Microsoft.VisualBasic.CompilerServices
+Imports Microsoft.VisualBasic.MyServices.Internal
+
+Namespace Microsoft.VisualBasic.Devices
+ Friend Module NetworkUtilities
+
+ ' Password used in overloads where there is no password parameter
+ Friend Const DEFAULT_PASSWORD As String = ""
+
+ ' Default timeout value
+ Friend Const DEFAULT_TIMEOUT As Integer = 100000
+
+ ' UserName used in overloads where there is no userName parameter
+ Friend Const DEFAULT_USERNAME As String = ""
+
+ '''
+ ''' Posts a message to close the .
+ '''
+ Friend Sub CloseProgressDialog(dialog As ProgressDialog)
+ ' Don't invoke unless dialog is up and running
+ If dialog IsNot Nothing Then
+ dialog.IndicateClosing()
+
+ If dialog.IsHandleCreated Then
+ dialog.BeginInvoke(New MethodInvoker(AddressOf dialog.CloseDialog))
+ Else
+ ' Ensure dialog is closed. If we get here it means the file was copied before the handle for
+ ' the progress dialog was created.
+ dialog.Close()
+ End If
+ End If
+ End Sub
+
+ '''
+ ''' Gets network credentials from a userName and password.
+ '''
+ ''' The name of the user.
+ ''' The password of the user.
+ ''' A or .
+ Friend Function GetNetworkCredentials(userName As String, password As String) As ICredentials
+
+ Return If(String.IsNullOrWhiteSpace(userName) OrElse String.IsNullOrWhiteSpace(password),
+ Nothing,
+ DirectCast(New NetworkCredential(userName, password), ICredentials)
+ )
+ End Function
+
+ '''
+ ''' Centralize setup a to be used with FileDownload and FileUpload.
+ '''
+ ''' Address to the remote file, http, ftp etc...
+ ''' Name and path of file where download is saved.
+ ''' Indicates whether or not to show a progress bar.
+ ''' .
+ Friend Function GetProgressDialog(
+ address As String,
+ destinationFileName As String,
+ showUI As Boolean) As ProgressDialog
+
+ If showUI AndAlso Environment.UserInteractive Then
+ 'Construct the local file. This will validate the full name and path
+ Dim fullFilename As String = FileSystemUtils.NormalizeFilePath(
+ path:=destinationFileName,
+ paramName:=NameOf(destinationFileName))
+ Return New ProgressDialog With {
+ .Text = Utils.GetResourceString(SR.ProgressDialogDownloadingTitle, address),
+ .LabelText = Utils.GetResourceString(
+ ResourceKey:=SR.ProgressDialogDownloadingLabel,
+ address,
+ fullFilename)
+ }
+ End If
+ Return Nothing
+ End Function
+
+ '''
+ ''' Gets a from a uri string.
+ ''' We also use this function to validate the UriString (remote file address).
+ '''
+ ''' The remote file address.
+ ''' A if successful, otherwise it throws an .
+ Friend Function GetUri(address As String) As Uri
+ Try
+ Return New Uri(address)
+ Catch ex As UriFormatException
+ 'Throw an exception with an error message more appropriate to our API
+ Throw GetArgumentExceptionWithArgName(
+ argumentName:=NameOf(address),
+ resourceKey:=SR.Network_InvalidUriString,
+ address)
+ End Try
+ End Function
+
+ End Module
+End Namespace
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/WebClientExtended.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/WebClientExtended.vb
new file mode 100644
index 00000000000..ca95e62b799
--- /dev/null
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Devices/WebClientExtended.vb
@@ -0,0 +1,77 @@
+' Licensed to the .NET Foundation under one or more agreements.
+' The .NET Foundation licenses this file to you under the MIT license.
+
+Imports System.Net
+
+Namespace Microsoft.VisualBasic.Devices
+
+ '''
+ ''' Temporary class used to provide WebClient with a timeout property.
+ '''
+ ''' This class will be deleted when Timeout is added to WebClient.
+ Friend NotInheritable Class WebClientExtended
+ Inherits WebClient
+
+ ' The Timeout value to be used by WebClient's WebRequest for Downloading or Uploading a file
+ Private _timeout As Integer = 100000
+
+ ' Flag used to indicate whether or not we should use passive mode when ftp downloading
+ Private _useNonPassiveFtp As Boolean
+
+#Disable Warning BC41004 ' First statement of this 'Sub New' should be an explicit call to 'MyBase.New' or 'MyClass.New' because the constructor in the base class is marked obsolete
+
+ Friend Sub New()
+ End Sub
+
+#Enable Warning BC41004 ' First statement of this 'Sub New' should be an explicit call to 'MyBase.New' or 'MyClass.New' because the constructor in the base class is marked obsolete
+
+ '''
+ ''' Sets or indicates the timeout used by WebRequest used by WebClient
+ '''
+ Public WriteOnly Property Timeout() As Integer
+ Set(value As Integer)
+ Debug.Assert(value > 0, "illegal value for timeout")
+ _timeout = value
+ End Set
+ End Property
+
+ '''
+ ''' Enables switching the server to non passive mode.
+ '''
+ ''' We need this in order for the progress UI on a download to work
+ Public WriteOnly Property UseNonPassiveFtp() As Boolean
+ Set(value As Boolean)
+ _useNonPassiveFtp = value
+ End Set
+ End Property
+
+ '''
+ ''' Makes sure that the timeout value for WebRequests (used for all Download
+ ''' and Upload methods) is set to the Timeout value.
+ '''
+ '''
+ Protected Overrides Function GetWebRequest(address As Uri) As WebRequest
+ Dim request As WebRequest = MyBase.GetWebRequest(address)
+
+ Debug.Assert(request IsNot Nothing, "Unable to get WebRequest from base class")
+ If request IsNot Nothing Then
+ request.Timeout = _timeout
+ If _useNonPassiveFtp Then
+ Dim ftpRequest As FtpWebRequest = TryCast(request, FtpWebRequest)
+ If ftpRequest IsNot Nothing Then
+ ftpRequest.UsePassive = False
+ End If
+ End If
+
+ Dim httpRequest As HttpWebRequest = TryCast(request, HttpWebRequest)
+ If httpRequest IsNot Nothing Then
+ httpRequest.AllowAutoRedirect = False
+ End If
+
+ End If
+
+ Return request
+ End Function
+
+ End Class
+End Namespace
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Logging/FileLogTraceListener.Properties.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Logging/FileLogTraceListener.Properties.vb
index c3b4475e72e..146f885c0bd 100644
--- a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Logging/FileLogTraceListener.Properties.vb
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/Logging/FileLogTraceListener.Properties.vb
@@ -23,7 +23,7 @@ Namespace Microsoft.VisualBasic.Logging
Private Const PROPERTY_COUNT As Integer = 12
' Indicates whether or not properties have been set
- ' Note: Properties that use m_PropertiesSet to track whether or not
+ ' Note: Properties that use _propertiesSet to track whether or not
' they've been set should always be set through the property setter and not
' by directly changing the corresponding private field.
Private ReadOnly _propertiesSet As New BitArray(PROPERTY_COUNT, False)
diff --git a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/MyServices/Internal/WebClientCopy.vb b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/MyServices/Internal/WebClientCopy.vb
index d9d404950b2..203d72a44d2 100644
--- a/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/MyServices/Internal/WebClientCopy.vb
+++ b/src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/MyServices/Internal/WebClientCopy.vb
@@ -1,9 +1,8 @@
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
-Imports System.IO
Imports System.Net
-Imports System.Windows.Forms
+Imports Microsoft.VisualBasic.Devices
Namespace Microsoft.VisualBasic.MyServices.Internal
@@ -13,10 +12,10 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
Friend NotInheritable Class WebClientCopy
' Dialog shown if user wants to see progress UI. Allows the user to cancel the file transfer.
- Private WithEvents m_ProgressDialog As ProgressDialog
+ Private WithEvents _progressDialog As ProgressDialog
' The WebClient performs the downloading or uploading operations for us
- Private WithEvents m_WebClient As WebClient
+ Private WithEvents _webClient As WebClient
'Keeps track of the error that happened during upload/download so we can throw it once we can guarantee we are back on the main thread
Private _exceptionEncounteredDuringFileTransfer As Exception
@@ -33,50 +32,10 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
''' The used to do the downloading or uploading.
''' UI for indicating progress.
Public Sub New(client As WebClient, dialog As ProgressDialog)
+ Debug.Assert(client IsNot Nothing, $"No {client}")
- Debug.Assert(client IsNot Nothing, "No WebClient")
-
- m_WebClient = client
- m_ProgressDialog = dialog
-
- End Sub
-
- '''
- ''' Posts a message to close the progress dialog.
- '''
- Private Sub CloseProgressDialog()
- ' Don't invoke unless dialog is up and running
- If m_ProgressDialog IsNot Nothing Then
- m_ProgressDialog.IndicateClosing()
-
- If m_ProgressDialog.IsHandleCreated Then
- m_ProgressDialog.BeginInvoke(New MethodInvoker(AddressOf m_ProgressDialog.CloseDialog))
- Else
- ' Ensure dialog is closed. If we get here it means the file was copied before the handle for
- ' the progress dialog was created.
- m_ProgressDialog.Close()
- End If
- End If
- End Sub
-
- '''
- ''' Notifies the progress dialog to increment the progress bar.
- '''
- ''' The percentage of bytes read.
- Private Sub InvokeIncrement(progressPercentage As Integer)
- ' Don't invoke unless dialog is up and running
- If m_ProgressDialog IsNot Nothing Then
- If m_ProgressDialog.IsHandleCreated Then
-
- ' For performance, don't invoke if increment is 0
- Dim increment As Integer = progressPercentage - _percentage
- _percentage = progressPercentage
- If increment > 0 Then
- m_ProgressDialog.BeginInvoke(New DoIncrement(AddressOf m_ProgressDialog.Increment), increment)
- End If
-
- End If
- End If
+ _webClient = client
+ _progressDialog = dialog
End Sub
'''
@@ -87,10 +46,10 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
''' Note: that we don't want to close the progress dialog here. Wait until
''' the actual file transfer cancel event comes through and do it there.
'''
- Private Sub m_ProgressDialog_UserCancelledEvent() Handles m_ProgressDialog.UserHitCancel
+ Private Sub _progressDialog_UserHitCancel() Handles _progressDialog.UserHitCancel
'cancel the upload/download transfer. We'll close the ProgressDialog
'as soon as the WebClient cancels the xfer.
- m_WebClient.CancelAsync()
+ _webClient.CancelAsync()
End Sub
'''
@@ -98,9 +57,12 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
'''
'''
'''
- Private Sub m_WebClient_DownloadFileCompleted(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs) Handles m_WebClient.DownloadFileCompleted
+ Private Sub _webClient_DownloadFileCompleted(sender As Object, e As ComponentModel.AsyncCompletedEventArgs) _
+ Handles _webClient.DownloadFileCompleted
+
Try
- ' If the download was interrupted by an exception, keep track of the exception, which we'll throw from the main thread
+ ' If the download was interrupted by an exception, keep track of the exception,
+ ' which we'll throw from the main thread
If e.Error IsNot Nothing Then
_exceptionEncounteredDuringFileTransfer = e.Error
End If
@@ -110,7 +72,7 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
End If
Finally
'We don't close the dialog until we receive the WebClient.DownloadFileCompleted event
- CloseProgressDialog()
+ CloseProgressDialog(_progressDialog)
End Try
End Sub
@@ -119,7 +81,9 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
'''
'''
'''
- Private Sub m_WebClient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles m_WebClient.DownloadProgressChanged
+ Private Sub _webClient_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) _
+ Handles _webClient.DownloadProgressChanged
+
InvokeIncrement(e.ProgressPercentage)
End Sub
@@ -128,7 +92,8 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
'''
'''
'''
- Private Sub m_WebClient_UploadFileCompleted(sender As Object, e As UploadFileCompletedEventArgs) Handles m_WebClient.UploadFileCompleted
+ Private Sub _webClient_UploadFileCompleted(sender As Object, e As UploadFileCompletedEventArgs) _
+ Handles _webClient.UploadFileCompleted
' If the upload was interrupted by an exception, keep track of the
' exception, which we'll throw from the main thread
@@ -142,7 +107,7 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
Finally
'We don't close the dialog until we receive the
'WebClient.DownloadFileCompleted event
- CloseProgressDialog()
+ CloseProgressDialog(_progressDialog)
End Try
End Sub
@@ -151,32 +116,59 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
'''
'''
'''
- Private Sub m_WebClient_UploadProgressChanged(sender As Object, e As UploadProgressChangedEventArgs) Handles m_WebClient.UploadProgressChanged
+ Private Sub _webClient_UploadProgressChanged(sender As Object, e As UploadProgressChangedEventArgs) _
+ Handles _webClient.UploadProgressChanged
+
Dim increment As Long = (e.BytesSent * 100) \ e.TotalBytesToSend
InvokeIncrement(CInt(increment))
End Sub
+ '''
+ ''' Notifies the progress dialog to increment the progress bar.
+ '''
+ ''' The percentage of bytes read.
+ Private Sub InvokeIncrement(progressPercentage As Integer)
+ ' Don't invoke unless dialog is up and running
+ If _progressDialog IsNot Nothing Then
+ If _progressDialog.IsHandleCreated Then
+
+ ' For performance, don't invoke if increment is 0
+ Dim increment As Integer = progressPercentage - _percentage
+ _percentage = progressPercentage
+ If increment > 0 Then
+ _progressDialog.BeginInvoke(
+ New DoIncrement(AddressOf _progressDialog.Increment),
+ increment)
+ End If
+
+ End If
+ End If
+ End Sub
+
'''
''' Downloads a file.
'''
''' The source for the file.
''' The path and name where the file is saved.
Public Sub DownloadFile(address As Uri, destinationFileName As String)
- Debug.Assert(m_WebClient IsNot Nothing, "No WebClient")
- Debug.Assert(address IsNot Nothing, "No address")
- Debug.Assert((Not String.IsNullOrWhiteSpace(destinationFileName)) AndAlso Directory.Exists(Path.GetDirectoryName(Path.GetFullPath(destinationFileName))), "Invalid path")
+ Debug.Assert(_webClient IsNot Nothing, $"No {NameOf(_webClient)}")
+ Debug.Assert(address IsNot Nothing, $"No {NameOf(address)}")
+ Dim path As String = IO.Path.GetDirectoryName(IO.Path.GetFullPath(destinationFileName))
+ Debug.Assert((Not String.IsNullOrWhiteSpace(destinationFileName)) _
+ AndAlso IO.Directory.Exists(path), $"Invalid {NameOf(path)}")
' If we have a dialog we need to set up an async download
- If m_ProgressDialog IsNot Nothing Then
- m_WebClient.DownloadFileAsync(address, destinationFileName)
- m_ProgressDialog.ShowProgressDialog() 'returns when the download sequence is over, whether due to success, error, or being canceled
+ If _progressDialog IsNot Nothing Then
+ _webClient.DownloadFileAsync(address, destinationFileName)
+ 'returns when the download sequence is over, whether due to success, error, or being canceled
+ _progressDialog.ShowProgressDialog()
Else
- m_WebClient.DownloadFile(address, destinationFileName)
+ _webClient.DownloadFile(address, destinationFileName)
End If
'Now that we are back on the main thread, throw the exception we encountered if the user didn't cancel.
If _exceptionEncounteredDuringFileTransfer IsNot Nothing Then
- If m_ProgressDialog Is Nothing OrElse Not m_ProgressDialog.UserCanceledTheDialog Then
+ If _progressDialog Is Nothing OrElse Not _progressDialog.UserCanceledTheDialog Then
Throw _exceptionEncounteredDuringFileTransfer
End If
End If
@@ -189,22 +181,24 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
''' The name and path of the source file.
''' The address to which the file is uploaded.
Public Sub UploadFile(sourceFileName As String, address As Uri)
- Debug.Assert(m_WebClient IsNot Nothing, "No WebClient")
- Debug.Assert(address IsNot Nothing, "No address")
- Debug.Assert((Not String.IsNullOrWhiteSpace(sourceFileName)) AndAlso File.Exists(sourceFileName), "Invalid file")
+ Debug.Assert(_webClient IsNot Nothing, $"No {NameOf(_webClient)}")
+ Debug.Assert(address IsNot Nothing, $"No {NameOf(address)}")
+ Debug.Assert((Not String.IsNullOrWhiteSpace(sourceFileName)) _
+ AndAlso IO.File.Exists(sourceFileName), "Invalid file")
' If we have a dialog we need to set up an async download
- If m_ProgressDialog IsNot Nothing Then
- m_WebClient.UploadFileAsync(address, sourceFileName)
- m_ProgressDialog.ShowProgressDialog() 'returns when the download sequence is over, whether due to success, error, or being canceled
+ If _progressDialog IsNot Nothing Then
+ _webClient.UploadFileAsync(address, sourceFileName)
+ 'returns when the download sequence is over, whether due to success, error, or being canceled
+ _progressDialog.ShowProgressDialog()
Else
- m_WebClient.UploadFile(address, sourceFileName)
+ _webClient.UploadFile(address, sourceFileName)
End If
'Now that we are back on the main thread, throw the exception we
'encountered if the user didn't cancel.
If _exceptionEncounteredDuringFileTransfer IsNot Nothing Then
- If m_ProgressDialog Is Nothing OrElse Not m_ProgressDialog.UserCanceledTheDialog Then
+ If _progressDialog Is Nothing OrElse Not _progressDialog.UserCanceledTheDialog Then
Throw _exceptionEncounteredDuringFileTransfer
End If
End If
diff --git a/src/System.Private.Windows.Core/src/NativeMethods.txt b/src/System.Private.Windows.Core/src/NativeMethods.txt
index 0ab48ccad76..41354b135f7 100644
--- a/src/System.Private.Windows.Core/src/NativeMethods.txt
+++ b/src/System.Private.Windows.Core/src/NativeMethods.txt
@@ -74,6 +74,8 @@ FDEX_PROP_FLAGS
FILETIME
GetCurrentThreadId
GetSysColorBrush
+GetWindowText
+GetWindowTextLength
GdipBitmapLockBits
GdipBitmapUnlockBits
GdipCreateFromHWND
@@ -156,6 +158,7 @@ LoadIcon
LoadRegTypeLib
LPARAM
LRESULT
+MapWindowPoints
MAX_PATH
MonitorFromPoint
MonitorFromRect
diff --git a/src/System.Private.Windows.Core/src/Windows/Win32/Foundation/HandleRef.cs b/src/System.Private.Windows.Core/src/Windows/Win32/Foundation/HandleRef.cs
index 291807850ae..92dcc83cdfb 100644
--- a/src/System.Private.Windows.Core/src/Windows/Win32/Foundation/HandleRef.cs
+++ b/src/System.Private.Windows.Core/src/Windows/Win32/Foundation/HandleRef.cs
@@ -1,11 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
namespace Windows.Win32.Foundation;
///
/// Adapter to use when owning classes cannot directly implement .
///
+///
+///
+/// Whenever you need to keep the owning object from being finalized during interop calls, use
+/// on the .
+///
+///
+/// This is the typed equivalent of . Marshalling doesn't know this, and while one
+/// could write a custom marshaler, we want our imports to do no marshalling for performance and trimming reasons.
+///
+///
internal readonly struct HandleRef : IHandle, IEquatable>
where THandle : unmanaged, IEquatable
{
@@ -36,5 +49,27 @@ public bool Equals(HandleRef other)
public static bool operator ==(HandleRef left, HandleRef right) => left.Equals(right);
public static bool operator !=(HandleRef left, HandleRef right) => !(left == right);
+ public static unsafe explicit operator HandleRef(HandleRef handle)
+ {
+ if (sizeof(nint) != sizeof(THandle))
+ {
+ throw new InvalidCastException();
+ }
+
+ THandle local = handle.Handle;
+ return new(handle.Wrapper, Unsafe.As(ref local));
+ }
+
+ public static unsafe explicit operator HandleRef(HandleRef handle)
+ {
+ if (sizeof(nint) != sizeof(THandle))
+ {
+ throw new InvalidCastException();
+ }
+
+ nint local = handle.Handle;
+ return new(handle.Wrapper, Unsafe.As(ref local));
+ }
+
public bool IsNull => Handle.Equals(default);
}
diff --git a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetWindowText.cs b/src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.GetWindowText.cs
similarity index 98%
rename from src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetWindowText.cs
rename to src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.GetWindowText.cs
index b7c9758eb40..16f1b789fb2 100644
--- a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetWindowText.cs
+++ b/src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.GetWindowText.cs
@@ -9,7 +9,7 @@
namespace Windows.Win32;
-internal static partial class PInvoke
+internal static partial class PInvokeCore
{
[SkipLocalsInit]
public static unsafe string GetWindowText(T hWnd) where T : IHandle
diff --git a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetWindowTextLength.cs b/src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.GetWindowTextLength.cs
similarity index 91%
rename from src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetWindowTextLength.cs
rename to src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.GetWindowTextLength.cs
index b3100b2c784..6a339b9b513 100644
--- a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.GetWindowTextLength.cs
+++ b/src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.GetWindowTextLength.cs
@@ -3,7 +3,7 @@
namespace Windows.Win32;
-internal static partial class PInvoke
+internal static partial class PInvokeCore
{
///
public static int GetWindowTextLength(T hWnd) where T : IHandle
diff --git a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.MapWindowPoints.cs b/src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.MapWindowPoints.cs
similarity index 96%
rename from src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.MapWindowPoints.cs
rename to src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.MapWindowPoints.cs
index 9a8a3950c5c..60e67f7051e 100644
--- a/src/System.Windows.Forms.Primitives/src/Windows/Win32/PInvoke.MapWindowPoints.cs
+++ b/src/System.Private.Windows.Core/src/Windows/Win32/PInvoke.MapWindowPoints.cs
@@ -5,7 +5,7 @@
namespace Windows.Win32;
-internal static partial class PInvoke
+internal static partial class PInvokeCore
{
///
public static unsafe int MapWindowPoints(TFrom hWndFrom, TTo hWndTo, ref RECT lpRect)
diff --git a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System.Windows.Forms.Analyzers.CSharp.Tests.csproj b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System.Windows.Forms.Analyzers.CSharp.Tests.csproj
index c53d4a18958..ca28c94ff6d 100644
--- a/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System.Windows.Forms.Analyzers.CSharp.Tests.csproj
+++ b/src/System.Windows.Forms.Analyzers.CSharp/tests/UnitTests/System.Windows.Forms.Analyzers.CSharp.Tests.csproj
@@ -20,7 +20,7 @@
-
+
diff --git a/src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/System.Windows.Forms.Analyzers.VisualBasic.Tests.vbproj b/src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/System.Windows.Forms.Analyzers.VisualBasic.Tests.vbproj
index 5f6ed966383..a8eb9b5508a 100644
--- a/src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/System.Windows.Forms.Analyzers.VisualBasic.Tests.vbproj
+++ b/src/System.Windows.Forms.Analyzers.VisualBasic/tests/UnitTests/System.Windows.Forms.Analyzers.VisualBasic.Tests/System.Windows.Forms.Analyzers.VisualBasic.Tests.vbproj
@@ -22,7 +22,7 @@
-
+
diff --git a/src/System.Windows.Forms.Analyzers/tests/UnitTests/System.Windows.Forms.Analyzers.Tests.csproj b/src/System.Windows.Forms.Analyzers/tests/UnitTests/System.Windows.Forms.Analyzers.Tests.csproj
index 86584281b28..781b7a39230 100644
--- a/src/System.Windows.Forms.Analyzers/tests/UnitTests/System.Windows.Forms.Analyzers.Tests.csproj
+++ b/src/System.Windows.Forms.Analyzers/tests/UnitTests/System.Windows.Forms.Analyzers.Tests.csproj
@@ -23,7 +23,7 @@
-
+
diff --git a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/MultilineStringEditor.MultilineStringEditorUI.cs b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/MultilineStringEditor.MultilineStringEditorUI.cs
index f33bfe0efec..e8f811fb9e3 100644
--- a/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/MultilineStringEditor.MultilineStringEditorUI.cs
+++ b/src/System.Windows.Forms.Design/src/System/ComponentModel/Design/MultilineStringEditor.MultilineStringEditorUI.cs
@@ -334,7 +334,7 @@ public override string Text
return string.Empty;
}
- string windowText = PInvoke.GetWindowText(this);
+ string windowText = PInvokeCore.GetWindowText(this);
if (!_ctrlEnterPressed)
{
return windowText;
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs
index b40189a18be..263541f38c3 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs
@@ -270,7 +270,7 @@ public Point ControlToAdornerWindow(Control c)
}
Point pt = new(c.Left, c.Top);
- PInvoke.MapWindowPoints(c.Parent, _adornerWindow, ref pt);
+ PInvokeCore.MapWindowPoints(c.Parent, _adornerWindow, ref pt);
if (c.Parent.IsMirrored)
{
pt.X -= c.Width;
@@ -284,7 +284,7 @@ public Point ControlToAdornerWindow(Control c)
///
public Point MapAdornerWindowPoint(IntPtr handle, Point pt)
{
- PInvoke.MapWindowPoints((HWND)handle, _adornerWindow, ref pt);
+ PInvokeCore.MapWindowPoints((HWND)handle, _adornerWindow, ref pt);
return pt;
}
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs
index 17588b0b7f0..91468f43523 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ControlDesigner.cs
@@ -287,7 +287,7 @@ internal Point GetOffsetToClientArea()
Point nativeOffset = default;
if (Control.Parent is { } parent)
{
- PInvoke.MapWindowPoints(Control, parent, ref nativeOffset);
+ PInvokeCore.MapWindowPoints(Control, parent, ref nativeOffset);
}
Point offset = Control.Location;
@@ -1778,7 +1778,7 @@ protected virtual unsafe void WndProc(ref Message m)
if (m.MsgInternal >= PInvokeCore.WM_MOUSEFIRST && m.MsgInternal <= PInvokeCore.WM_MOUSELAST)
{
location = PARAM.ToPoint(m.LParamInternal);
- PInvoke.MapWindowPoints(m, (HWND)default, ref location);
+ PInvokeCore.MapWindowPoints(m, (HWND)default, ref location);
}
else if (m.MsgInternal >= PInvokeCore.WM_NCMOUSEMOVE && m.MsgInternal <= PInvokeCore.WM_NCMBUTTONDBLCLK)
{
@@ -2068,9 +2068,9 @@ protected virtual unsafe void WndProc(ref Message m)
{
// Re-map the clip rect we pass to the paint event args to our child coordinates.
Point point = default;
- PInvoke.MapWindowPoints(m.HWND, Control, ref point);
+ PInvokeCore.MapWindowPoints(m.HWND, Control, ref point);
graphics.TranslateTransform(-point.X, -point.Y);
- PInvoke.MapWindowPoints(m.HWND, Control, ref clip);
+ PInvokeCore.MapWindowPoints(m.HWND, Control, ref clip);
}
Rectangle paintRect = clip;
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ListViewDesigner.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ListViewDesigner.cs
index 75a5ae3dfe5..5132596132e 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ListViewDesigner.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ListViewDesigner.cs
@@ -83,7 +83,7 @@ protected override unsafe bool GetHitTest(Point point)
HWND headerHwnd = (HWND)PInvokeCore.SendMessage(listView, PInvoke.LVM_GETHEADER);
if (hwndHit == headerHwnd)
{
- PInvoke.MapWindowPoints(HWND.Null, headerHwnd, ref point);
+ PInvokeCore.MapWindowPoints(HWND.Null, headerHwnd, ref point);
_hdrhit.pt = point;
PInvokeCore.SendMessage(headerHwnd, PInvoke.HDM_HITTEST, 0, ref _hdrhit);
if (_hdrhit.flags == HEADER_HITTEST_INFO_FLAGS.HHT_ONDIVIDER)
diff --git a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripAdornerWindowService.cs b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripAdornerWindowService.cs
index 8abe894e35e..a0f80d1c1fa 100644
--- a/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripAdornerWindowService.cs
+++ b/src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/ToolStripAdornerWindowService.cs
@@ -108,7 +108,7 @@ public Point ControlToAdornerWindow(Control c)
}
Point pt = new(c.Left, c.Top);
- PInvoke.MapWindowPoints(c.Parent, _toolStripAdornerWindow, ref pt);
+ PInvokeCore.MapWindowPoints(c.Parent, _toolStripAdornerWindow, ref pt);
return pt;
}
diff --git a/src/System.Windows.Forms.Primitives/src/NativeMethods.txt b/src/System.Windows.Forms.Primitives/src/NativeMethods.txt
index d0315834878..cef1c663efe 100644
--- a/src/System.Windows.Forms.Primitives/src/NativeMethods.txt
+++ b/src/System.Windows.Forms.Primitives/src/NativeMethods.txt
@@ -239,8 +239,6 @@ GetViewportExtEx
GetWindow
GetWindowDpiAwarenessContext
GetWindowPlacement
-GetWindowText
-GetWindowTextLength
GetWindowThreadProcessId
GetWorldTransform
GMR_*
@@ -456,7 +454,6 @@ LVTILEVIEWINFO_FLAGS
LVTILEVIEWINFO_MASK
MA_*
MapVirtualKey
-MapWindowPoints
MAX_TAB_STOPS
MCGRIDINFO
MCGRIDINFO_FLAGS
diff --git a/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj b/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj
index b9bf37356e1..5d0859b2ba8 100644
--- a/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj
+++ b/src/System.Windows.Forms.Primitives/tests/TestUtilities/System.Windows.Forms.Primitives.TestUtilities.csproj
@@ -16,7 +16,7 @@
-
+
diff --git a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs
index c27e6b25dd3..71413e64ab4 100644
--- a/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs
+++ b/src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/User32/GetWindowTextTests.cs
@@ -34,7 +34,7 @@ private void CallGetWindowText(bool useBeforeGetTextLengthCallback)
windowClass.BeforeGetTextLengthCallback = () => shortText;
}
- string result = PInvoke.GetWindowText(windowHandle);
+ string result = PInvokeCore.GetWindowText(windowHandle);
PInvoke.DestroyWindow(windowHandle);
Assert.Equal(longText, result);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Accessibility/LabelEditAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Accessibility/LabelEditAccessibleObject.cs
index 42151b43f84..b8f2849e309 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Accessibility/LabelEditAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Accessibility/LabelEditAccessibleObject.cs
@@ -66,7 +66,7 @@ internal override IRawElementProviderSimple* HostRawElementProvider
};
public override string? Name => _labelEdit.TryGetTarget(out var target)
- ? PInvoke.GetWindowText(target)
+ ? PInvokeCore.GetWindowText(target)
: null;
private protected override bool IsInternal => true;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Accessibility/LabelEditUiaTextProvider.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Accessibility/LabelEditUiaTextProvider.cs
index c887ec9b392..1397d1d2b66 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Accessibility/LabelEditUiaTextProvider.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Accessibility/LabelEditUiaTextProvider.cs
@@ -61,7 +61,7 @@ public override ITextRangeProvider* DocumentRange
public override SupportedTextSelection SupportedTextSelection => SupportedTextSelection.SupportedTextSelection_Single;
- public override string Text => PInvoke.GetWindowText(_owningChildEdit);
+ public override string Text => PInvokeCore.GetWindowText(_owningChildEdit);
public override int TextLength => (int)PInvokeCore.SendMessage(_owningChildEdit, PInvokeCore.WM_GETTEXTLENGTH);
@@ -225,7 +225,7 @@ public override bool LineScroll(int charactersHorizontal, int linesVertical)
public override Point PointToScreen(Point pt)
{
- PInvoke.MapWindowPoints(_owningChildEdit.Handle, HWND.Null, ref pt);
+ PInvokeCore.MapWindowPoints(_owningChildEdit.Handle, HWND.Null, ref pt);
return pt;
}
@@ -269,7 +269,7 @@ public override HRESULT RangeFromPoint(UiaPoint point, ITextRangeProvider** pRet
// Convert screen to client coordinates.
// (Essentially ScreenToClient but MapWindowPoints accounts for window mirroring using WS_EX_LAYOUTRTL.)
- if (PInvoke.MapWindowPoints(HWND.Null, _owningChildEdit.Handle, ref clientLocation) == 0)
+ if (PInvokeCore.MapWindowPoints(HWND.Null, _owningChildEdit.Handle, ref clientLocation) == 0)
{
*pRetVal = ComHelpers.GetComPointer(
new UiaTextRange(
@@ -305,7 +305,7 @@ public override HRESULT RangeFromPoint(UiaPoint point, ITextRangeProvider** pRet
public override Rectangle RectangleToScreen(Rectangle rect)
{
RECT r = rect;
- PInvoke.MapWindowPoints(_owningChildEdit.Handle, HWND.Null, ref r);
+ PInvokeCore.MapWindowPoints(_owningChildEdit.Handle, HWND.Null, ref r);
return r;
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/Control.ActiveXImpl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/Control.ActiveXImpl.cs
index 34b4b41802e..956d3b37f3d 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/Control.ActiveXImpl.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/ActiveX/Control.ActiveXImpl.cs
@@ -360,7 +360,7 @@ internal unsafe HRESULT DoVerb(
HWND hwndMap = hwnd.IsNull ? hwndParent : hwnd;
Point pt = new(PARAM.LOWORD(lpmsg->lParam), PARAM.HIWORD(lpmsg->lParam));
- PInvoke.MapWindowPoints(hwndMap, _control, ref pt);
+ PInvokeCore.MapWindowPoints(hwndMap, _control, ref pt);
// Check to see if this message should really go to a child control, and if so, map the
// point into that child's window coordinates.
@@ -1812,7 +1812,7 @@ internal unsafe HRESULT SetObjectRects(RECT* lprcPosRect, RECT* lprcClipRect)
RECT rcIntersect = intersect;
HWND hWndParent = PInvoke.GetParent(_control);
- PInvoke.MapWindowPoints(hWndParent, _control, ref rcIntersect);
+ PInvokeCore.MapWindowPoints(hWndParent, _control, ref rcIntersect);
_lastClipRect = rcIntersect;
setRegion = true;
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
index 504df44ad99..0b70b40114c 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
@@ -3581,7 +3581,7 @@ internal virtual string WindowText
}
using var scope = MultithreadSafeCallScope.Create();
- return PInvoke.GetWindowText(this);
+ return PInvokeCore.GetWindowText(this);
}
set
{
@@ -8462,7 +8462,7 @@ internal bool PerformContainerValidation(ValidationConstraints validationConstra
///
public Point PointToClient(Point p)
{
- PInvoke.MapWindowPoints((HWND)default, this, ref p);
+ PInvokeCore.MapWindowPoints((HWND)default, this, ref p);
return p;
}
@@ -8471,7 +8471,7 @@ public Point PointToClient(Point p)
///
public Point PointToScreen(Point p)
{
- PInvoke.MapWindowPoints(this, (HWND)default, ref p);
+ PInvokeCore.MapWindowPoints(this, (HWND)default, ref p);
return p;
}
@@ -9250,7 +9250,7 @@ internal virtual void RecreateHandleCore()
public Rectangle RectangleToClient(Rectangle r)
{
RECT rect = r;
- PInvoke.MapWindowPoints(HWND.Null, this, ref rect);
+ PInvokeCore.MapWindowPoints(HWND.Null, this, ref rect);
return rect;
}
@@ -9260,7 +9260,7 @@ public Rectangle RectangleToClient(Rectangle r)
public Rectangle RectangleToScreen(Rectangle r)
{
RECT rect = r;
- PInvoke.MapWindowPoints(this, HWND.Null, ref rect);
+ PInvokeCore.MapWindowPoints(this, HWND.Null, ref rect);
return rect;
}
@@ -10721,7 +10721,7 @@ protected internal void UpdateBounds()
PInvokeCore.GetWindowRect(this, out rect);
if (!GetTopLevel())
{
- PInvoke.MapWindowPoints(HWND.Null, PInvoke.GetParent(this), ref rect);
+ PInvokeCore.MapWindowPoints(HWND.Null, PInvoke.GetParent(this), ref rect);
}
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.ComboBoxItemAccessibleObject.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.ComboBoxItemAccessibleObject.cs
index ea613e32f8e..d49d703126f 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.ComboBoxItemAccessibleObject.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.ComboBoxItemAccessibleObject.cs
@@ -51,7 +51,7 @@ public override Rectangle Bounds
// Translate the item rect to screen coordinates
RECT translated = itemRect;
- PInvoke.MapWindowPoints(listHandle, HWND.Null, ref translated);
+ PInvokeCore.MapWindowPoints(listHandle, HWND.Null, ref translated);
return translated;
}
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.ComboBoxUiaTextProvider.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.ComboBoxUiaTextProvider.cs
index 94d47b5157f..7ac16d211bd 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.ComboBoxUiaTextProvider.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBox.ComboBoxUiaTextProvider.cs
@@ -97,7 +97,7 @@ public override LOGFONTW Logfont
public override string Text
=> _owningComboBox.IsHandleCreated
- ? PInvoke.GetWindowText(_owningChildEdit)
+ ? PInvokeCore.GetWindowText(_owningChildEdit)
: string.Empty;
public override int TextLength
@@ -292,7 +292,7 @@ public override bool LineScroll(int charactersHorizontal, int linesVertical)
public override Point PointToScreen(Point pt)
{
- PInvoke.MapWindowPoints(_owningChildEdit, (HWND)default, ref pt);
+ PInvokeCore.MapWindowPoints(_owningChildEdit, (HWND)default, ref pt);
return pt;
}
@@ -342,7 +342,7 @@ public override HRESULT RangeFromPoint(UiaPoint point, ITextRangeProvider** pRet
// Convert screen to client coordinates.
// (Essentially ScreenToClient but MapWindowPoints accounts for window mirroring using WS_EX_LAYOUTRTL.)
- if (PInvoke.MapWindowPoints((HWND)default, _owningChildEdit, ref clientLocation) == 0)
+ if (PInvokeCore.MapWindowPoints((HWND)default, _owningChildEdit, ref clientLocation) == 0)
{
*pRetVal = ComHelpers.GetComPointer(
new UiaTextRange(
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs
index 279abf1aec0..94b9dd5d3c9 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs
@@ -391,7 +391,7 @@ public override Font Font
get => base.Font;
set
{
- if (!IsHandleCreated || PInvoke.GetWindowTextLength(this) <= 0)
+ if (!IsHandleCreated || PInvokeCore.GetWindowTextLength(this) <= 0)
{
base.Font = value;
return;
@@ -1965,7 +1965,7 @@ public int Find(char[] characterSet, int start, int end)
return -1;
}
- textLength = PInvoke.GetWindowTextLength(this);
+ textLength = PInvokeCore.GetWindowTextLength(this);
if (start == end)
{
start = 0;
@@ -3392,7 +3392,7 @@ private void WmSelectionChange(SELCHANGE selChange)
LRESULT compMode = PInvokeCore.SendMessage(this, PInvokeCore.EM_GETIMECOMPMODE);
if (compMode != PInvoke.ICM_NOTOPEN)
{
- int textLength = PInvoke.GetWindowTextLength(this);
+ int textLength = PInvokeCore.GetWindowTextLength(this);
if (selStart == selEnd && textLength == MaxLength)
{
PInvokeCore.SendMessage(this, PInvokeCore.WM_KILLFOCUS);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBoxBase.TextBoxBaseUiaTextProvider.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBoxBase.TextBoxBaseUiaTextProvider.cs
index 68a2c1d69bb..db73cb1f741 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBoxBase.TextBoxBaseUiaTextProvider.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBoxBase.TextBoxBaseUiaTextProvider.cs
@@ -107,7 +107,7 @@ public override HRESULT RangeFromPoint(UiaPoint point, ITextRangeProvider** pRet
// Convert screen to client coordinates.
// (Essentially ScreenToClient but MapWindowPoints accounts for window mirroring using WS_EX_LAYOUTRTL.)
- if (PInvoke.MapWindowPoints((HWND)default, Owner, ref clientLocation) == 0)
+ if (PInvokeCore.MapWindowPoints((HWND)default, Owner, ref clientLocation) == 0)
{
*pRetVal = ComHelpers.GetComPointer(
new UiaTextRange(
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBoxBase.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBoxBase.cs
index 0ecf890d3a6..dc4ddfd02db 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBoxBase.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TextBox/TextBoxBase.cs
@@ -1089,7 +1089,7 @@ public virtual int TextLength
// Note: Currently WinForms does not fully support surrogates. If
// the text contains surrogate characters this property may return incorrect values.
- => IsHandleCreated ? PInvoke.GetWindowTextLength(this) : Text.Length;
+ => IsHandleCreated ? PInvokeCore.GetWindowTextLength(this) : Text.Length;
internal override string WindowText
{
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs
index c451f6f2921..793565dc2c2 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/StatusStrip.cs
@@ -586,7 +586,7 @@ protected override void WndProc(ref Message m)
gripLocation = new Point(SizeGripBounds.Right, SizeGripBounds.Bottom);
}
- PInvoke.MapWindowPoints(this, rootHwnd, ref gripLocation);
+ PInvokeCore.MapWindowPoints(this, rootHwnd, ref gripLocation);
int deltaBottomEdge = Math.Abs(rootHwndClientArea.bottom - gripLocation.Y);
int deltaRightEdge = Math.Abs(rootHwndClientArea.right - gripLocation.X);
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripManager.ModalMenuFilter.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripManager.ModalMenuFilter.cs
index 07efc345062..839fb73d14c 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripManager.ModalMenuFilter.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripManager.ModalMenuFilter.cs
@@ -333,7 +333,7 @@ private void ProcessMouseButtonPressed(HWND hwndMouseMessageIsFrom, Point locati
if (activeToolStrip is not null)
{
Point translatedLocation = location;
- PInvoke.MapWindowPoints(hwndMouseMessageIsFrom, activeToolStrip, ref translatedLocation);
+ PInvokeCore.MapWindowPoints(hwndMouseMessageIsFrom, activeToolStrip, ref translatedLocation);
if (!activeToolStrip.ClientRectangle.Contains(translatedLocation))
{
if (activeToolStrip is ToolStripDropDown activeToolStripDropDown)
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/CommonDialogs/FileDialog.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/CommonDialogs/FileDialog.cs
index 040bdc13573..b8afd168404 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/CommonDialogs/FileDialog.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Dialogs/CommonDialogs/FileDialog.cs
@@ -151,7 +151,7 @@ public bool DereferenceLinks
set => SetOption(OFN_NODEREFERENCELINKS, !value);
}
- private protected string DialogCaption => PInvoke.GetWindowText(_dialogHWnd);
+ private protected string DialogCaption => PInvokeCore.GetWindowText(_dialogHWnd);
///
/// Gets or sets a string containing the file name selected in the file dialog box.
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Internal/WinFormsUtils.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Internal/WinFormsUtils.cs
index e82f9df6e16..5496f69767f 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Internal/WinFormsUtils.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Internal/WinFormsUtils.cs
@@ -158,7 +158,7 @@ internal static string GetControlInformation(HWND hwnd)
}
#if DEBUG
- string windowText = PInvoke.GetWindowText(hwnd);
+ string windowText = PInvokeCore.GetWindowText(hwnd);
string typeOfControl = "Unknown";
string nameOfControl = "";
Control? c = Control.FromHandle(hwnd);
@@ -283,7 +283,7 @@ public static char GetMnemonic(string? text, bool convertToUpperCase)
///
public static Point TranslatePoint(Point point, Control fromControl, Control toControl)
{
- PInvoke.MapWindowPoints(fromControl, toControl, ref point);
+ PInvokeCore.MapWindowPoints(fromControl, toControl, ref point);
return point;
}
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs
index a08fa70f1e9..900eec76512 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Printing/PrintPreviewControl.cs
@@ -592,7 +592,7 @@ private void CalculatePageInfo()
private void DrawMessage(Graphics g, Rectangle rect, bool isExceptionPrinting)
{
- using var brush = ForeColor.GetCachedSolidBrushScope();
+ using var brush = SystemColors.ControlText.GetCachedSolidBrushScope();
using StringFormat format = new()
{
diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip/ToolTip.cs b/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip/ToolTip.cs
index c56f6b45640..6fad5f45a92 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip/ToolTip.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/ToolTip/ToolTip.cs
@@ -2052,7 +2052,7 @@ private void WmShow()
// Use GetWindowText instead of GetCaptionForTool to retrieve the actual caption.
// GetCaptionForTool doesn't work correctly when the text for a tool is retrieved
// by TTN_NEEDTEXT notification (e.g. TabPages of TabControl).
- AnnounceText(toolControl, PInvoke.GetWindowText(this));
+ AnnounceText(toolControl, PInvokeCore.GetWindowText(this));
}
// We need to re-get the rectangle of the tooltip here because
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/TestHelpers.cs b/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/TestHelpers.cs
index 0748cec2e59..9ec3ee661f7 100644
--- a/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/TestHelpers.cs
+++ b/src/System.Windows.Forms/tests/IntegrationTests/System.Windows.Forms.IntegrationTests.Common/TestHelpers.cs
@@ -442,7 +442,7 @@ internal static bool SendKeysToProcess(Process process, string keys, bool switch
HWND foregroundWindow = PInvokeCore.GetForegroundWindow();
- string windowTitle = PInvoke.GetWindowText(foregroundWindow);
+ string windowTitle = PInvokeCore.GetWindowText(foregroundWindow);
if (PInvoke.GetWindowThreadProcessId(foregroundWindow, out uint processId) == 0 ||
processId != process.Id)
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/SendInput.cs b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/SendInput.cs
index de5eb270603..0a375371c24 100644
--- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/SendInput.cs
+++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Infra/SendInput.cs
@@ -85,7 +85,7 @@ private static void SetForegroundWindow(Form window)
// Move the window into the foreground as it may not have been achieved by the 'SetWindowPos' call
if (!PInvoke.SetForegroundWindow(window))
{
- string windowTitle = PInvoke.GetWindowText(window);
+ string windowTitle = PInvokeCore.GetWindowText(window);
if (PInvoke.GetWindowThreadProcessId(window, out uint processId) == 0 || processId != Environment.ProcessId)
{
string message = $"ForegroundWindow doesn't belong the test process! The current window HWND: {window}, title:{windowTitle}.";
diff --git a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/System.Windows.Forms.UI.IntegrationTests.csproj b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/System.Windows.Forms.UI.IntegrationTests.csproj
index 90c10249e2a..b13e4ca4193 100644
--- a/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/System.Windows.Forms.UI.IntegrationTests.csproj
+++ b/src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/System.Windows.Forms.UI.IntegrationTests.csproj
@@ -17,7 +17,7 @@
-
+
diff --git a/src/Common/tests/TestUtilities/AnchorLayoutV2Scope.cs b/src/System.Windows.Forms/tests/TestUtilities/AnchorLayoutV2Scope.cs
similarity index 91%
rename from src/Common/tests/TestUtilities/AnchorLayoutV2Scope.cs
rename to src/System.Windows.Forms/tests/TestUtilities/AnchorLayoutV2Scope.cs
index 5f07b05cac9..76915aef94f 100644
--- a/src/Common/tests/TestUtilities/AnchorLayoutV2Scope.cs
+++ b/src/System.Windows.Forms/tests/TestUtilities/AnchorLayoutV2Scope.cs
@@ -16,7 +16,7 @@ public AnchorLayoutV2Scope(bool enable)
// Prevent multiple AnchorLayoutV2Scope instances from running simultaneously.
// Using Monitor to allow recursion on the same thread.
Monitor.Enter(typeof(AnchorLayoutV2Scope));
- _switchScope = new(AppContextSwitchNames.AnchorLayoutV2, enable);
+ _switchScope = new(WinFormsAppContextSwitchNames.AnchorLayoutV2, enable);
}
public void Dispose()
diff --git a/src/Common/tests/TestUtilities/ApplyParentFontToMenusScope.cs b/src/System.Windows.Forms/tests/TestUtilities/ApplyParentFontToMenusScope.cs
similarity index 90%
rename from src/Common/tests/TestUtilities/ApplyParentFontToMenusScope.cs
rename to src/System.Windows.Forms/tests/TestUtilities/ApplyParentFontToMenusScope.cs
index 192cad2c4eb..5a6366cf9ef 100644
--- a/src/Common/tests/TestUtilities/ApplyParentFontToMenusScope.cs
+++ b/src/System.Windows.Forms/tests/TestUtilities/ApplyParentFontToMenusScope.cs
@@ -16,7 +16,7 @@ public ApplyParentFontToMenusScope(bool enable)
// Prevent multiple ApplyParentFontToMenusScopes from running simultaneously. Using Monitor to allow recursion on
// the same thread.
Monitor.Enter(typeof(ApplyParentFontToMenusScope));
- _switchScope = new(AppContextSwitchNames.ApplyParentFontToMenus, enable);
+ _switchScope = new(WinFormsAppContextSwitchNames.ApplyParentFontToMenus, enable);
}
public void Dispose()
diff --git a/src/Common/tests/TestUtilities/DataGridViewUIAStartRowCountAtZeroScope.cs b/src/System.Windows.Forms/tests/TestUtilities/DataGridViewUIAStartRowCountAtZeroScope.cs
similarity index 90%
rename from src/Common/tests/TestUtilities/DataGridViewUIAStartRowCountAtZeroScope.cs
rename to src/System.Windows.Forms/tests/TestUtilities/DataGridViewUIAStartRowCountAtZeroScope.cs
index 73992929041..7df6754afff 100644
--- a/src/Common/tests/TestUtilities/DataGridViewUIAStartRowCountAtZeroScope.cs
+++ b/src/System.Windows.Forms/tests/TestUtilities/DataGridViewUIAStartRowCountAtZeroScope.cs
@@ -15,7 +15,7 @@ public DataGridViewUIAStartRowCountAtZeroScope(bool enable)
// Prevent multiple BinaryFormatterScopes from running simultaneously. Using Monitor to allow recursion on
// the same thread.
Monitor.Enter(typeof(DataGridViewUIAStartRowCountAtZeroScope));
- _switchScope = new(AppContextSwitchNames.DataGridViewUIAStartRowCountAtZero, enable);
+ _switchScope = new(WinFormsAppContextSwitchNames.DataGridViewUIAStartRowCountAtZero, enable);
}
public void Dispose()
diff --git a/src/Common/tests/TestUtilities/NoClientNotificationsScope.cs b/src/System.Windows.Forms/tests/TestUtilities/NoClientNotificationsScope.cs
similarity index 91%
rename from src/Common/tests/TestUtilities/NoClientNotificationsScope.cs
rename to src/System.Windows.Forms/tests/TestUtilities/NoClientNotificationsScope.cs
index def9b9c6009..05f4e146262 100644
--- a/src/Common/tests/TestUtilities/NoClientNotificationsScope.cs
+++ b/src/System.Windows.Forms/tests/TestUtilities/NoClientNotificationsScope.cs
@@ -16,7 +16,7 @@ public NoClientNotificationsScope(bool enable)
// Prevent multiple NoClientNotificationsScopes from running simultaneously. Using Monitor to allow recursion on
// the same thread.
Monitor.Enter(typeof(NoClientNotificationsScope));
- _switchScope = new(AppContextSwitchNames.NoClientNotifications, enable);
+ _switchScope = new(WinFormsAppContextSwitchNames.NoClientNotifications, enable);
}
public void Dispose()
diff --git a/src/Common/tests/TestUtilities/ScaleTopLevelFormMinMaxSizeForDpiScope.cs b/src/System.Windows.Forms/tests/TestUtilities/ScaleTopLevelFormMinMaxSizeForDpiScope.cs
similarity index 90%
rename from src/Common/tests/TestUtilities/ScaleTopLevelFormMinMaxSizeForDpiScope.cs
rename to src/System.Windows.Forms/tests/TestUtilities/ScaleTopLevelFormMinMaxSizeForDpiScope.cs
index 1bc6029ebfc..4019ff4c55c 100644
--- a/src/Common/tests/TestUtilities/ScaleTopLevelFormMinMaxSizeForDpiScope.cs
+++ b/src/System.Windows.Forms/tests/TestUtilities/ScaleTopLevelFormMinMaxSizeForDpiScope.cs
@@ -16,7 +16,7 @@ public ScaleTopLevelFormMinMaxSizeForDpiScope(bool enable)
// Prevent multiple ScaleTopLevelFormMinMaxSizeForDpi from running simultaneously.
// Using Monitor to allow recursion on the same thread.
Monitor.Enter(typeof(ScaleTopLevelFormMinMaxSizeForDpiScope));
- _switchScope = new(AppContextSwitchNames.ScaleTopLevelFormMinMaxSizeForDpi, enable);
+ _switchScope = new(WinFormsAppContextSwitchNames.ScaleTopLevelFormMinMaxSizeForDpi, enable);
}
public void Dispose()
diff --git a/src/Common/tests/TestUtilities/ServicePointManagerCheckCrlScope.cs b/src/System.Windows.Forms/tests/TestUtilities/ServicePointManagerCheckCrlScope.cs
similarity index 90%
rename from src/Common/tests/TestUtilities/ServicePointManagerCheckCrlScope.cs
rename to src/System.Windows.Forms/tests/TestUtilities/ServicePointManagerCheckCrlScope.cs
index 7f070c99dfb..1db15540067 100644
--- a/src/Common/tests/TestUtilities/ServicePointManagerCheckCrlScope.cs
+++ b/src/System.Windows.Forms/tests/TestUtilities/ServicePointManagerCheckCrlScope.cs
@@ -16,7 +16,7 @@ public ServicePointManagerCheckCrlScope(bool enable)
// Prevent multiple ServicePointManagerCheckCrlScope instances from running simultaneously.
// Using Monitor to allow recursion on the same thread.
Monitor.Enter(typeof(ServicePointManagerCheckCrlScope));
- _switchScope = new(AppContextSwitchNames.ServicePointManagerCheckCrl, enable);
+ _switchScope = new(WinFormsAppContextSwitchNames.ServicePointManagerCheckCrl, enable);
}
public void Dispose()
diff --git a/src/Common/tests/TestUtilities/TreeNodeCollectionAddRangeRespectsSortOrderScope.cs b/src/System.Windows.Forms/tests/TestUtilities/TreeNodeCollectionAddRangeRespectsSortOrderScope.cs
similarity index 90%
rename from src/Common/tests/TestUtilities/TreeNodeCollectionAddRangeRespectsSortOrderScope.cs
rename to src/System.Windows.Forms/tests/TestUtilities/TreeNodeCollectionAddRangeRespectsSortOrderScope.cs
index 2269ff9805a..8a9261388f8 100644
--- a/src/Common/tests/TestUtilities/TreeNodeCollectionAddRangeRespectsSortOrderScope.cs
+++ b/src/System.Windows.Forms/tests/TestUtilities/TreeNodeCollectionAddRangeRespectsSortOrderScope.cs
@@ -15,7 +15,7 @@ public TreeNodeCollectionAddRangeRespectsSortOrderScope(bool enable)
// Prevent multiple TreeNodeCollectionAddRangeRespectsSortOrderScopes from running simultaneously.
// Using Monitor to allow recursion on the same thread.
Monitor.Enter(typeof(TreeNodeCollectionAddRangeRespectsSortOrderScope));
- _switchScope = new(AppContextSwitchNames.TreeNodeCollectionAddRangeRespectsSortOrder, enable);
+ _switchScope = new(WinFormsAppContextSwitchNames.TreeNodeCollectionAddRangeRespectsSortOrder, enable);
}
public void Dispose()
diff --git a/src/System.Windows.Forms/tests/TestUtilities/WinFormsAppContextSwitchNames.cs b/src/System.Windows.Forms/tests/TestUtilities/WinFormsAppContextSwitchNames.cs
new file mode 100644
index 00000000000..8bc32a947c0
--- /dev/null
+++ b/src/System.Windows.Forms/tests/TestUtilities/WinFormsAppContextSwitchNames.cs
@@ -0,0 +1,53 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace System;
+
+public static class WinFormsAppContextSwitchNames
+{
+ ///
+ /// The switch that controls whether AnchorLayoutV2 feature is enabled.
+ ///
+ public const string AnchorLayoutV2
+ = "System.Windows.Forms.AnchorLayoutV2";
+
+ ///
+ /// The switch that controls whether the parent font
+ /// (as set by
+ /// or by the parent control or form's font) is applied to menus.
+ ///
+ public const string ApplyParentFontToMenus
+ = "System.Windows.Forms.ApplyParentFontToMenus";
+
+ ///
+ /// The switch that controls whether or not the DataGridView starts its UI row count at zero.
+ ///
+ public const string DataGridViewUIAStartRowCountAtZero
+ = "System.Windows.Forms.DataGridViewUIAStartRowCountAtZero";
+
+ ///
+ /// The switch that controls whether UIA notifications are raised.
+ ///
+ public const string NoClientNotifications
+ = "Switch.System.Windows.Forms.AccessibleObject.NoClientNotifications";
+
+ ///
+ /// The switch that controls whether to scale the top level form min/max size for dpi.
+ ///
+ public const string ScaleTopLevelFormMinMaxSizeForDpi
+ = "System.Windows.Forms.ScaleTopLevelFormMinMaxSizeForDpi";
+
+ ///
+ /// The switch that controls whether certificates are checked against the certificate authority revocation list.
+ /// If true, revoked certificates will not be accepted by WebRequests and WebClients as valid.
+ /// Otherwise, revoked certificates will be accepted as valid.
+ ///
+ public const string ServicePointManagerCheckCrl
+ = "System.Windows.Forms.ServicePointManagerCheckCrl";
+
+ ///
+ /// The switch that controls whether the TreeNodeCollection will insert nodes in the sorted order.
+ ///
+ public const string TreeNodeCollectionAddRangeRespectsSortOrder
+ = "System.Windows.Forms.ApplyParentFontToMenus";
+}
diff --git a/src/System.Windows.Forms/tests/UnitTests/DpiHelperTests.cs b/src/System.Windows.Forms/tests/UnitTests/DpiHelperTests.cs
index b9f591b944d..7ea87b545fd 100644
--- a/src/System.Windows.Forms/tests/UnitTests/DpiHelperTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/DpiHelperTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Drawing;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/GlobalUsings.cs b/src/System.Windows.Forms/tests/UnitTests/GlobalUsings.cs
index 72156815b28..4a17bb78e74 100644
--- a/src/System.Windows.Forms/tests/UnitTests/GlobalUsings.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/GlobalUsings.cs
@@ -4,6 +4,7 @@
global using System.Diagnostics;
global using System.Windows.Forms;
global using System.Private.Windows.Core;
+global using System.Private.Windows.Core.TestUtilities;
global using Windows.Win32;
global using Windows.Win32.Foundation;
global using Windows.Win32.Graphics.Gdi;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderConverterTests.cs
index 89ee023cf45..35284384405 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ColumnHeaderConverterTests.cs
@@ -3,7 +3,6 @@
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Internals.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Internals.cs
index 200ad80c7aa..039839a7e90 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Internals.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Internals.cs
@@ -3,7 +3,6 @@
using System.Drawing;
using System.Runtime.CompilerServices;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Properties.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Properties.cs
index 6fd8409b5ec..a9764cdc269 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Properties.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ControlTests.Properties.cs
@@ -5,8 +5,8 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms.Layout;
-using Moq;
using System.Windows.Forms.TestUtilities;
+using Moq;
using Windows.Win32.System.Ole;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CreateParamsTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CreateParamsTests.cs
index 40e1233fb31..ba17e7079cd 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CreateParamsTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CreateParamsTests.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Windows.Forms.TestUtilities;
-
namespace System.Windows.Forms.Tests;
// NB: doesn't require thread affinity
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CursorConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CursorConverterTests.cs
index 9ae3a40b80a..9f55023a978 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CursorConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CursorConverterTests.cs
@@ -4,7 +4,6 @@
using System.ComponentModel.Design.Serialization;
using System.Drawing;
using System.Reflection;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleTests.cs
index 9da2b1bf633..f5bb1330b10 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleTests.cs
@@ -4,7 +4,6 @@
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageListTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageListTests.cs
index cead2dd8cdf..7cbca8b5ec0 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageListTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ImageListTests.cs
@@ -4,7 +4,6 @@
using System.ComponentModel;
using System.Drawing;
using System.Runtime.Serialization.Formatters.Binary;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTypeConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTypeConverterTests.cs
index b970d65c02e..60296bbc9b6 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTypeConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Layout/TableLayoutSettingsTypeConverterTests.cs
@@ -5,7 +5,6 @@
using System.ComponentModel.Design.Serialization;
using System.Xml;
using Moq;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Layout.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaConverterTests.cs
index 21b0369617e..83b48e7394d 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkAreaConverterTests.cs
@@ -5,7 +5,6 @@
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkConverterTests.cs
index 3e61b254bd8..6c062e46062 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/LinkConverterTests.cs
@@ -3,7 +3,6 @@
using System.ComponentModel.Design.Serialization;
using System.Globalization;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupConverterTests.cs
index cd0f16d725e..ecee380710b 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewGroupConverterTests.cs
@@ -4,7 +4,6 @@
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using Moq;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs
index 84a87cd4c29..f08f37d2471 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Drawing;
-using System.Windows.Forms.TestUtilities;
using Microsoft.DotNet.RemoteExecutor;
using Point = System.Drawing.Point;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItemConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItemConverterTests.cs
index b015192279c..95d7adb1ee1 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItemConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewItemConverterTests.cs
@@ -4,7 +4,6 @@
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewSubItemConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewSubItemConverterTests.cs
index 1e4d3d52977..7bf0d6149a3 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewSubItemConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewSubItemConverterTests.cs
@@ -4,7 +4,6 @@
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MessageTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MessageTests.cs
index 67de793d5fa..c6d5c82d4bd 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MessageTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/MessageTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.InteropServices;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/OpacityConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/OpacityConverterTests.cs
index e4f7f297a89..fab257278ad 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/OpacityConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/OpacityConverterTests.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel.Design.Serialization;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingConverterTests.cs
index 82723280058..d3efb92541d 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingConverterTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/PaddingConverterTests.cs
@@ -6,7 +6,6 @@
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using Moq;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ProgressBarTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ProgressBarTests.cs
index d4abdef9bdd..07ac5ab4a90 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ProgressBarTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ProgressBarTests.cs
@@ -3,8 +3,8 @@
using System.ComponentModel;
using System.Drawing;
-using Moq;
using System.Windows.Forms.TestUtilities;
+using Moq;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelCellPositionTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelCellPositionTests.cs
index d3919d39216..e1aee1c382e 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelCellPositionTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TableLayoutPanelCellPositionTests.cs
@@ -4,7 +4,6 @@
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipTests.cs
index 00a49978e49..bbfd4f46ae7 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolTipTests.cs
@@ -3,10 +3,9 @@
using System.ComponentModel;
using System.Drawing;
+using System.Windows.Forms.Automation;
using Moq;
using Moq.Protected;
-using System.Windows.Forms.Automation;
-using System.Windows.Forms.TestUtilities;
namespace System.Windows.Forms.Tests;
diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/VisualStyles/TextMetricsTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/VisualStyles/TextMetricsTests.cs
index fb457711095..c4c77d8f12e 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/VisualStyles/TextMetricsTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/VisualStyles/TextMetricsTests.cs
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Windows.Forms.TestUtilities;
-
namespace System.Windows.Forms.VisualStyles.Tests;
// NB: doesn't require thread affinity
diff --git a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs
index ea668abf9a5..d1cbd8b6022 100644
--- a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs
@@ -4,8 +4,8 @@
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
-using Moq;
using System.Windows.Forms.TestUtilities;
+using Moq;
using Point = System.Drawing.Point;
using Size = System.Drawing.Size;