private static void DeleteUserSelectedMarking(Outlook.MeetingItem item)
        {
            Debug.WriteLine("PspfMarkingsAddIn: DeleteUserSelectedMarking");
            Debug.WriteLine("==============================================================================");

            Outlook.UserProperties userProperties = null;
            Outlook.UserProperty   userProperty   = null;

            try
            {
                userProperties = item.UserProperties;
                userProperty   = userProperties[TemporaryLabelPropertyName];
                if (userProperty != null)
                {
                    userProperty.Delete();
                }
            }
            finally
            {
                if (userProperty != null)
                {
                    Marshal.ReleaseComObject(userProperty);
                }

                if (userProperties != null)
                {
                    Marshal.ReleaseComObject(userProperties);
                }
            }
        }
Beispiel #2
0
 /// <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.TaskItem olItem, string name)
 {
     Outlook.UserProperty olProperty = olItem.UserProperties[name];
     if (olProperty != null)
     {
         olProperty.Delete();
     }
 }
        /// <summary>
        /// Set the CRM id for this item to this value.
        /// </summary>
        /// <param name="olItem">The Outlook item under consideration.</param>
        /// <param name="crmId">The value to set.</param>
        public static void SetCrmId(this Outlook.AppointmentItem olItem, CrmId crmId)
        {
            Outlook.UserProperty property = olItem.UserProperties[SyncStateManager.CrmIdPropertyName];

            if (property == null)
            {
                property = olItem.UserProperties.Add(SyncStateManager.CrmIdPropertyName, Outlook.OlUserPropertyType.olText);
                SyncStateManager.Instance.SetByCrmId(crmId, SyncStateManager.Instance.GetOrCreateSyncState(olItem));
            }
            if (CrmId.IsInvalid(crmId))
            {
                property.Delete();
            }
            else
            {
                property.Value = crmId.ToString();
            }
        }
Beispiel #4
0
        public void FixUserProperties()
        {
            Outlook.Application outlookApp;
            Outlook.NameSpace   outlookNamespace;
            Outlook.Items       outlookContacts;

            outlookApp = new Outlook.Application();

            outlookNamespace = outlookApp.GetNamespace("mapi");

            outlookNamespace.Logon("Outlook", null, true, false);

            try
            {
                Outlook.MAPIFolder contactsFolder = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
                outlookContacts = contactsFolder.Items;

                string oldPrefixId      = string.Format("google/contacts/{0}/id", ConfigurationManager.AppSettings["Gmail.Username"]);
                string oldPrefixUpdated = string.Format("google/contacts/{0}/updated", ConfigurationManager.AppSettings["Gmail.Username"]);

                int hashCode = ConfigurationManager.AppSettings["Gmail.Username"].GetHashCode();

                int    maxUserIdLength = 32 - ("g/con/" + "/up").Length;
                string userId          = ConfigurationManager.AppSettings["Gmail.Username"];
                if (userId.Length > maxUserIdLength)
                {
                    userId = userId.GetHashCode().ToString("X"); //if a user id would overflow UserProperty name, then use that user id hash code as id.
                }
                string newPrefixId      = "g/con/" + userId + "/id";
                string newPrefixUpdated = "g/con/" + userId + "/up";

                //max property length: 32

                //foreach (Outlook.ContactItem contact in outlookContacts)
                for (int i = 0; i < outlookContacts.Count; i++)
                {
                    try
                    {
                        if (!(outlookContacts[i] is Outlook.ContactItem))
                        {
                            continue;
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    Outlook.ContactItem contact = outlookContacts[i] as Outlook.ContactItem;

                    Outlook.UserProperty updatedProp = contact.UserProperties[newPrefixUpdated];
                    if (updatedProp != null)
                    {
                        string lastUpdatedStr = (string)updatedProp.Value;
                        updatedProp.Delete();

                        updatedProp = contact.UserProperties.Add(newPrefixUpdated, Outlook.OlUserPropertyType.olDateTime, true);
                        DateTime lastUpdated = DateTime.Parse(lastUpdatedStr);
                        updatedProp.Value = lastUpdated;

                        if (!contact.Saved)
                        {
                            contact.Save();
                        }

                        continue;
                    }

                    Outlook.UserProperty prop = contact.UserProperties[newPrefixId];
                    if (prop != null)
                    {
                        continue;
                    }

                    prop = contact.UserProperties[oldPrefixId];
                    if (prop != null)
                    {
                        string id = (string)prop.Value;
                        prop.Delete();

                        prop       = contact.UserProperties.Add(newPrefixId, Outlook.OlUserPropertyType.olText, true);
                        prop.Value = id;
                    }

                    prop = contact.UserProperties[oldPrefixUpdated];
                    if (prop != null)
                    {
                        DateTime lastUpdated = (DateTime)prop.Value;
                        prop.Delete();

                        prop       = contact.UserProperties.Add(newPrefixUpdated, Outlook.OlUserPropertyType.olDateTime, true);
                        prop.Value = lastUpdated;
                    }

                    if (!contact.Saved)
                    {
                        contact.Save();
                    }
                }
            }
            finally
            {
                outlookNamespace.Logoff();
            }
        }