updated files before move

This commit is contained in:
Bjarke Berg
2021-02-03 07:58:42 +01:00
parent 8624a246ba
commit 0f226b590a
16 changed files with 282 additions and 621 deletions

View File

@@ -1,30 +1,42 @@
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.HealthCheck;
using Umbraco.Core.HealthCheck.Checks;
using Umbraco.Core.Services;
namespace Umbraco.Core.Configuration.HealthChecks
namespace Umbraco.Core.HealthChecks.Checks.LiveEnvironment
{
[HealthCheck("61214FF3-FC57-4B31-B5CF-1D095C977D6D", "Debug Compilation Mode",
/// <summary>
/// Health check for the configuration of debug-flag.
/// </summary>
[HealthCheck(
"61214FF3-FC57-4B31-B5CF-1D095C977D6D",
"Debug Compilation Mode",
Description = "Leaving debug compilation mode enabled can severely slow down a website and take up more memory on the server.",
Group = "Live Environment")]
public class CompilationDebugCheck : AbstractSettingsCheck
{
private readonly IOptionsMonitor<HostingSettings> _hostingSettings;
public CompilationDebugCheck(ILocalizedTextService textService, ILoggerFactory loggerFactory, IOptionsMonitor<HostingSettings> hostingSettings)
: base(textService, loggerFactory)
{
/// <summary>
/// Initializes a new instance of the <see cref="CompilationDebugCheck"/> class.
/// </summary>
public CompilationDebugCheck(ILocalizedTextService textService, IOptionsMonitor<HostingSettings> hostingSettings)
: base(textService) =>
_hostingSettings = hostingSettings;
}
/// <inheritdoc/>
public override string ItemPath => Constants.Configuration.ConfigHostingDebug;
/// <inheritdoc/>
public override string ReadMoreLink => Constants.HealthChecks.DocumentationLinks.LiveEnvironment.CompilationDebugCheck;
/// <inheritdoc/>
public override ValueComparisonType ValueComparisonType => ValueComparisonType.ShouldEqual;
/// <inheritdoc/>
public override IEnumerable<AcceptableConfiguration> Values => new List<AcceptableConfiguration>
{
new AcceptableConfiguration
@@ -34,12 +46,13 @@ namespace Umbraco.Core.Configuration.HealthChecks
}
};
/// <inheritdoc/>
public override string CurrentValue => _hostingSettings.CurrentValue.Debug.ToString();
public override string CheckSuccessMessage => TextService.Localize("healthcheck/compilationDebugCheckSuccessMessage");
/// <inheritdoc/>
public override string CheckSuccessMessage => LocalizedTextService.Localize("healthcheck/compilationDebugCheckSuccessMessage");
public override string CheckErrorMessage => TextService.Localize("healthcheck/compilationDebugCheckErrorMessage");
public override string RectifySuccessMessage => TextService.Localize("healthcheck/compilationDebugCheckRectifySuccessMessage");
/// <inheritdoc/>
public override string CheckErrorMessage => LocalizedTextService.Localize("healthcheck/compilationDebugCheckErrorMessage");
}
}

View File

@@ -1,71 +0,0 @@
using System;
using Microsoft.Extensions.Logging;
using Umbraco.Core.HealthCheck;
using Umbraco.Core.Services;
namespace Umbraco.Core.Configuration.HealthChecks
{
public class ConfigurationService : IConfigurationService
{
private readonly ILocalizedTextService _textService;
private readonly ILogger<ConfigurationService> _logger;
private readonly IConfigManipulator _configManipulator;
/// <param name="textService"></param>
/// <param name="logger"></param>
/// <param name="configManipulator"></param>
/// <returns></returns>
public ConfigurationService(ILocalizedTextService textService, ILogger<ConfigurationService> logger, IConfigManipulator configManipulator)
{
if (textService == null) HandleNullParameter(nameof(textService));
if (configManipulator == null) HandleNullParameter(nameof(configManipulator));
if (logger == null) HandleNullParameter(nameof(logger));
_configManipulator = configManipulator;
_textService = textService;
_logger = logger;
}
private void HandleNullParameter(string parameter)
{
_logger.LogError("Error trying to get configuration value", parameter);
throw new ArgumentNullException(parameter);
}
/// <summary>
/// Updates a value in a given configuration file with the given path
/// </summary>
/// <param name="value"></param>
/// <param name="itemPath"></param>
/// <returns></returns>
public ConfigurationServiceResult UpdateConfigFile(string value, string itemPath)
{
try
{
if (itemPath == null)
{
return new ConfigurationServiceResult
{
Success = false,
Result = _textService.Localize("healthcheck/configurationServiceNodeNotFound", new[] { itemPath, value })
};
}
_configManipulator.SaveConfigValue(itemPath, value);
return new ConfigurationServiceResult
{
Success = true
};
}
catch (Exception ex)
{
_logger.LogError(ex, "Error trying to update configuration");
return new ConfigurationServiceResult
{
Success = false,
Result = _textService.Localize("healthcheck/configurationServiceError", new[] { ex.Message })
};
}
}
}
}

View File

@@ -1,80 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Hosting;
using Umbraco.Core.Services;
namespace Umbraco.Core.HealthCheck.Checks.Configuration
{
[Obsolete("This is not currently in the appsettings.JSON and so can either be removed, or rewritten in .NET Core fashion")]
[HealthCheck("046A066C-4FB2-4937-B931-069964E16C66", "Try Skip IIS Custom Errors",
Description = "Starting with IIS 7.5, this must be set to true for Umbraco 404 pages to show. Otherwise, IIS will takeover and render its built-in error page.",
Group = "Configuration")]
public class TrySkipIisCustomErrorsCheck : AbstractSettingsCheck
{
private readonly ILocalizedTextService _textService;
private readonly ILoggerFactory _loggerFactory;
private readonly Version _iisVersion;
private readonly GlobalSettings _globalSettings;
public TrySkipIisCustomErrorsCheck(ILocalizedTextService textService, ILoggerFactory loggerFactory, IOptions<GlobalSettings> globalSettings)
: base(textService, loggerFactory)
{
_textService = textService;
_loggerFactory = loggerFactory;
//TODO: detect if hosted in IIS, and then IIS version if we want to go this route
_iisVersion = new Version("7.5");
_globalSettings = globalSettings.Value;
}
public override string ItemPath => "TBC";
public override ValueComparisonType ValueComparisonType => ValueComparisonType.ShouldEqual;
public override string CurrentValue => null;
public override IEnumerable<AcceptableConfiguration> Values
{
get
{
// beware! 7.5 and 7.5.0 are not the same thing!
var recommendedValue = _iisVersion >= new Version("7.5")
? bool.TrueString.ToLower()
: bool.FalseString.ToLower();
return new List<AcceptableConfiguration> { new AcceptableConfiguration { IsRecommended = true, Value = recommendedValue } };
}
}
public override string CheckSuccessMessage
{
get
{
return _textService.Localize("healthcheck/trySkipIisCustomErrorsCheckSuccessMessage",
new[] { Values.First(v => v.IsRecommended).Value, _iisVersion.ToString() });
}
}
public override string CheckErrorMessage
{
get
{
return _textService.Localize("healthcheck/trySkipIisCustomErrorsCheckErrorMessage",
new[] { CurrentValue, Values.First(v => v.IsRecommended).Value, _iisVersion.ToString() });
}
}
public override string RectifySuccessMessage
{
get
{
return _textService.Localize("healthcheck/trySkipIisCustomErrorsCheckRectifySuccessMessage",
new[] { "Not implemented" });
//new[] { Values.First(v => v.IsRecommended).Value, _iisVersion.ToString() });
}
}
}
}