Exemplo n.º 1
0
        private static void CreateTemplateFile(string syncJobPath)
        {
            if (string.IsNullOrWhiteSpace(syncJobPath) || File.Exists(syncJobPath))
            {
                Log.Error("Target file {0} invalid or already exists, won't replace.", syncJobPath);
                Usage();
                Environment.ExitCode = 3;
                return;
            }
            var syncJob = new SyncJob
            {
                SourceDbConnection = new SqlConnectionStringBuilder
                {
                    DataSource     = "sourceserver",
                    InitialCatalog = "sourcedatabase",
                    UserID         = "userid",
                    Password       = "******"
                }.ToString(),
                TargetDbConnection = new SqlConnectionStringBuilder
                {
                    DataSource     = "targetserver",
                    InitialCatalog = "targetdatabase",
                    UserID         = "userid",
                    Password       = "******"
                }.ToString(),
                Tables = new List <string> {
                    "dbo.Table1", "dbo.Table2"
                },
                BatchSize = 1000
            };

            Log.Info("Saving file to {0}", syncJobPath);
            syncJob.Save(syncJobPath);
            Log.Success("File saved");
        }
Exemplo n.º 2
0
 private static void CreateTemplateFile(string syncJobPath)
 {
     if (string.IsNullOrWhiteSpace(syncJobPath) || File.Exists(syncJobPath))
     {
         Log.Error("Target file {0} invalid or already exists, won't replace.", syncJobPath);
         Usage();
         Environment.ExitCode = 3;
         return;
     }
     var syncJob = new SyncJob
     {
         SourceDbConnection = new SqlConnectionStringBuilder
         {
             DataSource = "sourceserver",
             InitialCatalog = "sourcedatabase",
             UserID = "userid",
             Password = "******"
         }.ToString(),
         TargetDbConnection = new SqlConnectionStringBuilder
         {
             DataSource = "targetserver",
             InitialCatalog = "targetdatabase",
             UserID = "userid",
             Password = "******"
         }.ToString(),
         Tables = new List<string>{ "dbo.Table1", "dbo.Table2"},
         BatchSize = 1000
     };
     Log.Info("Saving file to {0}", syncJobPath);
     syncJob.Save(syncJobPath);
     Log.Success("File saved");
 }
Exemplo n.º 3
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();
                    }
                    );
            }
        }
Exemplo n.º 4
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();
                }
                    );
            }
        }
Exemplo n.º 5
0
        public static void Run(string syncJobPath, bool globalChangeTracking = false)
        {
            SyncJob syncJob;

            if (!SyncJob.TryLoad(syncJobPath, out syncJob) || syncJob == null)
            {
                Log.Error("Failed to load SyncJob file {0}", syncJobPath);
                Program.Usage();
                Environment.Exit(1);
            }
            ProcessSync(syncJob, globalChangeTracking);
        }
Exemplo n.º 6
0
 public static bool TryLoad(string jobPath, out SyncJob syncJob)
 {
     syncJob = null;
     HRONObjectParseError[] errors;
     return(
         File.Exists(jobPath) &&
         HRONSerializer.TryParseObject(
             0,
             File.ReadAllText(jobPath, Encoding.UTF8).ReadLines(),
             out syncJob,
             out errors
             )
         );
 }
Exemplo n.º 7
0
 public static bool TryLoad(string jobPath, out SyncJob syncJob)
 {
     syncJob = null;
     HRONObjectParseError[] errors;
     return (
         File.Exists(jobPath) &&
         HRONSerializer.TryParseObject(
             0,
             File.ReadAllText(jobPath, Encoding.UTF8).ReadLines(),
             out syncJob,
             out errors
             )
         );
 }