/// <summary> /// Validates database settings to make sure we can connect to it and its setup correctly. /// </summary> private bool ValidateDatabase() { DBConnection conn = new DBConnection(); Logger.Info("Attempting to connect to database on " + m_simulationSettings.DatabaseHostname + ":" + m_simulationSettings.DatabasePort, LoggerVerboseLevel.Normal); Task<bool> task = conn.ConnectAsync(m_simulationSettings.DatabaseHostname, m_simulationSettings.DatabasePort, m_simulationSettings.DatabaseName, m_simulationSettings.DatabaseUsername, m_simulationSettings.DatabasePassword); task.Wait(); if (task.Result == true) { Logger.Info("Connected successfully, database information is valid.", LoggerVerboseLevel.Normal); conn.DisconnectAsync().Wait(); return true; } else { Logger.Error("Failed to connect to database.", LoggerVerboseLevel.Normal); return false; } }
/// <summary> /// Sets up the database connection. /// </summary> /// <returns>Returns true if successful, else false.</returns> private async Task<bool> SetupDBConnection() { bool result = false; if (m_databaseConnection == null) { Logger.Info("Attempting to connect to database on " + m_settings.DatabaseHostname + ":" + m_settings.DatabasePort + " ...", LoggerVerboseLevel.High); m_databaseConnection = new DBConnection(); result = await m_databaseConnection.ConnectAsync(m_settings.DatabaseHostname, m_settings.DatabasePort, m_settings.DatabaseName, m_settings.DatabaseUsername, m_settings.DatabasePassword); } else { Logger.Error("Lost database connection, attempting to setup connection again ...", LoggerVerboseLevel.Normal); result = await m_databaseConnection.ReconnectAsync(); } if (result == false) { Logger.Error("Failed to connect to database on " + m_settings.DatabaseHostname + ":" + m_settings.DatabasePort, LoggerVerboseLevel.Normal); } else { Logger.Info("Successfully connected to database.", LoggerVerboseLevel.High); } return result; }