private void ShadowParallelExecutionStrategy(ReplicateInBulkCommand command, IReadOnlyDictionary <TableName, Type[]> tableTypesDictionary, ParallelOptions options)
        {
            Parallel.ForEach(
                tableTypesDictionary,
                options,
                tableTypesPair =>
            {
                using (var targetConnection = CreateDataConnection(command.TargetStorageDescriptor))
                    using (var sourceConnection = CreateTransactionlessDataConnection(command.SourceStorageDescriptor))
                    {
                        try
                        {
                            var replicationCommands = CreateShadowReplicationCommands(tableTypesPair.Key, command.BulkCopyTimeout, command.DbManagementMode);
                            _bulkReplicator.Replicate(tableTypesPair.Value, sourceConnection, targetConnection, replicationCommands);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception($"Failed to replicate using shadow parallel strategy {tableTypesPair.Key}", ex);
                        }
                    }
            });

            ExecuteInTransactionScope(
                command,
                (targetConnection, schemaManagenentActor) =>
            {
                var schemaChangedEvents = schemaManagenentActor.ExecuteCommands(CreateSchemaChangesCommands(command.DbManagementMode));

                // Delete existed tables then rename newly created ones (remove prefix):
                schemaManagenentActor.ExecuteCommands(CreateTablesReplacingCommands(tableTypesDictionary.Keys));
                schemaManagenentActor.ExecuteCommands(CreateSchemaChangesCompensationalCommands(schemaChangedEvents));
            });
        }
        private void Replicate(ReplicateInBulkCommand command, TableName tableName, IReadOnlyCollection <Type> types)
        {
            using var targetConnection = CreateDataConnection(command.TargetStorageDescriptor);
            using var sourceConnection = CreateSourceDataConnection(command.SourceStorageDescriptor);

            try
            {
                var replicationCommands = CreateReplicationCommands(
                    tableName,
                    command.BulkCopyTimeout,
                    command.DbManagementMode,
                    command.SourceStorageDescriptor.Tenant);

                Console.WriteLine($"Replicating {tableName}");
                _bulkReplicator.Replicate(
                    types,
                    sourceConnection,
                    targetConnection,
                    replicationCommands,
                    command.SourceStorageDescriptor.Tenant);
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to replicate using parallel strategy {tableName}", ex);
            }
        }