/// <summary> /// Reports the printer status at a specific time /// </summary> private void Reporting() { Config.Load(); if (Config.Reporting.SimpleMailReport || Config.Reporting.ExcelMailReport) { Logger.Log("Reporting started", LogType.Service); PrinterManager manager = new PrinterManager(); while (true) { Config.Load(); Logger.Log("Mail report invoked", LogType.Service); DateTime now = DateTime.Now; if (now <= Config.Reporting.TimeToStart) { Logger.Log("Reporting sleeping for " + (Config.Reporting.TimeToStart - now) , LogType.Service); Thread.Sleep(Config.Reporting.TimeToStart - now); } else { Logger.Log("Reporting sleeping for " + (Config.Reporting.TimeToStart.AddHours(24) - now), LogType.Service); Thread.Sleep(Config.Reporting.TimeToStart.AddHours(24) - now); } manager.LoadPrinterList(); // no need to write the checked printers back to the database // no database update is performed after manager.ParallelPollPrinterList(); MailReportFormatter mailReportFormatter; ReportMessage message = null; if (Config.Reporting.SimpleMailReport) { mailReportFormatter = new TextMailReportFormatter(); mailReportFormatter.AddPrinterList(manager.PrinterList); message = mailReportFormatter.GenerateReportMessage(); try { Mailer.SendMailOverSmtp(Config.Reporting.SendReportTo, "Prinfo.NET Reporting", message.Message); } catch (Exception ex) { Logger.Log(GlobalizationHelper.LibraryResource.GetString("smtp_error") + ex.Message, LogType.Error); } } if (Config.Reporting.ExcelMailReport) { mailReportFormatter = new ExcelMailReportFormatter(); mailReportFormatter.AddPrinterList(manager.PrinterList); message = mailReportFormatter.GenerateReportMessage(); try { Mailer.SendMailOverSmtp(Config.Reporting.SendReportTo, "Prinfo.NET Reporting", message.Message, message.Attachment); } catch (Exception ex) { Logger.Log(GlobalizationHelper.LibraryResource.GetString("smtp_error") + ex.Message, LogType.Error); } } } } }