public ServiceProviderResponse GetServiceProvider(ServiceProviderRequest request)
        {
            Logger.Current.Verbose("Request to fetch communication logindetails for specific contact.");
            ServiceProviderResponse response        = new ServiceProviderResponse();
            ServiceProvider         serviceProvider = serviceProviderRepository.GetServiceProviders(Convert.ToInt16(request.ServiceProviderViewModel.AccountID), request.ServiceProviderViewModel.CommunicationTypeID, request.ServiceProviderViewModel.MailType);

            if (serviceProvider != null)
            {
                ServiceProviderViewModel ServiceProviderViewModel = Mapper.Map <ServiceProvider, ServiceProviderViewModel>(serviceProvider as ServiceProvider);
                response.ServiceProviderViewModel = ServiceProviderViewModel;
            }

            return(response);
        }
        public override void Process()
        {
            leadAdapterAndAccountMap = leadAdaptersRepository.GetLeadAdapterByID(LeadAdapterAccountMapID);

            ServiceProvider ServiceProviders = serviceProviderRepository
                                               .GetServiceProviders(1, CommunicationType.Mail, MailType.TransactionalEmail);

            var response = customFieldService.GetAllCustomFields(new GetAllCustomFieldsRequest(leadAdapterAndAccountMap.AccountID));
            IEnumerable <FieldViewModel> customFields = response.CustomFields;
            var dropdownfeildsresposne = cacheService.GetDropdownValues(leadAdapterAndAccountMap.AccountID);

            IEnumerable <DropdownValueViewModel> phoneFields = dropdownfeildsresposne.Where(x => x.DropdownID == (short)DropdownFieldTypes.PhoneNumberType).Select(x => x.DropdownValuesList).FirstOrDefault();

            var jobLogId = InsertJobLog(leadAdapterAndAccountMap);
            var contacts = this.GetContacts("lead_feed.xml", customFields, jobLogId, phoneFields);

            if (contacts.ContactData != null && contacts.ContactData.Any())
            {
                Logger.Current.Informational("Got contacts for inserting : " + contacts.ContactData.Count);
                /* Bulk Insert */
                Task.Factory.StartNew(() => { MailgunVerification(contacts.ContactData.ToList()); }, TaskCreationOptions.LongRunning);
                Task.Factory.StartNew(() => { ContactsBulkinsert(contacts); }, TaskCreationOptions.LongRunning);
            }
            else
            {
                Logger.Current.Informational("No contacts for inserting, Account name : " + leadAdapterAndAccountMap.AccountName);
            }
        }
