Esempio n. 1
0
        public override int Run(string[] args)
        {
            Database db = CreateDatabase();

            db.Load();

            if (!string.IsNullOrEmpty(DataTables))
            {
                HandleDataTables(db, DataTables);
            }
            if (!string.IsNullOrEmpty(DataTablesPattern))
            {
                List <Table> tables = db.FindTablesRegEx(DataTablesPattern);
                foreach (Table t in tables.Where(t => !db.DataTables.Contains(t)))
                {
                    db.DataTables.Add(t);
                }
            }

            if (!Overwrite && Directory.Exists(db.Dir))
            {
                if (!ConsoleQuestion.AskYN(string.Format("{0} already exists - do you want to replace it", db.Dir)))
                {
                    return(1);
                }
            }

            db.ScriptToDir(TableHint);

            Console.WriteLine("Snapshot successfully created at " + db.Dir);
            return(0);
        }
Esempio n. 2
0
        private static int Main(string[] args)
        {
            try {
                return(ConsoleCommandDispatcher.DispatchCommand(
                           GetCommands(), args, Console.Out));
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
#if DEBUG
                if (Debugger.IsAttached)
                {
                    ConsoleQuestion.WaitForKeyPress();
                }
#endif
                return(-1);
            }
        }
Esempio n. 3
0
        public override int Run(string[] remainingArguments)
        {
            Database db = CreateDatabase();

            if (!Directory.Exists(db.Dir))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Snapshot dir {0} does not exist.", db.Dir);
                Console.ForegroundColor = ConsoleColor.White;
                return(1);
            }

            if (DBHelper.DbExists(db.Connection) && !Overwrite)
            {
                if (!ConsoleQuestion.AskYN(string.Format("{0} {1} already exists - do you want to drop it", Server, DbName)))
                {
                    Console.WriteLine("Create command cancelled.");
                    return(1);
                }
                Overwrite = true;
            }

            try {
                db.CreateFromDir(Overwrite);
                Console.WriteLine();
                Console.WriteLine("Database created successfully.");
            } catch (BatchSqlFileException ex) {
                Console.WriteLine();
                Console.WriteLine(@"Create completed with the following errors:");
                Console.ForegroundColor = ConsoleColor.Red;
                foreach (SqlFileException e in ex.Exceptions)
                {
                    Console.WriteLine(@"{0} (Line {1}): {2}", e.FileName.Replace("/", "\\"), e.LineNumber, e.Message);
                }
                Console.ForegroundColor = ConsoleColor.White;
                return(-1);
            } catch (SqlFileException ex) {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write(@"An unexpected SQL error occurred while executing scripts, and the process wasn't completed.
{0} (Line {1}): {2}", ex.FileName.Replace("/", "\\"), ex.LineNumber, ex.Message);
                Console.ForegroundColor = ConsoleColor.White;
                return(-1);
            }

            return(0);
        }
Esempio n. 4
0
		public override int Run(string[] remainingArguments) {
			var sourceDb = new Database();
			var targetDb = new Database();
			sourceDb.Connection = _source;
			targetDb.Connection = _target;
			sourceDb.Load();
			targetDb.Load();
			DatabaseDiff diff = sourceDb.Compare(targetDb);
			if (diff.IsDiff) {
				Console.WriteLine("Databases are different.");
				if (!string.IsNullOrEmpty(_outDiff)) {
					if (!_overwrite && File.Exists(_outDiff)) {
						if (!ConsoleQuestion.AskYN(string.Format("{0} already exists - do you want to replace it", _outDiff))) {
							return 1;
						}
					}
					File.WriteAllText(_outDiff, diff.Script());
					Console.WriteLine("Script to make the databases identical has been created at {0}", Path.GetFullPath(_outDiff));
				}
				return 1;
			}
			Console.WriteLine("Databases are identical.");
			return 0;
		}