Files
speckle-sharp-connectors/Sdk/Speckle.Connectors.Common/Operations/PassthroughProgress.cs
T
Adam Hathcock 0e0dd81b56 Fix sending caching (#441)
* Fix upload speed calculation

* Better progress for humans?

* format

* add percentage to caching

* Update SDK
2024-12-10 11:49:53 +00:00

39 lines
1.0 KiB
C#

using Speckle.Sdk.Transports;
namespace Speckle.Connectors.Common.Operations;
//this aggregates speed across all SDK uploads and passes it to the main thread
public class PassthroughProgress : IProgress<ProgressArgs>
{
private readonly Action<ProgressArgs> _progressCallback;
private readonly Dictionary<ProgressEvent, long> _totals = new();
public PassthroughProgress(Action<ProgressArgs> progressCallback)
{
_progressCallback = progressCallback;
foreach (ProgressEvent value in Enum.GetValues(typeof(ProgressEvent)))
{
_totals[value] = 0;
}
}
public void Report(ProgressArgs value)
{
if (value.ProgressEvent == ProgressEvent.DownloadBytes || value.ProgressEvent == ProgressEvent.UploadBytes)
{
long totalBytes;
lock (_totals)
{
_totals[value.ProgressEvent] += value.Count;
totalBytes = _totals[value.ProgressEvent];
}
_progressCallback(value with { Count = totalBytes });
}
else
{
_progressCallback(value);
}
}
}