public static bool TestDBConnection(DBConnectionDetails DBConnection, LogHandler Logger) { if (Logger.DebugMode) { Logger.LogTrace("Enter TestDBConnection Method"); } if (DBConnection.DBType == SupportedDatabases.PostgreSQL) { try { DatabaseUtils.Postgres.ConnectToPostGRES(DBConnection); if (Logger.DebugMode) { Logger.LogDebug("Successful Connection to database"); } return(true); } catch (Exception ex) { Logger.LogWarning("Unable to connect to database: " + ex.Message); return(false); } } return(true); }
public UIMainScreen() { //Create the logger InitializeComponent(); Logger = new ODL.Common.LogHandler(); #if DEBUG Logger.DebugMode = true; #endif Logger.LogTableUpdated += RefreshLogGrid; Logger.LogInformation("Welcome to OpenDataLoader."); if (Logger.DebugMode) { Logger.LogDebug("Created Logger"); } //Populate dropdown for dbtype if (Logger.DebugMode) { Logger.LogTrace("Creating Dropdown Selections"); } List <KeyValuePair <String, String> > lstDBTypes = new List <KeyValuePair <String, String> >(); Array DBtypes = Enum.GetValues(typeof(ODL.Common.SupportedDatabases)); foreach (ODL.Common.SupportedDatabases _entry in DBtypes) { lstDBTypes.Add(new KeyValuePair <String, String>(_entry.ToString(), ((int)_entry).ToString())); } cmbDatabaseType.DisplayMember = "Key"; cmbDatabaseType.ValueMember = "Value"; cmbDatabaseType.DataSource = lstDBTypes; //Populate the dropdowns for the File Source and File Type cmbFileSource.DisplayMember = "Key"; cmbFileSource.ValueMember = "Value"; cmbFileSource.DataSource = ConvolutedWayToMakeNestedDropdowns(); if (Logger.DebugMode) { Logger.LogTrace("Loading DBConfig from json (if available)"); } //Load config from json ConnectionDetails = ODL.Common.DatabaseUtils.Load(Logger); txtDBUsername.Text = ConnectionDetails.DBUsername; txtDBPassword.Text = ConnectionDetails.DBPassword; txtDBServer.Text = ConnectionDetails.DBServer; txtDBCatalog.Text = ConnectionDetails.DBCatalog; txtDBPort.Text = ConnectionDetails.DBPort.ToString(); cmbDatabaseType.Text = ConnectionDetails.DBType.ToString(); }