/// <summary> /// Gets the email body. /// </summary> /// <param name="FileId">The file id.</param> /// <param name="EmailTemplId">The email templ id.</param> /// <param name="LoanAlertId">The loan alert id.</param> /// <param name="em">The em.</param> /// <returns></returns> private string GetEmailBody(int FileId, int EmailTemplId, int LoanAlertId, EmailManager.EmailMgr em) { var ereq = new EmailPreviewRequest { FileId = FileId, EmailTemplId = EmailTemplId, LoanAlertId = LoanAlertId }; try { EmailPreviewResponse epr = em.PreviewEmail(ereq); if (epr.resp.Successful) { string emailBody = string.Empty; if (epr.EmailHtmlContent != null && epr.EmailHtmlContent.Length > 0) { emailBody = Encoding.UTF8.GetString(epr.EmailHtmlContent); } return(emailBody); } } catch (Exception exception) { string err = MethodBase.GetCurrentMethod() + string.Format("Generate email body faild for FileId={0} EmailTemplId={1}. Exception: {2}", FileId, EmailTemplId, exception); int Event_id = 4025; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } return(string.Empty); }
/// <summary> /// Acknowledges the alert. /// </summary> /// <param name="currentLoanAlertId">The current loan alert id.</param> /// <param name="userId">The user id.</param> /// <returns></returns> public bool AcknowledgeAlert(int currentLoanAlertId, int userId) { string err = ""; bool logErr = false; DataSet ds = null; try { EmailManager.EmailMgr em = EmailManager.EmailMgr.Instance; bool status = false; ds = m_da.AcknowledgeAlert(currentLoanAlertId, userId, out status); if (status == false) { return(false); } //if ((ds == null) || (ds.Tables.Count <= 0) || (ds.Tables[0].Rows.Count <= 0)) //{ // err = MethodBase.GetCurrentMethod() + " failed to Acknowledge Rule Alert, AlertId=" + currentLoanAlertId; // logErr = true; // return false; //} if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < 1; i++) { int FileId = Convert.ToInt32(ds.Tables[0].Rows[i]["FileId"]); int EmailTemplId = Convert.ToInt32(ds.Tables[0].Rows[i]["AlertEmailTemplId"]); int LoanAlertId = Convert.ToInt32(ds.Tables[0].Rows[i]["LoanAlertId"]); var ereq = new EmailPreviewRequest { FileId = FileId, EmailTemplId = EmailTemplId, LoanAlertId = LoanAlertId }; try { EmailPreviewResponse epr = em.PreviewEmail(ereq); if (!epr.resp.Successful) { err = MethodBase.GetCurrentMethod() + ", failed to get email body from Email Manager. \r\nreason:" + epr.resp.StatusInfo; int Event_id = 4032; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return(false); } string emailBody = string.Empty; if (epr.EmailHtmlContent != null && epr.EmailHtmlContent.Length > 0) { emailBody = Encoding.UTF8.GetString(epr.EmailHtmlContent); } m_da.AcknowledgeAlertEmailQue(currentLoanAlertId, userId, emailBody, epr.EmailHtmlContent); return(true); } catch (Exception exception) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + exception.Message + "\r\n\r\nStackTrace: " + exception.StackTrace; int Event_id = 4033; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return(false); } } } return(true); } catch (Exception e) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + e.Message + "\r\n\r\nStackTrace: " + e.StackTrace; int Event_id = 4035; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return(false); } finally { if (logErr) { Trace.TraceError(err); int Event_id = 4037; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } if (ds != null) { ds.Clear(); ds.Dispose(); ds = null; } } }
public void ProcessLoanRulesOld() { string err = ""; bool logErr = false; DataSet ds = null; try { EmailManager.EmailMgr em = EmailManager.EmailMgr.Instance; ds = m_da.ProcessLoanRules(); if ((ds == null) || (ds.Tables.Count <= 0) || (ds.Tables[0].Rows.Count <= 0)) { err = MethodBase.GetCurrentMethod() + " no rules to process."; int Event_id = 4003; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Information, Event_id, Category); return; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { int EmailId = Convert.ToInt32(ds.Tables[0].Rows[i]["EmailId"]); int FileId = Convert.ToInt32(ds.Tables[0].Rows[i]["FileId"]); int EmailTemplId = Convert.ToInt32(ds.Tables[0].Rows[i]["EmailTmplId"]); int LoanAlertId = Convert.ToInt32(ds.Tables[0].Rows[i]["LoanAlertId"]); int AlertEmailType = Convert.ToInt32(ds.Tables[0].Rows[i]["AlertEmailType"]); var ereq = new EmailPreviewRequest { FileId = FileId, EmailTemplId = EmailTemplId, LoanAlertId = LoanAlertId }; try { EmailPreviewResponse epr = em.PreviewEmail(ereq); if (epr.resp.Successful) { string emailBody = string.Empty; if (epr.EmailHtmlContent != null && epr.EmailHtmlContent.Length > 0) { emailBody = Encoding.UTF8.GetString(epr.EmailHtmlContent); } m_da.UpdateEmailBody(EmailId, LoanAlertId, AlertEmailType, emailBody, epr.EmailHtmlContent); } } catch (Exception exception) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + exception.Message + "\r\n\r\nStackTrace: " + exception.StackTrace; int Event_id = 4005; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } } } catch (Exception e) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + e.Message + "\r\n\r\nStackTrace: " + e.StackTrace; int Event_id = 4007; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return; } finally { if (logErr) { Trace.TraceError(err); int Event_id = 4008; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } if (ds != null) { ds.Clear(); ds.Dispose(); ds = null; } } }
public void ProcessLoanRules() { string err = ""; bool logErr = false; DataSet ds = null; List <Table.PendingRuleInfo> pendingRuelInfos = null; List <Table.TemplateRules> templateRuleses = null; EmailManager.EmailMgr em = EmailManager.EmailMgr.Instance; try { int loop_count = 0; pendingRuelInfos = m_da.GetPendgingRuleInfo(); if (pendingRuelInfos == null || pendingRuelInfos.Count <= 0) { err = MethodBase.GetCurrentMethod() + " no rules to process."; //EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Information); return; } /* * Moved the logic to the database store procedure * * for (int i = 0; i < pendingRuelInfos.Count; i++) * { * try * { * pendingRuelInfos[i].RuleCondValue = m_da.GetConditionValue(pendingRuelInfos[i].FileId, * pendingRuelInfos[i].RuleCondId); * loop_count = loop_count + 1; * if (loop_count > 500) * { * loop_count = 0; * Thread.Sleep(50); * } * } * catch (Exception exception) * { * err = MethodBase.GetCurrentMethod() + string.Format(" GetConditionValue error for FileId<{0}>,RuleCondId<{1}>", pendingRuelInfos[i].FileId, pendingRuelInfos[i].RuleCondId); * EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning); * } * } */ //var invalidRuleInfo = from ri in pendingRuelInfos // where ri.RuleCondValue == -1 // select ri; var invalidRuleInfo = pendingRuelInfos .Select((item, index) => new { Info = item, Index = index }) .Where(x => x.Info.RuleCondValue == -1); foreach (var ruleInfo in invalidRuleInfo) { var pointFieldId = ""; var fieldValue = ""; var prevfieldValue = ""; DataSet ds1 = new DataSet(); try { ds1 = m_da.GetPointFieldIdAndValue(ruleInfo.Info.FileId, ruleInfo.Info.RuleCondId); if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0) { if (!ds1.Tables[0].Rows[0].IsNull("PointFieldId")) { pointFieldId = ds1.Tables[0].Rows[0]["PointFieldId"].ToString(); } if (!ds1.Tables[0].Rows[0].IsNull("CurrentValue")) { fieldValue = ds1.Tables[0].Rows[0]["CurrentValue"].ToString(); } if (!ds1.Tables[0].Rows[0].IsNull("PrevValue")) { prevfieldValue = ds1.Tables[0].Rows[0]["PrevValue"].ToString(); } } } catch (Exception exception) { err = MethodBase.GetCurrentMethod() + " GetPointFieldIdAndValue."; int Event_id = 4009; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } //err = string.Format("FileId={0},PointFieldId={1},Value=[Prev-{5}:Curr-{2}],RuleId={3},RuleConditionId={4}", ruleInfo.Info.FileId, pointFieldId, fieldValue, ruleInfo.Info.RuleId, ruleInfo.Info.RuleCondId, prevfieldValue); //EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning); pendingRuelInfos[ruleInfo.Index].RuleCondValue = 0; } templateRuleses = m_da.GetPendgingTemplateRuleInfo(); if (templateRuleses == null || templateRuleses.Count <= 0) { //err = MethodBase.GetCurrentMethod() + " can't get template rule information."; //EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning); return; } loop_count = 0; var query = from rule in pendingRuelInfos group rule by new { rule.RuleId, rule.FileId } into g select new { GroupKey = g.Key, Conditions = g }; foreach (var groupItem in query) { try { //get template info var templateRuelQuery = from tr in templateRuleses where tr.RuleId == groupItem.GroupKey.RuleId select tr; Table.TemplateRules templateRule = templateRuelQuery.SingleOrDefault(); string AdvFormula = string.Empty; if (templateRule == null) { err = MethodBase.GetCurrentMethod() + " can't get template rule information for ruleID " + groupItem.GroupKey.RuleId; int Event_id = 4011; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); continue; } bool ruleValue = GetAdvFormulaValue(templateRule.AdvFormula, groupItem.Conditions.ToList()); if (ruleValue) { int alertEmailType = 1; int emailTemplId = 0; int fileId = groupItem.GroupKey.FileId; int loanAlertID = 0; loanAlertID = CreateRuleAlert(fileId, groupItem.GroupKey.RuleId, alertEmailType, templateRule.Desc, templateRule.AckReq, "Rule Alert", ""); //create rule alert if (templateRule.AlertEmailTemplId != 0 && templateRule.AckReq == false) { alertEmailType = 1; emailTemplId = templateRule.AlertEmailTemplId; if (loanAlertID != 0) { string emailBody = GetEmailBody(fileId, emailTemplId, loanAlertID, em); UpdateRuleAlertEmailBody(loanAlertID, alertEmailType, emailBody); CreateEmailQue(emailTemplId, loanAlertID, fileId, alertEmailType, emailBody); } } //create rule recom email if (templateRule.RecomEmailTemplid != 0) { alertEmailType = 2; emailTemplId = templateRule.RecomEmailTemplid; if (loanAlertID != 0) { string emailBody = GetEmailBody(fileId, emailTemplId, loanAlertID, em); UpdateRuleAlertEmailBody(loanAlertID, alertEmailType, emailBody); CreateEmailQue(emailTemplId, loanAlertID, fileId, alertEmailType, emailBody); } } } loop_count = loop_count + 1; if (loop_count > 500) { loop_count = 0; Thread.Sleep(50); } UpdateLoanRuleLastCheck(groupItem.GroupKey.RuleId); } catch (Exception exception) { string errInfo = MethodBase.GetCurrentMethod() + string.Format(" Exception: fileID={0}, ruleID={1}, Message: {2}", groupItem.GroupKey.FileId, groupItem.GroupKey.RuleId, exception.Message); int Event_id = 4015; EventLog.WriteEntry(InfoHubEventLog.LogSource, errInfo, EventLogEntryType.Warning, Event_id, Category); } } UpdateRuleManagerServiceStatus(); } catch (Exception e) { err = MethodBase.GetCurrentMethod() + "\r\n\r\nException: " + e.Message + "\r\n\r\nStackTrace: " + e.StackTrace; int Event_id = 4017; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); return; } finally { if (logErr) { Trace.TraceError(err); int Event_id = 4019; EventLog.WriteEntry(InfoHubEventLog.LogSource, err, EventLogEntryType.Warning, Event_id, Category); } if (ds != null) { ds.Clear(); ds.Dispose(); ds = null; } } }