コード例 #1
0
        private FM35Global ProcessFunding(IEnumerable <IEnumerable <ILearner> > learnersList)
        {
            ConcurrentBag <FM35Global> fundingOutputsList = new ConcurrentBag <FM35Global>();

            Parallel.ForEach(learnersList, ll =>
            {
                fundingOutputsList.Add(_fundingService.ProcessFunding(ll, CancellationToken.None));
            });

            return(TransformFundingOutput(fundingOutputsList.ToList()));
        }
コード例 #2
0
        private TOut RunFunding(FundingDto fundingDto, CancellationToken cancellationToken)
        {
            TOut results;

            try
            {
                var learners = BuildLearners <Tin>(fundingDto.ValidLearners);

                results = _fundingService.ProcessFunding(fundingDto.UKPRN, learners, cancellationToken);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while processing {_taskName} Task", ex);
                throw;
            }

            return(results);
        }
        private TOut RunFunding(FundingDto fundingDto, CancellationToken cancellationToken)
        {
            IEnumerable <TOut>             fm25Results;
            IEnumerable <TPeriodsationOut> fm25PeriodisationResults;

            try
            {
                var learners = BuildLearners <Tin>(fundingDto.ValidLearners);

                fm25Results = _fundingServiceFM25.ProcessFunding(fundingDto.UKPRN, learners, cancellationToken).ToList();
                fm25PeriodisationResults = _fundingServiceFM25Periodisation.ProcessFunding(fundingDto.UKPRN, fm25Results, cancellationToken).ToList();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while processing {_taskName} Task", ex);
                throw;
            }

            return(_fundingOutputCondenserService.CondensePeriodisationResults(fm25Results, fm25PeriodisationResults));
        }
