AggregatingProgressIncrementer
An accumulator for request and response data transfers.
using System;
using System.IO;
using System.Threading;
namespace Azure.Storage
{
internal sealed class AggregatingProgressIncrementer : IProgress<long>
{
private long _currentValue;
private readonly IProgress<long> _innerHandler;
public static AggregatingProgressIncrementer None { get; } = new AggregatingProgressIncrementer(null);
public long Current => Volatile.Read(ref _currentValue);
public Stream CreateProgressIncrementingStream(Stream stream)
{
if (_innerHandler == null || stream == null)
return stream;
return new ProgressIncrementingStream(stream, this);
}
public AggregatingProgressIncrementer(IProgress<long> innerHandler)
{
_innerHandler = innerHandler;
}
public void Report(long bytes)
{
Interlocked.Add(ref _currentValue, bytes);
_innerHandler?.Report(Current);
}
public void Reset()
{
Volatile.Write(ref _currentValue, 0);
Report(0);
}
}
}