public IDataObjectTypesProvider Create(ReplicateInBulkCommand command)
        {
            if (command.TargetStorageDescriptor.ConnectionStringIdentity is FactsConnectionStringIdentity)
            {
                return new CommandRegardlessDataObjectTypesProvider(
                    new List<Type>
                        {
                            typeof(Project),
                            typeof(Category),
                            typeof(CategoryGroup),
                            typeof(Territory),
                            typeof(Client),
                            typeof(Firm),
                            typeof(Account),
                            typeof(Activity),
                            typeof(BranchOfficeOrganizationUnit),
                            typeof(CategoryFirmAddress),
                            typeof(CategoryOrganizationUnit),
                            typeof(Contact),
                            typeof(FirmAddress),
                            typeof(FirmContact),
                            typeof(Lead),
                            typeof(LegalPerson),
                            typeof(Order),
                            typeof(SalesModelCategoryRestriction)
                        });
            }
            if (command.TargetStorageDescriptor.ConnectionStringIdentity is CustomerIntelligenceConnectionStringIdentity)
            {
                return new CommandRegardlessDataObjectTypesProvider(
                    new List<Type>
                        {
                            typeof(Storage.Model.CI.Firm),
                            typeof(Storage.Model.CI.FirmActivity),
                            typeof(Storage.Model.CI.FirmBalance),
                            typeof(Storage.Model.CI.FirmCategory1),
                            typeof(Storage.Model.CI.FirmCategory2),
                            typeof(Storage.Model.CI.FirmLead),
                            typeof(Storage.Model.CI.FirmTerritory),
                            typeof(Storage.Model.CI.Client),
                            typeof(Storage.Model.CI.ClientContact),
                            typeof(Storage.Model.CI.Project),
                            typeof(Storage.Model.CI.ProjectCategory),
                            typeof(Storage.Model.CI.Territory),
                            typeof(Storage.Model.CI.CategoryGroup),
                            typeof(Storage.Model.Statistics.ProjectStatistics),
                            typeof(Storage.Model.Statistics.ProjectCategoryStatistics),
                            typeof(Storage.Model.Statistics.FirmForecast),
                            typeof(Storage.Model.Statistics.FirmCategory3),
                        });
            }

            throw new ArgumentException($"Instance of type IDataObjectTypesProvider cannot be created for connection string name {command.TargetStorageDescriptor.MappingSchema}");
        }
Exemplo n.º 2
0
        private void SequentialExecutionStrategy(ReplicateInBulkCommand command, IReadOnlyDictionary<TableName, Type[]> tableTypesDictionary)
        {
            ExecuteInTransactionScope(
                command,
                (targetConnection, schemaManagenentActor) =>
                {
                    var schemaChangedEvents = schemaManagenentActor.ExecuteCommands(CreateSchemaChangesCommands(command.DbManagementMode));

                    foreach (var tableTypesPair in tableTypesDictionary)
                    {
                        try
                        {
                            var replicationCommands = CreateReplicationCommands(tableTypesPair.Key, command.BulkCopyTimeout, command.DbManagementMode);
                            ReplaceInBulk(tableTypesPair.Value, command.SourceStorageDescriptor, targetConnection, replicationCommands);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception($"Failed to replicate using sequential strategy {tableTypesPair.Key}", ex);
                        }
                    }

                    schemaManagenentActor.ExecuteCommands(CreateSchemaChangesCompensationalCommands(schemaChangedEvents));
                });
        }
Exemplo n.º 3
0
 private void ExecuteInTransactionScope(ReplicateInBulkCommand command, Action<DataConnection, SequentialPipelineActor> action)
 {
     using (var transation = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionOptions))
     {
         using (var targetConnection = CreateDataConnection(command.TargetStorageDescriptor))
         {
             var schemaManagenentActor = CreateDbSchemaManagementActor((SqlConnection)targetConnection.Connection, command.TargetStorageDescriptor.CommandTimeout);
             action(targetConnection, schemaManagenentActor);
             transation.Complete();
         }
     }
 }
Exemplo n.º 4
0
        private void ParallelExecutionStrategy(ReplicateInBulkCommand command, IReadOnlyDictionary<TableName, Type[]> tableTypesDictionary)
        {
            IReadOnlyCollection<IEvent> schemaChangedEvents = null;
            ExecuteInTransactionScope(
                command,
                (targetConnection, schemaManagenentActor) =>
                {
                    schemaChangedEvents = schemaManagenentActor.ExecuteCommands(CreateSchemaChangesCommands(command.DbManagementMode));
                });

            Parallel.ForEach(
                    tableTypesDictionary,
                    tableTypesPair =>
                    {
                        using (var connection = CreateDataConnection(command.TargetStorageDescriptor))
                        {
                            try
                            {
                                var replicationCommands = CreateReplicationCommands(tableTypesPair.Key, command.BulkCopyTimeout, command.DbManagementMode);
                                ReplaceInBulk(tableTypesPair.Value, command.SourceStorageDescriptor, connection, replicationCommands);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception($"Failed to replicate using parallel strategy {tableTypesPair.Key}", ex);
                            }
                        }
                    });

            ExecuteInTransactionScope(
                command,
                (targetConnection, schemaManagenentActor) =>
                {
                    schemaManagenentActor.ExecuteCommands(CreateSchemaChangesCompensationalCommands(schemaChangedEvents));
                });
        }
Exemplo n.º 5
0
 private Action<ReplicateInBulkCommand, IReadOnlyDictionary<TableName, Type[]>> DetermineExecutionStrategy(ReplicateInBulkCommand command)
 {
     switch (command.ExecutionMode)
     {
         case ExecutionMode.Parallel:
             return ParallelExecutionStrategy;
         case ExecutionMode.Sequential:
             return SequentialExecutionStrategy;
         default:
             throw new ArgumentException($"Execution mode {command.ExecutionMode} is not supported", nameof(command));
     }
 }