private void AssignProperties(Appointment apt, Event instance) { instance.Summary = apt.Subject; instance.Description = apt.Description; instance.Location = apt.Location; instance.Start = GoogleCalendarUtils.ConvertEventDateTime(apt.Start); instance.End = GoogleCalendarUtils.ConvertEventDateTime(apt.End); }
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); }
void ExportAppointment(Appointment apt) { AppointmentType aptType = apt.Type; if (aptType == AppointmentType.Pattern) { EnsurePatternId(apt); } else if (aptType != AppointmentType.Normal) { string eventPatternId = EnsurePatternId(apt.RecurrencePattern); Debug.Assert(!String.IsNullOrEmpty(eventPatternId)); if (aptType == AppointmentType.Occurrence) { return; } EventsResource.InstancesRequest instancesRequest = CalendarService.Events.Instances(CalendarEntry.Id, eventPatternId); OccurrenceCalculator calculator = OccurrenceCalculator.CreateInstance(apt.RecurrencePattern.RecurrenceInfo); instancesRequest.OriginalStart = GoogleCalendarUtils.ConvertEventDateTime(calculator.CalcOccurrenceStartTime(apt.RecurrenceIndex)).DateTimeRaw; Events occurrenceEvents = instancesRequest.Execute(); Debug.Assert(occurrenceEvents.Items.Count == 1); Event occurrence = occurrenceEvents.Items[0]; if (aptType == AppointmentType.ChangedOccurrence) { this.AssignProperties(apt, occurrence); } else if (aptType == AppointmentType.DeletedOccurrence) { occurrence.Status = "cancelled"; } Event changedOccurrence = CalendarService.Events.Update(occurrence, CalendarEntry.Id, occurrence.Id).Execute(); apt.CustomFields["eventId"] = changedOccurrence.Id; Log.WriteLine(String.Format("Exported {0} occurrance: {1}, id={2}", (aptType == AppointmentType.ChangedOccurrence) ? "changed" : "deleted", apt.Subject, changedOccurrence.Id)); return; } Event instance = this.CreateEvent(aptType); AssignProperties(apt, instance); Event result = CalendarService.Events.Insert(instance, CalendarEntry.Id).Execute(); Log.WriteLine(String.Format("Exported appointment: {0}, id={1}", apt.Subject, result.Id)); }
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)); }