Пример #1
0
        /// <summary>
        /// for saing delay lead email data in message table
        /// </summary>
        public void sendDelayLeadNotification()
        {
            Trace.TraceInformation("Worker Role DelayLead sendDelayLeadNotification() called {0}", DateTime.Now);
            try
            {
                try
                {
                    List <int> objallcompany = objLeadNotifcationBusiness.GetAllActiveCompanies();
                    string     culture       = "";
                    string     UserName      = "";
                    int        StageDuration = 0;
                    foreach (int companyId in objallcompany)
                    {
                        IList <ErucaCRM.Domain.LeadEmailNotificationModel> objLeadNotificationModel;
                        try
                        {
                            objLeadNotificationModel = objLeadNotifcationBusiness.GetCompanyDataForEmail(companyId);
                        }
                        catch (Exception exception)
                        {
                            hasError = true;
                            logdata.Append("\n");
                            logdata.Append("," + WorkerRoleDelayLead.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exception.Message + ".Error Occured while Fetching Company data for Email.");
                            continue;
                        }
                        for (int emailNotificationIndex = 0; emailNotificationIndex < objLeadNotificationModel.Count; emailNotificationIndex++)
                        {
                            culture  = objLeadNotificationModel[emailNotificationIndex].CultureName;
                            UserName = objLeadNotificationModel[emailNotificationIndex].Name;
                            WorkerRoleDelayLead.UserId = objLeadNotificationModel[emailNotificationIndex].UserId;
                            string[]      LeadsData        = objLeadNotificationModel[emailNotificationIndex].LeadIds.Split('|');
                            string        currentStageName = "";
                            string        leadId           = "";
                            string        dayDifference    = "";
                            string        title            = "";
                            string        stageId          = "";
                            string        stageName        = "";
                            bool          loopReachedEnd   = false;
                            StringBuilder objstringbuilder = new StringBuilder();
                            for (int leadDataIndex = 0; leadDataIndex < LeadsData.Count(); leadDataIndex++)
                            {
                                string[] LeadSeparated = LeadsData[leadDataIndex].Split(',');
                                if (checkStageLeadData(LeadSeparated.Count()))
                                {
                                    leadId        = LeadSeparated[0];
                                    dayDifference = LeadSeparated[1];
                                    title         = LeadSeparated[2];
                                    stageId       = LeadSeparated[3];
                                    stageName     = LeadSeparated[4];
                                    int stageIdForLead = Convert.ToInt32(stageId);
                                    LeadNotifcationBusiness leadNotificationBusiness = new LeadNotifcationBusiness(unitOfWork);
                                    try
                                    {
                                        StageDuration = leadNotificationBusiness.GetStageLeadDuration(stageIdForLead);
                                    }
                                    catch (Exception exception)
                                    {
                                        hasError = true;
                                        logdata.Append("\n");
                                        logdata.Append("," + WorkerRoleDelayLead.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exception.Message + "." + "Error Occured while Fetching Lead data for StageDuration.");
                                        continue;
                                    }
                                    try
                                    {
                                        if (currentStageName != stageName)
                                        {
                                            if (currentStageName != "")
                                            {
                                                loopReachedEnd = true;
                                            }
                                            else
                                            {
                                                loopReachedEnd = false;
                                            }
                                            if (currentStageName != stageName && loopReachedEnd)
                                            {
                                                objstringbuilder.Append("</ul></div>");
                                            }
                                            currentStageName = stageName;
                                            {
                                                objstringbuilder.Append("<div style='background-color:mintcream;border:1px solid Grey;border-radius:5px; float:left; margin-right:10px; margin-top:30px; width:800px; box-shadow:0 0 3px #666; padding:5px;'>");
                                                objstringbuilder.Append("<p><b>" + CommonFunctions.GetGlobalizedLabel("Lead", "StageName", culture) + " :</b>" + currentStageName + " <i> (" + CommonFunctions.GetGlobalizedLabel("Lead", "MaxDuration", culture) + ":" + StageDuration + CommonFunctions.GetGlobalizedLabel("Lead", "Days", culture) + ") </i></p><br/><b style='float:left'>" + CommonFunctions.GetGlobalizedLabel("Lead", "Leads", culture) + "</b>");
                                                objstringbuilder.Append("<ul style='float:left'><li><b><a href='" + ReadConfiguration.ErucaCRMURL + "#" + Convert.ToInt32(leadId).Encrypt() + "'> " + title + " </a></b><i> (" + CommonFunctions.GetGlobalizedLabel("Lead", "TotalTimeSpent", culture) + " :" + dayDifference + CommonFunctions.GetGlobalizedLabel("Lead", "Days", culture) + ") </i></li>");
                                                //  objstringbuilder.Append("<p><b>" + "Test Check" + " :</b>" + currentStageName + " <i> (" + "Test Check" + ":" + StageDuration + "Test Check" + ") </i></p><br/><b style='float:left'>" + "Test Check" + "</b>");
                                                // objstringbuilder.Append("<ul style='float:left'><li><b><a href='" + ReadConfiguration.ErucaCRMURL + "#" + Convert.ToInt32(leadId).Encrypt() + "'> " + title + " </a></b><i> (" + "Test Check" + " :" + dayDifference + "Test Check" + ") </i></li>");
                                            }
                                        }
                                        else
                                        {
                                            objstringbuilder.Append("<li><b><a href='" + ReadConfiguration.ErucaCRMURL + "#" + Convert.ToInt32(leadId).Encrypt() + "'>" + title + "</a></b><i> (" + CommonFunctions.GetGlobalizedLabel("Lead", "TotalTimeSpent", culture) + " :" + dayDifference + CommonFunctions.GetGlobalizedLabel("Lead", "Days", culture) + ") </i></li>");
                                        }
                                    }
                                    catch (Exception exception)
                                    {
                                        hasError = true;
                                        logdata.Append("\n");
                                        logdata.Append(companyId + "," + WorkerRoleDelayLead.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exception.Message + "." + "Error Occured While Fetching Data From EXCEL File or Configuration File.");
                                    }
                                }
                            }
                            objstringbuilder.Append("</ul></div>");

                            objmailhelper.ToAddress     = objLeadNotificationModel[emailNotificationIndex].EmailId;
                            objmailhelper.RecipientName = objLeadNotificationModel[emailNotificationIndex].Name;
                            objmailhelper.Subject       = Constants.LEADS_TIMEEXCEED_NOTIFICATION_SUBJECT;
                            try
                            {
                                objmailhelper.Body = "<p>" + CommonFunctions.GetGlobalizedLabel("Lead", "Hi", culture) + " " + UserName + ",</p><br/><br/><p>" + CommonFunctions.GetGlobalizedLabel("Lead", "EmailTopMsg", culture) + ":</br></br>";
                                objmailhelper.Body = objmailhelper.Body + objstringbuilder.ToString() + "<div style='clear:both;'></div><div style='width:700px;margin-top:20px;'><p>Regards</p></BR><P>Administration</P></div>";
                                logdata.Append("\n");
                                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                                    CloudConfigurationManager.GetSetting("StorageConnectionString"));
                                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
                                CloudTable       table       = tableClient.GetTableReference("Message");
                                table.CreateIfNotExists();
                                Message message = new Message();
                                AutoMapper.Mapper.Map(objmailhelper, message);
                                EmailBody = message.Body;
                                var sendEmailRow = new SendEmail
                                {
                                    PartitionKey     = message.RecipientName,
                                    RowKey           = message.ToAddress,
                                    EmailAddress     = message.ToAddress,
                                    EmailSent        = false,
                                    MessageBody      = message.Body,
                                    ScheduledDate    = DateTime.Now,
                                    FromEmailAddress = ReadConfiguration.EmailForScheduler,
                                    SubjectLine      = message.Subject,
                                };
                                try
                                {
                                    Trace.TraceInformation("Worker Role DelayLead saved data in message table {0}", DateTime.Now);
                                    TableOperation insertOperation = TableOperation.InsertOrReplace(sendEmailRow);
                                    table.Execute(insertOperation);
                                }
                                catch (Exception ex)
                                {
                                    string err = "Error creating SendEmail row:  " + ex.Message;
                                    if (ex.InnerException != null)
                                    {
                                        err += " Inner Exception: " + ex.InnerException;
                                    }
                                    Trace.TraceError(err);
                                }
                                string queueMessageString =
                                    sendEmailRow.PartitionKey + "," +
                                    sendEmailRow.RowKey + ",";
                                CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

                                var queueMessage = new CloudQueueMessage(queueMessageString);
                                sendEmailQueue = queueClient.GetQueueReference("azuremailqueue");
                                sendEmailQueue.AddMessage(queueMessage);
                                Trace.TraceInformation("Worker Role DelayLead saved data in queue table {0}", DateTime.Now);
                                logdata.Append(companyId + "," + WorkerRoleDelayLead.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Success.ToString() + "," + objmailhelper.Subject);
                            }
                            catch (System.Net.Mail.SmtpException exception)
                            {
                                hasError = true;
                                logdata.Append("\n");
                                logdata.Append(companyId + "," + WorkerRoleDelayLead.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exception.Message + "." + "Error Occured on Sending Email to the the User");
                            }
                            catch (Exception exception)
                            {
                                hasError = true;
                                logdata.Append("\n");
                                logdata.Append(companyId + "," + WorkerRoleDelayLead.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exception.Message + "." + "Error Occured on Sending Email to the the User");
                            }
                        }
                    }
                    saveEmailData(hasError, logdata, startdate);
                    // await messageTable.ExecuteAsync(returnInsertOperation);
                }
                catch (Exception exception)
                {
                    hasError = true;
                    logdata.Append("\n");
                    logdata.Append("," + WorkerRoleDelayLead.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exception.Message + "." + "Error Occured while Fetching Company.");
                    saveEmailData(hasError, logdata, startdate);
                }
            }
            catch (Exception ex)
            {
                //  Add(ex, true);
            }
        }
