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.
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.
This code snippet shows how to register a schedule for a specific date.
SchedClient.ScheduleAuthoring scheduleClient;
SchedAuth.Schedule schedule;
int scheduleID = 0;
try {
//***** SPECIFIC DATE *****
schedule = new SchedAuth.Schedule((int) SchedAuth.RecurrenceType.Yearly);
//Setup Schedule
schedule.Name = "Specific Date Schedule1";
schedule.Description = "This schedule executes on 18 Dec at 15:39";
//Setup Range
schedule.RecurrenceRange.Occurrences = 1; //Could also use the RecurenceRange.StartDate and EndDate to specify a range
//Setup Pattern
schedule.RecurrencePatternYearly.DayX = 18;
schedule.RecurrencePatternYearly.EveryXMonth = 01;
schedule.RecurrencePatternYearly.StartTime = new SchedAuth.Time(15, 39);
//Open Connection and save schedule
scheduleClient = new SchedClient.ScheduleAuthoring();
scheduleClient.CreateConnection();
scheduleClient.Connection.Open(GetConnectionString());
scheduleID = scheduleClient.UpdateSchedule(schedule);
//AddMailPolicyForSchedule(scheduleID, "This is a test mail.", "User@K2.net");
AddSolutionPolicy(scheduleID);
MessageBox.Show("Done");
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
} finally {
schedule = null;
scheduleClient = null;
}
}
This code snippet shows how to register a schedule for a specific day of the week.
SchedClient.ScheduleAuthoring scheduleClient;
SchedAuth.Schedule schedule;
int scheduleID = 0;
try {
//***** EVERY MONDAY *****
schedule = new SchedAuth.Schedule((int) SchedAuth.RecurrenceType.Weekly);
//Setup Schedule
schedule.Name = "Every Monday Schedule";
schedule.Description = "This schedule executes every Monday at 7:45";
//No Range will be used here, as we want to execute this every Monday
//Setup Pattern
schedule.RecurrencePatternWeekly.Monday = true; //Could do this for every Monday and Wednesday by adding Monday = true and Wednesday = true
schedule.RecurrencePatternWeekly.EveryXWeeks = 1; //Could do this every 3rd week by changing to 3
schedule.RecurrencePatternWeekly.StartTime = new SchedAuth.Time(7, 45); //Use this as 24H
//Open Connection and save schedule
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;
}
}
This code snippet shows how to register a schedule for a specific time of the month.
SchedClient.ScheduleAuthoring scheduleClient;
SchedAuth.Schedule schedule;
int scheduleID = 0;
try {
//***** EVERY LAST FRIDAY OF THE MONTH *****
schedule = new SchedAuth.Schedule((int) SchedAuth.RecurrenceType.Monthly);
//Setup Schedule
schedule.Name = "Every Last Friday of the Month Schedule";
schedule.Description = "This schedule executes every Last Friday of Every Month";
//No Range will be used here, as we want to execute this every Month
//Setup Pattern
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); //Use this as 24H
//Open Connection and save schedule
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;
}
}
This code snippet shows how to register a schedule for a specific interval.
SchedClient.ScheduleAuthoring scheduleClient;
SchedAuth.Schedule schedule;
int scheduleID = 0;
try {
//***** EVERY MONDAY *****
schedule = new SchedAuth.Schedule((int) SchedAuth.RecurrenceType.Interval);
//Setup Schedule
schedule.Name = "Every 5 min";
schedule.Description = "This schedule executes every 5 min for the next 20 minutes";
//No Range will be used here, as we want to execute this every Month
schedule.RecurrenceRange.StartDate = DateTime.Now;
schedule.RecurrenceRange.EndDate = DateTime.Now.AddMinutes(20);
//Setup Pattern
schedule.RecurrencePatternInterval.Minutes = 5;
//Open Connection and save schedule
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;
}
}