public async Task <Result> Handle(GetStatistics request, CancellationToken cancellationToken) { _logger.LogInformation("Getting statistics"); try { var today = DateTime.Today.ToLocalTime().Date; var schedules = await _repository.GetReportSchedulesAsync(); var statistics = new { TotalSchedules = schedules.Count(), ExecutingSchedules = schedules .Count(s => today > s.EmissionStart.Date && s.EmissionEnd.Date > today), OutdatedSchedules = schedules .Count(s => today > s.EmissionEnd.Date), FutureSchedules = schedules .Count(s => today < s.EmissionStart.Date) }; return(Result.Success(statistics)); } catch (Exception e) { _logger.LogError(e, "In Get Statistics Handler"); return(Result.Fail(e)); } }
public async Task Handle(NewDay notification, CancellationToken cancellationToken) { _logger.LogInformation("Initialized deletion of outdated schedules"); try { var schedules = await _repository.GetReportSchedulesAsync(); var outdated = schedules .Where(s => s.EmissionEnd.Date < DateTime.Now.Date.AddDays(15)) .Select(s => s.Id); _logger.LogInformation($"Schedules to delete: {outdated.Count()}"); if (outdated != null && outdated.Count() > 0) { await _repository.DeleteSchedulesAsync(outdated); } } catch (Exception e) { _logger.LogError(e, e.Message); throw e; } }
public async Task <Result> Handle(GetReportScheduleInfos request, CancellationToken cancellationToken) { try { var schedules = await _repository.GetReportSchedulesAsync(); return(Result.Success(schedules .ToList() .Select(x => x.AsInfoDto()))); } catch (Exception e) { return(Result.Fail(e)); } }
public async Task Handle(NewDay notification, CancellationToken cancellationToken) { var today = _date.Now(); try { var schedules = await _repository.GetReportSchedulesAsync(); var reportConstructConfigurations = schedules .Where(x => _date.IsEarlier(today, x.EmissionEnd) && _date.IsEarlier(x.EmissionStart, today)) .Where(x => ShouldBeEmittedToday(x)) .Select(x => new ReportConstructionDescriptor() { ReportTemplateId = x.ReportTemplate, AssignedOrganizationIds = x.AssignedOrganizations, DeadlineDate = today + x.DeadlinePeriod }) .ToList(); if (reportConstructConfigurations is null || reportConstructConfigurations.Count() == 0) { return; } var command = new ConstructReports() { ReportDescriptors = reportConstructConfigurations }; await _service.CommandAsync(command, "constructor", "api/cs/report/construct"); } catch (Exception e) { throw e; } }