diff --git a/src/Umbraco.Configuration/Models/HealthChecksSettingsSettings.cs b/src/Umbraco.Configuration/Models/HealthChecksSettings.cs similarity index 100% rename from src/Umbraco.Configuration/Models/HealthChecksSettingsSettings.cs rename to src/Umbraco.Configuration/Models/HealthChecksSettings.cs diff --git a/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs b/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs index 1c24d0eb6c..21ebe55f2f 100644 --- a/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs @@ -41,7 +41,7 @@ namespace Umbraco.Core.Configuration /// The auto-fill configuration for the specified property alias, or null. public static IImagingAutoFillUploadField GetConfig(this ContentSettings contentSettings, string propertyTypeAlias) { - var autoFillConfigs = contentSettings.Imaging.ImageAutoFillProperties; + var autoFillConfigs = contentSettings.Imaging.AutoFillImageProperties; return autoFillConfigs?.FirstOrDefault(x => x.Alias == propertyTypeAlias); } } diff --git a/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs b/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs index 4eb2c774bf..0fe541416a 100644 --- a/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs @@ -1,10 +1,7 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ActiveDirectorySettings { - [JsonPropertyName("Domain")] - public string ActiveDirectoryDomain { get; set; } + public string Domain { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs index 027adedd09..056611a0ed 100644 --- a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs @@ -1,13 +1,21 @@ using System; using System.Collections.Generic; using System.Data.Common; -using System.Text.Json.Serialization; namespace Umbraco.Core.Configuration.Models { public class ConnectionStrings { - [JsonPropertyName(Constants.System.UmbracoConnectionName)] + // Backing field for UmbracoConnectionString to load from configuration value with key umbracoDbDSN. + // Attributes cannot be applied to map from keys that don't match, and have chosen to retain the key name + // used in configuration for older Umbraco versions. + // See: https://stackoverflow.com/a/54607296/489433 + private string umbracoDbDSN + { + get => string.Empty; + set => UmbracoConnectionString = value; + } + public string UmbracoConnectionString { get; set; } private Dictionary AsDictionary() => new Dictionary diff --git a/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs index 7ec8bf219f..018936896c 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentImagingSettings.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Text.Json.Serialization; -using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; namespace Umbraco.Core.Configuration.Models @@ -21,8 +19,7 @@ namespace Umbraco.Core.Configuration.Models public IEnumerable ImageFileTypes { get; set; } = new[] { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" }; - [JsonPropertyName("AutoFillImageProperties")] - public IEnumerable ImageAutoFillProperties { get; set; } = DefaultImagingAutoFillUploadField; + public IEnumerable AutoFillImageProperties { get; set; } = DefaultImagingAutoFillUploadField; private class ImagingAutoFillUploadField : IImagingAutoFillUploadField { diff --git a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs index 4cc74f709a..0a405d7db3 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentSettings.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text.Json.Serialization; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Macros; @@ -20,7 +19,6 @@ namespace Umbraco.Core.Configuration.Models // TODO: to retain previous configuration structure, this should come from a nested collection, // "Errors:Error404". Although we can use JsonPropertyName to map when the JSON field name differs // from the one in this class, not sure how we'd "flatten" a collection like this. - [JsonPropertyName("Error404")] public IEnumerable Error404Collection { get; set; } // public IEnumerable Error404Collection => _configuration @@ -30,7 +28,6 @@ namespace Umbraco.Core.Configuration.Models public string PreviewBadge { get; set; } = DefaultPreviewBadge; - [JsonPropertyName("MacroErrors")] public MacroErrorBehaviour MacroErrorBehaviour { get; set; } = MacroErrorBehaviour.Inline; public IEnumerable DisallowedUploadFiles { get; set; } = new[] { "ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd" }; diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index 6a7411c733..8f5f64ffbc 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { /// /// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information @@ -54,9 +52,8 @@ namespace Umbraco.Core.Configuration.Models public string NoNodesViewPath { get; set; } = "~/config/splashes/NoNodes.cshtml"; - public bool IsSmtpServerConfigured => !string.IsNullOrWhiteSpace(SmtpSettings?.Host); + public bool IsSmtpServerConfigured => !string.IsNullOrWhiteSpace(Smtp?.Host); - [JsonPropertyName("Smtp")] - public SmtpSettings SmtpSettings { get; set; } + public SmtpSettings Smtp { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs b/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs new file mode 100644 index 0000000000..37580195d6 --- /dev/null +++ b/src/Umbraco.Core/Configuration/Models/HealthChecksSettings.cs @@ -0,0 +1,108 @@ +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core.Configuration.HealthChecks; + +namespace Umbraco.Core.Configuration.Models +{ + public class HealthChecksSettings + { + // TODO: implement + public IEnumerable DisabledChecks { get; set; } = Enumerable.Empty(); + + public HealthCheckNotificationSettings NotificationSettings { get; set; } = new HealthCheckNotificationSettings(); + + /* + public IEnumerable DisabledChecks => _configuration + .GetSection(Prefix+"DisabledChecks") + .GetChildren() + .Select( + x => new DisabledHealthCheck + { + Id = x.GetValue("Id"), + DisabledOn = x.GetValue("DisabledOn"), + DisabledBy = x.GetValue("DisabledBy") + }); + + public IHealthCheckNotificationSettings NotificationSettings => + new HealthCheckNotificationSettings( + _configuration.GetSection(Prefix+"NotificationSettings")); + + + private class DisabledHealthCheck : IDisabledHealthCheck + { + public Guid Id { get; set; } + public DateTime DisabledOn { get; set; } + public int DisabledBy { get; set; } + } + */ + + // TODO: move to new file + public class HealthCheckNotificationSettings + { + public bool Enabled { get; set; } = false; + + public string FirstRunTime { get; set; } + + public int PeriodInHours { get; set; } = 24; + + // TODO: implement + + public IReadOnlyDictionary NotificationMethods { get; set; } = new Dictionary(); + + public IEnumerable DisabledChecks { get; set; } = Enumerable.Empty(); + + /* + public IReadOnlyDictionary NotificationMethods => _configurationSection + .GetSection("NotificationMethods") + .GetChildren() + .ToDictionary(x => x.Key, x => (INotificationMethod) new NotificationMethod(x.Key, x), StringComparer.InvariantCultureIgnoreCase); + + public IEnumerable DisabledChecks => _configurationSection + .GetSection("DisabledChecks").GetChildren().Select( + x => new DisabledHealthCheck + { + Id = x.GetValue("Id"), + DisabledOn = x.GetValue("DisabledOn"), + DisabledBy = x.GetValue("DisabledBy") + }); + */ + } + + /* + private class NotificationMethod : INotificationMethod + { + private readonly IConfigurationSection _configurationSection; + + public NotificationMethod(string alias, IConfigurationSection configurationSection) + { + Alias = alias; + _configurationSection = configurationSection; + } + + public string Alias { get; } + public bool Enabled => _configurationSection.GetValue("Enabled", false); + + public HealthCheckNotificationVerbosity Verbosity => + _configurationSection.GetValue("Verbosity", HealthCheckNotificationVerbosity.Summary); + + public bool FailureOnly => _configurationSection.GetValue("FailureOnly", true); + + public IReadOnlyDictionary Settings => _configurationSection + .GetSection("Settings").GetChildren().ToDictionary(x => x.Key, + x => (INotificationMethodSettings) new NotificationMethodSettings(x.Key, x.Value), StringComparer.InvariantCultureIgnoreCase); + } + + private class NotificationMethodSettings : INotificationMethodSettings + { + public NotificationMethodSettings(string key, string value) + { + Key = key; + Value = value; + } + + public string Key { get; } + public string Value { get; } + } + */ + } +} diff --git a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs index a774a948ea..c9adbebc23 100644 --- a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs @@ -1,13 +1,10 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class HostingSettings { /// /// Gets the configuration for the location of temporary files. /// - [JsonPropertyName("LocalTempStorage")] public LocalTempStorage LocalTempStorageLocation { get; set; } = LocalTempStorage.Default; public string ApplicationVirtualPath => null; @@ -16,7 +13,6 @@ namespace Umbraco.Core.Configuration.Models /// Gets a value indicating whether umbraco is running in [debug mode]. /// /// true if [debug mode]; otherwise, false. - [JsonPropertyName("Debug")] public bool DebugMode { get; set; } = false; } } diff --git a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs index 9c2fd4bf37..03efac0ffd 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingCacheSettings.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ImagingCacheSettings { @@ -10,7 +8,6 @@ namespace Umbraco.Core.Configuration.Models public uint CachedNameLength { get; set; } = 7; - [JsonPropertyName("Folder")] public string CacheFolder { get; set; } = "../App_Data/Cache"; } } diff --git a/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs b/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs index 6b445d8c40..f9db53d7dd 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingResizeSettings.cs @@ -1,14 +1,9 @@ - -using System.Text.Json.Serialization; - -namespace Umbraco.Core.Configuration.Models +namespace Umbraco.Core.Configuration.Models { public class ImagingResizeSettings { - [JsonPropertyName("MaxWidth")] - public int MaxResizeWidth { get; set; } = 5000; + public int MaxWidth { get; set; } = 5000; - [JsonPropertyName("MaxHeight")] - public int MaxResizeHeight { get; set; } = 5000; + public int MaxHeight { get; set; } = 5000; } } diff --git a/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs b/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs index 6aeb83d61c..d6fbfae813 100644 --- a/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs +++ b/src/Umbraco.Core/HealthCheck/Checks/Permissions/FolderAndFilePermissionsCheck.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Install; using Umbraco.Core.IO; using Umbraco.Core.Services; @@ -29,14 +31,14 @@ namespace Umbraco.Web.HealthCheck.Checks.Permissions public class FolderAndFilePermissionsCheck : HealthCheck { private readonly ILocalizedTextService _textService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IFilePermissionHelper _filePermissionHelper; private readonly IIOHelper _ioHelper; - public FolderAndFilePermissionsCheck(ILocalizedTextService textService, IGlobalSettings globalSettings, IFilePermissionHelper filePermissionHelper, IIOHelper ioHelper) + public FolderAndFilePermissionsCheck(ILocalizedTextService textService, IOptions globalSettings, IFilePermissionHelper filePermissionHelper, IIOHelper ioHelper) { _textService = textService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _filePermissionHelper = filePermissionHelper; _ioHelper = ioHelper; } diff --git a/src/Umbraco.Core/HealthCheck/Checks/Security/HttpsCheck.cs b/src/Umbraco.Core/HealthCheck/Checks/Security/HttpsCheck.cs index 43776ad827..7f85d326df 100644 --- a/src/Umbraco.Core/HealthCheck/Checks/Security/HttpsCheck.cs +++ b/src/Umbraco.Core/HealthCheck/Checks/Security/HttpsCheck.cs @@ -8,6 +8,8 @@ using Umbraco.Core.IO; using Umbraco.Core.Services; using Umbraco.Core.Logging; using Umbraco.Web.HealthCheck.Checks.Config; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.HealthCheck.Checks.Security { @@ -19,17 +21,17 @@ namespace Umbraco.Web.HealthCheck.Checks.Security public class HttpsCheck : HealthCheck { private readonly ILocalizedTextService _textService; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly ILogger _logger; private readonly IRequestAccessor _requestAccessor; private const string FixHttpsSettingAction = "fixHttpsSetting"; - public HttpsCheck(ILocalizedTextService textService, IGlobalSettings globalSettings, IIOHelper ioHelper, ILogger logger, IRequestAccessor requestAccessor) + public HttpsCheck(ILocalizedTextService textService, IOptions globalSettings, IIOHelper ioHelper, ILogger logger, IRequestAccessor requestAccessor) { _textService = textService; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; _ioHelper = ioHelper; _logger = logger; _requestAccessor = requestAccessor; diff --git a/src/Umbraco.Core/HealthCheck/Checks/Services/SmtpCheck.cs b/src/Umbraco.Core/HealthCheck/Checks/Services/SmtpCheck.cs index 7b57c01223..77b1201ef6 100644 --- a/src/Umbraco.Core/HealthCheck/Checks/Services/SmtpCheck.cs +++ b/src/Umbraco.Core/HealthCheck/Checks/Services/SmtpCheck.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.IO; using System.Net.Sockets; +using Microsoft.Extensions.Options; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Services; namespace Umbraco.Web.HealthCheck.Checks.Services @@ -16,14 +18,12 @@ namespace Umbraco.Web.HealthCheck.Checks.Services public class SmtpCheck : HealthCheck { private readonly ILocalizedTextService _textService; - private readonly IRuntimeState _runtime; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; - public SmtpCheck(ILocalizedTextService textService, IRuntimeState runtime, IGlobalSettings globalSettings) + public SmtpCheck(ILocalizedTextService textService, IOptions globalSettings) { _textService = textService; - _runtime = runtime; - _globalSettings = globalSettings; + _globalSettings = globalSettings.Value; } /// @@ -48,11 +48,11 @@ namespace Umbraco.Web.HealthCheck.Checks.Services private HealthCheckStatus CheckSmtpSettings() { - var message = string.Empty; var success = false; - var smtpSettings = _globalSettings.SmtpSettings; + var smtpSettings = _globalSettings.Smtp; + string message; if (smtpSettings == null) { message = _textService.Localize("healthcheck/smtpMailSettingsNotFound"); diff --git a/src/Umbraco.Core/Models/MediaExtensions.cs b/src/Umbraco.Core/Models/MediaExtensions.cs index aa7a48d8f4..9615969c07 100644 --- a/src/Umbraco.Core/Models/MediaExtensions.cs +++ b/src/Umbraco.Core/Models/MediaExtensions.cs @@ -29,7 +29,7 @@ namespace Umbraco.Core.Models /// public static string[] GetUrls(this IMedia media, ContentSettings contentSettings, MediaUrlGeneratorCollection mediaUrlGenerators) { - return contentSettings.Imaging.ImageAutoFillProperties + return contentSettings.Imaging.AutoFillImageProperties .Select(field => media.GetUrl(field.Alias, mediaUrlGenerators)) .Where(link => string.IsNullOrWhiteSpace(link) == false) .ToArray(); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 067b26e0f0..4f1c421d97 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -20,7 +20,6 @@ - diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs index 68d72f36fc..dd2f27320e 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/EmailNotificationMethod.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods ILocalizedTextService textService, IRequestAccessor requestAccessor, IOptions globalSettings, - IHealthChecksSettings healthChecksSettings, + IOptions healthChecksSettings, IOptions contentSettings) : base(healthChecksSettings) { diff --git a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/NotificationMethodBase.cs b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/NotificationMethodBase.cs index 3e6606e965..2c0c5bcc1f 100644 --- a/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/NotificationMethodBase.cs +++ b/src/Umbraco.Infrastructure/HealthCheck/NotificationMethods/NotificationMethodBase.cs @@ -2,13 +2,15 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Options; using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.Models; namespace Umbraco.Web.HealthCheck.NotificationMethods { public abstract class NotificationMethodBase : IHealthCheckNotificationMethod { - protected NotificationMethodBase(IHealthChecksSettings healthCheckSettingsConfig) + protected NotificationMethodBase(IOptions healthCheckSettings) { var type = GetType(); var attribute = type.GetCustomAttribute(); @@ -18,7 +20,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods return; } - var notificationMethods = healthCheckSettingsConfig.NotificationSettings.NotificationMethods; + var notificationMethods = healthCheckSettings.Value.NotificationSettings.NotificationMethods; if(!notificationMethods.TryGetValue(attribute.Alias, out var notificationMethod)) { Enabled = false; diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs index 1d8d8a8f79..1123ad0f9e 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs @@ -125,7 +125,7 @@ namespace Umbraco.Core.Runtime // register a server registrar, by default it's the db registrar composition.RegisterUnique(f => { - var globalSettings = f.GetInstance(); + var globalSettings = f.GetInstance>().Value; // TODO: we still register the full IServerMessenger because // even on 1 single server we can have 2 concurrent app domains diff --git a/src/Umbraco.Infrastructure/Scheduling/HealthCheckNotifier.cs b/src/Umbraco.Infrastructure/Scheduling/HealthCheckNotifier.cs index adae7b3828..e681538e12 100644 --- a/src/Umbraco.Infrastructure/Scheduling/HealthCheckNotifier.cs +++ b/src/Umbraco.Infrastructure/Scheduling/HealthCheckNotifier.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; using Umbraco.Core; -using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Scoping; using Umbraco.Core.Sync; @@ -17,7 +17,7 @@ namespace Umbraco.Web.Scheduling private readonly HealthCheckNotificationMethodCollection _notifications; private readonly IScopeProvider _scopeProvider; private readonly IProfilingLogger _logger; - private readonly IHealthChecksSettings _healthChecksSettingsConfig; + private readonly HealthChecksSettings _healthChecksSettings; private readonly IServerRegistrar _serverRegistrar; private readonly IRuntimeState _runtimeState; @@ -29,7 +29,7 @@ namespace Umbraco.Web.Scheduling HealthCheckNotificationMethodCollection notifications, IMainDom mainDom, IProfilingLogger logger, - IHealthChecksSettings healthChecksSettingsConfig, + HealthChecksSettings healthChecksSettings, IServerRegistrar serverRegistrar, IRuntimeState runtimeState, IScopeProvider scopeProvider) @@ -41,7 +41,7 @@ namespace Umbraco.Web.Scheduling _scopeProvider = scopeProvider; _runtimeState = runtimeState; _logger = logger; - _healthChecksSettingsConfig = healthChecksSettingsConfig; + _healthChecksSettings = healthChecksSettings; _serverRegistrar = serverRegistrar; _runtimeState = runtimeState; } @@ -74,7 +74,7 @@ namespace Umbraco.Web.Scheduling using (var scope = _scopeProvider.CreateScope()) using (_logger.DebugDuration("Health checks executing", "Health checks complete")) { - var healthCheckConfig = _healthChecksSettingsConfig; + var healthCheckConfig = _healthChecksSettings; // Don't notify for any checks that are disabled, nor for any disabled // just for notifications diff --git a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs index 6f014955b8..cfa9ced735 100644 --- a/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs +++ b/src/Umbraco.Infrastructure/Scheduling/SchedulerComponent.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.Scheduling private readonly HealthCheckCollection _healthChecks; private readonly HealthCheckNotificationMethodCollection _notifications; private readonly IUmbracoContextFactory _umbracoContextFactory; - private readonly IHealthChecksSettings _healthChecksSettingsConfig; + private readonly HealthChecksSettings _healthChecksSettings; private readonly IServerMessenger _serverMessenger; private readonly IRequestAccessor _requestAccessor; private readonly LoggingSettings _loggingSettings; @@ -57,7 +57,7 @@ namespace Umbraco.Web.Scheduling IContentService contentService, IAuditService auditService, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger, - IApplicationShutdownRegistry applicationShutdownRegistry, IHealthChecksSettings healthChecksSettingsConfig, + IApplicationShutdownRegistry applicationShutdownRegistry, IOptions healthChecksSettings, IServerMessenger serverMessenger, IRequestAccessor requestAccessor, IOptions loggingSettings, IOptions keepAliveSettings, IHostingEnvironment hostingEnvironment) @@ -74,7 +74,7 @@ namespace Umbraco.Web.Scheduling _healthChecks = healthChecks; _notifications = notifications; - _healthChecksSettingsConfig = healthChecksSettingsConfig ?? throw new ArgumentNullException(nameof(healthChecksSettingsConfig)); + _healthChecksSettings = healthChecksSettings.Value ?? throw new ArgumentNullException(nameof(healthChecksSettings)); _serverMessenger = serverMessenger; _requestAccessor = requestAccessor; _loggingSettings = loggingSettings.Value; @@ -129,7 +129,7 @@ namespace Umbraco.Web.Scheduling tasks.Add(RegisterLogScrubber(_loggingSettings)); tasks.Add(RegisterTempFileCleanup()); - var healthCheckConfig = _healthChecksSettingsConfig; + var healthCheckConfig = _healthChecksSettings; if (healthCheckConfig.NotificationSettings.Enabled) tasks.Add(RegisterHealthCheckNotifier(healthCheckConfig, _healthChecks, _notifications, _logger)); @@ -155,7 +155,7 @@ namespace Umbraco.Web.Scheduling return task; } - private IBackgroundTask RegisterHealthCheckNotifier(IHealthChecksSettings healthCheckSettingsConfig, + private IBackgroundTask RegisterHealthCheckNotifier(HealthChecksSettings healthCheckSettingsConfig, HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications, IProfilingLogger logger) { @@ -176,7 +176,7 @@ namespace Umbraco.Web.Scheduling } var periodInMilliseconds = healthCheckSettingsConfig.NotificationSettings.PeriodInHours * 60 * 60 * 1000; - var task = new HealthCheckNotifier(_healthCheckRunner, delayInMilliseconds, periodInMilliseconds, healthChecks, notifications, _mainDom, logger, _healthChecksSettingsConfig, _serverRegistrar, _runtime, _scopeProvider); + var task = new HealthCheckNotifier(_healthCheckRunner, delayInMilliseconds, periodInMilliseconds, healthChecks, notifications, _mainDom, logger, _healthChecksSettings, _serverRegistrar, _runtime, _scopeProvider); _healthCheckRunner.TryAdd(task); return task; } diff --git a/src/Umbraco.Infrastructure/Users/EmailSender.cs b/src/Umbraco.Infrastructure/Users/EmailSender.cs index 28bbf6471d..d563a0c36f 100644 --- a/src/Umbraco.Infrastructure/Users/EmailSender.cs +++ b/src/Umbraco.Infrastructure/Users/EmailSender.cs @@ -60,12 +60,12 @@ namespace Umbraco.Core using (var client = new SmtpClient()) { - client.Connect(_globalSettings.SmtpSettings.Host, _globalSettings.SmtpSettings.Port); + client.Connect(_globalSettings.Smtp.Host, _globalSettings.Smtp.Port); - if (!(_globalSettings.SmtpSettings.Username is null && - _globalSettings.SmtpSettings.Password is null)) + if (!(_globalSettings.Smtp.Username is null && + _globalSettings.Smtp.Password is null)) { - client.Authenticate(_globalSettings.SmtpSettings.Username, _globalSettings.SmtpSettings.Password); + client.Authenticate(_globalSettings.Smtp.Username, _globalSettings.Smtp.Password); } client.Send(ConstructEmailMessage(message)); @@ -89,16 +89,16 @@ namespace Umbraco.Core { using (var client = new SmtpClient()) { - await client.ConnectAsync(_globalSettings.SmtpSettings.Host, _globalSettings.SmtpSettings.Port); + await client.ConnectAsync(_globalSettings.Smtp.Host, _globalSettings.Smtp.Port); - if (!(_globalSettings.SmtpSettings.Username is null && - _globalSettings.SmtpSettings.Password is null)) + if (!(_globalSettings.Smtp.Username is null && + _globalSettings.Smtp.Password is null)) { - await client.AuthenticateAsync(_globalSettings.SmtpSettings.Username, _globalSettings.SmtpSettings.Password); + await client.AuthenticateAsync(_globalSettings.Smtp.Username, _globalSettings.Smtp.Password); } var mailMessage = ConstructEmailMessage(message); - if (_globalSettings.SmtpSettings.DeliveryMethod == SmtpDeliveryMethod.Network) + if (_globalSettings.Smtp.DeliveryMethod == SmtpDeliveryMethod.Network) { await client.SendAsync(mailMessage); } @@ -143,7 +143,7 @@ namespace Umbraco.Core { var fromEmail = mailMessage.From?.Address; if(string.IsNullOrEmpty(fromEmail)) - fromEmail = _globalSettings.SmtpSettings.From; + fromEmail = _globalSettings.Smtp.From; var messageToSend = new MimeMessage { diff --git a/src/Umbraco.Web.BackOffice/HealthCheck/HealthCheckController.cs b/src/Umbraco.Web.BackOffice/HealthCheck/HealthCheckController.cs index 6b8eada506..fc5ea85dfa 100644 --- a/src/Umbraco.Web.BackOffice/HealthCheck/HealthCheckController.cs +++ b/src/Umbraco.Web.BackOffice/HealthCheck/HealthCheckController.cs @@ -8,6 +8,8 @@ using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.HealthCheck; using Umbraco.Web.Common.Attributes; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Web.BackOffice.Controllers { @@ -22,12 +24,12 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly IList _disabledCheckIds; private readonly ILogger _logger; - public HealthCheckController(HealthCheckCollection checks, ILogger logger, IHealthChecksSettings healthChecksSettings) + public HealthCheckController(HealthCheckCollection checks, ILogger logger, IOptions healthChecksSettings) { _checks = checks ?? throw new ArgumentNullException(nameof(checks)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - var healthCheckConfig = healthChecksSettings ?? throw new ArgumentNullException(nameof(healthChecksSettings)); + var healthCheckConfig = healthChecksSettings.Value ?? throw new ArgumentNullException(nameof(healthChecksSettings)); _disabledCheckIds = healthCheckConfig.DisabledChecks .Select(x => x.Id) .ToList(); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index d03fb183e7..46d035d76b 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -104,29 +104,28 @@ namespace Umbraco.Extensions { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ConnectionStrings")); + services.Configure(configuration.GetSection("ConnectionStrings"), o => o.BindNonPublicProperties = true); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Core:Debug")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "MemberPassword:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "KeepAlive:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Content:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Logging:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ExceptionFilter:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ActiveDirectory:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigModelsBuilderPrefix)); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging:")); - services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "RequestHandler:")); - - // TODO: HealthChecksSettings (+ one other?) + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "MemberPassword")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "KeepAlive")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Content")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Logging")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ExceptionFilter")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "ActiveDirectory")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Runtime")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "TypeFinder")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Global")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Hosting")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "NuCache")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Examine")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigGlobalPrefix + "ModelsBuilder")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Imaging")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "RequestHandler")); + services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "HealthChecks")); // TODO: remove this var configsFactory = new AspNetCoreConfigsFactory(configuration); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs index 0b9154b6cf..394a15e1d4 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoWebServiceCollectionExtensions.cs @@ -64,8 +64,8 @@ namespace Umbraco.Extensions options.CachedNameLength = imagingSettings.Cache.CachedNameLength; options.OnParseCommands = context => { - RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, imagingSettings.Resize.MaxResizeWidth); - RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, imagingSettings.Resize.MaxResizeHeight); + RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Width, imagingSettings.Resize.MaxWidth); + RemoveIntParamenterIfValueGreatherThen(context.Commands, ResizeWebProcessor.Height, imagingSettings.Resize.MaxHeight); }; options.OnBeforeSave = _ => { }; options.OnProcessed = _ => { }; diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml index 0a7c95e7fe..dc47195a18 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml +++ b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/AuthorizeUpgrade.cshtml @@ -12,7 +12,7 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IOptionsSnapshot globalSettings +@inject IOptions globalSettings @inject IRuntimeMinifier runtimeMinifier @{ diff --git a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml index bce17553d6..b7c654a80d 100644 --- a/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml +++ b/src/Umbraco.Web.UI.NetCore/Umbraco/UmbracoBackOffice/Default.cshtml @@ -13,7 +13,7 @@ @inject BackOfficeServerVariables backOfficeServerVariables @inject IUmbracoVersion umbracoVersion @inject IHostingEnvironment hostingEnvironment -@inject IOptionsSnapshot globalSettings +@inject IOptions globalSettings @inject IRuntimeMinifier runtimeMinifier @inject IProfilerHtml profilerHtml diff --git a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs index 752983c7c9..c6ded26ce2 100644 --- a/src/Umbraco.Web/Configuration/ConfigModelConversions.cs +++ b/src/Umbraco.Web/Configuration/ConfigModelConversions.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.Configuration RegisterType = globalSettings.RegisterType, ReservedPaths = globalSettings.ReservedPaths, ReservedUrls = globalSettings.ReservedUrls, - SmtpSettings = new SmtpSettings + Smtp = new SmtpSettings { DeliveryMethod = globalSettings.SmtpSettings.DeliveryMethod, From = globalSettings.SmtpSettings.From,