コード例 #1
0
        public MessageHandlerStatus Handle(MessageQueues.Message message)
        {
            try
            {
                if (message.LeadScoreConditionType != (int)LeadScoreConditionType.ContactNoteTagAdded)
                {
                    return(MessageHandlerStatus.InvalidMessageHandler);
                }

                var leadScoreRuleResponse = leadScoreRuleService.GetLeadScoreRules(
                    new GetLeadScoreRuleByConditionRequest()
                {
                    AccountId      = message.AccountId,
                    Condition      = LeadScoreConditionType.ContactNoteTagAdded,
                    ConditionValue = message.LinkedEntityId.ToString()
                });

                var rules = leadScoreRuleResponse.Rules;

                var response = leadScoreService.IsScoreAudited(
                    new LeadScoreAuditCheckRequest()
                {
                    AccountId      = message.AccountId,
                    ContactId      = message.ContactId,
                    Condition      = LeadScoreConditionType.ContactNoteTagAdded,
                    ConditionValue = message.LinkedEntityId.ToString(),
                    EntityId       = message.EntityId
                });

                if (response.IsAudited)
                {
                    return(MessageHandlerStatus.DuplicateLeadScoreRequest);
                }

                Logger.Current.Informational("Auditing the lead score for contact note tag for message:" + message.MessageId);
                var insertScoreResponse = leadScoreService.InsertLeadScore(new InsertLeadScoreRequest()
                {
                    Condition      = LeadScoreConditionType.ContactNoteTagAdded,
                    ContactId      = message.ContactId,
                    ConditionValue = message.LinkedEntityId.ToString(),
                    AccountId      = message.AccountId,
                    RequestedBy    = message.UserId,
                    EntityId       = message.EntityId,
                    Rules          = rules
                });

                if (insertScoreResponse.Exception == null)
                {
                    Logger.Current.Informational("Audited successfully." + message.MessageId);
                    return(MessageHandlerStatus.LeadScoreAuditedSuccessfully);
                }
                else
                {
                    Logger.Current.Error("Error occurred while auditing the lead score." + message.MessageId, insertScoreResponse.Exception);
                    return(MessageHandlerStatus.FailedToAuditScore);
                }
            }
            catch (Exception ex)
            {
                Logger.Current.Error("Exception occured while handling the Message.", ex);
                return(MessageHandlerStatus.FailedToAuditScore);
            }
        }
コード例 #2
0
        protected override void ExecuteInternal(IJobExecutionContext context)
        {
            var messages = _messageService
                           .GetLeadScoreMessages()
                           .Messages
                           .ToArray();

            if (!messages.IsAny())
            {
                return;
            }

            var auditedMessages = new List <LeadScoreMessage>();

            Log.Informational($"Received messages count: {messages.Length}");
            foreach (var message in messages)
            {
                try
                {
                    Log.Informational($"Processing LeadScore Message message {message}");
                    GetLeadScoreRuleByConditionResponse leadScoreRuleResponse;
                    string conditionValue;
                    int    entityId;
                    SetCondtionValueAndEntityValue(message, out entityId, out conditionValue);

                    var leadScoreRuleRequest = new GetLeadScoreRuleByConditionRequest
                    {
                        AccountId      = message.AccountID,
                        Condition      = (LeadScoreConditionType)message.LeadScoreConditionType,
                        ConditionValue = conditionValue,
                        EntityID       = entityId
                    };

                    if (message.LeadScoreConditionType == (byte)LeadScoreConditionType.ContactClicksLink)
                    {
                        leadScoreRuleResponse = _leadScoreRuleService.GetCampaignClickLeadScoreRule(leadScoreRuleRequest);
                    }
                    else
                    {
                        leadScoreRuleResponse = _leadScoreRuleService.GetLeadScoreRules(leadScoreRuleRequest);
                    }

                    Log.Informational($"Audit leadscore, condtion value: {conditionValue}, entity id:{entityId}, message {message.ToString()}");

                    if (leadScoreRuleResponse.Rules != null && leadScoreRuleResponse.Rules.Any())
                    {
                        Log.Informational(string.Format("Audit leadscore count, Rule ID: {0}", leadScoreRuleResponse.Rules.Count(), leadScoreRuleResponse.Rules.Select(s => s.Id)));

                        var response = _leadScoreService.IsScoreAudited(
                            new LeadScoreAuditCheckRequest
                        {
                            AccountId      = message.AccountID,
                            ContactId      = message.ContactID,
                            Condition      = (LeadScoreConditionType)message.LeadScoreConditionType,
                            ConditionValue = conditionValue,
                            EntityId       = entityId,
                            Rules          = leadScoreRuleResponse.Rules
                        });

                        if (!response.IsAudited && (response.UnAuditedRules != null && response.UnAuditedRules.Any()))
                        {
                            Log.Informational($"Update leadscore, message {message.ToString()}");
                            Log.Informational(string.Format("while inserting Audit leadscore count, Rule ID: {0}", leadScoreRuleResponse.Rules.Count(), leadScoreRuleResponse.Rules.Select(s => s.Id)));

                            _leadScoreService.InsertLeadScore(new InsertLeadScoreRequest()
                            {
                                Condition      = (LeadScoreConditionType)message.LeadScoreConditionType,
                                ConditionValue = conditionValue,
                                ContactId      = message.ContactID,
                                AccountId      = message.AccountID,
                                RequestedBy    = message.UserID,
                                EntityId       = entityId,
                                Rules          = response.UnAuditedRules
                            });
                            message.Remarks = "Lead score applied";
                            message.LeadScoreProcessStatusID = (int)TrackMessageProcessStatus.Processed;
                            auditedMessages.Add(message);
                        }
                        else if (response.IsAudited)
                        {
                            Log.Informational($"Leadscore already applied, message {message.ToString()}");
                            message.LeadScoreProcessStatusID = (int)TrackMessageProcessStatus.Processed;
                            message.Remarks = "Lead score is already applied";
                        }
                    }
                    else if (leadScoreRuleResponse.Rules == null || !leadScoreRuleResponse.Rules.Any())
                    {
                        Log.Informational($"No rule defined, message {message.ToString()}");
                        message.Remarks = "No rule defined";
                        message.LeadScoreProcessStatusID = (int)TrackMessageProcessStatus.Ignored;
                    }
                    message.ProcessedOn = DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                    Log.Informational($"Error occurred while processing leadscore {message} {ex}");
                    message.ProcessedOn = DateTime.MinValue;
                    message.LeadScoreProcessStatusID = (int)TrackMessageProcessStatus.Error;
                    message.Remarks = $"Lead score not processed, {ex}";
                }
            }
            _messageService.UpdateLeadScoreMessage(new UpdateLeadScoreMessage()
            {
                Messages = messages
            });
            //update all messages
            if (auditedMessages.Any())
            {
                //index all contacts messages
                var indexingData = new IndexingData
                {
                    EntityIDs = auditedMessages.Select(m => m.ContactID).ToList(),
                    IndexType = (int)IndexType.Contacts
                };
                _accountService.InsertIndexingData(new InsertIndexingDataRequest {
                    IndexingData = indexingData
                });
            }
        }