Hi,
I needed to run some email-reminder task so I created a class to perform this task.
It simply does a DB query and sends an email for every returned record.
I tried following the instructions in the book + found some code samples, so I attached my class at the end.
My full class name is: Igiza.UnnTasks.SendInvitationReminders
Then I built my project using aspnet_compiler to get a DLL, copied this DLL (called Asp_Subcode_UnnTasks) into the bin directory of my website and then I created a Scheduler entry:
Full class name and assembley: Igiza.UnnTasks.SendInvitationReminders, App_SubCode_UnnTasks
Schedule Enabled: Yes
Time Lapse: 1 minute
Retry Frequency: 1 minute
The rest is default.
If I attach a debugger I see that my constructor is getting called but objScheduleHistoryItem has Success=false, and my DoWork() is never called (don't know if it's related).
What can be the reason for that and how can I make this simple scheduler work?
Many thanks
Ofer
==================
using System;using System.Data;using System.Collections.Generic;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using DotNetNuke;using DotNetNuke.Services;using DotNetNuke.Services.Scheduling;using DotNetNuke.Services.Exceptions;using DotNetNuke.Common.Lists;using DotNetNuke.Services.Localization;using DotNetNuke.Services.Mail;using Igiza.Modules.UnnInvite;using Igiza.Common;namespace Igiza.UnnTasks/// <summary>/// Summary description for SendInvitationReminders/// </summary>public class SendInvitationReminders : DotNetNuke.Services.Scheduling.SchedulerClient{/// <summary>
/// Constructor
/// </summary>
/// <param name="objScheduleHistoryItem"></param>public SendInvitationReminders(ScheduleHistoryItem objScheduleHistoryItem)
{
base.SchedulerEventGUID = "";
base.aProcessMethod = "";
base.Status = "";
base.ScheduleHistoryItem = new ScheduleHistoryItem();
this.ScheduleHistoryItem = objScheduleHistoryItem;
}public override void DoWork()
{
try
{
this.Progressing(); // Optional
ListController listCtl = new ListController();
ListEntryInfo leInfo = listCtl.GetListEntryInfo("unn_GlobalParams", "ScheduledSendReminderEmailDays");
int days = 0;
int invites = 0;
if (leInfo != null)
{
days = Convert.ToInt32(leInfo.Text);
} if (days > 0)
{
//
// ok to send reminders..
//
UnnInviteController inviteCtl = new UnnInviteController();
List<UnnInviteInfo> inviteCol = inviteCtl.GetInvitations(days);
foreach (UnnInviteInfo info in inviteCol)
{
//
// loop thru the invitation list collection
//
string emailSubject = Localization.GetString("EMAIL_USER_REMINDER_SUBJECT.Text", UnnUtils.UnnSystemEmailsFile);
//
// Now send the email to the new user
//
Mail.SendMail(/*info.SenderEmail*/ "ofer@igiza.com", info.EmailAddress, "", emailSubject, info.InvitingUserMessage, "", "html", "", "", "", "");//
// Update the record that am enail was sent
//
inviteCtl.UpdateReminders(info.Token);
//
// increase the reminders count
//
invites++;this.ScheduleHistoryItem.Succeeded = true; // Requiredthis.ScheduleHistoryItem.AddLogNote(string.Format("SendInvitationReminders: Sent {0} invitations", invites));catch (Exception exc)this.ScheduleHistoryItem.Succeeded = false; // Requiredthis.ScheduleHistoryItem.AddLogNote("EXCEPTION: " + exc.ToString()); // Optional// notification that we have erroredthis.Errored(ref exc);// log the exceptionExceptions.LogException(exc); // Optional}
{
}
}
}
{
}
}
}