public override async Task GenerateReport( IReportServiceContext reportServiceContext, ZipArchive archive, CancellationToken cancellationToken) { var externalFileName = GetFilename(reportServiceContext); var fileName = GetZipFilename(reportServiceContext); var fcsLookup = await _fcsProviderService.GetContractAllocationNumberFSPCodeLookupAsync(reportServiceContext.Ukprn, cancellationToken); var periodisedValuesLookup = await _periodisedValuesLookupProvider.ProvideAsync(reportServiceContext, cancellationToken); var model = await _modelBuilder.BuildFundingSummaryReportModel(reportServiceContext, periodisedValuesLookup, fcsLookup, cancellationToken); using (var workbook = _excelService.NewWorkbook()) { workbook.Worksheets.Clear(); _fundingSummaryReportRenderService.Render(model, _excelService.GetWorksheetFromWorkbook(workbook, "Funding Summary")); var replacedFileName = $"{externalFileName}.xlsx".Replace('_', '/'); _excelService.ApplyLicense(); await _excelService.SaveWorkbookAsync(workbook, replacedFileName, reportServiceContext.Container, cancellationToken); await WriteZipEntry(archive, $"{fileName}.xlsx", workbook, cancellationToken); } if (reportServiceContext.DataPersistFeatureEnabled) { var persistModels = model.FundingCategories.SelectMany(fc => fc.FundingSubCategories.SelectMany(fsc => fsc.FundLineGroups.SelectMany(flg => flg.FundLines.Select(fl => new FundingSummaryPersistModel { Ukprn = reportServiceContext.Ukprn, ContractNo = fc.ContractAllocationNumber, FundingCategory = fc.FundingCategoryTitle, FundingSubCategory = fsc.FundingSubCategoryTitle, FundLine = fl.Title, Aug19 = fl.Period1, Sep19 = fl.Period2, Oct19 = fl.Period3, Nov19 = fl.Period4, Dec19 = fl.Period5, Jan20 = fl.Period6, Feb20 = fl.Period7, Mar20 = fl.Period8, Apr20 = fl.Period9, May20 = fl.Period10, Jun20 = fl.Period11, Jul20 = fl.Period12, AugMar = fl.Period1To8, AprJul = fl.Period9To12, YearToDate = fl.YearToDate, Total = fl.Total })))).ToList(); Stopwatch stopWatchLog = new Stopwatch(); stopWatchLog.Start(); await _persistReportData.PersistReportDataAsync( persistModels, reportServiceContext.Ukprn, reportServiceContext.ReturnPeriod, TableNameConstants.FundingSummaryReport, reportServiceContext.ReportDataConnectionString, cancellationToken); _logger.LogDebug($"Performance-FundingSummaryReport logging took - {stopWatchLog.ElapsedMilliseconds} ms "); stopWatchLog.Stop(); } else { _logger.LogDebug(" Data Persist Feature is disabled."); } }