Session Schedule
The SessionSchedule class allows specifying time intervals when a session must be logged on (active). message sequence numbers.
Parameters
The SessionSchedule constructor creates the session schedule.
The first two parameters (firstDay
and lastDay
) define a working week. During these days, the session will always be connected at the logon time and disconnected at the logout
time if the session duration equals to a single day. If the session must be active for the entire week, then the scheduler
will connect the session at the logon time on the day specified by the firstDay
parameter and disconnect it at the logout time on the day specified by the lastDay
parameter.
Note
It is possible for the firstDay
parameter value to be greater than the value of the lastDay
parameter. In this case, the schedule will cross the end of the week and
continue until the lastDay
.
If the firstDay
and lastDay
parameters have the same value, then the length (number of days) of the working week depends on the values of the logonTime
and the logoutTime
parameters:
- If the
logonTime
is less than thelogoutTime
, then the working week will be a single day. - If the
logonTime
is greater than thelogoutTime
, then the working week will be seven days (the first logon will be performed at the logon time on the first day, the last logout will be performed at the logout time a week later).
The logonTime
and logoutTime
parameters define the logon and logout time for the session for each working day if the session duration is a single day. If the session must
continue for the entire week, then the logonTime
parameter value specifies the time for the logon to be performed on the
first day of the working week, and the logoutTime
parameter value specifies the time of the logout to be performed on the last day of the working week.
For example:
// Session is active from 8:00 until 17:00 each working day.
var regularSingleDay = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(17, 0, 0));
// Session starts on Monday at 8:00 and continues until 17:00 on Friday
var regularWeek = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(17, 0, 0));
// Session starts on Monday at 23:00, crosses midnight and is disconnected at 05:00 on Tuesday.
// The next connection is established on Tuesday at 23:00 and finished at 05:00 on Wednesday.
// And so on..
// The last logon will be performed on Friday, at 23:00 and the final logout will occur at 5:00 on Saturday morning.
// Next Monday, before the logon, message sequence numbers will be reset.
var crossMidnightSingleDay = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Saturday, new TimeSpan(23, 0, 0), new TimeSpan(5, 0, 0));
// Session starts on Friday at 16:00, continues four calendar days and is disconnected on Monday, at 02:00.
var crossMidnightWeek = new SessionSchedule(DayOfWeek.Friday, DayOfWeek.Monday, new TimeSpan(16, 0, 0), new TimeSpan(2, 0, 0));
Time Zone
By default, the Scheduler uses the local time to determine when a session should be connected/disconnected.
Use the UtcTimeUsage property for switching to UTC.
Advanced Cases
The SessionSchedule constructor supports common use cases.
However, sometimes it is necessary to set different logon and logout times for different days. The scheduler provides this ability via the LogonTime(DayOfWeek, TimeSpan) and LogoutTime(DayOfWeek, TimeSpan) properties.
Different Logon / Logout Times
The following example demonstrates how a schedule can be updated to disconnect the session on Friday earlier.
// Construct the schedule with the same logon/logout time for all days.
var shortFriday = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(17, 0, 0));
// Update the logout time for Friday.
shortFriday.LogoutTime(DayOfWeek.Friday, new TimeSpan(16, 30, 0));
Day Off
Another example demonstrates how the schedule can be updated to define one day off in the middle of the working week.
// Construct the schedule with the same logon/logout time for all days.
var dayOffOnWednesday = new SessionSchedule(DayOfWeek.Monday, DayOfWeek.Friday, new TimeSpan(8, 0, 0), new TimeSpan(17, 0, 0));
// Disable logon and logout on Wednesday.
dayOffOnWednesday.LogoutTime(DayOfWeek.Wednesday, TimeSpan.MinValue);