private static async Task TransferDataItem(IDataSinkAdapter sink, string dataItemId, IDataItem dataItem, ITransferStatistics statistics, CancellationToken cancellation) { try { await sink.WriteAsync(dataItem, cancellation); statistics.AddTransferred(); } catch (AggregateException aggregateException) { foreach (var exception in aggregateException.Flatten().InnerExceptions) statistics.AddError(dataItemId, exception); } catch (Exception exception) { statistics.AddError(dataItemId, exception); } }
protected async Task WriteDataAsync(IDataSinkAdapter sinkAdapter, IEnumerable<IDataItem> data) { Task[] writeTasks = Enumerable .Range(0, sinkAdapter.MaxDegreeOfParallelism) .Select(i => (Task)Task.FromResult<object>(null)) .ToArray(); foreach (var dataItem in data) { var completed = await Task.WhenAny(writeTasks); await completed; writeTasks[Array.IndexOf(writeTasks, completed)] = sinkAdapter.WriteAsync(dataItem, CancellationToken.None); } await sinkAdapter.CompleteAsync(CancellationToken.None); for (var index = 0; index < writeTasks.Length; ++index) await writeTasks[index]; }
private static async Task TransferDataItem(IDataSinkAdapter sink, string dataItemId, IDataItem dataItem, ITransferStatistics statistics, CancellationToken cancellation) { try { await sink.WriteAsync(dataItem, cancellation); statistics.AddTransferred(); } catch (AggregateException aggregateException) { foreach (var exception in aggregateException.Flatten().InnerExceptions) { statistics.AddError(dataItemId, exception); } } catch (Exception exception) { statistics.AddError(dataItemId, exception); } }
protected async Task WriteDataAsync(IDataSinkAdapter sinkAdapter, IEnumerable <IDataItem> data) { Task[] writeTasks = Enumerable .Range(0, sinkAdapter.MaxDegreeOfParallelism) .Select(i => (Task)Task.FromResult <object>(null)) .ToArray(); foreach (var dataItem in data) { var completed = await Task.WhenAny(writeTasks); await completed; writeTasks[Array.IndexOf(writeTasks, completed)] = sinkAdapter.WriteAsync(dataItem, CancellationToken.None); } await sinkAdapter.CompleteAsync(CancellationToken.None); for (var index = 0; index < writeTasks.Length; ++index) { await writeTasks[index]; } }