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

Update Ref classes for AE support in .NET Standard #756

Merged
merged 10 commits into from
Oct 19, 2020
Merged

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<TargetGroup Condition="$(TargetFramework.StartsWith('netstandard'))">netstandard</TargetGroup>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netstandard' AND !$(TargetFramework.StartsWith('netstandard1.')) AND $(TargetFramework) != 'netstandard2.0'">
<DefineConstants>$(DefineConstants);NETSTANDARD21_AND_ABOVE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Microsoft.Data.SqlClient.cs" />
<Compile Include="Microsoft.Data.SqlClient.Manual.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<Product>Core $(BaseProduct)</Product>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<DefineConstants>$(DefineConstants);netcoreapp;</DefineConstants>
<DefineConstants>$(DefineConstants);NETCOREAPP;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netstandard'">
<DefineConstants>$(DefineConstants);netstandard;</DefineConstants>
<DefineConstants>$(DefineConstants);NETSTANDARD;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netcoreapp' AND '$(TargetFramework)' != 'netcoreapp2.1'">
<DefineConstants>$(DefineConstants);NETCORE3</DefineConstants>
<PropertyGroup Condition="'$(TargetGroup)' == 'netcoreapp' AND !$(TargetFramework.StartsWith('netcoreapp2.'))">
<DefineConstants>$(DefineConstants);NETCOREAPP31_AND_ABOVE</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<DebugType>portable</DebugType>
Expand Down Expand Up @@ -234,15 +234,6 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\InvalidUdtException.cs">
<Link>Microsoft\Data\SqlClient\Server\InvalidUdtException.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\AlwaysEncryptedAttestationException.cs">
<Link>Microsoft\Data\SqlClient\AlwaysEncryptedAttestationException.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\EnclaveProviderBase.cs">
<Link>Microsoft\Data\SqlClient\EnclaveProviderBase.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\EnclaveSessionCache.cs">
<Link>Microsoft\Data\SqlClient\EnclaveSessionCache.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SignatureVerificationCache.cs">
<Link>Microsoft\Data\SqlClient\SignatureVerificationCache.cs</Link>
</Compile>
Expand Down Expand Up @@ -272,6 +263,15 @@
<Compile Include="Microsoft\Data\SqlClient\TdsParser.NetStandard.cs" />
</ItemGroup>
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(TargetFramework)' != 'netstandard2.0'">
<Compile Include="..\..\src\Microsoft\Data\SqlClient\AlwaysEncryptedAttestationException.cs">
<Link>Microsoft\Data\SqlClient\AlwaysEncryptedAttestationException.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\EnclaveProviderBase.cs">
<Link>Microsoft\Data\SqlClient\EnclaveProviderBase.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\EnclaveSessionCache.cs">
<Link>Microsoft\Data\SqlClient\EnclaveSessionCache.cs</Link>
</Compile>
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionEnclaveProvider.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlEnclaveAttestationParameters.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\EnclaveDelegate.NetCoreApp.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ internal static partial class DbConnectionStringKeywords
internal const string MaxPoolSize = "Max Pool Size";
internal const string Pooling = "Pooling";
internal const string MinPoolSize = "Min Pool Size";
#if netcoreapp
#if NETCOREAPP
internal const string PoolBlockingPeriod = "Pool Blocking Period";
#endif
}
Expand Down Expand Up @@ -839,7 +839,7 @@ internal static class DbConnectionStringSynonyms
internal const string NET = "net";
internal const string NETWORK = "network";

