From 0be532554977d1672b9de8b5a2146015b3ef4fdf Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Mon, 27 Sep 2021 09:27:21 -0700 Subject: [PATCH 01/11] Merge changes from netfx of SqlConnectionPoolKey into netcore version --- .../Data/SqlClient/SqlConnectionPoolKey.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) 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 index f9a43f0c02..a22a0d6c58 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs @@ -15,7 +15,30 @@ internal class SqlConnectionPoolKey : DbConnectionPoolKey private int _hashValue; private SqlCredential _credential; private readonly string _accessToken; + +#if NETFX + private ServerCertificateValidationCallback _serverCertificateValidationCallback; + private ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; + private SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; +#endif +#if NETFX + internal SqlConnectionPoolKey(string 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; + _accessToken = accessToken; + _serverCertificateValidationCallback = serverCertificateValidationCallback; + _clientCertificateRetrievalCallback = clientCertificateRetrievalCallback; + _originalNetworkAddressInfo = originalNetworkAddressInfo; + CalculateHashCode(); + } +#else 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."); @@ -23,11 +46,16 @@ internal SqlConnectionPoolKey(string connectionString, SqlCredential credential, _accessToken = accessToken; CalculateHashCode(); } +#endif private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) { _credential = key.Credential; _accessToken = key.AccessToken; +#if NETFX + _serverCertificateValidationCallback = key._serverCertificateValidationCallback; + _clientCertificateRetrievalCallback = key._clientCertificateRetrievalCallback; +#endif CalculateHashCode(); } @@ -59,6 +87,31 @@ internal string AccessToken return _accessToken; } } +#if NETFX + internal ServerCertificateValidationCallback ServerCertificateValidationCallback + { + get + { + return _serverCertificateValidationCallback; + } + } + + internal ClientCertificateRetrievalCallback ClientCertificateRetrievalCallback + { + get + { + return _clientCertificateRetrievalCallback; + } + } + + internal SqlClientOriginalNetworkAddressInfo OriginalNetworkAddressInfo + { + get + { + return _originalNetworkAddressInfo; + } + } +#endif public override bool Equals(object obj) { @@ -66,6 +119,11 @@ public override bool Equals(object obj) return (key != null && _credential == key._credential && ConnectionString == key.ConnectionString +#if NETFX + && _serverCertificateValidationCallback == key._serverCertificateValidationCallback + && _clientCertificateRetrievalCallback == key._clientCertificateRetrievalCallback + && _originalNetworkAddressInfo == key._originalNetworkAddressInfo) +#endif && string.CompareOrdinal(_accessToken, key._accessToken) == 0); } @@ -92,6 +150,16 @@ private void CalculateHashCode() _hashValue = _hashValue * 17 + _accessToken.GetHashCode(); } } + +#if NETFX + if (_originalNetworkAddressInfo != null) + { + unchecked + { + _hashValue = _hashValue * 17 + _originalNetworkAddressInfo.GetHashCode(); + } + } +#endif } } } From 4d1f09530317d3ac5264b183ed1dd94db7af7041 Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Mon, 27 Sep 2021 10:15:27 -0700 Subject: [PATCH 02/11] Fix compiler error for netfx build when referencing the merged SqlConnectionPoolKey and change the ifdef to NETFRAMEWORK instead of NETFX since it's not defined in the netfx csproj --- .../Data/SqlClient/SqlConnectionPoolKey.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 index a22a0d6c58..8911635a57 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs @@ -16,13 +16,13 @@ internal class SqlConnectionPoolKey : DbConnectionPoolKey private SqlCredential _credential; private readonly string _accessToken; -#if NETFX +#if NETFRAMEWORK private ServerCertificateValidationCallback _serverCertificateValidationCallback; private ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; private SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; #endif -#if NETFX +#if NETFRAMEWORK internal SqlConnectionPoolKey(string connectionString, SqlCredential credential, string accessToken, @@ -52,7 +52,7 @@ private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) { _credential = key.Credential; _accessToken = key.AccessToken; -#if NETFX +#if NETFRAMEWORK _serverCertificateValidationCallback = key._serverCertificateValidationCallback; _clientCertificateRetrievalCallback = key._clientCertificateRetrievalCallback; #endif @@ -87,7 +87,7 @@ internal string AccessToken return _accessToken; } } -#if NETFX +#if NETFRAMEWORK internal ServerCertificateValidationCallback ServerCertificateValidationCallback { get @@ -119,10 +119,10 @@ public override bool Equals(object obj) return (key != null && _credential == key._credential && ConnectionString == key.ConnectionString -#if NETFX +#if NETFRAMEWORK && _serverCertificateValidationCallback == key._serverCertificateValidationCallback && _clientCertificateRetrievalCallback == key._clientCertificateRetrievalCallback - && _originalNetworkAddressInfo == key._originalNetworkAddressInfo) + && _originalNetworkAddressInfo == key._originalNetworkAddressInfo #endif && string.CompareOrdinal(_accessToken, key._accessToken) == 0); } @@ -151,7 +151,7 @@ private void CalculateHashCode() } } -#if NETFX +#if NETFRAMEWORK if (_originalNetworkAddressInfo != null) { unchecked From dc2c90b1ae897a1f49215d25ab4476ffe8137435 Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Mon, 27 Sep 2021 10:19:49 -0700 Subject: [PATCH 03/11] Move the SqlConnectionPoolKey.cs from netcore to shared src and updated the references in the netfx csproj --- .../src/Microsoft.Data.SqlClient.csproj | 4 +- .../netfx/src/Microsoft.Data.SqlClient.csproj | 8 +- .../Data/SqlClient/SqlConnectionPoolKey.cs | 152 ------------------ .../Data/SqlClient/SqlConnectionPoolKey.cs | 0 4 files changed, 8 insertions(+), 156 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs rename src/Microsoft.Data.SqlClient/{netcore => }/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs (100%) 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 d918134b15..6748126174 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -214,6 +214,9 @@ Microsoft\Data\SqlClient\SqlColumnEncryptionKeyStoreProvider.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs + Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs @@ -485,7 +488,6 @@ - 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 f54e7630c6..4acbd0e429 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -110,6 +110,9 @@ Microsoft\Data\Common\NameValuePair.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs + Microsoft\Data\Sql\SqlNotificationRequest.cs @@ -430,7 +433,7 @@ - + @@ -453,7 +456,6 @@ - @@ -621,4 +623,4 @@ - + \ No newline at end of file diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs deleted file mode 100644 index 46b77f8fb2..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ /dev/null @@ -1,152 +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, ICloneable - { - private SqlCredential _credential; - private int _hashValue; - private readonly string _accessToken; - private ServerCertificateValidationCallback _serverCertificateValidationCallback; - private ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; - private SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; - - internal SqlConnectionPoolKey(string 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; - _accessToken = accessToken; - _serverCertificateValidationCallback = serverCertificateValidationCallback; - _clientCertificateRetrievalCallback = clientCertificateRetrievalCallback; - _originalNetworkAddressInfo = originalNetworkAddressInfo; - CalculateHashCode(); - } - - private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) - { - _credential = key.Credential; - _accessToken = key.AccessToken; - _serverCertificateValidationCallback = key._serverCertificateValidationCallback; - _clientCertificateRetrievalCallback = key._clientCertificateRetrievalCallback; - CalculateHashCode(); - } - - object ICloneable.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); - } - - 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(); - } - } - - if (_originalNetworkAddressInfo != null) - { - unchecked - { - _hashValue = _hashValue * 17 + _originalNetworkAddressInfo.GetHashCode(); - } - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs From 11437004b087ceb1e4e1cb5ead09872003ea2fba Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Mon, 27 Sep 2021 10:21:50 -0700 Subject: [PATCH 04/11] Move the compile include for SqlConnectionPoolKey.cs in the correct location in the netfx csproj --- .../netfx/src/Microsoft.Data.SqlClient.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 4acbd0e429..61e69d60f4 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -110,9 +110,6 @@ Microsoft\Data\Common\NameValuePair.cs - - Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs - Microsoft\Data\Sql\SqlNotificationRequest.cs @@ -288,6 +285,9 @@ Microsoft\Data\SqlClient\SqlColumnEncryptionKeyStoreProvider.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs + Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs @@ -623,4 +623,4 @@ - \ No newline at end of file + From 895eb171aee9742958458ab90d8c2e88f73c6667 Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Mon, 27 Sep 2021 10:42:11 -0700 Subject: [PATCH 05/11] Update file to conform with coding style cleaning up IDE0044 and IDE0019 --- .../Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs index 8911635a57..c3b02b249b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs @@ -13,13 +13,13 @@ namespace Microsoft.Data.SqlClient internal class SqlConnectionPoolKey : DbConnectionPoolKey { private int _hashValue; - private SqlCredential _credential; + private readonly SqlCredential _credential; private readonly string _accessToken; #if NETFRAMEWORK - private ServerCertificateValidationCallback _serverCertificateValidationCallback; - private ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; - private SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; + private readonly ServerCertificateValidationCallback _serverCertificateValidationCallback; + private readonly ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; + private readonly SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; #endif #if NETFRAMEWORK @@ -115,8 +115,7 @@ internal SqlClientOriginalNetworkAddressInfo OriginalNetworkAddressInfo public override bool Equals(object obj) { - SqlConnectionPoolKey key = obj as SqlConnectionPoolKey; - return (key != null + return (obj is SqlConnectionPoolKey key && _credential == key._credential && ConnectionString == key.ConnectionString #if NETFRAMEWORK From f2cf2c478046705b11788408b1f32e64efe08d9a Mon Sep 17 00:00:00 2001 From: Lawrence LCI <31262254+lcheunglci@users.noreply.github.com> Date: Tue, 28 Sep 2021 15:53:15 -0700 Subject: [PATCH 06/11] Revise the ifdef in the Equals method in SqlConnectionPoolKey --- .../src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs index c3b02b249b..8296fb9e1b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs @@ -118,12 +118,13 @@ public override bool Equals(object obj) 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 - && string.CompareOrdinal(_accessToken, key._accessToken) == 0); + ); } public override int GetHashCode() From 1630bbf5358f7d63b818707b5acaf90bb7b279aa Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Mon, 4 Oct 2021 14:59:09 -0700 Subject: [PATCH 07/11] Renamed the shared src SqlConnectionPoolKey.cs to SqlConnectionPoolKey.Common.cs and seperated it into a partial classes for clarify --- .../src/Microsoft.Data.SqlClient.csproj | 5 +- .../Data/SqlClient/SqlConnectionPoolKey.cs | 56 +++++++++ .../netfx/src/Microsoft.Data.SqlClient.csproj | 7 +- .../Data/SqlClient/SqlConnectionPoolKey.cs | 108 ++++-------------- .../SqlClient/SqlConnectionPoolKey.Common.cs | 55 +++++++++ 5 files changed, 142 insertions(+), 89 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs rename src/Microsoft.Data.SqlClient/{ => netfx}/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs (60%) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs 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 ed1de50754..6f46535f84 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -217,8 +217,8 @@ Microsoft\Data\SqlClient\SqlColumnEncryptionKeyStoreProvider.cs - - Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.Common.cs Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs @@ -493,6 +493,7 @@ + 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 new file mode 100644 index 0000000000..966efd9ca2 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs @@ -0,0 +1,56 @@ +// 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 +{ + internal partial class SqlConnectionPoolKey : DbConnectionPoolKey + { + private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) + { + _credential = key.Credential; + _accessToken = key.AccessToken; + CalculateHashCode(); + } + + 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(); + } + + public override bool Equals(object obj) + { + return (obj is SqlConnectionPoolKey key + && _credential == key._credential + && ConnectionString == key.ConnectionString + && string.CompareOrdinal(_accessToken, key._accessToken) == 0); + } + + partial 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 1ad3bffdd1..b0af9096f9 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -288,8 +288,8 @@ Microsoft\Data\SqlClient\SqlColumnEncryptionKeyStoreProvider.cs - - Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.Common.cs Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs @@ -458,6 +458,7 @@ + @@ -562,7 +563,7 @@ True $(ResxFileName).resx - + Resources\StringsHelper.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs similarity index 60% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs rename to src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs index 8296fb9e1b..2ebff4e530 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. @@ -8,86 +8,48 @@ 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 + internal partial class SqlConnectionPoolKey : DbConnectionPoolKey { - private int _hashValue; - private readonly SqlCredential _credential; - private readonly string _accessToken; - -#if NETFRAMEWORK private readonly ServerCertificateValidationCallback _serverCertificateValidationCallback; private readonly ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; private readonly SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; -#endif - -#if NETFRAMEWORK - internal SqlConnectionPoolKey(string 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; - _accessToken = accessToken; - _serverCertificateValidationCallback = serverCertificateValidationCallback; - _clientCertificateRetrievalCallback = clientCertificateRetrievalCallback; - _originalNetworkAddressInfo = originalNetworkAddressInfo; - CalculateHashCode(); - } -#else - 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(); - } -#endif private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) { _credential = key.Credential; _accessToken = key.AccessToken; -#if NETFRAMEWORK _serverCertificateValidationCallback = key._serverCertificateValidationCallback; _clientCertificateRetrievalCallback = key._clientCertificateRetrievalCallback; -#endif CalculateHashCode(); } - public override object Clone() + internal SqlConnectionPoolKey(string connectionString, + SqlCredential credential, + string accessToken, + ServerCertificateValidationCallback serverCertificateValidationCallback, + ClientCertificateRetrievalCallback clientCertificateRetrievalCallback, + SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo) : base(connectionString) { - return new SqlConnectionPoolKey(this); + Debug.Assert(_credential == null || _accessToken == null, "Credential and AccessToken can't have the value at the same time."); + _credential = credential; + _accessToken = accessToken; + _serverCertificateValidationCallback = serverCertificateValidationCallback; + _clientCertificateRetrievalCallback = clientCertificateRetrievalCallback; + _originalNetworkAddressInfo = originalNetworkAddressInfo; + CalculateHashCode(); } - internal override string ConnectionString + public override bool Equals(object obj) { - get - { - return base.ConnectionString; - } - - set - { - base.ConnectionString = value; - CalculateHashCode(); - } + return (obj is SqlConnectionPoolKey key + && _credential == key._credential + && ConnectionString == key.ConnectionString + && string.CompareOrdinal(_accessToken, key._accessToken) == 0 + && _serverCertificateValidationCallback == key._serverCertificateValidationCallback + && _clientCertificateRetrievalCallback == key._clientCertificateRetrievalCallback + && _originalNetworkAddressInfo == key._originalNetworkAddressInfo); } - internal SqlCredential Credential => _credential; - - internal string AccessToken - { - get - { - return _accessToken; - } - } -#if NETFRAMEWORK internal ServerCertificateValidationCallback ServerCertificateValidationCallback { get @@ -111,28 +73,8 @@ internal SqlClientOriginalNetworkAddressInfo OriginalNetworkAddressInfo return _originalNetworkAddressInfo; } } -#endif - - public override bool Equals(object obj) - { - 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() - { - return _hashValue; - } - private void CalculateHashCode() + partial void CalculateHashCode() { _hashValue = base.GetHashCode(); @@ -151,7 +93,6 @@ private void CalculateHashCode() } } -#if NETFRAMEWORK if (_originalNetworkAddressInfo != null) { unchecked @@ -159,7 +100,6 @@ private void CalculateHashCode() _hashValue = _hashValue * 17 + _originalNetworkAddressInfo.GetHashCode(); } } -#endif } } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs new file mode 100644 index 0000000000..adde342319 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs @@ -0,0 +1,55 @@ +// 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 partial class SqlConnectionPoolKey : DbConnectionPoolKey + { + private int _hashValue; + private readonly SqlCredential _credential; + private readonly string _accessToken; + + 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 int GetHashCode() + { + return _hashValue; + } + + partial void CalculateHashCode(); + } +} From 57da38b3115ced1ddf0bec60a5955ec00f78c343 Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Wed, 6 Oct 2021 14:51:32 -0700 Subject: [PATCH 08/11] Merge the netfx and netcore versions of SqlConnectionPoolKey.cs back into SqlConnectionPoolKey.Common.cs --- .../src/Microsoft.Data.SqlClient.csproj | 1 - .../Data/SqlClient/SqlConnectionPoolKey.cs | 56 -------- .../netfx/src/Microsoft.Data.SqlClient.csproj | 3 +- .../Data/SqlClient/SqlConnectionPoolKey.cs | 105 --------------- .../SqlClient/SqlConnectionPoolKey.Common.cs | 124 +++++++++++++++++- 5 files changed, 123 insertions(+), 166 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs 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 03fa7e3e57..b3b0f5c856 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -496,7 +496,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 966efd9ca2..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ /dev/null @@ -1,56 +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 -{ - internal partial class SqlConnectionPoolKey : DbConnectionPoolKey - { - private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) - { - _credential = key.Credential; - _accessToken = key.AccessToken; - CalculateHashCode(); - } - - 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(); - } - - public override bool Equals(object obj) - { - return (obj is SqlConnectionPoolKey key - && _credential == key._credential - && ConnectionString == key.ConnectionString - && string.CompareOrdinal(_accessToken, key._accessToken) == 0); - } - - partial 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 b0af9096f9..b1c6048316 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -458,7 +458,6 @@ - @@ -629,4 +628,4 @@ - + \ No newline at end of file diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs deleted file mode 100644 index 2ebff4e530..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ /dev/null @@ -1,105 +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 -{ - internal partial class SqlConnectionPoolKey : DbConnectionPoolKey - { - private readonly ServerCertificateValidationCallback _serverCertificateValidationCallback; - private readonly ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; - private readonly SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; - - private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) - { - _credential = key.Credential; - _accessToken = key.AccessToken; - _serverCertificateValidationCallback = key._serverCertificateValidationCallback; - _clientCertificateRetrievalCallback = key._clientCertificateRetrievalCallback; - CalculateHashCode(); - } - - internal SqlConnectionPoolKey(string 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; - _accessToken = accessToken; - _serverCertificateValidationCallback = serverCertificateValidationCallback; - _clientCertificateRetrievalCallback = clientCertificateRetrievalCallback; - _originalNetworkAddressInfo = originalNetworkAddressInfo; - CalculateHashCode(); - } - - public override bool Equals(object obj) - { - return (obj is SqlConnectionPoolKey key - && _credential == key._credential - && ConnectionString == key.ConnectionString - && string.CompareOrdinal(_accessToken, key._accessToken) == 0 - && _serverCertificateValidationCallback == key._serverCertificateValidationCallback - && _clientCertificateRetrievalCallback == key._clientCertificateRetrievalCallback - && _originalNetworkAddressInfo == key._originalNetworkAddressInfo); - } - - internal ServerCertificateValidationCallback ServerCertificateValidationCallback - { - get - { - return _serverCertificateValidationCallback; - } - } - - internal ClientCertificateRetrievalCallback ClientCertificateRetrievalCallback - { - get - { - return _clientCertificateRetrievalCallback; - } - } - - internal SqlClientOriginalNetworkAddressInfo OriginalNetworkAddressInfo - { - get - { - return _originalNetworkAddressInfo; - } - } - - partial void CalculateHashCode() - { - _hashValue = base.GetHashCode(); - - if (_credential != null) - { - unchecked - { - _hashValue = _hashValue * 17 + _credential.GetHashCode(); - } - } - else if (_accessToken != null) - { - unchecked - { - _hashValue = _hashValue * 17 + _accessToken.GetHashCode(); - } - } - - if (_originalNetworkAddressInfo != null) - { - unchecked - { - _hashValue = _hashValue * 17 + _originalNetworkAddressInfo.GetHashCode(); - } - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs index adde342319..b5d55ac16b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs @@ -10,7 +10,7 @@ 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 partial class SqlConnectionPoolKey : DbConnectionPoolKey + internal class SqlConnectionPoolKey : DbConnectionPoolKey { private int _hashValue; private readonly SqlCredential _credential; @@ -50,6 +50,126 @@ public override int GetHashCode() return _hashValue; } - partial void CalculateHashCode(); +#if NETFRAMEWORK + private readonly ServerCertificateValidationCallback _serverCertificateValidationCallback; + private readonly ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; + private readonly SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; + + private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) + { + _credential = key.Credential; + _accessToken = key.AccessToken; + _serverCertificateValidationCallback = key._serverCertificateValidationCallback; + _clientCertificateRetrievalCallback = key._clientCertificateRetrievalCallback; + CalculateHashCode(); + } + + internal SqlConnectionPoolKey(string 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; + _accessToken = accessToken; + _serverCertificateValidationCallback = serverCertificateValidationCallback; + _clientCertificateRetrievalCallback = clientCertificateRetrievalCallback; + _originalNetworkAddressInfo = originalNetworkAddressInfo; + CalculateHashCode(); + } + + public override bool Equals(object obj) + { + return (obj is SqlConnectionPoolKey key + && _credential == key._credential + && ConnectionString == key.ConnectionString + && string.CompareOrdinal(_accessToken, key._accessToken) == 0 + && _serverCertificateValidationCallback == key._serverCertificateValidationCallback + && _clientCertificateRetrievalCallback == key._clientCertificateRetrievalCallback + && _originalNetworkAddressInfo == key._originalNetworkAddressInfo); + } + + internal ServerCertificateValidationCallback ServerCertificateValidationCallback + => _serverCertificateValidationCallback; + + internal ClientCertificateRetrievalCallback ClientCertificateRetrievalCallback + => _clientCertificateRetrievalCallback; + + internal SqlClientOriginalNetworkAddressInfo OriginalNetworkAddressInfo + => _originalNetworkAddressInfo; + + internal void CalculateHashCode() + { + _hashValue = base.GetHashCode(); + + if (_credential != null) + { + unchecked + { + _hashValue = _hashValue * 17 + _credential.GetHashCode(); + } + } + else if (_accessToken != null) + { + unchecked + { + _hashValue = _hashValue * 17 + _accessToken.GetHashCode(); + } + } + + if (_originalNetworkAddressInfo != null) + { + unchecked + { + _hashValue = _hashValue * 17 + _originalNetworkAddressInfo.GetHashCode(); + } + } + } +#else + private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) + { + _credential = key.Credential; + _accessToken = key.AccessToken; + CalculateHashCode(); + } + + 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(); + } + + public override bool Equals(object obj) + { + return (obj is SqlConnectionPoolKey key + && _credential == key._credential + && ConnectionString == key.ConnectionString + && string.CompareOrdinal(_accessToken, key._accessToken) == 0); + } + + internal void CalculateHashCode() + { + _hashValue = base.GetHashCode(); + + if (_credential != null) + { + unchecked + { + _hashValue = _hashValue * 17 + _credential.GetHashCode(); + } + } + else if (_accessToken != null) + { + unchecked + { + _hashValue = _hashValue * 17 + _accessToken.GetHashCode(); + } + } + } +#endif // NETFRAMEWORK } } From 1b2bad56b95b99b5babdb6225e3cb62cbe37ac7e Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Wed, 6 Oct 2021 14:56:32 -0700 Subject: [PATCH 09/11] Rename SqlConnectionPoolKey.Common.cs in shared src to SqlConnectionPoolKey.cs --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../netfx/src/Microsoft.Data.SqlClient.csproj | 4 ++-- ...SqlConnectionPoolKey.Common.cs => SqlConnectionPoolKey.cs} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{SqlConnectionPoolKey.Common.cs => SqlConnectionPoolKey.cs} (100%) 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 b3b0f5c856..93f37a9135 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -217,8 +217,8 @@ Microsoft\Data\SqlClient\SqlColumnEncryptionKeyStoreProvider.cs - - Microsoft\Data\SqlClient\SqlConnectionPoolKey.Common.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs 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 b1c6048316..00e56127a8 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -288,8 +288,8 @@ Microsoft\Data\SqlClient\SqlColumnEncryptionKeyStoreProvider.cs - - Microsoft\Data\SqlClient\SqlConnectionPoolKey.Common.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.Common.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs From 71aef5f45c9fd5fb5b4ed4d9878ef023b259caa2 Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Wed, 6 Oct 2021 20:18:19 -0700 Subject: [PATCH 10/11] Revise changes based on comments restore original approach forthe method CalculateHashCode and Equals and move the fields and properties to the top --- .../Data/SqlClient/SqlConnectionPoolKey.cs | 145 +++++++----------- 1 file changed, 55 insertions(+), 90 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs index b5d55ac16b..3e68178f9f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs @@ -16,18 +16,12 @@ internal class SqlConnectionPoolKey : DbConnectionPoolKey private readonly SqlCredential _credential; private readonly string _accessToken; - public override object Clone() - { - return new SqlConnectionPoolKey(this); - } + internal SqlCredential Credential => _credential; + internal string AccessToken => _accessToken; internal override string ConnectionString { - get - { - return base.ConnectionString; - } - + get => base.ConnectionString; set { base.ConnectionString = value; @@ -35,49 +29,63 @@ internal override string ConnectionString } } - internal SqlCredential Credential => _credential; +#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 string AccessToken + internal SqlConnectionPoolKey(string connectionString, + SqlCredential credential, + string accessToken, + ServerCertificateValidationCallback serverCertificateValidationCallback, + ClientCertificateRetrievalCallback clientCertificateRetrievalCallback, + SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo) : base(connectionString) { - get - { - return _accessToken; - } + Debug.Assert(_credential == null || _accessToken == null, "Credential and AccessToken can't have the value at the same time."); + _credential = credential; + _accessToken = accessToken; + _serverCertificateValidationCallback = serverCertificateValidationCallback; + _clientCertificateRetrievalCallback = clientCertificateRetrievalCallback; + _originalNetworkAddressInfo = originalNetworkAddressInfo; + CalculateHashCode(); } - - public override int GetHashCode() + #endregion +#else + #region NET Core + internal SqlConnectionPoolKey(string connectionString, SqlCredential credential, string accessToken) : base(connectionString) { - return _hashValue; + Debug.Assert(_credential == null || _accessToken == null, "Credential and AccessToken can't have the value at the same time."); + _credential = credential; + _accessToken = accessToken; + CalculateHashCode(); } - -#if NETFRAMEWORK - private readonly ServerCertificateValidationCallback _serverCertificateValidationCallback; - private readonly ClientCertificateRetrievalCallback _clientCertificateRetrievalCallback; - private readonly SqlClientOriginalNetworkAddressInfo _originalNetworkAddressInfo; + #endregion +#endif private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) { _credential = key.Credential; _accessToken = key.AccessToken; +#if NETFRAMEWORK _serverCertificateValidationCallback = key._serverCertificateValidationCallback; _clientCertificateRetrievalCallback = key._clientCertificateRetrievalCallback; +#endif CalculateHashCode(); } - internal SqlConnectionPoolKey(string connectionString, - SqlCredential credential, - string accessToken, - ServerCertificateValidationCallback serverCertificateValidationCallback, - ClientCertificateRetrievalCallback clientCertificateRetrievalCallback, - SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo) : base(connectionString) + public override object Clone() { - Debug.Assert(_credential == null || _accessToken == null, "Credential and AccessToken can't have the value at the same time."); - _credential = credential; - _accessToken = accessToken; - _serverCertificateValidationCallback = serverCertificateValidationCallback; - _clientCertificateRetrievalCallback = clientCertificateRetrievalCallback; - _originalNetworkAddressInfo = originalNetworkAddressInfo; - CalculateHashCode(); + return new SqlConnectionPoolKey(this); } public override bool Equals(object obj) @@ -86,21 +94,20 @@ public override bool Equals(object obj) && _credential == key._credential && ConnectionString == key.ConnectionString && string.CompareOrdinal(_accessToken, key._accessToken) == 0 +#if NETFRAMEWORK && _serverCertificateValidationCallback == key._serverCertificateValidationCallback && _clientCertificateRetrievalCallback == key._clientCertificateRetrievalCallback - && _originalNetworkAddressInfo == key._originalNetworkAddressInfo); + && _originalNetworkAddressInfo == key._originalNetworkAddressInfo +#endif + ); } - internal ServerCertificateValidationCallback ServerCertificateValidationCallback - => _serverCertificateValidationCallback; - - internal ClientCertificateRetrievalCallback ClientCertificateRetrievalCallback - => _clientCertificateRetrievalCallback; - - internal SqlClientOriginalNetworkAddressInfo OriginalNetworkAddressInfo - => _originalNetworkAddressInfo; + public override int GetHashCode() + { + return _hashValue; + } - internal void CalculateHashCode() + private void CalculateHashCode() { _hashValue = base.GetHashCode(); @@ -119,6 +126,7 @@ internal void CalculateHashCode() } } +#if NETFRAMEWORK if (_originalNetworkAddressInfo != null) { unchecked @@ -126,50 +134,7 @@ internal void CalculateHashCode() _hashValue = _hashValue * 17 + _originalNetworkAddressInfo.GetHashCode(); } } +#endif } -#else - private SqlConnectionPoolKey(SqlConnectionPoolKey key) : base(key) - { - _credential = key.Credential; - _accessToken = key.AccessToken; - CalculateHashCode(); - } - - 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(); - } - - public override bool Equals(object obj) - { - return (obj is SqlConnectionPoolKey key - && _credential == key._credential - && ConnectionString == key.ConnectionString - && string.CompareOrdinal(_accessToken, key._accessToken) == 0); - } - - internal void CalculateHashCode() - { - _hashValue = base.GetHashCode(); - - if (_credential != null) - { - unchecked - { - _hashValue = _hashValue * 17 + _credential.GetHashCode(); - } - } - else if (_accessToken != null) - { - unchecked - { - _hashValue = _hashValue * 17 + _accessToken.GetHashCode(); - } - } - } -#endif // NETFRAMEWORK } } From 1dd6a0871a42c171e012ec270c8d63258952109d Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Thu, 7 Oct 2021 14:02:18 -0700 Subject: [PATCH 11/11] Remove the unused namespace --- .../src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs index 3e68178f9f..c35ce6f08e 100644 --- a/src/Microsoft.Data.SqlClient/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;