I need to take a recurring event that was set up in the kendo scheduler and unpack it so i can get an entry for each date. I am using iCal.Net to do this.
It works as expected for recurring events, but when i delete an occurrence from the recurring event and try to pass kendoEvent.RecurrenceException to iCalEvent.ExceptionDates.Add(new PeriodList(kendoEvent.RecurrenceException) I get a null reference exception when i call iCal-Calendar.GetOccurrences.
Do I need to do something when converting between kendo and ical?
TIA
My code is:
public static List<Occurrence> UnpackRecurrence(ISchedulerEvent scheduleEvent, DateTime? start = null, DateTime? end = null) { List<Occurrence> rVal = new List<Occurrence>(); if (string.IsNullOrWhiteSpace(scheduleEvent.RecurrenceRule) == false) { var recurrencePattern = new RecurrencePattern(scheduleEvent.RecurrenceRule); iCalendar calendar = new iCalendar(); Event evnt = new Event() { Start = new iCalDateTime(scheduleEvent.Start), End = new iCalDateTime(scheduleEvent.End) }; evnt.RecurrenceRules.Add(recurrencePattern); if (string.IsNullOrWhiteSpace(scheduleEvent.RecurrenceException) == false) { evnt.ExceptionDates.Add(new PeriodList(scheduleEvent.RecurrenceException)); } calendar.Events.Add(evnt); start = start ?? scheduleEvent.Start; if (end == null) { if (recurrencePattern.Until != DateTime.MinValue) { end = recurrencePattern.Until; } else if (recurrencePattern.Count > 0) { end = DateTime.Now.AddYears(recurrencePattern.Count); } else { end = DateTime.Now.AddYears(5); // we probably shouldn't hit this } } rVal = calendar.GetOccurrences(new iCalDateTime(start.Value), new iCalDateTime(end.Value)).ToList(); } return rVal; }
