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()