/// <summary>
        /// Tries to obtains a <see cref="RangeShardMap{TKey}"/> given the name.
        /// </summary>
        /// <typeparam name="TKey">Key type.</typeparam>
        /// <param name="shardMapName">Name of shard map.</param>
        /// <param name="shardMap">Shard map with the specified name.</param>
        /// <returns><c>true</c> if shard map with the specified name was found, <c>false</c> otherwise.</returns>
        public bool TryGetRangeShardMap <TKey>(string shardMapName, out RangeShardMap <TKey> shardMap)
        {
            ShardMapManager.ValidateShardMapName(shardMapName);

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Tracer.TraceVerbose(
                    TraceSourceConstants.ComponentNames.ShardMapManager,
                    "TryGetRangeShardMap",
                    "Start; ShardMap: {0}",
                    shardMapName);

                shardMap = this.LookupAndConvertShardMapHelper <RangeShardMap <TKey> >(
                    "TryGetRangeShardMap",
                    shardMapName,
                    ShardMapExtensions.AsRangeShardMap <TKey>,
                    false);

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ShardMapManager,
                    "TryGetRangeShardMap",
                    "Complete; ShardMap: {0}",
                    shardMapName);

                return(shardMap != null);
            }
        }
        internal static RangeShardMap <TKey> AsRangeShardMap <TKey>(this ShardMap shardMap, bool throwOnFailure)
        {
            Debug.Assert(shardMap != null);
            RangeShardMap <TKey> rsm = null;

            if (shardMap.MapType == ShardMapType.Range)
            {
                rsm = shardMap as RangeShardMap <TKey>;
            }


            if (rsm == null && throwOnFailure)
            {
                throw ShardMapExtensions.GetConversionException <TKey>(shardMap.StoreShardMap, "Range");
            }

            return(rsm);
        }
        /// <summary>
        /// Create a range based <see cref="RangeShardMap{TKey}"/>.
        /// </summary>
        /// <typeparam name="TKey">Type of keys.</typeparam>
        /// <param name="shardMapName">Name of shard map.</param>
        /// <returns>Range shard map with the specified name.</returns>
        public RangeShardMap <TKey> CreateRangeShardMap <TKey>(string shardMapName)
        {
            ShardMapManager.ValidateShardMapName(shardMapName);

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                DefaultStoreShardMap dssm = new DefaultStoreShardMap(
                    Guid.NewGuid(),
                    shardMapName,
                    ShardMapType.Range,
                    ShardKey.ShardKeyTypeFromType(typeof(TKey)));

                RangeShardMap <TKey> rangeShardMap = new RangeShardMap <TKey>(this, dssm);

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ShardMapManager,
                    "CreateRangeShardMap",
                    "Start; ShardMap: {0}",
                    shardMapName);

                Stopwatch stopwatch = Stopwatch.StartNew();

                this.AddShardMapToStore("CreateRangeShardMap", dssm);

                stopwatch.Stop();

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ShardMapManager,
                    "CreateRangeShardMap", "Added ShardMap to Store; ShardMap: {0} Duration: {1}",
                    shardMapName,
                    stopwatch.Elapsed);

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ShardMapManager,
                    "CreateRangeShardMap",
                    "Complete; ShardMap: {0} Duration: {1}",
                    shardMapName,
                    stopwatch.Elapsed);

                return(rangeShardMap);
            }
        }