public bool PerformMigration() { bool migrationSuccess = false; MySqlConnection = MySqlDbConnection.getInstance(); List <HockeyPlayer> hockeyPlayers = new List <HockeyPlayer>(); hockeyPlayers = MySqlConnection.Read(); Console.WriteLine($"Read {hockeyPlayers.Count} records out of the MySQL database."); MySqlConnection.ResetConnection(); MongoConnection = MongoDbConnection.getInstance(); int counter = 0; foreach (var player in hockeyPlayers) { bool insertSuccess = MongoConnection.Insert(player); if (insertSuccess == false) { throw new MigrationMySql2MongoDbException("Failed to insert player into MongoDB."); } else { counter++; } } Console.WriteLine($"Wrote {counter} records to the Monday database."); return(migrationSuccess); }
// ===================================================== public static DbConnection getInstance(string uid = null, string password = null) // ===================================================== { if (_dbConnection == null) { if (Server == DbConnection.Server.MySql) { _dbConnection = MySqlDbConnection.getInstance(); } else if (Server == DbConnection.Server.MongoDb) { _dbConnection = MongoDbConnection.getInstance(); } else { throw new HammerMainException("Error: DB Server unavailable."); } } return(_dbConnection); }