コード例 #1
0
        public async Task ExecuteAsync(CancellationToken cancellationToken, IProgress <BatchAnonymizeProgressDetail> progress = null)
        {
            List <Task <IEnumerable <TResult> > > executionTasks = new List <Task <IEnumerable <TResult> > >();
            List <TSource> batchData = new List <TSource>();

            TSource content;

            while ((content = await RawDataReader.NextAsync().ConfigureAwait(false)) != null)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    throw new OperationCanceledException();
                }

                batchData.Add(content);
                if (batchData.Count < BatchSize)
                {
                    continue;
                }

                executionTasks.Add(AnonymizeAsync(batchData, progress, cancellationToken));
                batchData = new List <TSource>();
                if (executionTasks.Count < PartitionCount)
                {
                    continue;
                }

                await ConsumeExecutionResultTask(executionTasks, progress).ConfigureAwait(false);
            }

            if (batchData.Count > 0)
            {
                executionTasks.Add(AnonymizeAsync(batchData, progress, cancellationToken));
            }

            while (executionTasks.Count > 0)
            {
                await ConsumeExecutionResultTask(executionTasks, progress).ConfigureAwait(false);
            }

            if (AnonymizedDataConsumer != null)
            {
                await AnonymizedDataConsumer.CompleteAsync().ConfigureAwait(false);
            }
        }