Beispiel #1
0
        /// <summary>
        /// Description:This method is used to change the dedup type from Simulate to Full-Dedup.
        /// User can check 'N' number of time to simulate to verify the data before DeDup.
        /// Once they satisfied then it will change it to Full Dedup.
        /// Once its change to Full Dedup then we can not revert back to Simulate mode
        /// </summary>
        /// <param name="connectorConfig"></param>
        /// <param name="dbConfig"></param>
        /// <param name="ccid"></param>
        public string FinalizedForDedup_Repository(ConnectorConfig connectorConfig)
        {
            try
            {
                if (connectorConfig == null && (connectorConfig != null && (string.IsNullOrEmpty(connectorConfig.ccid) || !connectorConfig.connectorId.HasValue)))
                {
                    return("");
                }

                if ((connectorConfig.syncDestination == ConnectorType.Heroku_Postgres ||
                     connectorConfig.syncDestination == ConnectorType.Azure_Postgres ||
                     connectorConfig.syncDestination == ConnectorType.AWS_Postgres ||
                     connectorConfig.syncDestination == ConnectorType.Azure_SQL) &&
                    (connectorConfig.dbConfig == null ||
                     (connectorConfig.dbConfig != null && string.IsNullOrEmpty(connectorConfig.dbConfig.syncDefaultDatabaseUrl))))
                {
                    return("");
                }

                var entity = Find(connectorConfig.ccid, connectorConfig.connectorId);
                //Drop the ctindex table & backup table before changing to Real Dedup mode
                StringBuilder sb = new StringBuilder();
                sb.Append($"DROP TABLE IF EXISTS \"{entity.dest_schema}\".\"{entity.dest_object_name}_ctindex\";");
                sb.Append($"DROP TABLE IF EXISTS \"{entity.dest_schema}\".\"{entity.dest_object_name}_deleted\";");
                using (ConnectionFactory connectionFactory = new ConnectionFactory(connectorConfig.destDBConfig.syncDefaultDatabaseUrl))
                {
                    try
                    {
                        connectionFactory.DbConnection.ExecuteScalarAsync <int>(sb.ToString()).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error:{0}", ex.Message);
                        return(ex.Message);
                    }
                }

                //Assign value to destination object
                entity.dest_object_name = (connectorConfig.dedupSourceType == SourceType.Remove_Duplicates_from_a_Single_Table ? connectorConfig.sourceObjectName
                    : (connectorConfig.dbConfig_compare.table_type == SelectedTableType.Create_New_Table ? connectorConfig.dbConfig_compare.new_table_name : connectorConfig.dbConfig_compare.object_name));

                connectorConfig.destDBConfig.syncDefaultDatabaseUrl = (connectorConfig.dedupSourceType == SourceType.Remove_Duplicates_from_a_Single_Table ? connectorConfig.dbConfig.syncDefaultDatabaseUrl
                    : connectorConfig.dbConfig_compare.syncDefaultDatabaseUrl);

                connectorConfig.destDBConfig.dataSource = (connectorConfig.dedupSourceType == SourceType.Remove_Duplicates_from_a_Single_Table ? connectorConfig.dbConfig.dataSource
                : connectorConfig.dbConfig_compare.dataSource);

                connectorConfig.destDBConfig.databaseType = (connectorConfig.dedupSourceType == SourceType.Remove_Duplicates_from_a_Single_Table ? connectorConfig.dbConfig.databaseType
               : connectorConfig.dbConfig_compare.databaseType);

                entity.dest_config_json = JsonConvert.SerializeObject(connectorConfig.destDBConfig);

                entity.dest_schema = (connectorConfig.dedupSourceType == SourceType.Remove_Duplicates_from_a_Single_Table ? connectorConfig.dbSchema
                    : connectorConfig.dbConfig_compare.db_schema);

                entity.sync_started_at      = null;
                entity.sync_ended_at        = null;
                entity.job_id               = "";
                entity.simulation_count     = -1;
                entity.sync_count           = null;
                entity.dedup_type           = DedupType.Full_Dedup;
                entity.sync_status          = null;
                entity.unique_records_count = 0;
                entity.sync_updated_count   = 0;

                entity.sync_ended_at    = null;
                entity.sync_started_at  = null;
                entity.last_sync_at     = null;
                entity.last_sync_status = null;

                //Delete destination table
                SyncRepository.RemovePGSyncTable(connectorConfig);
                _context.Entry(entity).State = EntityState.Modified;
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error:{0}", ex.Message);
                return(ex.Message);
            }
            return("success");
        }