streamline runtime level checks

This commit is contained in:
Shannon
2021-06-08 16:32:26 -06:00
parent 26f989124d
commit 7d0572f2d1
13 changed files with 49 additions and 21 deletions

View File

@@ -5,9 +5,26 @@ namespace Umbraco.Extensions
{
public static class RuntimeStateExtensions
{
/// <summary>
/// Returns true if the installer is enabled based on the current runtime state
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static bool EnableInstaller(this IRuntimeState state)
=> state.Level == RuntimeLevel.Install || state.Level == RuntimeLevel.Upgrade || state.Level == RuntimeLevel.PackageMigrations;
/// <summary>
/// Returns true if Umbraco <see cref="IRuntimeState"/> is greater than <see cref="RuntimeLevel.BootFailed"/>
/// </summary>
public static bool UmbracoCanBoot(this IRuntimeState state) => state.Level > RuntimeLevel.BootFailed;
/// <summary>
/// Returns true if the runtime state indicates that unattended boot logic should execute
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static bool RunUnattendedBootLogic(this IRuntimeState state)
=> (state.Reason == RuntimeLevelReason.UpgradeMigrations || state.Reason == RuntimeLevelReason.UpgradePackageMigrations)
&& state.Level == RuntimeLevel.Run;
}
}