Advertisement
davidb37

Notifications for Clandar

Apr 5th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 KB | None | 0 0
  1.       protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             Timer timer = new Timer();
  4.  
  5.             reminder = 5;
  6.             worker = new BackgroundWorker();
  7.             worker.DoWork += worker_DoWork;
  8.  
  9.             timer.Elapsed += timer_Elapsed;
  10.             timer.Interval = TimeSpan.FromMinutes(reminder).TotalMilliseconds;
  11.  
  12.             timer.Enabled = true;
  13.             timer.Start();
  14.         }
  15.  
  16.         private void timer_Elapsed(object sender, ElapsedEventArgs e)
  17.         {
  18.             if (!worker.IsBusy)
  19.                 worker.RunWorkerAsync();
  20.         }
  21.  
  22.         private void worker_DoWork(object sender, DoWorkEventArgs e)
  23.         {
  24.             //whatever You want the background thread to do...
  25.             doReminders(reminder);
  26.         }
  27.  
  28.         /// <summary>
  29.         /// Does the reminders.
  30.         /// sends out reminders based on the amount of minuties before a meeting
  31.         /// </summary>
  32.         protected void doReminders(double reminder)
  33.         {
  34.             try
  35.             {
  36.                 List<ApertureDal.Appointment> _appointments = _dal.GetAppointmentsByReminderLength(reminder);
  37.  
  38.                 _appointments.ForEach(x =>
  39.                 {
  40.                     _dal.sendAppointmentEmails(x.ID, x.emailAddress, x.TimeCode, x.emailAddress, new Guid(Constants.calenderEmail), x.CustomerFirstName, x.CustomerLastName, x.managerName, x.preferedContactNumber, x.emailAddress, x.Start, x.End, x.managerId);
  41.                 });
  42.             }
  43.             catch (Exception ex)
  44.             {
  45.             }
  46.         }
  47.     }
  48.  
  49.  
  50.  
  51.         /// <summary>
  52.         /// Gets the appointments.
  53.         /// </summary>
  54.         /// <param name="reminderLength">Length of the reminder.</param>
  55.         /// <returns></returns>
  56.         public List<Appointment> GetAppointmentsByReminderLength(double reminderLength)
  57.         {
  58.             List<Appointment> list = new List<Appointment>();
  59.  
  60.             try
  61.             {
  62.                 var q = from a in apertureNetEntities.Appointments.Where(a => a.Start.Value.AddMinutes(-reminderLength) <= DateTime.Now)
  63.                         select a;
  64.  
  65.                 list = q.ToList();
  66.             }
  67.             catch (Exception ex)
  68.  
  69.             {
  70.                 string inner = string.Empty;
  71.                 if (ex.InnerException != null)
  72.                 {
  73.                     inner = ex.InnerException.ToString();
  74.                 }
  75.                 logger.Error("Error in List<Appointment> function GetAppointmentsByReminderLength " + ex.ToString() + " " + inner);
  76.                 return null;
  77.             }
  78.  
  79.             return list;
  80.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement