private void BtnDuplicate_Click(object sender, EventArgs e) { AutoMailerCDORoot cdo = AutoMailerCDO.CDO; if (!string.IsNullOrEmpty(TriggerName)) { MailTrigger trigger = cdo.Triggers.Where(x => x.Name.Equals(TriggerName)).FirstOrDefault(); MailTrigger newTrigger = trigger.Clone(trigger); cdo.Triggers.Add(newTrigger); AutoMailerCDO.UpdateCDO(cdo); AutoMailerCDO.UploadCDO(); SetupControls(); } }
private void BtnDelete_Click(object sender, EventArgs e) { bool update = !string.IsNullOrEmpty(TriggerName); if (update) { AutoMailerCDORoot cdo = AutoMailerCDO.CDO; MailTrigger trigger = cdo.Triggers.Where(x => x.Name.Equals(TriggerName)).FirstOrDefault(); cdo.Triggers.Remove(trigger); AutoMailerCDO.UpdateCDO(cdo); AutoMailerCDO.UploadCDO(); SetupControls(); } }
private void BtnSave_Click(object sender, EventArgs e) { AutoMailerCDORoot cdo = AutoMailerCDO.CDO; bool update = !string.IsNullOrEmpty(TriggerName); if (cdo.Triggers.Any(x => x.Name.Equals(txtName.Text)) && !update) { MessageBox.Show("There is already a Trigger with this name."); return; } if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("Name cannot be blank."); return; } MailTrigger trigger = update ? cdo.Triggers.Where(x => x.Name.Equals(TriggerName)).FirstOrDefault() : new MailTrigger(); trigger.Name = txtName.Text; trigger.ReportFilter = cmbReports.SelectedItem.ToString(); trigger.Frequency = (FrequencyType)Enum.Parse(typeof(FrequencyType), cmbFrequency.SelectedItem.ToString()); trigger.Time = dtpTime.Value; trigger.Date = dtpDate.Value; trigger.Days = chkDays.CheckedIndices.Cast <int>().ToArray(); trigger.To = txtTo.Text; trigger.CC = txtCC.Text; trigger.BCC = txtBcc.Text; trigger.Subject = txtSubject.Text; trigger.Body = txtHtml.Text; trigger.Active = chkTriggerActive.Checked; if (!update) { cdo.Triggers.Add(trigger); } AutoMailerCDO.UpdateCDO(cdo); AutoMailerCDO.UploadCDO(); SetupControls(); }
public List <ITask> GetTriggers() { AutoMailerCDO cdo = CustomDataObject.Get <AutoMailerCDO>(AutoMailerCDO.Key); List <MailTrigger> Triggers = cdo.Triggers; List <ITask> result = new List <ITask>(); DateTime Now = DateTime.Now; foreach (MailTrigger trigger in Triggers.Where(x => x.Active)) { bool run = false; if (!trigger.Active) { continue; } bool onTime = trigger.Time.Hour.Equals(Now.Hour) && trigger.Time.Minute.Equals(Now.Minute) && Math.Abs(trigger.Time.Second - Now.Second) < 10; run = (trigger.Frequency == Enums.FrequencyType.Daily || trigger.Frequency == Enums.FrequencyType.Weekly || trigger.Frequency == Enums.FrequencyType.BiWeekly) && DaysOfWeek(trigger.Days).Contains(Now.DayOfWeek.ToString()) && onTime; if (!run) { run = trigger.Frequency == Enums.FrequencyType.Monthly && onTime && Now.Day.Equals(trigger.Date.Day); } if (!run) { run = trigger.Frequency == Enums.FrequencyType.Yearly && onTime && Now.Day.Equals(trigger.Date.Day) && Now.Month.Equals(trigger.Date.Month); } if (run) { result.Add(trigger); } } return(result); }