private void ApplyActorAudit <T>(EntityEntry <IBaseSimpleAuditEntity> entry, IActorProvider <T> actorProvider) where T : struct { if (actorProvider == null) { throw new ArgumentNullException(nameof(actorProvider)); } if (!(entry.Entity is ISimpleActorAuditEntity <T> simpleTimeAuditEntity)) { return; } switch (entry.State) { case EntityState.Added: simpleTimeAuditEntity.CreatedBy = actorProvider.Provide(); break; case EntityState.Modified: simpleTimeAuditEntity.LastModifiedBy = actorProvider.Provide(); break; } }
public async Task Execute( IEnumerable <FundingActorDto> fundingActorDtos, string outputKey, CancellationToken cancellationToken) { _logger.LogDebug($"Starting {_actorName} Actors"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <Task <string> > taskList = new List <Task <string> >(); List <TActor> actors = new List <TActor>(); foreach (FundingActorDto fundingActorDto in fundingActorDtos) { TActor actor = _fundingActorProvider.Provide(); actors.Add(actor); taskList.Add(actor.Process(fundingActorDto, cancellationToken)); } await Task.WhenAll(taskList).ConfigureAwait(false); IEnumerable <TActorReturn> results = taskList.Select(t => _jsonSerializationService.Deserialize <TActorReturn>(t.Result)); _logger.LogDebug($"Completed {taskList.Count} {_actorName} Actors - {stopWatch.ElapsedMilliseconds}"); List <Task> tasksDestroy = new List <Task>(); foreach (TActor actor in actors) { tasksDestroy.Add(_fundingActorProvider.DestroyAsync(actor, cancellationToken)); } await Task.WhenAll(tasksDestroy).ConfigureAwait(false); _logger.LogDebug($"Destroyed {taskList.Count} {_actorName} Actors - {stopWatch.ElapsedMilliseconds}"); stopWatch.Restart(); var output = _jsonSerializationService.Serialize(_fundingOutputCondenserService.Condense(results)); _logger.LogDebug($"Persisting {_actorName} bytes:{output.Length}"); await _keyValuePersistenceService.SaveAsync(outputKey, output, cancellationToken).ConfigureAwait(false); _logger.LogDebug($"Persisted {_actorName} results - {stopWatch.ElapsedMilliseconds}"); }
public async Task Execute(IEnumerable <FundingDto> fundingActorDtos, IFundingServiceContext fundingServiceContext, CancellationToken cancellationToken) { _logger.LogDebug($"Starting {_actorName} Actors"); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <Task <string> > taskList = new List <Task <string> >(); List <IFM70Actor> actors = new List <IFM70Actor>(); foreach (FundingDto fundingActorDto in fundingActorDtos) { IFM70Actor actor = _fundingActorProvider.Provide(); actors.Add(actor); taskList.Add(actor.Process(fundingActorDto, cancellationToken)); } await Task.WhenAll(taskList).ConfigureAwait(false); IEnumerable <FM70Global> results = taskList.Select(t => _jsonSerializationService.Deserialize <FM70Global>(t.Result)); _logger.LogDebug($"Completed {taskList.Count} {_actorName} Actors - {stopWatch.ElapsedMilliseconds}"); List <Task> tasksDestroy = new List <Task>(); foreach (IFM70Actor actor in actors) { tasksDestroy.Add(_fundingActorProvider.DestroyAsync(actor, cancellationToken)); } await Task.WhenAll(tasksDestroy).ConfigureAwait(false); _logger.LogDebug($"Destroyed {taskList.Count} {_actorName} Actors - {stopWatch.ElapsedMilliseconds}"); stopWatch.Restart(); var output = _fundingOutputCondenserService.Condense(results, fundingServiceContext.Ukprn, fundingServiceContext.Year); await _filePersistanceService.PersistAsync(fundingServiceContext.FundingFm70OutputKey, fundingServiceContext.Container, output, cancellationToken).ConfigureAwait(false); _logger.LogDebug($"Persisted {_actorName} results - {stopWatch.ElapsedMilliseconds}"); }