Beispiel #1
0
        static ConfigUtil()
        {
            try
            {
                var builder = new ConfigurationBuilder();
                builder.AddJsonFile("DbBackup.json", false, true);

                config  = builder.Build() as ConfigurationRoot;
                initial = true;
            }
            catch
            {
                initial = false;
            }
            if (!System.IO.File.Exists(configFile))
            {
                using (var sw = new System.IO.StreamWriter(configFile))
                {
                    DbBackupConfig c = new DbBackupConfig();

                    var json = JsonUtil.ToJsonString(c);
                    sw.Write(json);
                }
            }
            else
            {
                initial = true;
            }
        }
Beispiel #2
0
        public IActionResult ConnectTest(DbBackupConfig config)
        {
            ConfigUtil.Write(config);

            bool result = DbFactory.GetDbInstance().ConnectTest();

            return(Content(result.ToString()));
        }
Beispiel #3
0
        public static IDb GetDbInstance()
        {
            DbBackupConfig config = ConfigUtil.GetConfig();
            IDb            db     = null;

            if (config.dbtype == DbType.MySql.ToString())
            {
                db = new MySqlDb(config);
            }

            return(db);
        }
Beispiel #4
0
        public static DbBackupConfig GetConfig()
        {
            if (config == null || initial == false)
            {
                ReLoadConfig();
            }

            DbBackupConfig dbBackupConfig = new DbBackupConfig();

            foreach (var item in dbBackupConfig.GetType().GetProperties())
            {
                item.SetValue(dbBackupConfig, config[item.Name]);
            }

            return(dbBackupConfig);
        }
Beispiel #5
0
        public static bool Write(DbBackupConfig conf)
        {
            try
            {
                if (System.IO.File.Exists(configFile))
                {
                    using (var sw = new System.IO.StreamWriter(configFile))
                    {
                        var json = JsonUtil.ToJsonString(conf);
                        sw.Write(json);
                    }

                    ReLoadConfig();
                    var t = config["username"];
                    return(true);
                }
            }
            catch
            {
            }

            return(false);
        }
Beispiel #6
0
 public MySqlDb(DbBackupConfig _config)
 {
     config = _config;
 }