public async Task <string> Process(FundingDto actorModel, CancellationToken cancellationToken) { FM35Global results = RunFunding(actorModel, cancellationToken); actorModel = null; GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true); return(BuildFundingOutput(results)); }
public async Task <IActionResult> FundWallet(FundingDto fundingDto) { if (!ModelState.IsValid) { return(BadRequest(ResponseMessage.Message("Invalid Model", ModelState, fundingDto))); } var currencyExist = _currencyRepository.CurrencyExist(fundingDto.CurrencyId); if (!currencyExist) { return(NotFound(ResponseMessage.Message("Currency Not found", "currency id provided is invalid", fundingDto))); } var user = _userRepository.GetUserById(fundingDto.WalletOwnerId); if (user == null) { return(NotFound(ResponseMessage.Message("User Not found", "user id provided is invalid", fundingDto))); } //var userHasCurrency = _walletRepository.UserHasWalletWithCurrency(fundingDto); var wallet = _walletRepository.GetUserWalletByCurrencyId(fundingDto.WalletOwnerId, fundingDto.CurrencyId); if (wallet == null) { Wallet newWallet = new Wallet() { Balance = fundingDto.Amount, CurrencyId = fundingDto.CurrencyId, IsMain = false, OwnerId = fundingDto.WalletOwnerId, }; var walletCreated = _walletRepository.AddWallet(newWallet); if (!walletCreated) { return(BadRequest(ResponseMessage.Message("Unable to fund wallet", "An error was encountered while trying to fund the wallet", fundingDto))); } return(Ok(ResponseMessage.Message("Wallet successfully created and funded", null, fundingDto))); } var walletFunded = await _walletRepository.FundWallet(wallet, fundingDto.Amount); if (!walletFunded) { return(BadRequest(ResponseMessage.Message("Unable to fund wallet", "An error was encountered while trying to fund the wallet", fundingDto))); } return(Ok(ResponseMessage.Message("Wallet successfully funded", null, fundingDto))); }
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)); }
/// <summary> /// /// </summary> /// <param name="fundingDto"></param> /// <returns></returns> public bool UserHasWalletWithCurrency(FundingDto fundingDto) { return(_context.Wallets.Any(w => w.CurrencyId == fundingDto.CurrencyId && w.OwnerId == fundingDto.WalletOwnerId)); }
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 async Task <TOut> Process(FundingDto dto, CancellationToken cancellationToken) { return(RunFunding(dto, cancellationToken)); }
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); }