Add IsRestarting property to Umbraco application notifications (#11883)

* Add IsRestarting property to Umbraco application notifications

* Add IUmbracoApplicationLifetimeNotification and update constructors

* Only subscribe to events on initial startup

* Cleanup CoreRuntime

* Do not reset StaticApplicationLogging instance after stopping/during restart
This commit is contained in:
Ronald Barendse
2022-01-25 06:38:20 +01:00
committed by Bjarke Berg
parent f49b661c26
commit 76593aa7ca
6 changed files with 139 additions and 68 deletions

View File

@@ -0,0 +1,17 @@
namespace Umbraco.Cms.Core.Notifications
{
/// <summary>
/// Represents an Umbraco application lifetime (starting, started, stopping, stopped) notification.
/// </summary>
/// <seealso cref="Umbraco.Cms.Core.Notifications.INotification" />
public interface IUmbracoApplicationLifetimeNotification : INotification
{
/// <summary>
/// Gets a value indicating whether Umbraco is restarting (e.g. after an install or upgrade).
/// </summary>
/// <value>
/// <c>true</c> if Umbraco is restarting; otherwise, <c>false</c>.
/// </value>
bool IsRestarting { get; }
}
}

View File

@@ -3,7 +3,16 @@ namespace Umbraco.Cms.Core.Notifications
/// <summary>
/// Notification that occurs when Umbraco has completely booted up and the request processing pipeline is configured.
/// </summary>
/// <seealso cref="Umbraco.Cms.Core.Notifications.INotification" />
public class UmbracoApplicationStartedNotification : INotification
{ }
/// <seealso cref="Umbraco.Cms.Core.Notifications.IUmbracoApplicationLifetimeNotification" />
public class UmbracoApplicationStartedNotification : IUmbracoApplicationLifetimeNotification
{
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoApplicationStartedNotification" /> class.
/// </summary>
/// <param name="isRestarting">Indicates whether Umbraco is restarting.</param>
public UmbracoApplicationStartedNotification(bool isRestarting) => IsRestarting = isRestarting;
/// <inheritdoc />
public bool IsRestarting { get; }
}
}

View File

@@ -1,16 +1,34 @@
using System;
namespace Umbraco.Cms.Core.Notifications
{
/// <summary>
/// Notification that occurs at the very end of the Umbraco boot process (after all <see cref="IComponent" />s are initialized).
/// </summary>
/// <seealso cref="Umbraco.Cms.Core.Notifications.INotification" />
public class UmbracoApplicationStartingNotification : INotification
/// <seealso cref="Umbraco.Cms.Core.Notifications.IUmbracoApplicationLifetimeNotification" />
public class UmbracoApplicationStartingNotification : IUmbracoApplicationLifetimeNotification
{
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoApplicationStartingNotification" /> class.
/// </summary>
/// <param name="runtimeLevel">The runtime level</param>
public UmbracoApplicationStartingNotification(RuntimeLevel runtimeLevel) => RuntimeLevel = runtimeLevel;
[Obsolete("Use ctor with all params")]
public UmbracoApplicationStartingNotification(RuntimeLevel runtimeLevel)
: this(runtimeLevel, false)
{
// TODO: Remove this constructor in V10
}
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoApplicationStartingNotification" /> class.
/// </summary>
/// <param name="runtimeLevel">The runtime level</param>
/// <param name="isRestarting">Indicates whether Umbraco is restarting.</param>
public UmbracoApplicationStartingNotification(RuntimeLevel runtimeLevel, bool isRestarting)
{
RuntimeLevel = runtimeLevel;
IsRestarting = isRestarting;
}
/// <summary>
/// Gets the runtime level.
@@ -19,5 +37,8 @@ namespace Umbraco.Cms.Core.Notifications
/// The runtime level.
/// </value>
public RuntimeLevel RuntimeLevel { get; }
/// <inheritdoc />
public bool IsRestarting { get; }
}
}

View File

@@ -3,7 +3,16 @@ namespace Umbraco.Cms.Core.Notifications
/// <summary>
/// Notification that occurs when Umbraco has completely shutdown.
/// </summary>
/// <seealso cref="Umbraco.Cms.Core.Notifications.INotification" />
public class UmbracoApplicationStoppedNotification : INotification
{ }
/// <seealso cref="Umbraco.Cms.Core.Notifications.IUmbracoApplicationLifetimeNotification" />
public class UmbracoApplicationStoppedNotification : IUmbracoApplicationLifetimeNotification
{
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoApplicationStoppedNotification" /> class.
/// </summary>
/// <param name="isRestarting">Indicates whether Umbraco is restarting.</param>
public UmbracoApplicationStoppedNotification(bool isRestarting) => IsRestarting = isRestarting;
/// <inheritdoc />
public bool IsRestarting { get; }
}
}

View File

@@ -1,9 +1,30 @@
using System;
namespace Umbraco.Cms.Core.Notifications
{
/// <summary>
/// Notification that occurs when Umbraco is shutting down (after all <see cref="IComponent" />s are terminated).
/// </summary>
/// <seealso cref="Umbraco.Cms.Core.Notifications.INotification" />
public class UmbracoApplicationStoppingNotification : INotification
{ }
/// <seealso cref="Umbraco.Cms.Core.Notifications.IUmbracoApplicationLifetimeNotification" />
public class UmbracoApplicationStoppingNotification : IUmbracoApplicationLifetimeNotification
{
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoApplicationStoppingNotification" /> class.
/// </summary>
[Obsolete("Use ctor with all params")]
public UmbracoApplicationStoppingNotification()
: this(false)
{
// TODO: Remove this constructor in V10
}
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoApplicationStoppingNotification" /> class.
/// </summary>
/// <param name="isRestarting">Indicates whether Umbraco is restarting.</param>
public UmbracoApplicationStoppingNotification(bool isRestarting) => IsRestarting = isRestarting;
/// <inheritdoc />
public bool IsRestarting { get; }
}
}