public void RemoveBackUpJobConfig(string id) { BackUpJobConfig backUpJobConfig = ReadBackUpJobConfig(id); if (backUpJobConfig != null) { string error = ""; EnvironmentInfo.SqliteHelper.UpdateData(out error, $"delete from sys_backup_job where Id='{id}';"); EnvironmentInfo.BackUpJobConfigs.Remove(backUpJobConfig); } }
private BackUpPolicy ConvertToPolicy(BackUpJobConfig backUpJobConfig) { BackUpPolicy policy = new BackUpPolicy(); string[] cronArry = backUpJobConfig.Cron.Split(' '); int second = int.Parse(cronArry[0]); int minute = int.Parse(cronArry[1]); int hour = int.Parse(cronArry[2]); policy.SelectedTime = DateTime.Now.Date.AddHours(hour).AddMinutes(minute).AddSeconds(second); string dayOfWeek = cronArry[5]; string[] week = dayOfWeek.Split(','); foreach (var day in week) { switch (day) { case "1": policy.Sunday = true; break; case "2": policy.Monday = true; break; case "3": policy.Tuesday = true; break; case "4": policy.Wednesday = true; break; case "5": policy.Thursday = true; break; case "6": policy.Friday = true; break; case "7": policy.Saturday = true; break; } } policy.DataBaseName = backUpJobConfig.DataBaseName; return(policy); }
/// <summary> /// 更新策略到配置文件 /// </summary> /// <returns></returns> public void WritePolicyConfig() { if (Policys == null) { return; } Policys.ToList().ForEach(x => { BackUpJobConfig config = new BackUpJobConfig(); config.Id = x.Id; config.DataBaseName = x.DataBaseName; config.Cron = ConvertToCron(x); config.BackUpType = x.BackUpType == BackUpType.DataBase ? 0 : 1; manger.WriteBackUpJobConfig(config); }); }
public List <BackUpJobConfig> BackUpJobConfigs() { string error = ""; DataTable dataTable = EnvironmentInfo.SqliteHelper.GetDataTable(out error, "select * from sys_backup_job;"); List <BackUpJobConfig> configs = new List <BackUpJobConfig>(); foreach (DataRow dr in dataTable.Rows) { BackUpJobConfig config = new BackUpJobConfig(); config.Id = dr["Id"].ToString(); config.DataBaseName = dr["DataBaseName"].ToString(); config.Cron = dr["Cron"].ToString(); config.BackUpType = int.Parse(dr["BackUpType"].ToString()); configs.Add(config); } return(configs); }
public void WriteBackUpJobConfig(BackUpJobConfig backUpJobConfig) { BackUpJobConfig config = ReadBackUpJobConfig(backUpJobConfig.Id); if (config == null) { string error = ""; EnvironmentInfo.SqliteHelper.UpdateData(out error, $"insert into sys_backup_job values('{backUpJobConfig.Id}','{backUpJobConfig.DataBaseName}','{backUpJobConfig.Cron}',{backUpJobConfig.BackUpType});"); EnvironmentInfo.BackUpJobConfigs.Add(backUpJobConfig); } else { string error = ""; EnvironmentInfo.SqliteHelper.UpdateData(out error, $"update sys_backup_job set DataBaseName='{backUpJobConfig.DataBaseName}',Cron='{backUpJobConfig.Cron}',BackUpType={backUpJobConfig.BackUpType} where Id='{backUpJobConfig.Id}';"); config.DataBaseName = backUpJobConfig.DataBaseName; config.Cron = backUpJobConfig.Cron; config.BackUpType = backUpJobConfig.BackUpType; } }