コード例 #4
0
        private FM35Global RunFunding(FundingDto actorModel, CancellationToken cancellationToken)
        {
            if (ExecutionContext is ExecutionContext executionContextObj)
            {
                executionContextObj.JobId   = "-1";
                executionContextObj.TaskKey = ActorId.ToString();
            }

            ILogger logger = LifetimeScope.Resolve <ILogger>();

            IExternalDataCache externalDataCache;
            FM35Global         results;

            try
            {
                logger.LogDebug($"{nameof(FM35Actor)} {ActorId} {GC.GetGeneration(actorModel)} starting");

                externalDataCache = BuildExternalDataCache(actorModel.ExternalDataCache);

                logger.LogDebug($"{nameof(FM35Actor)} {ActorId} {GC.GetGeneration(actorModel)} finished getting input data");

                cancellationToken.ThrowIfCancellationRequested();
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString());
                logger.LogError($"Error while processing {nameof(FM35Actor)}", ex);
                throw;
            }

            using (var childLifetimeScope = LifetimeScope.BeginLifetimeScope(c =>
            {
                c.RegisterInstance(externalDataCache).As <IExternalDataCache>();
            }))
            {
                ExecutionContext executionContext = (ExecutionContext)childLifetimeScope.Resolve <IExecutionContext>();
                executionContext.JobId   = actorModel.JobId.ToString();
                executionContext.TaskKey = ActorId.ToString();
                ILogger jobLogger = childLifetimeScope.Resolve <ILogger>();

                try
                {
                    jobLogger.LogDebug($"{nameof(FM35Actor)} {ActorId} {GC.GetGeneration(actorModel)} started processing");
                    IFundingService <FM35LearnerDto, FM35Global> fundingService = childLifetimeScope.Resolve <IFundingService <FM35LearnerDto, FM35Global> >();

                    var learners = BuildLearners <FM35LearnerDto>(actorModel.ValidLearners);

                    results = fundingService.ProcessFunding(actorModel.UKPRN, learners, cancellationToken);
                    jobLogger.LogDebug($"{nameof(FM35Actor)} {ActorId} {GC.GetGeneration(actorModel)} completed processing");
                }
                catch (Exception ex)
                {
                    ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString());
                    jobLogger.LogError($"Error while processing {nameof(FM35Actor)}", ex);
                    throw;
                }
            }

            externalDataCache = null;

            return(results);
        }
        private FM25Global RunFunding(FundingDto actorModel, CancellationToken cancellationToken)
        {
            if (ExecutionContext is ExecutionContext executionContextObj)
            {
                executionContextObj.JobId   = "-1";
                executionContextObj.TaskKey = ActorId.ToString();
            }

            ILogger logger = LifetimeScope.Resolve <ILogger>();

            IExternalDataCache externalDataCache;
            FM25Global         condensedResults;

            try
            {
                logger.LogDebug($"{nameof(FM25Actor)} {ActorId} starting");

                externalDataCache = BuildExternalDataCache(actorModel.ExternalDataCache);

                logger.LogDebug($"{nameof(FM25Actor)} {ActorId} finished getting input data");

                cancellationToken.ThrowIfCancellationRequested();
            }
            catch (Exception ex)
            {
                ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString());
                logger.LogError($"Error while processing {nameof(FM25Actor)}", ex);
                throw;
            }

            using (var childLifetimeScope = LifetimeScope.BeginLifetimeScope(c =>
            {
                c.RegisterInstance(externalDataCache).As <IExternalDataCache>();
            }))
            {
                ExecutionContext executionContext = (ExecutionContext)childLifetimeScope.Resolve <IExecutionContext>();
                executionContext.JobId   = actorModel.JobId.ToString();
                executionContext.TaskKey = ActorId.ToString();
                ILogger jobLogger = childLifetimeScope.Resolve <ILogger>();

                try
                {
                    jobLogger.LogDebug($"{nameof(FM25Actor)} {ActorId} {GC.GetGeneration(actorModel)} started processing");

                    IEnumerable <FM25Global>          fm25Results;
                    IEnumerable <PeriodisationGlobal> fm25PeriodisationResults;

                    using (var fundingServiceLifetimeScope = childLifetimeScope.BeginLifetimeScope(c =>
                    {
                        c.RegisterInstance(new FM25RulebaseProvider()).As <IRulebaseStreamProvider <FM25LearnerDto> >();
                    }))
                    {
                        jobLogger.LogDebug("FM25 Rulebase Starting");

                        IFundingService <FM25LearnerDto, IEnumerable <FM25Global> > fundingService = fundingServiceLifetimeScope.Resolve <IFundingService <FM25LearnerDto, IEnumerable <FM25Global> > >();

                        var learners = BuildLearners <FM25LearnerDto>(actorModel.ValidLearners);

                        fm25Results = fundingService.ProcessFunding(actorModel.UKPRN, learners, cancellationToken).ToList();

                        jobLogger.LogDebug("FM25 Rulebase Finishing");
                    }

                    using (var fundingServiceLifetimeScope = childLifetimeScope.BeginLifetimeScope(c =>
                    {
                        c.RegisterInstance(new FM25PeriodisationRulebaseProvider()).As <IRulebaseStreamProvider <FM25Global> >();
                    }))
                    {
                        jobLogger.LogDebug("FM25 Periodisation Rulebase Starting");

                        IFundingService <FM25Global, IEnumerable <PeriodisationGlobal> > periodisationService = fundingServiceLifetimeScope.Resolve <IFundingService <FM25Global, IEnumerable <PeriodisationGlobal> > >();

                        fm25PeriodisationResults = periodisationService.ProcessFunding(actorModel.UKPRN, fm25Results, cancellationToken).ToList();

                        jobLogger.LogDebug("FM25 Periodisation Rulebase Finishing");

                        IFM25FundingOutputCondenserService <FM25Global, PeriodisationGlobal> condenser = fundingServiceLifetimeScope.Resolve <IFM25FundingOutputCondenserService <FM25Global, PeriodisationGlobal> >();

                        condensedResults = condenser.CondensePeriodisationResults(fm25Results, fm25PeriodisationResults);
                    }

                    jobLogger.LogDebug($"{nameof(FM25Actor)} {ActorId} {GC.GetGeneration(actorModel)} completed processing");
                }
                catch (Exception ex)
                {
                    ActorEventSource.Current.ActorMessage(this, "Exception-{0}", ex.ToString());
                    jobLogger.LogError($"Error while processing {nameof(FM25Actor)}", ex);
                    throw;
                }
            }

            externalDataCache = null;

            return(condensedResults);
        }