示例#1
0
        private void frmCustomModules_Load(object sender, EventArgs e)
        {
            using (new WaitCursor(this))
            {
                try
                {
                    RestAPIWrapper.EnsureLoggedIn(Globals.ThisAddIn.SuiteCRMUserSession);

                    if (Globals.ThisAddIn.SuiteCRMUserSession.NotLoggedIn)
                    {
                        MessageBox.Show("Please enter SuiteCRM details in General tab and try again", "Invalid Authentication");
                        base.Close();
                        return;
                    }

                    PopulateCustomModulesListView(this.lstViewAvailableModules, this.IgnoreModules);
                }
                catch (Exception ex)
                {
                    Log.Warn("frmCustomModules_Load error", ex);
                    base.Close();
                    MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        /// <summary>
        /// Get contact ids of all email addresses in my From, To, or CC fields which
        /// are known to CRM and not included in these excluded addresses.
        /// </summary>
        /// <param name="excludedAddresses">email addresses for which contact ids should
        /// not be returned.</param>
        /// <returns>A list of strings representing CRM contact ids.</returns>
        private List <string> GetValidContactIds(List <string> excludedAddresses)
        {
            RestAPIWrapper.EnsureLoggedIn(SuiteCRMUserSession);

            List <string> result           = new List <string>();
            List <string> checkedAddresses = new List <string>();

            try
            {
                foreach (string address in ConstructAddressList($"{this.From};{this.To};{this.CC}"))
                {
                    if (!checkedAddresses.Contains(address) && !excludedAddresses.Contains(address.ToUpper()))
                    {
                        var contactReturn = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.Contacts>("get_entry_list",
                                                                                                                 ConstructGetContactIdByAddressPacket(address));

                        if (contactReturn.entry_list != null && contactReturn.entry_list.Count > 0)
                        {
                            result.Add(contactReturn.entry_list[0].id);
                        }
                    }
                    checkedAddresses.Add(address);
                }
            }
            catch (Exception ex)
            {
                log.Warn("GetValidContactIDs error", ex);
                throw;
            }

            return(result);
        }
        /// <summary>
        /// Get contact ids of all email addresses in my From, To, or CC fields which
        /// are known to CRM and not included in these excluded addresses.
        /// </summary>
        /// <param name="moduleKeys">Keys (standardised names) of modules to search.</param>
        /// <param name="excludedAddresses">email addresses for which related ids should
        /// not be returned.</param>
        /// <returns>A list of strings representing CRM ids.</returns>
        private IEnumerable <CrmEntity> GetRelatedIds(IEnumerable <string> moduleKeys, IEnumerable <string> excludedAddresses)
        {
            RestAPIWrapper.EnsureLoggedIn();

            List <CrmEntity> result           = new List <CrmEntity>();
            List <string>    checkedAddresses = new List <string>();

            try
            {
                foreach (string address in ConstructAddressList($"{this.From};{this.To};{this.CC}"))
                {
                    if (!checkedAddresses.Contains(address) && !excludedAddresses.Contains(address.ToUpper()))
                    {
                        RESTObjects.IdsOnly contacts = null;

                        foreach (string moduleKey in moduleKeys)
                        {
                            contacts = SuiteCRMUserSession.RestServer.GetCrmResponse <RESTObjects.IdsOnly>("get_entry_list",
                                                                                                           ConstructGetContactIdByAddressPacket(address, moduleKey));


                            if (contacts.entry_list != null && contacts.entry_list.Count > 0)
                            {
                                result.AddRange(contacts.entry_list.Select(x => new CrmEntity(moduleKey, x.id)));
                            }
                        }
                    }
                    checkedAddresses.Add(address);
                }
            }
            catch (Exception ex)
            {
                log.Warn("GetValidContactIDs error", ex);
                throw;
            }

            return(result);
        }