我如何在Scheduler的DoWork()方法中检索DNN ModuleSetting或TabSetting?

问题描述 投票:0回答:1

我有一个DotNetNuke模块,它有一个名为CRMCheck的View和Scheduler类。

我已经设置了我的Scheduler任务来每隔几分钟调用我的类。(MyModule.Module.CRM.CRMCheck)

我需要检索保存的Module或TabSettings的Setting。我正在保存Module和ModuleTabSettings,默认情况下,DNN在使用Settings[]时将使用ModuleTabSettings,并同时保存这两个模块。

所以我的主要问题是我想获取我在模块的设置部分保存的电子邮件地址,而Scheduler DoWork()方法应该使用这个地址。

我还遇到了一个问题,就是当你使用Scheduler时,你无法获得portal ID,DNN在这篇文章中也说明了这一点。https:/dnncommunity.orgforumsaft191

这就是错误。

enter image description here

这是在我的模块View Class下面的Scheduler代码。

    public class CRMCheck : SchedulerClient
{
    private readonly DaoCRM m_DaoCRM = new DaoCRM();


public CRMCheck(ScheduleHistoryItem oItem) : base()
    {
        this.ScheduleHistoryItem = oItem;
    }

    public Control LocalResourceFile { get; private set; }

    public override void DoWork()
    {
        try
        {
            //Perform required items for logging
            this.Progressing();

            //Your code goes here
            DateTime? TimeNow = DateTime.Now;
            var CRMItems = ShowCRMListDNN();
            foreach (var item in CRMItems)
            {
                DateTime? RegisteredDateINDatabase = item.DateRegistered;
                var TimeDifference = TimeNow - RegisteredDateINDatabase;
                var DidTheyPurchaseSomething = item.PurchasedSomething;
                if(TimeDifference.Value.TotalHours > 3 && DidTheyPurchaseSomething == false)
                {
                    //email and stuff
                    SendSuccessEmailToAdmin(item.FirstName, item.LastName, item.CompanyName, item.EmailAddress, item.Cellphone, item.ERPUserId, item.DateRegistered, item.PortalID, item.PurchasedSomething);
                }
            }


            //To log note
            this.ScheduleHistoryItem.AddLogNote("Item Executed");

            //Show success
            this.ScheduleHistoryItem.Succeeded = true;
        }
        catch (Exception ex)
        {
            this.ScheduleHistoryItem.Succeeded = false;
            //InsertLogNote("Exception= " + ex.ToString());
            this.Errored(ref ex);
            DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
        }
    }

    public List<CRM> ShowCRMListDNN()
    {
        var result = new List<CRM>();
        try
        {
            return result = m_DaoCRM.ShowCRMListNoPortalID();
        }
        catch (Exception ex)
        {
        EventLogController logController = new EventLogController();
        logController.AddLog("Problem fetching CRM List for Scheduled Job.", ex.ToString(), EventLogController.EventLogType.ADMIN_ALERT);
        return result;
      }
    }

    /// <summary>
    /// Sends an email when the job runs
    /// </summary>
    /// <remarks>ZR - Added - 09/03/2018</remarks>
    private void SendSuccessEmailToAdmin(string FirstName, string LastName, string CompanyName, string Email, string Cellphone, int ERPUserID, DateTime? DateRegistered, int Portal, bool PurchasedSomething)
    {
        if (Settings["CRMEmail"] != null && !string.IsNullOrWhiteSpace(Settings["CRMEmail"].ToString()))
        {
            System.Text.StringBuilder strAdminEmailMsg = new System.Text.StringBuilder();

            strAdminEmailMsg.AppendLine("<br><br>");
            strAdminEmailMsg.AppendLine("<table style=\"border-color:#007799;color:#007799;border-style:double;font-family:arial,verdana;font-size:8pt;\" width=\"70%\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\">");
            strAdminEmailMsg.AppendLine("    <tr>");
            strAdminEmailMsg.AppendLine("        <td style=\"text-align:center;background:#007799;color:#ffffff;font-weight:bold;font-family:arial;font-size:11pt;\">New Customer Registration</td>");
            strAdminEmailMsg.AppendLine("    </tr>");
            strAdminEmailMsg.AppendLine("    <tr>");
            strAdminEmailMsg.AppendLine("        <td align=\"center\"><table width=\"80%\" style=\"font-family:verdana;font-size:8pt;\">");
            strAdminEmailMsg.AppendFormat("  <tr><td align=\"left\">Date:</td><td align=\"left\">{0}</td></tr>", DateTime.Now.ToLocalTime()).AppendLine();
            strAdminEmailMsg.AppendLine("</table>");

            strAdminEmailMsg.AppendLine("<table style=\"color:#007799;font-family:arial,verdana;font-size:8pt;\" width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\">");
            strAdminEmailMsg.AppendLine("    <tr>");
            strAdminEmailMsg.AppendLine("        <td>&nbsp;</td>");
            strAdminEmailMsg.AppendLine("    </tr>");
            strAdminEmailMsg.AppendLine("    <tr>");
            strAdminEmailMsg.AppendLine("        <td style=\"text-align:center\">&nbsp;");
            //all changes in inner table
            strAdminEmailMsg.AppendLine("            <table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#007799\" border=\"1\" style=\"font-family:verdana;font-size:8pt;border-collapse:collapse;\">");
            strAdminEmailMsg.AppendLine("                <tr>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">FirstName</td>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">{0}</td>", FirstName);
            strAdminEmailMsg.AppendLine("                </tr>");
            strAdminEmailMsg.AppendLine("                <tr>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">Last Name</td>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">{0}</td>", LastName);
            strAdminEmailMsg.AppendLine("                </tr>");
            strAdminEmailMsg.AppendLine("                <tr>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">Company Name</td>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">{0}</td>", CompanyName);
            strAdminEmailMsg.AppendLine("                </tr>");
            strAdminEmailMsg.AppendLine("                <tr>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">Email</td>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">{0}</td>", Email);
            strAdminEmailMsg.AppendLine("                </tr>");
            strAdminEmailMsg.AppendLine("            </table>");
            strAdminEmailMsg.AppendLine("        </td>");
            strAdminEmailMsg.AppendLine("    </tr>");
            strAdminEmailMsg.AppendLine("</table>");

            SendEmail("System Job", strAdminEmailMsg.ToString(), Settings["CRMEmail"].ToString());
        }
    }

    /// <summary>
    /// Send an email
    /// </summary>
    /// <param name="MailSubject"></param>
    /// <param name="MailMessage"></param>
    /// <param name="RecipientEmail"></param>
    private void SendEmail(string MailSubject, string MailMessage, string RecipientEmail)
    {
        bool EmailSent = false;

        //EmailSent = webcall
        EmailSent = SessionManager.GSettings.Globalvars.ClHelper.eBusiness.SendEmail(-1, 2, RecipientEmail, MailSubject, MailMessage);

        //Show a message to the user if it was sent or not
        if (!EmailSent)
        {
            EventLogController logController = new EventLogController();
            logController.AddLog("Problem sending Job Email", "", EventLogController.EventLogType.ADMIN_ALERT);
        }

    }

}
dotnetnuke scheduler dnn9
1个回答
0
投票

我找到了一个变通的方法,创建了一个Dao类的方法,通过这个方法,我可以调用一个数据库查询到ModuleSettings表。

© www.soinside.com 2019 - 2024. All rights reserved.