using Duplicati.Library.Main.Operation.Common;
using Duplicati.Library.Utility;
namespace Duplicati.Library.Main.Backend;
#nullable enable
partial class BackendManager
{
///
/// Represents a pending QuotaInfo operation
///
private sealed record ProgressHandler(Options Options, IBackendWriter Stats, ITaskReader TaskReader)
{
///
/// Stores the last throttle values
///
/// The upload throttle value
/// The download throttle value
private sealed record ThrottleValues(string? Upload, string? Download);
///
/// The last throttle values
///
private ThrottleValues lastThrottleValue = new(string.Empty, string.Empty);
///
/// Handles the progress of a throttled stream
///
/// The throttled stream
/// The progress
/// The filename
public void HandleProgress(ThrottledStream ts, long pg, string filename)
{
// This pauses and throws on cancellation, but ignores stop
TaskReader.TransferRendevouz().Await();
var prev = lastThrottleValue;
// Update the throttle speeds if they have changed
Options.RawOptions.TryGetValue("throttle-upload", out var tmpUpload);
Options.RawOptions.TryGetValue("throttle-download", out var tmpDownload);
if (tmpUpload != prev.Upload || tmpDownload != prev.Download)
{
ts.WriteSpeed = Options.MaxUploadPrSecond;
ts.ReadSpeed = Options.MaxDownloadPrSecond;
lastThrottleValue = new(tmpUpload, tmpDownload);
}
Stats.BackendProgressUpdater.UpdateProgress(pg);
}
}
}