public Task ConsumeResponses(IDictionary <Guid, string> fileMappings, string rebuiltDir, string originalDir, CancellationToken token) { return(Task.Factory.StartNew(() => { string errorReport = null; while (_pendingFiles.Count > 0) { var response = _collection.Take(token); _pendingFiles.Remove(response.Key); _logger.LogInformation($"Archive File Id: {_config.ArchiveFileId}, Archived File Id: {response.Key}, status: {response.Value}"); if (response.Value == AdaptationOutcome.Replace) { _archiveManager.AddToArchive(_config.OutputPath, $"{rebuiltDir}/{response.Key}", fileMappings[response.Key]); } else if (response.Value == AdaptationOutcome.Unmodified) { _archiveManager.AddToArchive(_config.OutputPath, $"{originalDir}/{response.Key}", fileMappings[response.Key]); } else { errorReport = _errorReportGenerator.AddIdToReport($"{_config.ArchiveFileId}/{response.Key}"); } } if (errorReport != null) { _fileManager.WriteFile($"{rebuiltDir}/{ErrorReportFileName}", Encoding.UTF8.GetBytes(errorReport)); _archiveManager.AddToArchive(_config.OutputPath, $"{rebuiltDir}/{ErrorReportFileName}", ErrorReportFileName); } })); }