A newer version of this page is available. Switch to the current version.

OccurrenceCalculator Class

Enables you to calculate the occurrences for a given recurrent appointment.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v18.2.Core.dll

Declaration

public abstract class OccurrenceCalculator
Public MustInherit Class OccurrenceCalculator

Related API Members

The following members accept/return OccurrenceCalculator objects:

Remarks

Use the OccurrenceCalculator object to calculate occurrences for a predefined time interval, as illustrated in the code sample below.

NOTE

The calculated appointments do not contain custom fields. This behavior is by design; it increases performance.

If you need to construct the actual recurrence appointment series with both standard and custom appointment fields, then you have to use the AppointmentPatternExpander.Expand method from the DevExpress.XtraScheduler.Native namespace. Create a new AppointmentPatternExpander instance using the Appointment.RecurrencePattern value of your appointment, and then call the Expand method to get the appointments collection.

Examples

The following code sample retrieves the recurrence pattern of the first appointment in the scheduler's collection and replaces all occurrences with appointments of AppointmentType.Normal type. It utilizes the OccurrenceCalculator.CalcOccurrences method to calculate items in the recurrent series.

// Calculate occurrences for the first recurrent series.
Appointment pattern = schedulerStorage1.Appointments.Items.FirstOrDefault(item => item.Type == AppointmentType.Pattern);
if (pattern == null) return;
OccurrenceCalculator calc = OccurrenceCalculator.CreateInstance(pattern.RecurrenceInfo);
TimeInterval processedInterval = new TimeInterval(DateTime.Today, DateTime.Today.AddDays(7));
AppointmentBaseCollection calculatedOccurrences = calc.CalcOccurrences(processedInterval, pattern);

// Create normal appointments in place of occurrences.
schedulerStorage1.BeginUpdate();
for (int i = 0; i < calculatedOccurrences.Count; i++) {
    Appointment resultAppointment = schedulerStorage1.CreateAppointment(AppointmentType.Normal);
    resultAppointment.Subject = String.Format("Occurrence {0} - {1}", calculatedOccurrences[i].Subject, i);
    resultAppointment.Description = calculatedOccurrences[i].Description;
    resultAppointment.Start = calculatedOccurrences[i].Start;
    resultAppointment.End = calculatedOccurrences[i].End;
    schedulerStorage1.Appointments.Add(resultAppointment);
}
schedulerStorage1.EndUpdate();

// Remove the pattern and occurrences.
schedulerStorage1.Appointments.Remove(pattern);

Inheritance

Object
OccurrenceCalculator
See Also