null reference error when adding KendoEvent.RecurrenceException to iCal.ExceptionDates

2 posts, 0 answers
  1. Logan
    Logan avatar
    49 posts
    Member since:
    Apr 2013

    Posted 17 Dec 2018 Link to this post

    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;
            }

     

  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    974 posts

    Posted 20 Dec 2018 Link to this post

    Hello Logan,

    We have not tested the functionality offered by the Ical.Net library. Note that the RecurrenceException field in the SchedulerEvent object will hold a string of coma separated ISO 8601 with a Z zone designator (UTC) dates. Depending on the implementation of the PeriodList() constructor, you may need to process that string before passing it to that method.

    In case you have any other questions on the Kendo UI widgets or their build-in API, please do not hesitate to contact us.

    Regards,
    Veselin Tsvetanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top