I am listening to the Items.ItemChange() event on a MAPIFolder, and triggering this event handler when it fires:
private async void monitor_AppointmentModified(object sender, EventArgs<AppointmentItem> e)
{
var item = e.Value;
Debug.Print("Outlook Appointment Modified: {0}", item.GlobalAppointmentID);
try
{
var result = await GCalUtils.ModifyEventAsync(item);
}
catch (Exception ex)
{
PrintToDebug(ex);
}
}
Which calls a utility class to push the modified event to google calendar:
public static async Task<Event> ModifyEventAsync(AppointmentItem item, string calendarId = PrimaryCalendarId)
{
var gCalEventId = item.UserProperties.Find(Resources.GCalId);
var updateRequest = Service.Events.Update(item.AsGCalEvent(), calendarId, gCalEventId.Value.ToString());
var result = await updateRequest.ExecuteAsync() as Event;
if (result != null && item.IsRecurring)
ModifyRecurrences(item, calendarId, result.Id);
return result;
}
...so if the item is a recurring AppointmentItem, I call ModifyRecurrences:
private static async void ModifyRecurrences(AppointmentItem item, string calendarId, string eventId)
{
var exceptions = item.GetRecurrencePattern().Exceptions.Cast<Microsoft.Office.Interop.Outlook.Exception>().ToList();
if (!exceptions.Any()) return;
// other stuff happens... eventually... hopefully
}
... but regardless of what I actually did to an occurrence of the series, whether I move an item to a new time, adjust the start or end time, or delete the item entirely, the exceptions.Any()
call always returns false. There are never any exceptions in the collection, and if I understand the concepts correctly then by modifying an instance of the recurring series I have just created an exception and it should show up in the Exceptions collection.
I suspect I may have a stale copy of the AppointmentItem, but I've not a clue how to verify that.