public static string GetOutlookGoogleAppointmentId(AppointmentsSynchronizer sync, Outlook.AppointmentItem outlookAppointment)
        {
            string id = null;

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

            try
            {
                userProperties = outlookAppointment.UserProperties;
                idProp         = userProperties[sync.OutlookPropertyNameId];
                if (idProp != null)
                {
                    id = (string)idProp.Value;
                }
            }
            finally
            {
                if (idProp != null)
                {
                    Marshal.ReleaseComObject(idProp);
                }
                if (userProperties != null)
                {
                    Marshal.ReleaseComObject(userProperties);
                }
            }
            return(id);
        }
Ejemplo n.º 2
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);
         }
     }
     //
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
        public static DateTime?GetOutlookLastSync(Synchronizer sync, Outlook.ContactItem outlookContact)
        {
            DateTime?result = null;

            Outlook.UserProperties userProperties = outlookContact.UserProperties;
            try
            {
                Outlook.UserProperty prop = userProperties[sync.OutlookPropertyNameSynced];
                if (prop != null)
                {
                    try
                    {
                        result = (DateTime)prop.Value;
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(prop);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(userProperties);
            }
            return(result);
        }
Ejemplo n.º 5
0
        private object GetMailItemUserProperty(Outlook.UserProperties mailUserProperties)
        {
            object result = null;

            //Outlook.UserProperties mailUserProperties = mailItem.UserProperties;
            Outlook.UserProperty propJobMetaData = mailUserProperties.Find("JobMetaData");
            if (propJobMetaData != null)
            {
                try
                {
                    IList <Recruiter.JobItem> list = JsonConvert.DeserializeObject <IList <Recruiter.JobItem> >(propJobMetaData.Value);
                    //if (list.Count == 0)
                    result = list;
                    //this.jobListTaskPane.AddJobsInfo( list );
                }
                catch// (Exception ex)
                {
                    try
                    {
                        result = JsonConvert.DeserializeObject <ILetter>(propJobMetaData.Value);
                    }
                    catch// (Exception ex0)
                    {
                        //result = JsonConvert.DeserializeObject<NonJobLetter>( propJobMetaData.Value )
                    }
                    //
                }
            }

            return(result);
        }
        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);
                }
            }
        }
        public static DateTime?GetOutlookLastSync(AppointmentsSynchronizer sync, Outlook.AppointmentItem outlookAppointment)
        {
            DateTime?result = null;

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

            try
            {
                userProperties = outlookAppointment.UserProperties;
                prop           = userProperties[sync.OutlookPropertyNameSynced];
                if (prop != null)
                {
                    result = (DateTime)prop.Value;
                }
            }
            finally
            {
                if (prop != null)
                {
                    Marshal.ReleaseComObject(prop);
                }
                if (userProperties != null)
                {
                    Marshal.ReleaseComObject(userProperties);
                }
            }
            return(result);
        }
        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);
                }
            }
        }
        private static ProtectiveMarking GetUserSelectedMarking(Outlook.MeetingItem item)
        {
            Debug.WriteLine("PspfMarkingsAddIn: GetUserSelectedMarking");
            Debug.WriteLine("==============================================================================");

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

            try
            {
                userProperties = item.UserProperties;
                userProperty   = userProperties[TemporaryLabelPropertyName];
                if (userProperty != null)
                {
                    return(Config.Current.ProtectiveMarkings[userProperty.Value]);
                }
            }
            finally
            {
                if (userProperty != null)
                {
                    Marshal.ReleaseComObject(userProperty);
                }

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

            return(null);
        }
Ejemplo n.º 10
0
        public static string GetOutlookGoogleContactId(Synchronizer sync, Outlook.ContactItem outlookContact)
        {
            string id = null;

            Outlook.UserProperties userProperties = outlookContact.UserProperties;
            try
            {
                Outlook.UserProperty idProp = userProperties[sync.OutlookPropertyNameId];
                if (idProp != null)
                {
                    try
                    {
                        id = (string)idProp.Value;
                        if (id == null)
                        {
                            throw new Exception();
                        }
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(idProp);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(userProperties);
            }
            return(id);
        }
        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);
            }
        }
