Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove UWP (uap) references and special cased code #2483

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,9 @@
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.IoControlTransferType.cs">
<Link>Common\Interop\Windows\Kernel32\Interop.IoControlTransferType.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.LoadLibraryEx.cs">
<Link>Common\Interop\Windows\kernel32\Interop.LoadLibraryEx.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Windows\NtDll\Interop.FILE_FULL_EA_INFORMATION.cs">
<Link>Common\Interop\Windows\NtDll\Interop.FILE_FULL_EA_INFORMATION.cs</Link>
</Compile>
Expand Down Expand Up @@ -826,16 +829,25 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\Sql\SqlDataSourceEnumerator.Windows.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumerator.Windows.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs">
<Link>Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserSafeHandles.Windows.cs">
<Link>Microsoft\Data\SqlClient\TdsParserSafeHandles.Windows.cs</Link>
</Compile>

<Compile Include="Interop\SNINativeMethodWrapper.Windows.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Common.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SessionHandle.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCngProvider.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCspProvider.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectNative.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectFactory.Windows.cs" />
<Compile Include="Microsoft\Data\SqlTypes\SqlFileStream.Windows.cs" />
</ItemGroup>
Expand Down Expand Up @@ -894,31 +906,6 @@
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectFactory.Managed.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsUAPAssembly)' == 'true'">
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.uap.cs" />
<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SessionHandle.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.uap.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectFactory.Managed.cs" />
</ItemGroup>

<!-- Assets needed on Windows but should be avoided on UAP to avoid sni.dll -->
<ItemGroup Condition="'$(TargetsWindows)' == 'true' and '$(IsUAPAssembly)' != 'true'">
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.LoadLibraryEx.cs">
<Link>Common\Interop\Windows\kernel32\Interop.LoadLibraryEx.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs">
<Link>Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs</Link>
</Compile>
<Compile Include="Interop\SNINativeMethodWrapper.Windows.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectNative.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Windows.cs" />
</ItemGroup>

<!-- Resources -->
<ItemGroup>
Expand Down Expand Up @@ -947,10 +934,6 @@
</ItemGroup>

<!-- Package References Etc -->
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(IsUAPAssembly)' == 'true'">
<Reference Include="System.Collections.NonGeneric" />
<Reference Include="System.Memory" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerVersion)" />
<PackageReference Include="System.Runtime.Caching" Version="$(SystemRuntimeCachingVersion)" />
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1509,9 +1509,7 @@ internal SqlError ProcessSNIError(TdsParserStateObject stateObj)
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.TdsParser.ProcessSNIError |ERR|ADV > Empty error message received from SNI. Error Message = {0}", details.errorMessage);
}

string sniContextEnumName = TdsEnums.GetSniContextEnumName(stateObj.SniContext);

