private void SyncShards(IEnumerable <ShardBase> shards, bool queueRequest = false)
        {
            if (queueRequest)
            {
                foreach (var shard in shards)
                {
                    var request = new ShardSyncRequest
                    {
                        Catalog            = shard.Catalog,
                        ServerInstanceName = shard.ServerInstanceName,
                        ShardSetName       = ShardSetName,
                    };

                    request.Save();
                }

                return;
            }

            var driver = GetShardSetDriver();

            var parallelOptions = GetParallelOptions();
            var parallelResults = new ConcurrentBag <ShardDeploymentResult>();

            Parallel.ForEach(shards, parallelOptions, shard =>
            {
                Exception ex = null;
                try
                {
                    driver.SyncShard(shard, this);
                }
                catch (Exception e)
                {
                    ex = e;
                }
                if (ex != null)
                {
                    parallelResults.Add(new ShardDeploymentResult
                    {
                        Exception = ex,
                        Shard     = shard
                    });
                }
            });

            CheckResultsAndThrow(parallelResults);
        }
        /// <summary>
        /// Handles the shard synchronize request and processes it against the shard set driver.
        /// </summary>
        /// <param name="request">The shard synchronize request.</param>
        /// <param name="queue">The queue.</param>
        public static void HandleShardSyncRequest(ShardSyncRequest request, BaseShardSetActionQueue queue)
        {
            var config = GetCurrentShardSetConfig(request.ShardSetName);
            var driver = GetShardSetDriver(config);

            Action <ShardSyncRequest> process = (
                x =>
            {
                var shard = new RangeShard
                {
                    Catalog = request.Catalog,
                    ServerInstanceName = request.ServerInstanceName,
                };

                driver.SyncShard(shard, config);
            });

            Action <ShardSyncRequest> complete =
                (x => queue.SendQueueProcessingEvent(GetCompletionMessage("ShardSyncRequest", x)));
            Action <ShardSyncRequest> error =
                (x => queue.SendQueueProcessingEvent(GetErrorMessage("ShardSyncRequest", x)));

            request.Process(process, complete, error);
        }