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);
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: Nomanghous/DBtoOL
        private OutLook.ContactItem checkForUpdatedItemsInDB()
        {
            Microsoft.Office.Interop.Outlook.Items OutlookItems;
            //OutLook.MAPIFolder Folder_Contacts;
            // Folder_Contacts = (OutLook.MAPIFolder)OutLookApp.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderContacts);
            OutlookItems         = folder.Items;
            progressBar1.Maximum = folder.Items.Count;
            for (int i = 1; i < OutlookItems.Count; i++)
            {
                object missing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Outlook.ContactItem contact = (Microsoft.Office.Interop.Outlook.ContactItem)OutlookItems[i];
                if (progressBar1.Value < progressBar1.Maximum)
                {
                    MethodInvoker m = new MethodInvoker(() => progressBar1.Value++);
                    progressBar1.Invoke(m);
                }
                if (contact != null)
                {
                    OutLook.UserProperty userProperty2 = contact.UserProperties.Find("Organizational ID", missing);
                    if (userProperty2 != null && userProperty2.Value != string.Empty)
                    {
                        if (!ifExistsInDB(userProperty2.Value))
                        {
                            contact.Delete();
                        }
                    }
                }
            }
            MethodInvoker m2 = new MethodInvoker(() => progressBar1.Value = 0);

            progressBar1.Invoke(m2);

            return(null);
        }
예제 #3
0
        /// <summary>
        /// A CRM item is perceived to have changed if its modified date is different from
        /// that of its Outlook representation, or if its should sync flag is.
        /// </summary>
        /// <param name="crmItem">A CRM item.</param>
        /// <param name="outlookItem">An Outlook item, assumed to represent the same entity.</param>
        /// <returns>True if either of these propertyies differ between the representations.</returns>
        private bool CrmItemChanged(eEntryValue crmItem, Outlook.ContactItem outlookItem)
        {
            Outlook.UserProperty dateModifiedProp = outlookItem.UserProperties["SOModifiedDate"];

            return(dateModifiedProp.Value != crmItem.GetValueAsString("date_modified") ||
                   ShouldSyncFlagChanged(outlookItem, crmItem));
        }
예제 #4
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);
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        /// <summary>
        /// Update an existing Outlook item with values taken from a corresponding CRM item. Note that
        /// this just overwrites all values in the Outlook item.
        /// </summary>
        /// <param name="crmType">The CRM type of the item from which values are to be taken.</param>
        /// <param name="crmItem">The CRM item from which values are to be taken.</param>
        /// <param name="date_start">The state date/time of the item, adjusted for timezone.</param>
        /// <param name="oItem">The outlook item assumed to correspond with the CRM item.</param>
        /// <returns>An appropriate sync state.</returns>
        private SyncState <Outlook.AppointmentItem> UpdateExistingOutlookItemFromCrm(
            string crmType,
            eEntryValue crmItem,
            DateTime date_start,
            SyncState <Outlook.AppointmentItem> oItem)
        {
            LogItemAction(oItem.OutlookItem, "AppointmentSyncing.UpdateExistingOutlookItemFromCrm");
            Outlook.AppointmentItem olAppointment          = oItem.OutlookItem;
            Outlook.UserProperty    olPropertyModifiedDate = olAppointment.UserProperties["SOModifiedDate"];

            if (olPropertyModifiedDate.Value != crmItem.GetValueAsString("date_modified"))
            {
                olAppointment.Subject = crmItem.GetValueAsString("name");
                olAppointment.Body    = crmItem.GetValueAsString("description");
                if (!string.IsNullOrWhiteSpace(crmItem.GetValueAsString("date_start")))
                {
                    UpdateOutlookStartAndDuration(crmType, crmItem, date_start, olAppointment);
                }

                EnsureSynchronisationPropertiesForOutlookItem(olAppointment, crmItem.GetValueAsString("date_modified"), crmType, crmItem.id);
                olAppointment.Save();
                LogItemAction(oItem.OutlookItem, "AppointmentSyncing.UpdateExistingOutlookItemFromCrm, item saved");
            }
            Log.Warn((string)("Not default dResult.date_modified= " + crmItem.GetValueAsString("date_modified")));
            oItem.OModifiedDate = DateTime.ParseExact(crmItem.GetValueAsString("date_modified"), "yyyy-MM-dd HH:mm:ss", null);

            return(oItem);
        }
