Exemplo n.º 1
0
        private List <Guid> FindLeadSimilarAccounts(Guid leadId)
        {
            List <Guid>           similarRecords           = new List <Guid>();
            SimilarSearchXmlMatch leadToAccountXmlMatching = GetLeadToAccountXmlMatching();
            SimilarSearchXmlMatch leadToLeadXmlMatching    = GetLeadXmlMatchingg();
            EntitySchemaQuery     esq = new EntitySchemaQuery(_userConnection.EntitySchemaManager, "Lead");

            AddColumnsFromMatching(esq, leadToAccountXmlMatching);
            AddColumnsFromMatching(esq, leadToLeadXmlMatching);
            esq.AddColumn("QualifiedAccount");
            Entity lead = esq.GetEntity(_userConnection, leadId);

            if (lead != null)
            {
                XmlDocument accountSearchValues
                    = _deduplicationSearch.CreateXmlSimilarSearchValue(lead, leadToAccountXmlMatching);
                XmlDocument leadSearchValues
                    = _deduplicationSearch.CreateXmlSimilarSearchValue(lead, leadToLeadXmlMatching);
                List <Guid> accountIds      = _deduplicationSearch.FindSimilarEntity("Account", leadId, accountSearchValues);
                List <Guid> leadIds         = _deduplicationSearch.FindSimilarEntity("Lead", leadId, leadSearchValues);
                List <Guid> leadsAccountIds = GetLeadsQualifiedEntityIds(leadIds, "Account");
                accountIds.AddRange(leadsAccountIds);
                similarRecords = accountIds.Distinct().ToList();
                Guid qualifiedAccount = lead.GetTypedColumnValue <Guid>("QualifiedAccountId");
                similarRecords.Remove(qualifiedAccount);
            }
            return(similarRecords);
        }
Exemplo n.º 2
0
        private void AddColumnsFromMatching(EntitySchemaQuery esq, SimilarSearchXmlMatch similarSearchXmlMatching)
        {
            var columnsMatching = similarSearchXmlMatching.EntityColumns;

            foreach (KeyValuePair <string, SimilarSearchXmlMatch.Rule> rule in columnsMatching)
            {
                esq.AddColumn(rule.Key);
            }
        }
Exemplo n.º 3
0
        protected virtual SimilarSearchXmlMatch GetLeadXmlMatchingg()
        {
            var matching = new SimilarSearchXmlMatch();

            matching.SourceSchemaName      = "Lead";
            matching.DestinationSchemaName = "Lead";
            var entityColumns = new Dictionary <string, SimilarSearchXmlMatch.Rule>();

            entityColumns["Contact"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "Contact",
                SchemaName = "Lead"
            };
            entityColumns["Account"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "Account",
                SchemaName = "Lead"
            };
            entityColumns["Email"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "Email",
                SchemaName = "Lead"
            };
            entityColumns["BusinesPhone"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "BusinesPhone",
                SchemaName = "Lead"
            };
            entityColumns["MobilePhone"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "MobilePhone",
                SchemaName = "Lead"
            };
            entityColumns["Website"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "Website",
                SchemaName = "Lead"
            };
            entityColumns["City"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "CityId",
                SchemaName = "Lead"
            };
            entityColumns["Country"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "CountryId",
                SchemaName = "Lead"
            };
            entityColumns["LeadType"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "LeadTypeId",
                SchemaName = "Lead"
            };
            matching.EntityColumns = entityColumns;
            return(matching);
        }
Exemplo n.º 4
0
        private List <Guid> FindLeadSimilarLeads(Guid leadId)
        {
            List <Guid>           similarRecords        = new List <Guid>();
            SimilarSearchXmlMatch leadToLeadXmlMatching = GetLeadXmlMatchingg();
            EntitySchemaQuery     esq = new EntitySchemaQuery(_userConnection.EntitySchemaManager, "Lead");

            AddColumnsFromMatching(esq, leadToLeadXmlMatching);
            Entity lead = esq.GetEntity(_userConnection, leadId);

            if (lead != null)
            {
                XmlDocument searchValues
                               = _deduplicationSearch.CreateXmlSimilarSearchValue(lead, leadToLeadXmlMatching);
                similarRecords = _deduplicationSearch.FindSimilarEntity("Lead", leadId, searchValues);
            }
            return(similarRecords);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create XML used for search similar records.
        /// </summary>
        /// <param name="entity">Entity.</param>
        /// <param name="xmlMatch">Columns matching for create search values.</param>
        /// <returns>XML for search similar records.</returns>
        public virtual XmlDocument CreateXmlSimilarSearchValue(Entity entity, SimilarSearchXmlMatch xmlMatch)
        {
            XmlDocument xmlConfig = new XmlDocument();
            XmlElement  columns   = xmlConfig.CreateElement("columns");

            xmlConfig.AppendChild(columns);
            foreach (var configItem in xmlMatch.EntityColumns)
            {
                SimilarSearchXmlMatch.Rule rule = configItem.Value;
                string     leadColumnName       = entity.Schema.Columns.GetByName(configItem.Key).ColumnValueName;
                object     columnValue          = entity.GetColumnValue(leadColumnName);
                XmlElement column = CreateSimilarSearchXmlItem(rule.SchemaName, xmlMatch.DestinationSchemaName,
                                                               rule.TypeId, rule.ColumnName, columnValue, xmlConfig);
                columns.AppendChild(column);
            }
            return(xmlConfig);
        }
Exemplo n.º 6
0
        protected virtual SimilarSearchXmlMatch GetLeadToAccountXmlMatching()
        {
            var matching = new SimilarSearchXmlMatch();

            matching.SourceSchemaName      = "Lead";
            matching.DestinationSchemaName = "Account";
            var entityColumns = new Dictionary <string, SimilarSearchXmlMatch.Rule>();

            entityColumns["Account"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "Name",
                SchemaName = "Account"
            };
            entityColumns["Email"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "Number",
                SchemaName = "AccountCommunication",
                TypeId     = Guid.Parse(CommunicationTypeConsts.EmailId)
            };
            entityColumns["BusinesPhone"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "SearchNumber",
                SchemaName = "AccountCommunication",
                TypeId     = Guid.Parse(CommunicationTypeConsts.WorkPhoneId)
            };
            entityColumns["MobilePhone"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "SearchNumber",
                SchemaName = "AccountCommunication",
                TypeId     = Guid.Parse(CommunicationTypeConsts.MobilePhoneId)
            };
            entityColumns["Website"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "Number",
                SchemaName = "AccountCommunication",
                TypeId     = Guid.Parse(CommunicationTypeConsts.WebId)
            };
            entityColumns["City"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "CityId",
                SchemaName = "AccountAddress"
            };
            entityColumns["Country"] = new SimilarSearchXmlMatch.Rule {
                ColumnName = "CountryId",
                SchemaName = "AccountAddress"
            };
            matching.EntityColumns = entityColumns;
            return(matching);
        }