public static Config Config() { if (!ConfigFileExist()) { Log.log.Info("配置文件[" + configFilePath + "]不存在。创建新配置文件。"); CreateEmptyFile(); Log.log.Info("创建成功[" + configFilePath + "]。"); } Log.log.Info("开始读取配置文件[" + configFilePath + "]。"); string json = TextStreamClass.Read(configFilePath); Log.log.Debug("开始反序列化配置文件。"); JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings { Formatting = Formatting.Indented, StringEscapeHandling = StringEscapeHandling.EscapeNonAscii }; Config config = JsonConvert.DeserializeObject <Config>(json, jsonSerializerSettings); Log.log.Debug("完成反序列化配置文件。"); Log.log.Info("完成读取配置文件[" + configFilePath + "]。"); return(config); }
static void Main(string[] args) { try { Start(); var config = PrepareConfig(); om.Backup(config); End(); } catch (Exception ex) { try { Log.log.Fatal("Crashed."); Log.log.Fatal("Message:" + ex.Message); Log.log.Fatal("Data:" + ex.Data); Log.log.Fatal("TargetSite:" + ex.TargetSite); Log.log.Fatal("StackTrace:" + ex.StackTrace); Log.log.Fatal("Source:" + ex.Source); } catch (Exception subex) { TextStreamClass.Write(CRASH_FILE_NAME, "Crashed" + "\r\n"); var now = DateTime.Now; TextStreamClass.Append(CRASH_FILE_NAME, now.ToShortDateString() + " " + now.ToShortTimeString() + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "------inner------" + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "Message:" + ex.Message + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "Data:" + ex.Data); TextStreamClass.Append(CRASH_FILE_NAME, "TargetSite:" + ex.TargetSite + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "StackTrace:" + ex.StackTrace + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "Source:" + ex.Source + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "------outter------" + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "Message:" + subex.Message + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "Data:" + subex.Data + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "TargetSite:" + subex.TargetSite + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "StackTrace:" + subex.StackTrace + "\r\n"); TextStreamClass.Append(CRASH_FILE_NAME, "Source:" + subex.Source + "\r\n"); } } }
private static void CreateEmptyFile() { Config config = new Config { BackupOracles = new BackupOracle[] { new BackupOracle { OracleDatabase = "", OracleUsername = "", OraclePassword = "", FullBackup = true, BackupTables = null, BackupDirectoryPath = "" }, new BackupOracle { OracleDatabase = "", OracleUsername = "", OraclePassword = "", FullBackup = false, BackupTables = new BackupTable[] { new BackupTable { Tablename = "Table1", ClearTableAfterBackup = false }, new BackupTable { Tablename = "Table2", ClearTableAfterBackup = true } }, BackupDirectoryPath = "" } } }; string json = JsonConvert.SerializeObject(config, new JsonSerializerSettings { Formatting = Formatting.Indented, StringEscapeHandling = StringEscapeHandling.EscapeNonAscii }); TextStreamClass.Write(configFilePath, json); }