All information about an appointment is saved as a single record in an underlying data source. Correspondingly, all appointment properties can be saved to the data source as scalar values (string, integer, boolean, DateTime).
Complex properties and collections (like reminders, resources, recurrence settings) are saved to the data source as XML strings in a corresponding format.
We use corresponding helpers to generate the mentioned XML strings while saving data and restore the mentioned properties/collections while loading appointments.
In some scenarios, it may be required to manually create such strings or parse XML strings obtained from a data source into corresponding objects.
This article describes how to use corresponding XML helpers for this task.
Reminders for Appointments
To generate an XML string containing information about an appointment's reminders, use the ReminderInfoCollectionXmlPersistenceHelper.ToXml method:
C#ReminderInfoCollection someReminders = new ReminderInfoCollection();
someReminders.Add(new ReminderInfo() { AlertTime = DateTime.Now, TimeBeforeStart = TimeSpan.FromMinutes(10) });
ReminderInfoCollectionXmlPersistenceHelper helper = new ReminderInfoCollectionXmlPersistenceHelper(someReminders);
string reminderXML = helper.ToXml();
Visual BasicDim someReminders As New ReminderInfoCollection()
someReminders.Add(New ReminderInfo() With {.AlertTime = DateTime.Now, .TimeBeforeStart = TimeSpan.FromMinutes(10)})
Dim helper As New ReminderInfoCollectionXmlPersistenceHelper(someReminders)
Dim reminderXML As String = helper.ToXml()
The ReminderInfoCollectionXmlPersistenceHelper.ObjectFromXml method can be used to restore a reminder collection from a given XML string:
C#ReminderInfoCollection parsedReminders = new ReminderInfoCollection();
ReminderInfoCollectionXmlPersistenceHelper.ObjectFromXml(parsedReminders, reminderXML);
Visual BasicDim parsedReminders As New ReminderInfoCollection()
ReminderInfoCollectionXmlPersistenceHelper.ObjectFromXml(parsedReminders, reminderXML)
Shared Resources for Appointments
When the Storage.Appointments.ResourceSharing option is enabled, each appointment can be assigned to several resources.
To create an XML string with information about a shared resource collection, use the AppointmentResourceIdCollectionXmlPersistenceHelper.ToXml method:
C#ResourceIdCollection resources = new ResourceIdCollection();
resources.Add(2);
resources.Add(5);
AppointmentResourceIdCollectionXmlPersistenceHelper resourceHelper = new AppointmentResourceIdCollectionXmlPersistenceHelper(resources);
string resourcesInXML = resourceHelper.ToXml();
Visual BasicDim resources As New ResourceIdCollection()
resources.Add(2)
resources.Add(5)
Dim resourceHelper As New AppointmentResourceIdCollectionXmlPersistenceHelper(resources)
Dim resourcesInXML As String = resourceHelper.ToXml()
The AppointmentResourceIdCollectionXmlPersistenceHelper.ObjectFromXml method can be used to restore the resource collection from an XML string:
C#ResourceIdCollection parsedResources = new ResourceIdCollection();
AppointmentResourceIdCollectionXmlPersistenceHelper.ObjectFromXml(parsedResources, resourcesInXML);
Visual BasicDim parsedResources As New ResourceIdCollection()
AppointmentResourceIdCollectionXmlPersistenceHelper.ObjectFromXml(parsedResources, resourcesInXML)
Take special note that starting from v15.2, resource IDs are saved in XML format using Base64 encoding:
Example of an XML string containing information about resources in old versions
XML<ResourceIds>
<ResourceId Type="System.Int32" Value="2" />
<ResourceId Type="System.Int32" Value="5" />
</ResourceIds>
Starting from version 15.2, the same string is encoded:
XML<ResourceIds>
<ResourceId Value="~Xtra#Base64AAEAAAD/////AQAAAAAAAAAEAQAAAAxTeXN0ZW0uSW50MzIBAAAAB21fdmFsdWUACAIAAAAL" />
<ResourceId Value="~Xtra#Base64AAEAAAD/////AQAAAAAAAAAEAQAAAAxTeXN0ZW0uSW50MzIBAAAAB21fdmFsdWUACAUAAAAL" />
</ResourceIds>
To switch back to the previous serialization mechanism, set the static Base64XmlObjectSerialization property to false:
C#protected void Application_Start(object sender, EventArgs e) {
DevExpress.XtraScheduler.SchedulerCompatibility.Base64XmlObjectSerialization = false;
}
Visual BasicProtected Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
DevExpress.XtraScheduler.SchedulerCompatibility.Base64XmlObjectSerialization = False
End Sub
Recurrence Information for Appointments
To generate an XML string with recurrence information for a specific pattern, use the RecurrenceInfo.ToXml method:
C#RecurrenceInfo recInfo = new RecurrenceInfo(); //ASPxScheduler1.SelectedAppointments[0].RecurrenceInfo;
recInfo.Start = DateTime.Now;
recInfo.Type = RecurrenceType.Weekly;
recInfo.Periodicity = 2;
recInfo.WeekDays = WeekDays.Monday | WeekDays.Wednesday;
recInfo.Range = RecurrenceRange.OccurrenceCount;
recInfo.OccurrenceCount = 15;
string recurrenceXML = recInfo.ToXml();
Visual BasicDim recInfo As New RecurrenceInfo() 'ASPxScheduler1.SelectedAppointments[0].RecurrenceInfo;
recInfo.Start = DateTime.Now
recInfo.Type = RecurrenceType.Weekly
recInfo.Periodicity = 2
recInfo.WeekDays = WeekDays.Monday Or WeekDays.Wednesday
recInfo.Range = RecurrenceRange.OccurrenceCount
recInfo.OccurrenceCount = 15
Dim recurrenceXML As String = recInfo.ToXml()
The RecurrenceInfo.FromXml method can be used to restore this information from an XML string:
C#RecurrenceInfo parsedInfo = new RecurrenceInfo();
parsedInfo.FromXml(recurrenceXML);
Visual BasicDim parsedInfo As New RecurrenceInfo()
parsedInfo.FromXml(recurrenceXML)