public WlbScheduledTask GetNextExecutingTask() { WlbScheduledTask firstTask = null; int currentTimeSortKey = GetSortKey(WlbScheduledTask.ConvertToWlbTaskDayOfWeek(DateTime.Now.DayOfWeek), DateTime.Now); foreach (int key in this.VirtualTaskList.Keys) { //only consider Enabled tasks if (this.VirtualTaskList[key].Enabled) { if (null == firstTask) { firstTask = this.VirtualTaskList[key]; } if (key > currentTimeSortKey) { return(this.VirtualTaskList[key]); } } } //we are still here, so we have not found the next task. this means that we // need to account for week wrapping. This shoudl be the first task of the Virtual // Task List return(firstTask); }
public WlbScheduledTask GetLastExecutingTask() { int[] taskKeys = new int[this.VirtualTaskList.Keys.Count]; this.VirtualTaskList.Keys.CopyTo(taskKeys, 0); WlbScheduledTask lastTask = this.VirtualTaskList[taskKeys[taskKeys.Length - 1]]; int currentTimeSortKey = GetSortKey(WlbScheduledTask.ConvertToWlbTaskDayOfWeek(DateTime.Now.DayOfWeek), DateTime.Now); for (int i = taskKeys.Length - 1; i >= 0; i--) { //Only consider Enabled tasks if (this.VirtualTaskList[taskKeys[i]].Enabled) { if (taskKeys[i] < currentTimeSortKey) { return(this.VirtualTaskList[taskKeys[i]]); } } } //we are still here, so we have not found the previous task. this means that we // need to account for week wrapping. This should be the last task of the Virtual // Task List return(lastTask); }