Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Scheduler > ICal Export with customAppointment

Not answered ICal Export with customAppointment

Feed from this thread
  • LAURIO avatar

    Posted on Mar 25, 2009 (permalink)

    Hi telerik team,

    I would like to implement the Ical export on my scheduler, following yours sample code and i've got an error message on this line:


    exporter.Export(RadScheduler1.Appointments, writer) 

    "Impossible to Cast an object from type CustomAppointment on telerik.windows.controls.scheduler.Appointment". Have you got an idea? thanks a lot,

    best regards

    NL

    Reply

  • Rosi Rosi admin's avatar

    Posted on Mar 25, 2009 (permalink)

    Hi Laurio,

    Thanks for bringing this to our attention.

    This seems to be a bug in RadScheduler control. The fix will be included in the Service Pack which will be released by the middle of April.  Your Telerik points have been updated for your involvement.

    Also to implement complete  Export/Import functionality with custom appointments you need to create your own CustomAppointmentCalendarExporter class which will inherit BaseCalendarExporter and will override WriteAdditionalDataForAppointment method. In this method you have to  add the code for exporting the additional data.

    For example:
     protected override void WriteAdditionalDataForAppointment(IAppointment appointment, CalObject calObject) 
            { 
                var app = appointment as CustomAppointment; 
                if (app == nullreturn
     
                if (app.RoomID!= null
                { 
                    calObject.AddProperty(CalendarConstants.Room, CalHelper.CalTextEncode(app.RoomID)); 
                } 
     
               
            } 

    To import data with custom appointments you need to create CustomAppointmentCalendarImporter class which should inherits CalendarImporterBase  class.

    For example:
        public class CustomAppointmentCalendarImporter : CalendarImporterBase 
        { 
            /// <summary> 
            /// Initializes a new instance of the <see cref=" CustomAppointmentCalendarImporter"/> class. 
            /// </summary> 
            public  CustomAppointmentCalendarImporter() : base(new CustomAppointmentFactory()) 
            { 
            } 
     
            /// <summary> 
            /// Initializes a new instance of the <see cref=" CustomAppointmentCalendarImporter"/> class. 
            /// </summary> 
            /// <param name="ignoreParseErrors">If set to <c>true</c> ignore appointment that can not parse.</param> 
            public  CustomAppointmentCalendarImporter(bool ignoreParseErrors) 
                : base(new  CustomAppointmentFactory(), ignoreParseErrors) 
            { 
            } 
     
            /// <summary> 
            /// Writes the additional data for appointment. 
            /// </summary> 
            /// <param name="customappointment">The appointment.</param> 
            /// <param name="calObject">The cal object.</param> 
            protected override void ApplyAdditionalData(IAppointment appointment, CalObject calObject) 
            { 
                var app = ( CustomAppointment)appointment; 
     
             
                CalProperty prop = calObject["Room"]; 
                if (prop != null
                { 
                    app.RoomID= prop.ToText(); 
                } 
            } 
        } 

    And the last class you need to create is CustomAppointmentFactory which will inherit IAppointmentFactory interface.
     public class CustomAppointmentFactory : IAppointmentFactory 
        { 
            public IAppointment CreateNewCustomAppointment() 
            { 
                return new CustomAppointment(); 
            } 
        } 

    Hope this helps.

    Regards,
    Rosi
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.

    Reply

  • LAURIO avatar

    Posted on Mar 25, 2009 (permalink)

    ok nice, i'll try this however as i extended my appointmentBase class, it seems logical to have to make the same for the exporter, i mean it doesn't looks like a bug to my opinion unless you want to automatically "bind" the exporter to class which is instanciate for appointments without having to extend the exporter one. Thanks a lot

    Reply

  • Rosi Rosi admin's avatar

    Posted on Mar 25, 2009 (permalink)

    Hi Laurio,

    With the current implementation of RadScheduler, the CustomAppointment class should inherits the Appointment class so that everything works as expected. Otherwise, you will get the exception even if you extend the exporter class.

    Regards,
    Rosi
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.

    Reply

  • Maarten avatar

    Posted on Jul 20, 2011 (permalink)

    Hello Telerik Team,

    I get an error on the following line:

    calObject.AddProperty(CalendarConstants.Room, CalHelper.CalTextEncode(app.RoomID));

    What can this be? The rest of the code:

    CustomAppointmentCalendarExporter:
    using System.Text;
    using Telerik.Windows.Controls.Scheduler.ICalendar;
    using Telerik.Windows.Controls.Scheduler;
     
    namespace radSchedulerTest
    {
        class CustomAppointmentCalendarExporter : CalendarExporterBase
        {
            protected override void WriteAdditionalDataForAppointment(IAppointment appointment, CalObject calObject)
            {
                var app = appointment as ContactAppointment;
     
                if (app != null) return;
     
                if (app.ContactEmail != null)
                {
                    //calObject.AddProperty();
                }
     
                if (app.ContactName != null)
                {
                    //calObject.AddProperty(CalendarConstants.Contact, CalHelper.
                }
            }
        }
    }

    ContactAppoinment:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Windows.Controls.Scheduler;
     
    namespace radSchedulerTest
    {
        class ContactAppointment : AppointmentBase
        {
            private string contactName;
            private string contactEmail;
     
            public string ContactName
            {
                get
                {
                    return this.contactName;
                }
                set
                {
                    if (contactName != value)
                    {
                        this.contactName = value;
                        this.OnPropertyChanged("ContactName");
                    }
                }
            }
     
            public string ContactEmail
            {
                get
                {
                    return this.contactEmail;
                }
                set
                {
                    if (contactEmail != value)
                    {
                        this.contactEmail = value;
                        this.OnPropertyChanged("ContactEmail");
                    }
                }
            }
             
            public override IAppointment Copy()
            {
                IAppointment appointment = new ContactAppointment();
                appointment.CopyFrom(this);
                return appointment;
            }
     
            public override void CopyFrom(IAppointment other)
            {
                base.CopyFrom(other);
                var appointment = other as ContactAppointment;
                if (appointment != null)
                {
                    ContactName = appointment.ContactName;
                    ContactEmail = appointment.ContactEmail;
                }
            }
        }
    }

    ContactAppointmentCollection:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Windows.Controls.Scheduler;
     
    namespace radSchedulerTest
    {
        class ContactAppointmentCollection : BaseAppointmentCollection<IAppointment>
        {
            public ContactAppointmentCollection()
            {
            }
     
            public ContactAppointmentCollection(IEnumerable<IAppointment> appointments)
                : base(appointments.ToList<IAppointment>())
            {
            }
     
            public override IAppointment CreateNewAppointment()
            {
                return new ContactAppointment();
            }
        }
    }

    If you can, can you give me an example code project?

    Thanks in advance!
    Kind regards,

    Maarten

    Reply

  • Rosi Rosi admin's avatar

    Posted on Jul 25, 2011 (permalink)

    Hello Maarten,

    Could you share details what is the error that you get on the following line:
    calObject.AddProperty(CalendarConstants.Room, CalHelper.CalTextEncode(app.RoomID));

    If it is the same as ""Impossible to Cast an object from type CustomAppointment on telerik.windows.controls.scheduler.Appointment" I suggest you change the code like shown below:

    class ContactAppointment : Appointment
        {
    }


    Best wishes,
    Rosi
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

    Reply

  • Maarten avatar

    Posted on Jul 25, 2011 (permalink)

    Hello Rosi,

    Thanks for you answer.

    I get the following error: The name 'CalendarConstants' does not exist in the current context.

    What are those calendarconstants actually?

    Kind regards,
    Maarten

    Reply

  • Rosi Rosi admin's avatar

    Posted on Jul 28, 2011 (permalink)

    Hi Maarten,

    I suggest you replace this line of code with the following:
    calObject.AddProperty("Room", CalHelper.CalTextEncode(app.RoomID));


    Regards,
    Rosi
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

    Reply

  • Maarten avatar

    Posted on Jul 28, 2011 (permalink)

    Hello Rosi,

    When I do that I get this error:

    Telerik.Windows.Controls.Scheduler.ICalendar.CalHelper does not contain a definition for 'CalTextEncode'

    Kind regards,
    Maarten

    Reply

  • Rosi Rosi admin's avatar

    Posted on Jul 29, 2011 (permalink)

    Hi Maarten,

    I suggest you use the code below:
    calObject.AddProperty("Room", app.RoomID);

    Kind regards,
    Rosi
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

    Reply

  • Maarten avatar

    Posted on Jul 29, 2011 (permalink)

    Hello Rosi,

    I can't get any additional data into my iCal file. I just don't know why.

    Thanks for your help anyway!

    Kind regards,
    Maarten

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > Scheduler > ICal Export with customAppointment
Related resources for "ICal Export with customAppointment"

WPF Scheduler Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]