2
0

Added ProgressToken timeRemaining

This commit is contained in:
glax 2023-09-08 19:58:29 +02:00
parent dc9e9e705c
commit c3d62bd337

View File

@ -7,6 +7,9 @@ public class ProgressToken
public int incrementsCompleted { get; set; } public int incrementsCompleted { get; set; }
public float progress => GetProgress(); public float progress => GetProgress();
public DateTime executionStarted { get; private set; }
public TimeSpan timeRemaining => GetTimeRemaining();
public enum State { Running, Complete, Standby, Cancelled } public enum State { Running, Complete, Standby, Cancelled }
public State state { get; private set; } public State state { get; private set; }
@ -16,6 +19,7 @@ public class ProgressToken
this.increments = increments; this.increments = increments;
this.incrementsCompleted = 0; this.incrementsCompleted = 0;
this.state = State.Complete; this.state = State.Complete;
this.executionStarted = DateTime.UnixEpoch;
} }
private float GetProgress() private float GetProgress()
@ -25,6 +29,13 @@ public class ProgressToken
return 0; 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() public void Increment()
{ {
this.incrementsCompleted++; this.incrementsCompleted++;
@ -40,6 +51,7 @@ public class ProgressToken
public void Start() public void Start()
{ {
state = State.Running; state = State.Running;
this.executionStarted = DateTime.Now;
} }
public void Complete() public void Complete()