/// <summary> /// Checks if there are any mail notifications scheduled for now. If there is mails will be sent. Otherwise nothing happens. /// </summary> public void RunMailService() { var logMailer = new LogMailer.LogMailer(new LogParserRegex(), new LogReader(), new MailSender(_logger), _logger); try { logMailer.Send(); _logger.Debug($"{this.GetType().Name}, RunMailerService(): logmails send succesfully to admin"); } catch (Exception e) { Console.WriteLine("Kunne ikke sende daglig aktivitet i fejlloggen!"); _logger.LogForAdmin("Fejl under afsendelse af daglig log aktivitet. Daglig aktivitet ikke udsendt."); _logger.Error($"{GetType().Name}, RunMailService(), Error when trying to send daily log mail to admin", e); } var startOfDay = ToUnixTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 00, 00, 00)); var endOfDay = ToUnixTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59)); var notifications = _repo.AsQueryable().Where(r => r.DateTimestamp >= startOfDay && r.DateTimestamp <= endOfDay && !r.Notified); if (notifications.Any()) { Console.WriteLine("Forsøger at sende emails."); foreach (var notification in notifications.ToList()) { if (notification.Repeat) { var newDateTime = ToUnixTime(FromUnixTime(notification.DateTimestamp).AddMonths(1)); _repo.Insert(new MailNotificationSchedule() { DateTimestamp = newDateTime, Notified = false, Repeat = true }); } notification.Notified = true; AttemptSendMails(_mailService, FromUnixTime(notification.PayRoleTimestamp), 2); } _repo.Save(); _logger.Debug($"{this.GetType().Name}, RunMailerService(), Notification mails for leaders sending finished"); } else { _logger.Debug($"{this.GetType().Name}, RunMailerService(): No notifications for leaders found for today"); Console.WriteLine("Ingen email-adviseringer fundet! Programmet lukker om 3 sekunder."); Console.WriteLine(Environment.CurrentDirectory); Thread.Sleep(3000); } }
/// <summary> /// Checks if there are any mail notifications scheduled for now. If there is mails will be sent. Otherwise nothing happens. /// </summary> public void RunMailService() { var logMailer = new LogMailer.LogMailer(new LogParser(), new LogReader(), new MailSender(_logger)); try { logMailer.Send(); } catch (Exception e) { Console.WriteLine("Kunne ikke sende daglig aktivitet i fejlloggen!"); _logger.Log("Fejl under afsendelse af daglig log aktivitet. Daglig aktivitet ikke udsendt.", "mail", e, 2); } var startOfDay = ToUnixTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 00, 00, 00)); var endOfDay = ToUnixTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59)); var notifications = _repo.AsQueryable().Where(r => r.DateTimestamp >= startOfDay && r.DateTimestamp <= endOfDay && !r.Notified); if (notifications.Any()) { Console.WriteLine("Forsøger at sende emails."); foreach (var notification in notifications.ToList()) { if (notification.Repeat) { var newDateTime = ToUnixTime(FromUnixTime(notification.DateTimestamp).AddMonths(1)); _repo.Insert(new MailNotificationSchedule() { DateTimestamp = newDateTime, Notified = false, Repeat = true }); } notification.Notified = true; AttemptSendMails(_mailService, FromUnixTime(notification.PayRoleTimestamp), 2); } _repo.Save(); } else { Console.WriteLine("Ingen email-adviseringer fundet! Programmet lukker om 3 sekunder."); Console.WriteLine(Environment.CurrentDirectory); Thread.Sleep(3000); } }
public void Send_Everything() { var mailSub = NSubstitute.Substitute.For <IMailSender>(); var parserSub = NSubstitute.Substitute.For <ILogParser>(); parserSub .Messages(Arg.Any <List <string> >(), Arg.Any <DateTime>()) .Returns(new List <string> { "Exception doing post of type Core.DomainModel.Substitute", "Exception doing post of type Core.DomainModel.Substitute", "Exception doing post of type Core.DomainModel.Substitute", }); var readerSub = NSubstitute.Substitute.For <ILogReader>(); readerSub.Read(Arg.Any <string>()) .Returns(new List <string> { "28-12-2015 15:21:14 : Exception doing post of type Core.DomainModel.Substitute" }); var logMailer = new Mail.LogMailer.LogMailer(parserSub, readerSub, mailSub); logMailer.Send(); mailSub.Received().SendMail(Arg.Any <string>(), Arg.Any <string>(), @"Web: Exception doing post of type Core.DomainModel.Substitute Exception doing post of type Core.DomainModel.Substitute Exception doing post of type Core.DomainModel.Substitute DMZ: Exception doing post of type Core.DomainModel.Substitute Exception doing post of type Core.DomainModel.Substitute Exception doing post of type Core.DomainModel.Substitute Mail: Exception doing post of type Core.DomainModel.Substitute Exception doing post of type Core.DomainModel.Substitute Exception doing post of type Core.DomainModel.Substitute"); }