public void RunSuccess(T_ScheduleRule rule) { var now = DateTime.Now; rule.LastSuccessTime = now; _scheduleRuleRepository.Update(rule); }
public bool IsTaskCanBeRunNow(T_ScheduleRule rule) { var nowTime = DateTime.Now; var elaspDays = (nowTime.Date - rule.LastSuccessTime.Date).TotalDays; var nowTimeTime = nowTime.TimeOfDay; T_ScheduleRuleLine ruleLine = null; //Predicate<ScheduleRuleLine, TimeSpan, double> matchScheduleLine = (l, nowtime, elaspDays) => { }; //see if nowTime is meet the interval day+LastSuccessTime if ((elaspDays % rule.IntervalDay == 0) && ((elaspDays > 0 && rule.IntervalDay >= 1) || elaspDays == 0 && rule.IntervalDay == 1)) { //get the rule line whose time range the nowTime can sit in //returnRuleLine = rule.ScheduleRuleLines.FirstOrDefault(l => nowTimeTime >= l.TimeRangeFrom.TimeOfDay // && nowTimeTime < l.TimeRangeTo.TimeOfDay // && l.ScheduleRuleObj.LastSuccessTime.TimeOfDay < l.TimeRangeFrom.TimeOfDay.Add(TimeSpan.FromDays(elaspDays))); ruleLine = rule.ScheduleRuleLines.FirstOrDefault(l => ScheduleRuleLineFilter(l, nowTimeTime, elaspDays)); } return(ruleLine != null); }