private async Task <IEnumerable <string> > AnonymizeAsync(List <string> batchData, bool breakOnAnonymizationException, IProgress <BatchAnonymizeProgressDetail> progress, CancellationToken cancellationToken) { return(await Task.Run(() => { List <string> result = new List <string>(); BatchAnonymizeProgressDetail batchAnonymizeProgressDetail = new BatchAnonymizeProgressDetail(); foreach (string content in batchData) { if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException(); } try { string anonymizedResult = AnonymizerFunction(content); result.Add(anonymizedResult); batchAnonymizeProgressDetail.ProcessCompleted++; } catch (Exception) { if (breakOnAnonymizationException) { throw; } batchAnonymizeProgressDetail.ProcessFailed++; } } progress?.Report(batchAnonymizeProgressDetail); return result; }).ConfigureAwait(false)); }
private async Task <IEnumerable <TResult> > AnonymizeAsync(List <TSource> batchData, IProgress <BatchAnonymizeProgressDetail> progress, CancellationToken cancellationToken) { return(await Task.Run(async() => { List <TResult> result = new List <TResult>(); BatchAnonymizeProgressDetail batchAnonymizeProgressDetail = new BatchAnonymizeProgressDetail(); batchAnonymizeProgressDetail.CurrentThreadId = Thread.CurrentThread.ManagedThreadId; foreach (TSource content in batchData) { if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException(); } TResult anonymizedResult = await AnonymizerFunctionAsync(content); if (EmptyElement.IsEmptyElement(anonymizedResult)) { batchAnonymizeProgressDetail.ProcessSkipped++; } else { batchAnonymizeProgressDetail.ProcessCompleted++; } result.Add(anonymizedResult); } progress?.Report(batchAnonymizeProgressDetail); return result; }).ConfigureAwait(false)); }