AskYN() public static method

public static AskYN ( string question ) : bool
question string
return bool
Ejemplo n.º 1
0
        public override int Run(string[] args)
        {
            _logger = new Logger(Verbose);

            if (!Overwrite && Directory.Exists(ScriptDir))
            {
                if (!ConsoleQuestion.AskYN($"{ScriptDir} already exists - do you want to replace it"))
                {
                    return(1);
                }
            }

            var scriptCommand = new ScriptCommand {
                ConnectionString = ConnectionString,
                DbName           = DbName,
                Pass             = Pass,
                ScriptDir        = ScriptDir,
                Server           = Server,
                User             = User,
                Logger           = _logger,
                Overwrite        = Overwrite
            };

            var filteredTypes   = HandleFilteredTypes();
            var namesAndSchemas = HandleDataTables(DataTables);

            try {
                scriptCommand.Execute(namesAndSchemas, DataTablesPattern, DataTablesExcludePattern, TableHint, filteredTypes);
            } catch (Exception ex) {
                throw new ConsoleHelpAsException(ex.ToString());
            }
            return(0);
        }
Ejemplo n.º 2
0
        public override int Run(string[] remainingArguments)
        {
            if (!string.IsNullOrEmpty(_outDiff))
            {
                Console.WriteLine();
                if (!_overwrite && File.Exists(_outDiff))
                {
                    var question = string.Format("{0} already exists - do you want to replace it", _outDiff);
                    if (!ConsoleQuestion.AskYN(question))
                    {
                        return(1);
                    }
                }
            }

            var compareCommand = new CompareCommand {
                Source  = _source,
                Target  = _target,
                Verbose = _verbose,
                OutDiff = _outDiff
            };

            try {
                return(compareCommand.Execute() ? 1 : 0);
            } catch (Exception ex) {
                throw new ConsoleHelpAsException(ex.Message);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo 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.");
                Console.WriteLine(diff.SummarizeChanges(_verbose));
                if (!string.IsNullOrEmpty(_outDiff))
                {
                    Console.WriteLine();
                    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);
        }
Ejemplo n.º 5
0
        public override int Run(string[] args)
        {
            var db = CreateDatabase();

            if (!Overwrite && Directory.Exists(db.Dir))
            {
                if (!ConsoleQuestion.AskYN(string.Format("{0} already exists - do you want to replace it", db.Dir)))
                {
                    return(1);
                }
            }
            Log(TraceLevel.Verbose, "Loading database schema...");
            db.Load();
            Log(TraceLevel.Verbose, "Database schema loaded.");

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

            db.ScriptToDir(TableHint, Log);

            Log(TraceLevel.Info, Environment.NewLine + "Snapshot successfully created at " + db.Dir);
            var routinesWithWarnings = db.Routines.Select(r => new {
                Routine  = r,
                Warnings = r.Warnings().ToList()
            }).Where(r => r.Warnings.Any()).ToList();

            if (routinesWithWarnings.Any())
            {
                Log(TraceLevel.Info, "With the following warnings:");
                foreach (
                    var warning in
                    routinesWithWarnings.SelectMany(
                        r =>
                        r.Warnings.Select(
                            w => string.Format("- {0} [{1}].[{2}]: {3}", r.Routine.RoutineType, r.Routine.Owner, r.Routine.Name, w))))
                {
                    Log(TraceLevel.Warning, warning);
                }
            }
            return(0);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
            var routinesWithWarnings = db.Routines.Select(r => new {
                Routine  = r,
                Warnings = r.Warnings().ToList()
            }).Where(r => r.Warnings.Any()).ToList();

            if (routinesWithWarnings.Any())
            {
                Console.WriteLine("With the following warnings:");
                foreach (var warning in routinesWithWarnings.SelectMany(r => r.Warnings.Select(w => string.Format("- {0} [{1}].[{2}]: {3}", r.Routine.RoutineType, r.Routine.Owner, r.Routine.Name, w))))
                {
                    Console.WriteLine(warning);
                }
            }
            return(0);
        }
Ejemplo n.º 8
0
        public override int Run(string[] remainingArguments)
        {
            var db = CreateDatabase();

            if (!Directory.Exists(db.Dir))
            {
                Log(TraceLevel.Error, string.Format("Snapshot dir {0} does not exist.", db.Dir));
                return(1);
            }

            if (!Overwrite)
            {
                Log(TraceLevel.Verbose, "Checking if database already exists...");
                if (DBHelper.DbExists(db.Connection))
                {
                    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, Log);
                Log(TraceLevel.Info, Environment.NewLine + "Database created successfully.");
            } catch (BatchSqlFileException ex) {
                Log(TraceLevel.Info, Environment.NewLine + "Create completed with the following errors:");
                foreach (var e in ex.Exceptions)
                {
                    Log(TraceLevel.Info, string.Format("- {0} (Line {1}):", e.FileName.Replace("/", "\\"), e.LineNumber));
                    Log(TraceLevel.Error, string.Format(" {0}", e.Message));
                }
                return(-1);
            } catch (SqlFileException ex) {
                Log(TraceLevel.Info, Environment.NewLine + string.Format(@"An unexpected SQL error occurred while executing scripts, and the process wasn't completed.
{0} (Line {1}):", ex.FileName.Replace("/", "\\"), ex.LineNumber));
                Log(TraceLevel.Error, ex.Message);
                return(-1);
            }

            return(0);
        }