Пример #2
0
        /// <summary>
        /// Save Recent Activites emails to azure table
        /// </summary>
        public void GetRecentActivitiesEmailData()
        {
            Trace.TraceInformation("Worker Role RecentActivity start GetRecentActivitiesEmailData() {0}", DateTime.Now);

            try
            {
                List <int> objallcompany = objLeadNotifcationBusiness.GetAllActiveCompanies();
                foreach (int companyId in objallcompany)
                {
                    try
                    {
                        accountSetting = userBusiness.GetSendNotificationsActiveUsersId(companyId);
                    }
                    catch (Exception accountSettingExp)
                    {
                        hasError = true;
                        logdata.Append("\n");
                        logdata.Append(companyID + "," + " " + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + accountSettingExp.Message + ". Error Occured When Feching  User Account Setting Data");
                        continue;
                    }
                    try
                    {
                        foreach (var user in accountSetting)
                        {
                            WorkerRoleRecentActivity.CultureName = user.User.CultureInformation == null ? "en-US" : user.User.CultureInformation.CultureName;
                            WorkerRoleCommonFunctions.SetCurrentUserCulture();
                            WorkerRoleRecentActivity.UserId = user.UserId;
                            companyID = companyId;
                            WorkerRoleRecentActivity.TimeZoneOffSet = user.User.TimeZone == null ? "0" : user.User.TimeZone.offset.ToString();
                            int TotalRecords = 0;
                            List <SSP_GetRecentActivitesForEmailNotification_Result> RecentActivities = new List <SSP_GetRecentActivitesForEmailNotification_Result>();
                            try
                            {
                                RecentActivities = objLeadNotifcationBusiness.GetRecentActivitiesForNotification(ErucaCRM.Utility.ReadConfiguration.PageSize, companyId, user.UserId, ref TotalRecords);
                                AutoMapper.Mapper.Map(RecentActivities, RecentActivitiesModel);
                            }
                            catch (Exception exRecentActivities)
                            {
                                hasError = true;
                                logdata.Append("\n");
                                logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exRecentActivities.Message + ". Error Occured When Feching Recent Activites Data");
                                continue;
                            }

                            objmailhelper = new ErucaCRM.Utility.MailHelper();
                            if (RecentActivities.Count > 0)
                            {
                                maxLeadAuditId = RecentActivities.Max(x => x.LeadAuditId);
                            }
                            foreach (var homemodel in RecentActivitiesModel)
                            {
                                try
                                {
                                    MailBodyTemplat    = WorkerRoleCommonFunctions.GetGlobalizedLabel("EmailTemplates", "RecentActivityEmailBody", WorkerRoleRecentActivity.CultureName);
                                    mailSubjectTemplat = WorkerRoleCommonFunctions.GetGlobalizedLabel("EmailTemplates", "RecentActivityEmailSubject", WorkerRoleRecentActivity.CultureName);
                                    objmailhelper.Body = objmailhelper.Body + string.Format(MailBodyTemplat, ErucaCRM.Utility.ReadConfiguration.OwnerDetail + Convert.ToInt32(homemodel.CreatedBy).Encrypt(), ErucaCRM.Utility.ReadConfiguration.NoImage, homemodel.LeadAuditId, homemodel.ActivityText, homemodel.ActivityCreatedTime);
                                    if (objmailhelper.Subject == null)
                                    {
                                        objmailhelper.Subject = string.Format(mailSubjectTemplat, TotalRecords);
                                    }
                                    leadAuditIds.Add(homemodel.LeadAuditId);
                                }
                                catch (Exception expEmailTemplate)
                                {
                                    hasError = true;
                                    logdata.Append("\n");
                                    logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + expEmailTemplate.Message + ". Error Occured When Reading Config File (OwnerDetail|NoImage|) || Reading Culture File.(EmailTemplates(RecentActivityEmailBody|RecentActivityEmailSubject|))");
                                }
                            }
                            if (RecentActivitiesModel.Count > 0)
                            {
                                try
                                {
                                    objmailhelper.Body = "<div style='width: 450px'> <div style='width:100%;text-align:center'><img src='" + ErucaCRM.Utility.ReadConfiguration.SiteUrl + ErucaCRM.Utility.ReadConfiguration.WebsiteLogoPath + "'></div>" + objmailhelper.Body;

                                    if (TotalRecords > ErucaCRM.Utility.ReadConfiguration.PageSize)
                                    {
                                        objmailhelper.Body = objmailhelper.Body + " <div style='text-align: right; margin: 15px 0 0 0;'><a href='" + ErucaCRM.Utility.ReadConfiguration.PopUrl + "' style='text-decoration:none;background: none repeat scroll 0 0 #0798bc; width:300px;color: #fff; font-size: 9px; border: 1px solid #8db6e4; border-radius: 3px; cursor: pointer; margin: 14px 5px 13px; padding: 1px;'>" + WorkerRoleCommonFunctions.GetGlobalizedLabel("DashBoard", "ViewAll", WorkerRoleRecentActivity.CultureName) + "</a></div></div>";
                                    }
                                    //send email
                                    objmailhelper.ToAddress     = user.User.EmailId;
                                    objmailhelper.RecipientName = user.User.FirstName + " " + user.User.LastName;
                                    //objmailhelper.SendMailMessage(objmailhelper.ToAddress, objmailhelper.Subject, objmailhelper.Body);

                                    // Retrieve the storage account from the connection string.
                                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                                        CloudConfigurationManager.GetSetting("StorageConnectionString"));
                                    // Create the table client.
                                    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
                                    // Create the table if it doesn't exist.
                                    CloudTable table = tableClient.GetTableReference("Message");
                                    table.CreateIfNotExists();
                                    // Create a new customer entity.

                                    Message message = new Message();
                                    message.ToAddress      = objmailhelper.ToAddress;
                                    message.Subject        = objmailhelper.Subject;
                                    message.Body           = objmailhelper.Body;
                                    message.ReciepientName = objmailhelper.RecipientName;
                                    var sendEmailRow = new SendEmail
                                    {
                                        PartitionKey     = message.ReciepientName,
                                        RowKey           = message.ToAddress,
                                        EmailAddress     = message.ToAddress,
                                        EmailSent        = false,
                                        MessageBody      = message.Body,
                                        ScheduledDate    = DateTime.Now,
                                        FromEmailAddress = ErucaCRM.Utility.ReadConfiguration.EmailForScheduler,
                                        SubjectLine      = message.Subject,
                                    };

                                    try
                                    {
                                        TableOperation insertOperation = TableOperation.InsertOrReplace(sendEmailRow);
                                        table.Execute(insertOperation);
                                        Trace.TraceInformation("Worker Role RecentActivity saved data in message table {0}", DateTime.Now);
                                    }
                                    catch (Exception ex)
                                    {
                                        string err = "Error creating SendEmail row:  " + ex.Message;
                                        if (ex.InnerException != null)
                                        {
                                            err += " Inner Exception: " + ex.InnerException;
                                        }
                                        Trace.TraceError(err);
                                    }

                                    string queueMessageString =
                                        sendEmailRow.PartitionKey + "," +
                                        sendEmailRow.RowKey + ",";
                                    // Create the queue client.
                                    CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
                                    // Retrieve a reference to a queue.
                                    CloudQueue queue = queueClient.GetQueueReference("azuremailqueue");
                                    // Create the queue if it doesn't already exist.
                                    queue.CreateIfNotExists();
                                    var queueMessage = new CloudQueueMessage(queueMessageString);
                                    // Create a message and add it to the queue.
                                    CloudQueueMessage cloudMessage = new CloudQueueMessage("azuremailqueue");
                                    queue.AddMessage(queueMessage);
                                    Trace.TraceInformation("Worker Role RecentActivity saved data in queue table {0}", DateTime.Now);
                                    userBusiness.UpdateUserNotification(WorkerRoleRecentActivity.UserId, maxLeadAuditId);

                                    logdata.Append("\n");
                                    logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Success.ToString() + "," + objmailhelper.Subject);
                                }
                                catch (System.Net.Mail.SmtpException expEmailSend)
                                {
                                    hasError = true;
                                    logdata.Append("\n");
                                    logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + expEmailSend.Message + ". Error Occured When Sending Email || Reading Config File File(PopUrl|SiteUrl|WebsiteLogoPath|PageSize).");
                                }
                                catch (Exception expEmailSend)
                                {
                                    hasError = true;
                                    logdata.Append("\n");
                                    logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + expEmailSend.Message + ". Error Occured When Sending Email || Reading Config File File(PopUrl|SiteUrl|WebsiteLogoPath|PageSize).");
                                }
                            }
                        }
                    }
                    catch (Exception exeption)
                    {
                        hasError = true;
                        logdata.Append("\n");
                        logdata.Append(companyID + "," + WorkerRoleRecentActivity.UserId + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exeption.Message);
                    }
                }
                SaveLogData();
            }
            catch (Exception exep)
            {
                logdata.Append("\n");
                logdata.Append("" + "," + "" + "," + ErucaCRM.Utility.Enums.ResponseResult.Failure.ToString() + "," + exep.Message + ". Error Occur When Feching All Company Data.Please Check Network Releated Information.");
                hasError = true;
                SaveLogData();
            }
        }