public FM25ActorTask(
     IJsonSerializationService jsonSerializationService,
     IActorProvider <IFM25Actor> fundingActorProvider,
     IFilePersistanceService filePersistanceService,
     IFM25FundingOutputCondenserService <FM25Global, PeriodisationGlobal> fundingOutputCondenserService,
     ILogger logger,
     string actorName)
 {
     _jsonSerializationService      = jsonSerializationService;
     _fundingActorProvider          = fundingActorProvider;
     _filePersistanceService        = filePersistanceService;
     _fundingOutputCondenserService = fundingOutputCondenserService;
     _logger    = logger;
     _actorName = actorName;
 }
 private FM25ActorTask NewTask(
     IJsonSerializationService jsonSerializationService = null,
     IActorProvider <IFM25Actor> fundingActorProvider   = null,
     IFilePersistanceService filePersistanceService     = null,
     IFM25FundingOutputCondenserService <FM25Global, PeriodisationGlobal> fundingOutputCondenserService = null,
     ILogger logger   = null,
     string actorName = null)
 {
     return(new FM25ActorTask(
                jsonSerializationService,
                fundingActorProvider,
                filePersistanceService,
                fundingOutputCondenserService,
                logger,
                actorName));
 }
 public FM25FundingTask(
     IJsonSerializationService jsonSerializationService,
     IFilePersistanceService filePersistanceService,
     IFundingService <Tin, IEnumerable <TOut> > fundingServiceFM25,
     IFundingService <TOut, IEnumerable <TPeriodsationOut> > fundingServiceFM25Periodisation,
     IFM25FundingOutputCondenserService <TOut, TPeriodsationOut> fundingOutputCondenserService,
     ILogger logger,
     string taskName,
     string outputKey)
 {
     _jsonSerializationService        = jsonSerializationService;
     _filePersistanceService          = filePersistanceService;
     _fundingServiceFM25              = fundingServiceFM25;
     _fundingServiceFM25Periodisation = fundingServiceFM25Periodisation;
     _fundingOutputCondenserService   = fundingOutputCondenserService;
     _logger    = logger;
     _taskName  = taskName;
     _outputKey = outputKey;
 }
        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);
        }