Esempio n. 1
0
        public async Task <ReferenceDataRoot> MapReferenceData(IReferenceDataContext referenceDataContext, MapperData mapperData, CancellationToken cancellationToken)
        {
            var desktopReferenceData = new DesktopReferenceDataRoot();

            using (var zipFileStream = await _fileService.OpenReadStreamAsync(referenceDataContext.DesktopInputReferenceDataFileKey, referenceDataContext.Container, cancellationToken))
            {
                using (var zip = new ZipArchive(zipFileStream, ZipArchiveMode.Read))
                {
                    _logger.LogInfo("Reference Data - Retrieve MetaData");
                    desktopReferenceData.MetaDatas = _zipArchiveFileService.RetrieveModel <MetaData>(zip, DesktopReferenceDataConstants.MetaDataFile);

                    _logger.LogInfo("Reference Data - Retrieve Devolved Postcodes");
                    desktopReferenceData.DevolvedPostcodes = GetDevolvedPostcodes(zip, mapperData.Postcodes);

                    _logger.LogInfo("Reference Data - Retrieve Employers");
                    desktopReferenceData.Employers = _zipArchiveFileService.RetrieveModels <Employer>(zip, DesktopReferenceDataConstants.EmployersFile, x => mapperData.EmployerIds.Contains(x.ERN));

                    _logger.LogInfo("Reference Data - Retrieve Epa Organisations");
                    desktopReferenceData.EPAOrganisations = _zipArchiveFileService.RetrieveModels <EPAOrganisation>(zip, DesktopReferenceDataConstants.EPAOrganisationsFile, x => mapperData.EpaOrgIds.Contains(x.ID));

                    _logger.LogInfo("Reference Data - Retrieve Lars Frameworks");
                    desktopReferenceData.LARSFrameworks = _zipArchiveFileService.RetrieveModels <LARSFrameworkDesktop>(zip, DesktopReferenceDataConstants.LARSFrameworksFile);

                    _logger.LogInfo("Reference Data - Retrieve Lars Framework Aims");
                    desktopReferenceData.LARSFrameworkAims = _zipArchiveFileService.RetrieveModels <LARSFrameworkAimDesktop>(zip, DesktopReferenceDataConstants.LARSFrameworkAimsFile);

                    _logger.LogInfo("Reference Data - Retrieve Lars Learning Deliveries");
                    desktopReferenceData.LARSLearningDeliveries = _zipArchiveFileService.RetrieveModels <LARSLearningDelivery>(zip, DesktopReferenceDataConstants.LARSLearningDeliveriesFile, x => mapperData.LARSLearningDeliveryKeys.Select(l => l.LearnAimRef).Contains(x.LearnAimRef, StringComparer.OrdinalIgnoreCase));

                    _logger.LogInfo("Reference Data - Retrieve Lars Standards");
                    desktopReferenceData.LARSStandards = _zipArchiveFileService.RetrieveModels <LARSStandard>(zip, DesktopReferenceDataConstants.LARSStandardsFile, x => mapperData.StandardCodes.Contains(x.StandardCode));

                    _logger.LogInfo("Reference Data - Retrieve Organisations");
                    desktopReferenceData.Organisations = _zipArchiveFileService.RetrieveModels <Organisation>(zip, DesktopReferenceDataConstants.OrganisationsFile, x => mapperData.UKPRNs.Contains(x.UKPRN));

                    _logger.LogInfo("Reference Data - Retrieve Postcodes");
                    desktopReferenceData.Postcodes = _zipArchiveFileService.RetrieveModels <Postcode>(zip, DesktopReferenceDataConstants.PostcodesFile, x => mapperData.Postcodes.Contains(x.PostCode));
                }
            }

            var referenceDataRoot = MapData(desktopReferenceData, mapperData);

            return(referenceDataRoot);
        }
        public async Task <IReadOnlyCollection <T> > MapReferenceDataByType <T>(
            IInputReferenceDataContext inputReferenceDataContext,
            CancellationToken cancellationToken)
        {
            if (!_fileNameRef.TryGetValue(typeof(T), out string referenceFilename))
            {
                throw new ApplicationException($"type ({typeof(T)}) not recognized.");
            }

            using (var zipFileStream = await _fileService.OpenReadStreamAsync(
                       inputReferenceDataContext.InputReferenceDataFileKey, inputReferenceDataContext.Container, cancellationToken))
            {
                using (var zip = new ZipArchive(zipFileStream, ZipArchiveMode.Read))
                {
                    var retrievedData = _zipArchiveFileService.RetrieveModels <T>(zip, referenceFilename);
                    return(retrievedData);
                }
            }
        }