예제 #7
0
        /// <summary>
        /// A CRM item is perceived to have changed if its modified date is different from
        /// that of its Outlook representation, or if its should sync flag is.
        /// </summary>
        /// <param name="crmItem">A CRM item.</param>
        /// <param name="olItem">An Outlook item, assumed to represent the same entity.</param>
        /// <returns>True if either of these propertyies differ between the representations.</returns>
        private bool CrmItemChanged(EntryValue crmItem, Outlook.ContactItem olItem)
        {
            Outlook.UserProperty dateModifiedProp = olItem.UserProperties[SyncStateManager.ModifiedDatePropertyName];

            return(dateModifiedProp.Value != crmItem.GetValueAsString("date_modified") ||
                   ShouldSyncFlagChanged(olItem, crmItem));
        }
예제 #8
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);
        }
예제 #9
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);
        }
        private void FolderItemAddHandler(string folderName, object item)
        {
            if (folderName == "Outbox" || folderName == "Sent Items")
            {
                return;
            }

            Outlook.MailItem mailItem = (Outlook.MailItem)item;
            if (mailItem != null)
            {
                Outlook.UserProperty hd = mailItem.UserProperties.Find("secret");
                if (hd != null)
                {
                    string message = string.Format("Added email with {0} to {1}", hd.Value, folderName);
                    MessageBox.Show(message);
                }
                else
                {
                    string message = string.Format("Added email: {0} to {1}", mailItem.Subject, folderName);
                    MessageBox.Show(message);
                }
            }
            else
            {
                string message = string.Format("Added {0} to {1}", item.GetType().Name, folderName);
                MessageBox.Show(message);
            }
        }
예제 #11
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);
     }
 }
예제 #12
0
        /// <summary>
        /// Archive this email item to CRM.
        /// </summary>
        /// <param name="olItem">The email item to archive.</param>
        /// <param name="reason">The reason it is being archived.</param>
        /// <returns>A result object indicating success or failure.</returns>
        public static ArchiveResult Archive(this Outlook.MailItem olItem, EmailArchiveReason reason, string excludedEmails = "")
        {
            ArchiveResult result;

            Outlook.UserProperty olProperty = olItem.UserProperties[CrmIdPropertyName];

            if (olProperty == null)
            {
                result = olItem.AsArchiveable(reason).Save(excludedEmails);

                if (result.IsSuccess)
                {
                    olItem.Categories = string.IsNullOrEmpty(olItem.Categories) ?
                                        SuiteCRMCategoryName :
                                        $"{olItem.Categories},{SuiteCRMCategoryName}";
                    olItem.EnsureProperty(CrmIdPropertyName, result.EmailId);
                }
            }
            else
            {
                result = ArchiveResult.Success(olProperty.Value, new[] { new AlreadyArchivedException(olItem) });
            }

            return(result);
        }
예제 #13
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);
         }
     }
     //
 }
        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);
        }
        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);
        }
예제 #16
0
        public static void SetOutlookGoogleContactId(Syncronizer sync, Outlook.ContactItem outlookContact, ContactEntry googleContact)
        {
            if (googleContact.Id.Uri == null)
            {
                throw new NullReferenceException("GoogleContact must have a valid Id");
            }

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

            //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;*/

            //save sync datetime
            prop = outlookContact.UserProperties[sync.OutlookPropertyNameSynced];
            if (prop == null)
            {
                prop = outlookContact.UserProperties.Add(sync.OutlookPropertyNameSynced, Outlook.OlUserPropertyType.olDateTime, null, null);
            }
            prop.Value = DateTime.Now;
        }
        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);
                }
            }
        }
