You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.4 KiB
67 lines
2.4 KiB
1 year ago
|
namespace StabilityMatrix.Core.Models.Progress;
|
||
1 year ago
|
|
||
1 year ago
|
public record struct ProgressReport
|
||
1 year ago
|
{
|
||
|
/// <summary>
|
||
|
/// 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 bool IsIndeterminate { get; init; } = false;
|
||
1 year ago
|
public float Percentage => (float) Math.Ceiling(Math.Clamp(Progress ?? 0, 0, 1) * 100);
|
||
1 year ago
|
public ProgressType Type { get; init; } = ProgressType.Generic;
|
||
1 year ago
|
|
||
1 year ago
|
public ProgressReport(double progress, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic)
|
||
1 year ago
|
{
|
||
|
Progress = progress;
|
||
|
Title = title;
|
||
|
Message = message;
|
||
|
IsIndeterminate = isIndeterminate;
|
||
1 year ago
|
Type = type;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
public ProgressReport(ulong current, ulong total, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic)
|
||
1 year ago
|
{
|
||
|
Current = current;
|
||
|
Total = total;
|
||
|
Progress = (double) current / total;
|
||
|
Title = title;
|
||
|
Message = message;
|
||
|
IsIndeterminate = isIndeterminate;
|
||
1 year ago
|
Type = type;
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
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;
|
||
|
Title = title;
|
||
|
Message = message;
|
||
|
IsIndeterminate = isIndeterminate;
|
||
|
Type = type;
|
||
|
}
|
||
|
|
||
1 year ago
|
public ProgressReport(ulong current, string? title = null, string? message = null, ProgressType type = ProgressType.Generic)
|
||
1 year ago
|
{
|
||
|
Current = current;
|
||
|
Title = title;
|
||
|
Message = message;
|
||
|
IsIndeterminate = true;
|
||
1 year ago
|
Type = type;
|
||
1 year ago
|
}
|
||
1 year ago
|
|
||
|
// Implicit conversion from action
|
||
1 year ago
|
}
|