Example #1
0
        public void RevertToSnapshot()
        {
            Snapshot now = GetSnapshot();

            List <string> changedTables = _latestSnapshot
                                          .Where(x => x.Value != now[x.Key])
                                          .Select(x => x.Key)
                                          .ToList();

            if (!changedTables.Any())
            {
                return;
            }

            DataWiper dataWiper = new DataWiper(_connectionString);

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();

                SqlConstraints.DisableAllConstraints(connection);

                foreach (string tableName in changedTables)
                {
                    dataWiper.Execute(connection, tableName);
                }

                DataToSql toSql = new DataToSql(_connectionString, _directory, changedTables);
                toSql.Execute(connection);

                SqlConstraints.EnableAllConstraints(connection);
            }

            TakeSnapshot();
        }
Example #2
0
        private static bool ExecuteInput(ConsoleKeyInfo input, string connectionString, string directory)
        {
            System.Console.ForegroundColor = ConsoleColor.Cyan;
            System.Console.WriteLine();

            switch (input.KeyChar)
            {
            case '1':
                System.Console.WriteLine("Storing database \n   {0} \nTo directory \n  {1}", connectionString, directory);

                DataToFile dataToFile = new DataToFile(connectionString, directory);
                dataToFile.Execute();
                break;

            case '2':
                System.Console.WriteLine("Wiping database \n    {0}", connectionString);
                System.Console.ForegroundColor = ConsoleColor.Green;
                System.Console.WriteLine("Are you sure you want to continue? Y/N");
                ConsoleKeyInfo confirmInfo = System.Console.ReadKey();
                System.Console.WriteLine();
                System.Console.ForegroundColor = ConsoleColor.Cyan;

                if (confirmInfo.KeyChar == 'Y' || confirmInfo.KeyChar == 'y')
                {
                    DataWiper dataWiper = new DataWiper(connectionString);
                    dataWiper.Execute();
                }
                else
                {
                    System.Console.ForegroundColor = ConsoleColor.Red;
                    System.Console.WriteLine("Aborted");
                }

                break;

            case '3':
                System.Console.WriteLine("Deploying data to database \n {0} From \n {1}", connectionString, directory);

                DataToSql dataToSql = new DataToSql(connectionString, directory);
                dataToSql.Execute();
                break;

            case '4':
                return(false);

            default:
                System.Console.ForegroundColor = ConsoleColor.Red;
                System.Console.WriteLine("Incorrect input");
                break;
            }

            return(true);
        }