예제 #18
0
 /// <summary>
 /// Ensure that this Outlook item has a property of this name with this value.
 /// </summary>
 /// <param name="olItem">The Outlook item.</param>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 protected override void EnsureSynchronisationPropertyForOutlookItem(Outlook.ContactItem olItem, string name, string value)
 {
     try
     {
         Outlook.UserProperty olProperty = olItem.UserProperties[name];
         if (olProperty == null)
         {
             olProperty = olItem.UserProperties.Add(name, Outlook.OlUserPropertyType.olText);
         }
         if (!olProperty.Value.Equals(value))
         {
             try
             {
                 olProperty.Value = value ?? string.Empty;
                 Log.Debug($"ContactSyncing.EnsureSynchronisationPropertyForOutlookItem: Set property {name} to value {value} on item {olItem.Subject}");
             }
             finally
             {
                 this.SaveItem(olItem);
             }
         }
     }
     catch (Exception any)
     {
         ErrorHandler.Handle($"Failed to set property {name} to value {value} on Contact {olItem.FullName}", any);
     }
 }
        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);
        }
예제 #21
0
        /// <summary>
        /// Update an existing Outlook item with values taken from a corresponding CRM item. Note that
        /// this just overwrites all values in the Outlook item.
        /// </summary>
        /// <param name="crmItem">The CRM item from which values are to be taken.</param>
        /// <param name="itemSyncState">The sync state of an outlook item assumed to correspond with the CRM item.</param>
        /// <returns>An appropriate sync state.</returns>
        private SyncState <Outlook.ContactItem> UpdateExistingOutlookItemFromCrm(EntryValue crmItem, SyncState <Outlook.ContactItem> itemSyncState)
        {
            if (!itemSyncState.IsDeletedInOutlook)
            {
                Outlook.ContactItem  olItem           = itemSyncState.OutlookItem;
                Outlook.UserProperty dateModifiedProp = olItem.UserProperties[SyncStateManager.ModifiedDatePropertyName];
                Outlook.UserProperty shouldSyncProp   = olItem.UserProperties["SShouldSync"];
                this.LogItemAction(olItem, "ContactSyncing.UpdateExistingOutlookItemFromCrm");

                if (CrmItemChanged(crmItem, olItem))
                {
                    DateTime crmDate     = DateTime.Parse(crmItem.GetValueAsString("date_modified"));
                    DateTime outlookDate = dateModifiedProp == null ? DateTime.MinValue : DateTime.Parse(dateModifiedProp.Value.ToString());

                    if (crmDate > this.LastRunCompleted && outlookDate > this.LastRunCompleted)
                    {
                        MessageBox.Show(
                            $"Contact {olItem.FirstName} {olItem.LastName} has changed both in Outlook and CRM; please check which is correct",
                            "Update problem", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (crmDate > outlookDate)
                    {
                        this.SetOutlookItemPropertiesFromCrmItem(crmItem, olItem);
                    }
                }

                this.LogItemAction(olItem, "ContactSyncing.UpdateExistingOutlookItemFromCrm");
                itemSyncState.OModifiedDate = DateTime.ParseExact(crmItem.GetValueAsString("date_modified"), "yyyy-MM-dd HH:mm:ss", null);
            }

            return(itemSyncState);
        }
예제 #22
0
        public static string GetCRMEntryId(this Outlook.MailItem olItem)
        {
            string result;

            Outlook.UserProperty property = null;

            try
            {
                property = olItem.UserProperties[SyncStateManager.CrmIdPropertyName];

                if (property == null)
                {
                    /* #6661: fail over to legacy property name if current property
                     * name not found */
                    property = olItem.UserProperties[SyncStateManager.LegacyCrmIdPropertyName];
                }

                result = property != null?property.Value.ToString() : string.Empty;
            }
            catch (COMException cex)
            {
                ErrorHandler.Handle("Could not get property while archiving email", cex);
                result = string.Empty;
            }

            return(result);
        }
        /// <summary>
        /// Add the item implied by this SyncState, which may not exist in CRM, to CRM.
        /// </summary>
        /// <param name="syncState">The sync state.</param>
        /// <returns>The id of the entry added or updated.</returns>
        internal override string AddOrUpdateItemFromOutlookToCrm(SyncState <Outlook.AppointmentItem> syncState)
        {
            Outlook.AppointmentItem olItem         = syncState.OutlookItem;
            Outlook.UserProperty    olPropertyType = olItem.UserProperties[TypePropertyName];
            var itemType = olPropertyType != null?olPropertyType.Value.ToString() : this.DefaultCrmModule;

            return(this.AddOrUpdateItemFromOutlookToCrm(syncState, itemType, syncState.CrmEntryId));
        }
예제 #24
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();
     }
 }
