Adding custom schedules to the K2 Scheduler
By using the K2 Scheduler it is possible to set alerts for specific dates, specific days of the week, specific times during the month, and for specific periods of time. The custom schedules samples presented here give example schedules that can be used to add these different schedule durations.
Custom schedules samples
These code snippets demonstrate how to register custom event schedules in K2.
Sample Project
We have provided a sample Visual Studio project that implements these code snippets:
K2Documentation.Samples.Management.Schedules.zip. The sample project is provided for demonstration purposes only. It is not supported by K2 product support and is not intended to be used as-is in production environments.
Schedule for specific date
This code snippet shows how to register a schedule for a specific date.
privatevoid btnScpecificDate_Click(object sender, EventArgs e) {
SchedClient.ScheduleAuthoring scheduleClient;
SchedAuth.Schedule schedule;
int scheduleID = 0;
try {
schedule = new SchedAuth.Schedule((int) SchedAuth.RecurrenceType.Yearly);
schedule.Name = "Specific Date Schedule1";
schedule.Description = "This schedule executes on 18 Dec at 15:39";
schedule.RecurrenceRange.Occurrences = 1;
schedule.RecurrencePatternYearly.DayX = 18;
schedule.RecurrencePatternYearly.EveryXMonth = 01;
schedule.RecurrencePatternYearly.StartTime = new SchedAuth.Time(15, 39);
scheduleClient = new SchedClient.ScheduleAuthoring();
scheduleClient.CreateConnection();
scheduleClient.Connection.Open(GetConnectionString());
scheduleID = scheduleClient.UpdateSchedule(schedule);
AddSolutionPolicy(scheduleID);
MessageBox.Show("Done");
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
} finally {
schedule = null;
scheduleClient = null;
}
}
Schedule for specific day of the week
This code snippet shows how to register a schedule for a specific day of the week.
privatevoid btnEveryMonday_Click(object sender, EventArgs e) {
SchedClient.ScheduleAuthoring scheduleClient;
SchedAuth.Schedule schedule;
int scheduleID = 0;
try {
schedule = new SchedAuth.Schedule((int) SchedAuth.RecurrenceType.Weekly);
schedule.Name = "Every Monday Schedule";
schedule.Description = "This schedule executes every Monday at 7:45";
schedule.RecurrencePatternWeekly.Monday = true;
schedule.RecurrencePatternWeekly.EveryXWeeks = 1;
schedule.RecurrencePatternWeekly.StartTime = new SchedAuth.Time(7, 45);
scheduleClient = new SchedClient.ScheduleAuthoring();
scheduleClient.CreateConnection();
scheduleClient.Connection.Open(GetConnectionString());
scheduleID = scheduleClient.UpdateSchedule(schedule);
AddMailPolicyForSchedule(scheduleID, "This is a every Monday mail test.", "User@K2.net");
MessageBox.Show("Done");
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
} finally {
schedule = null;
scheduleClient = null;
}
}
Schedule for specific time of the month
This code snippet shows how to register a schedule for a specific time of the month.
privatevoid btnLastDayOfEachMonth_Click(object sender, EventArgs e) {
SchedClient.ScheduleAuthoring scheduleClient;
SchedAuth.Schedule schedule;
int scheduleID = 0;
try {
schedule = new SchedAuth.Schedule((int) SchedAuth.RecurrenceType.Monthly);
schedule.Name = "Every Last Friday of the Month Schedule";
schedule.Description = "This schedule executes every Last Friday of Every Month";
schedule.RecurrencePatternMonthly.DayType = (int) SchedAuth.DayType.Friday;
schedule.RecurrencePatternMonthly.WeekX = (int) SchedAuth.WeekX.Last;
schedule.RecurrencePatternMonthly.EveryXMonth = 1;
schedule.RecurrencePatternMonthly.StartTime = new SchedAuth.Time(7, 54);
scheduleClient = new SchedClient.ScheduleAuthoring();
scheduleClient.CreateConnection();
scheduleClient.Connection.Open(GetConnectionString());
scheduleID = scheduleClient.UpdateSchedule(schedule);
AddMailPolicyForSchedule(scheduleID, "This is a every Last Friday of the Month mail test.", "User@K2.net");
MessageBox.Show("Done");
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
} finally {
schedule = null;
scheduleClient = null;
}
}
Schedule for specific interval
This code snippet shows how to register a schedule for a specific interval.
privatevoid btnIntervalSchedule_Click(object sender, EventArgs e) {
SchedClient.ScheduleAuthoring scheduleClient;
SchedAuth.Schedule schedule;
int scheduleID = 0;
try {
schedule = new SchedAuth.Schedule((int) SchedAuth.RecurrenceType.Interval);
schedule.Name = "Every 5 min";
schedule.Description = "This schedule executes every 5 min for the next 20 minutes";
schedule.RecurrenceRange.StartDate = DateTime.Now;
schedule.RecurrenceRange.EndDate = DateTime.Now.AddMinutes(20);
schedule.RecurrencePatternInterval.Minutes = 5;
scheduleClient = new SchedClient.ScheduleAuthoring();
scheduleClient.CreateConnection();
scheduleClient.Connection.Open(GetConnectionString());
scheduleID = scheduleClient.UpdateSchedule(schedule);
AddMailPolicyForSchedule(scheduleID, "This is a every 5 min mail test.", "User@K2.net");
MessageBox.Show("Done");
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
} finally {
schedule = null;
scheduleClient = null;
}
}