From df287f291e24b31328d54b2cc0d0f68f1382b46c Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 2 Aug 2017 22:32:28 +1000 Subject: [PATCH] Updates health check config to work the Umbraco/Testable way --- .../DisabledHealthCheckElement.cs | 2 +- .../DisabledHealthChecksElementCollection.cs | 4 +- .../HealthCheckNotificationSettingsElement.cs | 31 +++++++- .../HealthChecks/HealthChecksSection.cs | 16 ++++- ...heckElement.cs => IDisabledHealthCheck.cs} | 2 +- .../IHealthCheckNotificationSettings.cs | 13 ++++ ...IHealthCheckNotificationSettingsElement.cs | 11 --- .../HealthChecks/IHealthChecks.cs | 10 +++ .../HealthChecks/IHealthChecksSection.cs | 8 --- .../HealthChecks/INotificationMethod.cs | 13 ++++ .../INotificationMethodElement.cs | 11 --- ...ment.cs => INotificationMethodSettings.cs} | 2 +- .../HealthChecks/NotificationMethodElement.cs | 31 +++++++- .../NotificationMethodSettingsElement.cs | 2 +- ...ficationMethodSettingsElementCollection.cs | 70 +++++++++++++++---- .../NotificationMethodsElementCollection.cs | 67 ++++++++++++++---- .../Configuration/UmbracoConfig.cs | 40 ++++++++++- src/Umbraco.Core/Umbraco.Core.csproj | 10 +-- .../HealthCheck/HealthCheckController.cs | 3 +- .../HealthCheckNotificationMethodResolver.cs | 3 +- .../Scheduling/HealthCheckNotifier.cs | 5 +- src/Umbraco.Web/Scheduling/Scheduler.cs | 19 ++--- 22 files changed, 281 insertions(+), 92 deletions(-) rename src/Umbraco.Core/Configuration/HealthChecks/{IDisabledHealthCheckElement.cs => IDisabledHealthCheck.cs} (78%) create mode 100644 src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettingsElement.cs create mode 100644 src/Umbraco.Core/Configuration/HealthChecks/IHealthChecks.cs delete mode 100644 src/Umbraco.Core/Configuration/HealthChecks/IHealthChecksSection.cs create mode 100644 src/Umbraco.Core/Configuration/HealthChecks/INotificationMethod.cs delete mode 100644 src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodElement.cs rename src/Umbraco.Core/Configuration/HealthChecks/{INotificationMethodSettingsElement.cs => INotificationMethodSettings.cs} (69%) diff --git a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheckElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheckElement.cs index eb8379dc22..01392da614 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheckElement.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheckElement.cs @@ -6,7 +6,7 @@ using System.Text; namespace Umbraco.Core.Configuration.HealthChecks { - public class DisabledHealthCheckElement : ConfigurationElement, IDisabledHealthCheckElement + public class DisabledHealthCheckElement : ConfigurationElement, IDisabledHealthCheck { private const string IdKey = "id"; private const string DisabledOnKey = "disabledOn"; diff --git a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs b/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs index 7303947ec7..cf57a3a91a 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs @@ -4,7 +4,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.HealthChecks { [ConfigurationCollection(typeof(DisabledHealthCheckElement), AddItemName = "check")] - public class DisabledHealthChecksElementCollection : ConfigurationElementCollection, IEnumerable + public class DisabledHealthChecksElementCollection : ConfigurationElementCollection, IEnumerable { protected override ConfigurationElement CreateNewElement() { @@ -24,7 +24,7 @@ namespace Umbraco.Core.Configuration.HealthChecks } } - IEnumerator IEnumerable.GetEnumerator() + IEnumerator IEnumerable.GetEnumerator() { for (var i = 0; i < Count; i++) { diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs index 77328c2e94..1ccf3e357b 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs @@ -1,8 +1,10 @@ -using System.Configuration; +using System; +using System.Collections.Generic; +using System.Configuration; namespace Umbraco.Core.Configuration.HealthChecks { - public class HealthCheckNotificationSettingsElement : ConfigurationElement, IHealthCheckNotificationSettingsElement + public class HealthCheckNotificationSettingsElement : ConfigurationElement, IHealthCheckNotificationSettings { private const string EnabledKey = "enabled"; private const string FirstRunTimeKey = "firstRunTime"; @@ -54,5 +56,30 @@ namespace Umbraco.Core.Configuration.HealthChecks return (DisabledHealthChecksElementCollection)base[DisabledChecksKey]; } } + + bool IHealthCheckNotificationSettings.Enabled + { + get { return Enabled; } + } + + string IHealthCheckNotificationSettings.FirstRunTime + { + get { return FirstRunTime; } + } + + int IHealthCheckNotificationSettings.PeriodInHours + { + get { return PeriodInHours; } + } + + IReadOnlyDictionary IHealthCheckNotificationSettings.NotificationMethods + { + get { return NotificationMethods; } + } + + IEnumerable IHealthCheckNotificationSettings.DisabledChecks + { + get { return DisabledChecks; } + } } } diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthChecksSection.cs b/src/Umbraco.Core/Configuration/HealthChecks/HealthChecksSection.cs index f0ff50216b..90a7d8c567 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/HealthChecksSection.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/HealthChecksSection.cs @@ -1,8 +1,10 @@ -using System.Configuration; +using System; +using System.Collections.Generic; +using System.Configuration; namespace Umbraco.Core.Configuration.HealthChecks { - public class HealthChecksSection : ConfigurationSection, IHealthChecksSection + public class HealthChecksSection : ConfigurationSection, IHealthChecks { private const string DisabledChecksKey = "disabledChecks"; private const string NotificationSettingsKey = "notificationSettings"; @@ -18,5 +20,15 @@ namespace Umbraco.Core.Configuration.HealthChecks { get { return ((HealthCheckNotificationSettingsElement)(base[NotificationSettingsKey])); } } + + IEnumerable IHealthChecks.DisabledChecks + { + get { return DisabledChecks; } + } + + IHealthCheckNotificationSettings IHealthChecks.NotificationSettings + { + get { return NotificationSettings; } + } } } diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheckElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs similarity index 78% rename from src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheckElement.cs rename to src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs index 7c9f1ab929..4ea63048f8 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheckElement.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.HealthChecks { - public interface IDisabledHealthCheckElement + public interface IDisabledHealthCheck { Guid Id { get; } DateTime DisabledOn { get; } diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs b/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs new file mode 100644 index 0000000000..4564e87ed6 --- /dev/null +++ b/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Umbraco.Core.Configuration.HealthChecks +{ + public interface IHealthCheckNotificationSettings + { + bool Enabled { get; } + string FirstRunTime { get; } + int PeriodInHours { get; } + IReadOnlyDictionary NotificationMethods { get; } + IEnumerable DisabledChecks { get; } + } +} diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettingsElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettingsElement.cs deleted file mode 100644 index eeef6a1ec2..0000000000 --- a/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettingsElement.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Umbraco.Core.Configuration.HealthChecks -{ - public interface IHealthCheckNotificationSettingsElement - { - bool Enabled { get; } - string FirstRunTime { get; } - int PeriodInHours { get; } - NotificationMethodsElementCollection NotificationMethods { get; } - DisabledHealthChecksElementCollection DisabledChecks { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecks.cs b/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecks.cs new file mode 100644 index 0000000000..7680836074 --- /dev/null +++ b/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecks.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace Umbraco.Core.Configuration.HealthChecks +{ + public interface IHealthChecks + { + IEnumerable DisabledChecks { get; } + IHealthCheckNotificationSettings NotificationSettings { get; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecksSection.cs b/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecksSection.cs deleted file mode 100644 index 39cdf64c73..0000000000 --- a/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecksSection.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Core.Configuration.HealthChecks -{ - public interface IHealthChecksSection - { - DisabledHealthChecksElementCollection DisabledChecks { get; } - HealthCheckNotificationSettingsElement NotificationSettings { get; } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethod.cs b/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethod.cs new file mode 100644 index 0000000000..84bf55e160 --- /dev/null +++ b/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethod.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace Umbraco.Core.Configuration.HealthChecks +{ + public interface INotificationMethod + { + string Alias { get; } + bool Enabled { get; } + HealthCheckNotificationVerbosity Verbosity { get; } + bool FailureOnly { get; } + IReadOnlyDictionary Settings { get; } + } +} diff --git a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodElement.cs deleted file mode 100644 index c5693e69c4..0000000000 --- a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodElement.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Umbraco.Core.Configuration.HealthChecks -{ - public interface INotificationMethodElement - { - string Alias { get; } - bool Enabled { get; } - HealthCheckNotificationVerbosity Verbosity { get; } - bool FailureOnly { get; } - NotificationMethodSettingsElementCollection Settings { get; } - } -} diff --git a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettingsElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettings.cs similarity index 69% rename from src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettingsElement.cs rename to src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettings.cs index 845bf6079e..89d4799484 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettingsElement.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettings.cs @@ -1,6 +1,6 @@ namespace Umbraco.Core.Configuration.HealthChecks { - public interface INotificationMethodSettingsElement + public interface INotificationMethodSettings { string Key { get; } string Value { get; } diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodElement.cs index 0466b06811..2646c97475 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodElement.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodElement.cs @@ -1,8 +1,10 @@ -using System.Configuration; +using System; +using System.Collections.Generic; +using System.Configuration; namespace Umbraco.Core.Configuration.HealthChecks { - public class NotificationMethodElement : ConfigurationElement, INotificationMethodElement + public class NotificationMethodElement : ConfigurationElement, INotificationMethod { private const string AliasKey = "alias"; private const string EnabledKey = "enabled"; @@ -54,5 +56,30 @@ namespace Umbraco.Core.Configuration.HealthChecks return (NotificationMethodSettingsElementCollection)base[SettingsKey]; } } + + string INotificationMethod.Alias + { + get { return Alias; } + } + + bool INotificationMethod.Enabled + { + get { return Enabled; } + } + + HealthCheckNotificationVerbosity INotificationMethod.Verbosity + { + get { return Verbosity; } + } + + bool INotificationMethod.FailureOnly + { + get { return FailureOnly; } + } + + IReadOnlyDictionary INotificationMethod.Settings + { + get { return Settings; } + } } } diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElement.cs index 4408d9d655..a861291427 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElement.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.HealthChecks { - public class NotificationMethodSettingsElement : ConfigurationElement, INotificationMethodSettingsElement + public class NotificationMethodSettingsElement : ConfigurationElement, INotificationMethodSettings { private const string KeyKey = "key"; private const string ValueKey = "value"; diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs b/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs index d25cf9526d..174727f722 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs @@ -1,10 +1,12 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Configuration; +using System.Linq; namespace Umbraco.Core.Configuration.HealthChecks { [ConfigurationCollection(typeof(NotificationMethodSettingsElement), AddItemName = "add")] - public class NotificationMethodSettingsElementCollection : ConfigurationElementCollection, IEnumerable + public class NotificationMethodSettingsElementCollection : ConfigurationElementCollection, IEnumerable, IReadOnlyDictionary { protected override ConfigurationElement CreateNewElement() { @@ -14,27 +16,65 @@ namespace Umbraco.Core.Configuration.HealthChecks protected override object GetElementKey(ConfigurationElement element) { return ((NotificationMethodSettingsElement)(element)).Key; - } + } - public new NotificationMethodSettingsElement this[string key] - { - get - { - return (NotificationMethodSettingsElement)BaseGet(key); - } - } - - IEnumerator IEnumerable.GetEnumerator() + IEnumerator> IEnumerable>.GetEnumerator() { for (var i = 0; i < Count; i++) { - yield return BaseGet(i) as NotificationMethodSettingsElement; + var val = (NotificationMethodSettingsElement)BaseGet(i); + var key = (string)BaseGetKey(i); + yield return new KeyValuePair(key, val); } } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + IEnumerator IEnumerable.GetEnumerator() { - return GetEnumerator(); + for (var i = 0; i < Count; i++) + { + yield return (NotificationMethodSettingsElement)BaseGet(i); + } + } + + bool IReadOnlyDictionary.ContainsKey(string key) + { + return ((IReadOnlyDictionary)this).Keys.Any(x => x == key); + } + + bool IReadOnlyDictionary.TryGetValue(string key, out INotificationMethodSettings value) + { + try + { + var val = (NotificationMethodSettingsElement)BaseGet(key); + value = val; + return true; + } + catch (Exception) + { + value = null; + return false; + } + } + + INotificationMethodSettings IReadOnlyDictionary.this[string key] + { + get { return (NotificationMethodSettingsElement)BaseGet(key); } + } + + IEnumerable IReadOnlyDictionary.Keys + { + get { return BaseGetAllKeys().Cast(); } + } + + IEnumerable IReadOnlyDictionary.Values + { + get + { + for (var i = 0; i < Count; i++) + { + yield return (NotificationMethodSettingsElement)BaseGet(i); + } + } } } } diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodsElementCollection.cs b/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodsElementCollection.cs index 79cf6a2933..9eebc47309 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodsElementCollection.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodsElementCollection.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; using System.Configuration; +using System.Linq; namespace Umbraco.Core.Configuration.HealthChecks { [ConfigurationCollection(typeof(NotificationMethodElement), AddItemName = "notificationMethod")] - public class NotificationMethodsElementCollection : ConfigurationElementCollection, IEnumerable + public class NotificationMethodsElementCollection : ConfigurationElementCollection, IEnumerable, IReadOnlyDictionary { protected override ConfigurationElement CreateNewElement() { @@ -16,26 +17,64 @@ namespace Umbraco.Core.Configuration.HealthChecks { return ((NotificationMethodElement)(element)).Alias; } - - new public NotificationMethodElement this[string key] - { - get - { - return (NotificationMethodElement)BaseGet(key); - } - } - - IEnumerator IEnumerable.GetEnumerator() + + IEnumerator> IEnumerable>.GetEnumerator() { for (var i = 0; i < Count; i++) { - yield return BaseGet(i) as NotificationMethodElement; + var val = (NotificationMethodElement)BaseGet(i); + var key = (string)BaseGetKey(i); + yield return new KeyValuePair(key, val); } } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + IEnumerator IEnumerable.GetEnumerator() { - return GetEnumerator(); + for (var i = 0; i < Count; i++) + { + yield return (NotificationMethodElement)BaseGet(i); + } + } + + bool IReadOnlyDictionary.ContainsKey(string key) + { + return ((IReadOnlyDictionary) this).Keys.Any(x => x == key); + } + + bool IReadOnlyDictionary.TryGetValue(string key, out INotificationMethod value) + { + try + { + var val = (NotificationMethodElement)BaseGet(key); + value = val; + return true; + } + catch (Exception) + { + value = null; + return false; + } + } + + INotificationMethod IReadOnlyDictionary.this[string key] + { + get { return (NotificationMethodElement)BaseGet(key); } + } + + IEnumerable IReadOnlyDictionary.Keys + { + get { return BaseGetAllKeys().Cast(); } + } + + IEnumerable IReadOnlyDictionary.Values + { + get + { + for (var i = 0; i < Count; i++) + { + yield return (NotificationMethodElement)BaseGet(i); + } + } } } } diff --git a/src/Umbraco.Core/Configuration/UmbracoConfig.cs b/src/Umbraco.Core/Configuration/UmbracoConfig.cs index 8881c5fb2e..82d90073e8 100644 --- a/src/Umbraco.Core/Configuration/UmbracoConfig.cs +++ b/src/Umbraco.Core/Configuration/UmbracoConfig.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Configuration.BaseRest; using Umbraco.Core.Configuration.Dashboard; using Umbraco.Core.Configuration.Grid; +using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; @@ -52,6 +53,12 @@ namespace Umbraco.Core.Configuration var dashboardConfig = ConfigurationManager.GetSection("umbracoConfiguration/dashBoard") as IDashboardSection; SetDashboardSettings(dashboardConfig); } + + if (_healthChecks == null) + { + var healthCheckConfig = ConfigurationManager.GetSection("umbracoConfiguration/HealthChecks") as IHealthChecks; + SetHealthCheckSettings(healthCheckConfig); + } } /// @@ -60,18 +67,36 @@ namespace Umbraco.Core.Configuration /// /// /// - public UmbracoConfig(IUmbracoSettingsSection umbracoSettings, IBaseRestSection baseRestSettings, IDashboardSection dashboardSettings) + /// + public UmbracoConfig(IUmbracoSettingsSection umbracoSettings, IBaseRestSection baseRestSettings, IDashboardSection dashboardSettings, IHealthChecks healthChecks) { + SetHealthCheckSettings(healthChecks); SetUmbracoSettings(umbracoSettings); SetBaseRestExtensions(baseRestSettings); SetDashboardSettings(dashboardSettings); } + private IHealthChecks _healthChecks; private IDashboardSection _dashboardSection; private IUmbracoSettingsSection _umbracoSettings; private IBaseRestSection _baseRestExtensions; private IGridConfig _gridConfig; + /// + /// Gets the IHealthCheck config + /// + public IHealthChecks HealthCheck() + { + if (_healthChecks == null) + { + var ex = new ConfigurationErrorsException("Could not load the " + typeof(IHealthChecks) + " from config file, ensure the web.config and healthchecks.config files are formatted correctly"); + LogHelper.Error("Config error", ex); + throw ex; + } + + return _healthChecks; + } + /// /// Gets the IDashboardSection /// @@ -86,14 +111,23 @@ namespace Umbraco.Core.Configuration return _dashboardSection; } + + /// + /// Only for testing + /// + /// + public void SetDashboardSettings(IDashboardSection value) + { + _dashboardSection = value; + } /// /// Only for testing /// /// - internal void SetDashboardSettings(IDashboardSection value) + public void SetHealthCheckSettings(IHealthChecks value) { - _dashboardSection = value; + _healthChecks = value; } /// diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 9cc37bcf92..3cdc070466 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -216,11 +216,11 @@ - - - - - + + + + + diff --git a/src/Umbraco.Web/HealthCheck/HealthCheckController.cs b/src/Umbraco.Web/HealthCheck/HealthCheckController.cs index 92f72cc5a6..153c151f99 100644 --- a/src/Umbraco.Web/HealthCheck/HealthCheckController.cs +++ b/src/Umbraco.Web/HealthCheck/HealthCheckController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Web.Http; +using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Web.Editors; @@ -20,7 +21,7 @@ namespace Umbraco.Web.HealthCheck { _healthCheckResolver = HealthCheckResolver.Current; - var healthCheckConfig = (HealthChecksSection)ConfigurationManager.GetSection("umbracoConfiguration/HealthChecks"); + var healthCheckConfig = UmbracoConfig.For.HealthCheck(); _disabledCheckIds = healthCheckConfig.DisabledChecks .Select(x => x.Id) .ToList(); diff --git a/src/Umbraco.Web/HealthCheck/HealthCheckNotificationMethodResolver.cs b/src/Umbraco.Web/HealthCheck/HealthCheckNotificationMethodResolver.cs index d20c075ba7..3e676a0621 100644 --- a/src/Umbraco.Web/HealthCheck/HealthCheckNotificationMethodResolver.cs +++ b/src/Umbraco.Web/HealthCheck/HealthCheckNotificationMethodResolver.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Configuration; using System.Reflection; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; using Umbraco.Web.HealthCheck.NotificationMethods; @@ -55,7 +56,7 @@ namespace Umbraco.Web.HealthCheck } // Using alias, get related configuration - var healthCheckConfig = (HealthChecksSection)ConfigurationManager.GetSection("umbracoConfiguration/HealthChecks"); + var healthCheckConfig = UmbracoConfig.For.HealthCheck(); var notificationMethods = healthCheckConfig.NotificationSettings.NotificationMethods; var notificationMethod = notificationMethods[attribute.Alias]; if (notificationMethod == null) diff --git a/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs b/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs index 3851d86df6..61296a37bd 100644 --- a/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs +++ b/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Logging; using Umbraco.Core.Sync; @@ -44,9 +45,9 @@ namespace Umbraco.Web.Scheduling return false; // do NOT repeat, going down } - using (DisposableTimer.DebugDuration(() => "Health checks executing", () => "Health checks complete")) + using (_appContext.ProfilingLogger.DebugDuration("Health checks executing", "Health checks complete")) { - var healthCheckConfig = (HealthChecksSection)ConfigurationManager.GetSection("umbracoConfiguration/HealthChecks"); + var healthCheckConfig = UmbracoConfig.For.HealthCheck(); // Don't notify for any checks that are disabled, nor for any disabled // just for notifications diff --git a/src/Umbraco.Web/Scheduling/Scheduler.cs b/src/Umbraco.Web/Scheduling/Scheduler.cs index 6e470ad145..9eeefbf54a 100644 --- a/src/Umbraco.Web/Scheduling/Scheduler.cs +++ b/src/Umbraco.Web/Scheduling/Scheduler.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Logging; +using Umbraco.Web.HealthCheck; using Umbraco.Web.Routing; namespace Umbraco.Web.Scheduling @@ -65,15 +66,15 @@ namespace Umbraco.Web.Scheduling LogHelper.Debug(() => "Initializing the scheduler"); var settings = UmbracoConfig.For.UmbracoSettings(); - var healthCheckConfig = (HealthChecksSection)ConfigurationManager.GetSection("umbracoConfiguration/HealthChecks"); + var healthCheckConfig = UmbracoConfig.For.HealthCheck(); - const int DelayMilliseconds = 60000; + const int delayMilliseconds = 60000; var tasks = new List { - new KeepAlive(_keepAliveRunner, DelayMilliseconds, 300000, e.UmbracoContext.Application), - new ScheduledPublishing(_publishingRunner, DelayMilliseconds, 60000, e.UmbracoContext.Application, settings), - new ScheduledTasks(_tasksRunner, DelayMilliseconds, 60000, e.UmbracoContext.Application, settings), - new LogScrubber(_scrubberRunner, DelayMilliseconds, LogScrubber.GetLogScrubbingInterval(settings), e.UmbracoContext.Application, settings), + new KeepAlive(_keepAliveRunner, delayMilliseconds, 300000, e.UmbracoContext.Application), + new ScheduledPublishing(_publishingRunner, delayMilliseconds, 60000, e.UmbracoContext.Application, settings), + new ScheduledTasks(_tasksRunner, delayMilliseconds, 60000, e.UmbracoContext.Application, settings), + new LogScrubber(_scrubberRunner, delayMilliseconds, LogScrubber.GetLogScrubbingInterval(settings), e.UmbracoContext.Application, settings), }; if (healthCheckConfig.NotificationSettings.Enabled) @@ -82,15 +83,15 @@ namespace Umbraco.Web.Scheduling int delayInMilliseconds; if (string.IsNullOrEmpty(healthCheckConfig.NotificationSettings.FirstRunTime)) { - delayInMilliseconds = DelayMilliseconds; + delayInMilliseconds = delayMilliseconds; } else { // Otherwise start at scheduled time delayInMilliseconds = DateTime.Now.PeriodicMinutesFrom(healthCheckConfig.NotificationSettings.FirstRunTime) * 60 * 1000; - if (delayInMilliseconds < DelayMilliseconds) + if (delayInMilliseconds < delayMilliseconds) { - delayInMilliseconds = DelayMilliseconds; + delayInMilliseconds = delayMilliseconds; } }