예제 #25
0
    /// <summary>
    /// WrapperEvent fired when a mailItem is opened.
    /// This handler is designed to initialize the state of the compose button
    /// states (Sign/Encrypt) with recorded values, if present, or with default
    /// settings values.
    /// </summary>
    /// <param name="mailItem">the opened mailItem</param>
    /// <param name="Cancel">False when the event occurs. If the event procedure sets this argument to True,
    /// the open operation is not completed and the inspector is not displayed.</param>
    void mailItem_Open(Outlook.MailItem mailItem, ref bool Cancel)
    {
      if (mailItem == null)
        return;

      // New mail (Compose)
      if (mailItem.Sent == false)
      {
        Outlook.UserProperty SignProperpty = mailItem.UserProperties["GnuPGSetting.Sign"];
        if (SignProperpty == null)
        {
          ribbon.SignButton.Checked = _settings.AutoSign;
        }
        else
        {
          ribbon.SignButton.Checked = (bool)SignProperpty.Value;
        }

        Outlook.UserProperty EncryptProperpty = mailItem.UserProperties["GnuPGSetting.Encrypt"];
        if (EncryptProperpty == null)
        {
          ribbon.EncryptButton.Checked = _settings.AutoEncrypt;
        }
        else
        {
          ribbon.EncryptButton.Checked = (bool)EncryptProperpty.Value;
        }
      }
      else
        // Read mail
      {
        // Default: disable read-buttons
        ribbon.DecryptButton.Enabled = ribbon.VerifyButton.Enabled = false;

        // Handle plain text mail
        if (mailItem.BodyFormat == Outlook.OlBodyFormat.olFormatPlain)
        {
          // Look for PGP headers
          Match match = Regex.Match(mailItem.Body, _pgpHeaderPattern);

          if ((_autoDecrypt || _settings.AutoDecrypt) && match.Value == _pgpEncryptedHeader)
          {
            _autoDecrypt = false;
            DecryptEmail(mailItem);
            // Update match again, in case decryption failed/cancelled.
            match = Regex.Match(mailItem.Body, _pgpHeaderPattern);
        }
          else if (_settings.AutoVerify && match.Value == _pgpSignedHeader)
        {
            VerifyEmail(mailItem);
          }

          ribbon.VerifyButton.Enabled = (match.Value == _pgpSignedHeader);
          ribbon.DecryptButton.Enabled = (match.Value == _pgpEncryptedHeader);
        }
      }
      ribbon.InvalidateButtons();
    }
예제 #26
0
 /// <summary>
 /// Ensure that this Outlook item has a property of this name with this value.
 /// </summary>
 /// <remarks>
 /// TODO: Candidate for refactoring to superclass.
 /// </remarks>
 /// <param name="olItem">The Outlook item.</param>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 private static void EnsureSynchronisationPropertyForOutlookItem(Outlook.ContactItem olItem, string name, string value)
 {
     Outlook.UserProperty olProperty = olItem.UserProperties[name];
     if (olProperty == null)
     {
         olProperty = olItem.UserProperties.Add(name, Outlook.OlUserPropertyType.olText);
     }
     olProperty.Value = value;
 }
예제 #27
0
        /// <summary>
        /// We should delete an item from CRM if it already exists in CRM, but it is now private.
        /// </summary>
        /// <param name="olItem">The Outlook item</param>
        /// <returns>true if the Outlook item should be deleted from CRM.</returns>
        private bool ShouldDeleteFromCrm(Outlook.AppointmentItem olItem)
        {
            Outlook.UserProperty olPropertyEntryId = olItem.UserProperties["SEntryID"];
            bool result = (olPropertyEntryId != null && olItem.Sensitivity != Outlook.OlSensitivity.olNormal);

            LogItemAction(olItem, $"ShouldDeleteFromCrm returning {result}");

            return(result);
        }
