/// <summary> /// Merges the with. /// </summary> /// <param name="googleCalendarItem">The google calendar item.</param> /// <param name="outlookCalendarItem">The outlook calendar item.</param> /// <returns>True if Changed.</returns> public static bool MergeWith(this EventEntry googleCalendarItem, AppointmentItem outlookCalendarItem) { var result = false; result |= googleCalendarItem.Title.ApplyProperty(g => g.Text, outlookCalendarItem.Subject); result |= googleCalendarItem.Content.ApplyProperty(g => g.Content, outlookCalendarItem.Body); if (googleCalendarItem.EventTransparency == null) { googleCalendarItem.EventTransparency = new EventEntry.Transparency(); } result |= googleCalendarItem.EventTransparency.ApplyProperty(g => g.Value, outlookCalendarItem.BusyStatus.GetStatus()); if (googleCalendarItem.EventVisibility == null) { googleCalendarItem.EventVisibility = new EventEntry.Visibility(); } result |= googleCalendarItem.EventVisibility.ApplyProperty(g => g.Value, outlookCalendarItem.Sensitivity.GetStatus()); result |= googleCalendarItem.Locations.Merge(outlookCalendarItem.Location); result |= googleCalendarItem.Participants.Merge(outlookCalendarItem); if (outlookCalendarItem.RecurrenceState == OlRecurrenceState.olApptNotRecurring) { When time = googleCalendarItem.Times.FirstOrInstance(); if (!googleCalendarItem.Times.Any()) { googleCalendarItem.Times.Add(time); } result |= time.ApplyProperty(t => t.AllDay, outlookCalendarItem.AllDayEvent); result |= time.ApplyProperty(t => t.StartTime, outlookCalendarItem.Start); result |= time.ApplyProperty(t => t.EndTime, outlookCalendarItem.End); if (outlookCalendarItem.ReminderSet) { Google.GData.Extensions.Reminder reminder = time.Reminders.FirstOrInstance(t => t.Method == Google.GData.Extensions.Reminder.ReminderMethod.alert); var timespan = TimeSpan.FromMinutes(outlookCalendarItem.ReminderMinutesBeforeStart); result |= reminder.ApplyProperty(r => r.Method, Google.GData.Extensions.Reminder.ReminderMethod.alert); result |= reminder.ApplyProperty(r => r.Minutes, timespan.Minutes); result |= reminder.ApplyProperty(r => r.Hours, timespan.Hours); result |= reminder.ApplyProperty(r => r.Days, timespan.Days); } } else { if (googleCalendarItem.Recurrence == null) { googleCalendarItem.Recurrence = new Recurrence(); } result |= googleCalendarItem.Recurrence.ApplyProperty(r => r.Value, RecurrenceSerializer.Serialize(outlookCalendarItem.GetRecurrencePattern(), outlookCalendarItem.Start, outlookCalendarItem.AllDayEvent)); } return(result); }
/// <summary> /// Merges the recurrence. /// </summary> /// <param name="outlookCalendarItem">The outlook calendar item.</param> /// <param name="recurrence">The recurrence.</param> /// <returns>True if Change.</returns> public static bool MergeRecurrence(this AppointmentItem outlookCalendarItem, Recurrence recurrence) { if (recurrence != null && !string.IsNullOrWhiteSpace(recurrence.Value)) { var result = false; var outlookRecurrencePattern = outlookCalendarItem.GetRecurrencePattern(); var googleRecurrencePattern = RecurrenceSerializer.Deserialize(recurrence.Value); try { result |= outlookCalendarItem.ApplyProperty(r => r.AllDayEvent, googleRecurrencePattern.AllDayEvent); } catch (TargetInvocationException) { } result |= outlookRecurrencePattern.ApplyProperty(r => r.RecurrenceType, googleRecurrencePattern.RecurrenceType); result |= outlookRecurrencePattern.ApplyProperty(r => r.PatternStartDate, googleRecurrencePattern.StartPattern.HasValue ? googleRecurrencePattern.StartPattern.Value.Date : DateTime.Today); if (googleRecurrencePattern.EndPattern.HasValue) { result |= outlookRecurrencePattern.ApplyProperty(r => r.PatternEndDate, googleRecurrencePattern.EndPattern.Value.Date); } else { result |= outlookRecurrencePattern.ApplyProperty(r => r.NoEndDate, true); } result |= outlookRecurrencePattern.ApplyProperty(r => r.DayOfMonth, googleRecurrencePattern.DayOfMonth); result |= outlookRecurrencePattern.ApplyProperty(r => r.DayOfWeekMask, googleRecurrencePattern.DayOfWeek); result |= outlookRecurrencePattern.ApplyProperty(r => r.MonthOfYear, googleRecurrencePattern.MonthOfYear); if (outlookRecurrencePattern.StartTime.TimeOfDay.Ticks != googleRecurrencePattern.StartTime.TimeOfDay.Ticks) { result |= outlookRecurrencePattern.ApplyProperty(r => r.StartTime, googleRecurrencePattern.StartTime); } if (outlookRecurrencePattern.EndTime.TimeOfDay.Ticks != googleRecurrencePattern.EndTime.TimeOfDay.Ticks) { result |= outlookRecurrencePattern.ApplyProperty(r => r.EndTime, googleRecurrencePattern.EndTime); } if (googleRecurrencePattern.Count.HasValue) { result |= outlookRecurrencePattern.ApplyProperty(r => r.Occurrences, googleRecurrencePattern.Count.Value); } if (googleRecurrencePattern.Interval.HasValue) { result |= outlookRecurrencePattern.ApplyProperty(r => r.Interval, googleRecurrencePattern.Interval.Value); } return(result); } if (outlookCalendarItem.RecurrenceState == OlRecurrenceState.olApptNotRecurring) { outlookCalendarItem.ClearRecurrencePattern(); return(true); } return(false); }