Example #1
0
        public static DBConnectionDetails Load(LogHandler Logger)
        {
            if (Logger.DebugMode)
            {
                Logger.LogTrace("Enter Load DBConnection Method");
            }
            DBConnectionDetails _ReturnObject = null;

            if (File.Exists("./DBConnectionConfig.json"))
            {
                try
                {
                    String _LoadedFile = Encoding.UTF8.GetString(File.ReadAllBytes("./DBConnectionConfig.json"));
                    _ReturnObject            = Newtonsoft.Json.JsonConvert.DeserializeObject <DBConnectionDetails>(_LoadedFile);
                    _ReturnObject.DBPassword = Decrypt(_ReturnObject.DBPassword, _ReturnObject.DBServer, _ReturnObject.DBUsername);
                    Logger.LogInformation("Found and loaded saved Database Connection Settings file.");
                }
                catch (Exception ex)
                {
                    Logger.LogError("Found but could not load saved Database Connection Settings file." + ex.Message);
                    _ReturnObject = new DBConnectionDetails();
                }
            }
            else
            {
                _ReturnObject = new DBConnectionDetails();
            }
            return(_ReturnObject);
        }
Example #2
0
 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);
 }
Example #3
0
 public static Npgsql.NpgsqlConnection ConnectToPostGRES(DBConnectionDetails dbConnectionInfo)
 {
     Npgsql.NpgsqlConnectionStringBuilder _connString = new Npgsql.NpgsqlConnectionStringBuilder();
     _connString.Username = dbConnectionInfo.DBUsername;
     _connString.Password = dbConnectionInfo.DBPassword;
     _connString.Database = dbConnectionInfo.DBCatalog;
     _connString.Host     = dbConnectionInfo.DBServer;
     _connString.Port     = dbConnectionInfo.DBPort;
     Npgsql.NpgsqlConnection _dbConnection = new Npgsql.NpgsqlConnection(_connString.ConnectionString);
     _dbConnection.Open();
     return(_dbConnection);
 }
Example #4
0
        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();
        }
Example #5
0
 public static void Save(DBConnectionDetails DBConnection, LogHandler Logger)
 {
     if (Logger.DebugMode)
     {
         Logger.LogTrace("Enter Save DBConnection Method");
     }
     try
     {
         DBConnection.DBPassword = Encrypt(DBConnection.DBPassword, DBConnection.DBServer, DBConnection.DBUsername);
         String _Serialized = Newtonsoft.Json.JsonConvert.SerializeObject(DBConnection, Newtonsoft.Json.Formatting.Indented);
         File.WriteAllText("./DBConnectionConfig.json", _Serialized);
     }
     catch (Exception ex)
     {
         Logger.LogError("Could not save Database Connection Settings file. " + ex.Message);
     }
 }