|
|
@ -1,4 +1,6 @@ |
|
|
|
namespace StabilityMatrix.Core.Models.Progress; |
|
|
|
using StabilityMatrix.Core.Processes; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace StabilityMatrix.Core.Models.Progress; |
|
|
|
|
|
|
|
|
|
|
|
public record struct ProgressReport |
|
|
|
public record struct ProgressReport |
|
|
|
{ |
|
|
|
{ |
|
|
@ -6,21 +8,30 @@ public record struct ProgressReport |
|
|
|
/// Progress value as percentage between 0 and 1. |
|
|
|
/// Progress value as percentage between 0 and 1. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public double? Progress { get; init; } = 0; |
|
|
|
public double? Progress { get; init; } = 0; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Current progress count. |
|
|
|
/// Current progress count. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public ulong? Current { get; init; } = 0; |
|
|
|
public ulong? Current { get; init; } = 0; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Total progress count. |
|
|
|
/// Total progress count. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public ulong? Total { get; init; } = 0; |
|
|
|
public ulong? Total { get; init; } = 0; |
|
|
|
public string? Title { get; init; } |
|
|
|
public string? Title { get; init; } |
|
|
|
public string? Message { get; init; } |
|
|
|
public string? Message { get; init; } |
|
|
|
|
|
|
|
public ProcessOutput? ProcessOutput { get; init; } |
|
|
|
public bool IsIndeterminate { get; init; } = false; |
|
|
|
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 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; |
|
|
|
Progress = progress; |
|
|
|
Title = title; |
|
|
|
Title = title; |
|
|
@ -29,31 +40,52 @@ public record struct ProgressReport |
|
|
|
Type = type; |
|
|
|
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; |
|
|
|
Current = current; |
|
|
|
Total = total; |
|
|
|
Total = total; |
|
|
|
Progress = (double) current / total; |
|
|
|
Progress = (double)current / total; |
|
|
|
Title = title; |
|
|
|
Title = title; |
|
|
|
Message = message; |
|
|
|
Message = message; |
|
|
|
IsIndeterminate = isIndeterminate; |
|
|
|
IsIndeterminate = isIndeterminate; |
|
|
|
Type = type; |
|
|
|
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 (current < 0) |
|
|
|
if (total < 0) throw new ArgumentOutOfRangeException(nameof(total), "Total progress cannot be negative."); |
|
|
|
throw new ArgumentOutOfRangeException(nameof(current), "Current progress cannot negative."); |
|
|
|
Current = (ulong) current; |
|
|
|
if (total < 0) |
|
|
|
Total = (ulong) total; |
|
|
|
throw new ArgumentOutOfRangeException(nameof(total), "Total progress cannot be negative."); |
|
|
|
Progress = (double) current / total; |
|
|
|
Current = (ulong)current; |
|
|
|
|
|
|
|
Total = (ulong)total; |
|
|
|
|
|
|
|
Progress = (double)current / total; |
|
|
|
Title = title; |
|
|
|
Title = title; |
|
|
|
Message = message; |
|
|
|
Message = message; |
|
|
|
IsIndeterminate = isIndeterminate; |
|
|
|
IsIndeterminate = isIndeterminate; |
|
|
|
Type = type; |
|
|
|
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; |
|
|
|
Current = current; |
|
|
|
Title = title; |
|
|
|
Title = title; |
|
|
|