Exemplo n.º 1
0
        public async Task FileLevelErrorReportAsync(
            IEasJobContext easContext,
            IEnumerable <EasCsvRecord> models,
            IEnumerable <ValidationErrorModel> errors,
            CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            var reportOutputFilenames = new List <string>();

            if (!string.IsNullOrWhiteSpace(easContext.ReportOutputFileNames))
            {
                reportOutputFilenames.AddRange(easContext.ReportOutputFileNames.Split('|'));
            }

            foreach (var validationReport in _validationReports)
            {
                var reportsGenerated = await validationReport.GenerateReportAsync(easContext, models, errors, cancellationToken);

                reportOutputFilenames.AddRange(reportsGenerated);
            }

            await _resultReport.GenerateReportAsync(easContext, models, errors, cancellationToken);

            var zipName = _fileNameService.GetZipName(easContext.Ukprn, easContext.JobId, _zipName);

            await _zipService.CreateZipAsync(zipName, reportOutputFilenames, easContext.Container.ToString(), cancellationToken);

            easContext.ReportOutputFileNames = string.Join("|", reportOutputFilenames);
        }
Exemplo n.º 2
0
        public async Task ProduceReportsAsync(IEnumerable <ReportDataModel> reportData, INcsJobContextMessage ncsJobContextMessage, CancellationToken cancellationToken)
        {
            var reportOutputFileNames = new List <string>();

            foreach (var report in _ncsReports)
            {
                var reportsGenerated = await report.GenerateReport(reportData, ncsJobContextMessage, cancellationToken);

                reportOutputFileNames.AddRange(reportsGenerated);
            }

            var zipName = _filenameService.GetZipName(ncsJobContextMessage.Ukprn, ncsJobContextMessage.JobId, ReportConstants.DctZipName);

            await _zipService.CreateZipAsync(zipName, reportOutputFileNames, ncsJobContextMessage.DctContainer, cancellationToken);

            await CopyZipToDss(zipName, ncsJobContextMessage, cancellationToken);
        }
        private async Task ProduceReports(
            IEsfJobContext esfJobContext,
            SupplementaryDataWrapper wrapper,
            ISourceFileModel sourceFile,
            CancellationToken cancellationToken,
            bool passedFileValidation)
        {
            _logger.LogInfo("ESF Reporting service called");

            var reportNames = new List <string>();

            try
            {
                if (!string.IsNullOrWhiteSpace(sourceFile?.FileName))
                {
                    foreach (var validationReport in _validationReports)
                    {
                        reportNames.Add(await validationReport.GenerateReport(esfJobContext, sourceFile, wrapper, cancellationToken));
                    }
                }

                if (passedFileValidation)
                {
                    var reportsToRun = _esfReports.Where(r => esfJobContext.Tasks.Contains(r.TaskName, StringComparer.OrdinalIgnoreCase));
                    foreach (var report in reportsToRun)
                    {
                        reportNames.Add(await report.GenerateReport(esfJobContext, sourceFile, wrapper, cancellationToken));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                throw;
            }

            var zipFileName = $"{esfJobContext.UkPrn}/{esfJobContext.JobId}{ReportNameConstants.ZipName}";

            await _zipService.CreateZipAsync(zipFileName, reportNames, esfJobContext.BlobContainerName, cancellationToken);
        }
        public async Task <List <string> > Callback(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            List <string> reportOutputFilenames = new List <string>();

            if (!string.IsNullOrWhiteSpace(reportServiceContext.ReportOutputFileNames))
            {
                reportOutputFilenames.AddRange(reportServiceContext.ReportOutputFileNames.Split('|').ToList());
            }

            _logger.LogDebug("Inside ReportService callback");

            try
            {
                _excelService.ApplyLicense(Assembly.GetExecutingAssembly().GetManifestResourceStream(LicenseResource));

                if (cancellationToken.IsCancellationRequested)
                {
                    _logger.LogDebug("ReportService Callback  cancelling before Generating Reports");
                }

                // list of reports to be generated
                var reportsToBeGenerated = _reports.Where(x => reportServiceContext.Tasks.Contains(x.TaskName, StringComparer.OrdinalIgnoreCase)).ToList();

                if (!_reports.Any())
                {
                    _logger.LogDebug($"No reports found.");
                }

                // Populate Dependent data.
                _logger.LogInfo("Starting External Data");

                var reportsDependsOn     = reportsToBeGenerated.SelectMany(x => x.DependsOn).Distinct().ToList();
                var reportsDependentData = await _reportsDependentDataPopulationService.PopulateAsync(reportServiceContext, reportsDependsOn, cancellationToken);

                await _reportServiceContextKeysMutator.MutateAsync(reportServiceContext, reportsDependentData, cancellationToken);

                _logger.LogInfo("Finishing External Data");

                foreach (var report in reportsToBeGenerated)
                {
                    _logger.LogInfo($"Starting {report.GetType().Name}");

                    var reportsGenerated = await report.GenerateAsync(reportServiceContext, reportsDependentData, cancellationToken);

                    reportOutputFilenames.AddRange(reportsGenerated);

                    _logger.LogInfo($"Finishing {report.GetType().Name}");
                }

                await _zipService.CreateZipAsync(reportServiceContext, reportOutputFilenames, reportServiceContext.Container, cancellationToken);

                reportServiceContext.ReportOutputFileNames = string.Join("|", reportOutputFilenames);

                _logger.LogDebug("Completed ReportService callback");
            }
            catch (Exception ex)
            {
                _logger.LogError($"ReportService callback exception {ex.Message}", ex);
                throw;
            }

            return(reportOutputFilenames);
        }