public void ExecuteReports(object sender, ElapsedEventArgs args) { var actualReports = _reports.GetReports().Where(r => r.FirstReportDate >= DateTime.Today && (DateTime.Today - r.FirstReportDate).TotalDays % TimeSpan.FromDays((int)r.Periodicity).TotalDays == 0) .OrderBy(r => r.Code); IReportHandler handler = null; foreach (var report in actualReports) { switch (report.Code) { case ReportCode.MoveAndStop: if (handler == null || handler.GetType() != typeof(MoveAndStopReportHandler)) { handler = new MoveAndStopReportHandler(); } break; case ReportCode.MessagesFromObject: if (handler == null || handler.GetType() != typeof(MessagesFOReportsHandler)) { handler = new MessagesFOReportsHandler(); } break; default: continue; } report.ExecuteReport(handler); } }