Example #1
0
        static int Main(string[] args)
        {
            MigrationOptions options = null;

            try
            {
                if (args == null || args.Length < 2)
                {
                    Console.WriteLine("Usage:");
                    Console.WriteLine("SqlDatabaseCopy.exe <sourceConnectionString> <targetConnectionString> [-SchemaOnly | -DataOnly] [-NoLog]");
                    return(-1);
                }

                options = GetOptions(args);
                var handler = new MigrationHandler(options);
                handler.Process();
                return(HandleErrors(handler));
            }
            catch (Exception ex)
            {
                ConsoleHelper.WriteError(ex);
                options?.Log?.WriteLine(ex.ToString());
                return(-1);
            }
            finally
            {
                options?.Log?.Dispose();
            }
        }
Example #2
0
        public static void Process(MigrationOptions options, IEnumerable <MigrationItem> items, int totalCount, WorkerAction action, bool noRetry = false)
        {
            var worker = new Worker(options, action);

            worker.noRetry = noRetry;
            worker.Process(items, totalCount);
        }
Example #3
0
 private Worker(MigrationOptions options, WorkerAction action)
 {
     this.threads = Enumerable.Range(0, options.MaxThreads).Select(_ => new Thread(DoWork)
     {
         IsBackground = true
     }).ToArray();
     this.action  = action;
     this.options = options;
 }
        public static MigrationOptions GetFromAppConfig()
        {
            var options = new MigrationOptions();

            options.ScripterOptions = SqlScripterOptions.GetFromAppConfig();
            options.MaxThreads      = Convert.ToInt32(ConfigurationManager.AppSettings["MaxThreads"]);
            options.MaxErrors       = Convert.ToInt32(ConfigurationManager.AppSettings["MaxErrors"]);
            options.MaxAttempts     = Convert.ToInt32(ConfigurationManager.AppSettings["MaxAttempts"]);
            options.MaxAttempts     = Convert.ToInt32(ConfigurationManager.AppSettings["MaxAttempts"]);
            options.LogSql          = Convert.ToBoolean(ConfigurationManager.AppSettings["LogSql"]);

            return(options);
        }
Example #5
0
        static MigrationOptions GetOptions(string[] args)
        {
            bool noLog   = false;
            var  options = MigrationOptions.GetFromAppConfig();

            options.SourceConnectionString = args[0];
            options.TargetConnectionString = args[1];

            for (int i = 2; i < args.Length; i++)
            {
                switch (args[i].ToLower().Trim())
                {
                case "-schemaonly":
                    options.SchemaOnly = true;
                    break;

                case "-dataonly":
                    options.DataOnly = true;
                    break;

                case "-nolog":
                    noLog = true;
                    break;

                default:
                    throw new InvalidOperationException($"Unknown parameter: {args[i]}");
                }
            }

            if (options.SchemaOnly && options.DataOnly)
            {
                throw new InvalidOperationException("It's not allowed to use SchemaOnly and DataOnly options same time");
            }

            if (noLog)
            {
                options.Log = TextWriter.Null;
            }
            else
            {
                Directory.CreateDirectory("log");
                options.Log = TextWriter.Synchronized(new StreamWriter($"log\\SqlDatabaseCopy_{DateTime.Now.ToString("yyyyMMdd_HHmmsstt")}.log"));
            }

            return(options);
        }
 public MigrationHandler(MigrationOptions options)
 {
     this.options = options;
 }
Example #7
0
 public static void Process(MigrationOptions options, IEnumerable <MigrationItem> items, WorkerAction action, bool noRetry = false)
 {
     Process(options, items, items.Count(), action, noRetry);
 }