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 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();
        }