wabbajack/Wabbajack.RateLimiter/Job.cs
Luca a87f8dac7f
New Features from External Contributors [Merged to Internal Test Branch so Tests can run!] (#2325)
* added enderalse GOGID

* Fix readme opening twice when loading last modlist

* Edit Wabbajack CLI button text

* Cancel running downloads when shutting down application

* Add resume support for IHttpDownloader

* Add resume support for manual downloads

* Update CHANGELOG.md

* Improve game selection to only show games with results combined with the amount of lists

* Undo accidental removal of loading settings

* Add more tooltips and improve existing ones

* Update CHANGELOG.md

* Main test external pull readme fix (#2335)

* Fix SelectedGameType crashing Wabbajack when no settings are present yet, fix readme being clickable when not specified resulting in crash

* Add readme fix to CHANGELOG, fix typo

* Add readme button fix to changelog

---------

Co-authored-by: UrbanCMC <UrbanCMC@web.de>
Co-authored-by: Angad <angadmisra28@gmail.com>
Co-authored-by: trawzified <55751269+tr4wzified@users.noreply.github.com>
Co-authored-by: Timothy Baldridge <tbaldridge@gmail.com>
2023-05-07 14:32:18 -06:00

46 lines
1.3 KiB
C#

using System;
using System.Threading;
using System.Threading.Tasks;
namespace Wabbajack.RateLimiter;
public class Job<T> : IJob, IDisposable
{
public ulong ID { get; internal init; }
public string Description { get; internal init; }
public bool Started { get; internal set; }
public IResource<T> Resource { get; init; }
private bool _isFinished = false;
public void Dispose()
{
if (_isFinished) return;
_isFinished = true;
Resource.Finish(this);
}
public long Current { get; internal set; }
public long? Size { get; set; }
public async ValueTask Report(long processedSize, CancellationToken token)
{
await Resource.Report(this, (int)Math.Min(processedSize, int.MaxValue), token);
Current += processedSize;
OnUpdate?.Invoke(this, (Percent.FactoryPutInRange(Current, Size ?? 1), Current));
}
public void ReportNoWait(int processedSize)
{
Resource.ReportNoWait(this, processedSize);
OnUpdate?.Invoke(this, (Percent.FactoryPutInRange(Current, Size ?? 1), Current));
}
public void ResetProgress()
{
Current = 0;
OnUpdate?.Invoke(this, (Percent.FactoryPutInRange(Current, Size ?? 1), Current));
}
public event EventHandler<(Percent Progress, long Processed)> OnUpdate;
}