For those of you following this series, I'm going to take a slight detour to explain one of the little bits of magic that we have been using to make loading and saving appointments very easy: RecurrenceExceptionHelper.  If you downloaded the sample application from part 3, you'll see this sitting in the Silverlight-RIA-Entity folder (aka the Silverlight portion of the solution). 

The first thing you might be asking is where the need for such a class comes from.  Well, handling Recurrence rules and Exceptions are two of the more complex things that you can do when working with appointments.  When using a two table approach to saving appointments, exceptions are referenced by an AppointmentType variable and the references are handled via the relationship between the tables.

Well, relational databases are not my cup of tea, so storing exceptions with the appointment seemed like the next best step.  When working with saving recurrence patterns, the RadScheduler team has provided us with the RecurrencePatternHelper (you'll see this referenced in the project we've been working on) which comes from the Telerik.Windows.Controls.Scheduler.ICalendar namespace.  This helper provides two main functions- turning a recurrence pattern into a nicely serialized string for storage and producing a recurrence pattern when you provide that string back to it.

Exceptions, on the other hand, don't have a standard method for handling them, especially when you start creating custom appointment types.  So came the need for RecurrenceExceptionHelper.

The purpose of the class is twofold, much like its friend RecurrencePatternHelper- to serialize a list of exceptions for storage and to turn that stored string into exceptions we can add back to our appointments when they are retrieved from the database.  So we have two methods to use here:

  • RecreateExceptions - take a string created by RecurrenceExceptionHelper and return a list of ExceptionOccurences, which can be added to an appointment using Appointment.RecurrenceRule.AddException
  • MakeExceptionString - take a list of exceptions and create a string that holds all the data we need to save exceptions to a given appointment.

I included comments in the class that sum up nicely how we save these items:

    /* How I save exceptions, volume 1  
     * String will be split with the following values in the following locations:  
     *      [0] = exception.Date  
     *      [1] = Appointment.Start (DateTime)  
     *      [2] = Appointment.End (DateTime)  
     *      [3] = Appointment.Subject (String)  
     *      [4] = Appointment.Body (String)  
     *      [5] = Appointment.IsAllDayEvent (Bool)  
     *      [6] = Appointment.Location (String)  
     *      [7] = Appointment.URL (String)  
     *      [8] = Appointment.UniqueID (String)  
     *      [9] = Appointment.Type (Int)  
     * When creating appointment exceptions upon saving an appointment, we basically need to create the  
     *  exceptions collection and then re-break it down to this format, in case there are any exceptions  
     *  we need to delete, modify, etc..  Also, these fields will ALWAYS exist, even if they are null\  
     * So... if you want to do a custom appointment, be sure to add to this list for reference  
     *  and be sure to modify the below MakeExceptionString method        


Make note of this section because it explains exactly how an ExceptionOccurence is broken down.  Moving forward as we start working with a custom appointment class, you'll see how important it is to know how RecurrenceExceptionHelper works so you can add new fields into your saved exceptions.

I know this wasn't the most exciting installment of this series, but I wanted to take a few moments to explain this class because it will become very important to know how it works as you move forward with custom appointments and how RadScheduler works with them.

In the next episode, we'll be looking into how to customize the AppointmentEditTemplate to incorporate the Location, URL, Developer, and ProductLine variables from our database.

Happy coding!

About the Author

Evan Hutnick

works as a Developer Evangelist for Telerik specializing in Silverlight and WPF in addition to being a Microsoft MVP for Silverlight. After years as a development enthusiast in .Net technologies, he has been able to excel in XAML development helping to provide samples and expertise in these cutting edge technologies. You can find him on Twitter @EvanHutnick.


Comments are disabled in preview mode.