Ejemplo n.º 1
0
        public async Task <bool> Sync(SynchronizationSet syncSet, Table table, TableSchema tableSchema)
        {
            _logger.LogInformation("{TableName} - sync started", table.Name);

            _syncSet                 = syncSet;
            _table                   = table;
            _tableSchema             = tableSchema;
            _sourceQueryFactory      = _queryFactory.GetSource(syncSet.Name);
            _destinationQueryFactory = _queryFactory.GetDestination(syncSet.Name);
            _primaryKeys             = _tableSchema.Columns.Where(x => x.IsPrimaryKey).ToList();
            _identityColumns         = _tableSchema.Columns.Where(x => x.IsIdentity).ToList();
            _sourceQuery             = BuildSourceQuery(BuildMainQuery(_sourceQueryFactory));
            _destinationQuery        = BuildMainQuery(_destinationQueryFactory);

            ThreadPool.QueueUserWorkItem(InsertWorker);
            ThreadPool.QueueUserWorkItem(UpdateWorker);

            Merge();
            FinalizeInsertDestination();
            FinalizeUpdateDestination();

            _cancellationToken.Cancel();
            _logger.LogInformation("{TableName} - sync completed", table.Name);
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> Compare(SynchronizationSet syncSet)
        {
            _syncSet          = syncSet;
            _sourceQuery      = _queryFactory.GetSource(syncSet.Name);
            _destinationQuery = _queryFactory.GetDestination(syncSet.Name);

            return(Compare(syncSet.SourceDatabase.Tables, syncSet.DestinationDatabase.Tables));
        }
Ejemplo n.º 3
0
        public async Task <bool> Load(SynchronizationSet syncSet)
        {
            _logger.LogInformation("Load {SyncSetName} schema", syncSet.Name);

            _syncSet          = syncSet;
            _sourceQuery      = _queryFactory.GetSource(syncSet.Name);
            _destinationQuery = _queryFactory.GetDestination(syncSet.Name);

            List <TableSchema> sourceTables      = (await GetTables(_sourceQuery)).Where(x => syncSet.Tables.Any(table => table.Name == x.Name)).ToList();
            List <TableSchema> destinationTables = (await GetTables(_destinationQuery)).Where(x => syncSet.Tables.Any(table => table.Name == x.Name)).ToList();

            foreach (var table in sourceTables)
            {
                _logger.LogDebug("Load source table {TableName} schema", table.Name);

                table.Columns = (await GetTableColumns(_sourceQuery, table.ObjectId)).ToList();
            }

            foreach (var table in destinationTables)
            {
                _logger.LogDebug("Load destination table {TableName} schema", table.Name);

                table.Columns = (await GetTableColumns(_destinationQuery, table.ObjectId)).ToList();
            }

            syncSet.SourceDatabase = new DatabaseSchema()
            {
                Tables = sourceTables
            };
            syncSet.DestinationDatabase = new DatabaseSchema()
            {
                Tables = destinationTables
            };

            _logger.LogInformation("Loaded {SyncSetName} schema", syncSet.Name);
            return(true);
        }