async Task <IEnumerable <Message> > FeedContactsAffectedBySavedSearch(int searchDefinitionId, int workflowId, int accountId) { IList <Message> messages = new List <Message>(); try { Logger.Current.Informational("For Getting SavedSearch Contacts By SearchdefinitionID In Automation Engine"); var contactIds = await advancedSearchService.GetSavedSearchContactIds(new ApplicationServices.Messaging.Search.GetSavedSearchContactIdsRequest() { SearchDefinitionIds = new int[] { searchDefinitionId }, AccountId = accountId }); foreach (var recipient in contactIds) { messages.Add(new Message() { MessageId = Guid.NewGuid().ToString().ToLower(), EntityId = searchDefinitionId, ContactId = recipient, AccountId = accountId, LeadScoreConditionType = (int)LeadScoreConditionType.ContactMatchesSavedSearch, WorkflowId = workflowId }); } return(messages); } catch (Exception ex) { Logger.Current.Error("An error occured while fetching contactIds for a saved search. ", ex); Logger.Current.Informational("SearchdefinitionId : " + searchDefinitionId + " WorkflowId : " + workflowId + " AccountId : " + accountId); } return(messages); }
protected override void Execute() { Logger.Current.Informational("Entering into SmartSearchProcessor"); try { List <int> contactIds = null; Dictionary <int, int> searchDefinitions = advancedSearchRepository.GetAllSearchDefinitionIsAndAccountIds(); foreach (var data in searchDefinitions) { try { GetSavedSearchContactIdsRequest advRequest = new GetSavedSearchContactIdsRequest() { SearchDefinitionId = data.Key, AccountId = data.Value }; var task = Task.Run(() => advancedSearchService.GetSavedSearchContactIds(advRequest)); contactIds = task.Result; List <SmartSearchContact> savedSearchContacts = new List <SmartSearchContact>(); foreach (int contactId in contactIds) { SmartSearchContact savedSearchcontact = new SmartSearchContact(); savedSearchcontact.SearchDefinitionID = data.Key; savedSearchcontact.ContactID = contactId; savedSearchcontact.AccountID = data.Value; savedSearchcontact.IsActive = true; savedSearchContacts.Add(savedSearchcontact); } contactRepository.DeleteSavedSearchContactsBySearchDefinitionId(data.Key, data.Value); contactRepository.InsertBulkSavedSearchesContacts(savedSearchContacts); advancedSearchRepository.UpdateSmartSearchQueue(data.Key, data.Value, true); } catch (Exception ex) { Logger.Current.Error(string.Format("Couldn't not fetch data for Smart Search {0} , Account {1}", data.Key, data.Value), ex); advancedSearchRepository.UpdateSmartSearchQueue(data.Key, data.Value, true); } } } catch (Exception ex) { Logger.Current.Error("Error while Smart Search Contacts Processing", ex); } }
protected override void ExecuteInternal(IJobExecutionContext context) { Log.Informational("Entering into SmartSearchProcessor"); var searchDefinitions = _advancedSearchRepository.GetAllSearchDefinitionIsAndAccountIds(); foreach (var seachDefinition in searchDefinitions) { try { var advRequest = new GetSavedSearchContactIdsRequest { SearchDefinitionId = seachDefinition.Key, AccountId = seachDefinition.Value }; var contactIds = _advancedSearchService.GetSavedSearchContactIds(advRequest).Result; var savedSearchContacts = new List <SmartSearchContact>(); foreach (var contactId in contactIds) { var savedSearchcontact = new SmartSearchContact { SearchDefinitionID = seachDefinition.Key, ContactID = contactId, AccountID = seachDefinition.Value, IsActive = true }; savedSearchContacts.Add(savedSearchcontact); } _contactRepository.DeleteSavedSearchContactsBySearchDefinitionId(seachDefinition.Key, seachDefinition.Value); _contactRepository.InsertBulkSavedSearchesContacts(savedSearchContacts); _advancedSearchRepository.UpdateSmartSearchQueue(seachDefinition.Key, seachDefinition.Value, true); } catch (Exception ex) { Log.Error($"Couldn't not fetch data for Smart Search {seachDefinition.Key} , Account {seachDefinition.Value}", ex); _advancedSearchRepository.UpdateSmartSearchQueue(seachDefinition.Key, seachDefinition.Value, true); } } }
public async Task <HttpResponseMessage> GetContactsFromSearchDefinition(int id, int accountId, int userId, int roleId) { GetCampaignRecipientIdsResponse response = new GetCampaignRecipientIdsResponse(); try { var contacts = await advancedSearchService.GetSavedSearchContactIds(new GetSavedSearchContactIdsRequest() { AccountId = accountId, RequestedBy = userId, RoleId = (short)roleId, SearchDefinitionId = id }); response.ContactIds = contacts; } catch (Exception ex) { response.Exception = ex; } return(Request.BuildResponse(response)); }
protected override void ExecuteInternal(IJobExecutionContext context) { var response = _accountService.GetBulkOperationData(new GetBulkOperationDataRequest()); try { Log.Informational("Entering into BulkOperation processor"); List <int> ids = null; while (response.BulkOperations != null) { var notification = new Notification { Time = DateTime.Now.ToUniversalTime(), Status = NotificationStatus.New, EntityId = response.BulkOperations.OperationID, UserID = response.BulkOperations.UserID, ModuleID = (byte)AppModules.Contacts }; try { if (response.BulkOperations.SearchDefinitionID != null) { Log.Informational("Bulk SearchDefinitionID" + response.BulkOperations.SearchDefinitionID); GetSavedSearchContactIdsRequest advRequest = new GetSavedSearchContactIdsRequest() { SearchDefinitionId = (int)response.BulkOperations.SearchDefinitionID, AccountId = response.BulkOperations.AccountID }; Log.Informational("For Getting SavedSearch Contacts By SearchdefinitionID In BulkOperation"); ids = _advancedSearchService.GetSavedSearchContactIds(advRequest).Result; } else if (response.BulkContactIDs.Length > 0) { Log.Informational("Bulk contacts Length" + response.BulkContactIDs.ToList()); ids = response.BulkContactIDs.ToList(); } if (ids.IsAny() || !string.IsNullOrEmpty(response.BulkOperations.SearchCriteria)) { GetBulkContactsResponse contactsResponse = _contactService.GetBulkContacts(new GetBulkContactsRequest() { BulkOperations = response.BulkOperations, ContactIds = ids }); _accountService.InsertBulkData(contactsResponse.ContactIds, response.BulkOperations.BulkOperationID); #region Actions if (response.BulkOperations.OperationType == (int)BulkOperationTypes.Action) { Log.Informational("Performing bulk add action with operationId : " + response.BulkOperations.OperationID); IEnumerable <int> contactIds = null; IDictionary <int, Guid> emailGuids = new Dictionary <int, Guid>(); IDictionary <int, Guid> textGuids = new Dictionary <int, Guid>(); var action = _actionService.UpdateActionBulkData(response.BulkOperations.OperationID, response.BulkOperations.AccountID, response.BulkOperations.UserID, response.BulkOperations.AccountPrimaryEmail, response.BulkOperations.AccountDomain, false, false, "", response.BulkOperations.ActionCompleted, contactIds, false, 0, emailGuids, textGuids); notification.Subject = action.Details; notification.Details = "Bulk Operation for adding action completed successfully"; notification.ModuleID = (byte)AppModules.ContactActions; } #endregion #region Note else if (response.BulkOperations.OperationType == (int)BulkOperationTypes.Note) { Log.Verbose("Updating Note Bulk Data for operationid: " + response.BulkOperations.OperationID); if (ids.IsAny()) { var note = _noteService.UpdateNoteBulkData(response.BulkOperations.OperationID, response.BulkOperations.AccountID, contactsResponse.ContactIds); notification.Subject = note.Details; notification.Details = "Bulk Operation for adding note completed successfully"; } else { notification.Subject = "Could not perform operation"; notification.Details = "Opeartion could not be performed as there were no contacts found"; } notification.ModuleID = (byte)AppModules.Contacts; } #endregion #region Tour else if (response.BulkOperations.OperationType == (int)BulkOperationTypes.Tour) { Log.Informational("Performing bulk add tour with operationId : " + response.BulkOperations.OperationID); IDictionary <int, Guid> emailGuids = new Dictionary <int, Guid>(); IDictionary <int, Guid> textGuids = new Dictionary <int, Guid>(); var tour = _tourService.UpdateTourBulkData(response.BulkOperations.OperationID, response.BulkOperations.AccountID, response.BulkOperations.UserID, response.BulkOperations.AccountPrimaryEmail, response.BulkOperations.AccountDomain, false, "", null, false, 0, emailGuids, textGuids); notification.Subject = tour.TourDetails; notification.Details = "Bulk Operation for adding tour completed successfully"; notification.ModuleID = (byte)AppModules.ContactTours; } #endregion #region Tag else if (response.BulkOperations.OperationType == (int)BulkOperationTypes.Tag) { Log.Informational("Performing bulk add tag with operationId : " + response.BulkOperations.OperationID); var tag = _tagService.UpdateTagBulkData(response.BulkOperations.OperationID, response.BulkOperations.AccountID, response.BulkOperations.UserID); notification.Subject = tag.TagName; notification.Details = "Bulk Operation for adding tag completed successfully"; notification.ModuleID = (byte)AppModules.Contacts; _accountService.ScheduleAnalyticsRefresh(response.BulkOperations.OperationID, (byte)IndexType.Tags); } #endregion #region ChangeOwner else if (response.BulkOperations.OperationType == (int)BulkOperationTypes.ChangeOwner) { Log.Informational("Performing bulk change owner with operationId : " + response.BulkOperations.OperationID); if (ids.IsAny()) { var owner = _contactService.UpdateOwnerBulkData(response.BulkOperations.OperationID, response.BulkOperations.UserID, response.BulkOperations.AccountID, contactsResponse.ContactIds); notification.Subject = "New owner: " + owner.FirstName + " " + owner.LastName; notification.Details = "Bulk Operation for changing owner completed successfully"; } else { notification.Subject = "Could not perform operation"; notification.Details = "Opeartion could not be performed as there were no contacts found"; } notification.ModuleID = (byte)AppModules.Contacts; } #endregion #region Export else if (response.BulkOperations.OperationType == (int)BulkOperationTypes.Export) { Log.Informational("Performing bulk export with operationId : " + response.BulkOperations.OperationID); IEnumerable <FieldViewModel> searchFields = null; GetAdvanceSearchFieldsResponse filedsresponse = _advancedSearchService.GetSearchFields(new GetAdvanceSearchFieldsRequest() { accountId = response.BulkOperations.AccountID, RoleId = response.BulkOperations.RoleID }); if (filedsresponse.FieldsViewModel != null) { searchFields = ExcludeNonViewableFields(filedsresponse.FieldsViewModel); } Task.Run(() => _contactService.UpdateBulkExcelExport(response.BulkOperations, contactsResponse.Contacts, searchFields)); } #endregion #region Delete else if (response.BulkOperations.OperationType == (int)BulkOperationTypes.Delete) { Log.Informational("Performing bulk delete with operationId : " + response.BulkOperations.OperationID); if (ids.IsAny()) { _contactService.UpdateDeleteBulkData(response.BulkOperations.OperationID, response.BulkOperations.UserID, response.BulkOperations.AccountID, contactsResponse.ContactIds); notification.Subject = "Bulk Operation for deleting contacts completed successfully"; notification.Details = "Bulk Operation for deleting contacts completed successfully"; } else { notification.Subject = "Could not perform operation"; notification.Details = "Opeartion could not be performed as there were no contacts found"; } notification.ModuleID = (byte)AppModules.Contacts; } #endregion _accountService.UpdateBulkOperationStatus(new UpdateBulkOperationStatusRequest() { BulkOperationId = response.BulkOperations.BulkOperationID, Status = BulkOperationStatus.Completed }); if (response.BulkOperations.OperationType != (int)BulkOperationTypes.Export) { _userService.AddNotification(new AddNotificationRequest() { Notification = notification }); } } else { _accountService.UpdateBulkOperationStatus(new UpdateBulkOperationStatusRequest() { BulkOperationId = response.BulkOperations.BulkOperationID, Status = BulkOperationStatus.Failed }); } //TODO: Remove this, will cause job run too much time response = _accountService.GetBulkOperationData(new GetBulkOperationDataRequest() { }); } catch (Exception exe) { Log.Error("Error while BulkOperation", exe); _accountService.UpdateBulkOperationStatus(new UpdateBulkOperationStatusRequest() { BulkOperationId = response.BulkOperations.BulkOperationID, Status = BulkOperationStatus.Failed }); //TODO: Remove this, will cause job run too much time response = _accountService.GetBulkOperationData(new GetBulkOperationDataRequest() { }); } } } catch (Exception ex) { Log.Error("Error while BulkOperation", ex); _accountService.UpdateBulkOperationStatus(new UpdateBulkOperationStatusRequest() { BulkOperationId = response.BulkOperations.BulkOperationID, Status = BulkOperationStatus.Failed }); } }
protected override void Execute() { GetBulkOperationDataResponse response = accountService.GetQueuedBulkOperationData(new GetBulkOperationDataRequest() { }); try { Logger.Current.Informational("Entering into BulkOperation Ready processor"); List <int> ids = null; while (response.BulkOperations != null) { try { if (response.BulkOperations.SearchDefinitionID != null) { Logger.Current.Informational("BulkOperation Ready processor SearchDefinitionID" + response.BulkOperations.SearchDefinitionID); GetSavedSearchContactIdsRequest advRequest = new GetSavedSearchContactIdsRequest() { SearchDefinitionId = (int)response.BulkOperations.SearchDefinitionID, AccountId = response.BulkOperations.AccountID, SearchCriteria = response.BulkOperations.SearchCriteria, RoleId = response.BulkOperations.RoleID, RequestedBy = response.BulkOperations.UserID }; Logger.Current.Informational("For Getting SavedSearch Contacts By SearchdefinitionID In BulkOperation Ready processor"); ids = advancedSearchService.GetSavedSearchContactIds(advRequest).Result; } else if (!response.BulkContactIDs.IsAny() && (response.BulkOperations.SearchDefinitionID == null || response.BulkOperations.SearchDefinitionID == 0)) { GetBulkContactsResponse contactsResponse = contactService.GetBulkContacts(new GetBulkContactsRequest() { BulkOperations = response.BulkOperations, ContactIds = new List <int>() { }, RoleId = response.BulkOperations.RoleID, RequestedBy = response.BulkOperations.UserID }); ids = contactsResponse.ContactIds.ToList(); } if (ids.IsAny() && ids.Count > 0) { var bulkConactsData = ids.Select(i => new BulkContact() { BulkOperationID = response.BulkOperations.BulkOperationID, ContactID = i }).ToList(); contactService.InsertBulkOperationConacts(new BulkoperationConactsInsertionRequest() { ConactsData = bulkConactsData }); Logger.Current.Informational("BulkOperation Ready processor Conacts Inserted Successfully,BulkoperationId: " + response.BulkOperations.BulkOperationID); } else { if (!response.BulkContactIDs.IsAny()) { accountService.UpdateBulkOperationStatus(new UpdateBulkOperationStatusRequest() { BulkOperationId = response.BulkOperations.BulkOperationID, Status = BulkOperationStatus.Failed }); } } accountService.UpdateBulkOperationStatus(new UpdateBulkOperationStatusRequest() { BulkOperationId = response.BulkOperations.BulkOperationID, Status = BulkOperationStatus.Created }); response = accountService.GetQueuedBulkOperationData(new GetBulkOperationDataRequest() { }); } catch (Exception exe) { Logger.Current.Error("Error while BulkOperation Ready Processor Processing", exe); accountService.UpdateBulkOperationStatus(new UpdateBulkOperationStatusRequest() { BulkOperationId = response.BulkOperations.BulkOperationID, Status = BulkOperationStatus.Failed }); response = accountService.GetQueuedBulkOperationData(new GetBulkOperationDataRequest() { }); } } } catch (Exception ex) { Logger.Current.Error("Error while BulkOperation Ready Processor", ex); accountService.UpdateBulkOperationStatus(new UpdateBulkOperationStatusRequest() { BulkOperationId = response.BulkOperations.BulkOperationID, Status = BulkOperationStatus.Failed }); } }