#if netcoreapp
#if NETCOREAPP
//internal const string PoolBlockingPeriod = POOLBLOCKINGPERIOD;
internal const string POOLBLOCKINGPERIOD = "PoolBlockingPeriod";
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ public override void KillConnection()
internal static void SetKeepAliveValues(ref Socket socket)
{

#if NETCORE3
#if NETCOREAPP31_AND_ABOVE
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 1);
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, 30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,7 @@ private void SetCachedCommandExecuteReaderAsyncContext(ExecuteReaderAsyncCallCon
}
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml' path='docs/members[@name="SqlCommand"]/ExecuteReaderAsync[@name="CancellationToken"]/*'/>
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml' path='docs/members[@name="SqlCommand"]/ExecuteScalarAsync[@name="CancellationToken"]/*'/>
public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken)
{
_parentOperationStarted = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal static class KEY
internal const string Application_Name = "application name";
internal const string AsynchronousProcessing = "asynchronous processing";
internal const string AttachDBFilename = "attachdbfilename";
#if netcoreapp
#if NETCOREAPP
internal const string PoolBlockingPeriod = "pool blocking period";
#endif
internal const string ColumnEncryptionSetting = "column encryption setting";
Expand Down Expand Up @@ -141,7 +141,7 @@ private static class SYNONYM
// network library
internal const string NET = "net";
internal const string NETWORK = "network";
#if netcoreapp
#if NETCOREAPP
// pool blocking period
internal const string POOLBLOCKINGPERIOD = "poolblockingperiod";
#endif
Expand All @@ -159,7 +159,7 @@ private static class SYNONYM
// make sure to update SynonymCount value below when adding or removing synonyms
}

#if netcoreapp
#if NETCOREAPP
internal const int SynonymCount = 25;
#else
internal const int SynonymCount = 24;
Expand Down Expand Up @@ -258,7 +258,7 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
}

_integratedSecurity = ConvertValueToIntegratedSecurity();
#if netcoreapp
#if NETCOREAPP
_poolBlockingPeriod = ConvertValueToPoolBlockingPeriod();
#endif
_encrypt = ConvertValueToBoolean(KEY.Encrypt, DEFAULT.Encrypt);
Expand Down Expand Up @@ -511,7 +511,7 @@ internal SqlConnectionString(SqlConnectionString connectionOptions, string dataS
_commandTimeout = connectionOptions._commandTimeout;
_connectTimeout = connectionOptions._connectTimeout;
_loadBalanceTimeout = connectionOptions._loadBalanceTimeout;
#if netcoreapp
#if NETCOREAPP
_poolBlockingPeriod = connectionOptions._poolBlockingPeriod;
#endif
_maxPoolSize = connectionOptions._maxPoolSize;
Expand Down Expand Up @@ -650,7 +650,7 @@ internal static Dictionary<string, string> GetParseSynonyms()
{ KEY.Application_Name, KEY.Application_Name },
{ KEY.AsynchronousProcessing, KEY.AsynchronousProcessing },
{ KEY.AttachDBFilename, KEY.AttachDBFilename },
#if netcoreapp
#if NETCOREAPP
{ KEY.PoolBlockingPeriod, KEY.PoolBlockingPeriod},
#endif
{ KEY.Command_Timeout, KEY.Command_Timeout },
Expand Down Expand Up @@ -703,7 +703,7 @@ internal static Dictionary<string, string> GetParseSynonyms()
{ SYNONYM.MULTIPLEACTIVERESULTSETS, KEY.MARS },
{ SYNONYM.MULTISUBNETFAILOVER, KEY.MultiSubnetFailover },
{ SYNONYM.NETWORK_ADDRESS, KEY.Data_Source },
#if netcoreapp
#if NETCOREAPP
{ SYNONYM.POOLBLOCKINGPERIOD, KEY.PoolBlockingPeriod},
#endif
{ SYNONYM.SERVER, KEY.Data_Source },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private enum Keywords
Pooling,
MinPoolSize,
MaxPoolSize,
#if netcoreapp
#if NETCOREAPP
PoolBlockingPeriod,
#endif
MultipleActiveResultSets,
Expand Down Expand Up @@ -114,7 +114,7 @@ private static string[] CreateValidKeywords()
validKeywords[(int)Keywords.ApplicationIntent] = DbConnectionStringKeywords.ApplicationIntent;
validKeywords[(int)Keywords.ApplicationName] = DbConnectionStringKeywords.ApplicationName;
validKeywords[(int)Keywords.AttachDBFilename] = DbConnectionStringKeywords.AttachDBFilename;
#if netcoreapp
#if NETCOREAPP
validKeywords[(int)Keywords.PoolBlockingPeriod] = DbConnectionStringKeywords.PoolBlockingPeriod;
#endif
validKeywords[(int)Keywords.CommandTimeout] = DbConnectionStringKeywords.CommandTimeout;
Expand Down Expand Up @@ -158,7 +158,7 @@ private static Dictionary<string, Keywords> CreateKeywordsDictionary()
hash.Add(DbConnectionStringKeywords.ApplicationIntent, Keywords.ApplicationIntent);
hash.Add(DbConnectionStringKeywords.ApplicationName, Keywords.ApplicationName);
hash.Add(DbConnectionStringKeywords.AttachDBFilename, Keywords.AttachDBFilename);
#if netcoreapp
#if NETCOREAPP
hash.Add(DbConnectionStringKeywords.PoolBlockingPeriod, Keywords.PoolBlockingPeriod);
#endif
hash.Add(DbConnectionStringKeywords.CommandTimeout, Keywords.CommandTimeout);
Expand Down Expand Up @@ -208,7 +208,7 @@ private static Dictionary<string, Keywords> CreateKeywordsDictionary()
hash.Add(DbConnectionStringSynonyms.MULTIPLEACTIVERESULTSETS, Keywords.MultipleActiveResultSets);
hash.Add(DbConnectionStringSynonyms.MULTISUBNETFAILOVER, Keywords.MultiSubnetFailover);
hash.Add(DbConnectionStringSynonyms.NETWORKADDRESS, Keywords.DataSource);
#if netcoreapp
#if NETCOREAPP
hash.Add(DbConnectionStringSynonyms.POOLBLOCKINGPERIOD, Keywords.PoolBlockingPeriod);
#endif
hash.Add(DbConnectionStringSynonyms.SERVER, Keywords.DataSource);
Expand Down Expand Up @@ -326,7 +326,7 @@ public override object this[string keyword]
case Keywords.AttestationProtocol:
AttestationProtocol = ConvertToAttestationProtocol(keyword, value);
break;
#if netcoreapp
#if NETCOREAPP
case Keywords.PoolBlockingPeriod: PoolBlockingPeriod = ConvertToPoolBlockingPeriod(keyword, value); break;
#endif
case Keywords.Encrypt:
Expand Down Expand Up @@ -914,7 +914,7 @@ private object GetAt(Keywords index)
return ApplicationName;
case Keywords.AttachDBFilename:
return AttachDBFilename;
#if netcoreapp
#if NETCOREAPP
case Keywords.PoolBlockingPeriod: return PoolBlockingPeriod;
#endif
case Keywords.CommandTimeout:
Expand Down Expand Up @@ -1029,7 +1029,7 @@ private void Reset(Keywords index)
case Keywords.Authentication:
_authentication = DbConnectionStringDefaults.Authentication;
break;
#if netcoreapp
#if NETCOREAPP
case Keywords.PoolBlockingPeriod:
_poolBlockingPeriod = DbConnectionStringDefaults.PoolBlockingPeriod;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ internal void WriteInt(int v, TdsParserStateObject stateObj)

internal static void WriteInt(Span<byte> buffer, int value)
{
#if netcoreapp
#if NETCOREAPP
BitConverter.TryWriteBytes(buffer, value);
#else
buffer[0] = (byte)(value & 0xff);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!-- ResolveComReferenceSilent suppresses warnings thrown due to the inclusion of mscoree.
We should remove ResolveComReferenceSilent as soon as we can remove the dependency on mscoree. -->
<ResolveComReferenceSilent>True</ResolveComReferenceSilent>
<DefineConstants>$(DefineConstants);netfx;</DefineConstants>
<DefineConstants>$(DefineConstants);NETFRAMEWORK;</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<!-- CSC Compiler Options -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3022,7 +3022,7 @@ protected override Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior b
return returnedTask;
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml' path='docs/members[@name="SqlCommand"]/ExecuteReaderAsync[@name="CancellationToken"]/*'/>
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml' path='docs/members[@name="SqlCommand"]/ExecuteScalarAsync[@name="CancellationToken"]/*'/>
public override Task<object> ExecuteScalarAsync(CancellationToken cancellationToken)
{
return ExecuteReaderAsync(cancellationToken).ContinueWith((executeTask) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public override void BeforeUnload(SqlAuthenticationMethod authentication)
_logger.LogInfo(_type, "BeforeUnload", $"being unloaded from SqlAuthProviders for {authentication}.");
}

#if netstandard
#if NETSTANDARD
private Func<object> parentActivityOrWindowFunc = null;

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/ActiveDirectoryAuthenticationProvider.xml' path='docs/members[@name="ActiveDirectoryAuthenticationProvider"]/SetParentActivityOrWindowFunc/*'/>
public void SetParentActivityOrWindowFunc(Func<object> parentActivityOrWindowFunc) => this.parentActivityOrWindowFunc = parentActivityOrWindowFunc;
#endif

#if netfx
#if NETFRAMEWORK
private Func<System.Windows.Forms.IWin32Window> _iWin32WindowFunc = null;

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/ActiveDirectoryAuthenticationProvider.xml' path='docs/members[@name="ActiveDirectoryAuthenticationProvider"]/SetIWin32WindowFunc/*'/>
Expand Down Expand Up @@ -101,24 +101,24 @@ public override Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthentication
return new SqlAuthenticationToken(result.AccessToken, result.ExpiresOn);
}
/*
/*
* Today, MSAL.NET uses another redirect URI by default in desktop applications that run on Windows
* (urn:ietf:wg:oauth:2.0:oob). In the future, we'll want to change this default, so we recommend
* that you use https://login.microsoftonline.com/common/oauth2/nativeclient.
*
*
* https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-desktop-app-registration#redirect-uris
*/
string redirectURI = "https://login.microsoftonline.com/common/oauth2/nativeclient";
#if netcoreapp
#if NETCOREAPP
if (parameters.AuthenticationMethod != SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow)
{
redirectURI = "http://localhost";
}
#endif
IPublicClientApplication app;
#if netstandard
#if NETSTANDARD
if (parentActivityOrWindowFunc != null)
{
app = PublicClientApplicationBuilder.Create(_applicationClientId)
Expand All @@ -130,7 +130,7 @@ public override Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthentication
.Build();
}
#endif
#if netfx
#if NETFRAMEWORK
if (_iWin32WindowFunc != null)
{
app = PublicClientApplicationBuilder.Create(_applicationClientId)
Expand All @@ -142,7 +142,7 @@ public override Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthentication
.Build();
}
#endif
#if !netcoreapp
#if !NETCOREAPP
else
#endif
{
Expand Down Expand Up @@ -229,14 +229,14 @@ private async Task<AuthenticationResult> AcquireTokenInteractiveDeviceFlowAsync(
SqlAuthenticationMethod authenticationMethod)
{
CancellationTokenSource cts = new CancellationTokenSource();
#if netcoreapp
#if NETCOREAPP
/*
* On .NET Core, MSAL will start the system browser as a separate process. MSAL does not have control over this browser,
* but once the user finishes authentication, the web page is redirected in such a way that MSAL can intercept the Uri.
* MSAL cannot detect if the user navigates away or simply closes the browser. Apps using this technique are encouraged
* to define a timeout (via CancellationToken). We recommend a timeout of at least a few minutes, to take into account
* cases where the user is prompted to change password or perform 2FA.
*
*
* https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/System-Browser-on-.Net-Core#system-browser-experience
*/
cts.CancelAfter(180000);
Expand All @@ -257,7 +257,7 @@ private async Task<AuthenticationResult> AcquireTokenInteractiveDeviceFlowAsync(
{
/*
* We will use the MSAL Embedded or System web browser which changes by Default in MSAL according to this table:
*
*
* Framework Embedded System Default
* -------------------------------------------
* .NET Classic Yes Yes^ Embedded
Expand All @@ -267,9 +267,9 @@ private async Task<AuthenticationResult> AcquireTokenInteractiveDeviceFlowAsync(
* Xamarin.Android Yes Yes System
* Xamarin.iOS Yes Yes System
* Xamarin.Mac Yes No Embedded
*
*
* ^ Requires "http://localhost" redirect URI
*
*
* https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/MSAL.NET-uses-web-browser#at-a-glance
*/
return await app.AcquireTokenInteractive(scopes)
Expand All @@ -296,11 +296,11 @@ private async Task<AuthenticationResult> AcquireTokenInteractiveDeviceFlowAsync(

private Task DefaultDeviceFlowCallback(DeviceCodeResult result)
{
// This will print the message on the console which tells the user where to go sign-in using
// This will print the message on the console which tells the user where to go sign-in using
// a separate browser and the code to enter once they sign in.
// The AcquireTokenWithDeviceCode() method will poll the server after firing this
// device code callback to look for the successful login of the user via that browser.
// This background polling (whose interval and timeout data is also provided as fields in the
// This background polling (whose interval and timeout data is also provided as fields in the
// deviceCodeCallback class) will occur until:
// * The user has successfully logged in via browser and entered the proper code
// * The timeout specified by the server for the lifetime of this code (typically ~15 minutes) has been reached
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void OnEventCommand(EventCommandEventArgs e)
// If registration fails, all write and unregister commands will be a no-op.

// If managed networking is enabled, don't call native wrapper methods
#if netcoreapp
#if NETCOREAPP || NETSTANDARD
if (AppContext.TryGetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", out bool isEnabled) && isEnabled)
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
{
return;
Expand Down
Loading