public static IList <IScheduledRule> LoadRules(string strRules) { IList <IScheduledRule> list = new List <IScheduledRule>(); foreach (Match match in ScheduledUtils.regex.Matches(strRules)) { ScheduledRule scheduledRule = new ScheduledRule(); scheduledRule.Rule = new TaskRule { Type = match.Groups["Type"].Value, Offest = match.Groups["Offset"].Value }; string value = match.Groups["Count"].Value; scheduledRule.Count = (string.IsNullOrEmpty(value) ? 0 : TypeParsers.ConvertTo <int>(value)); string value2 = match.Groups["EndDate"].Value; scheduledRule.End = (string.IsNullOrEmpty(value2) ? DateTime.MinValue : TypeParsers.ConvertTo <DateTime>(value2)); if (Enum.IsDefined(ScheduledUtils.type, scheduledRule.Rule.Type)) { list.Add(scheduledRule); } } foreach (Match match2 in ScheduledUtils.regexBlockInterval.Matches(strRules)) { ScheduledBlockIntervalRule scheduledBlockIntervalRule = new ScheduledBlockIntervalRule(); scheduledBlockIntervalRule.Begin = match2.Groups["Begin"].Value; scheduledBlockIntervalRule.Interval = match2.Groups["Interval"].Value; scheduledBlockIntervalRule.Region = new TaskRegion { Type = match2.Groups["RegionType"].Value, StartOffest = match2.Groups["StartOffset"].Value, StopOffest = match2.Groups["StopOffset"].Value }; if (Enum.IsDefined(ScheduledUtils.type, scheduledBlockIntervalRule.Region.Type)) { list.Add(scheduledBlockIntervalRule); } } foreach (Match match3 in ScheduledUtils.regexBlockTimer.Matches(strRules)) { ScheduledBlockTimerRule scheduledBlockTimerRule = new ScheduledBlockTimerRule(); scheduledBlockTimerRule.Begin = match3.Groups["Begin"].Value; scheduledBlockTimerRule.Rule = new TaskRule { Type = match3.Groups["RuleType"].Value, Offest = match3.Groups["RuleOffset"].Value }; scheduledBlockTimerRule.Region = new TaskRegion { Type = match3.Groups["RegionType"].Value, StartOffest = match3.Groups["StartOffset"].Value, StopOffest = match3.Groups["StopOffset"].Value }; if (Enum.IsDefined(ScheduledUtils.type, scheduledBlockTimerRule.Rule.Type) && Enum.IsDefined(ScheduledUtils.type, scheduledBlockTimerRule.Region.Type)) { list.Add(scheduledBlockTimerRule); } } return(list); }
private static IScheduledItem BaseRule(ScheduledRule rule) { if (rule == null) { return(null); } IScheduledItem result = null; try { string type; switch (type = rule.Rule.Type) { case "BySecond": case "ByMinute": case "Hourly": case "Daily": case "Weekly": case "Monthly": result = new ScheduledTime(rule.Rule.Type, rule.Rule.Offest); break; case "BySleep": if (rule.Count == 0 && (rule.End == DateTime.MaxValue || rule.End == DateTime.MinValue)) { result = new SimpleInterval(DateTime.Now, TimeSpan.Parse(rule.Rule.Offest)); } else { if (rule.Count > 0) { result = new SimpleInterval(DateTime.Now, TimeSpan.Parse(rule.Rule.Offest), rule.Count); } else { if (rule.End != DateTime.MaxValue) { result = new SimpleInterval(DateTime.Now, TimeSpan.Parse(rule.Rule.Offest), rule.End); } } } break; } } catch { } return(result); }
public static IScheduledItem Provider(IScheduledRule rule) { IScheduledItem result; if (rule is ScheduledBlockIntervalRule) { ScheduledBlockIntervalRule rule2 = rule as ScheduledBlockIntervalRule; result = SchedulerFactory.BlockIntervalRule(rule2); } else { if (rule is ScheduledBlockTimerRule) { ScheduledBlockTimerRule rule3 = rule as ScheduledBlockTimerRule; result = SchedulerFactory.BlockTimerRule(rule3); } else { ScheduledRule rule4 = rule as ScheduledRule; result = SchedulerFactory.BaseRule(rule4); } } return(result); }