From c3d62bd337fffb1f5c8f3043b72967a7690eea5f Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 8 Sep 2023 19:58:29 +0200 Subject: [PATCH] Added ProgressToken timeRemaining --- Tranga/Jobs/ProgressToken.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Tranga/Jobs/ProgressToken.cs b/Tranga/Jobs/ProgressToken.cs index 6624bc6..9bada05 100644 --- a/Tranga/Jobs/ProgressToken.cs +++ b/Tranga/Jobs/ProgressToken.cs @@ -7,6 +7,9 @@ public class ProgressToken public int incrementsCompleted { get; set; } public float progress => GetProgress(); + public DateTime executionStarted { get; private set; } + public TimeSpan timeRemaining => GetTimeRemaining(); + public enum State { Running, Complete, Standby, Cancelled } public State state { get; private set; } @@ -16,6 +19,7 @@ public class ProgressToken this.increments = increments; this.incrementsCompleted = 0; this.state = State.Complete; + this.executionStarted = DateTime.UnixEpoch; } private float GetProgress() @@ -25,6 +29,13 @@ public class ProgressToken return 0; } + private TimeSpan GetTimeRemaining() + { + if (increments > 0 && incrementsCompleted > 0) + return DateTime.Now.Subtract(this.executionStarted).Divide(incrementsCompleted).Multiply(increments - incrementsCompleted); + return TimeSpan.MaxValue; + } + public void Increment() { this.incrementsCompleted++; @@ -40,6 +51,7 @@ public class ProgressToken public void Start() { state = State.Running; + this.executionStarted = DateTime.Now; } public void Complete()