示例#1
0
 public static void SetOutlookLastSync(Synchronizer sync, Outlook.ContactItem outlookContact)
 {
     //save sync datetime
     Outlook.UserProperties userProperties = outlookContact.UserProperties;
     try
     {
         Outlook.UserProperty prop = userProperties[sync.OutlookPropertyNameSynced];
         if (prop == null)
         {
             prop = userProperties.Add(sync.OutlookPropertyNameSynced, Outlook.OlUserPropertyType.olDateTime, true);
         }
         try
         {
             prop.Value = DateTime.Now;
         }
         finally
         {
             Marshal.ReleaseComObject(prop);
         }
     }
     finally
     {
         Marshal.ReleaseComObject(userProperties);
     }
 }
        public static void SetOutlookLastSync(AppointmentsSynchronizer sync, Outlook.AppointmentItem outlookAppointment)
        {
            //save sync datetime
            Outlook.UserProperties userProperties = null;
            Outlook.UserProperty   prop           = null;
            try
            {
                userProperties = outlookAppointment.UserProperties;
                prop           = userProperties[sync.OutlookPropertyNameSynced];
                if (prop == null)
                {
                    prop = userProperties.Add(sync.OutlookPropertyNameSynced, Outlook.OlUserPropertyType.olDateTime, false);
                }

                prop.Value = DateTime.Now;
            }
            finally
            {
                if (prop != null)
                {
                    Marshal.ReleaseComObject(prop);
                }
                if (userProperties != null)
                {
                    Marshal.ReleaseComObject(userProperties);
                }
            }
        }
示例#3
0
 private void SetMailItemUserProperty(Outlook.MailItem mailItem, object item)
 {
     Outlook.UserProperties mailUserProperties = mailItem.UserProperties;
     Outlook.UserProperty   propJobMetaData    = null;
     try
     {
         // Where 1 is OlFormatText (introduced in Outlook 2007)
         propJobMetaData = mailUserProperties.Add("JobMetaData", Outlook.OlUserPropertyType.olText, false, 1);
         //IList<Recruiter.JobItem> list = iRecruiter.IncludedJobItems.Values.ToList();
         string temp = JsonConvert.SerializeObject(item);
         propJobMetaData.Value = temp;
         //propJobMetaData.Value = htmlResults;
         mailItem.Save();
         //
     }
     catch (Exception)
     {
         //MessageBox.Show( ex.Message );
     }
     finally
     {
         if (propJobMetaData != null)
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(propJobMetaData);
         }
         if (propJobMetaData != null)
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(mailUserProperties);
         }
     }
     //
 }
示例#4
0
        public void MenuLabel_ButtonAction(Office.IRibbonControl control)
        {
            Debug.WriteLine("RibbonLabel: MenuLabel_ButtonAction");
            Debug.WriteLine("==============================================================================");

            string buttonIndexText   = control.Id.Substring(ButtonIdPrefix.Length);
            int    selectedItemIndex = int.Parse(buttonIndexText);

            object context     = null;
            object currentItem = null;

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

            try
            {
                context = control.Context;
                var inspector = (Outlook.Inspector)context;
                currentItem = inspector.CurrentItem;

                if (currentItem is Outlook.AppointmentItem item)
                {
                    // Set selected item index to temporary label property to be read on send
                    userProperties     = item.UserProperties;
                    userProperty       = userProperties.Add(PspfMarkingsAddIn.TemporaryLabelPropertyName, Outlook.OlUserPropertyType.olInteger);
                    userProperty.Value = selectedItemIndex;
                    //item.Save();

                    UpdateSubject(item, selectedItemIndex);
                }
            }
            finally
            {
                if (userProperty != null)
                {
                    Marshal.ReleaseComObject(userProperty);
                }

                if (userProperties != null)
                {
                    Marshal.ReleaseComObject(userProperties);
                }

                if (currentItem != null)
                {
                    Marshal.ReleaseComObject(currentItem);
                }

                if (context != null)
                {
                    Marshal.ReleaseComObject(context);
                }
            }
        }
        /// <summary>
        /// Sets the syncId of the Outlook contact and the last sync date.
        /// Please assure to always call this function when saving OutlookItem
        /// </summary>
        /// <param name="sync"></param>
        /// <param name="outlookContact"></param>
        /// <param name="googleContact"></param>
        public static void SetOutlookGoogleContactId(ContactsSynchronizer sync, Outlook.ContactItem outlookContact, Contact googleContact)
        {
            if (googleContact.ContactEntry.Id.Uri == null)
            {
                throw new NullReferenceException("GoogleContact must have a valid Id");
            }

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

            try
            {
                userProperties = outlookContact.UserProperties;
                prop           = userProperties[sync.OutlookPropertyNameId];
                //check if outlook contact aready has google id property.
                if (prop == null)
                {
                    prop = userProperties.Add(sync.OutlookPropertyNameId, Outlook.OlUserPropertyType.olText, false);
                }

                prop.Value = googleContact.ContactEntry.Id.Uri.Content;
            }
            catch (Exception ex)
            {
                Logger.Log(ex, EventType.Debug);
                Logger.Log("Name: " + sync.OutlookPropertyNameId, EventType.Debug);
                Logger.Log("Value: " + googleContact.ContactEntry.Id.Uri.Content, EventType.Debug);
                throw;
            }
            finally
            {
                if (prop != null)
                {
                    Marshal.ReleaseComObject(prop);
                }
                if (userProperties != null)
                {
                    Marshal.ReleaseComObject(userProperties);
                }
            }
            SetOutlookLastSync(sync, outlookContact);
        }
