public override void ConnectToDatabase (string connectionString, string migratorName, bool validateTables)
        {
            m_connectionString = connectionString;
            MySqlConnection c = new MySqlConnection (connectionString);
            int subStrA = connectionString.IndexOf ("Database=", StringComparison.Ordinal);
            int subStrB = connectionString.IndexOf (";", subStrA, StringComparison.Ordinal);
            string noDatabaseConnector = m_connectionString.Substring (0, subStrA) +
                                         m_connectionString.Substring (subStrB + 1);

        retry:
            try {
                ExecuteNonQuery (noDatabaseConnector, "create schema IF NOT EXISTS " + c.Database,
                                new Dictionary<string, object> (), false);
            } catch {
                MainConsole.Instance.Error (
                    "[MySQL]: We cannot connect to the MySQL instance you have provided. Please make sure it is online, and then press enter to try again.");
                try {
                    Console.Read ();
                } catch {
                }
                goto retry;
            }
            c.Close ();

            var migrationManager = new MigrationManager(this, migratorName, validateTables);
            try {
                migrationManager.DetermineOperation ();
                migrationManager.ExecuteOperation ();
            } catch {
                MainConsole.Instance.Error ("[MySQL]: Unable to determine migration requirements.");

            }
        }
        public void MigrationTestsTests()
        {
            //IMPORTANT NOTIFICATION
            //Till I figure out a way, please delete the .db file or drop tables clean before running this

            //Switch the comments to test one technology or another
            var technology = DataManagerTechnology.SQLite;
            //var technology = DataManagerTechnology.MySql;

            var mysqlconnectionstring = "Data Source=localhost;Database=WhiteCoretest;User ID=WhiteCoretest;Password=test;";
            var sqliteconnectionstring = string.Format("URI=file:{0},version=3", dbFileName);
            string connectionString = (technology==DataManagerTechnology.SQLite)?sqliteconnectionstring:mysqlconnectionstring;

            CreateEmptyDatabase();
            DataSessionProvider sessionProvider = new DataSessionProvider(technology, connectionString);
            IDataConnector genericData = ((technology==DataManagerTechnology.SQLite)? (IDataConnector) new SQLiteLoader():new MySQLDataLoader());

            genericData.ConnectToDatabase(connectionString);

            var migrators = new List<Migrator>();
            var testMigrator0 = new TestMigrator();
            migrators.Add(testMigrator0);

            var migrationManager = new MigrationManager(sessionProvider, genericData, migrators);
            Assert.AreEqual(testMigrator0.Version, migrationManager.LatestVersion, "Latest version is correct");
            Assert.IsNull(migrationManager.GetDescriptionOfCurrentOperation(),"Description should be null before deciding what to do.");
            migrationManager.DetermineOperation();
            var operationDescription = migrationManager.GetDescriptionOfCurrentOperation();
            Assert.AreEqual(MigrationOperationTypes.CreateDefaultAndUpgradeToTarget, operationDescription.OperationType, "Operation type is correct.");
            Assert.AreEqual(testMigrator0.Version, operationDescription.CurrentVersion, "Current version is correct");
            //There will be no migration because there is only one migrator which will provide the default
            Assert.IsNull(operationDescription.StartVersion, "Start migration version is correct");
            Assert.IsNull(operationDescription.EndVersion, "End migration version is correct");
            try
            {
                migrationManager.ExecuteOperation();
                Assert.AreEqual(testMigrator0.Version, genericData.GetWhiteCoreVersion(), "Version of settings is updated");
            }
            catch(MigrationOperationException)
            {
                Assert.Fail("Something failed during execution we weren't expecting.");
            }
            bool valid = migrationManager.ValidateVersion(migrationManager.LatestVersion);
            Assert.AreEqual(true,valid,"Database is a valid version");

            migrationManager.DetermineOperation();
            var operationDescription2 = migrationManager.GetDescriptionOfCurrentOperation();
            Assert.AreEqual(MigrationOperationTypes.DoNothing, operationDescription2.OperationType, "Operation type is correct.");
            Assert.AreEqual(testMigrator0.Version, operationDescription2.CurrentVersion, "Current version is correct");
            Assert.IsNull(operationDescription2.StartVersion, "Start migration version is correct");
            Assert.IsNull(operationDescription2.EndVersion, "End migration version is correct");
            migrationManager.ExecuteOperation();

            genericData.CloseDatabase();
        }
        public override void ConnectToDatabase(string connectionString, string migratorName, bool validateTables)
        {
        
            // connection string in the format...
            // Data Source=File:<db_filename>
            m_connectionString = connectionString;
            string[] s1 = m_connectionString.Split(new[] {"Data Source=", ";", ","}, StringSplitOptions.RemoveEmptyEntries);

            // first element should be file:<db_filename>
            s1[0] = s1[0].Remove(0, 5);
            m_fileName = s1 [0];

            // some sanity checks
            string filePath = Path.GetDirectoryName (s1[0]);
            string fileName = Path.GetFileName (s1[0]);

            if (filePath == "") //Only add this if we aren't an absolute path already eg file:data.db
            {
                m_connectionString = string.Format ("Data Source=file://{0}", Path.Combine (m_defaultDataPath, fileName));
                filePath = m_defaultDataPath;
                m_fileName = Path.Combine (m_defaultDataPath, fileName);
            }

            if (!Directory.Exists (filePath))
                Directory.CreateDirectory (filePath);           // directory does not exist!
            if (!File.Exists(m_fileName))
                File.Create(m_fileName).Dispose();              // database file does not exist, create an empty one to use     

            SqliteConnection connection = new SqliteConnection(m_connectionString);

            try {
                connection.Open ();

                var migrationManager = new MigrationManager (this, migratorName, validateTables);
                migrationManager.DetermineOperation ();
                migrationManager.ExecuteOperation ();
            } catch {
                MainConsole.Instance.Warn ("[Sqlite]: Unable to connect to database ("+m_connectionString+")");
            }
            connection.Close();
        }
        public override void ConnectToDatabase(string connectionString, string migratorName, bool validateTables)
        {
            _connectionString = connectionString;
            string[] s1 = _connectionString.Split(new[] {"Data Source=", ","}, StringSplitOptions.RemoveEmptyEntries);

            s1[0] = s1[0].Remove(0, 7);

            _fileName = Path.GetFileName(s1[0]);
            if (_fileName == s1[0]) //Only add this if we arn't an absolute path already
                _connectionString = string.Format("Data Source=file://{0}", Path.Combine(Util.BasePathCombine(""), _fileName));

            SqliteConnection connection = new SqliteConnection(_connectionString);
            connection.Open();
            var migrationManager = new MigrationManager(this, migratorName, validateTables);
            migrationManager.DetermineOperation();
            migrationManager.ExecuteOperation();
            connection.Close();
        }
        public override void ConnectToDatabase(string connectionString, string migratorName, bool validateTables)
        {
            // connection string in the format...
            // Data Source=File:<db_filename>
            _connectionString = connectionString;
            string[] s1 = _connectionString.Split(new[] {"Data Source=", ";", ","}, StringSplitOptions.RemoveEmptyEntries);

            // first element should be file:<db_filename>
            s1[0] = s1[0].Remove(0, 5);
            _fileName = s1 [0];

            // some sanity checks
            string filePath = Path.GetDirectoryName (s1[0]);
            string fileName = Path.GetFileName (s1[0]);

            if (filePath == "") //Only add this if we arn't an absolute path already
            {
                filePath = Util.BasePathCombine ("");
                _connectionString = string.Format ("Data Source=file://{0}", Path.Combine (Util.BasePathCombine (""), fileName));
            }

            if (!Directory.Exists (filePath))
                Directory.CreateDirectory (filePath);           // directory does not exist!
            if (!File.Exists(_fileName))
                File.Create(_fileName).Dispose();               // database file does not exist, create an empty one to use

            SqliteConnection connection = new SqliteConnection(_connectionString);

            connection.Open ();
            var migrationManager = new MigrationManager(this, migratorName, validateTables);
            migrationManager.DetermineOperation();
            migrationManager.ExecuteOperation();
            connection.Close();
        }