/// <summary> /// Get the CRM id for this item, if known, else the empty string. /// </summary> /// <param name="olItem">The Outlook item under consideration.</param> /// <returns>the CRM id for this item, if known, else the empty string.</returns> public static CrmId GetCrmId(this Outlook.ContactItem olItem) { Outlook.UserProperty property = olItem.UserProperties[SyncStateManager.CrmIdPropertyName]; CrmId result = property != null?CrmId.Get(property.Value) : CrmId.Empty; return(result); }
/// <summary> /// Set this item as manually syncable, briefly. As a side effect of making the change triggers sync. /// </summary> /// <remarks>In order to allow manual sync, we need to be able to override the disablement of syncing - /// but only briefly.</remarks> /// <param name="olItem">The item which may be synced despite syncing being disabled</param> public static void SetManualOverride(this Outlook.ContactItem olItem) { var p = olItem.UserProperties.Add(OverridePropertyName, Outlook.OlUserPropertyType.olDateTime); p.Value = DateTime.UtcNow; olItem.Save(); }
public static void ClearCrmId(this Outlook.ContactItem olItem) { var state = SyncStateManager.Instance.GetExistingSyncState(olItem); olItem.ClearUserProperty(SyncStateManager.CrmIdPropertyName); if (state != null) { state.CrmEntryId = null; } olItem.Save(); }
public static void ChangeCrmId(this Outlook.ContactItem olItem, string text) { var crmId = new CrmId(text); var state = SyncStateManager.Instance.GetExistingSyncState(olItem); var userProperty = olItem.UserProperties.Find(SyncStateManager.CrmIdPropertyName) ?? olItem.UserProperties.Add(SyncStateManager.CrmIdPropertyName, Outlook.OlUserPropertyType.olText); userProperty.Value = crmId.ToString(); if (state != null) { state.CrmEntryId = crmId; } olItem.Save(); }
/// <summary> /// True if the override window is open for this item. /// </summary> /// <remarks>In order to allow manual sync, we need to be able to override the disablement of syncing - /// but only briefly.</remarks> /// <param name="olItem">The item which we wish to sync.</param> /// <returns>True if the manual sync window is open for this item.</returns> public static bool IsManualOverride(this Outlook.ContactItem olItem) { bool result = false; if (olItem.UserProperties[OverridePropertyName] != null) { DateTime value = olItem.UserProperties[OverridePropertyName].Value; if ((DateTime.UtcNow - value).Minutes < OverrideWindowMinutes) { result = true; } else { /* no point holding on to a timed-out manual override property */ olItem.ClearManualOverride(); } } return(result); }
/// <summary> /// Removed the specified user property from this item. /// </summary> /// <param name="olItem">The item from which the property should be removed.</param> /// <param name="name">The name of the property to remove.</param> public static void ClearUserProperty(this Outlook.ContactItem olItem, string name) { olItem.UserProperties[name]?.Delete(); }
/// <summary> /// Remove all the synchronisation properties from this item. /// </summary> /// <param name="olItem">The item from which the property should be removed.</param> public static void ClearSynchronisationProperties(this Outlook.ContactItem olItem) { olItem.ClearUserProperty(SyncStateManager.CrmIdPropertyName); olItem.ClearUserProperty(SyncStateManager.ModifiedDatePropertyName); olItem.ClearUserProperty(SyncStateManager.TypePropertyName); }
/// <summary> /// Clear the manually syncability of this item; does not break is manual sync was not set. /// </summary> /// <remarks>In order to allow manual sync, we need to be able to override the disablement of syncing - /// but only briefly.</remarks> /// <param name="olItem">The item which may be synced despite syncing being disabled</param> public static void ClearManualOverride(this Outlook.ContactItem olItem) { olItem.UserProperties[OverridePropertyName]?.Delete(); }
private void DoEnumContacts() { if (btnMode.State == AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown) { securityManager1.DisableOOMWarnings = true; } try { Outlook.NameSpace namespace_ = OutlookApp.GetNamespace("MAPI"); if (namespace_ != null) { try { Outlook.MAPIFolder folder = namespace_.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); if (folder != null) { try { ContactsForm frmContacts = new ContactsForm(); try { Outlook.Items items = folder.Items; if (items != null) { try { for (int i = 1; i <= items.Count; i++) { Outlook.ContactItem contact = items.Item(i) as Outlook.ContactItem; if (contact != null) { try { if (!string.IsNullOrEmpty(contact.Email1DisplayName)) { DataRow newRow = frmContacts.dsContacts.Tables["Contacts"].NewRow(); newRow["DisplayName"] = contact.Email1DisplayName; newRow["Address"] = contact.Email1Address; newRow["AddressType"] = contact.Email1AddressType; frmContacts.dsContacts.Tables["Contacts"].Rows.Add(newRow); } if (!string.IsNullOrEmpty(contact.Email2DisplayName)) { DataRow newRow = frmContacts.dsContacts.Tables["Contacts"].NewRow(); newRow["DisplayName"] = contact.Email2DisplayName; newRow["Address"] = contact.Email2Address; newRow["AddressType"] = contact.Email2AddressType; frmContacts.dsContacts.Tables["Contacts"].Rows.Add(newRow); } if (!string.IsNullOrEmpty(contact.Email3DisplayName)) { DataRow newRow = frmContacts.dsContacts.Tables["Contacts"].NewRow(); newRow["DisplayName"] = contact.Email3DisplayName; newRow["Address"] = contact.Email3Address; newRow["AddressType"] = contact.Email3AddressType; frmContacts.dsContacts.Tables["Contacts"].Rows.Add(newRow); } } finally { Marshal.ReleaseComObject(contact); } } } } finally { Marshal.ReleaseComObject(items); } } } catch { } frmContacts.ShowDialog(); frmContacts.Dispose(); } finally { Marshal.ReleaseComObject(folder); } } } finally { Marshal.ReleaseComObject(namespace_); } } } finally { if (btnMode.State == AddinExpress.MSO.ADXMsoButtonState.adxMsoButtonDown) { securityManager1.DisableOOMWarnings = false; } } }