string sqlContextInfo = StringsHelper.GetResourceString(sniContextEnumName);
string sqlContextInfo = StringsHelper.GetResourceString(stateObj.SniContext.ToString());
string providerRid = string.Format("SNI_PN{0}", details.provider);
string providerName = StringsHelper.GetResourceString(providerRid);
Debug.Assert(!string.IsNullOrEmpty(providerName), $"invalid providerResourceId '{providerRid}'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using Microsoft.Data.Common;

namespace Microsoft.Data.SqlClient
{
Expand Down Expand Up @@ -998,47 +994,6 @@ internal enum FedAuthInfoId : byte
internal const byte DATA_CLASSIFICATION_VERSION_WITHOUT_RANK_SUPPORT = 0x01;
internal const byte DATA_CLASSIFICATION_VERSION_MAX_SUPPORTED = 0x02;

// Needed for UapAot, since we cannot use Enum.GetName() on SniContext.
// Enum.GetName() uses reflection, which is blocked on UapAot for internal types
// like SniContext.
internal static string GetSniContextEnumName(SniContext sniContext)
{
switch (sniContext)
{
case SniContext.Undefined:
return "Undefined";
case SniContext.Snix_Connect:
return "Snix_Connect";
case SniContext.Snix_PreLoginBeforeSuccessfulWrite:
return "Snix_PreLoginBeforeSuccessfulWrite";
case SniContext.Snix_PreLogin:
return "Snix_PreLogin";
case SniContext.Snix_LoginSspi:
return "Snix_LoginSspi";
case SniContext.Snix_ProcessSspi:
return "Snix_ProcessSspi";
case SniContext.Snix_Login:
return "Snix_Login";
case SniContext.Snix_EnableMars:
return "Snix_EnableMars";
case SniContext.Snix_AutoEnlist:
return "Snix_AutoEnlist";
case SniContext.Snix_GetMarsSession:
return "Snix_GetMarsSession";
case SniContext.Snix_Execute:
return "Snix_Execute";
case SniContext.Snix_Read:
return "Snix_Read";
case SniContext.Snix_Close:
return "Snix_Close";
case SniContext.Snix_SendRows:
return "Snix_SendRows";
default:
Debug.Fail($"Received unknown SniContext enum. Value: {sniContext}");
return null;
}
}

ErikEJ marked this conversation as resolved.
Show resolved Hide resolved
// TCE Related constants
internal const byte MAX_SUPPORTED_TCE_VERSION = 0x03; // max version
internal const byte MIN_TCE_VERSION_WITH_ENCLAVE_SUPPORT = 0x02; // min version with enclave support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Microsoft.Data.SqlClient.TestUtilities;
using Microsoft.Identity.Client;
using Xunit;
using System.Net.NetworkInformation;
using System.Text;
using System.Security.Principal;
using System.Runtime.InteropServices;
using Azure.Identity;
using Azure.Core;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
Expand Down Expand Up @@ -78,10 +78,6 @@ public static class DataTestUtility
public const string AKVEventSourceName = "Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.EventSource";
private const string ManagedNetworkingAppContextSwitch = "Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows";

// uap constant
const long APPMODEL_ERROR_NO_PACKAGE = 15700L;
public static readonly bool IsRunningAsUWPApp = RunningAsUWPApp();

private static Dictionary<string, bool> AvailableDatabases;
private static BaseEventListener TraceListener;

Expand Down Expand Up @@ -683,10 +679,6 @@ public static string GetUserIdentityAccessToken()

public static bool IsAccessTokenSetup() => !string.IsNullOrEmpty(GetAccessToken());

public static bool IsSystemIdentityTokenSetup() => !string.IsNullOrEmpty(GetSystemIdentityAccessToken());

public static bool IsUserIdentityTokenSetup() => !string.IsNullOrEmpty(GetUserIdentityAccessToken());

public static bool IsFileStreamSetup() => !string.IsNullOrEmpty(FileStreamDirectory) && IsNotAzureServer() && IsNotAzureSynapse();

private static bool CheckException<TException>(Exception ex, string exceptionMessage, bool innerExceptionMustBeNull) where TException : Exception
Expand Down Expand Up @@ -787,58 +779,6 @@ public static TException ExpectFailure<TException>(Action actionThatFails, strin
}
}

public static TException ExpectFailure<TException, TInnerException>(Action actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, bool innerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception
{
try
{
actionThatFails();
Assert.Fail("ERROR: Did not get expected exception");
return null;
}
catch (Exception ex)
{
if ((CheckException<TException>(ex, exceptionMessage, false)) && (CheckException<TInnerException>(ex.InnerException, innerExceptionMessage, innerInnerExceptionMustBeNull)))
{
return (ex as TException);
}
else
{
throw;
}
}
}

public static TException ExpectFailure<TException, TInnerException, TInnerInnerException>(Action actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, string innerInnerExceptionMessage = null, bool innerInnerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception where TInnerInnerException : Exception
{
try
{
actionThatFails();
Assert.Fail("ERROR: Did not get expected exception");
return null;
}
catch (Exception ex)
{
if ((CheckException<TException>(ex, exceptionMessage, false)) && (CheckException<TInnerException>(ex.InnerException, innerExceptionMessage, false)) && (CheckException<TInnerInnerException>(ex.InnerException.InnerException, innerInnerExceptionMessage, innerInnerInnerExceptionMustBeNull)))
{
return (ex as TException);
}
else
{
throw;
}
}
}

public static void ExpectAsyncFailure<TException>(Func<Task> actionThatFails, string exceptionMessage = null, bool innerExceptionMustBeNull = false) where TException : Exception
{
ExpectFailure<AggregateException, TException>(() => actionThatFails().Wait(), null, exceptionMessage, innerExceptionMustBeNull);
}

public static void ExpectAsyncFailure<TException, TInnerException>(Func<Task> actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, bool innerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception
{
ExpectFailure<AggregateException, TException, TInnerException>(() => actionThatFails().Wait(), null, exceptionMessage, innerExceptionMessage, innerInnerExceptionMustBeNull);
}

public static string GenerateObjectName()
{
return string.Format("TEST_{0}{1}{2}", Environment.GetEnvironmentVariable("ComputerName"), Environment.TickCount, Guid.NewGuid()).Replace('-', '_');
Expand Down Expand Up @@ -1100,44 +1040,5 @@ public static string GetMachineFQDN(string hostname)
}
return fqdn.ToString();
}

public static bool IsNotLocalhost()
{
// get the tcp connection string
SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString);

string hostname = "";

// parse the datasource
ParseDataSource(builder.DataSource, out hostname, out _, out _);

// hostname must not be localhost, ., 127.0.0.1 nor ::1
return !(new string[] { "localhost", ".", "127.0.0.1", "::1" }).Contains(hostname.ToLowerInvariant());

}

private static bool RunningAsUWPApp()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return false;
}
else
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern int GetCurrentPackageFullName(ref int packageFullNameLength, StringBuilder packageFullName);

{
int length = 0;
StringBuilder sb = new(0);
_ = GetCurrentPackageFullName(ref length, sb);

sb = new StringBuilder(length);
int result = GetCurrentPackageFullName(ref length, sb);

return result != APPMODEL_ERROR_NO_PACKAGE;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,6 @@ public void NamedPipeInvalidConnStringTest()
OpenBadConnection(builder.ConnectionString, invalidConnStringError);
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsRunningAsUWPApp))]
public static void LocalDBNotSupportedOnUapTest()
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(@$"server=(localdb)\{DataTestUtility.LocalDbAppName}")
{
IntegratedSecurity = true,
ConnectTimeout = 2
};

Assert.Throws<PlatformNotSupportedException>(() =>
{
using (SqlConnection conn = new SqlConnection(builder.ConnectionString))
{
conn.Open();
}
});
}


private void GenerateConnectionException(string connectionString)
{
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
Expand Down
Loading