Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public ActionResult <IEnumerable <ReportDto> > GetAllReports()
        {
            string token = HttpContext.Request.Headers["token"];

            if (token != TokenEmulator)
            {
                return(Unauthorized());
            }

            #region Unsafe transfer
            //var reports = new List<ReportDTO>();
            //foreach (var report in _reports.GetReports())
            //{
            //    ReportDTO reportDTO;
            //    switch (report.Code)
            //    {
            //        case ReportCode.MoveAndStop:
            //            var entity = report as MoveAndStopReport;
            //            reportDTO = new ReportDTO()
            //            {
            //            };
            //            break;
            //        case ReportCode.MessagesFromObject:
            //            break;
            //        default:
            //            continue;
            //    }
            //    reports.Add(reportDTO);
            //}
            //var settings = new JsonSerializerSettings()
            //{
            //    TypeNameHandling = TypeNameHandling.Auto
            //};
            //var response = JsonConvert.SerializeObject(reports, settings);
            #endregion

            var response = DtoConverter.ConvertReportsToDtos(_reports.GetReports());
            return(new ActionResult <IEnumerable <ReportDto> >(response));
        }