Ejemplo n.º 1
0
        public async Task <bool> Callback(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            _logger.LogInfo("Reporting callback invoked");

            var reportZipFileKey = $"{reportServiceContext.Ukprn}_{reportServiceContext.JobId}_Reports.zip";

            cancellationToken.ThrowIfCancellationRequested();

            MemoryStream memoryStream  = new MemoryStream();
            var          zipFileExists = await _streamableKeyValuePersistenceService.ContainsAsync(reportZipFileKey, cancellationToken);

            if (zipFileExists)
            {
                await _streamableKeyValuePersistenceService.GetAsync(reportZipFileKey, memoryStream, cancellationToken);
            }

            using (memoryStream)
            {
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true))
                {
                    await ExecuteTasks(reportServiceContext, archive, cancellationToken);
                }

                await _streamableKeyValuePersistenceService.SaveAsync(reportZipFileKey, memoryStream, cancellationToken);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> Callback(CancellationToken cancellationToken)
        {
            _logger.LogInfo("Reporting callback invoked");

            var reportZipFileKey = $"R{_reportServiceContext.ReturnPeriod:00}_{_reportServiceContext.Ukprn}_Reports.zip";

            cancellationToken.ThrowIfCancellationRequested();

            MemoryStream memoryStream  = new MemoryStream();
            var          zipFileExists = await _streamableKeyValuePersistenceService.ContainsAsync(reportZipFileKey, cancellationToken);

            if (zipFileExists)
            {
                if (_reportServiceContext.Tasks.Any(x => x.CaseInsensitiveEquals(ReportTaskNameConstants.TaskClearPeriodEndDASZip)))
                {
                    await _streamableKeyValuePersistenceService.RemoveAsync(reportZipFileKey, cancellationToken);
                }
                else
                {
                    await _streamableKeyValuePersistenceService.GetAsync(reportZipFileKey, memoryStream, cancellationToken);
                }
            }

            using (memoryStream)
            {
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true))
                {
                    await ExecuteTasks(_reportServiceContext, archive, cancellationToken);
                }

                await _streamableKeyValuePersistenceService.SaveAsync(reportZipFileKey, memoryStream, cancellationToken);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public async Task <bool> Callback(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            _logger.LogInfo("Data Match Reporting callback invoked", jobIdOverride: reportServiceContext.JobId);

            cancellationToken.ThrowIfCancellationRequested();

            string reportZipFileKey;

            if (reportServiceContext.IsIlrSubmission)
            {
                reportZipFileKey = $"{reportServiceContext.Ukprn}_{reportServiceContext.JobId}_Reports.zip";
            }
            else
            {
                reportZipFileKey = $"R{reportServiceContext.ReturnPeriod:00}_{reportServiceContext.Ukprn}_Reports.zip";
            }

            MemoryStream memoryStream  = new MemoryStream();
            var          zipFileExists = await _streamableKeyValuePersistenceService.ContainsAsync(reportZipFileKey, cancellationToken);

            if (zipFileExists)
            {
                await _streamableKeyValuePersistenceService.GetAsync(reportZipFileKey, memoryStream, cancellationToken);
            }

            using (memoryStream)
            {
                bool needZip;
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true))
                {
                    needZip = await ExecuteTasks(reportServiceContext, archive, cancellationToken);
                }

                if (needZip)
                {
                    await _streamableKeyValuePersistenceService.SaveAsync(reportZipFileKey, memoryStream, cancellationToken);
                }
            }

            return(true);
        }
        public async Task <FM35Global> GetFM35Data(
            IReportServiceContext reportServiceContext,
            CancellationToken cancellationToken)
        {
            await _getDataLock.WaitAsync(cancellationToken);

            try
            {
                if (_loadedDataAlready)
                {
                    return(_fundingOutputs);
                }

                cancellationToken.ThrowIfCancellationRequested();

                _loadedDataAlready = true;
                int ukPrn = reportServiceContext.Ukprn;

                if (string.Equals(reportServiceContext.CollectionName, "ILR1819", StringComparison.OrdinalIgnoreCase))
                {
                    string fm35Filename = reportServiceContext.FundingFM35OutputKey;
                    _logger.LogWarning($"Reading {fm35Filename}; Storage is {_storage}; CancellationToken is {cancellationToken}");
                    if (await _storage.ContainsAsync(fm35Filename, cancellationToken))
                    {
                        _logger.LogWarning($"Available {fm35Filename}");
                        using (MemoryStream ms = new MemoryStream())
                        {
                            await _storage.GetAsync(fm35Filename, ms, cancellationToken);

                            _logger.LogWarning($"Deserialising {fm35Filename} with {ms.Length}");
                            _fundingOutputs = _jsonSerializationService.Deserialize <FM35Global>(ms);
                        }
                    }

                    _logger.LogWarning($"Finished {fm35Filename}");
                }
                else
                {
                    FM35Global fm35Global = new FM35Global();
                    using (var ilrContext = _ilrRulebaseContextFactory())
                    {
                        var fm35GlobalDb = await ilrContext.FM35_globals.FirstOrDefaultAsync(x => x.UKPRN == ukPrn, cancellationToken);

                        FM35_LearningDelivery[] res = await ilrContext.FM35_LearningDeliveries.Where(x => x.UKPRN == ukPrn)
                                                      .Include(x => x.FM35_LearningDelivery_PeriodisedValues).ToArrayAsync(cancellationToken);

                        IGrouping <string, FM35_LearningDelivery>[] learners = res.GroupBy(x => x.LearnRefNumber).ToArray();

                        fm35Global.Learners = new List <FM35Learner>();

                        foreach (IGrouping <string, FM35_LearningDelivery> fm35LearningDeliveries in learners)
                        {
                            var learningDeliveryDto = new List <LearningDelivery>();
                            foreach (var ld in fm35LearningDeliveries)
                            {
                                var ldPeriodisedValues = ld.FM35_LearningDelivery_PeriodisedValues.Select(ldpv => new LearningDeliveryPeriodisedValue()
                                {
                                    AttributeName = ldpv.AttributeName,
                                    Period1       = ldpv.Period_1,
                                    Period2       = ldpv.Period_2,
                                    Period3       = ldpv.Period_3,
                                    Period4       = ldpv.Period_4,
                                    Period5       = ldpv.Period_5,
                                    Period6       = ldpv.Period_6,
                                    Period7       = ldpv.Period_7,
                                    Period8       = ldpv.Period_8,
                                    Period9       = ldpv.Period_9,
                                    Period10      = ldpv.Period_10,
                                    Period11      = ldpv.Period_11,
                                    Period12      = ldpv.Period_12
                                }).ToList();

                                learningDeliveryDto.Add(new LearningDelivery()
                                {
                                    AimSeqNumber = ld.AimSeqNumber,
                                    LearningDeliveryPeriodisedValues = ldPeriodisedValues,
                                    LearningDeliveryValue            = new LearningDeliveryValue()
                                    {
                                        FundLine      = ld.FundLine,
                                        AchApplicDate = ld.AchApplicDate // todo: finish the entire LearningDeliveryValue here
                                    }
                                });
                            }

                            FM35Learner learner = new FM35Learner()
                            {
                                LearnRefNumber     = fm35LearningDeliveries.Key,
                                LearningDeliveries = learningDeliveryDto
                            };

                            fm35Global.Learners.Add(learner);
                        }

                        if (fm35GlobalDb != null)
                        {
                            fm35Global.LARSVersion = fm35GlobalDb.LARSVersion;
                            fm35Global.OrgVersion  = fm35GlobalDb.OrgVersion;
                            fm35Global.PostcodeDisadvantageVersion = fm35GlobalDb.PostcodeDisadvantageVersion;
                            fm35Global.RulebaseVersion             = fm35GlobalDb.RulebaseVersion;
                            fm35Global.UKPRN = fm35GlobalDb.UKPRN;
                        }
                    }

                    _fundingOutputs = fm35Global;
                }
            }
            finally
            {
                _getDataLock.Release();
            }

            return(_fundingOutputs);
        }