/// <summary> /// Populates a <see cref="DropDownList"/> with all known candidates. /// </summary> /// <param name="list">The <see cref="DropDownList"/> to fill.</param> protected void FillCandidates(DropDownList list) { list.Items.Clear(); list.Items.Add(new ListItem("(Select a candidate below)", string.Empty)); Dictionary <string, Candidate> candidates = Cfis.GetCandidates(); foreach (Candidate c in candidates.Values) { list.Items.Add(new ListItem(string.Format("{0} (ID: {1})", c.Name, c.ID), c.ID)); } }
private void _timer_Elapsed(object sender, ElapsedEventArgs e) { // check to see if an iteration is already underway if (_accounts != null) { return; } DateTime lastRun = CPProviders.SettingsProvider.LastReminderDistributionDate.Date; // only run once each day if (lastRun.Date == DateTime.Today) { return; } _accounts = new Dictionary <string, IEnumerable <CPUser> >(); try { // get all candidates/accounts foreach (string cid in Cfis.GetCandidates().Keys) { List <CPUser> group = new List <CPUser>(); var users = CPSecurity.Provider.GetCampaignUsers(cid, null, false); foreach (var user in users) { if (!user.Enabled) { continue; } group.Add(user); } _accounts[cid] = group; } // prepare to collect failed addresses NameValueCollection failures = new NameValueCollection(); // iterate through candidates foreach (string cid in _accounts.Keys) { // retrieve this candidate's users var group = _accounts[cid]; if (group == null || group.Count() == 0) { continue; } // retrieve this candidate's elections foreach (string election in Elections.GetActiveElectionCycles(cid)) { // retrieve events from WCF service //ComplianceVisits cv = _dataProxy.GetComplianceVisits(cid, election); //events.AddItems(cv.UpcomingVisits); //events.AddItems(cv.UpcomingDeadlines); //events.AddItems(_dataProxy.GetStatementReviews(cid, election).UpcomingDeadlines); //events.AddItems(_dataProxy.GetFilingDeadlines(cid, election).Upcoming); var dbEvents = GetDoingBusinessEvents(cid, election, lastRun); // iterate through events foreach (CPCalendarItem ev in dbEvents) { if (ev.StartDate.Date > lastRun) { // send e-mail using (EventReminderMessage message = new EventReminderMessage(cid, election, ev)) { //CfbLogger.Write(new CfbLogEntry(string.Format("Sending e-mail for candidate {0}", cid), CfbLogCategory.Trace, 0, CfbEventID.Informational, TraceEventType.Information, "EventReminderMessage Tick Start", null)); message.Recipients = group; NameValueCollection failed = message.Send(); if (failed.Count > 0) { foreach (string recipient in failed.Keys) { failures[recipient] = failed[recipient]; } } } } } int dbCount = dbEvents.Count(); if (dbCount > 0) { CfbLogger.Write(new CfbLogEntry(string.Format("Processed {0} upcoming Doing Business Review events for candidate ID: {1}, election cycle: {2}", dbCount, cid, election), CfbLogCategory.Email, 0, CfbEventID.Informational, TraceEventType.Information, "EventReminderMessage Processed Events", null)); } } } // log failed addresses if (failures.Count > 0) { StringBuilder errorMessage = new StringBuilder("The following error(s) occurred while sending reminder e-mails to the following C-Access users:\n\n"); foreach (string recipient in failures.Keys) { errorMessage.AppendFormat("{0}: {1}\n\n", recipient, failures[recipient]); } CfbLogger.Write(new CfbLogEntry(errorMessage, CfbLogCategory.Email, 0, CfbEventID.EmailFailure, TraceEventType.Warning, "EventReminderMessage Failure", null)); } } catch (Exception ex) { if (CfbExceptionPolicy.LogException(ex)) { throw; } } finally { CPProviders.SettingsProvider.LastReminderDistributionDate = DateTime.Now; _accounts = null; } }