示例#6
0
        /// <summary>
        /// Sets the syncId of the Outlook contact and the last sync date.
        /// Please assure to always call this function when saving OutlookItem
        /// </summary>
        /// <param name="sync"></param>
        /// <param name="outlookContact"></param>
        /// <param name="googleContact"></param>
        public static void SetOutlookGoogleContactId(Synchronizer sync, Outlook.ContactItem outlookContact, Contact googleContact)
        {
            if (googleContact.ContactEntry.Id.Uri == null)
            {
                throw new NullReferenceException("GoogleContact must have a valid Id");
            }

            //check if outlook contact aready has google id property.
            Outlook.UserProperties userProperties = outlookContact.UserProperties;
            try
            {
                Outlook.UserProperty prop = userProperties[sync.OutlookPropertyNameId];
                if (prop == null)
                {
                    prop = userProperties.Add(sync.OutlookPropertyNameId, Outlook.OlUserPropertyType.olText, true);
                }
                try
                {
                    prop.Value = googleContact.ContactEntry.Id.Uri.Content;
                }
                finally
                {
                    Marshal.ReleaseComObject(prop);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(userProperties);
            }

            //save last google's updated date as property

            /*prop = outlookContact.UserProperties[OutlookPropertyNameUpdated];
             * if (prop == null)
             *  prop = outlookContact.UserProperties.Add(OutlookPropertyNameUpdated, Outlook.OlUserPropertyType.olDateTime, null, null);
             * prop.Value = googleContact.Updated;*/

            //Also set the OutlookLastSync date when setting a match between Outlook and Google to assure the lastSync updated when Outlook contact is saved afterwards
            SetOutlookLastSync(sync, outlookContact);
        }
示例#7
0
 private static void EncryptMail(Outlook.MailItem mail)
 {
     Outlook.UserProperties userProperties = null;
     Outlook.UserProperty   userProperty   = null;
     try
     {
         userProperties     = mail.UserProperties;
         userProperty       = userProperties.Add("SDSEncrypt", Outlook.OlUserPropertyType.olYesNo, false, 1);
         userProperty.Value = true;
     }
     finally
     {
         if (userProperty != null)
         {
             Marshal.ReleaseComObject(userProperty);
         }
         if (userProperties != null)
         {
             Marshal.ReleaseComObject(userProperties);
         }
     }
 }
        public void SetUserProperty <Type>(string name, Type value)
        {
            using (ComRelease com = new ComRelease())
            {
                NSOutlook.UserProperties userProperties = com.Add(GetUserProperties());
                NSOutlook.UserProperty   prop           = com.Add(userProperties.Find(name, true));
                if (prop == null)
                {
                    prop = userProperties.Add(name, Mapping.OutlookPropertyType <Type>());
                }

                if (typeof(Type).IsEnum)
                {
                    int i = Array.FindIndex(typeof(Type).GetEnumNames(), n => n.Equals(value.ToString()));
                    prop.Value = typeof(Type).GetEnumValues().GetValue(i);
                }
                else
                {
                    prop.Value = value;
                }
            }
        }