public async Task SaveJson <T>(IEsfJobContext esfJobContext, string fileName, T fileValidationResult, CancellationToken cancellationToken) { using (var stream = await _fileService.OpenWriteStreamAsync(fileName, esfJobContext.BlobContainerName, cancellationToken)) { _jsonSerializationService.Serialize(fileValidationResult, stream); } }
public ISourceFileModel Build(IEsfJobContext esfJobContext) { if (string.IsNullOrWhiteSpace(esfJobContext.FileName)) { throw new ArgumentException($"{nameof(JobContextMessageKey.Filename)} is required"); } var fileName = esfJobContext.FileName; string[] fileNameParts = fileName.SplitFileName(_filenameExtension); if (fileNameParts.Length != 5) { throw new ArgumentException($"{nameof(JobContextMessageKey.Filename)} is invalid"); } var fileNameDatePart = GetPreparedDateFromFileName(fileName); if (!DateTime.TryParse(fileNameDatePart, out var preparationDateTime)) { throw new ArgumentException($"{nameof(JobContextMessageKey.Filename)} is invalid"); } var jobId = esfJobContext.JobId; return(new SourceFileModel { ConRefNumber = fileNameParts[2], UKPRN = fileNameParts[1], FileName = fileName, PreparationDate = preparationDateTime, SuppliedDate = esfJobContext.SubmissionDateTimeUtc, JobId = jobId }); }
public async Task <string> GenerateReport( IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper wrapper, CancellationToken cancellationToken) { var fundingSummaryReportModels = await _modelBuilder.Build(esfJobContext, cancellationToken); string fileName = GetExternalFilename(esfJobContext.UkPrn, ReportName, esfJobContext.JobId, esfJobContext.SubmissionDateTimeUtc, _excelExtension); using (var workbook = _excelFileService.NewWorkbook()) { workbook.Worksheets.Clear(); foreach (var tab in fundingSummaryReportModels) { var worksheet = _excelFileService.GetWorksheetFromWorkbook(workbook, tab.TabName); await _renderService.RenderAsync(esfJobContext, tab, worksheet); } await _excelFileService.SaveWorkbookAsync(workbook, fileName, esfJobContext.BlobContainerName, cancellationToken); } return(fileName); }
public async Task <SupplementaryDataWrapper> GetFile( IEsfJobContext esfJobContext, ISourceFileModel sourceFileModel, CancellationToken cancellationToken) { SupplementaryDataWrapper wrapper = new SupplementaryDataWrapper(); ICollection <SupplementaryDataLooseModel> esfRecords = new List <SupplementaryDataLooseModel>(); IList <ValidationErrorModel> errors = new List <ValidationErrorModel>(); try { esfRecords = await _eSFProviderService.GetESFRecordsFromFile(esfJobContext, cancellationToken); if (esfRecords == null || !esfRecords.Any()) { _logger.LogInfo("No ESF records to process"); } } catch (ValidationException ex) { _logger.LogError($"The file format is incorrect, key: {sourceFileModel.FileName}", ex); errors.Add(new ValidationErrorModel { RuleName = "Fileformat_01", ErrorMessage = "The file format is incorrect. Please check the field headers are as per the Guidance document.", IsWarning = false }); } wrapper.SupplementaryDataLooseModels = esfRecords; wrapper.ValidErrorModels = errors; return(wrapper); }
public IEnumerable <AimAndDeliverableReportRow> Build( IEsfJobContext esfJobContext, ICollection <LearningDelivery> learningDeliveries, ICollection <DPOutcome> dpOutcomes, ICollection <ESFLearningDeliveryDeliverablePeriod> deliverablePeriods, ICollection <ESFDPOutcome> esfDpOutcomes, ICollection <LARSLearningDelivery> larsLearningDeliveries, ICollection <FCSDeliverableCodeMapping> fcsDeliverableCodeMappings) { return(BuildReportRows( esfJobContext.StartCollectionYearAbbreviation, esfJobContext.EndCollectionYearAbbreviation, learningDeliveries, dpOutcomes, deliverablePeriods, esfDpOutcomes, larsLearningDeliveries, fcsDeliverableCodeMappings) .OrderBy(x => x.LearningDelivery?.LearnRefNumber) .ThenBy(x => x.LearningDelivery?.ConRefNumber) .ThenBy(x => x.LearningDelivery?.LearnStartDate) .ThenBy(x => x.LearningDelivery?.AimSeqNumber) .ThenBy(x => x.DeliverablePeriod?.Period) .ThenBy(x => x.DeliverablePeriod?.DeliverableCode)); }
public async Task Execute( IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper wrapper, CancellationToken cancellationToken) { await _controller.ValidateData(wrapper, sourceFile, cancellationToken); }
public async Task ProduceReports( IEsfJobContext esfJobContext, SupplementaryDataWrapper wrapper, ISourceFileModel sourceFile, CancellationToken cancellationToken) { await ProduceReports(esfJobContext, wrapper, sourceFile, cancellationToken, true); }
public ISourceFileModel BuildDefault(IEsfJobContext esfJobContext) { return(new SourceFileModel { UKPRN = esfJobContext.UkPrn.ToString(), SuppliedDate = esfJobContext.SubmissionDateTimeUtc, JobId = esfJobContext.JobId }); }
public async Task Execute( IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper supplementaryDataWrapper, CancellationToken cancellationToken) { var success = await _storageController.StoreData(sourceFile, supplementaryDataWrapper, cancellationToken); if (!success) { _logger.LogError("Failed to save data to the data store."); } }
public async Task <string> GenerateReport( IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper wrapper, CancellationToken cancellationToken) { var report = GetValidationReport(wrapper.SupplementaryDataModels, wrapper.ValidErrorModels); var externalFilename = GetExternalFilename(sourceFile.UKPRN, sourceFile.JobId ?? 0, sourceFile.SuppliedDate ?? DateTime.MinValue, ReportExtension); await SaveJson(esfJobContext, externalFilename, report, cancellationToken); return(externalFilename); }
public async Task ExecuteTasks( IEsfJobContext esfJobContext, ISourceFileModel sourceFileModel, SupplementaryDataWrapper supplementaryDataWrapper, CancellationToken cancellationToken) { var tasks = esfJobContext.Tasks; foreach (var task in tasks) { cancellationToken.ThrowIfCancellationRequested(); await HandleTask(esfJobContext, supplementaryDataWrapper, task, sourceFileModel, cancellationToken); } }
public async Task <string> GenerateReport( IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper wrapper, CancellationToken cancellationToken) { ReportFileName = $"{sourceFile.ConRefNumber} " + ReportFileName; string externalFileName = GetExternalFilename(sourceFile.UKPRN, sourceFile.JobId ?? 0, sourceFile.SuppliedDate ?? DateTime.MinValue, _reportExtension); await WriteCsv(esfJobContext, externalFileName, wrapper.ValidErrorModels.OrderBy(s => s.IsWarning).ThenBy(s => s.RuleName), cancellationToken); return(externalFileName); }
public async Task <string> GenerateReport( IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper wrapper, CancellationToken cancellationToken) { var reportModels = BuildModels(wrapper); ReportFileName = $"{sourceFile.ConRefNumber} " + ReportFileName; string externalFileName = GetExternalFilename(esfJobContext.UkPrn, esfJobContext.JobId, sourceFile.SuppliedDate ?? DateTime.MinValue, _reportExtension); await WriteCsv(esfJobContext, externalFileName, reportModels, cancellationToken); return(externalFileName); }
public async Task <string> GenerateReport( IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper wrapper, CancellationToken cancellationToken) { var externalFileName = GetExternalFilename(esfJobContext.UkPrn, esfJobContext.JobId, sourceFile?.SuppliedDate ?? DateTime.MinValue, ReportExtension); cancellationToken.ThrowIfCancellationRequested(); var ukPrn = esfJobContext.UkPrn; var reportModels = await GetModels(ukPrn, esfJobContext.CollectionYear, cancellationToken); await WriteCsv(esfJobContext, externalFileName, reportModels, cancellationToken); return(externalFileName); }
public async Task <string> GenerateReport(IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper wrapper, CancellationToken cancellationToken) { var externalFileName = GetExternalFilename(esfJobContext.UkPrn, esfJobContext.JobId, sourceFile?.SuppliedDate ?? DateTime.MinValue, ReportNameConstants.CsvExtension); var learningDeliveries = _aimAndDeliverableDataProvider.GetLearningDeliveriesAsync(esfJobContext.UkPrn, cancellationToken); var dpOutcomes = _aimAndDeliverableDataProvider.GetDpOutcomesAsync(esfJobContext.UkPrn, cancellationToken); var deliverablePeriods = _aimAndDeliverableDataProvider.GetDeliverablePeriodsAsync(esfJobContext.UkPrn, cancellationToken); var esfDpOutcomes = _aimAndDeliverableDataProvider.GetEsfDpOutcomesAsync(esfJobContext.UkPrn, cancellationToken); var fcsDeliverableCodeMappings = _aimAndDeliverableDataProvider.GetFcsDeliverableCodeMappingsAsync(cancellationToken); await Task.WhenAll(learningDeliveries, dpOutcomes, deliverablePeriods, esfDpOutcomes, fcsDeliverableCodeMappings); var learnAimRefs = new HashSet <string>(learningDeliveries.Result.Select(l => l.LearnAimRef), StringComparer.OrdinalIgnoreCase); var larsLearningDeliveries = await _aimAndDeliverableDataProvider.GetLarsLearningDeliveriesAsync(learnAimRefs, cancellationToken); var reportModels = _aimAndDeliverableModelBuilder.Build(esfJobContext, learningDeliveries.Result, dpOutcomes.Result, deliverablePeriods.Result, esfDpOutcomes.Result, larsLearningDeliveries, fcsDeliverableCodeMappings.Result); await WriteCsv(esfJobContext, externalFileName, reportModels, cancellationToken, _aimAndDeliverableMapper); return(externalFileName); }
private async Task HandleTask( IEsfJobContext esfJobContext, SupplementaryDataWrapper wrapper, string task, ISourceFileModel sourceFile, CancellationToken cancellationToken) { var orderedHandlers = _taskHandlers.OrderBy(t => t.Order); foreach (var handler in orderedHandlers) { if (!handler.IsMatch(task)) { continue; } await handler.Execute(esfJobContext, sourceFile, wrapper, cancellationToken); break; } }
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 RunTasks( IEsfJobContext esfJobContext, CancellationToken cancellationToken) { var wrapper = new SupplementaryDataWrapper(); var sourceFileModel = _sourceFileModelBuilder.BuildDefault(esfJobContext); _periodHelper.CacheCurrentPeriod(esfJobContext); _excelFileService.ApplyLicense(Assembly.GetExecutingAssembly().GetManifestResourceStream(LicenseResource)); if (esfJobContext.Tasks.Contains(Constants.ValidationTask)) { sourceFileModel = _sourceFileModelBuilder.Build(esfJobContext); wrapper = await _fileValidationService.GetFile(esfJobContext, sourceFileModel, cancellationToken); if (!wrapper.ValidErrorModels.Any()) { await _validationErrorMessageService.PopulateErrorMessages(cancellationToken); wrapper = await _fileValidationService.RunFileValidators(sourceFileModel, wrapper); } if (wrapper.ValidErrorModels.Any()) { await _storageController.StoreValidationOnly(sourceFileModel, wrapper, cancellationToken); await _reportingController.FileLevelErrorReport(esfJobContext, wrapper, sourceFileModel, cancellationToken); return; } } await _taskHelper.ExecuteTasks(esfJobContext, sourceFileModel, wrapper, cancellationToken); await _reportingController.ProduceReports(esfJobContext, wrapper, sourceFileModel, cancellationToken); }
public async Task RenderAsync(IEsfJobContext esfJobContext, IFundingSummaryReportTab fundingSummaryReportTab, Worksheet worksheet) { var maxReportYear = fundingSummaryReportTab.Body.Select(x => x.Year).Max(); var currentYear = int.Parse(string.Concat("20", esfJobContext.StartCollectionYearAbbreviation)); var currentPeriod = GetCurrentPeriod(maxReportYear, currentYear, esfJobContext.CurrentPeriod); ColumnCount = CalculateColumns(fundingSummaryReportTab.Body.Count()); worksheet.Workbook.DefaultStyle = _defaultStyle; worksheet.Cells.StandardWidth = 20; worksheet.Cells.Columns[0].Width = 65; RenderHeader(worksheet, NextMaxRow(worksheet), fundingSummaryReportTab.Header); RenderBody(worksheet, currentPeriod, fundingSummaryReportTab); RenderFooter(worksheet, NextMaxRow(worksheet) + 1, fundingSummaryReportTab.Footer); AddImageToReport(worksheet); UpdateColumnProperties(worksheet); }
public async Task <string> GenerateReport( IEsfJobContext esfJobContext, ISourceFileModel sourceFile, SupplementaryDataWrapper wrapper, CancellationToken cancellationToken) { var ukPrn = esfJobContext.UkPrn; var conRefNumbers = await _referenceDataService.GetContractAllocationsForUkprn(ukPrn, cancellationToken); if (!conRefNumbers.Any()) { conRefNumbers = new List <string> { NotApplicable }; } var collectionYear = Convert.ToInt32($"20{esfJobContext.CollectionYear.ToString().Substring(0, 2)}"); var sourceFiles = await _supplementaryDataService.GetImportFiles(esfJobContext.UkPrn.ToString(), cancellationToken); _logger.LogDebug($"{sourceFiles.Count} esf files found for ukprn {ukPrn} and collection year 20{esfJobContext.CollectionYear.ToString().Substring(0, 2)}."); var supplementaryData = await _supplementaryDataService.GetSupplementaryData(collectionYear, sourceFiles, cancellationToken); var ilrYearlyFileData = (await _ilrService.GetIlrFileDetails(ukPrn, collectionYear, cancellationToken)).ToList(); var fm70YearlyData = (await _ilrService.GetYearlyIlrData(ukPrn, esfJobContext.CollectionName, collectionYear, esfJobContext.ReturnPeriod, cancellationToken)).ToList(); var workbook = new Workbook(); workbook.Worksheets.Clear(); foreach (var conRefNumber in conRefNumbers) { var file = sourceFiles.FirstOrDefault(sf => sf.ConRefNumber.CaseInsensitiveEquals(conRefNumber)); FundingSummaryHeaderModel fundingSummaryHeaderModel = PopulateReportHeader(file, ilrYearlyFileData, ukPrn, conRefNumber, cancellationToken); var fm70YearlyDataForConRef = new List <FM70PeriodisedValuesYearly>(); var supplementaryDataYearlyModels = new List <SupplementaryDataYearlyModel>(); supplementaryData.TryGetValue(conRefNumber, out var suppData); foreach (var fm70Data in fm70YearlyData) { var periodisedValuesPerConRef = fm70Data.Fm70PeriodisedValues.Where(x => conRefNumber.CaseInsensitiveEquals(x.ConRefNumber)).ToList(); fm70YearlyDataForConRef.Add(new FM70PeriodisedValuesYearly() { Fm70PeriodisedValues = periodisedValuesPerConRef, FundingYear = fm70Data.FundingYear }); supplementaryDataYearlyModels.Add(new SupplementaryDataYearlyModel { FundingYear = fm70Data.FundingYear, SupplementaryData = suppData?.FirstOrDefault(x => x.FundingYear == fm70Data.FundingYear)?.SupplementaryData ?? new List <SupplementaryDataModel>() }); } var fundingSummaryModels = PopulateReportData(collectionYear, fm70YearlyDataForConRef, supplementaryDataYearlyModels).ToList(); ReplaceConRefNumInTitle(fundingSummaryModels, conRefNumber); FundingSummaryFooterModel fundingSummaryFooterModel = await PopulateReportFooter(cancellationToken); FundingSummaryModel rowOfData = fundingSummaryModels.FirstOrDefault(x => x.DeliverableCode == "ST01" && x.YearlyValues.Any()); var yearAndDataLengthModels = new List <YearAndDataLengthModel>(); if (rowOfData != null) { int valCount = rowOfData.YearlyValues.Sum(x => x.Values.Count); _reportWidth = valCount + rowOfData.Totals.Count + 2; foreach (FundingSummaryReportYearlyValueModel fundingSummaryReportYearlyValueModel in rowOfData.YearlyValues) { yearAndDataLengthModels.Add(new YearAndDataLengthModel( fundingSummaryReportYearlyValueModel.FundingYear, fundingSummaryReportYearlyValueModel.Values.Count)); } } _cachedHeaders = GetHeaderEntries(collectionYear, yearAndDataLengthModels); _cellStyles = _excelStyleProvider.GetFundingSummaryStyles(workbook); Worksheet sheet = workbook.Worksheets.Add(conRefNumber); sheet.Cells.StandardWidth = 19; sheet.Cells.Columns[0].Width = 63.93; sheet.IsGridlinesVisible = false; AddImageToReport(sheet); workbook = GetWorkbookReport(workbook, sheet, fundingSummaryHeaderModel, fundingSummaryModels, fundingSummaryFooterModel); } string externalFileName = GetExternalFilename(ukPrn.ToString(), esfJobContext.JobId, sourceFile?.SuppliedDate ?? DateTime.MinValue, _excelExtension); await WriteExcelFile(esfJobContext, externalFileName, workbook, cancellationToken); return(externalFileName); }
public void CacheCurrentPeriod(IEsfJobContext esfJobContext) { _service.CurrentPeriod = esfJobContext.CurrentPeriod; }
public async Task WriteCsv(IEsfJobContext esfJobContext, string fileName, IEnumerable <TModel> models, CancellationToken cancellationToken, TClassMap classMap = null) { await _csvFileService.WriteAsync <TModel, TClassMap>(models, fileName, esfJobContext.BlobContainerName, cancellationToken, classMap : classMap); }
public async Task <ICollection <IFundingSummaryReportTab> > Build(IEsfJobContext esfJobContext, CancellationToken cancellationToken) { var baseIlrYear = _yearConfiguration.BaseIlrYear; var ukPrn = esfJobContext.UkPrn; IEnumerable <string> conRefNumbers; var dateTimeNowUtc = _dateTimeProvider.GetNowUtc(); var dateTimeNowUk = _dateTimeProvider.ConvertUtcToUk(dateTimeNowUtc); var reportGenerationTime = dateTimeNowUk.ToString(ReportingConstants.TimeFormat) + " on " + dateTimeNowUk.ToString(ReportingConstants.ShortDateFormat); var referenceDataVersions = await _dataProvider.ProvideReferenceDataVersionsAsync(cancellationToken); var orgData = await _dataProvider.ProvideOrganisationReferenceDataAsync(ukPrn, cancellationToken); if (!orgData.ConRefNumbers.Any()) { conRefNumbers = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { NotApplicable }; } else { conRefNumbers = new HashSet <string>(orgData.ConRefNumbers, StringComparer.OrdinalIgnoreCase); } var currentCollectionYearString = CalculateCollectionYear(esfJobContext.CurrentPeriod, esfJobContext.StartCollectionYearAbbreviation, esfJobContext.CollectionName); var currentCollectionYear = int.Parse(currentCollectionYearString); var dataRetrievalCollectionYearString = string.Concat("20", esfJobContext.StartCollectionYearAbbreviation); var dataRetrievalCollectionYear = int.Parse(dataRetrievalCollectionYearString); var reportGroupHeaderDictionary = _yearConfiguration.PeriodisedValuesHeaderDictionary(currentCollectionYear); var esfSourceFiles = await _dataProvider.GetImportFilesAsync(esfJobContext.UkPrn, cancellationToken); _logger.LogDebug($"{esfSourceFiles.Count} esf files found for ukprn {ukPrn} and collection year {currentCollectionYearString}."); var supplementaryData = await _dataProvider.GetSupplementaryDataAsync(currentCollectionYear, esfSourceFiles, cancellationToken); var ilrYearlyFileData = await _dataProvider.GetIlrFileDetailsAsync(ukPrn, reportGroupHeaderDictionary.Keys, cancellationToken); var fm70YearlyData = await _dataProvider.GetYearlyIlrDataAsync(ukPrn, dataRetrievalCollectionYear, esfJobContext.ReturnPeriod, _yearConfiguration.YearToCollectionDictionary(), cancellationToken); var periodisedEsf = PeriodiseEsfSuppData(conRefNumbers, supplementaryData); var periodisedILR = PeriodiseIlr(conRefNumbers, fm70YearlyData.SelectMany(x => x.Fm70PeriodisedValues)); var fundingSummaryTabs = new List <IFundingSummaryReportTab>(); var footer = PopulateReportFooter(referenceDataVersions, reportGenerationTime); var academicYearDictionary = _yearConfiguration.YearToAcademicYearDictionary(); foreach (var conRefNumber in conRefNumbers) { var models = BuildBodyTemplateForYears(currentCollectionYear, baseIlrYear, academicYearDictionary); var file = esfSourceFiles.FirstOrDefault(sf => sf.ConRefNumber.CaseInsensitiveEquals(conRefNumber)); var header = PopulateReportHeader(file, ilrYearlyFileData, ukPrn, orgData.Name, conRefNumber, currentCollectionYear, baseIlrYear, academicYearDictionary); var fundingSummaryModels = PopulateReportData(conRefNumber, reportGroupHeaderDictionary, models, periodisedEsf.GetValueOrDefault(conRefNumber), periodisedILR.GetValueOrDefault(conRefNumber)); fundingSummaryTabs.Add(new FundingSummaryReportTab { Title = FundingSummaryReportConstants.BodyTitle, TabName = conRefNumber, Header = header, Footer = footer, Body = fundingSummaryModels }); } return(fundingSummaryTabs); }
public async Task <ICollection <SupplementaryDataLooseModel> > GetESFRecordsFromFile(IEsfJobContext esfJobContext, CancellationToken cancellationToken) { _logger.LogInfo("Try and get csv from Azure blob."); cancellationToken.ThrowIfCancellationRequested(); var csvConfig = GetCsvConfig(); return(await _csvFileService.ReadAllAsync <SupplementaryDataLooseModel, ESFMapper>(esfJobContext.FileName, esfJobContext.BlobContainerName, cancellationToken, csvConfig)); }
protected async Task WriteExcelFile(IEsfJobContext esfJobContext, string fileName, Workbook workbook, CancellationToken cancellationToken) { await _excelFileService.SaveWorkbookAsync(workbook, fileName, esfJobContext.BlobContainerName, cancellationToken); }
private void RegisterYearSpecificServices(ContainerBuilder container, IEsfJobContext esfJobContext) { int[] crossOverReturnPeriods = new[] { 1, 2 }; if (esfJobContext.CollectionYear == AcademicYearConstants.Year1920 || (esfJobContext.CollectionName == ESF2021CollectionName && esfJobContext.CollectionYear == AcademicYearConstants.Year2021 && crossOverReturnPeriods.Contains(esfJobContext.CurrentPeriod))) { container.Register(c => { var ilrConfig = c.Resolve <IILRConfiguration>(); SqlConnection IlrSqlFunc() => new SqlConnection(ilrConfig.ILR1920ConnectionString); return(new Ilr1920AimAndDeliverableDataProvider.IlrDataProvider(IlrSqlFunc)); }).As <IlrAimAndDeliverableDataProviderInterface>(); container.RegisterType <AimAndDeliverable1920Mapper>().As <AbstractAimAndDeliverableMapper>(); container.Register(c => { var ilrConfig = c.Resolve <IILRConfiguration>(); var esfConfig = c.Resolve <IESFConfiguration>(); var returnPeriodLookup = c.Resolve <IReturnPeriodLookup>(); SqlConnection Ilr1819SqlFunc() => new SqlConnection(ilrConfig.ILR1819ConnectionString); SqlConnection Ilr1920SqlFunc() => new SqlConnection(ilrConfig.ILR1920ConnectionString); SqlConnection EsfSqlFunc() => new SqlConnection(esfConfig.ESFFundingConnectionString); var connectionDictionary = new Dictionary <int, Func <SqlConnection> > { { AcademicYearConstants.Year2019, Ilr1920SqlFunc }, { AcademicYearConstants.Year2018, Ilr1819SqlFunc } }; if (esfJobContext.CollectionName == ESF2021CollectionName) { return(new EsfIlrFundingSummaryDataProvider(connectionDictionary, EsfSqlFunc, returnPeriodLookup)); } return(new IlrFundingSummaryDataProvider(connectionDictionary, EsfSqlFunc, returnPeriodLookup)); }).As <IlrFundingSummaryDataProviderInterface>(); container.RegisterType <IlrFundingSummaryYear1920Configuration>().As <IFundingSummaryYearConfiguration>(); } else if (esfJobContext.CollectionYear == AcademicYearConstants.Year2021) { container.Register(c => { var ilrConfig = c.Resolve <IILRConfiguration>(); SqlConnection IlrSqlFunc() => new SqlConnection(ilrConfig.ILR2021ConnectionString); return(new Ilr2021AimAndDeliverableDataProvider.IlrDataProvider(IlrSqlFunc)); }).As <IlrAimAndDeliverableDataProviderInterface>(); container.RegisterType <AimAndDeliverable2021Mapper>().As <AbstractAimAndDeliverableMapper>(); container.Register(c => { var ilrConfig = c.Resolve <IILRConfiguration>(); var esfConfig = c.Resolve <IESFConfiguration>(); var returnPeriodLookup = c.Resolve <IReturnPeriodLookup>(); SqlConnection Ilr1819SqlFunc() => new SqlConnection(ilrConfig.ILR1819ConnectionString); SqlConnection Ilr1920SqlFunc() => new SqlConnection(ilrConfig.ILR1920ConnectionString); SqlConnection Ilr2021SqlFunc() => new SqlConnection(ilrConfig.ILR2021ConnectionString); SqlConnection EsfSqlFunc() => new SqlConnection(esfConfig.ESFFundingConnectionString); var connectionDictionary = new Dictionary <int, Func <SqlConnection> > { { AcademicYearConstants.Year2020, Ilr2021SqlFunc }, { AcademicYearConstants.Year2019, Ilr1920SqlFunc }, { AcademicYearConstants.Year2018, Ilr1819SqlFunc } }; if (esfJobContext.CollectionName == ESF2021CollectionName) { return(new EsfIlrFundingSummaryDataProvider(connectionDictionary, EsfSqlFunc, returnPeriodLookup)); } return(new IlrFundingSummaryDataProvider(connectionDictionary, EsfSqlFunc, returnPeriodLookup)); }).As <IlrFundingSummaryDataProviderInterface>(); container.RegisterType <IlrFundingSummaryYear2021Configuration>().As <IFundingSummaryYearConfiguration>(); } }