diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index ab2d25908c..598ee9be7d 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -256,6 +256,9 @@ Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs + Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs @@ -547,7 +550,6 @@ - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs deleted file mode 100644 index f9a43f0c02..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ /dev/null @@ -1,97 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Diagnostics; -using Microsoft.Data.Common; - -namespace Microsoft.Data.SqlClient -{ - // SqlConnectionPoolKey: Implementation of a key to connection pool groups for specifically to be used for SqlConnection - // Connection string and SqlCredential are used as a key - internal class SqlConnectionPoolKey : DbConnectionPoolKey - { - private int _hashValue; - private SqlCredential _credential; - private readonly string _accessToken; - - internal SqlConnectionPoolKey(string connectionString, SqlCredential credential, string accessToken) : base(connectionString) - { - Debug.Assert(_credential == null || _accessToken == null, "Credential and AccessToken can't have the value at the same time."); - _credential = credential; - _accessToken = accessToken; - CalculateHashCode(); - } - - private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) - { - _credential = key.Credential; - _accessToken = key.AccessToken; - CalculateHashCode(); - } - - public override object Clone() - { - return new SqlConnectionPoolKey(this); - } - - internal override string ConnectionString - { - get - { - return base.ConnectionString; - } - - set - { - base.ConnectionString = value; - CalculateHashCode(); - } - } - - internal SqlCredential Credential => _credential; - - internal string AccessToken - { - get - { - return _accessToken; - } - } - - public override bool Equals(object obj) - { - SqlConnectionPoolKey key = obj as SqlConnectionPoolKey; - return (key != null - && _credential == key._credential - && ConnectionString == key.ConnectionString - && string.CompareOrdinal(_accessToken, key._accessToken) == 0); - } - - public override int GetHashCode() - { - return _hashValue; - } - - private void CalculateHashCode() - { - _hashValue = base.GetHashCode(); - - if (_credential != null) - { - unchecked - { - _hashValue = _hashValue * 17 + _credential.GetHashCode(); - } - } - else if (_accessToken != null) - { - unchecked - { - _hashValue = _hashValue * 17 + _accessToken.GetHashCode(); - } - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 87162db2ab..172b43bf60 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -342,6 +342,9 @@ Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs + Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs @@ -536,7 +539,6 @@ - diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs similarity index 57% rename from src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs index 46b77f8fb2..c35ce6f08e 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Diagnostics; using Microsoft.Data.Common; @@ -10,21 +9,46 @@ namespace Microsoft.Data.SqlClient { // SqlConnectionPoolKey: Implementation of a key to connection pool groups for specifically to be used for SqlConnection // Connection string and SqlCredential are used as a key - internal class SqlConnectionPoolKey : DbConnectionPoolKey, ICloneable + internal class SqlConnectionPoolKey : DbConnectionPoolKey { - private SqlCredential _credential; private int _hashValue; + private readonly SqlCredential _credential; private readonly string _accessToken; - private ServerCertificateValidationCallback _serverCertificateValidationCallback; - private ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; - private SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; + + internal SqlCredential Credential => _credential; + internal string AccessToken => _accessToken; + + internal override string ConnectionString + { + get => base.ConnectionString; + set + { + base.ConnectionString = value; + CalculateHashCode(); + } + } + +#if NETFRAMEWORK + #region NET Framework + private readonly ServerCertificateValidationCallback _serverCertificateValidationCallback; + private readonly ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; + private readonly SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; + + internal ServerCertificateValidationCallback ServerCertificateValidationCallback + => _serverCertificateValidationCallback; + + internal ClientCertificateRetrievalCallback ClientCertificateRetrievalCallback + => _clientCertificateRetrievalCallback; + + internal SqlClientOriginalNetworkAddressInfo OriginalNetworkAddressInfo + => _originalNetworkAddressInfo; internal SqlConnectionPoolKey(string connectionString, - SqlCredential credential, - string accessToken, - ServerCertificateValidationCallback serverCertificateValidationCallback, - ClientCertificateRetrievalCallback clientCertificateRetrievalCallback, - SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo) : base(connectionString) + SqlCredential credential, + string accessToken, + ServerCertificateValidationCallback serverCertificateValidationCallback, + ClientCertificateRetrievalCallback clientCertificateRetrievalCallback, + SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo) : base(connectionString) { Debug.Assert(_credential == null || _accessToken == null, "Credential and AccessToken can't have the value at the same time."); _credential = credential; @@ -34,86 +58,47 @@ internal SqlConnectionPoolKey(string connectionString, _originalNetworkAddressInfo = originalNetworkAddressInfo; CalculateHashCode(); } + #endregion +#else + #region NET Core + internal SqlConnectionPoolKey(string connectionString, SqlCredential credential, string accessToken) : base(connectionString) + { + Debug.Assert(_credential == null || _accessToken == null, "Credential and AccessToken can't have the value at the same time."); + _credential = credential; + _accessToken = accessToken; + CalculateHashCode(); + } + #endregion +#endif private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) { _credential = key.Credential; _accessToken = key.AccessToken; +#if NETFRAMEWORK _serverCertificateValidationCallback = key._serverCertificateValidationCallback; _clientCertificateRetrievalCallback = key._clientCertificateRetrievalCallback; +#endif CalculateHashCode(); } - object ICloneable.Clone() + public override object Clone() { return new SqlConnectionPoolKey(this); } - internal override string ConnectionString - { - get - { - return base.ConnectionString; - } - - set - { - base.ConnectionString = value; - CalculateHashCode(); - } - } - - internal SqlCredential Credential - { - get - { - return _credential; - } - } - - internal string AccessToken - { - get - { - return _accessToken; - } - } - - internal ServerCertificateValidationCallback ServerCertificateValidationCallback - { - get - { - return _serverCertificateValidationCallback; - } - } - - internal ClientCertificateRetrievalCallback ClientCertificateRetrievalCallback - { - get - { - return _clientCertificateRetrievalCallback; - } - } - - internal SqlClientOriginalNetworkAddressInfo OriginalNetworkAddressInfo - { - get - { - return _originalNetworkAddressInfo; - } - } - public override bool Equals(object obj) { - SqlConnectionPoolKey key = obj as SqlConnectionPoolKey; - - return (key != null && - _credential == key._credential && - ConnectionString == key.ConnectionString && - string.CompareOrdinal(_accessToken, key._accessToken) == 0 && - _serverCertificateValidationCallback == key._serverCertificateValidationCallback && - _clientCertificateRetrievalCallback == key._clientCertificateRetrievalCallback && - _originalNetworkAddressInfo == key._originalNetworkAddressInfo); + return (obj is SqlConnectionPoolKey key + && _credential == key._credential + && ConnectionString == key.ConnectionString + && string.CompareOrdinal(_accessToken, key._accessToken) == 0 +#if NETFRAMEWORK + && _serverCertificateValidationCallback == key._serverCertificateValidationCallback + && _clientCertificateRetrievalCallback == key._clientCertificateRetrievalCallback + && _originalNetworkAddressInfo == key._originalNetworkAddressInfo +#endif + ); } public override int GetHashCode() @@ -140,6 +125,7 @@ private void CalculateHashCode() } } +#if NETFRAMEWORK if (_originalNetworkAddressInfo != null) { unchecked @@ -147,6 +133,7 @@ private void CalculateHashCode() _hashValue = _hashValue * 17 + _originalNetworkAddressInfo.GetHashCode(); } } +#endif } } }