public static void BackUpData(string ruleName, DateTime?fromDay, DateTime?toDay, BackUpStatus theRuningStatusInSession) { StartFlag(theRuningStatusInSession); try { //读入静态配置表 StartLittleProcess(theRuningStatusInSession, StaticConfigTable.ReadToTableToString()); StaticConfigTable.ReadToTable(); //准备所需文件夹 StartLittleProcess(theRuningStatusInSession, DiskOperations.PrepareForBackUpToString()); DiskOperations.PrepareForBackUp(); //检查Rar压缩器 StartLittleProcess(theRuningStatusInSession, CommandRunner.CheckRarReadyToString()); CommandRunner.CheckRarReady(); //配置日志对象 StartLittleProcess(theRuningStatusInSession, TransferDataLogManager.TryConfigLogObjToString()); TransferDataLogManager.TryConfigLogObj(); //根据规则起另外线程开始工作 StartLittleProcess(theRuningStatusInSession, RulesPool.FindRuleByNameToString()); //需要克隆的原因在于RulesPool是静态的,上次运行的对象会影响下次的运行 TransferRule tr = RulesPool.FindRuleByName(ruleName); BackUpProcess bup = StartBackUp; bup.BeginInvoke(tr.Clone() as TransferRule, fromDay, toDay, theRuningStatusInSession, null, null); } catch (ApplicationException ae) { FailedFlag(theRuningStatusInSession, ae.Message); } }
internal void ConfigAllRuleFitler(TransferRule transferRule) { foreach (TableTransfer tt in _TablesToTransfer) { tt.ConfigRuleFitler(transferRule, _DbName, _DbName + _OrginCopyDbSuffix, _DbName, _DbName + _ForRestoreCopyDbSuffix); } }
/// <summary> /// 根据读取的rule字符构建成一个Rule对象 /// </summary> /// <param name="theRuleName">rule的名字</param> /// <param name="theRuleStrings">rule的字符串</param> private static TransferRule CalculateRules(string theRuleName, string theRuleStrings) { TransferRule tr = new TransferRule(); tr.RuleName = theRuleName; Regex rules = new Regex(@"(?<DbName>\w+):(\[(?<TableName>\w+)\(?(?<FilterRule>\w*)\)?\])+"); MatchCollection matchCollection = rules.Matches(theRuleStrings); foreach (Match aMatch in matchCollection) { //确定数据库 Utility.AssertAreSame(1, aMatch.Groups["DbName"].Captures.Count, DbErrorString(theRuleName)); DbTransfer dt = new DbTransfer(); dt.DbName = aMatch.Groups["DbName"].Captures[0].Value; //确定表 Utility.AssertAreSame(aMatch.Groups["TableName"].Captures.Count, aMatch.Groups["FilterRule"].Captures.Count, TableErrorString(theRuleName)); for (int i = 0; i < aMatch.Groups["TableName"].Captures.Count; i++) { TableTransfer tt = new TableTransfer(); tt.TableName = aMatch.Groups["TableName"].Captures[i].Value; tt.TableFilterName = aMatch.Groups["FilterRule"].Captures[i].Value; dt.AddTransferTable(tt); } tr.DbsToTransfer.Add(dt); } return(tr); }
internal bool GetNeedTimeFilter(TransferRule transferRule) { if(_TableFilter == null) { transferRule.Construct(); } return _TableFilter.GetNeedTimeFilter(); }
public void ConfigTheFilter(TransferRule theRule, string mainTableName, string orginDbName, string orginCopyDbName, string restoreDbName, string forRestoreCopyDbName) { _MainTable = mainTableName; _TheRule = theRule; _OrginDbName = orginDbName; _OrginCopyDbName = orginCopyDbName; _RestoreDbName = restoreDbName; _ForRestoreCopyDbName = forRestoreCopyDbName; }
public object Clone() { TransferRule aCloneObj = new TransferRule(); aCloneObj._RuleName = _RuleName; foreach (DbTransfer dt in _DbsToTransfer) { aCloneObj._DbsToTransfer.Add(dt.Clone() as DbTransfer); } return(aCloneObj); }
internal bool GetNeedTimeFilter(TransferRule transferRule) { foreach (TableTransfer tt in _TablesToTransfer) { if (tt.GetNeedTimeFilter(transferRule)) { return(true); } } return(false); }
/// <summary> /// 负责将读取到的config中rule的字符串转换成为rule的对象 /// </summary> /// <param name="theReadData">Key存放的是规则名字,Value存放的是该规则的字符串</param> /// <returns>rule集合</returns> public static List <TransferRule> Convert(Dictionary <string, string> theReadData) { List <TransferRule> retVal = new List <TransferRule>(); foreach (KeyValuePair <string, string> kvp in theReadData) { TransferRule aNewRule = CalculateRules(kvp.Key, kvp.Value); aNewRule.Check(kvp.Key, kvp.Value); aNewRule.Construct(); retVal.Add(aNewRule); } return(retVal); }
/// <summary> /// 写入Config /// </summary> /// <param name="theRule">待写入的Rule</param> /// <param name="startTime">开始时间(方法参数)</param> /// <param name="endTime">结束时间(方法参数)</param> public static void WriteConfig(TransferRule theRule, DateTime?startTime, DateTime?endTime) { TransferRule _TransferRule = theRule; Utility.AssertNotNull(theRule, Utility._Error_TransferRule_NotNull); List <string> needWrite = new List <string>(); //写规则的名字 needWrite.Add(_TransferRuleNameKey + _TransferRule.RuleName); //写规则字符 needWrite.Add(_TransferRuleKey + _TransferRule.MakeString()); //写参数名字 needWrite.Add(_TransderParameterKey + MakeParameters(startTime, endTime)); string fullConfigName = DiskOperations.DataTemp_ForBackUpDirectory + _DefaultConfigName; DiskOperations.WriteLinesToFile(fullConfigName, needWrite); }
public void ConfigTheFilter(TransferRule theRule, string mainTableName, string orginDbName, string orginCopyDbName, string restoreDbName, string forRestoreCopyDbName) { _MainTable = mainTableName; _TheRule = theRule; _OrginDbName = orginDbName; _OrginCopyDbName = orginCopyDbName; _RestoreDbName = restoreDbName; _ForRestoreCopyDbName = forRestoreCopyDbName; DbTransfer theDt = theRule.FindDbTransferByName(orginDbName); foreach (KeyValuePair <string, string> theColumnn in DefineProtectedTableFkColumnName()) { theDt.AddProtectTable(theColumnn.Key); } AfterConfigTheFilter(theRule, orginDbName, orginCopyDbName, restoreDbName, forRestoreCopyDbName); }
public static void RestoreData(string theRarFile, RestoreStatus theRuningStatusInSession) { StartFlag(theRuningStatusInSession); try { //读入静态配置表 StartLittleProcess(theRuningStatusInSession, StaticConfigTable.ReadToTableToString()); StaticConfigTable.ReadToTable(); //准备所需文件夹 StartLittleProcess(theRuningStatusInSession, DiskOperations.PrepareForRestoreToString()); DiskOperations.PrepareForRestore(); //检查Rar压缩器 StartLittleProcess(theRuningStatusInSession, CommandRunner.CheckRarReadyToString()); CommandRunner.CheckRarReady(); //配置日志对象 StartLittleProcess(theRuningStatusInSession, TransferDataLogManager.TryConfigLogObjToString()); TransferDataLogManager.TryConfigLogObj(); //解析Rar数据 StartLittleProcess(theRuningStatusInSession, TransferConfig.AnalyseRarDataToString()); DateTime? fromDay; DateTime? toDay; TransferRule theTransferRule = TransferConfig.AnalyseRarData(theRarFile, out fromDay, out toDay, DiskOperations.DataTemp_ForRestoreDirectory, false, false); //根据规则起另外线程开始工作 RestoreProcess rp = StartRestore; rp.BeginInvoke(theTransferRule, fromDay, toDay, theRuningStatusInSession, null, null); } catch (ApplicationException ae) { FailedFlag(theRuningStatusInSession, ae.Message); } }
internal void ConfigRuleFitler(TransferRule transferRule, string orginDbName, string orginCopyDbName, string restoreDbName, string forRestoreDbName) { _TableFilter.ConfigTheFilter(transferRule, _TableName, orginDbName, orginCopyDbName, restoreDbName, forRestoreDbName); }
private static void StartRestore(TransferRule rule, DateTime?fromDay, DateTime?toDay, RestoreStatus theRuningStatusInSession) { rule.RestoreData(fromDay, toDay, theRuningStatusInSession); }
private static void StartBackUp(TransferRule rule, DateTime?fromDay, DateTime?toDay, BackUpStatus theRuningStatusInSession) { rule.BackUpData(fromDay, toDay, theRuningStatusInSession); }
/// <summary> /// 在配置过滤器之后可以定义的事件 /// </summary> public abstract void AfterConfigTheFilter(TransferRule theRule, string orginDbName, string orginCopyDbName, string restoreDbName, string forRestoreCopyDbName);