RadScheduler for Silverlight learning series, part 4: So what is RecurrenceExceptionHelper?

Posted by: the telerik blogs, on 10 Sep 2009 | View original | Bookmarked: 0 time(s)

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:

/*HowIsaveexceptions,volume1
*
*Stringwillbesplitwiththefollowingvaluesinthefollowinglocations:
*
*[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)
*
*Whencreatingappointmentexceptionsuponsavinganappointment,webasicallyneedtocreatethe
*exceptionscollectionandthenre-breakitdowntothisformat,incasethereareanyexceptions
*weneedtodelete,modify,etc..Also,thesefieldswillALWAYSexist,eveniftheyarenull\
*
*So...ifyouwanttodoacustomappointment,besuretoaddtothislistforreference
*andbesuretomodifythebelowMakeExceptionStringmethod
*
*/

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!

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD