44 lines
1.6 KiB
C#
Raw Normal View History

using ReactiveUI;
using SPTInstaller.Interfaces;
using System.Windows.Input;
namespace SPTInstaller.Models;
2024-05-01 10:31:55 -04:00
public class PreCheckResult : IResult
{
public bool Succeeded { get; private set; }
2024-05-01 10:31:55 -04:00
public string Message { get; private set; }
2024-05-01 10:31:55 -04:00
public bool ActionButtonIsVisible { get; private set; }
2024-05-01 10:31:55 -04:00
public string ActionButtonText { get; private set; }
2024-05-01 10:31:55 -04:00
public ICommand ButtonPressedCommand { get; private set; }
2024-05-01 10:31:55 -04:00
protected PreCheckResult(string message, bool succeeded, string actionButtonText, Action? buttonPressedAction)
{
Message = message;
Succeeded = succeeded;
2024-05-01 10:31:55 -04:00
ActionButtonText = actionButtonText;
2024-05-01 10:31:55 -04:00
ActionButtonIsVisible = buttonPressedAction != null && !string.IsNullOrWhiteSpace(actionButtonText);
2024-05-01 10:31:55 -04:00
buttonPressedAction ??= () => { };
2024-05-01 10:31:55 -04:00
ButtonPressedCommand = ReactiveCommand.Create(buttonPressedAction);
}
2024-05-01 10:31:55 -04:00
public static PreCheckResult FromSuccess(string message = "") => new PreCheckResult(message, true, "", null);
2024-05-01 10:31:55 -04:00
public static PreCheckResult FromError(string message, string actionButtonText = "",
Action? actionButtonPressedAction = null) =>
new PreCheckResult(message, false, actionButtonText, actionButtonPressedAction);
public static PreCheckResult
FromException(Exception ex, string actionButtonText = "", Action? actionButtonPressedAction = null) =>
new PreCheckResult(
$"An exception was thrown during this precheck\n\nException:\n{ex.Message}\n\nStacktrace:\n{ex.StackTrace}",
false, actionButtonText, actionButtonPressedAction);
}