public Task <string> AggregateDataAsync(UserIdService userIdService, string databaseFolderPath, AggregationSetup setup, CancellationToken cancellationToken) { if (setup.Begin != setup.Begin.Date) { throw new ValidationException("The begin parameter must have no time component."); } if (setup.End != setup.End.Date) { throw new ValidationException("The end parameter must have no time component."); } return(Task.Run(() => { // log var message = $"User '{userIdService.GetUserId()}' aggregates data: {setup.Begin.ToISO8601()} to {setup.End.ToISO8601()} ... "; _logger.LogInformation(message); try { var progress = (IProgress <ProgressUpdatedEventArgs>) this.Progress; var instructions = AggregationService.ComputeInstructions(setup, _databaseManager.State, _logger); var days = (setup.End - setup.Begin).TotalDays; var totalDays = instructions.Count() * days; var i = 0; foreach (var instruction in instructions) { var projectId = instruction.Container.Id; for (int j = 0; j < days; j++) { cancellationToken.ThrowIfCancellationRequested(); var currentDay = setup.Begin.AddDays(j); var progressMessage = $"Processing project '{projectId}': {currentDay.ToString("yyyy-MM-dd")}"; var progressValue = (i * days + j) / totalDays; var eventArgs = new ProgressUpdatedEventArgs(progressValue, progressMessage); progress.Report(eventArgs); this.AggregateProject(userIdService.User, databaseFolderPath, projectId, currentDay, setup, instruction, cancellationToken); } i++; } } catch (Exception ex) { _logger.LogError(ex.GetFullMessage()); throw; } _logger.LogInformation($"{message} Done."); return string.Empty; }, cancellationToken)); }
public DataService(DatabaseManager databaseManager, UserIdService userIdService, ILoggerFactory loggerFactory, NexusOptions options) { _databaseManager = databaseManager; _userIdService = userIdService; _logger = loggerFactory.CreateLogger("Nexus Explorer"); _options = options; _blockSizeLimit = 5 * 1000 * 1000UL; this.Progress = new Progress <ProgressUpdatedEventArgs>(); }