void CreateChangedOccurrence(Appointment pattern, Event occurrenceEvent) { int indx = CalculateOccurrenceIndex(pattern, occurrenceEvent.OriginalStartTime); Appointment newOccurrence = pattern.CreateException(AppointmentType.ChangedOccurrence, indx); newOccurrence.Start = GoogleCalendarUtils.ConvertDateTime(occurrenceEvent.Start); newOccurrence.End = GoogleCalendarUtils.ConvertDateTime(occurrenceEvent.End); AssignCommonPropertiesTo(newOccurrence, occurrenceEvent); }
void AssingTimeIntervalPropertiesTo(Appointment target, Event source) { if (!source.Start.DateTime.HasValue) { target.AllDay = true; } target.Start = GoogleCalendarUtils.ConvertDateTime(source.Start); target.End = GoogleCalendarUtils.ConvertDateTime(source.End); }
public void Import(IList <Event> events) { Dictionary <string, Appointment> patternHash = new Dictionary <string, Appointment>(); Dictionary <string, Event> occurrenceHash = new Dictionary <string, Event>(); Storage.BeginUpdate(); try { RecurrencePatternParser parser = new RecurrencePatternParser(storage); foreach (Event item in events) { Appointment appointment = null; if (item.RecurringEventId != null) //occurrence? { occurrenceHash.Add(item.Id, item); } else if (item.Recurrence != null) //recurrence { appointment = parser.Parse(item.Recurrence, GoogleCalendarUtils.ConvertDateTime(item.Start), GoogleCalendarUtils.ConvertDateTime(item.End)); //parse and create pattern patternHash.Add(item.Id, appointment); } else //normal appointment { appointment = storage.CreateAppointment(AppointmentType.Normal); AssingTimeIntervalPropertiesTo(appointment, item); } if (appointment == null) { continue; } AssignCommonPropertiesTo(appointment, item); appointment.CustomFields["eventId"] = item.Id; Storage.Appointments.Add(appointment); } LinkOccurrencesWithPatterns(occurrenceHash, patternHash); } finally { Storage.EndUpdate(); } }
int CalculateOccurrenceIndex(Appointment pattern, EventDateTime originalStartTime) { OccurrenceCalculator calculator = OccurrenceCalculator.CreateInstance(pattern.RecurrenceInfo); return(calculator.FindOccurrenceIndex(GoogleCalendarUtils.ConvertDateTime(originalStartTime), pattern)); }