|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
namespace StabilityMatrix.Core.Models.Progress; |
|
|
|
|
using StabilityMatrix.Core.Processes; |
|
|
|
|
|
|
|
|
|
namespace StabilityMatrix.Core.Models.Progress; |
|
|
|
|
|
|
|
|
|
public record struct ProgressReport |
|
|
|
|
{ |
|
|
|
@ -6,21 +8,30 @@ public record struct ProgressReport
|
|
|
|
|
/// Progress value as percentage between 0 and 1. |
|
|
|
|
/// </summary> |
|
|
|
|
public double? Progress { get; init; } = 0; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Current progress count. |
|
|
|
|
/// </summary> |
|
|
|
|
public ulong? Current { get; init; } = 0; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Total progress count. |
|
|
|
|
/// </summary> |
|
|
|
|
public ulong? Total { get; init; } = 0; |
|
|
|
|
public string? Title { get; init; } |
|
|
|
|
public string? Message { get; init; } |
|
|
|
|
public ProcessOutput? ProcessOutput { get; init; } |
|
|
|
|
public bool IsIndeterminate { get; init; } = false; |
|
|
|
|
public float Percentage => (float) Math.Ceiling(Math.Clamp(Progress ?? 0, 0, 1) * 100); |
|
|
|
|
public float Percentage => (float)Math.Ceiling(Math.Clamp(Progress ?? 0, 0, 1) * 100); |
|
|
|
|
public ProgressType Type { get; init; } = ProgressType.Generic; |
|
|
|
|
|
|
|
|
|
public ProgressReport(double progress, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic) |
|
|
|
|
|
|
|
|
|
public ProgressReport( |
|
|
|
|
double progress, |
|
|
|
|
string? title = null, |
|
|
|
|
string? message = null, |
|
|
|
|
bool isIndeterminate = false, |
|
|
|
|
ProgressType type = ProgressType.Generic |
|
|
|
|
) |
|
|
|
|
{ |
|
|
|
|
Progress = progress; |
|
|
|
|
Title = title; |
|
|
|
@ -28,32 +39,53 @@ public record struct ProgressReport
|
|
|
|
|
IsIndeterminate = isIndeterminate; |
|
|
|
|
Type = type; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ProgressReport(ulong current, ulong total, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic) |
|
|
|
|
|
|
|
|
|
public ProgressReport( |
|
|
|
|
ulong current, |
|
|
|
|
ulong total, |
|
|
|
|
string? title = null, |
|
|
|
|
string? message = null, |
|
|
|
|
bool isIndeterminate = false, |
|
|
|
|
ProgressType type = ProgressType.Generic |
|
|
|
|
) |
|
|
|
|
{ |
|
|
|
|
Current = current; |
|
|
|
|
Total = total; |
|
|
|
|
Progress = (double) current / total; |
|
|
|
|
Progress = (double)current / total; |
|
|
|
|
Title = title; |
|
|
|
|
Message = message; |
|
|
|
|
IsIndeterminate = isIndeterminate; |
|
|
|
|
Type = type; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ProgressReport(int current, int total, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic) |
|
|
|
|
|
|
|
|
|
public ProgressReport( |
|
|
|
|
int current, |
|
|
|
|
int total, |
|
|
|
|
string? title = null, |
|
|
|
|
string? message = null, |
|
|
|
|
bool isIndeterminate = false, |
|
|
|
|
ProgressType type = ProgressType.Generic |
|
|
|
|
) |
|
|
|
|
{ |
|
|
|
|
if (current < 0) throw new ArgumentOutOfRangeException(nameof(current), "Current progress cannot negative."); |
|
|
|
|
if (total < 0) throw new ArgumentOutOfRangeException(nameof(total), "Total progress cannot be negative."); |
|
|
|
|
Current = (ulong) current; |
|
|
|
|
Total = (ulong) total; |
|
|
|
|
Progress = (double) current / total; |
|
|
|
|
if (current < 0) |
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(current), "Current progress cannot negative."); |
|
|
|
|
if (total < 0) |
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(total), "Total progress cannot be negative."); |
|
|
|
|
Current = (ulong)current; |
|
|
|
|
Total = (ulong)total; |
|
|
|
|
Progress = (double)current / total; |
|
|
|
|
Title = title; |
|
|
|
|
Message = message; |
|
|
|
|
IsIndeterminate = isIndeterminate; |
|
|
|
|
Type = type; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ProgressReport(ulong current, string? title = null, string? message = null, ProgressType type = ProgressType.Generic) |
|
|
|
|
|
|
|
|
|
public ProgressReport( |
|
|
|
|
ulong current, |
|
|
|
|
string? title = null, |
|
|
|
|
string? message = null, |
|
|
|
|
ProgressType type = ProgressType.Generic |
|
|
|
|
) |
|
|
|
|
{ |
|
|
|
|
Current = current; |
|
|
|
|
Title = title; |
|
|
|
@ -61,6 +93,6 @@ public record struct ProgressReport
|
|
|
|
|
IsIndeterminate = true; |
|
|
|
|
Type = type; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Implicit conversion from action |
|
|
|
|
} |
|
|
|
|