Ejemplo n.º 12
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);
                }
            }
        }
        public Type GetUserProperty <Type>(string name)
        {
            using (ComRelease com = new ComRelease())
            {
                NSOutlook.UserProperties userProperties = com.Add(GetUserProperties());
                NSOutlook.UserProperty   prop           = com.Add(userProperties.Find(name, true));
                if (prop == null)
                {
                    return(default(Type));
                }

                if (typeof(Type).IsEnum)
                {
                    return(typeof(Type).GetEnumValues().GetValue(prop.Value));
                }
                return(prop.Value);
            }
        }
        /// <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);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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;
                }
            }
        }
        private String syncFromOutlookToCrm()
        {
            printLogMsg(string.Format("Synchronizing appointments from Outlook to CRM."));

            if (log)
            {
                serviceProxy.WriteInfo("++++++WebService: syncFromCrmToOutlook");
            }

            try
            {
                Stopwatch swGetFolder = new Stopwatch();
                swGetFolder.Start();
                Outlook.Folder calFolder = GetFolder(outlookCalendarID, outlookCalendarStoreID);
                swGetFolder.Stop();

                DateTime start = DateTime.Now.AddDays(-rangeDateBack);
                DateTime end   = DateTime.Now.AddDays(rangeDateNext);

                Stopwatch swGetApps = new Stopwatch();
                swGetApps.Start();
                Outlook.Items rangeAppts = OutlookMgt.GetAppointmentsInRange(calFolder, start, end, this.lastSyncTime);
                swGetApps.Stop();

                Stopwatch swCntApps = new Stopwatch();
                swCntApps.Start();
                int apptCount = 0;

                //Ez a rész túl sokáig fut, holott csak számlálást végez. Megoldást kell keresni rá.
                if (rangeAppts != null)
                {
                    foreach (Outlook.AppointmentItem appt in rangeAppts)
                    {
                        ////B12773_CRMOutlookPluginIssues MGY 2016.07.04 Begin
                        //if (appt.LastModificationTime < this.lastSyncTime) continue;
                        ////B12773_CRMOutlookPluginIssues MGY 2016.07.04 End

                        if (appt.Sensitivity == Microsoft.Office.Interop.Outlook.OlSensitivity.olPrivate)
                        {
                            continue;
                        }
                        //B19443_ChangesToPluginFunctionality MGY 2018.05.24 Begin
                        if (isPublicHoliday(appt))
                        {
                            continue;
                        }
                        //B19443_ChangesToPluginFunctionality MGY 2018.05.24 End

                        apptCount++;
                    }
                }
                //apptCount = 10;

                if (apptCount == 0)
                {
                    progressToCrm.Minimum = 0;
                    progressToCrm.Maximum = 1;
                    progressToCrm.Value   = 0;
                    progressToCrm.Step    = 1;
                    progressToCrm.PerformStep();
                }
                swCntApps.Stop();

                if (apptCount > 0)
                {
                    int    taskProirity     = 0;
                    int    sensitivity      = 0;
                    int    activityTimeType = 0;
                    bool   findItem         = false;
                    string actnum;

                    progressToCrm.Minimum = 0;
                    progressToCrm.Maximum = apptCount;
                    progressToCrm.Value   = 0;
                    progressToCrm.Step    = 1;

                    foreach (Outlook.AppointmentItem appt in rangeAppts)
                    {
                        printLogMsg(string.Format("Checking Appointment: {0}.", appt.Subject));

                        //B12773_CRMOutlookPluginIssues MGY 2016.07.04 Begin
                        //Nem jó megoldás, mert amikor törlik az Activity párját AX-ból, akkor nem fog törlődni az appointment.
                        //if (appt.LastModificationTime < this.lastSyncTime) continue;
                        //B12773_CRMOutlookPluginIssues MGY 2016.07.04 End

                        //B08559_CRM_OutlookSyncBug MGY 2014.03.25 Begin
                        if (appt.Sensitivity == Microsoft.Office.Interop.Outlook.OlSensitivity.olPrivate)
                        {
                            continue;
                        }
                        //B08559_CRM_OutlookSyncBug MGY 2014.03.25 End
                        //B19443_ChangesToPluginFunctionality MGY 2018.05.24 Begin
                        if (isPublicHoliday(appt))
                        {
                            continue;
                        }
                        //B19443_ChangesToPluginFunctionality MGY 2018.05.24 End

                        string partyID              = string.Empty;
                        Outlook.UserProperties ups  = appt.UserProperties;
                        Outlook.UserProperty   prop = ups["PartyID"];
                        if (prop != null)
                        {
                            partyID = prop.Value;
                        }

                        findItem = false;
                        actnum   = "";
                        var values = smmActivityList.Where(pair => pair.Key.Contains(appt.EntryID)).Select(pair => pair.Value);
                        foreach (var item in values)
                        {
                            findItem = true;
                        }

                        if (!findItem)
                        {
                            OutlookMgt.TASKPRIORITYConvertOutlookOlImportanceToInt(ref taskProirity, appt);
                            OutlookMgt.SENSITIVITYConvertOutlookOlSensitivityToInt(ref sensitivity, appt);
                            OutlookMgt.ACTIVITYTIMETYPEConvertOutlookOlBusyStatusToInt(ref activityTimeType, appt);

                            if (serviceProxy.IsDeletedActivity(appt.EntryID, company))
                            {
                                printLogMsg("Appointment removed as not found in CRM: " + appt.Subject);
                                appt.Delete();
                                deletedOutlookItemCounter++;
                                progressToCrm.PerformStep();
                                continue;
                            }

                            try
                            {
                                //Mi van akkor ha az activity korábban módosult mint az utolsó sync time, viszont az appointment utólag módosult?
                                //Ekkor duplán létrejön az Activity??
                                //Megoldás: Appointmentben letároljuk az activityNum-ot.
                                bool actUpdated             = false;
                                Outlook.UserProperty uprops = appt.UserProperties.Find("ActivityNum");
                                if (uprops != null)
                                {
                                    actnum = Convert.ToString(uprops.Value);
                                    if (!String.IsNullOrEmpty(actnum))
                                    {
                                        serviceProxy.UpdateActivity(appt.Start.ToUniversalTime(),
                                                                    appt.End.ToUniversalTime(),
                                                                    empId,
                                                                    appt.AllDayEvent,
                                                                    appt.BillingInformation,
                                                                    appt.Body,
                                                                    appt.Subject,
                                                                    appt.Categories,
                                                                    taskProirity,
                                                                    appt.Location,
                                                                    appt.Mileage,
                                                                    appt.ReminderSet,
                                                                    appt.ReminderMinutesBeforeStart,
                                                                    appt.Resources,
                                                                    appt.ResponseRequested,
                                                                    sensitivity,
                                                                    activityTimeType,
                                                                    networkAlias,
                                                                    company,
                                                                    appt.EntryID,
                                                                    actnum);
                                        actUpdated = true;
                                    }
                                }

                                if (!actUpdated)
                                {
                                    actnum = serviceProxy.InsertActivity(appt.Start.ToUniversalTime(),
                                                                         appt.End.ToUniversalTime(),
                                                                         empId == null ? "" : empId,
                                                                         appt.AllDayEvent,
                                                                         appt.BillingInformation == null ? "" : appt.BillingInformation,
                                                                         appt.Body == null ? "" : appt.Body,
                                                                         appt.Subject == null ? "" : appt.Subject,
                                                                         appt.Categories == null ? "" : appt.Categories,
                                                                         taskProirity,
                                                                         appt.Location == null ? "" : appt.Location,
                                                                         appt.Mileage == null ? "" : appt.Mileage,
                                                                         appt.ReminderSet,
                                                                         appt.ReminderMinutesBeforeStart,
                                                                         appt.Resources == null ? "" : appt.Resources,
                                                                         appt.ResponseRequested,
                                                                         sensitivity,
                                                                         activityTimeType,
                                                                         networkAlias,
                                                                         company,
                                                                         appt.EntryID
                                                                         );

                                    Outlook.UserProperty propAppt = appt.UserProperties.Add("ActivityNum", Outlook.OlUserPropertyType.olText, false, Outlook.OlFormatText.olFormatTextText);
                                    propAppt.Value = actnum;
                                }

                                if (log)
                                {
                                    serviceProxy.WriteInfo("++++++WebService: " + "The " + actnum + " activity " + (actUpdated ? "updated!" : "inserted!"));
                                    printLogMsg(String.Format("Appointment '{0}' saved in CRM with identifier: {1}", appt.Subject, actnum));
                                }
                                savedCRMItemCounter++;
                            }
                            catch (Exception e)
                            {
                                System.Windows.Forms.MessageBox.Show("Could not insert activity: " + e.Message);
                            }
                        }
                        progressToCrm.PerformStep();
                    }
                }

                /*printLogMsg(String.Format("GetFolder: {0, 4}; GetApps: {1,4}; CountApps: {2,4}",
                 *  swGetFolder.ElapsedMilliseconds,
                 *  swGetApps.ElapsedMilliseconds,
                 *  swCntApps.ElapsedMilliseconds));*/
            }
            catch (Exception ex)
            {
                printLogMsg(string.Format("Error transferring appointments to CRM! Error message: {0}", ex.Message));
            }

            String message = String.Empty;

            //if (savedCRMItemCounter != 0)
            {
                message = message + "Number of activities transferred to CRM: " + savedCRMItemCounter + "\n";
            }

            //if (deletedOutlookItemCounter != 0)
            {
                message = message + "Number of activities deleted from Outlook: " + deletedOutlookItemCounter;
            }

            return(message);
        }
Ejemplo n.º 19
0
        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);
            }
        }