| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //------------------------------------------------------------------------------
- // <copyright file="ConnectionPoolKey.cs" company="Microsoft">
- // Copyright (c) Microsoft Corporation. All rights reserved.
- // </copyright>
- // <owner current="true" primary="true">[....]</owner>
- // <owner current="true" primary="false">[....]</owner>
- //------------------------------------------------------------------------------
- namespace System.Data.SqlClient
- {
- using System;
- using System.Collections;
- using System.Data.Common;
- using System.Diagnostics;
- // 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;
- 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();
- }
- 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;
- }
- }
- public override bool Equals(object obj)
- {
- SqlConnectionPoolKey key = obj as SqlConnectionPoolKey;
- return (key != null && _credential == key._credential && ConnectionString == key.ConnectionString && Object.ReferenceEquals(_accessToken, key._accessToken));
- }
- 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();
- }
- }
- }
- }
- }
|