예제 #28
0
 /// <summary>
 /// Ensure that this Outlook item has a property of this name with this value.
 /// </summary>
 /// <remarks>
 /// TODO: Candidate for refactoring to superclass.
 /// </remarks>
 /// <param name="olItem">The Outlook item.</param>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 protected override void EnsureSynchronisationPropertyForOutlookItem(Outlook.AppointmentItem olItem, string name, string value)
 {
     Outlook.UserProperty olProperty = olItem.UserProperties[name];
     if (olProperty == null)
     {
         olProperty = olItem.UserProperties.Add(name, Outlook.OlUserPropertyType.olText);
     }
     olProperty.Value = value;
 }
예제 #29
0
        /// <summary>
        /// Update an existing Outlook item with values taken from a corresponding CRM item. Note that
        /// this just overwrites all values in the Outlook item.
        /// </summary>
        /// <param name="crmItem">The CRM item from which values are to be taken.</param>
        /// <param name="oItem">The outlook item assumed to correspond with the CRM item.</param>
        /// <returns>An appropriate sync state.</returns>
        private SyncState <Outlook.ContactItem> UpdateExistingOutlookItemFromCrm(dynamic crmItem, SyncState <Outlook.ContactItem> oItem)
        {
            Outlook.ContactItem  cItem = oItem.OutlookItem;
            Outlook.UserProperty oProp = cItem.UserProperties["SOModifiedDate"];

            if (oProp.Value != crmItem.date_modified.value.ToString())
            {
                cItem.FirstName                 = crmItem.first_name.value.ToString();
                cItem.LastName                  = crmItem.last_name.value.ToString();
                cItem.Email1Address             = crmItem.email1.value.ToString();
                cItem.BusinessTelephoneNumber   = crmItem.phone_work.value.ToString();
                cItem.HomeTelephoneNumber       = crmItem.phone_home.value.ToString();
                cItem.MobileTelephoneNumber     = crmItem.phone_mobile.value.ToString();
                cItem.JobTitle                  = crmItem.title.value.ToString();
                cItem.Department                = crmItem.department.value.ToString();
                cItem.BusinessAddressCity       = crmItem.primary_address_city.value.ToString();
                cItem.BusinessAddressCountry    = crmItem.primary_address_country.value.ToString();
                cItem.BusinessAddressPostalCode = crmItem.primary_address_postalcode.value.ToString();

                if (crmItem.primary_address_street.value != null)
                {
                    cItem.BusinessAddressStreet = crmItem.primary_address_street.value.ToString();
                }
                cItem.Body    = crmItem.description.value.ToString();
                cItem.Account = cItem.CompanyName = String.Empty;
                if (crmItem.account_name != null && crmItem.account_name.value != null)
                {
                    cItem.Account     = crmItem.account_name.value.ToString();
                    cItem.CompanyName = crmItem.account_name.value.ToString();
                }

                cItem.BusinessFaxNumber = crmItem.phone_fax.value.ToString();
                cItem.Title             = crmItem.salutation.value.ToString();

                try
                {
                    var dateModified = crmItem.date_modified.value.ToString();
                    var shouldSync   = crmItem.sync_contact == null ?
                                       Boolean.TrueString :
                                       crmItem.sync_contact.value.ToString();
                    var crmId = crmItem.id.value.ToString();
                    EnsureSynchronisationPropertiesForOutlookItem(cItem, dateModified, shouldSync, crmId);
                }
                catch (Exception any)
                {
                    this.Log.Error("Attempt to read not present value from crmItem?", any);
                }

                this.LogItemAction(cItem, $"ContactSyncing.UpdateExistingOutlookItemFromCrm, saving with {cItem.Sensitivity}");

                cItem.Save();
            }

            this.LogItemAction(cItem, "ContactSyncing.UpdateExistingOutlookItemFromCrm");
            oItem.OModifiedDate = DateTime.ParseExact(crmItem.date_modified.value.ToString(), "yyyy-MM-dd HH:mm:ss", null);
            return(oItem);
        }
예제 #30
0
 public static DateTime?GetOutlookPropertyValueDateTime(Outlook.ContactItem outlookContact, string propertyName)
 {
     Outlook.UserProperty prop = outlookContact.UserProperties[propertyName];
     if (prop != null)
     {
         return((DateTime)prop.Value);
     }
     return(null);
 }