/// <summary>
 /// Given the connection string, opens up the corresponding data source and obtains the ShardMapManager.
 /// </summary>
 /// <param name="credentials">Credentials for performing ShardMapManager operations.</param>
 /// <param name="storeConnectionFactory">Factory for store connections.</param>
 /// <param name="storeOperationFactory">Factory for store operations.</param>
 /// <param name="cacheStore">Cache store.</param>
 /// <param name="loadPolicy">Initialization policy.</param>
 /// <param name="retryPolicy">Policy for performing retries on connections to shard map manager database.</param>
 /// <param name="retryBehavior">Policy for detecting transient errors.</param>
 internal ShardMapManager(
     SqlShardMapManagerCredentials credentials,
     IStoreConnectionFactory storeConnectionFactory,
     IStoreOperationFactory storeOperationFactory,
     ICacheStore cacheStore,
     ShardMapManagerLoadPolicy loadPolicy,
     RetryPolicy retryPolicy,
     RetryBehavior retryBehavior)
     : this(credentials, storeConnectionFactory, storeOperationFactory, cacheStore, loadPolicy, retryPolicy, retryBehavior, null)
 {
 }
        /// <summary>
        /// Given the connection string, opens up the corresponding data source and obtains the ShardMapManager.
        /// </summary>
        /// <param name="credentials">Credentials for performing ShardMapManager operations.</param>
        /// <param name="storeConnectionFactory">Factory for store connections.</param>
        /// <param name="storeOperationFactory">Factory for store operations.</param>
        /// <param name="cacheStore">Cache store.</param>
        /// <param name="loadPolicy">Initialization policy.</param>
        /// <param name="retryPolicy">Policy for performing retries on connections to shard map manager database.</param>
        /// <param name="retryBehavior">Policy for detecting transient errors.</param>
        /// <param name="retryEventHandler">Event handler for store operation retry events.</param>
        internal ShardMapManager(
            SqlShardMapManagerCredentials credentials,
            IStoreConnectionFactory storeConnectionFactory,
            IStoreOperationFactory storeOperationFactory,
            ICacheStore cacheStore,
            ShardMapManagerLoadPolicy loadPolicy,
            RetryPolicy retryPolicy,
            RetryBehavior retryBehavior,
            EventHandler <RetryingEventArgs> retryEventHandler)
        {
            Debug.Assert(credentials != null);

            this.Credentials            = credentials;
            this.StoreConnectionFactory = storeConnectionFactory;
            this.StoreOperationFactory  = storeOperationFactory;
            this.Cache = cacheStore;

            this.RetryPolicy = new TransientFaultHandling.RetryPolicy(
                new ShardManagementTransientErrorDetectionStrategy(retryBehavior),
                retryPolicy.GetRetryStrategy());

            // Register for TfhImpl.RetryPolicy.Retrying event.
            this.RetryPolicy.Retrying += this.ShardMapManagerRetryingEventHandler;

            // Add user specified event handler.
            if (retryEventHandler != null)
            {
                this.ShardMapManagerRetrying += retryEventHandler;
            }

            if (loadPolicy == ShardMapManagerLoadPolicy.Eager)
            {
                // We eagerly load everything from ShardMapManager. In case of lazy
                // loading policy, we will add things to local caches based on cache
                // misses on lookups.
                this.LoadFromStore();
            }
        }