Esempio n. 1
0
        private static void ProcessSync(SyncJob syncJob, bool globalChangeTracking)
        {
            using (SqlConnection
                   sourceConn = new SqlConnection(syncJob.SourceDbConnection),
                   targetConn = new SqlConnection(syncJob.TargetDbConnection)
                   )
            {
                Log.Info(
                    "Connecting to source database {0}.{1}",
                    sourceConn.DataSource,
                    sourceConn.Database
                    );
                sourceConn.Open();
                Log.Success("Connected {0}", sourceConn.ClientConnectionId);

                Log.Info(
                    "Connecting to target database {0}.{1}",
                    targetConn.DataSource,
                    targetConn.Database
                    );
                targetConn.Open();
                Log.Success("Connected {0}", targetConn.ClientConnectionId);

                Log.Info("Fetching table schemas");
                var schemaStopWatch = Stopwatch.StartNew();
                var tableSchemas    = (
                    syncJob
                    .Tables ?? new List <string>()
                    )
                                      .Select(
                    table => TableSchema.LoadSchema(sourceConn, targetConn, table, syncJob.BatchSize, globalChangeTracking)
                    ).ToArray();
                schemaStopWatch.Stop();
                Log.Success("Found {0} tables, duration {1}", tableSchemas.Length, schemaStopWatch.Elapsed);

                Array.ForEach(
                    tableSchemas,
                    tableSchema =>
                {
                    Log.Info("Begin {0}", tableSchema.TableName);
                    var syncStopWatch = Stopwatch.StartNew();
                    if (tableSchema.SourceVersion.Equals(tableSchema.TargetVersion))
                    {
                        Log.HighLight("Allready up to date");
                    }
                    else
                    {
                        SyncTable(targetConn, tableSchema, sourceConn);
                    }
                    syncStopWatch.Stop();
                    Log.Info("End {0}, duration {1}", tableSchema.TableName, syncStopWatch.Elapsed);
                    tableSchema.PersistsSourceTargetVersionState();
                }
                    );
            }
        }