Esempio n. 3
0
        private void SendErrorEmail(string subject, string bodyMessage)
        {
            try
            {
                string toEmail   = accountRepository.GetAccountPrimaryEmail(AccountID);
                string fromEmail = ConfigurationManager.AppSettings["SupportEmailId"];

                ServiceProvider ServiceProviders = serviceProviderRepository
                                                   .GetServiceProviders(1, CommunicationType.Mail, MailType.TransactionalEmail);

                LandmarkIT.Enterprise.CommunicationManager.Requests.SendMailRequest sendMailRequest = new LandmarkIT.Enterprise.CommunicationManager.Requests.SendMailRequest();

                Logger.Current.Verbose("Account Id in LeadAdapter:" + leadAdapterAndAccountMap.AccountID);
                Logger.Current.Verbose("Email Guid in LeadAdapter :" + ServiceProviders.LoginToken);
                string subjct = leadAdapterAndAccountMap.AccountName + " - " + subject;

                var body = " Error Message     : " + subject + ".\r\n Account Name     : " + leadAdapterAndAccountMap.AccountName + ".\r\n LeadAdapter        :  " + leadAdapterAndAccountMap.LeadAdapterTypeID.ToString() + "  .\r\n Instance occured on  : " + DateTime.UtcNow + " (UTC).\r\n More Info            : " + bodyMessage;

                List <string> To = new List <string>();
                To.Add(toEmail);
                EmailAgent agent = new EmailAgent();
                sendMailRequest.TokenGuid   = ServiceProviders.LoginToken;
                sendMailRequest.From        = fromEmail;
                sendMailRequest.IsBodyHtml  = true;
                sendMailRequest.DisplayName = "";
                sendMailRequest.To          = To;
                sendMailRequest.Subject     = subjct;
                sendMailRequest.Body        = body;
                sendMailRequest.RequestGuid = Guid.NewGuid();
                var varsendMailresponse = agent.SendEmail(sendMailRequest);
                if (varsendMailresponse.StatusID == LandmarkIT.Enterprise.CommunicationManager.Responses.CommunicationStatus.Success)
                {
                    Logger.Current.Informational("Support mail sent successfully");
                }
                Logger.Current.Verbose("Sending Email in LeadAdapter Engine :" + fromEmail);
            }
            catch (Exception ex)
            {
                Logger.Current.Error("An exception occured while sending email: ", ex);
            }
        }
        /*In this method we will get all the files for the lead adapter and we will download the file to our machine
         * in to the local folder of the lead adapter and we will get all the data that is embeded in the file
         * and we will validate each record and also checking the duplicate status and adding the particular recrod
         * and finally we will upload all the contacts and the joblogs and then we will move the file from local folder
         * to archive folder and we will delete the file from the ftp location.
         */
        public virtual void Process()
        {
            try
            {
                leadAdapterAndAccountMap = repository.GetLeadAdapterByID(LeadAdapterAccountMapID);
                ServiceProvider ServiceProviders = serviceProviderRepository
                                                   .GetServiceProviders(1, CommunicationType.Mail, MailType.TransactionalEmail);

                #region Read FTP
                var ftpManager = new FtpService();
                ftpManager.OnServiceFailure += ftpManager_OnServiceFailure;
                var filesList = ftpManager.GetFiles(leadAdapterAndAccountMap.RequestGuid, string.Empty, ServiceProviders.LoginToken,
                                                    leadAdapterAndAccountMap.LeadAdapterTypeID.ToString(), leadAdapterAndAccountMap.AccountName);

                foreach (var fileName in filesList)
                {
                    /*
                     * Read XML file from local path for Builder Number
                     * Get accounts related to builder number
                     * Copy file to all those accounts
                     * **/
                    try
                    {
                        var localFilePath = Path.Combine(leadAdapterAndAccountMap.LocalFilePath, fileName);
                        ftpManager.Download(leadAdapterAndAccountMap.RequestGuid, string.Empty, fileName, localFilePath);
                        List <LeadAdapterAndAccountMap> leadData = new List <LeadAdapterAndAccountMap>();

                        leadData.Add(leadAdapterAndAccountMap);

                        var nodes = GetNodes(localFilePath);
                        foreach (var node in nodes)
                        {
                            var attributes    = node.GetAllAttributesAndElements();
                            var builderNumber = attributes[_fieldMappings.GetOrDefault("BuilderNumber")].Value;
                            IEnumerable <Guid> matchedGuids = ftpManager.FindMatchGuids(leadAdapterAndAccountMap.RequestGuid);
                            leadData.AddRange(repository.GetEmptyCommunities(builderNumber, leadAdapterAndAccountMap.LeadAdapterTypeID, matchedGuids));
                        }
                        if (File.Exists(localFilePath))
                        {
                            File.Delete(localFilePath);
                        }

                        foreach (LeadAdapterAndAccountMap leadAdapter in leadData.GroupBy(g => g.Id).Select(s => s.First()))
                        {
                            Logger.Current.Informational("Inserting joblog for account id : " + leadAdapter.AccountID);
                            var jobLog = new LeadAdapterJobLogs();
                            jobLog.LeadAdapterAndAccountMapID = leadAdapter.Id;
                            jobLog.LeadAdapterJobStatusID     = LeadAdapterJobStatus.Undefined;
                            jobLog.Remarks  = string.Empty;
                            jobLog.FileName = fileName;
                            List <LeadAdapterJobLogDetails> details = new List <LeadAdapterJobLogDetails>();
                            jobLog.LeadAdapterJobLogDetails = details;
                            var leadAdapterJobLogID = importDataRepository.InsertLeadAdapterjob(jobLog, new Guid(), false, false, leadAdapter.AccountID, leadAdapter.CreatedBy, 1, leadAdapter.CreatedBy, true, 0);

                            var filePath        = Path.Combine(leadAdapter.LocalFilePath, fileName);
                            var fileName_rename = Path.GetFileNameWithoutExtension(filePath) + "~" + leadAdapterJobLogID + Path.GetExtension(filePath);
                            localFilePath = Path.Combine(leadAdapter.LocalFilePath, fileName_rename);

                            ftpManager.Download(leadAdapter.RequestGuid, string.Empty, fileName, localFilePath);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Current.Error("An error occured while accessing file downloading it to matched accounts, filename : " + fileName, ex);
                        continue;
                    }
                }
                ;
                #endregion

                #region Read Local Files
                readLocalFiles(ftpManager);
                #endregion
            }
            catch (IndexOutOfRangeException indexEx)
            {
                Logger.Current.Error("Index out of range exception, account name : " + leadAdapterAndAccountMap.AccountName, indexEx);
            }
            catch (Exception ex)
            {
                Logger.Current.Error("An error occured when uploading the contacts in the lead adapter, account name : " + leadAdapterAndAccountMap.AccountName, ex);
                SendEmail("Exception details" + ex, "Exception while processing data from " + leadAdapterAndAccountMap.LeadAdapterTypeID.ToString() + " LeadAdapter");
            }
            finally
            {
                repository.UpdateProcessedDate(LeadAdapterAccountMapID);
            }
        }