StepByStepPicking( FilteringHeuristic filtering) //choosing next value (tries all possible variations of parametrs, if doesnt fit - backtracking will solve the issue) { if (filtering == FilteringHeuristic.NONE) { if (Value.TeacherValue != Teachers.Last()) { Value.TeacherValue = Teachers.ElementAt(Teachers.IndexOf(Value.TeacherValue) + 1); } else if (Value.AudienceValue != Audiences.Last()) { Value.TeacherValue = Teachers.First(); // resetting previous data element Value.AudienceValue = Audiences.ElementAt(Audiences.IndexOf(Value.AudienceValue) + 1); } else if (Value.TimeValue != Times.Last()) { Value.AudienceValue = Audiences.First(); // resetting previous data element Value.TimeValue = Times.ElementAt(Times.IndexOf(Value.TimeValue) + 1); } else if (Value.DayValue != Days.Last()) { Value.TimeValue = Times.First(); // resetting previous data element Value.DayValue = Days.ElementAt(Days.IndexOf(Value.DayValue) + 1); } } else { Value = new Value(PossibleValues.First()); PossibleValues.RemoveAt(0); } }
public bool Check() { var perform = false; var now = DateTime.Now; for (int i = 0; i < Times.Count; i++) { var time = Times.ElementAt(i); var lastOccurence = DateTime.Today.AddDays(time > now.TimeOfDay ? -1 : 0) + time; var timeAfter = Times.ElementAt((i + 1) % Times.Count); var firstOccurenceAfter = lastOccurence.Date.AddDays(time >= timeAfter ? 1 : 0) + timeAfter; var halfwayTime = lastOccurence + (firstOccurenceAfter - lastOccurence).Divide(2); /* If the time to monitor has passed, trigger the event - unless * we are already halfway to the next scheduled monitoring time. */ if (checkFrom < lastOccurence && now < halfwayTime) { perform = true; break; } } if (DateTime.Now - lastCheck >= TimeSpan.FromMinutes(10)) { Profile.Debug(new { Action = "Checking monitor", Key = this.key, Times = Times, checkFrom = checkFrom, now = now, Result = perform }); lastCheck = DateTime.Now; } return(perform); }