/// <summary> /// Called when a scheduled job executes /// </summary> /// <returns>A status message to be stored in the database log and visible from admin mode</returns> public override string Execute() { OnStatusChanged(String.Format("Sending scheduled emails...")); List <EventPageBase> allEventPages = AttendScheduledEmailEngine.GetEventPageBases(); List <ScheduledEmailBlock> emailsToSend = AttendScheduledEmailEngine.GetScheduledEmailsToSend(allEventPages); int numberOfMailsSent = 0; int numberOfMailsToSend = emailsToSend.Count; foreach (ScheduledEmailBlock scheduledEmailBlock in emailsToSend) { List <IParticipant> participantsToSendEmailTo = AttendScheduledEmailEngine.GetParticipantsForScheduledEmail(scheduledEmailBlock); foreach (IParticipant participant in participantsToSendEmailTo) { AttendScheduledEmailEngine.SendScheduledEmail(scheduledEmailBlock, participant); numberOfMailsSent++; OnStatusChanged(String.Format("Sent " + numberOfMailsSent + " messages.")); if (_stopSignaled) { return("Stop of job was called"); } } AttendScheduledEmailEngine.MarkAsSent(scheduledEmailBlock); } return("Job completed. Sent " + numberOfMailsSent + " messages through " + numberOfMailsToSend + " templates."); }
protected void Page_Load(object sender, EventArgs e) { List <EventPageBase> AllEvents = AttendScheduledEmailEngine.GetEventPageBases(); List <ScheduledEmailBlock> upcoming = new List <ScheduledEmailBlock>(); List <ScheduledEmailBlock> sendNow = new List <ScheduledEmailBlock>(); foreach (EventPageBase eventPage in AllEvents) { upcoming.AddRange(AttendScheduledEmailEngine.GetScheduledEmailsToSend(eventPage, DateTime.Now, DateTime.MaxValue)); sendNow.AddRange(AttendScheduledEmailEngine.GetScheduledEmailsToSend(eventPage, DateTime.MinValue, DateTime.Now)); } (UpcomingControl as EmailList).Messages = (from x in upcoming orderby x.SendDateTime ascending select x).ToList <ScheduledEmailBlock>(); (SendNowControl as EmailList).Messages = (from x in sendNow orderby x.SendDateTime ascending select x).ToList <ScheduledEmailBlock>(); UpcomingControl.DataBind(); SendNowControl.DataBind(); }