public static void ResetOutlookGoogleAppointmentId(AppointmentsSynchronizer sync, Outlook.AppointmentItem outlookAppointment) { Outlook.UserProperties userProperties = null; try { userProperties = outlookAppointment.UserProperties; for (var i = userProperties.Count; i > 0; i--) { Outlook.UserProperty p = null; try { p = userProperties[i]; if (p.Name == sync.OutlookPropertyNameId || p.Name == sync.OutlookPropertyNameSynced) { userProperties.Remove(i); } } finally { if (p != null) { Marshal.ReleaseComObject(p); } } } } finally { Marshal.ReleaseComObject(userProperties); } }
public static void ResetOutlookGoogleContactId(Synchronizer sync, Outlook.ContactItem outlookContact) { Outlook.UserProperties userProperties = outlookContact.UserProperties; try { Outlook.UserProperty idProp = userProperties[sync.OutlookPropertyNameId]; try { Outlook.UserProperty lastSyncProp = userProperties[sync.OutlookPropertyNameSynced]; try { if (idProp == null && lastSyncProp == null) { return; } List <int> indexesToBeRemoved = new List <int>(); IEnumerator en = userProperties.GetEnumerator(); en.Reset(); int index = 1; // 1 based collection while (en.MoveNext()) { Outlook.UserProperty userProperty = en.Current as Outlook.UserProperty; if (userProperty == idProp || userProperty == lastSyncProp) { indexesToBeRemoved.Add(index); //outlookContact.UserProperties.Remove(index); //Don't return to remove both properties, googleId and lastSynced //return; } index++; Marshal.ReleaseComObject(userProperty); } for (int i = indexesToBeRemoved.Count - 1; i >= 0; i--) { userProperties.Remove(indexesToBeRemoved[i]); } //throw new Exception("Did not find prop."); } finally { if (lastSyncProp != null) { Marshal.ReleaseComObject(lastSyncProp); } } } finally { if (idProp != null) { Marshal.ReleaseComObject(idProp); } } } finally { Marshal.ReleaseComObject(userProperties); } }