protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var filePaths = await _directoryRepository.GetFiles(_options.InputDirectory); _logger.LogInformation($"In directory \"{_options.InputDirectory}\" found {filePaths.Count} files."); var index = 1; foreach (var filePath in filePaths) { var progress = $"[{index++}/{filePaths.Count}]"; var fileName = Path.GetFileName(filePath); _logger.LogInformation($"{progress} Handling \"{fileName}\"."); try { var(operation, matrices) = await _matrixRepository.GetMatrices(filePath, stoppingToken); var result = _calculator.Calculate(operation, matrices); var resultFilePath = GetResultFilePath(filePath); await _matrixRepository.SaveMatrices(resultFilePath, result, stoppingToken); _logger.LogInformation($"{progress} Result saved to \"{Path.GetFileName(resultFilePath)}\"."); } catch (OperationCanceledException e) { _logger.LogWarning($"{progress} Unable to handle \"{fileName}\". {e.Message}"); break; } catch (Exception e) { _logger.LogError(e, $"{progress} Unable to handle \"{fileName}\"."); } } }