Blogs

The Progress Bar - DevExpress XPF Blog

WinForms Scheduler Control – Exception handling and termination during Appointment Exchange (Coming in v2010 Vol 2)

     

Certain procedures, such as iCalendar import/export and appointment synchronization with Microsoft Outlook, can be quite lengthy and sometimes take a significant amount of time to complete based on the number of items being transferred over. If an error occurs, we should have the ability to analyze it on the spot and then decide whether the execution can continue or the process should be terminated.

Starting with the 2010.2 release of DXperience, the XtraScheduler control now includes this functionality. This version provides a descendant of the AppointmentExchanger class with a Terminate() method and an OnException event. This functionality works with Outlook, iCalendar and VCalendar appointment exchangers (i.e. used to import and/or export appointment to and from those formats).

When an exception occurs, the event handler OnException gets an object of type ExchangeExceptionEventArgs, containing the OriginalException property of the System.Exception type. Using this property, you can get the error message, call stack and all the other related information. Proper typecasting enables you to get data specific to a certain exchanger.

The following example shows how to access the _AppointmentItem object specific for the Microsoft Outlook Calendar:

void synchronizer_OnException(object sender, ExchangeExceptionEventArgs e) {

    OutlookExchangeExceptionEventArgs args = e as OutlookExchangeExceptionEventArgs;

    if (args.OutlookAppointment != null) {

        // do something

}

The Handled property allows you to stop propagation of exception(s) if you have already processed it and decided to continue execution.

If you want to terminate the process immediately, you can simply call the Terminate method of your exchanger instance. That saves you from the need to use flags to indicate an error and from handling the AppointmentImporting and AppointmentSynchronizing events to stop all subsequent attempts to synchronize appointments.

An example code for this approach is shown below.

using DevExpress.XtraScheduler;

using DevExpress.XtraScheduler.iCalendar;

//…

void ImportAppointments(Stream stream) {

    if (stream == null || stream == Stream.Null || stream.Length == 0)

        return;

    iCalendarImporter importer = new iCalendarImporter(schedulerStorage1);

    importer.OnException += new ExchangeExceptionEventHandler(importer_OnException);

    importer.Import(stream);

}

 

void importer_OnException(object sender, DevExpress.XtraScheduler.ExchangeExceptionEventArgs e) {

    iCalendarParseExceptionEventArgs args = e as iCalendarParseExceptionEventArgs;

    if (args != null) {

        if (ckhBreakOnError.Checked) {

            iCalendarImporter importer = (iCalendarImporter)sender;

            importer.Terminate();

        }

        ShowErrorMessage(String.Format("Can't parse line '{1}' at {0} index", args.LineIndex, args.LineText));

    }

    else

        ShowErrorMessage(e.OriginalException.Message);

   

    e.Handled = true; // prevent exception throwing

}

 

void ShowErrorMessage(string text) {

DevExpress.XtraEditors.XtraMessageBox.Show(text, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);

}

The complete sample project for this is also available in the DevExpress Code Central database at http://www.devexpress.com/example=E2492

Published Oct 27 2010, 02:29 PM by Emil Mesropian (DevExpress)
Bookmark and Share

Comments

 

IOANNIS MPOURKELIS said:

I am using the synchronization feature to sync xtrascheduler appointments with outlook.

I never had an exception during that synchronization process.

The only problem I experience is that the AppointmentImporter.SourceObjectCount method takes so much time and it is very CPU intensive.

October 27, 2010 8:47 PM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.