Cleaned up condig for Logging and Tours
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Configuration;
|
||||
using Umbraco.Configuration;
|
||||
using Umbraco.Configuration.Implementations;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
@@ -18,6 +19,8 @@ namespace Umbraco.Core.Configuration
|
||||
public IRuntimeSettings RuntimeSettings { get; } = new RuntimeSettings();
|
||||
public IActiveDirectorySettings ActiveDirectorySettings { get; } = new ActiveDirectorySettings();
|
||||
public IExceptionFilterSettings ExceptionFilterSettings { get; } = new ExceptionFilterSettings();
|
||||
public ITourSettings TourSettings { get; } = new TourSettings();
|
||||
public ILoggingSettings LoggingSettings { get; } = new LoggingSettings();
|
||||
|
||||
public IUmbracoSettingsSection UmbracoSettings { get; }
|
||||
|
||||
@@ -47,6 +50,9 @@ namespace Umbraco.Core.Configuration
|
||||
configs.Add<IActiveDirectorySettings>(() => ActiveDirectorySettings);
|
||||
configs.Add<IExceptionFilterSettings>(() => ExceptionFilterSettings);
|
||||
|
||||
configs.Add<ITourSettings>(() => TourSettings);
|
||||
configs.Add<ILoggingSettings>(() => LoggingSettings);
|
||||
|
||||
configs.AddCoreConfigs(ioHelper);
|
||||
return configs;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
|
||||
namespace Umbraco.Configuration.Implementations
|
||||
{
|
||||
internal abstract class ConfigurationManagerConfigBase
|
||||
{
|
||||
private UmbracoSettingsSection _umbracoSettingsSection;
|
||||
|
||||
public UmbracoSettingsSection UmbracoSettingsSection
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_umbracoSettingsSection is null)
|
||||
{
|
||||
_umbracoSettingsSection = ConfigurationManager.GetSection("umbracoConfiguration/settings") as UmbracoSettingsSection;
|
||||
}
|
||||
return _umbracoSettingsSection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
|
||||
namespace Umbraco.Configuration.Implementations
|
||||
{
|
||||
internal class LoggingSettings : ConfigurationManagerConfigBase, ILoggingSettings
|
||||
{
|
||||
public int MaxLogAge => UmbracoSettingsSection.Logging.MaxLogAge;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
|
||||
namespace Umbraco.Configuration.Implementations
|
||||
{
|
||||
internal class TourSettings : ConfigurationManagerConfigBase, ITourSettings
|
||||
{
|
||||
public bool EnableTours => UmbracoSettingsSection.BackOffice.Tours.EnableTours;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
|
||||
[ConfigurationProperty("tours")]
|
||||
internal TourConfigElement Tours => (TourConfigElement)this["tours"];
|
||||
|
||||
ITourSection IBackOfficeSection.Tours => Tours;
|
||||
ITourSettings IBackOfficeSection.Tours => Tours;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.UmbracoSettings
|
||||
{
|
||||
internal class LoggingElement : UmbracoConfigurationElement, ILoggingSection
|
||||
internal class LoggingElement : UmbracoConfigurationElement, ILoggingSettings
|
||||
{
|
||||
|
||||
[ConfigurationProperty("maxLogAge")]
|
||||
internal InnerTextConfigurationElement<int> MaxLogAge => GetOptionalTextElement("maxLogAge", -1);
|
||||
|
||||
int ILoggingSection.MaxLogAge => MaxLogAge;
|
||||
int ILoggingSettings.MaxLogAge => MaxLogAge;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Umbraco.Core.Configuration.UmbracoSettings
|
||||
{
|
||||
internal class TourConfigElement : UmbracoConfigurationElement, ITourSection
|
||||
internal class TourConfigElement : UmbracoConfigurationElement, ITourSettings
|
||||
{
|
||||
//disabled by default so that upgraders don't get it enabled by default
|
||||
// TODO: we probably just want to disable the initial one from automatically loading ?
|
||||
|
||||
@@ -31,10 +31,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
|
||||
|
||||
IRequestHandlerSection IUmbracoSettingsSection.RequestHandler => RequestHandler;
|
||||
|
||||
IBackOfficeSection IUmbracoSettingsSection.BackOffice => BackOffice;
|
||||
|
||||
ILoggingSection IUmbracoSettingsSection.Logging => Logging;
|
||||
|
||||
IWebRoutingSection IUmbracoSettingsSection.WebRouting => WebRouting;
|
||||
|
||||
IKeepAliveSection IUmbracoSettingsSection.KeepAlive => KeepAlive;
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
{
|
||||
public interface IBackOfficeSection
|
||||
{
|
||||
ITourSection Tours { get; }
|
||||
ITourSettings Tours { get; }
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Umbraco.Core.Configuration.UmbracoSettings
|
||||
{
|
||||
public interface ILoggingSection : IUmbracoConfigurationSection
|
||||
public interface ILoggingSettings : IUmbracoConfigurationSection
|
||||
{
|
||||
int MaxLogAge { get; }
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Umbraco.Core.Configuration.UmbracoSettings
|
||||
{
|
||||
public interface ITourSection
|
||||
public interface ITourSettings
|
||||
{
|
||||
bool EnableTours { get; }
|
||||
}
|
||||
@@ -4,15 +4,11 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
|
||||
{
|
||||
public interface IUmbracoSettingsSection : IUmbracoConfigurationSection
|
||||
{
|
||||
IBackOfficeSection BackOffice { get; }
|
||||
|
||||
IContentSection Content { get; }
|
||||
|
||||
ISecuritySection Security { get; }
|
||||
|
||||
IRequestHandlerSection RequestHandler { get; }
|
||||
|
||||
ILoggingSection Logging { get; }
|
||||
|
||||
IWebRoutingSection WebRouting { get; }
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ namespace Umbraco.Web.Scheduling
|
||||
{
|
||||
private readonly IRuntimeState _runtime;
|
||||
private readonly IAuditService _auditService;
|
||||
private readonly IUmbracoSettingsSection _settings;
|
||||
private readonly ILoggingSettings _settings;
|
||||
private readonly IProfilingLogger _logger;
|
||||
private readonly IScopeProvider _scopeProvider;
|
||||
|
||||
public LogScrubber(IBackgroundTaskRunner<RecurringTaskBase> runner, int delayMilliseconds, int periodMilliseconds,
|
||||
IRuntimeState runtime, IAuditService auditService, IUmbracoSettingsSection settings, IScopeProvider scopeProvider, IProfilingLogger logger)
|
||||
IRuntimeState runtime, IAuditService auditService, ILoggingSettings settings, IScopeProvider scopeProvider, IProfilingLogger logger)
|
||||
: base(runner, delayMilliseconds, periodMilliseconds)
|
||||
{
|
||||
_runtime = runtime;
|
||||
@@ -29,13 +29,13 @@ namespace Umbraco.Web.Scheduling
|
||||
}
|
||||
|
||||
// maximum age, in minutes
|
||||
private int GetLogScrubbingMaximumAge(IUmbracoSettingsSection settings)
|
||||
private int GetLogScrubbingMaximumAge(ILoggingSettings settings)
|
||||
{
|
||||
var maximumAge = 24 * 60; // 24 hours, in minutes
|
||||
try
|
||||
{
|
||||
if (settings.Logging.MaxLogAge > -1)
|
||||
maximumAge = settings.Logging.MaxLogAge;
|
||||
if (settings.MaxLogAge > -1)
|
||||
maximumAge = settings.MaxLogAge;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace Umbraco.Web.Scheduling
|
||||
|
||||
}
|
||||
|
||||
public static int GetLogScrubbingInterval(IUmbracoSettingsSection settings, ILogger logger)
|
||||
public static int GetLogScrubbingInterval()
|
||||
{
|
||||
const int interval = 4 * 60 * 60 * 1000; // 4 hours, in milliseconds
|
||||
return interval;
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Umbraco.Web.Scheduling
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IServerMessenger _serverMessenger;
|
||||
private readonly IRequestAccessor _requestAccessor;
|
||||
private readonly ILoggingSettings _loggingSettings;
|
||||
|
||||
private BackgroundTaskRunner<IBackgroundTask> _keepAliveRunner;
|
||||
private BackgroundTaskRunner<IBackgroundTask> _publishingRunner;
|
||||
@@ -56,7 +57,8 @@ namespace Umbraco.Web.Scheduling
|
||||
HealthCheckCollection healthChecks, HealthCheckNotificationMethodCollection notifications,
|
||||
IScopeProvider scopeProvider, IUmbracoContextFactory umbracoContextFactory, IProfilingLogger logger,
|
||||
IHostingEnvironment hostingEnvironment, IHealthChecks healthChecksConfig,
|
||||
IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, IServerMessenger serverMessenger, IRequestAccessor requestAccessor)
|
||||
IUmbracoSettingsSection umbracoSettingsSection, IIOHelper ioHelper, IServerMessenger serverMessenger, IRequestAccessor requestAccessor,
|
||||
ILoggingSettings loggingSettings)
|
||||
{
|
||||
_runtime = runtime;
|
||||
_contentService = contentService;
|
||||
@@ -69,10 +71,11 @@ namespace Umbraco.Web.Scheduling
|
||||
_healthChecks = healthChecks;
|
||||
_notifications = notifications;
|
||||
_healthChecksConfig = healthChecksConfig ?? throw new ArgumentNullException(nameof(healthChecksConfig));
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_umbracoSettingsSection = umbracoSettingsSection;
|
||||
_ioHelper = ioHelper;
|
||||
_serverMessenger = serverMessenger;
|
||||
_requestAccessor = requestAccessor;
|
||||
_loggingSettings = loggingSettings;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
@@ -121,7 +124,7 @@ namespace Umbraco.Web.Scheduling
|
||||
}
|
||||
|
||||
tasks.Add(RegisterScheduledPublishing());
|
||||
tasks.Add(RegisterLogScrubber(settings));
|
||||
tasks.Add(RegisterLogScrubber(_loggingSettings));
|
||||
tasks.Add(RegisterTempFileCleanup());
|
||||
|
||||
var healthCheckConfig = _healthChecksConfig;
|
||||
@@ -176,11 +179,11 @@ namespace Umbraco.Web.Scheduling
|
||||
return task;
|
||||
}
|
||||
|
||||
private IBackgroundTask RegisterLogScrubber(IUmbracoSettingsSection settings)
|
||||
private IBackgroundTask RegisterLogScrubber(ILoggingSettings settings)
|
||||
{
|
||||
// log scrubbing
|
||||
// install on all, will only run on non-replica servers
|
||||
var task = new LogScrubber(_scrubberRunner, DefaultDelayMilliseconds, LogScrubber.GetLogScrubbingInterval(settings, _logger), _runtime, _auditService, settings, _scopeProvider, _logger);
|
||||
var task = new LogScrubber(_scrubberRunner, DefaultDelayMilliseconds, LogScrubber.GetLogScrubbingInterval(), _runtime, _auditService, settings, _scopeProvider, _logger);
|
||||
_scrubberRunner.TryAdd(task);
|
||||
return task;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings
|
||||
[Test]
|
||||
public override void MaxLogAge()
|
||||
{
|
||||
Assert.IsTrue(SettingsSection.Logging.MaxLogAge == -1);
|
||||
Assert.IsTrue(LoggingSettings.MaxLogAge == -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings
|
||||
[TestFixture]
|
||||
public class LoggingElementTests : UmbracoSettingsTests
|
||||
{
|
||||
|
||||
|
||||
[Test]
|
||||
public virtual void MaxLogAge()
|
||||
{
|
||||
Assert.IsTrue(SettingsSection.Logging.MaxLogAge == 1440);
|
||||
Assert.IsTrue(LoggingSettings.MaxLogAge == 1440);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -22,16 +22,19 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings
|
||||
Debug.WriteLine("Testing defaults? {0}", TestingDefaults);
|
||||
if (TestingDefaults)
|
||||
{
|
||||
SettingsSection = configuration.GetSection("umbracoConfiguration/defaultSettings") as UmbracoSettingsSection;
|
||||
Settings = configuration.GetSection("umbracoConfiguration/defaultSettings") as UmbracoSettingsSection;
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsSection = configuration.GetSection("umbracoConfiguration/settings") as UmbracoSettingsSection;
|
||||
Settings = configuration.GetSection("umbracoConfiguration/settings") as UmbracoSettingsSection;
|
||||
}
|
||||
|
||||
Assert.IsNotNull(SettingsSection);
|
||||
Assert.IsNotNull(Settings);
|
||||
}
|
||||
|
||||
protected IUmbracoSettingsSection SettingsSection { get; private set; }
|
||||
protected IUmbracoSettingsSection SettingsSection => Settings;
|
||||
private UmbracoSettingsSection Settings { get; set; }
|
||||
|
||||
protected ILoggingSettings LoggingSettings => Settings.Logging;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
var content = new Mock<IContentSection>();
|
||||
var security = new Mock<ISecuritySection>();
|
||||
var requestHandler = new Mock<IRequestHandlerSection>();
|
||||
var logging = new Mock<ILoggingSection>();
|
||||
var logging = new Mock<ILoggingSettings>();
|
||||
var routing = new Mock<IWebRoutingSection>();
|
||||
|
||||
var userPasswordConfig = new Mock<IUserPasswordConfigurationSection>();
|
||||
@@ -56,7 +56,6 @@ namespace Umbraco.Tests.TestHelpers
|
||||
settings.Setup(x => x.Content).Returns(content.Object);
|
||||
settings.Setup(x => x.Security).Returns(security.Object);
|
||||
settings.Setup(x => x.RequestHandler).Returns(requestHandler.Object);
|
||||
settings.Setup(x => x.Logging).Returns(logging.Object);
|
||||
settings.Setup(x => x.WebRouting).Returns(routing.Object);
|
||||
|
||||
//Now configure some defaults - the defaults in the config section classes do NOT pertain to the mocked data!!
|
||||
|
||||
+429
-415
File diff suppressed because it is too large
Load Diff
@@ -25,8 +25,8 @@ namespace Umbraco.Web.Editors
|
||||
public class TourController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
private readonly TourFilterCollection _filters;
|
||||
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly ITourSettings _tourSettings;
|
||||
|
||||
public TourController(
|
||||
IGlobalSettings globalSettings,
|
||||
@@ -39,21 +39,21 @@ namespace Umbraco.Web.Editors
|
||||
IShortStringHelper shortStringHelper,
|
||||
UmbracoMapper umbracoMapper,
|
||||
TourFilterCollection filters,
|
||||
IUmbracoSettingsSection umbracoSettingsSection,
|
||||
IIOHelper ioHelper,
|
||||
IPublishedUrlProvider publishedUrlProvider)
|
||||
IPublishedUrlProvider publishedUrlProvider,
|
||||
ITourSettings tourSettings)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, shortStringHelper, umbracoMapper, publishedUrlProvider)
|
||||
{
|
||||
_filters = filters;
|
||||
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
|
||||
_ioHelper = ioHelper;
|
||||
_tourSettings = tourSettings;
|
||||
}
|
||||
|
||||
public IEnumerable<BackOfficeTourFile> GetTours()
|
||||
{
|
||||
var result = new List<BackOfficeTourFile>();
|
||||
|
||||
if (_umbracoSettingsSection.BackOffice.Tours.EnableTours == false)
|
||||
if (_tourSettings.EnableTours == false)
|
||||
return result;
|
||||
|
||||
var user = UmbracoContext.Security.CurrentUser;
|
||||
|
||||
Reference in New Issue
Block a user