- Relax and Be Served
- System Valet: Download It Here
A core component of System Valet is its task scheduler. All of the data and methods associated with scheduling are encapsulated in the CSvSchedule class (see Schedule.cpp). The Check() method is the heart of System Valet's task scheduler. This method is called by the OnTimer() method of the CSvListView class (see Listview.cpp) each time a WM_TIMER event is fired. It iterates through the list of scripts and checks each against a series of start criteria. It first checks the script's starting time against the current time by calling the CTime::GetCurrentTime() method to obtain the current time in a CTime object. It then compares the hours, minutes, and seconds of the CTime object returned with the hours, minutes, and seconds in the starting time's CTime object. If they are equal, the Check() method continues checking criteria.
The next check is to determine whether the current date lies within the script's specified starting and ending date. To obtain the current date it calls the GetMonth(), GetDay(), and GetYear() methods of the CTime object timeCurrent. It tests the date range by using the standard C comparison operators, less than (<) and greater than (>). CTime provides operator overloading for these operators so comparing CTime objects is simply a matter of creating a statement such as if(dateCurrent < dateStart || dateCurrent > dateEnd) dosomething.
The scheduling algorithm must also handle specific checks based on the type of schedule that is running. If the script only runs on weekdays, for example, the day of the week must be checked. This is done using the method CTime::GetDayOfWeek(), which returns a value between one and seven to represent the days Sunday through Saturday. The Check() method checks for weekdays by verifying that the current day of the week is between two and six.