From fc1e4b182af1fe029fc9a9d7aae2fd23a4757396 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 10:43:33 +0100 Subject: [PATCH 01/61] Move logging stuff --- .../Logging/DebugDiagnosticsLogger.cs | 21 ++++++++++------ .../Logging/IMessageTemplates.cs | 7 ++++++ .../Logging/LogProfiler.cs | 2 +- .../Logging/LoggingTaskExtension.cs | 0 .../Logging/VoidProfiler.cs | 2 +- src/Umbraco.Core/Composing/Current.cs | 2 +- src/Umbraco.Core/Logging/MessageTemplates.cs | 4 +-- src/Umbraco.Core/Umbraco.Core.csproj | 4 --- .../BulkInsertBenchmarks.cs | 2 +- .../Composing/TypeFinderTests.cs | 2 +- .../Migrations/AdvancedMigrationTests.cs | 10 ++++---- src/Umbraco.Tests/Models/ContentTests.cs | 4 +-- src/Umbraco.Tests/Models/ContentTypeTests.cs | 2 +- .../NPocoTests/NPocoBulkInsertTests.cs | 2 +- .../Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 4 +-- .../Scheduling/BackgroundTaskRunnerTests.cs | 2 +- .../Scheduling/BackgroundTaskRunnerTests2.cs | 4 +-- .../Services/ContentServicePerformanceTest.cs | 4 +-- .../Services/PerformanceTests.cs | 2 +- .../TestHelpers/ConsoleLogger.cs | 25 ++++++++++++------- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- 22 files changed, 63 insertions(+), 46 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Logging/DebugDiagnosticsLogger.cs (77%) create mode 100644 src/Umbraco.Abstractions/Logging/IMessageTemplates.cs rename src/{Umbraco.Core => Umbraco.Abstractions}/Logging/LogProfiler.cs (97%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Logging/LoggingTaskExtension.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Logging/VoidProfiler.cs (92%) diff --git a/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs b/src/Umbraco.Abstractions/Logging/DebugDiagnosticsLogger.cs similarity index 77% rename from src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs rename to src/Umbraco.Abstractions/Logging/DebugDiagnosticsLogger.cs index d1bde55306..552daba713 100644 --- a/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs +++ b/src/Umbraco.Abstractions/Logging/DebugDiagnosticsLogger.cs @@ -7,6 +7,13 @@ namespace Umbraco.Core.Logging /// public class DebugDiagnosticsLogger : ILogger { + private readonly IMessageTemplates _messageTemplates; + + public DebugDiagnosticsLogger(IMessageTemplates messageTemplates) + { + _messageTemplates = messageTemplates; + } + public bool IsEnabled(Type reporting, LogLevel level) => true; @@ -31,7 +38,7 @@ namespace Umbraco.Core.Logging /// public void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, reporting.FullName); } /// @@ -61,7 +68,7 @@ namespace Umbraco.Core.Logging /// public void Error(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, reporting.FullName); } /// @@ -79,7 +86,7 @@ namespace Umbraco.Core.Logging /// public void Warn(Type reporting, string message, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(message, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(message, propertyValues), reporting.FullName); } /// @@ -91,7 +98,7 @@ namespace Umbraco.Core.Logging /// public void Warn(Type reporting, Exception exception, string message, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(message + Environment.NewLine + exception, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(message + Environment.NewLine + exception, propertyValues), reporting.FullName); } /// @@ -103,7 +110,7 @@ namespace Umbraco.Core.Logging /// public void Info(Type reporting, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); } /// @@ -115,7 +122,7 @@ namespace Umbraco.Core.Logging /// public void Debug(Type reporting, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); } /// @@ -127,7 +134,7 @@ namespace Umbraco.Core.Logging /// public void Verbose(Type reporting, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); } } } diff --git a/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs b/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs new file mode 100644 index 0000000000..60aa1035ad --- /dev/null +++ b/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs @@ -0,0 +1,7 @@ +namespace Umbraco.Core.Logging +{ + public interface IMessageTemplates + { + string Render(string messageTemplate, params object[] args); + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Logging/LogProfiler.cs b/src/Umbraco.Abstractions/Logging/LogProfiler.cs similarity index 97% rename from src/Umbraco.Core/Logging/LogProfiler.cs rename to src/Umbraco.Abstractions/Logging/LogProfiler.cs index 74dae545b4..294f92dad3 100644 --- a/src/Umbraco.Core/Logging/LogProfiler.cs +++ b/src/Umbraco.Abstractions/Logging/LogProfiler.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Logging /// /// Implements by writing profiling results to an . /// - internal class LogProfiler : IProfiler + public class LogProfiler : IProfiler { private readonly ILogger _logger; diff --git a/src/Umbraco.Core/Logging/LoggingTaskExtension.cs b/src/Umbraco.Abstractions/Logging/LoggingTaskExtension.cs similarity index 100% rename from src/Umbraco.Core/Logging/LoggingTaskExtension.cs rename to src/Umbraco.Abstractions/Logging/LoggingTaskExtension.cs diff --git a/src/Umbraco.Core/Logging/VoidProfiler.cs b/src/Umbraco.Abstractions/Logging/VoidProfiler.cs similarity index 92% rename from src/Umbraco.Core/Logging/VoidProfiler.cs rename to src/Umbraco.Abstractions/Logging/VoidProfiler.cs index 24eb8e81c3..51bec521a3 100644 --- a/src/Umbraco.Core/Logging/VoidProfiler.cs +++ b/src/Umbraco.Abstractions/Logging/VoidProfiler.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Logging { - internal class VoidProfiler : IProfiler + public class VoidProfiler : IProfiler { private readonly VoidDisposable _disposable = new VoidDisposable(); diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index f12bf0dd63..ed64347816 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -113,7 +113,7 @@ namespace Umbraco.Core.Composing public static ILogger Logger => _logger ?? (_logger = _factory?.TryGetInstance() - ?? new DebugDiagnosticsLogger()); + ?? new DebugDiagnosticsLogger(new MessageTemplates())); public static IProfiler Profiler => _profiler ?? (_profiler = _factory?.TryGetInstance() diff --git a/src/Umbraco.Core/Logging/MessageTemplates.cs b/src/Umbraco.Core/Logging/MessageTemplates.cs index 47de1230ff..887aa1402d 100644 --- a/src/Umbraco.Core/Logging/MessageTemplates.cs +++ b/src/Umbraco.Core/Logging/MessageTemplates.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Logging /// /// Provides tools to support message templates. /// - public static class MessageTemplates + public class MessageTemplates : IMessageTemplates { // Umbraco now uses Message Templates (https://messagetemplates.org/) for logging, which means // we cannot plainly use string.Format() to format them. There is a work-in-progress C# lib, @@ -21,7 +21,7 @@ namespace Umbraco.Core.Logging private static readonly Lazy MinimalLogger = new Lazy(() => new LoggerConfiguration().CreateLogger()); - public static string Render(string messageTemplate, params object[] args) + public string Render(string messageTemplate, params object[] args) { // by default, unless initialized otherwise, Log.Logger is SilentLogger which cannot bind message // templates. Log.Logger is set to a true Logger when initializing Umbraco's logger, but in case diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index d41240c586..25de78105f 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -572,13 +572,9 @@ - - - - diff --git a/src/Umbraco.Tests.Benchmarks/BulkInsertBenchmarks.cs b/src/Umbraco.Tests.Benchmarks/BulkInsertBenchmarks.cs index d6dc1f8c73..dc260c4a3b 100644 --- a/src/Umbraco.Tests.Benchmarks/BulkInsertBenchmarks.cs +++ b/src/Umbraco.Tests.Benchmarks/BulkInsertBenchmarks.cs @@ -49,7 +49,7 @@ namespace Umbraco.Tests.Benchmarks [GlobalSetup] public void Setup() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var path = TestHelper.CurrentAssemblyDirectory; SetupSqlCe(path, logger); diff --git a/src/Umbraco.Tests/Composing/TypeFinderTests.cs b/src/Umbraco.Tests/Composing/TypeFinderTests.cs index ca622e9288..5511c5cba3 100644 --- a/src/Umbraco.Tests/Composing/TypeFinderTests.cs +++ b/src/Umbraco.Tests/Composing/TypeFinderTests.cs @@ -94,7 +94,7 @@ namespace Umbraco.Tests.Composing private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } diff --git a/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs b/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs index c13d141fa5..01c93a40ec 100644 --- a/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs +++ b/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CreateTableOfTDto() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) @@ -53,7 +53,7 @@ namespace Umbraco.Tests.Migrations [Test] public void DeleteKeysAndIndexesOfTDto() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) @@ -87,7 +87,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CreateKeysAndIndexesOfTDto() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) @@ -124,7 +124,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CreateKeysAndIndexes() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) @@ -161,7 +161,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CreateColumn() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index 3116087669..8dded05eab 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -55,7 +55,7 @@ namespace Umbraco.Tests.Models var mediaTypeService = Mock.Of(); var memberTypeService = Mock.Of(); Composition.Register(_ => ServiceContext.CreatePartial(dataTypeService: dataTypeService, contentTypeBaseServiceProvider: new ContentTypeBaseServiceProvider(_contentTypeService, mediaTypeService, memberTypeService))); - + } [Test] @@ -236,7 +236,7 @@ namespace Umbraco.Tests.Models private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } diff --git a/src/Umbraco.Tests/Models/ContentTypeTests.cs b/src/Umbraco.Tests/Models/ContentTypeTests.cs index 9c3b976bf3..74229dd5d6 100644 --- a/src/Umbraco.Tests/Models/ContentTypeTests.cs +++ b/src/Umbraco.Tests/Models/ContentTypeTests.cs @@ -129,7 +129,7 @@ namespace Umbraco.Tests.Models private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } diff --git a/src/Umbraco.Tests/Persistence/NPocoTests/NPocoBulkInsertTests.cs b/src/Umbraco.Tests/Persistence/NPocoTests/NPocoBulkInsertTests.cs index 2a6c1f4e12..85b07d4828 100644 --- a/src/Umbraco.Tests/Persistence/NPocoTests/NPocoBulkInsertTests.cs +++ b/src/Umbraco.Tests/Persistence/NPocoTests/NPocoBulkInsertTests.cs @@ -92,7 +92,7 @@ namespace Umbraco.Tests.Persistence.NPocoTests // create the db // prob not what we want, this is not a real database, but hey, the test is ignored anyways // we'll fix this when we have proper testing infrastructure - var dbSqlServer = TestObjects.GetUmbracoSqlServerDatabase(new DebugDiagnosticsLogger()); + var dbSqlServer = TestObjects.GetUmbracoSqlServerDatabase(new DebugDiagnosticsLogger(new MessageTemplates())); //drop the table dbSqlServer.Execute("DROP TABLE [umbracoServer]"); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 5850153100..7cf3c008f1 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -89,7 +89,7 @@ namespace Umbraco.Tests.Runtimes // test runtime public class TestRuntime : CoreRuntime { - protected override ILogger GetLogger() => new DebugDiagnosticsLogger(); + protected override ILogger GetLogger() => new DebugDiagnosticsLogger(new MessageTemplates()); protected override IProfiler GetProfiler() => new TestProfiler(); // must override the database factory diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index d0258a100f..fdeb743b6c 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -56,7 +56,7 @@ namespace Umbraco.Tests.Runtimes // FIXME: we need a better management of settings here (and, true config files?) // create the very basic and essential things we need - var logger = new ConsoleLogger(); + var logger = new ConsoleLogger(new MessageTemplates()); var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = new AppCaches(); // FIXME: has HttpRuntime stuff? @@ -244,7 +244,7 @@ namespace Umbraco.Tests.Runtimes // - assigning the factory to Current.Factory // create the very basic and essential things we need - var logger = new ConsoleLogger(); + var logger = new ConsoleLogger(new MessageTemplates()); var profiler = Mock.Of(); var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = AppCaches.Disabled; diff --git a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs index 3664717af7..27abca7cbd 100644 --- a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs +++ b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Scheduling [OneTimeSetUp] public void InitializeFixture() { - _logger = new DebugDiagnosticsLogger(); + _logger = new DebugDiagnosticsLogger(new MessageTemplates()); } [Test] diff --git a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs index 8e886d7dc9..6a65f3afbc 100644 --- a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs +++ b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Scheduling [Timeout(4000)] public async Task ThreadResumeIssue() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, logger); var work = new ThreadResumeIssueWorkItem(); runner.Add(work); @@ -76,7 +76,7 @@ namespace Umbraco.Tests.Scheduling [Ignore("Only runs in the debugger.")] public async Task DebuggerInterferenceIssue() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, logger); var taskCompleted = false; runner.TaskCompleted += (sender, args) => diff --git a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs index ef80672baf..ace45fe356 100644 --- a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs +++ b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs @@ -47,7 +47,7 @@ namespace Umbraco.Tests.Services private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } @@ -268,7 +268,7 @@ namespace Umbraco.Tests.Services var tagRepo = new TagRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository((IScopeAccessor)provider, tRepository, AppCaches); var languageRepository = new LanguageRepository((IScopeAccessor)provider, AppCaches.Disabled, Logger); - var ctRepository = new ContentTypeRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, commonRepository, languageRepository); + var ctRepository = new ContentTypeRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, commonRepository, languageRepository); var repository = new DocumentRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, ctRepository, tRepository, tagRepo, languageRepository); // Act diff --git a/src/Umbraco.Tests/Services/PerformanceTests.cs b/src/Umbraco.Tests/Services/PerformanceTests.cs index 9cf38e1789..0ac6eeb863 100644 --- a/src/Umbraco.Tests/Services/PerformanceTests.cs +++ b/src/Umbraco.Tests/Services/PerformanceTests.cs @@ -60,7 +60,7 @@ namespace Umbraco.Tests.Services private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } diff --git a/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs b/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs index a3e36db363..53d6078e4b 100644 --- a/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs +++ b/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs @@ -5,6 +5,13 @@ namespace Umbraco.Tests.TestHelpers { public class ConsoleLogger : ILogger { + private readonly IMessageTemplates _messageTemplates; + + public ConsoleLogger(IMessageTemplates messageTemplates) + { + _messageTemplates = messageTemplates; + } + public bool IsEnabled(Type reporting, LogLevel level) => true; @@ -27,13 +34,13 @@ namespace Umbraco.Tests.TestHelpers public void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("FATAL {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("FATAL {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); Console.WriteLine(exception); } public void Fatal(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("FATAL {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("FATAL {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } public void Error(Type reporting, Exception exception, string message) @@ -55,13 +62,13 @@ namespace Umbraco.Tests.TestHelpers public void Error(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("ERROR {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("ERROR {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); Console.WriteLine(exception); } public void Error(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("ERROR {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("ERROR {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } public void Warn(Type reporting, string message) @@ -71,7 +78,7 @@ namespace Umbraco.Tests.TestHelpers public void Warn(Type reporting, string message, params object[] propertyValues) { - Console.WriteLine("WARN {0} - {1}", reporting.Name, MessageTemplates.Render(message, propertyValues)); + Console.WriteLine("WARN {0} - {1}", reporting.Name, _messageTemplates.Render(message, propertyValues)); } public void Warn(Type reporting, Exception exception, string message) @@ -82,13 +89,13 @@ namespace Umbraco.Tests.TestHelpers public void Warn(Type reporting, Exception exception, string message, params object[] propertyValues) { - Console.WriteLine("WARN {0} - {1}", reporting.Name, MessageTemplates.Render(message, propertyValues)); + Console.WriteLine("WARN {0} - {1}", reporting.Name, _messageTemplates.Render(message, propertyValues)); Console.WriteLine(exception); } public void Info(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("INFO {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("INFO {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } public void Info(Type reporting, string message) @@ -103,7 +110,7 @@ namespace Umbraco.Tests.TestHelpers public void Debug(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("DEBUG {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("DEBUG {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } public void Verbose(Type reporting, string message) @@ -113,7 +120,7 @@ namespace Umbraco.Tests.TestHelpers public void Verbose(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("VERBOSE {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("VERBOSE {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } } } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 7e72a5aefb..2f86bddb3b 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -190,7 +190,7 @@ namespace Umbraco.Tests.Testing profiler = new LogProfiler(logger); break; case UmbracoTestOptions.Logger.Console: - logger = new ConsoleLogger(); + logger = new ConsoleLogger(new MessageTemplates()); profiler = new LogProfiler(logger); break; default: From 8f4d4cb23f76e717c6356823c7ac58631f2be3d7 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 10:56:11 +0100 Subject: [PATCH 02/61] Move a small part of current --- src/Umbraco.Abstractions/Composing/Current.cs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Umbraco.Abstractions/Composing/Current.cs diff --git a/src/Umbraco.Abstractions/Composing/Current.cs b/src/Umbraco.Abstractions/Composing/Current.cs new file mode 100644 index 0000000000..39a7f5c8be --- /dev/null +++ b/src/Umbraco.Abstractions/Composing/Current.cs @@ -0,0 +1,58 @@ +using System; +using Umbraco.Core.Logging; + +namespace Umbraco.Core.Composing +{ + /// + /// Provides a static service locator for most singletons. + /// + /// + /// This class is initialized with the container in UmbracoApplicationBase, + /// right after the container is created in UmbracoApplicationBase.HandleApplicationStart. + /// Obviously, this is a service locator, which some may consider an anti-pattern. And yet, + /// practically, it works. + /// + public static class CurrentCore + { + private static IFactory _factory; + + private static ILogger _logger; + private static IProfiler _profiler; + private static IProfilingLogger _profilingLogger; + + /// + /// Gets or sets the factory. + /// + public static IFactory Factory + { + get + { + if (_factory == null) throw new InvalidOperationException("No factory has been set."); + return _factory; + } + set + { + if (_factory != null) throw new InvalidOperationException("A factory has already been set."); + // if (_configs != null) throw new InvalidOperationException("Configs are unlocked."); + _factory = value; + } + } + + internal static bool HasFactory => _factory != null; + + #region Getters + + public static ILogger Logger + => _logger ?? (_logger = _factory?.TryGetInstance() ?? throw new Exception("TODO Fix")); //?? new DebugDiagnosticsLogger(new MessageTemplates())); + + public static IProfiler Profiler + => _profiler ?? (_profiler = _factory?.TryGetInstance() + ?? new LogProfiler(Logger)); + + public static IProfilingLogger ProfilingLogger + => _profilingLogger ?? (_profilingLogger = _factory?.TryGetInstance()) + ?? new ProfilingLogger(Logger, Profiler); + + #endregion + } +} From 934fa2748dce608bfe13fffb380b7fb3db41d65f Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 13:35:34 +0100 Subject: [PATCH 03/61] Move events --- .../Composing/ComponentCollection.cs | 0 .../Composing/ComponentCollectionBuilder.cs | 0 src/Umbraco.Abstractions/Composing/Current.cs | 2 +- .../CancellableEnumerableObjectEventArgs.cs | 1 - ...ancellableObjectEventArgsOfTEventObject.cs | 0 .../Events/CopyEventArgs.cs | 0 .../Events/DeleteEventArgs.cs | 2 +- .../Events/DeleteRevisionsEventArgs.cs | 0 .../Events/EventExtensions.cs | 0 .../Events/MoveEventArgs.cs | 0 .../Events/NewEventArgs.cs | 0 .../Events/PublishEventArgs.cs | 0 .../Events/RecycleBinEventArgs.cs | 4 --- .../Events/RolesEventArgs.cs | 0 .../Events/RollbackEventArgs.cs | 0 .../Events/SaveEventArgs.cs | 0 .../Events/SendToPublishEventArgs.cs | 0 .../Events/TransientEventMessagesFactory.cs | 2 +- .../IIgnoreUserStartNodesConfig.cs | 2 +- .../Umbraco.Configuration.csproj | 31 +++++++++++++++++++ src/Umbraco.Core/ConfigsExtensions.cs | 2 +- .../Configuration/Grid/GridConfig.cs | 2 +- .../Configuration/Grid/GridEditorsConfig.cs | 4 +-- src/Umbraco.Core/Manifest/IManifestParser.cs | 23 ++++++++++++++ src/Umbraco.Core/Manifest/ManifestParser.cs | 6 ++-- .../IDataEditor.cs | 1 - .../ParameterEditorCollection.cs | 6 ++-- .../PropertyEditorCollection.cs | 6 ++-- .../Runtime/CoreInitialComposer.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 25 +++------------ .../Manifest/ManifestParserTests.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 3 +- .../ContentAppFactoryCollectionBuilder.cs | 2 +- .../Dashboards/DashboardCollectionBuilder.cs | 2 +- .../Editors/BackOfficeController.cs | 4 +-- .../JavaScript/CssInitialization.cs | 4 +-- .../JavaScript/JsInitialization.cs | 4 +-- .../Sections/SectionCollectionBuilder.cs | 2 +- src/umbraco.sln | 6 ++++ 39 files changed, 94 insertions(+), 56 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Composing/ComponentCollection.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Composing/ComponentCollectionBuilder.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/CancellableEnumerableObjectEventArgs.cs (99%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/CancellableObjectEventArgsOfTEventObject.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/CopyEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/DeleteEventArgs.cs (99%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/DeleteRevisionsEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/EventExtensions.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/MoveEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/NewEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/PublishEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/RecycleBinEventArgs.cs (95%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/RolesEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/RollbackEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/SaveEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/SendToPublishEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/TransientEventMessagesFactory.cs (81%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PropertyEditors/IIgnoreUserStartNodesConfig.cs (82%) create mode 100644 src/Umbraco.Configuration/Umbraco.Configuration.csproj create mode 100644 src/Umbraco.Core/Manifest/IManifestParser.cs rename src/Umbraco.Core/{PropertyEditors => Models}/IDataEditor.cs (99%) diff --git a/src/Umbraco.Core/Composing/ComponentCollection.cs b/src/Umbraco.Abstractions/Composing/ComponentCollection.cs similarity index 100% rename from src/Umbraco.Core/Composing/ComponentCollection.cs rename to src/Umbraco.Abstractions/Composing/ComponentCollection.cs diff --git a/src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs b/src/Umbraco.Abstractions/Composing/ComponentCollectionBuilder.cs similarity index 100% rename from src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs rename to src/Umbraco.Abstractions/Composing/ComponentCollectionBuilder.cs diff --git a/src/Umbraco.Abstractions/Composing/Current.cs b/src/Umbraco.Abstractions/Composing/Current.cs index 39a7f5c8be..9f8168f1a9 100644 --- a/src/Umbraco.Abstractions/Composing/Current.cs +++ b/src/Umbraco.Abstractions/Composing/Current.cs @@ -38,7 +38,7 @@ namespace Umbraco.Core.Composing } } - internal static bool HasFactory => _factory != null; + public static bool HasFactory => _factory != null; #region Getters diff --git a/src/Umbraco.Core/Events/CancellableEnumerableObjectEventArgs.cs b/src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs similarity index 99% rename from src/Umbraco.Core/Events/CancellableEnumerableObjectEventArgs.cs rename to src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs index 1d52d0d847..5ac77d6253 100644 --- a/src/Umbraco.Core/Events/CancellableEnumerableObjectEventArgs.cs +++ b/src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs @@ -6,7 +6,6 @@ namespace Umbraco.Core.Events { /// /// Represents event data, for events that support cancellation, and expose impacted objects. - /// /// The type of the exposed, impacted objects. public class CancellableEnumerableObjectEventArgs : CancellableObjectEventArgs>, IEquatable> { diff --git a/src/Umbraco.Core/Events/CancellableObjectEventArgsOfTEventObject.cs b/src/Umbraco.Abstractions/Events/CancellableObjectEventArgsOfTEventObject.cs similarity index 100% rename from src/Umbraco.Core/Events/CancellableObjectEventArgsOfTEventObject.cs rename to src/Umbraco.Abstractions/Events/CancellableObjectEventArgsOfTEventObject.cs diff --git a/src/Umbraco.Core/Events/CopyEventArgs.cs b/src/Umbraco.Abstractions/Events/CopyEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/CopyEventArgs.cs rename to src/Umbraco.Abstractions/Events/CopyEventArgs.cs diff --git a/src/Umbraco.Core/Events/DeleteEventArgs.cs b/src/Umbraco.Abstractions/Events/DeleteEventArgs.cs similarity index 99% rename from src/Umbraco.Core/Events/DeleteEventArgs.cs rename to src/Umbraco.Abstractions/Events/DeleteEventArgs.cs index 07bbe562db..5be669886e 100644 --- a/src/Umbraco.Core/Events/DeleteEventArgs.cs +++ b/src/Umbraco.Abstractions/Events/DeleteEventArgs.cs @@ -100,7 +100,7 @@ namespace Umbraco.Core.Events public IEnumerable DeletedEntities { get => EventObject; - internal set => EventObject = value; + set => EventObject = value; } /// diff --git a/src/Umbraco.Core/Events/DeleteRevisionsEventArgs.cs b/src/Umbraco.Abstractions/Events/DeleteRevisionsEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/DeleteRevisionsEventArgs.cs rename to src/Umbraco.Abstractions/Events/DeleteRevisionsEventArgs.cs diff --git a/src/Umbraco.Core/Events/EventExtensions.cs b/src/Umbraco.Abstractions/Events/EventExtensions.cs similarity index 100% rename from src/Umbraco.Core/Events/EventExtensions.cs rename to src/Umbraco.Abstractions/Events/EventExtensions.cs diff --git a/src/Umbraco.Core/Events/MoveEventArgs.cs b/src/Umbraco.Abstractions/Events/MoveEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/MoveEventArgs.cs rename to src/Umbraco.Abstractions/Events/MoveEventArgs.cs diff --git a/src/Umbraco.Core/Events/NewEventArgs.cs b/src/Umbraco.Abstractions/Events/NewEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/NewEventArgs.cs rename to src/Umbraco.Abstractions/Events/NewEventArgs.cs diff --git a/src/Umbraco.Core/Events/PublishEventArgs.cs b/src/Umbraco.Abstractions/Events/PublishEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/PublishEventArgs.cs rename to src/Umbraco.Abstractions/Events/PublishEventArgs.cs diff --git a/src/Umbraco.Core/Events/RecycleBinEventArgs.cs b/src/Umbraco.Abstractions/Events/RecycleBinEventArgs.cs similarity index 95% rename from src/Umbraco.Core/Events/RecycleBinEventArgs.cs rename to src/Umbraco.Abstractions/Events/RecycleBinEventArgs.cs index 796952de98..3f0f3784a2 100644 --- a/src/Umbraco.Core/Events/RecycleBinEventArgs.cs +++ b/src/Umbraco.Abstractions/Events/RecycleBinEventArgs.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using Umbraco.Core.Models; namespace Umbraco.Core.Events { diff --git a/src/Umbraco.Core/Events/RolesEventArgs.cs b/src/Umbraco.Abstractions/Events/RolesEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/RolesEventArgs.cs rename to src/Umbraco.Abstractions/Events/RolesEventArgs.cs diff --git a/src/Umbraco.Core/Events/RollbackEventArgs.cs b/src/Umbraco.Abstractions/Events/RollbackEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/RollbackEventArgs.cs rename to src/Umbraco.Abstractions/Events/RollbackEventArgs.cs diff --git a/src/Umbraco.Core/Events/SaveEventArgs.cs b/src/Umbraco.Abstractions/Events/SaveEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/SaveEventArgs.cs rename to src/Umbraco.Abstractions/Events/SaveEventArgs.cs diff --git a/src/Umbraco.Core/Events/SendToPublishEventArgs.cs b/src/Umbraco.Abstractions/Events/SendToPublishEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/SendToPublishEventArgs.cs rename to src/Umbraco.Abstractions/Events/SendToPublishEventArgs.cs diff --git a/src/Umbraco.Core/Events/TransientEventMessagesFactory.cs b/src/Umbraco.Abstractions/Events/TransientEventMessagesFactory.cs similarity index 81% rename from src/Umbraco.Core/Events/TransientEventMessagesFactory.cs rename to src/Umbraco.Abstractions/Events/TransientEventMessagesFactory.cs index bd2e12dc17..7a0947c990 100644 --- a/src/Umbraco.Core/Events/TransientEventMessagesFactory.cs +++ b/src/Umbraco.Abstractions/Events/TransientEventMessagesFactory.cs @@ -3,7 +3,7 @@ /// /// A simple/default transient messages factory /// - internal class TransientEventMessagesFactory : IEventMessagesFactory + public class TransientEventMessagesFactory : IEventMessagesFactory { public EventMessages Get() { diff --git a/src/Umbraco.Core/PropertyEditors/IIgnoreUserStartNodesConfig.cs b/src/Umbraco.Abstractions/PropertyEditors/IIgnoreUserStartNodesConfig.cs similarity index 82% rename from src/Umbraco.Core/PropertyEditors/IIgnoreUserStartNodesConfig.cs rename to src/Umbraco.Abstractions/PropertyEditors/IIgnoreUserStartNodesConfig.cs index bef3f42f46..28ce8654c3 100644 --- a/src/Umbraco.Core/PropertyEditors/IIgnoreUserStartNodesConfig.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/IIgnoreUserStartNodesConfig.cs @@ -3,7 +3,7 @@ /// /// Marker interface for any editor configuration that supports Ignoring user start nodes /// - internal interface IIgnoreUserStartNodesConfig + public interface IIgnoreUserStartNodesConfig { bool IgnoreUserStartNodes { get; set; } } diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj new file mode 100644 index 0000000000..15c6ac263f --- /dev/null +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -0,0 +1,31 @@ + + + + netstandard2.0 + + + + + + + + + + + + + + + + <_UnmanagedRegistrationCache Remove="obj\Umbraco.Configuration.csproj.UnmanagedRegistration.cache" /> + + + + + + + + + + + diff --git a/src/Umbraco.Core/ConfigsExtensions.cs b/src/Umbraco.Core/ConfigsExtensions.cs index d1672c6c7f..5699540389 100644 --- a/src/Umbraco.Core/ConfigsExtensions.cs +++ b/src/Umbraco.Core/ConfigsExtensions.cs @@ -46,7 +46,7 @@ namespace Umbraco.Core factory.GetInstance(), factory.GetInstance(), configDir, - factory.GetInstance(), + factory.GetInstance(), factory.GetInstance().Debug)); } } diff --git a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridConfig.cs index 9aead74886..9691c749df 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridConfig.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Configuration.Grid { class GridConfig : IGridConfig { - public GridConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, ManifestParser manifestParser, bool isDebug) + public GridConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, IManifestParser manifestParser, bool isDebug) { EditorsConfig = new GridEditorsConfig(logger, appCaches, configFolder, manifestParser, isDebug); } diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs index d434da8c70..cab58a6d63 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs @@ -13,10 +13,10 @@ namespace Umbraco.Core.Configuration.Grid private readonly ILogger _logger; private readonly AppCaches _appCaches; private readonly DirectoryInfo _configFolder; - private readonly ManifestParser _manifestParser; + private readonly IManifestParser _manifestParser; private readonly bool _isDebug; - public GridEditorsConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, ManifestParser manifestParser, bool isDebug) + public GridEditorsConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, IManifestParser manifestParser, bool isDebug) { _logger = logger; _appCaches = appCaches; diff --git a/src/Umbraco.Core/Manifest/IManifestParser.cs b/src/Umbraco.Core/Manifest/IManifestParser.cs new file mode 100644 index 0000000000..3641396e0a --- /dev/null +++ b/src/Umbraco.Core/Manifest/IManifestParser.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Core.Manifest +{ + public interface IManifestParser + { + string Path { get; set; } + + /// + /// Gets all manifests, merged into a single manifest object. + /// + /// + PackageManifest Manifest { get; } + + /// + /// Parses a manifest. + /// + PackageManifest ParseManifest(string text); + + IEnumerable ParseGridEditors(string text); + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index efd9e92b1f..2e55d07059 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Manifest /// /// Parses the Main.js file and replaces all tokens accordingly. /// - public class ManifestParser + public class ManifestParser : IManifestParser { private static readonly string Utf8Preamble = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); @@ -153,7 +153,7 @@ namespace Umbraco.Core.Manifest /// /// Parses a manifest. /// - internal PackageManifest ParseManifest(string text) + public PackageManifest ParseManifest(string text) { if (string.IsNullOrWhiteSpace(text)) throw new ArgumentNullOrEmptyException(nameof(text)); @@ -179,7 +179,7 @@ namespace Umbraco.Core.Manifest } // purely for tests - internal IEnumerable ParseGridEditors(string text) + public IEnumerable ParseGridEditors(string text) { return JsonConvert.DeserializeObject>(text); } diff --git a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs b/src/Umbraco.Core/Models/IDataEditor.cs similarity index 99% rename from src/Umbraco.Core/PropertyEditors/IDataEditor.cs rename to src/Umbraco.Core/Models/IDataEditor.cs index 3685cc6494..5d1aece6e5 100644 --- a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs +++ b/src/Umbraco.Core/Models/IDataEditor.cs @@ -52,7 +52,6 @@ namespace Umbraco.Core.PropertyEditors /// Gets a configured value editor. /// IDataValueEditor GetValueEditor(object configuration); - /// /// Gets the configuration for the value editor. /// diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs index 4dd4a75c22..dacda815ec 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.PropertyEditors { public class ParameterEditorCollection : BuilderCollectionBase { - public ParameterEditorCollection(DataEditorCollection dataEditors, ManifestParser manifestParser) + public ParameterEditorCollection(DataEditorCollection dataEditors, IManifestParser manifestParser) : base(dataEditors .Where(x => (x.Type & EditorType.MacroParameter) > 0) .Union(manifestParser.Manifest.PropertyEditors)) @@ -15,11 +15,11 @@ namespace Umbraco.Core.PropertyEditors // note: virtual so it can be mocked public virtual IDataEditor this[string alias] => this.SingleOrDefault(x => x.Alias == alias); - + public virtual bool TryGet(string alias, out IDataEditor editor) { editor = this.FirstOrDefault(x => x.Alias == alias); return editor != null; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs index 712a66e55d..86cfde2ee4 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.PropertyEditors { public class PropertyEditorCollection : BuilderCollectionBase { - public PropertyEditorCollection(DataEditorCollection dataEditors, ManifestParser manifestParser) + public PropertyEditorCollection(DataEditorCollection dataEditors, IManifestParser manifestParser) : base(dataEditors .Where(x => (x.Type & EditorType.PropertyValue) > 0) .Union(manifestParser.Manifest.PropertyEditors)) @@ -20,11 +20,11 @@ namespace Umbraco.Core.PropertyEditors // note: virtual so it can be mocked public virtual IDataEditor this[string alias] => this.SingleOrDefault(x => x.Alias == alias); - + public virtual bool TryGet(string alias, out IDataEditor editor) { editor = this.FirstOrDefault(x => x.Alias == alias); return editor != null; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs index 1f004846d0..7ae5211876 100644 --- a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs @@ -55,7 +55,7 @@ namespace Umbraco.Core.Runtime composition.Register(); // register manifest parser, will be injected in collection builders where needed - composition.RegisterUnique(); + composition.RegisterUnique(); // register our predefined validators composition.ManifestValueValidators() diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 25de78105f..7fd5ebd75e 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -166,8 +166,6 @@ - - @@ -178,24 +176,14 @@ - - - - - - - - - - @@ -208,6 +196,7 @@ + @@ -248,6 +237,7 @@ + @@ -288,8 +278,9 @@ + + - @@ -297,12 +288,9 @@ - - - @@ -381,8 +369,6 @@ - - @@ -551,10 +537,7 @@ - - - diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index 1c90f68d62..0a187c5a8a 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -19,7 +19,7 @@ namespace Umbraco.Tests.Manifest [TestFixture] public class ManifestParserTests { - private ManifestParser _parser; + private IManifestParser _parser; [SetUp] public void Setup() diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 2f86bddb3b..75522112b8 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -365,7 +365,8 @@ namespace Umbraco.Tests.Testing // somehow property editor ends up wanting this Composition.WithCollectionBuilder(); - Composition.RegisterUnique(); + + Composition.RegisterUnique(); // note - don't register collections, use builders Composition.WithCollectionBuilder(); diff --git a/src/Umbraco.Web/ContentApps/ContentAppFactoryCollectionBuilder.cs b/src/Umbraco.Web/ContentApps/ContentAppFactoryCollectionBuilder.cs index 170b9169ef..233a5f5ac6 100644 --- a/src/Umbraco.Web/ContentApps/ContentAppFactoryCollectionBuilder.cs +++ b/src/Umbraco.Web/ContentApps/ContentAppFactoryCollectionBuilder.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.ContentApps // get the manifest parser just-in-time - injecting it in the ctor would mean that // simply getting the builder in order to configure the collection, would require // its dependencies too, and that can create cycles or other oddities - var manifestParser = factory.GetInstance(); + var manifestParser = factory.GetInstance(); return base.CreateItems(factory).Concat(manifestParser.Manifest.ContentApps.Select(x => new ManifestContentAppFactory(x))); } diff --git a/src/Umbraco.Web/Dashboards/DashboardCollectionBuilder.cs b/src/Umbraco.Web/Dashboards/DashboardCollectionBuilder.cs index 36a417e957..d790b04d46 100644 --- a/src/Umbraco.Web/Dashboards/DashboardCollectionBuilder.cs +++ b/src/Umbraco.Web/Dashboards/DashboardCollectionBuilder.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.Dashboards // get the manifest parser just-in-time - injecting it in the ctor would mean that // simply getting the builder in order to configure the collection, would require // its dependencies too, and that can create cycles or other oddities - var manifestParser = factory.GetInstance(); + var manifestParser = factory.GetInstance(); var dashboardSections = Merge(base.CreateItems(factory), manifestParser.Manifest.Dashboards); diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index e77a1b70f2..68f234a22a 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -39,13 +39,13 @@ namespace Umbraco.Web.Editors [DisableBrowserCache] public class BackOfficeController : UmbracoController { - private readonly ManifestParser _manifestParser; + private readonly IManifestParser _manifestParser; private readonly UmbracoFeatures _features; private readonly IRuntimeState _runtimeState; private BackOfficeUserManager _userManager; private BackOfficeSignInManager _signInManager; - public BackOfficeController(ManifestParser manifestParser, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) + public BackOfficeController(IManifestParser manifestParser, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger, umbracoHelper) { _manifestParser = manifestParser; diff --git a/src/Umbraco.Web/JavaScript/CssInitialization.cs b/src/Umbraco.Web/JavaScript/CssInitialization.cs index 172244038d..8cf9067606 100644 --- a/src/Umbraco.Web/JavaScript/CssInitialization.cs +++ b/src/Umbraco.Web/JavaScript/CssInitialization.cs @@ -10,9 +10,9 @@ namespace Umbraco.Web.JavaScript { internal class CssInitialization : AssetInitialization { - private readonly ManifestParser _parser; + private readonly IManifestParser _parser; - public CssInitialization(ManifestParser parser) + public CssInitialization(IManifestParser parser) { _parser = parser; } diff --git a/src/Umbraco.Web/JavaScript/JsInitialization.cs b/src/Umbraco.Web/JavaScript/JsInitialization.cs index 17e4f7b094..6956864ea3 100644 --- a/src/Umbraco.Web/JavaScript/JsInitialization.cs +++ b/src/Umbraco.Web/JavaScript/JsInitialization.cs @@ -17,9 +17,9 @@ namespace Umbraco.Web.JavaScript /// internal class JsInitialization : AssetInitialization { - private readonly ManifestParser _parser; + private readonly IManifestParser _parser; - public JsInitialization(ManifestParser parser) + public JsInitialization(IManifestParser parser) { _parser = parser; } diff --git a/src/Umbraco.Web/Sections/SectionCollectionBuilder.cs b/src/Umbraco.Web/Sections/SectionCollectionBuilder.cs index e38da85cfa..de883db83a 100644 --- a/src/Umbraco.Web/Sections/SectionCollectionBuilder.cs +++ b/src/Umbraco.Web/Sections/SectionCollectionBuilder.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.Sections // get the manifest parser just-in-time - injecting it in the ctor would mean that // simply getting the builder in order to configure the collection, would require // its dependencies too, and that can create cycles or other oddities - var manifestParser = factory.GetInstance(); + var manifestParser = factory.GetInstance(); return base.CreateItems(factory).Concat(manifestParser.Manifest.Sections); } diff --git a/src/umbraco.sln b/src/umbraco.sln index b89daf1925..07ed63c7a3 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -111,6 +111,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.ModelsBuilder.Embed EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Infrastructure", "Umbraco.Infrastructure\Umbraco.Infrastructure.csproj", "{3AE7BF57-966B-45A5-910A-954D7C554441}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Configuration", "Umbraco.Configuration\Umbraco.Configuration.csproj", "{FBE7C065-DAC0-4025-A78B-63B24D3AB00B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -155,6 +157,10 @@ Global {3AE7BF57-966B-45A5-910A-954D7C554441}.Debug|Any CPU.Build.0 = Debug|Any CPU {3AE7BF57-966B-45A5-910A-954D7C554441}.Release|Any CPU.ActiveCfg = Release|Any CPU {3AE7BF57-966B-45A5-910A-954D7C554441}.Release|Any CPU.Build.0 = Release|Any CPU + {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From f1d85be6bb56dec1268445b0ebee0a2d91acde4d Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 14:18:06 +0100 Subject: [PATCH 04/61] Move slim entities --- .../Models/Entities/EntityExtensions.cs | 7 +++---- .../Models/Entities/IMediaEntitySlim.cs | 0 .../Models/Entities/IMemberEntitySlim.cs | 0 .../Models/Entities/MediaEntitySlim.cs | 0 .../Models/Entities/MemberEntitySlim.cs | 0 src/Umbraco.Core/Umbraco.Core.csproj | 9 ++------- 6 files changed, 5 insertions(+), 11 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/EntityExtensions.cs (86%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/IMediaEntitySlim.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/IMemberEntitySlim.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/MediaEntitySlim.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/MemberEntitySlim.cs (100%) diff --git a/src/Umbraco.Core/Models/Entities/EntityExtensions.cs b/src/Umbraco.Abstractions/Models/Entities/EntityExtensions.cs similarity index 86% rename from src/Umbraco.Core/Models/Entities/EntityExtensions.cs rename to src/Umbraco.Abstractions/Models/Entities/EntityExtensions.cs index 2ee6a2d5ed..2df08f207d 100644 --- a/src/Umbraco.Core/Models/Entities/EntityExtensions.cs +++ b/src/Umbraco.Abstractions/Models/Entities/EntityExtensions.cs @@ -2,16 +2,15 @@ namespace Umbraco.Core.Models.Entities { - internal static class EntityExtensions + public static class EntityExtensions { /// /// Updates the entity when it is being saved. /// - internal static void UpdatingEntity(this IEntity entity) + public static void UpdatingEntity(this IEntity entity) { var now = DateTime.Now; - // just in case if (entity.CreateDate == default) { entity.CreateDate = now; @@ -27,7 +26,7 @@ namespace Umbraco.Core.Models.Entities /// /// Updates the entity when it is being saved for the first time. /// - internal static void AddingEntity(this IEntity entity) + public static void AddingEntity(this IEntity entity) { var now = DateTime.Now; var canBeDirty = entity as ICanBeDirty; diff --git a/src/Umbraco.Core/Models/Entities/IMediaEntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/IMediaEntitySlim.cs similarity index 100% rename from src/Umbraco.Core/Models/Entities/IMediaEntitySlim.cs rename to src/Umbraco.Abstractions/Models/Entities/IMediaEntitySlim.cs diff --git a/src/Umbraco.Core/Models/Entities/IMemberEntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/IMemberEntitySlim.cs similarity index 100% rename from src/Umbraco.Core/Models/Entities/IMemberEntitySlim.cs rename to src/Umbraco.Abstractions/Models/Entities/IMemberEntitySlim.cs diff --git a/src/Umbraco.Core/Models/Entities/MediaEntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/MediaEntitySlim.cs similarity index 100% rename from src/Umbraco.Core/Models/Entities/MediaEntitySlim.cs rename to src/Umbraco.Abstractions/Models/Entities/MediaEntitySlim.cs diff --git a/src/Umbraco.Core/Models/Entities/MemberEntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/MemberEntitySlim.cs similarity index 100% rename from src/Umbraco.Core/Models/Entities/MemberEntitySlim.cs rename to src/Umbraco.Abstractions/Models/Entities/MemberEntitySlim.cs diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 7fd5ebd75e..bb2ad5dec4 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -220,7 +220,6 @@ - @@ -258,10 +257,6 @@ - - - - @@ -274,10 +269,10 @@ - - + + From c6157b8765483bda4a7284f2938af2bcca5a00da Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 15:37:03 +0100 Subject: [PATCH 05/61] Move Configs to abstractions, and injected factory all over to create one because we need to inject stuff from system.configuration --- src/Umbraco.Abstractions/Composing/Current.cs | 2 ++ .../RegisterExtensions.cs | 0 src/Umbraco.Core/Composing/Composition.cs | 9 +----- src/Umbraco.Core/Composing/ConfigsFactory.cs | 14 +++++++++ src/Umbraco.Core/Composing/Current.cs | 4 +-- src/Umbraco.Core/Composing/IConfigsFactory.cs | 9 ++++++ src/Umbraco.Core/Runtime/CoreRuntime.cs | 5 ++-- src/Umbraco.Core/Umbraco.Core.csproj | 6 ++-- .../DistributedCache/DistributedCacheTests.cs | 2 +- .../Components/ComponentTests.cs | 30 ++++++++++--------- .../Composing/CollectionBuildersTests.cs | 2 +- .../Composing/CompositionTests.cs | 2 +- .../Composing/LazyCollectionBuilderTests.cs | 10 +++---- .../Composing/PackageActionCollectionTests.cs | 4 +-- src/Umbraco.Tests/IO/FileSystemsTests.cs | 2 +- src/Umbraco.Tests/Macros/MacroTests.cs | 2 +- src/Umbraco.Tests/Models/MacroTests.cs | 2 +- src/Umbraco.Tests/Models/MemberTests.cs | 2 +- src/Umbraco.Tests/Models/UserTests.cs | 2 +- src/Umbraco.Tests/Models/VariationTests.cs | 8 ++--- .../PropertyEditors/ImageCropperTest.cs | 2 +- .../PropertyEditorValueEditorTests.cs | 2 +- .../Published/ConvertersTests.cs | 2 +- .../PublishedContent/NuCacheChildrenTests.cs | 12 ++++---- .../PublishedContent/NuCacheTests.cs | 2 +- .../Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 6 ++-- .../Scoping/ScopeEventDispatcherTests.cs | 2 +- .../TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- 30 files changed, 87 insertions(+), 64 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/RegisterExtensions.cs (100%) create mode 100644 src/Umbraco.Core/Composing/ConfigsFactory.cs create mode 100644 src/Umbraco.Core/Composing/IConfigsFactory.cs diff --git a/src/Umbraco.Abstractions/Composing/Current.cs b/src/Umbraco.Abstractions/Composing/Current.cs index 9f8168f1a9..a1ae87d49f 100644 --- a/src/Umbraco.Abstractions/Composing/Current.cs +++ b/src/Umbraco.Abstractions/Composing/Current.cs @@ -1,5 +1,6 @@ using System; using Umbraco.Core.Logging; +using Umbraco.Core.Strings; namespace Umbraco.Core.Composing { @@ -42,6 +43,7 @@ namespace Umbraco.Core.Composing #region Getters + public static ILogger Logger => _logger ?? (_logger = _factory?.TryGetInstance() ?? throw new Exception("TODO Fix")); //?? new DebugDiagnosticsLogger(new MessageTemplates())); diff --git a/src/Umbraco.Core/RegisterExtensions.cs b/src/Umbraco.Abstractions/RegisterExtensions.cs similarity index 100% rename from src/Umbraco.Core/RegisterExtensions.cs rename to src/Umbraco.Abstractions/RegisterExtensions.cs diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Core/Composing/Composition.cs index 34c5296dce..7ff8901fc1 100644 --- a/src/Umbraco.Core/Composing/Composition.cs +++ b/src/Umbraco.Core/Composing/Composition.cs @@ -27,19 +27,12 @@ namespace Umbraco.Core.Composing /// A logger. /// The runtime state. /// Optional configs. - public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs = null) + public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs) { _register = register; TypeLoader = typeLoader; Logger = logger; RuntimeState = runtimeState; - - if (configs == null) - { - configs = new Configs(); - configs.AddCoreConfigs(); - } - Configs = configs; } diff --git a/src/Umbraco.Core/Composing/ConfigsFactory.cs b/src/Umbraco.Core/Composing/ConfigsFactory.cs new file mode 100644 index 0000000000..995ab4e3aa --- /dev/null +++ b/src/Umbraco.Core/Composing/ConfigsFactory.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using Umbraco.Core.Configuration; + +namespace Umbraco.Core.Composing +{ + public class ConfigsFactory : IConfigsFactory + { + public Configs Create() { + var configs = new Configs(section => ConfigurationManager.GetSection(section)); + configs.AddCoreConfigs(); + return configs; + } + } +} diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index ed64347816..01fcbaa9e8 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -93,11 +93,11 @@ namespace Umbraco.Core.Composing /// Unlocks so that it is possible to add configurations /// directly to without having to wire composition. /// - public static void UnlockConfigs() + public static void UnlockConfigs(IConfigsFactory configsFactory) { if (_factory != null) throw new InvalidOperationException("Cannot unlock configs when a factory has been set."); - _configs = new Configs(); + _configs = configsFactory.Create(); } internal static event EventHandler Resetted; diff --git a/src/Umbraco.Core/Composing/IConfigsFactory.cs b/src/Umbraco.Core/Composing/IConfigsFactory.cs new file mode 100644 index 0000000000..1b12f5e157 --- /dev/null +++ b/src/Umbraco.Core/Composing/IConfigsFactory.cs @@ -0,0 +1,9 @@ +using Umbraco.Core.Configuration; + +namespace Umbraco.Core.Composing +{ + public interface IConfigsFactory + { + Configs Create(); + } +} diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 5b069641c4..d9c8ff05d3 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Diagnostics; using System.Web; using System.Web.Hosting; @@ -345,8 +346,8 @@ namespace Umbraco.Core.Runtime /// protected virtual Configs GetConfigs() { - var configs = new Configs(); - configs.AddCoreConfigs(); + var configs = new ConfigsFactory().Create(); + return configs; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index bb2ad5dec4..f40f81ef71 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -158,7 +158,9 @@ + + @@ -254,6 +256,7 @@ + @@ -316,7 +319,6 @@ - @@ -361,7 +363,6 @@ - @@ -596,7 +597,6 @@ - diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index 650cc64720..54318ace15 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -25,7 +25,7 @@ namespace Umbraco.Tests.Cache.DistributedCache { var register = RegisterFactory.Create(); - var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.RegisterUnique(_ => new TestServerRegistrar()); composition.RegisterUnique(_ => new TestServerMessenger()); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 2ba94d8c78..73fc4bb4af 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Compose; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; @@ -23,6 +24,7 @@ namespace Umbraco.Tests.Components private static readonly List Composed = new List(); private static readonly List Initialized = new List(); private static readonly List Terminated = new List(); + private static readonly Configs Configs = new ConfigsFactory().Create(); private static IFactory MockFactory(Action> setup = null) { @@ -65,7 +67,7 @@ namespace Umbraco.Tests.Components public void Boot1A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -104,7 +106,7 @@ namespace Umbraco.Tests.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -120,7 +122,7 @@ namespace Umbraco.Tests.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -135,7 +137,7 @@ namespace Umbraco.Tests.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -152,7 +154,7 @@ namespace Umbraco.Tests.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -175,7 +177,7 @@ namespace Umbraco.Tests.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -210,7 +212,7 @@ namespace Umbraco.Tests.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Mock.Of()); @@ -236,7 +238,7 @@ namespace Umbraco.Tests.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Mock.Of()); @@ -251,7 +253,7 @@ namespace Umbraco.Tests.Components public void Requires2A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Mock.Of()); @@ -268,7 +270,7 @@ namespace Umbraco.Tests.Components { var register = MockRegister(); var factory = MockFactory(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), Configs); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Mock.Of()); @@ -287,7 +289,7 @@ namespace Umbraco.Tests.Components public void WeakDependencies() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); var types = new[] { typeof(Composer10) }; var composers = new Composers(composition, types, Mock.Of()); @@ -326,7 +328,7 @@ namespace Umbraco.Tests.Components public void DisableMissing() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); var types = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list var composers = new Composers(composition, types, Mock.Of()); @@ -341,7 +343,7 @@ namespace Umbraco.Tests.Components public void AttributesPriorities() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); var types = new[] { typeof(Composer26) }; // 26 disabled by assembly attribute var composers = new Composers(composition, types, Mock.Of()); @@ -364,7 +366,7 @@ namespace Umbraco.Tests.Components var typeLoader = new TypeLoader(AppCaches.Disabled.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), Mock.Of()); var register = MockRegister(); - var composition = new Composition(register, typeLoader, Mock.Of(), MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, typeLoader, Mock.Of(), MockRuntimeState(RuntimeLevel.Run), Configs); var types = typeLoader.GetTypes().Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web")); var composers = new Composers(composition, types, Mock.Of()); diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index ec757e09f0..4303f59916 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Composing Current.Reset(); var register = RegisterFactory.Create(); - _composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + _composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); } [TearDown] diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index 33855a8bfb..72f7e99ca6 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -37,7 +37,7 @@ namespace Umbraco.Tests.Composing var logger = new ProfilingLogger(Mock.Of(), Mock.Of()); var typeLoader = new TypeLoader(Mock.Of(), IOHelper.MapPath("~/App_Data/TEMP"), logger); - var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of()); + var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), new ConfigsFactory().Create()); // create the factory, ensure it is the mocked factory var factory = composition.CreateFactory(); diff --git a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs index 3996eba89f..69e8524b7c 100644 --- a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs @@ -40,7 +40,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypes() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add() @@ -66,7 +66,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesProducers() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add(() => new[] { typeof(TransientObject3), typeof(TransientObject2) }) @@ -91,7 +91,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypesAndProducers() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add() @@ -117,7 +117,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderThrowsOnIllegalTypes() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add() @@ -139,7 +139,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderCanExcludeTypes() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add() diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index 07db4be3d3..57f691eea5 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -19,8 +19,8 @@ namespace Umbraco.Tests.Composing public void PackageActionCollectionBuilderWorks() { var container = RegisterFactory.Create(); - - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add(() => TypeLoader.GetPackageActions()); diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index b21faec586..28c1817862 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -28,7 +28,7 @@ namespace Umbraco.Tests.IO { _register = RegisterFactory.Create(); - var composition = new Composition(_register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(_register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.Register(_ => Mock.Of()); composition.Register(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index 9cc1d14954..4700edc64b 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.Macros //Current.ApplicationContext = new ApplicationContext(cacheHelper, new ProfilingLogger(Mock.Of(), Mock.Of())); Current.Reset(); - Current.UnlockConfigs(); + Current.UnlockConfigs(new ConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/MacroTests.cs b/src/Umbraco.Tests/Models/MacroTests.cs index d980cd1d58..117301815e 100644 --- a/src/Umbraco.Tests/Models/MacroTests.cs +++ b/src/Umbraco.Tests/Models/MacroTests.cs @@ -15,7 +15,7 @@ namespace Umbraco.Tests.Models public void Init() { Current.Reset(); - Current.UnlockConfigs(); + Current.UnlockConfigs(new ConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/MemberTests.cs b/src/Umbraco.Tests/Models/MemberTests.cs index 5e92ad7ccf..9b478304d1 100644 --- a/src/Umbraco.Tests/Models/MemberTests.cs +++ b/src/Umbraco.Tests/Models/MemberTests.cs @@ -17,7 +17,7 @@ namespace Umbraco.Tests.Models public void Setup() { Current.Reset(); - Current.UnlockConfigs(); + Current.UnlockConfigs(new ConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index 797b79381a..8cc66d5eb0 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -16,7 +16,7 @@ namespace Umbraco.Tests.Models public void Setup() { Current.Reset(); - Current.UnlockConfigs(); + Current.UnlockConfigs(new ConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); } diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index ab5f726894..ce78287d6d 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Models Current.Reset(); - var configs = new Configs(); + var configs = new ConfigsFactory().Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); @@ -75,7 +75,7 @@ namespace Umbraco.Tests.Models // 1. if exact is set to true: culture cannot be null when the ContentVariation.Culture flag is set // 2. if wildcards is set to false: fail when "*" is passed in as either culture or segment. // 3. ContentVariation flag is ignored when wildcards are used. - // 4. Empty string is considered the same as null + // 4. Empty string is considered the same as null #region Nothing @@ -141,7 +141,7 @@ namespace Umbraco.Tests.Models #endregion #region CultureAndSegment - + Assert4B(ContentVariation.CultureAndSegment, null, null, false, true, false, true); Assert4B(ContentVariation.CultureAndSegment, null, "", false, true, false, true); Assert4B(ContentVariation.CultureAndSegment, null, "*", false, false, false, true); @@ -163,7 +163,7 @@ namespace Umbraco.Tests.Models } /// - /// Asserts the result of + /// Asserts the result of /// /// /// diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index 8d2ab84d35..dcf225d952 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -70,7 +70,7 @@ namespace Umbraco.Tests.PropertyEditors try { var container = RegisterFactory.Create(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder(); diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 764f6ac4a4..348305fbf5 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -24,7 +24,7 @@ namespace Umbraco.Tests.PropertyEditors Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; var register = RegisterFactory.Create(); - var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); register.Register(_ => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings()))); diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index 671129848c..f3dd459ba3 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -178,7 +178,7 @@ namespace Umbraco.Tests.Published Current.Reset(); var register = RegisterFactory.Create(); - var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Append() diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index 5d32606ee7..f08d77a80f 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -54,7 +54,7 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = new Configs(); + var configs = new ConfigsFactory().Create(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); var globalSettings = new GlobalSettings(); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); @@ -1114,7 +1114,7 @@ namespace Umbraco.Tests.PublishedContent _snapshotService.Notify(new[] { - new ContentCacheRefresher.JsonPayload(1, Guid.Empty, TreeChangeTypes.RefreshNode) + new ContentCacheRefresher.JsonPayload(1, Guid.Empty, TreeChangeTypes.RefreshNode) }, out _, out _); Assert.AreEqual(2, contentStore.Test.LiveGen); @@ -1134,7 +1134,7 @@ namespace Umbraco.Tests.PublishedContent /// 2) Save and publish it /// 3) Publish it with descendants /// 4) Repeat steps 2 and 3 - /// + /// /// Which has caused an exception. To replicate this test: /// 1) RefreshBranch with kits for a branch where the top most node is unpublished /// 2) RefreshBranch with kits for the branch where the top most node is published @@ -1162,7 +1162,7 @@ namespace Umbraco.Tests.PublishedContent //children of 1 yield return CreateInvariantKit(20, 1, 1, paths); - yield return CreateInvariantKit(30, 1, 2, paths); + yield return CreateInvariantKit(30, 1, 2, paths); yield return CreateInvariantKit(40, 1, 3, paths); } @@ -1199,12 +1199,12 @@ namespace Umbraco.Tests.PublishedContent var (gen, contentNode) = contentStore.Test.GetValues(1)[0]; Assert.AreEqual(assertGen, gen); //even when unpublishing/re-publishing/etc... the linked list is always maintained - AssertLinkedNode(contentNode, 100, 2, 3, 20, 40); + AssertLinkedNode(contentNode, 100, 2, 3, 20, 40); } //unpublish the root ChangePublishFlagOfRoot(false, 2, TreeChangeTypes.RefreshBranch); - + //publish the root (since it's not published, it will cause a RefreshBranch) ChangePublishFlagOfRoot(true, 3, TreeChangeTypes.RefreshBranch); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 0e05e6baad..7dba201b0a 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -49,7 +49,7 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = new Configs(); + var configs = new ConfigsFactory().Create(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); var globalSettings = new GlobalSettings(); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 7cf3c008f1..449cddfcc6 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -104,7 +104,7 @@ namespace Umbraco.Tests.Runtimes protected override Configs GetConfigs() { - var configs = new Configs(); + var configs = new ConfigsFactory().Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); return configs; diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index fdeb743b6c..60e86ad5b0 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -64,10 +64,11 @@ namespace Umbraco.Tests.Runtimes var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var mainDom = new SimpleMainDom(); var runtimeState = new RuntimeState(logger, null, null, new Lazy(() => mainDom), new Lazy(() => factory.GetInstance())); + var configs = new ConfigsFactory().Create(); // create the register and the composition var register = RegisterFactory.Create(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState); // create the core runtime and have it compose itself @@ -254,10 +255,11 @@ namespace Umbraco.Tests.Runtimes Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run); var mainDom = Mock.Of(); Mock.Get(mainDom).Setup(x => x.IsMainDom).Returns(true); + var configs = new ConfigsFactory().Create(); // create the register and the composition var register = RegisterFactory.Create(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState); // create the core runtime and have it compose itself diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index 001553a8ae..b964f89be8 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Tests.Scoping var register = RegisterFactory.Create(); - var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); _testObjects = new TestObjects(register); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index f62effcb62..a042803639 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -42,7 +42,7 @@ namespace Umbraco.Tests.TestHelpers logger, false); - var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.RegisterUnique(_ => Mock.Of()); composition.RegisterUnique(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 75522112b8..5e21f5de63 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -134,7 +134,7 @@ namespace Umbraco.Tests.Testing var register = RegisterFactory.Create(); - Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); Composition.RegisterUnique(typeLoader); Composition.RegisterUnique(logger); From 70aefc4ede4d29f301048b4df6f62e18f0be624a Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 08:00:48 +0100 Subject: [PATCH 06/61] Move Configs to abstractions --- .../Configuration/Configs.cs | 20 ++++++++++++------- .../Configuration}/IConfigsFactory.cs | 4 +--- src/Umbraco.Abstractions/Services/IRuntime.cs | 3 ++- .../ConfigsFactory.cs | 3 +-- src/Umbraco.Core/Configuration/CoreDebug.cs | 3 ++- src/Umbraco.Core/Runtime/CoreRuntime.cs | 12 +++++------ src/Umbraco.Core/Umbraco.Core.csproj | 3 +-- .../DistributedCache/DistributedCacheTests.cs | 1 + .../Composing/CollectionBuildersTests.cs | 1 + .../Composing/CompositionTests.cs | 1 + .../Composing/PackageActionCollectionTests.cs | 1 + src/Umbraco.Tests/IO/FileSystemsTests.cs | 1 + src/Umbraco.Tests/Macros/MacroTests.cs | 1 + src/Umbraco.Tests/Models/MacroTests.cs | 1 + src/Umbraco.Tests/Models/MemberTests.cs | 1 + src/Umbraco.Tests/Models/UserTests.cs | 1 + .../PropertyEditorValueEditorTests.cs | 1 + .../Published/ConvertersTests.cs | 1 + .../Runtimes/CoreRuntimeTests.cs | 8 ++++---- .../Scoping/ScopeEventDispatcherTests.cs | 1 + src/Umbraco.Web/Runtime/WebRuntime.cs | 4 ++-- src/Umbraco.Web/UmbracoApplicationBase.cs | 3 ++- 22 files changed, 46 insertions(+), 29 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Configuration/Configs.cs (83%) rename src/{Umbraco.Core/Composing => Umbraco.Abstractions/Configuration}/IConfigsFactory.cs (53%) rename src/Umbraco.Core/{Composing => Configuration}/ConfigsFactory.cs (81%) diff --git a/src/Umbraco.Core/Configuration/Configs.cs b/src/Umbraco.Abstractions/Configuration/Configs.cs similarity index 83% rename from src/Umbraco.Core/Configuration/Configs.cs rename to src/Umbraco.Abstractions/Configuration/Configs.cs index 51e1a327a0..e08c4097e4 100644 --- a/src/Umbraco.Core/Configuration/Configs.cs +++ b/src/Umbraco.Abstractions/Configuration/Configs.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Configuration; using Umbraco.Core.Composing; -using Umbraco.Core.Logging; namespace Umbraco.Core.Configuration { @@ -15,6 +13,13 @@ namespace Umbraco.Core.Configuration /// public class Configs { + private readonly Func _configGetter; + + public Configs(Func configGetter) + { + _configGetter = configGetter; + } + private readonly Dictionary> _configs = new Dictionary>(); private Dictionary> _registerings = new Dictionary>(); @@ -60,7 +65,7 @@ namespace Umbraco.Core.Configuration _configs[typeOfConfig] = new Lazy(() => { - if (Current.HasFactory) return Current.Factory.GetInstance(); + if (CurrentCore.HasFactory) return CurrentCore.Factory.GetInstance(); throw new InvalidOperationException($"Cannot get configuration of type {typeOfConfig} during composition."); }); _registerings[typeOfConfig] = register => register.Register(configFactory, Lifetime.Singleton); @@ -75,7 +80,7 @@ namespace Umbraco.Core.Configuration Add(() => GetConfig(sectionName)); } - private static TConfig GetConfig(string sectionName) + private TConfig GetConfig(string sectionName) where TConfig : class { // note: need to use SafeCallContext here because ConfigurationManager.GetSection ends up getting AppDomain.Evidence @@ -83,10 +88,11 @@ namespace Umbraco.Core.Configuration using (new SafeCallContext()) { - if ((ConfigurationManager.GetSection(sectionName) is TConfig config)) + if ((_configGetter(sectionName) is TConfig config)) return config; - var ex = new ConfigurationErrorsException($"Could not get configuration section \"{sectionName}\" from config files."); - Current.Logger.Error(ex, "Config error"); +// var ex = new ConfigurationErrorsException($"Could not get configuration section \"{sectionName}\" from config files."); + var ex = new Exception($"Could not get configuration section \"{sectionName}\" from config files."); +// Current.Logger.Error(ex, "Config error"); throw ex; } } diff --git a/src/Umbraco.Core/Composing/IConfigsFactory.cs b/src/Umbraco.Abstractions/Configuration/IConfigsFactory.cs similarity index 53% rename from src/Umbraco.Core/Composing/IConfigsFactory.cs rename to src/Umbraco.Abstractions/Configuration/IConfigsFactory.cs index 1b12f5e157..3e36f3fb55 100644 --- a/src/Umbraco.Core/Composing/IConfigsFactory.cs +++ b/src/Umbraco.Abstractions/Configuration/IConfigsFactory.cs @@ -1,6 +1,4 @@ -using Umbraco.Core.Configuration; - -namespace Umbraco.Core.Composing +namespace Umbraco.Core.Configuration { public interface IConfigsFactory { diff --git a/src/Umbraco.Abstractions/Services/IRuntime.cs b/src/Umbraco.Abstractions/Services/IRuntime.cs index d433dde12d..a7944ad256 100644 --- a/src/Umbraco.Abstractions/Services/IRuntime.cs +++ b/src/Umbraco.Abstractions/Services/IRuntime.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; namespace Umbraco.Core { @@ -12,7 +13,7 @@ namespace Umbraco.Core /// /// The application register. /// The application factory. - IFactory Boot(IRegister register); + IFactory Boot(IRegister register, IConfigsFactory configsFactory); /// /// Gets the runtime state. diff --git a/src/Umbraco.Core/Composing/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs similarity index 81% rename from src/Umbraco.Core/Composing/ConfigsFactory.cs rename to src/Umbraco.Core/Configuration/ConfigsFactory.cs index 995ab4e3aa..aeeef1e653 100644 --- a/src/Umbraco.Core/Composing/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -1,7 +1,6 @@ using System.Configuration; -using Umbraco.Core.Configuration; -namespace Umbraco.Core.Composing +namespace Umbraco.Core.Configuration { public class ConfigsFactory : IConfigsFactory { diff --git a/src/Umbraco.Core/Configuration/CoreDebug.cs b/src/Umbraco.Core/Configuration/CoreDebug.cs index b24e8a3329..aa95a25990 100644 --- a/src/Umbraco.Core/Configuration/CoreDebug.cs +++ b/src/Umbraco.Core/Configuration/CoreDebug.cs @@ -1,4 +1,5 @@ using System; +using System.Configuration; namespace Umbraco.Core.Configuration { @@ -6,7 +7,7 @@ namespace Umbraco.Core.Configuration { public CoreDebug() { - var appSettings = System.Configuration.ConfigurationManager.AppSettings; + var appSettings = ConfigurationManager.AppSettings; LogUncompletedScopes = string.Equals("true", appSettings[Constants.AppSettings.Debug.LogUncompletedScopes], StringComparison.OrdinalIgnoreCase); DumpOnTimeoutThreadAbort = string.Equals("true", appSettings[Constants.AppSettings.Debug.DumpOnTimeoutThreadAbort], StringComparison.OrdinalIgnoreCase); } diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index d9c8ff05d3..237dcece64 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -47,7 +47,7 @@ namespace Umbraco.Core.Runtime public IRuntimeState State => _state; /// - public virtual IFactory Boot(IRegister register) + public virtual IFactory Boot(IRegister register, IConfigsFactory configsFactory) { // create and register the essential services // ie the bare minimum required to boot @@ -82,7 +82,7 @@ namespace Umbraco.Core.Runtime ConfigureUnhandledException(); ConfigureApplicationRootPath(); - Boot(register, timer); + Boot(register, timer, configsFactory); } return _factory; @@ -91,7 +91,7 @@ namespace Umbraco.Core.Runtime /// /// Boots the runtime within a timer. /// - protected virtual IFactory Boot(IRegister register, DisposableTimer timer) + protected virtual IFactory Boot(IRegister register, DisposableTimer timer, IConfigsFactory configsFactory) { Composition composition = null; @@ -110,7 +110,7 @@ namespace Umbraco.Core.Runtime var databaseFactory = GetDatabaseFactory(); // configs - var configs = GetConfigs(); + var configs = GetConfigs(configsFactory); // type loader var typeLoader = new TypeLoader(appCaches.RuntimeCache, configs.Global().LocalTempPath, ProfilingLogger); @@ -344,9 +344,9 @@ namespace Umbraco.Core.Runtime /// /// Gets the configurations. /// - protected virtual Configs GetConfigs() + protected virtual Configs GetConfigs(IConfigsFactory configsFactory) { - var configs = new ConfigsFactory().Create(); + var configs = configsFactory.Create(); return configs; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index f40f81ef71..5755532cd6 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -158,9 +158,7 @@ - - @@ -176,6 +174,7 @@ + diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index 54318ace15..b752cb6a90 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Sync; using Umbraco.Tests.Components; diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index 4303f59916..25d46a3cdc 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -5,6 +5,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Tests.Components; diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index 72f7e99ca6..06c9c0b786 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index 57f691eea5..0073a4d624 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -6,6 +6,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.PackageActions; using Umbraco.Tests.Components; diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 28c1817862..2a32a1bc27 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Services; using Umbraco.Tests.Components; using Umbraco.Tests.TestHelpers; using Umbraco.Core.Composing.CompositionExtensions; +using Umbraco.Core.Configuration; using FileSystems = Umbraco.Core.IO.FileSystems; namespace Umbraco.Tests.IO diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index 4700edc64b..e813424ad6 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -2,6 +2,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Macros; diff --git a/src/Umbraco.Tests/Models/MacroTests.cs b/src/Umbraco.Tests/Models/MacroTests.cs index 117301815e..e96a8c7915 100644 --- a/src/Umbraco.Tests/Models/MacroTests.cs +++ b/src/Umbraco.Tests/Models/MacroTests.cs @@ -2,6 +2,7 @@ using System.Linq; using NUnit.Framework; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Tests.TestHelpers; diff --git a/src/Umbraco.Tests/Models/MemberTests.cs b/src/Umbraco.Tests/Models/MemberTests.cs index 9b478304d1..666b9a8ab1 100644 --- a/src/Umbraco.Tests/Models/MemberTests.cs +++ b/src/Umbraco.Tests/Models/MemberTests.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Linq; using NUnit.Framework; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Serialization; using Umbraco.Tests.TestHelpers; diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index 8cc66d5eb0..b8151fc944 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Linq; using NUnit.Framework; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models.Membership; using Umbraco.Core.Serialization; using Umbraco.Tests.TestHelpers; diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 348305fbf5..c1b80b97b1 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -4,6 +4,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index f3dd459ba3..01e14edf12 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -5,6 +5,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 449cddfcc6..daf4f4afe6 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -102,9 +102,9 @@ namespace Umbraco.Tests.Runtimes return mock.Object; } - protected override Configs GetConfigs() + protected override Configs GetConfigs(IConfigsFactory configsFactory) { - var configs = new ConfigsFactory().Create(); + var configs = configsFactory.Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); return configs; @@ -142,9 +142,9 @@ namespace Umbraco.Tests.Runtimes private IMainDom _mainDom; - public override IFactory Boot(IRegister container) + public override IFactory Boot(IRegister container, IConfigsFactory configsFactory) { - var factory = base.Boot(container); + var factory = base.Boot(container, configsFactory); _mainDom = factory.GetInstance(); return factory; } diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index b964f89be8..1597ef35cc 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Scoping; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Services; using Umbraco.Tests.Components; diff --git a/src/Umbraco.Web/Runtime/WebRuntime.cs b/src/Umbraco.Web/Runtime/WebRuntime.cs index 13cd717fd1..ede500e599 100644 --- a/src/Umbraco.Web/Runtime/WebRuntime.cs +++ b/src/Umbraco.Web/Runtime/WebRuntime.cs @@ -27,7 +27,7 @@ namespace Umbraco.Web.Runtime } /// - public override IFactory Boot(IRegister register) + public override IFactory Boot(IRegister register, IConfigsFactory configsFactory) { // create and start asap to profile boot var debug = GlobalSettings.DebugMode; @@ -43,7 +43,7 @@ namespace Umbraco.Web.Runtime _webProfiler = new VoidProfiler(); } - var factory = base.Boot(register); + var factory = base.Boot(register, configsFactory); // now (and only now) is the time to switch over to perWebRequest scopes. // up until that point we may not have a request, and scoped services would diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 59b5b1779b..24800500a8 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -5,6 +5,7 @@ using System.Web; using System.Web.Hosting; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; @@ -62,7 +63,7 @@ namespace Umbraco.Web // the boot manager is responsible for registrations var register = GetRegister(); _runtime = GetRuntime(); - _runtime.Boot(register); + _runtime.Boot(register, new ConfigsFactory()); } // called by ASP.NET (auto event wireup) once per app domain From 7a0dc23867038a8dde5150edbddff75a2b5c4671 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 10:08:16 +0100 Subject: [PATCH 07/61] Move some of the config to Umbraco.Configuration --- build/NuSpecs/tools/Web.config.install.xdt | 4 +- .../Properties/AssemblyInfo.cs | 35 +++++++++++ .../Umbraco.Abstractions.csproj | 4 ++ .../CaseInsensitiveEnumConfigConverter.cs | 0 .../CommaDelimitedConfigurationElement.cs | 2 +- .../DisabledHealthCheckElement.cs | 0 .../DisabledHealthChecksElementCollection.cs | 0 .../HealthCheckNotificationSettingsElement.cs | 0 .../HealthCheckNotificationVerbosity.cs | 0 .../HealthChecks/HealthChecksSection.cs | 0 .../HealthChecks/IDisabledHealthCheck.cs | 0 .../IHealthCheckNotificationSettings.cs | 0 .../HealthChecks/IHealthChecks.cs | 0 .../HealthChecks/INotificationMethod.cs | 0 .../INotificationMethodSettings.cs | 0 .../HealthChecks/NotificationMethodElement.cs | 0 .../NotificationMethodSettingsElement.cs | 0 ...ficationMethodSettingsElementCollection.cs | 0 .../NotificationMethodsElementCollection.cs | 0 ...ionalCommaDelimitedConfigurationElement.cs | 2 +- .../OptionalInnerTextConfigurationElement.cs | 2 +- .../Properties/AssemblyInfo.cs | 10 ++++ .../RawXmlConfigurationElement.cs | 2 +- .../Umbraco.Configuration.csproj | 8 +++ .../UmbracoConfigurationSection.cs | 0 .../UmbracoSettings/BackOfficeElement.cs | 2 +- .../UmbracoSettings/CharCollection.cs | 2 +- .../UmbracoSettings/CharElement.cs | 2 +- .../UmbracoSettings/ContentElement.cs | 4 +- .../ContentError404Collection.cs | 2 +- .../ContentErrorPageElement.cs | 2 +- .../UmbracoSettings/ContentErrorsElement.cs | 2 +- .../ContentSectionExtensions.cs | 0 .../ImagingAutoFillPropertiesCollection.cs | 2 +- .../ImagingAutoFillUploadFieldElement.cs | 2 +- .../UmbracoSettings/LoggingElement.cs | 2 +- .../UmbracoSettings/NotificationsElement.cs | 2 +- .../UmbracoSettings/SecurityElement.cs | 2 +- .../UmbracoSettings/TourConfigElement.cs | 2 +- .../UmbracoConfigurationElement.cs | 2 +- .../UmbracoSettings/UmbracoSettingsSection.cs | 12 ++-- .../UmbracoSettings/UrlReplacingElement.cs | 2 +- .../UmbracoSettings/WebRoutingElement.cs | 2 +- .../UmbracoVersion.cs | 2 +- .../Configuration/ConfigsExtensions.cs | 34 +++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 60 ++++--------------- .../Configurations/UmbracoSettings/web.config | 8 +-- src/Umbraco.Tests/Umbraco.Tests.csproj | 5 ++ src/Umbraco.Web.UI/web.Template.config | 4 +- src/Umbraco.Web/Umbraco.Web.csproj | 4 ++ 50 files changed, 146 insertions(+), 86 deletions(-) create mode 100644 src/Umbraco.Abstractions/Properties/AssemblyInfo.cs rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/CaseInsensitiveEnumConfigConverter.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/CommaDelimitedConfigurationElement.cs (93%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/DisabledHealthCheckElement.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/DisabledHealthChecksElementCollection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/HealthCheckNotificationSettingsElement.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/HealthCheckNotificationVerbosity.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/HealthChecksSection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/IDisabledHealthCheck.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/IHealthCheckNotificationSettings.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/IHealthChecks.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/INotificationMethod.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/INotificationMethodSettings.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/NotificationMethodElement.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/NotificationMethodSettingsElement.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/NotificationMethodSettingsElementCollection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/NotificationMethodsElementCollection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/OptionalCommaDelimitedConfigurationElement.cs (92%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/OptionalInnerTextConfigurationElement.cs (88%) create mode 100644 src/Umbraco.Configuration/Properties/AssemblyInfo.cs rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/RawXmlConfigurationElement.cs (90%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoConfigurationSection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/BackOfficeElement.cs (76%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/CharCollection.cs (90%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/CharElement.cs (87%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentElement.cs (98%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentError404Collection.cs (89%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentErrorPageElement.cs (92%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentErrorsElement.cs (95%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentSectionExtensions.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs (88%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs (93%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/LoggingElement.cs (80%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/NotificationsElement.cs (86%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/SecurityElement.cs (97%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/TourConfigElement.cs (85%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/UmbracoConfigurationElement.cs (95%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/UmbracoSettingsSection.cs (64%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/UrlReplacingElement.cs (92%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/WebRoutingElement.cs (94%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoVersion.cs (98%) create mode 100644 src/Umbraco.Core/Configuration/ConfigsExtensions.cs diff --git a/build/NuSpecs/tools/Web.config.install.xdt b/build/NuSpecs/tools/Web.config.install.xdt index 2b79f95c70..f118fa8c3a 100644 --- a/build/NuSpecs/tools/Web.config.install.xdt +++ b/build/NuSpecs/tools/Web.config.install.xdt @@ -5,9 +5,9 @@ -
+
-
+
diff --git a/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs b/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..6d5520f975 --- /dev/null +++ b/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: ComVisible(false)] +[assembly: Guid("DA322714-FB89-4943-92BD-BB122B82F66B")] + +// Umbraco Cms +[assembly: InternalsVisibleTo("Umbraco.Web")] +[assembly: InternalsVisibleTo("Umbraco.Web.UI")] +[assembly: InternalsVisibleTo("Umbraco.Examine")] +[assembly: InternalsVisibleTo("Umbraco.ModelsBuilder.Embedded")] + +[assembly: InternalsVisibleTo("Umbraco.Tests")] +[assembly: InternalsVisibleTo("Umbraco.Tests.Benchmarks")] + +// Allow this to be mocked in our unit tests +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] + +// Umbraco Deploy +[assembly: InternalsVisibleTo("Umbraco.Deploy")] +[assembly: InternalsVisibleTo("Umbraco.Deploy.UI")] +[assembly: InternalsVisibleTo("Umbraco.Deploy.Cloud")] + +// Umbraco Forms +[assembly: InternalsVisibleTo("Umbraco.Forms.Core")] +[assembly: InternalsVisibleTo("Umbraco.Forms.Core.Providers")] +[assembly: InternalsVisibleTo("Umbraco.Forms.Web")] + +// Umbraco Headless +[assembly: InternalsVisibleTo("Umbraco.Cloud.Headless")] + +// code analysis +// IDE1006 is broken, wants _value syntax for consts, etc - and it's even confusing ppl at MS, kill it +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "~_~")] diff --git a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj index 4a3654ede6..4ffd6ec08b 100644 --- a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj +++ b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj @@ -4,6 +4,10 @@ netstandard2.0 7.3 Umbraco.Core + 9.0.0 + 9.0.0 + 9.0.0 + Umbraco CMS diff --git a/src/Umbraco.Core/Configuration/CaseInsensitiveEnumConfigConverter.cs b/src/Umbraco.Configuration/CaseInsensitiveEnumConfigConverter.cs similarity index 100% rename from src/Umbraco.Core/Configuration/CaseInsensitiveEnumConfigConverter.cs rename to src/Umbraco.Configuration/CaseInsensitiveEnumConfigConverter.cs diff --git a/src/Umbraco.Core/Configuration/CommaDelimitedConfigurationElement.cs b/src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs similarity index 93% rename from src/Umbraco.Core/Configuration/CommaDelimitedConfigurationElement.cs rename to src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs index 3ced2fab46..00dde5f206 100644 --- a/src/Umbraco.Core/Configuration/CommaDelimitedConfigurationElement.cs +++ b/src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Configuration /// /// Defines a configuration section that contains inner text that is comma delimited /// - internal class CommaDelimitedConfigurationElement : InnerTextConfigurationElement, IEnumerable + public class CommaDelimitedConfigurationElement : InnerTextConfigurationElement, IEnumerable { public override CommaDelimitedStringCollection Value { diff --git a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheckElement.cs b/src/Umbraco.Configuration/HealthChecks/DisabledHealthCheckElement.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheckElement.cs rename to src/Umbraco.Configuration/HealthChecks/DisabledHealthCheckElement.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs rename to src/Umbraco.Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs b/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs rename to src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs b/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs rename to src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthChecksSection.cs b/src/Umbraco.Configuration/HealthChecks/HealthChecksSection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/HealthChecksSection.cs rename to src/Umbraco.Configuration/HealthChecks/HealthChecksSection.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs b/src/Umbraco.Configuration/HealthChecks/IDisabledHealthCheck.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs rename to src/Umbraco.Configuration/HealthChecks/IDisabledHealthCheck.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs b/src/Umbraco.Configuration/HealthChecks/IHealthCheckNotificationSettings.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs rename to src/Umbraco.Configuration/HealthChecks/IHealthCheckNotificationSettings.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecks.cs b/src/Umbraco.Configuration/HealthChecks/IHealthChecks.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/IHealthChecks.cs rename to src/Umbraco.Configuration/HealthChecks/IHealthChecks.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethod.cs b/src/Umbraco.Configuration/HealthChecks/INotificationMethod.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/INotificationMethod.cs rename to src/Umbraco.Configuration/HealthChecks/INotificationMethod.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettings.cs b/src/Umbraco.Configuration/HealthChecks/INotificationMethodSettings.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettings.cs rename to src/Umbraco.Configuration/HealthChecks/INotificationMethodSettings.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodElement.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodElement.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodElement.cs rename to src/Umbraco.Configuration/HealthChecks/NotificationMethodElement.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElement.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElement.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElement.cs rename to src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElement.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs rename to src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodsElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodsElementCollection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodsElementCollection.cs rename to src/Umbraco.Configuration/HealthChecks/NotificationMethodsElementCollection.cs diff --git a/src/Umbraco.Core/Configuration/OptionalCommaDelimitedConfigurationElement.cs b/src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs similarity index 92% rename from src/Umbraco.Core/Configuration/OptionalCommaDelimitedConfigurationElement.cs rename to src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs index 610067d2db..b6771f98b0 100644 --- a/src/Umbraco.Core/Configuration/OptionalCommaDelimitedConfigurationElement.cs +++ b/src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration /// /// Used for specifying default values for comma delimited config /// - internal class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement + public class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement { private readonly CommaDelimitedConfigurationElement _wrapped; private readonly string[] _defaultValue; diff --git a/src/Umbraco.Core/Configuration/OptionalInnerTextConfigurationElement.cs b/src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs similarity index 88% rename from src/Umbraco.Core/Configuration/OptionalInnerTextConfigurationElement.cs rename to src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs index b15e33019d..08dffd5975 100644 --- a/src/Umbraco.Core/Configuration/OptionalInnerTextConfigurationElement.cs +++ b/src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs @@ -4,7 +4,7 @@ /// This is used to supply optional/default values when using InnerTextConfigurationElement ///
/// - internal class OptionalInnerTextConfigurationElement : InnerTextConfigurationElement + public class OptionalInnerTextConfigurationElement : InnerTextConfigurationElement { private readonly InnerTextConfigurationElement _wrapped; private readonly T _defaultValue; diff --git a/src/Umbraco.Configuration/Properties/AssemblyInfo.cs b/src/Umbraco.Configuration/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..d10dd929da --- /dev/null +++ b/src/Umbraco.Configuration/Properties/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Umbraco Cms +[assembly: InternalsVisibleTo("Umbraco.Tests")] +[assembly: InternalsVisibleTo("Umbraco.Tests.Benchmarks")] + +// Allow this to be mocked in our unit tests +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/Umbraco.Core/Configuration/RawXmlConfigurationElement.cs b/src/Umbraco.Configuration/RawXmlConfigurationElement.cs similarity index 90% rename from src/Umbraco.Core/Configuration/RawXmlConfigurationElement.cs rename to src/Umbraco.Configuration/RawXmlConfigurationElement.cs index 5bc6ad3d32..d7f0ed0332 100644 --- a/src/Umbraco.Core/Configuration/RawXmlConfigurationElement.cs +++ b/src/Umbraco.Configuration/RawXmlConfigurationElement.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Configuration /// A configuration section that simply exposes the entire raw xml of the section itself which inheritors can use /// to do with as they please. /// - internal abstract class RawXmlConfigurationElement : ConfigurationElement + public abstract class RawXmlConfigurationElement : ConfigurationElement { protected RawXmlConfigurationElement() { diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj index 15c6ac263f..04f8eb14d3 100644 --- a/src/Umbraco.Configuration/Umbraco.Configuration.csproj +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -18,6 +18,8 @@ <_UnmanagedRegistrationCache Remove="obj\Umbraco.Configuration.csproj.UnmanagedRegistration.cache" /> + <_UnmanagedRegistrationCache Remove="obj\Umbraco.Configuration.csproj.UnmanagedRegistration.cache" /> + <_UnmanagedRegistrationCache Remove="obj\Umbraco.Configuration.csproj.UnmanagedRegistration.cache" /> @@ -28,4 +30,10 @@ + + + C:\Users\Bjarke\AppData\Local\Temp\Temporary ASP.NET Files\root\408beac9\de517473\assembly\dl3\77bf709f\48ac59e4_3595d501\Umbraco.Core.dll + + + diff --git a/src/Umbraco.Core/Configuration/UmbracoConfigurationSection.cs b/src/Umbraco.Configuration/UmbracoConfigurationSection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/UmbracoConfigurationSection.cs rename to src/Umbraco.Configuration/UmbracoConfigurationSection.cs diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/BackOfficeElement.cs b/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs similarity index 76% rename from src/Umbraco.Core/Configuration/UmbracoSettings/BackOfficeElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs index 79bff51d05..1a939d4c9e 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/BackOfficeElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class BackOfficeElement : UmbracoConfigurationElement, IBackOfficeSection + public class BackOfficeElement : UmbracoConfigurationElement, IBackOfficeSection { [ConfigurationProperty("tours")] internal TourConfigElement Tours => (TourConfigElement)this["tours"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/CharCollection.cs b/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs similarity index 90% rename from src/Umbraco.Core/Configuration/UmbracoSettings/CharCollection.cs rename to src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs index 7b62fcc123..3926e700c1 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/CharCollection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class CharCollection : ConfigurationElementCollection, IEnumerable + public class CharCollection : ConfigurationElementCollection, IEnumerable { internal void Add(CharElement c) { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/CharElement.cs b/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs similarity index 87% rename from src/Umbraco.Core/Configuration/UmbracoSettings/CharElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/CharElement.cs index 1ff63ac017..2971228d9e 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/CharElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs @@ -1,6 +1,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class CharElement : InnerTextConfigurationElement, IChar + public class CharElement : InnerTextConfigurationElement, IChar { private string _char; private string _replacement; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs similarity index 98% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs index 77ad7df0dc..1e1ecb4d0c 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Macros; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentElement : UmbracoConfigurationElement, IContentSection + public class ContentElement : UmbracoConfigurationElement, IContentSection { private const string DefaultPreviewBadge = @"
Preview modeClick to end
"; @@ -33,7 +33,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings [ConfigurationProperty("allowedUploadFiles")] internal CommaDelimitedConfigurationElement AllowedUploadFiles => GetOptionalDelimitedElement("allowedUploadFiles", new string[0]); - + [ConfigurationProperty("showDeprecatedPropertyEditors")] internal InnerTextConfigurationElement ShowDeprecatedPropertyEditors => GetOptionalTextElement("showDeprecatedPropertyEditors", false); diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentError404Collection.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs similarity index 89% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentError404Collection.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs index bdbcb27b4c..da146b14ec 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentError404Collection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentError404Collection : ConfigurationElementCollection, IEnumerable + public class ContentError404Collection : ConfigurationElementCollection, IEnumerable { internal void Add(ContentErrorPageElement element) { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorPageElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs similarity index 92% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorPageElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs index 96cea71a8e..8f5a5b3259 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorPageElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs @@ -3,7 +3,7 @@ using System.Xml.Linq; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentErrorPageElement : InnerTextConfigurationElement, IContentErrorPage + public class ContentErrorPageElement : InnerTextConfigurationElement, IContentErrorPage { public ContentErrorPageElement(XElement rawXml) : base(rawXml) diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorsElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs similarity index 95% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorsElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs index 5b5b54380d..a393267b9d 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorsElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs @@ -3,7 +3,7 @@ using System.Linq; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentErrorsElement : RawXmlConfigurationElement + public class ContentErrorsElement : RawXmlConfigurationElement { public IEnumerable Error404Collection diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentSectionExtensions.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentSectionExtensions.cs similarity index 100% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentSectionExtensions.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentSectionExtensions.cs diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs similarity index 88% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs rename to src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs index 0bac9721a3..69680251af 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ImagingAutoFillPropertiesCollection : ConfigurationElementCollection, IEnumerable + public class ImagingAutoFillPropertiesCollection : ConfigurationElementCollection, IEnumerable { protected override ConfigurationElement CreateNewElement() diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs similarity index 93% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs index 9b4c45b5c6..ec3dc43caf 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ImagingAutoFillUploadFieldElement : UmbracoConfigurationElement, IImagingAutoFillUploadField + public class ImagingAutoFillUploadFieldElement : UmbracoConfigurationElement, IImagingAutoFillUploadField { /// /// Allow setting internally so we can create a default diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/LoggingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs similarity index 80% rename from src/Umbraco.Core/Configuration/UmbracoSettings/LoggingElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs index 106b6cc134..daa45cf114 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/LoggingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class LoggingElement : UmbracoConfigurationElement, ILoggingSection + public class LoggingElement : UmbracoConfigurationElement, ILoggingSection { [ConfigurationProperty("maxLogAge")] diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/NotificationsElement.cs b/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs similarity index 86% rename from src/Umbraco.Core/Configuration/UmbracoSettings/NotificationsElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs index afadff5654..cc76b2cb00 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/NotificationsElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class NotificationsElement : UmbracoConfigurationElement + public class NotificationsElement : UmbracoConfigurationElement { [ConfigurationProperty("email")] internal InnerTextConfigurationElement NotificationEmailAddress => (InnerTextConfigurationElement)this["email"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/SecurityElement.cs b/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs similarity index 97% rename from src/Umbraco.Core/Configuration/UmbracoSettings/SecurityElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs index d45a3e7d85..42bafe4bd1 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/SecurityElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class SecurityElement : UmbracoConfigurationElement, ISecuritySection + public class SecurityElement : UmbracoConfigurationElement, ISecuritySection { [ConfigurationProperty("keepUserLoggedIn")] internal InnerTextConfigurationElement KeepUserLoggedIn => GetOptionalTextElement("keepUserLoggedIn", true); diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/TourConfigElement.cs b/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs similarity index 85% rename from src/Umbraco.Core/Configuration/UmbracoSettings/TourConfigElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs index dab69f3da0..f62d766d76 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/TourConfigElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class TourConfigElement : UmbracoConfigurationElement, ITourSection + public class TourConfigElement : UmbracoConfigurationElement, ITourSection { //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 ? diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoConfigurationElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs similarity index 95% rename from src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoConfigurationElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs index 670f620b15..30cc33a260 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoConfigurationElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings /// /// Base class with shared helper methods /// - internal class UmbracoConfigurationElement : ConfigurationElement + public class UmbracoConfigurationElement : ConfigurationElement { /// /// Used so the RawElement types are not re-created every time they are accessed diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs similarity index 64% rename from src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs rename to src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs index 7cf8096345..bc91dfd48a 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs @@ -5,23 +5,23 @@ namespace Umbraco.Core.Configuration.UmbracoSettings public class UmbracoSettingsSection : ConfigurationSection, IUmbracoSettingsSection { [ConfigurationProperty("backOffice")] - internal BackOfficeElement BackOffice => (BackOfficeElement)this["backOffice"]; + public BackOfficeElement BackOffice => (BackOfficeElement)this["backOffice"]; [ConfigurationProperty("content")] - internal ContentElement Content => (ContentElement)this["content"]; + public ContentElement Content => (ContentElement)this["content"]; [ConfigurationProperty("security")] - internal SecurityElement Security => (SecurityElement)this["security"]; + public SecurityElement Security => (SecurityElement)this["security"]; [ConfigurationProperty("requestHandler")] - internal RequestHandlerElement RequestHandler => (RequestHandlerElement)this["requestHandler"]; + public RequestHandlerElement RequestHandler => (RequestHandlerElement)this["requestHandler"]; [ConfigurationProperty("logging")] - internal LoggingElement Logging => (LoggingElement)this["logging"]; + public LoggingElement Logging => (LoggingElement)this["logging"]; [ConfigurationProperty("web.routing")] - internal WebRoutingElement WebRouting => (WebRoutingElement)this["web.routing"]; + public WebRoutingElement WebRouting => (WebRoutingElement)this["web.routing"]; IContentSection IUmbracoSettingsSection.Content => Content; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/UrlReplacingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs similarity index 92% rename from src/Umbraco.Core/Configuration/UmbracoSettings/UrlReplacingElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs index 3e12d106ff..45fe2c4294 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/UrlReplacingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class UrlReplacingElement : ConfigurationElement + public class UrlReplacingElement : ConfigurationElement { [ConfigurationProperty("removeDoubleDashes", DefaultValue = true)] internal bool RemoveDoubleDashes => (bool) base["removeDoubleDashes"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs similarity index 94% rename from src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs index 7b7102f2e7..4c74398e25 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class WebRoutingElement : ConfigurationElement, IWebRoutingSection + public class WebRoutingElement : ConfigurationElement, IWebRoutingSection { [ConfigurationProperty("trySkipIisCustomErrors", DefaultValue = "false")] public bool TrySkipIisCustomErrors => (bool) base["trySkipIisCustomErrors"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Configuration/UmbracoVersion.cs similarity index 98% rename from src/Umbraco.Core/Configuration/UmbracoVersion.cs rename to src/Umbraco.Configuration/UmbracoVersion.cs index 2f615d26b3..d7058fda01 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Configuration/UmbracoVersion.cs @@ -12,7 +12,7 @@ namespace Umbraco.Core.Configuration { static UmbracoVersion() { - var umbracoCoreAssembly = typeof(UmbracoVersion).Assembly; + var umbracoCoreAssembly = typeof(SemVersion).Assembly; // gets the value indicated by the AssemblyVersion attribute AssemblyVersion = umbracoCoreAssembly.GetName().Version; diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs new file mode 100644 index 0000000000..4761b14d1e --- /dev/null +++ b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs @@ -0,0 +1,34 @@ +using System.IO; +using Umbraco.Core.Cache; +using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Grid; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Core.Manifest; + +namespace Umbraco.Core +{ + /// + /// Provides extension methods for the class. + /// + public static class ConfigsExtensions + { + + + + public static void AddCoreConfigs(this Configs configs) + { + var configDir = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config)); + + // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition + configs.Add(factory => new GridConfig( + factory.GetInstance(), + factory.GetInstance(), + configDir, + factory.GetInstance(), + factory.GetInstance().Debug)); + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 5755532cd6..859a618b74 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -174,8 +174,11 @@ - - + + + + + @@ -275,6 +278,7 @@ + @@ -315,53 +319,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -991,7 +948,6 @@ - @@ -1183,6 +1139,10 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions + + {fbe7c065-dac0-4025-a78b-63b24d3ab00b} + Umbraco.Configuration + \ No newline at end of file diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/web.config b/src/Umbraco.Tests/Configurations/UmbracoSettings/web.config index 3b247ecbff..5ac2d56d14 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/web.config +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/web.config @@ -1,10 +1,10 @@  - + -
-
+
+
@@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index de76b94ff1..4f4a20d94e 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -107,6 +107,7 @@ + @@ -552,6 +553,10 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions + + {fbe7c065-dac0-4025-a78b-63b24d3ab00b} + Umbraco.Configuration + {31785BC3-256C-4613-B2F5-A1B0BDDED8C1} Umbraco.Core diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config index 6d68ea845a..e694afe5ff 100644 --- a/src/Umbraco.Web.UI/web.Template.config +++ b/src/Umbraco.Web.UI/web.Template.config @@ -11,8 +11,8 @@
-
-
+
+
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 317786b970..788a6dd737 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -104,6 +104,10 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions + + {fbe7c065-dac0-4025-a78b-63b24d3ab00b} + Umbraco.Configuration + {31785bc3-256c-4613-b2f5-a1b0bdded8c1} Umbraco.Core From bd7a2d670a39c19d501edab6ee8fb9c571a8aee3 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 10:10:12 +0100 Subject: [PATCH 08/61] Move some of the config to Umbraco.Configuration --- .../ConfigsExtensions.cs | 28 ++++++++++ src/Umbraco.Configuration/ConfigsFactory.cs | 21 ++++++++ .../CoreDebug.cs | 2 +- .../InnerTextConfigurationElement.cs | 2 +- .../UmbracoSettings/ContentImagingElement.cs | 6 +-- .../UmbracoSettings/RequestHandlerElement.cs | 4 +- src/Umbraco.Core/ConfigsExtensions.cs | 53 ------------------- .../Configuration/ConfigsFactory.cs | 13 ----- 8 files changed, 56 insertions(+), 73 deletions(-) create mode 100644 src/Umbraco.Configuration/ConfigsExtensions.cs create mode 100644 src/Umbraco.Configuration/ConfigsFactory.cs rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/CoreDebug.cs (97%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/InnerTextConfigurationElement.cs (96%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentImagingElement.cs (91%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/RequestHandlerElement.cs (95%) delete mode 100644 src/Umbraco.Core/ConfigsExtensions.cs delete mode 100644 src/Umbraco.Core/Configuration/ConfigsFactory.cs diff --git a/src/Umbraco.Configuration/ConfigsExtensions.cs b/src/Umbraco.Configuration/ConfigsExtensions.cs new file mode 100644 index 0000000000..0ecfc46896 --- /dev/null +++ b/src/Umbraco.Configuration/ConfigsExtensions.cs @@ -0,0 +1,28 @@ +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Grid; +using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Core +{ + /// + /// Provides extension methods for the class. + /// + public static class ConfigsExtensions + { + public static IGlobalSettings Global(this Configs configs) + => configs.GetConfig(); + + public static IUmbracoSettingsSection Settings(this Configs configs) + => configs.GetConfig(); + + public static IHealthChecks HealthChecks(this Configs configs) + => configs.GetConfig(); + + public static IGridConfig Grids(this Configs configs) + => configs.GetConfig(); + + public static CoreDebug CoreDebug(this Configs configs) + => configs.GetConfig(); + } +} diff --git a/src/Umbraco.Configuration/ConfigsFactory.cs b/src/Umbraco.Configuration/ConfigsFactory.cs new file mode 100644 index 0000000000..fbfefc132e --- /dev/null +++ b/src/Umbraco.Configuration/ConfigsFactory.cs @@ -0,0 +1,21 @@ +using System.Configuration; +using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Core.Configuration +{ + public class ConfigsFactory : IConfigsFactory + { + public Configs Create() { + var configs = new Configs(section => ConfigurationManager.GetSection(section)); + configs.Add(() => new GlobalSettings()); + configs.Add("umbracoConfiguration/settings"); + configs.Add("umbracoConfiguration/HealthChecks"); + + configs.Add(() => new CoreDebug()); + configs.Add("umbracoConfiguration/HealthChecks"); + configs.AddCoreConfigs(); + return configs; + } + } +} diff --git a/src/Umbraco.Core/Configuration/CoreDebug.cs b/src/Umbraco.Configuration/CoreDebug.cs similarity index 97% rename from src/Umbraco.Core/Configuration/CoreDebug.cs rename to src/Umbraco.Configuration/CoreDebug.cs index aa95a25990..e81ca14873 100644 --- a/src/Umbraco.Core/Configuration/CoreDebug.cs +++ b/src/Umbraco.Configuration/CoreDebug.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration { - internal class CoreDebug + public class CoreDebug { public CoreDebug() { diff --git a/src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs b/src/Umbraco.Configuration/InnerTextConfigurationElement.cs similarity index 96% rename from src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs rename to src/Umbraco.Configuration/InnerTextConfigurationElement.cs index 6a125f2c1b..3ff0c4d735 100644 --- a/src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs +++ b/src/Umbraco.Configuration/InnerTextConfigurationElement.cs @@ -9,7 +9,7 @@ namespace Umbraco.Core.Configuration /// {element}MyValue{/element} instead of as attribute values. ///
/// - internal class InnerTextConfigurationElement : RawXmlConfigurationElement + public class InnerTextConfigurationElement : RawXmlConfigurationElement { public InnerTextConfigurationElement() { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentImagingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs similarity index 91% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentImagingElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs index 67562c411a..91eb180d08 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentImagingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentImagingElement : ConfigurationElement + public class ContentImagingElement : ConfigurationElement { [ConfigurationProperty("imageFileTypes")] @@ -12,7 +12,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings //set the default GetDefaultImageFileTypes()); - internal static string[] GetDefaultImageFileTypes() + public static string[] GetDefaultImageFileTypes() { return new[] {"jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif"}; } @@ -49,7 +49,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings } } - internal static ImagingAutoFillPropertiesCollection GetDefaultImageAutoFillProperties() + public static ImagingAutoFillPropertiesCollection GetDefaultImageAutoFillProperties() { return new ImagingAutoFillPropertiesCollection { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/RequestHandlerElement.cs b/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs similarity index 95% rename from src/Umbraco.Core/Configuration/UmbracoSettings/RequestHandlerElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs index 263a822381..e5350bf596 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/RequestHandlerElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class RequestHandlerElement : UmbracoConfigurationElement, IRequestHandlerSection + public class RequestHandlerElement : UmbracoConfigurationElement, IRequestHandlerSection { [ConfigurationProperty("addTrailingSlash")] public InnerTextConfigurationElement AddTrailingSlash => GetOptionalTextElement("addTrailingSlash", true); @@ -38,7 +38,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings } } - internal static CharCollection GetDefaultCharReplacements() + public static CharCollection GetDefaultCharReplacements() { var dictionary = new Dictionary() { diff --git a/src/Umbraco.Core/ConfigsExtensions.cs b/src/Umbraco.Core/ConfigsExtensions.cs deleted file mode 100644 index 5699540389..0000000000 --- a/src/Umbraco.Core/ConfigsExtensions.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.IO; -using Umbraco.Core.Cache; -using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Grid; -using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.IO; -using Umbraco.Core.Logging; -using Umbraco.Core.Manifest; - -namespace Umbraco.Core -{ - /// - /// Provides extension methods for the class. - /// - public static class ConfigsExtensions - { - public static IGlobalSettings Global(this Configs configs) - => configs.GetConfig(); - - public static IUmbracoSettingsSection Settings(this Configs configs) - => configs.GetConfig(); - - public static IHealthChecks HealthChecks(this Configs configs) - => configs.GetConfig(); - - public static IGridConfig Grids(this Configs configs) - => configs.GetConfig(); - - internal static CoreDebug CoreDebug(this Configs configs) - => configs.GetConfig(); - - public static void AddCoreConfigs(this Configs configs) - { - var configDir = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config)); - - configs.Add(() => new GlobalSettings()); - configs.Add("umbracoConfiguration/settings"); - configs.Add("umbracoConfiguration/HealthChecks"); - - configs.Add(() => new CoreDebug()); - - // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition - configs.Add(factory => new GridConfig( - factory.GetInstance(), - factory.GetInstance(), - configDir, - factory.GetInstance(), - factory.GetInstance().Debug)); - } - } -} diff --git a/src/Umbraco.Core/Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs deleted file mode 100644 index aeeef1e653..0000000000 --- a/src/Umbraco.Core/Configuration/ConfigsFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration -{ - public class ConfigsFactory : IConfigsFactory - { - public Configs Create() { - var configs = new Configs(section => ConfigurationManager.GetSection(section)); - configs.AddCoreConfigs(); - return configs; - } - } -} From 914d6f3f2e5df53d93df4321b9cadd17d23cabcf Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 12:58:56 +0100 Subject: [PATCH 09/61] More config movement --- .../Configuration/ConfigsExtensions.cs | 2 - .../Configuration}/ConfigsFactory.cs | 1 - .../Configuration/Grid/GridEditorsConfig.cs | 6 +- src/Umbraco.Core/Manifest/IManifestFilter.cs | 2 +- src/Umbraco.Core/Manifest/IManifestParser.cs | 9 +- src/Umbraco.Core/Manifest/IPackageManifest.cs | 65 ++++++++ .../Manifest/ManifestFilterCollection.cs | 2 +- src/Umbraco.Core/Manifest/ManifestParser.cs | 15 +- src/Umbraco.Core/Manifest/PackageManifest.cs | 140 +++++++++--------- src/Umbraco.Core/Umbraco.Core.csproj | 2 + src/Umbraco.Tests/Published/ModelTypeTests.cs | 2 +- 11 files changed, 156 insertions(+), 90 deletions(-) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/ConfigsFactory.cs (90%) create mode 100644 src/Umbraco.Core/Manifest/IPackageManifest.cs diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs index 4761b14d1e..e54e360021 100644 --- a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs @@ -16,8 +16,6 @@ namespace Umbraco.Core public static class ConfigsExtensions { - - public static void AddCoreConfigs(this Configs configs) { var configDir = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config)); diff --git a/src/Umbraco.Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs similarity index 90% rename from src/Umbraco.Configuration/ConfigsFactory.cs rename to src/Umbraco.Core/Configuration/ConfigsFactory.cs index fbfefc132e..c0e80d3798 100644 --- a/src/Umbraco.Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -13,7 +13,6 @@ namespace Umbraco.Core.Configuration configs.Add("umbracoConfiguration/HealthChecks"); configs.Add(() => new CoreDebug()); - configs.Add("umbracoConfiguration/HealthChecks"); configs.AddCoreConfigs(); return configs; } diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs index cab58a6d63..a1ebf008fc 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs @@ -29,9 +29,9 @@ namespace Umbraco.Core.Configuration.Grid { get { - List GetResult() + List GetResult() { - var editors = new List(); + var editors = new List(); var gridConfig = Path.Combine(_configFolder.FullName, "grid.editors.config.js"); if (File.Exists(gridConfig)) { @@ -59,7 +59,7 @@ namespace Umbraco.Core.Configuration.Grid //cache the result if debugging is disabled var result = _isDebug ? GetResult() - : _appCaches.RuntimeCache.GetCacheItem>(typeof(GridEditorsConfig) + ".Editors",GetResult, TimeSpan.FromMinutes(10)); + : _appCaches.RuntimeCache.GetCacheItem>(typeof(GridEditorsConfig) + ".Editors",GetResult, TimeSpan.FromMinutes(10)); return result; } diff --git a/src/Umbraco.Core/Manifest/IManifestFilter.cs b/src/Umbraco.Core/Manifest/IManifestFilter.cs index 505f13d385..f1e2c633c8 100644 --- a/src/Umbraco.Core/Manifest/IManifestFilter.cs +++ b/src/Umbraco.Core/Manifest/IManifestFilter.cs @@ -14,6 +14,6 @@ namespace Umbraco.Core.Manifest /// /// It is possible to remove, change, or add manifests. /// - void Filter(List manifests); + void Filter(List manifests); } } diff --git a/src/Umbraco.Core/Manifest/IManifestParser.cs b/src/Umbraco.Core/Manifest/IManifestParser.cs index 3641396e0a..367ee3be77 100644 --- a/src/Umbraco.Core/Manifest/IManifestParser.cs +++ b/src/Umbraco.Core/Manifest/IManifestParser.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Umbraco.Core.Configuration.Grid; using Umbraco.Core.PropertyEditors; namespace Umbraco.Core.Manifest @@ -11,13 +12,13 @@ namespace Umbraco.Core.Manifest /// Gets all manifests, merged into a single manifest object. ///
/// - PackageManifest Manifest { get; } + IPackageManifest Manifest { get; } /// /// Parses a manifest. /// - PackageManifest ParseManifest(string text); + IPackageManifest ParseManifest(string text); - IEnumerable ParseGridEditors(string text); + IEnumerable ParseGridEditors(string text); } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Manifest/IPackageManifest.cs b/src/Umbraco.Core/Manifest/IPackageManifest.cs new file mode 100644 index 0000000000..01b0be70db --- /dev/null +++ b/src/Umbraco.Core/Manifest/IPackageManifest.cs @@ -0,0 +1,65 @@ +using System.Runtime.Serialization; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Core.Manifest +{ + public interface IPackageManifest + { + /// + /// Gets the source path of the manifest. + /// + /// + /// Gets the full absolute file path of the manifest, + /// using system directory separators. + /// + string Source { get; set; } + + /// + /// Gets or sets the scripts listed in the manifest. + /// + [DataMember(Name = "javascript")] + string[] Scripts { get; set; } + + /// + /// Gets or sets the stylesheets listed in the manifest. + /// + [DataMember(Name = "css")] + string[] Stylesheets { get; set; } + + /// + /// Gets or sets the property editors listed in the manifest. + /// + [DataMember(Name = "propertyEditors")] + IDataEditor[] PropertyEditors { get; set; } + + /// + /// Gets or sets the parameter editors listed in the manifest. + /// + [DataMember(Name = "parameterEditors")] + IDataEditor[] ParameterEditors { get; set; } + + /// + /// Gets or sets the grid editors listed in the manifest. + /// + [DataMember(Name = "gridEditors")] + GridEditor[] GridEditors { get; set; } + + /// + /// Gets or sets the content apps listed in the manifest. + /// + [DataMember(Name = "contentApps")] + ManifestContentAppDefinition[] ContentApps { get; set; } + + /// + /// Gets or sets the dashboards listed in the manifest. + /// + [DataMember(Name = "dashboards")] + ManifestDashboard[] Dashboards { get; set; } + + /// + /// Gets or sets the sections listed in the manifest. + /// + [DataMember(Name = "sections")] + ManifestSection[] Sections { get; set; } + } +} diff --git a/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs b/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs index febdb7e356..0f49c96094 100644 --- a/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs +++ b/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Manifest /// Filters package manifests. /// /// The package manifests. - public void Filter(List manifests) + public void Filter(List manifests) { foreach (var filter in this) filter.Filter(manifests); diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index 2e55d07059..4e2ca1f2b6 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using Newtonsoft.Json; using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.Grid; using Umbraco.Core.Exceptions; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -57,8 +58,8 @@ namespace Umbraco.Core.Manifest /// Gets all manifests, merged into a single manifest object. /// /// - public PackageManifest Manifest - => _cache.GetCacheItem("Umbraco.Core.Manifest.ManifestParser::Manifests", () => + public IPackageManifest Manifest + => _cache.GetCacheItem("Umbraco.Core.Manifest.ManifestParser::Manifests", () => { var manifests = GetManifests(); return MergeManifests(manifests); @@ -67,9 +68,9 @@ namespace Umbraco.Core.Manifest /// /// Gets all manifests. /// - private IEnumerable GetManifests() + private IEnumerable GetManifests() { - var manifests = new List(); + var manifests = new List(); foreach (var path in GetManifestFiles()) { @@ -97,7 +98,7 @@ namespace Umbraco.Core.Manifest /// /// Merges all manifests into one. /// - private static PackageManifest MergeManifests(IEnumerable manifests) + private static IPackageManifest MergeManifests(IEnumerable manifests) { var scripts = new HashSet(); var stylesheets = new HashSet(); @@ -153,7 +154,7 @@ namespace Umbraco.Core.Manifest /// /// Parses a manifest. /// - public PackageManifest ParseManifest(string text) + public IPackageManifest ParseManifest(string text) { if (string.IsNullOrWhiteSpace(text)) throw new ArgumentNullOrEmptyException(nameof(text)); @@ -179,7 +180,7 @@ namespace Umbraco.Core.Manifest } // purely for tests - public IEnumerable ParseGridEditors(string text) + public IEnumerable ParseGridEditors(string text) { return JsonConvert.DeserializeObject>(text); } diff --git a/src/Umbraco.Core/Manifest/PackageManifest.cs b/src/Umbraco.Core/Manifest/PackageManifest.cs index e50eb69467..a81021432d 100644 --- a/src/Umbraco.Core/Manifest/PackageManifest.cs +++ b/src/Umbraco.Core/Manifest/PackageManifest.cs @@ -1,70 +1,70 @@ -using System; -using Newtonsoft.Json; -using Umbraco.Core.PropertyEditors; - -namespace Umbraco.Core.Manifest -{ - /// - /// Represents the content of a package manifest. - /// - public class PackageManifest - { - /// - /// Gets the source path of the manifest. - /// - /// - /// Gets the full absolute file path of the manifest, - /// using system directory separators. - /// - [JsonIgnore] - public string Source { get; set; } - - /// - /// Gets or sets the scripts listed in the manifest. - /// - [JsonProperty("javascript")] - public string[] Scripts { get; set; } = Array.Empty(); - - /// - /// Gets or sets the stylesheets listed in the manifest. - /// - [JsonProperty("css")] - public string[] Stylesheets { get; set; } = Array.Empty(); - - /// - /// Gets or sets the property editors listed in the manifest. - /// - [JsonProperty("propertyEditors")] - public IDataEditor[] PropertyEditors { get; set; } = Array.Empty(); - - /// - /// Gets or sets the parameter editors listed in the manifest. - /// - [JsonProperty("parameterEditors")] - public IDataEditor[] ParameterEditors { get; set; } = Array.Empty(); - - /// - /// Gets or sets the grid editors listed in the manifest. - /// - [JsonProperty("gridEditors")] - public GridEditor[] GridEditors { get; set; } = Array.Empty(); - - /// - /// Gets or sets the content apps listed in the manifest. - /// - [JsonProperty("contentApps")] - public ManifestContentAppDefinition[] ContentApps { get; set; } = Array.Empty(); - - /// - /// Gets or sets the dashboards listed in the manifest. - /// - [JsonProperty("dashboards")] - public ManifestDashboard[] Dashboards { get; set; } = Array.Empty(); - - /// - /// Gets or sets the sections listed in the manifest. - /// - [JsonProperty("sections")] - public ManifestSection[] Sections { get; set; } = Array.Empty(); - } -} +using System; +using Newtonsoft.Json; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Core.Manifest +{ + /// + /// Represents the content of a package manifest. + /// + public class PackageManifest : IPackageManifest + { + /// + /// Gets the source path of the manifest. + /// + /// + /// Gets the full absolute file path of the manifest, + /// using system directory separators. + /// + [JsonIgnore] + public string Source { get; set; } + + /// + /// Gets or sets the scripts listed in the manifest. + /// + [JsonProperty("javascript")] + public string[] Scripts { get; set; } = Array.Empty(); + + /// + /// Gets or sets the stylesheets listed in the manifest. + /// + [JsonProperty("css")] + public string[] Stylesheets { get; set; } = Array.Empty(); + + /// + /// Gets or sets the property editors listed in the manifest. + /// + [JsonProperty("propertyEditors")] + public IDataEditor[] PropertyEditors { get; set; } = Array.Empty(); + + /// + /// Gets or sets the parameter editors listed in the manifest. + /// + [JsonProperty("parameterEditors")] + public IDataEditor[] ParameterEditors { get; set; } = Array.Empty(); + + /// + /// Gets or sets the grid editors listed in the manifest. + /// + [JsonProperty("gridEditors")] + public GridEditor[] GridEditors { get; set; } = Array.Empty(); + + /// + /// Gets or sets the content apps listed in the manifest. + /// + [JsonProperty("contentApps")] + public ManifestContentAppDefinition[] ContentApps { get; set; } = Array.Empty(); + + /// + /// Gets or sets the dashboards listed in the manifest. + /// + [JsonProperty("dashboards")] + public ManifestDashboard[] Dashboards { get; set; } = Array.Empty(); + + /// + /// Gets or sets the sections listed in the manifest. + /// + [JsonProperty("sections")] + public ManifestSection[] Sections { get; set; } = Array.Empty(); + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 859a618b74..dc1828fe6d 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -175,6 +175,7 @@ + @@ -201,6 +202,7 @@ + diff --git a/src/Umbraco.Tests/Published/ModelTypeTests.cs b/src/Umbraco.Tests/Published/ModelTypeTests.cs index 622bebdf78..1dab67b351 100644 --- a/src/Umbraco.Tests/Published/ModelTypeTests.cs +++ b/src/Umbraco.Tests/Published/ModelTypeTests.cs @@ -53,7 +53,7 @@ namespace Umbraco.Tests.Published // there's an "*" there because the arrays are not true SZArray - but that changes when we map Assert.AreEqual("{alias1}[*]", ModelType.For("alias1").MakeArrayType().FullName); // note the inner assembly qualified name - Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[{alias1}[*], Umbraco.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]", typeof(IEnumerable<>).MakeGenericType(ModelType.For("alias1").MakeArrayType()).FullName); + Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[{alias1}[*], Umbraco.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null]]", typeof(IEnumerable<>).MakeGenericType(ModelType.For("alias1").MakeArrayType()).FullName); } [Test] From 640da8bc912e57700eece3f1234128edf4f37a0b Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 10:43:33 +0100 Subject: [PATCH 10/61] Move logging stuff --- .../Logging/DebugDiagnosticsLogger.cs | 21 ++++++++++------ .../Logging/IMessageTemplates.cs | 7 ++++++ .../Logging/LogProfiler.cs | 2 +- .../Logging/LoggingTaskExtension.cs | 0 .../Logging/VoidProfiler.cs | 2 +- src/Umbraco.Core/Composing/Current.cs | 2 +- src/Umbraco.Core/Logging/MessageTemplates.cs | 4 +-- src/Umbraco.Core/Umbraco.Core.csproj | 4 --- .../BulkInsertBenchmarks.cs | 2 +- .../Composing/TypeFinderTests.cs | 2 +- .../Migrations/AdvancedMigrationTests.cs | 10 ++++---- src/Umbraco.Tests/Models/ContentTests.cs | 4 +-- src/Umbraco.Tests/Models/ContentTypeTests.cs | 2 +- .../NPocoTests/NPocoBulkInsertTests.cs | 2 +- .../Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 4 +-- .../Scheduling/BackgroundTaskRunnerTests.cs | 2 +- .../Scheduling/BackgroundTaskRunnerTests2.cs | 4 +-- .../Services/ContentServicePerformanceTest.cs | 4 +-- .../Services/PerformanceTests.cs | 2 +- .../TestHelpers/ConsoleLogger.cs | 25 ++++++++++++------- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- 22 files changed, 63 insertions(+), 46 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Logging/DebugDiagnosticsLogger.cs (77%) create mode 100644 src/Umbraco.Abstractions/Logging/IMessageTemplates.cs rename src/{Umbraco.Core => Umbraco.Abstractions}/Logging/LogProfiler.cs (97%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Logging/LoggingTaskExtension.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Logging/VoidProfiler.cs (92%) diff --git a/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs b/src/Umbraco.Abstractions/Logging/DebugDiagnosticsLogger.cs similarity index 77% rename from src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs rename to src/Umbraco.Abstractions/Logging/DebugDiagnosticsLogger.cs index d1bde55306..552daba713 100644 --- a/src/Umbraco.Core/Logging/DebugDiagnosticsLogger.cs +++ b/src/Umbraco.Abstractions/Logging/DebugDiagnosticsLogger.cs @@ -7,6 +7,13 @@ namespace Umbraco.Core.Logging /// public class DebugDiagnosticsLogger : ILogger { + private readonly IMessageTemplates _messageTemplates; + + public DebugDiagnosticsLogger(IMessageTemplates messageTemplates) + { + _messageTemplates = messageTemplates; + } + public bool IsEnabled(Type reporting, LogLevel level) => true; @@ -31,7 +38,7 @@ namespace Umbraco.Core.Logging /// public void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, reporting.FullName); } /// @@ -61,7 +68,7 @@ namespace Umbraco.Core.Logging /// public void Error(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues) + Environment.NewLine + exception, reporting.FullName); } /// @@ -79,7 +86,7 @@ namespace Umbraco.Core.Logging /// public void Warn(Type reporting, string message, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(message, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(message, propertyValues), reporting.FullName); } /// @@ -91,7 +98,7 @@ namespace Umbraco.Core.Logging /// public void Warn(Type reporting, Exception exception, string message, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(message + Environment.NewLine + exception, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(message + Environment.NewLine + exception, propertyValues), reporting.FullName); } /// @@ -103,7 +110,7 @@ namespace Umbraco.Core.Logging /// public void Info(Type reporting, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); } /// @@ -115,7 +122,7 @@ namespace Umbraco.Core.Logging /// public void Debug(Type reporting, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); } /// @@ -127,7 +134,7 @@ namespace Umbraco.Core.Logging /// public void Verbose(Type reporting, string messageTemplate, params object[] propertyValues) { - System.Diagnostics.Debug.WriteLine(MessageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); + System.Diagnostics.Debug.WriteLine(_messageTemplates.Render(messageTemplate, propertyValues), reporting.FullName); } } } diff --git a/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs b/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs new file mode 100644 index 0000000000..60aa1035ad --- /dev/null +++ b/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs @@ -0,0 +1,7 @@ +namespace Umbraco.Core.Logging +{ + public interface IMessageTemplates + { + string Render(string messageTemplate, params object[] args); + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Logging/LogProfiler.cs b/src/Umbraco.Abstractions/Logging/LogProfiler.cs similarity index 97% rename from src/Umbraco.Core/Logging/LogProfiler.cs rename to src/Umbraco.Abstractions/Logging/LogProfiler.cs index 74dae545b4..294f92dad3 100644 --- a/src/Umbraco.Core/Logging/LogProfiler.cs +++ b/src/Umbraco.Abstractions/Logging/LogProfiler.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Logging /// /// Implements by writing profiling results to an . /// - internal class LogProfiler : IProfiler + public class LogProfiler : IProfiler { private readonly ILogger _logger; diff --git a/src/Umbraco.Core/Logging/LoggingTaskExtension.cs b/src/Umbraco.Abstractions/Logging/LoggingTaskExtension.cs similarity index 100% rename from src/Umbraco.Core/Logging/LoggingTaskExtension.cs rename to src/Umbraco.Abstractions/Logging/LoggingTaskExtension.cs diff --git a/src/Umbraco.Core/Logging/VoidProfiler.cs b/src/Umbraco.Abstractions/Logging/VoidProfiler.cs similarity index 92% rename from src/Umbraco.Core/Logging/VoidProfiler.cs rename to src/Umbraco.Abstractions/Logging/VoidProfiler.cs index 24eb8e81c3..51bec521a3 100644 --- a/src/Umbraco.Core/Logging/VoidProfiler.cs +++ b/src/Umbraco.Abstractions/Logging/VoidProfiler.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Logging { - internal class VoidProfiler : IProfiler + public class VoidProfiler : IProfiler { private readonly VoidDisposable _disposable = new VoidDisposable(); diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index f12bf0dd63..ed64347816 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -113,7 +113,7 @@ namespace Umbraco.Core.Composing public static ILogger Logger => _logger ?? (_logger = _factory?.TryGetInstance() - ?? new DebugDiagnosticsLogger()); + ?? new DebugDiagnosticsLogger(new MessageTemplates())); public static IProfiler Profiler => _profiler ?? (_profiler = _factory?.TryGetInstance() diff --git a/src/Umbraco.Core/Logging/MessageTemplates.cs b/src/Umbraco.Core/Logging/MessageTemplates.cs index 47de1230ff..887aa1402d 100644 --- a/src/Umbraco.Core/Logging/MessageTemplates.cs +++ b/src/Umbraco.Core/Logging/MessageTemplates.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Logging /// /// Provides tools to support message templates. /// - public static class MessageTemplates + public class MessageTemplates : IMessageTemplates { // Umbraco now uses Message Templates (https://messagetemplates.org/) for logging, which means // we cannot plainly use string.Format() to format them. There is a work-in-progress C# lib, @@ -21,7 +21,7 @@ namespace Umbraco.Core.Logging private static readonly Lazy MinimalLogger = new Lazy(() => new LoggerConfiguration().CreateLogger()); - public static string Render(string messageTemplate, params object[] args) + public string Render(string messageTemplate, params object[] args) { // by default, unless initialized otherwise, Log.Logger is SilentLogger which cannot bind message // templates. Log.Logger is set to a true Logger when initializing Umbraco's logger, but in case diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index d41240c586..25de78105f 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -572,13 +572,9 @@ - - - - diff --git a/src/Umbraco.Tests.Benchmarks/BulkInsertBenchmarks.cs b/src/Umbraco.Tests.Benchmarks/BulkInsertBenchmarks.cs index d6dc1f8c73..dc260c4a3b 100644 --- a/src/Umbraco.Tests.Benchmarks/BulkInsertBenchmarks.cs +++ b/src/Umbraco.Tests.Benchmarks/BulkInsertBenchmarks.cs @@ -49,7 +49,7 @@ namespace Umbraco.Tests.Benchmarks [GlobalSetup] public void Setup() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var path = TestHelper.CurrentAssemblyDirectory; SetupSqlCe(path, logger); diff --git a/src/Umbraco.Tests/Composing/TypeFinderTests.cs b/src/Umbraco.Tests/Composing/TypeFinderTests.cs index ca622e9288..5511c5cba3 100644 --- a/src/Umbraco.Tests/Composing/TypeFinderTests.cs +++ b/src/Umbraco.Tests/Composing/TypeFinderTests.cs @@ -94,7 +94,7 @@ namespace Umbraco.Tests.Composing private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } diff --git a/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs b/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs index c13d141fa5..01c93a40ec 100644 --- a/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs +++ b/src/Umbraco.Tests/Migrations/AdvancedMigrationTests.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CreateTableOfTDto() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) @@ -53,7 +53,7 @@ namespace Umbraco.Tests.Migrations [Test] public void DeleteKeysAndIndexesOfTDto() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) @@ -87,7 +87,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CreateKeysAndIndexesOfTDto() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) @@ -124,7 +124,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CreateKeysAndIndexes() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) @@ -161,7 +161,7 @@ namespace Umbraco.Tests.Migrations [Test] public void CreateColumn() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var builder = Mock.Of(); Mock.Get(builder) diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index 3116087669..8dded05eab 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -55,7 +55,7 @@ namespace Umbraco.Tests.Models var mediaTypeService = Mock.Of(); var memberTypeService = Mock.Of(); Composition.Register(_ => ServiceContext.CreatePartial(dataTypeService: dataTypeService, contentTypeBaseServiceProvider: new ContentTypeBaseServiceProvider(_contentTypeService, mediaTypeService, memberTypeService))); - + } [Test] @@ -236,7 +236,7 @@ namespace Umbraco.Tests.Models private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } diff --git a/src/Umbraco.Tests/Models/ContentTypeTests.cs b/src/Umbraco.Tests/Models/ContentTypeTests.cs index 9c3b976bf3..74229dd5d6 100644 --- a/src/Umbraco.Tests/Models/ContentTypeTests.cs +++ b/src/Umbraco.Tests/Models/ContentTypeTests.cs @@ -129,7 +129,7 @@ namespace Umbraco.Tests.Models private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } diff --git a/src/Umbraco.Tests/Persistence/NPocoTests/NPocoBulkInsertTests.cs b/src/Umbraco.Tests/Persistence/NPocoTests/NPocoBulkInsertTests.cs index 2a6c1f4e12..85b07d4828 100644 --- a/src/Umbraco.Tests/Persistence/NPocoTests/NPocoBulkInsertTests.cs +++ b/src/Umbraco.Tests/Persistence/NPocoTests/NPocoBulkInsertTests.cs @@ -92,7 +92,7 @@ namespace Umbraco.Tests.Persistence.NPocoTests // create the db // prob not what we want, this is not a real database, but hey, the test is ignored anyways // we'll fix this when we have proper testing infrastructure - var dbSqlServer = TestObjects.GetUmbracoSqlServerDatabase(new DebugDiagnosticsLogger()); + var dbSqlServer = TestObjects.GetUmbracoSqlServerDatabase(new DebugDiagnosticsLogger(new MessageTemplates())); //drop the table dbSqlServer.Execute("DROP TABLE [umbracoServer]"); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 5850153100..7cf3c008f1 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -89,7 +89,7 @@ namespace Umbraco.Tests.Runtimes // test runtime public class TestRuntime : CoreRuntime { - protected override ILogger GetLogger() => new DebugDiagnosticsLogger(); + protected override ILogger GetLogger() => new DebugDiagnosticsLogger(new MessageTemplates()); protected override IProfiler GetProfiler() => new TestProfiler(); // must override the database factory diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index d0258a100f..fdeb743b6c 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -56,7 +56,7 @@ namespace Umbraco.Tests.Runtimes // FIXME: we need a better management of settings here (and, true config files?) // create the very basic and essential things we need - var logger = new ConsoleLogger(); + var logger = new ConsoleLogger(new MessageTemplates()); var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = new AppCaches(); // FIXME: has HttpRuntime stuff? @@ -244,7 +244,7 @@ namespace Umbraco.Tests.Runtimes // - assigning the factory to Current.Factory // create the very basic and essential things we need - var logger = new ConsoleLogger(); + var logger = new ConsoleLogger(new MessageTemplates()); var profiler = Mock.Of(); var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = AppCaches.Disabled; diff --git a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs index 3664717af7..27abca7cbd 100644 --- a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs +++ b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Scheduling [OneTimeSetUp] public void InitializeFixture() { - _logger = new DebugDiagnosticsLogger(); + _logger = new DebugDiagnosticsLogger(new MessageTemplates()); } [Test] diff --git a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs index 8e886d7dc9..6a65f3afbc 100644 --- a/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs +++ b/src/Umbraco.Tests/Scheduling/BackgroundTaskRunnerTests2.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Scheduling [Timeout(4000)] public async Task ThreadResumeIssue() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, logger); var work = new ThreadResumeIssueWorkItem(); runner.Add(work); @@ -76,7 +76,7 @@ namespace Umbraco.Tests.Scheduling [Ignore("Only runs in the debugger.")] public async Task DebuggerInterferenceIssue() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var runner = new BackgroundTaskRunner(new BackgroundTaskRunnerOptions { KeepAlive = true, LongRunning = true }, logger); var taskCompleted = false; runner.TaskCompleted += (sender, args) => diff --git a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs index ef80672baf..ace45fe356 100644 --- a/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs +++ b/src/Umbraco.Tests/Services/ContentServicePerformanceTest.cs @@ -47,7 +47,7 @@ namespace Umbraco.Tests.Services private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } @@ -268,7 +268,7 @@ namespace Umbraco.Tests.Services var tagRepo = new TagRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger); var commonRepository = new ContentTypeCommonRepository((IScopeAccessor)provider, tRepository, AppCaches); var languageRepository = new LanguageRepository((IScopeAccessor)provider, AppCaches.Disabled, Logger); - var ctRepository = new ContentTypeRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, commonRepository, languageRepository); + var ctRepository = new ContentTypeRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, commonRepository, languageRepository); var repository = new DocumentRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, ctRepository, tRepository, tagRepo, languageRepository); // Act diff --git a/src/Umbraco.Tests/Services/PerformanceTests.cs b/src/Umbraco.Tests/Services/PerformanceTests.cs index 9cf38e1789..0ac6eeb863 100644 --- a/src/Umbraco.Tests/Services/PerformanceTests.cs +++ b/src/Umbraco.Tests/Services/PerformanceTests.cs @@ -60,7 +60,7 @@ namespace Umbraco.Tests.Services private static IProfilingLogger GetTestProfilingLogger() { - var logger = new DebugDiagnosticsLogger(); + var logger = new DebugDiagnosticsLogger(new MessageTemplates()); var profiler = new TestProfiler(); return new ProfilingLogger(logger, profiler); } diff --git a/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs b/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs index a3e36db363..53d6078e4b 100644 --- a/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs +++ b/src/Umbraco.Tests/TestHelpers/ConsoleLogger.cs @@ -5,6 +5,13 @@ namespace Umbraco.Tests.TestHelpers { public class ConsoleLogger : ILogger { + private readonly IMessageTemplates _messageTemplates; + + public ConsoleLogger(IMessageTemplates messageTemplates) + { + _messageTemplates = messageTemplates; + } + public bool IsEnabled(Type reporting, LogLevel level) => true; @@ -27,13 +34,13 @@ namespace Umbraco.Tests.TestHelpers public void Fatal(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("FATAL {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("FATAL {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); Console.WriteLine(exception); } public void Fatal(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("FATAL {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("FATAL {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } public void Error(Type reporting, Exception exception, string message) @@ -55,13 +62,13 @@ namespace Umbraco.Tests.TestHelpers public void Error(Type reporting, Exception exception, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("ERROR {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("ERROR {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); Console.WriteLine(exception); } public void Error(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("ERROR {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("ERROR {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } public void Warn(Type reporting, string message) @@ -71,7 +78,7 @@ namespace Umbraco.Tests.TestHelpers public void Warn(Type reporting, string message, params object[] propertyValues) { - Console.WriteLine("WARN {0} - {1}", reporting.Name, MessageTemplates.Render(message, propertyValues)); + Console.WriteLine("WARN {0} - {1}", reporting.Name, _messageTemplates.Render(message, propertyValues)); } public void Warn(Type reporting, Exception exception, string message) @@ -82,13 +89,13 @@ namespace Umbraco.Tests.TestHelpers public void Warn(Type reporting, Exception exception, string message, params object[] propertyValues) { - Console.WriteLine("WARN {0} - {1}", reporting.Name, MessageTemplates.Render(message, propertyValues)); + Console.WriteLine("WARN {0} - {1}", reporting.Name, _messageTemplates.Render(message, propertyValues)); Console.WriteLine(exception); } public void Info(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("INFO {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("INFO {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } public void Info(Type reporting, string message) @@ -103,7 +110,7 @@ namespace Umbraco.Tests.TestHelpers public void Debug(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("DEBUG {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("DEBUG {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } public void Verbose(Type reporting, string message) @@ -113,7 +120,7 @@ namespace Umbraco.Tests.TestHelpers public void Verbose(Type reporting, string messageTemplate, params object[] propertyValues) { - Console.WriteLine("VERBOSE {0} - {1}", reporting.Name, MessageTemplates.Render(messageTemplate, propertyValues)); + Console.WriteLine("VERBOSE {0} - {1}", reporting.Name, _messageTemplates.Render(messageTemplate, propertyValues)); } } } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 7e72a5aefb..2f86bddb3b 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -190,7 +190,7 @@ namespace Umbraco.Tests.Testing profiler = new LogProfiler(logger); break; case UmbracoTestOptions.Logger.Console: - logger = new ConsoleLogger(); + logger = new ConsoleLogger(new MessageTemplates()); profiler = new LogProfiler(logger); break; default: From a0138af362be2f4640ccb326f715dc1dd1ae3760 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 10:56:11 +0100 Subject: [PATCH 11/61] Move a small part of current --- src/Umbraco.Abstractions/Composing/Current.cs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Umbraco.Abstractions/Composing/Current.cs diff --git a/src/Umbraco.Abstractions/Composing/Current.cs b/src/Umbraco.Abstractions/Composing/Current.cs new file mode 100644 index 0000000000..39a7f5c8be --- /dev/null +++ b/src/Umbraco.Abstractions/Composing/Current.cs @@ -0,0 +1,58 @@ +using System; +using Umbraco.Core.Logging; + +namespace Umbraco.Core.Composing +{ + /// + /// Provides a static service locator for most singletons. + /// + /// + /// This class is initialized with the container in UmbracoApplicationBase, + /// right after the container is created in UmbracoApplicationBase.HandleApplicationStart. + /// Obviously, this is a service locator, which some may consider an anti-pattern. And yet, + /// practically, it works. + /// + public static class CurrentCore + { + private static IFactory _factory; + + private static ILogger _logger; + private static IProfiler _profiler; + private static IProfilingLogger _profilingLogger; + + /// + /// Gets or sets the factory. + /// + public static IFactory Factory + { + get + { + if (_factory == null) throw new InvalidOperationException("No factory has been set."); + return _factory; + } + set + { + if (_factory != null) throw new InvalidOperationException("A factory has already been set."); + // if (_configs != null) throw new InvalidOperationException("Configs are unlocked."); + _factory = value; + } + } + + internal static bool HasFactory => _factory != null; + + #region Getters + + public static ILogger Logger + => _logger ?? (_logger = _factory?.TryGetInstance() ?? throw new Exception("TODO Fix")); //?? new DebugDiagnosticsLogger(new MessageTemplates())); + + public static IProfiler Profiler + => _profiler ?? (_profiler = _factory?.TryGetInstance() + ?? new LogProfiler(Logger)); + + public static IProfilingLogger ProfilingLogger + => _profilingLogger ?? (_profilingLogger = _factory?.TryGetInstance()) + ?? new ProfilingLogger(Logger, Profiler); + + #endregion + } +} From 4f5a5a09b4aed595216d7ccc2809a108c32d0121 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 13:35:34 +0100 Subject: [PATCH 12/61] Move events --- .../Composing/ComponentCollection.cs | 0 .../Composing/ComponentCollectionBuilder.cs | 0 src/Umbraco.Abstractions/Composing/Current.cs | 2 +- .../CancellableEnumerableObjectEventArgs.cs | 1 - ...ancellableObjectEventArgsOfTEventObject.cs | 0 .../Events/CopyEventArgs.cs | 0 .../Events/DeleteEventArgs.cs | 2 +- .../Events/DeleteRevisionsEventArgs.cs | 0 .../Events/EventExtensions.cs | 0 .../Events/MoveEventArgs.cs | 0 .../Events/NewEventArgs.cs | 0 .../Events/PublishEventArgs.cs | 0 .../Events/RecycleBinEventArgs.cs | 4 --- .../Events/RolesEventArgs.cs | 0 .../Events/RollbackEventArgs.cs | 0 .../Events/SaveEventArgs.cs | 0 .../Events/SendToPublishEventArgs.cs | 0 .../Events/TransientEventMessagesFactory.cs | 2 +- .../IIgnoreUserStartNodesConfig.cs | 2 +- .../Umbraco.Configuration.csproj | 31 +++++++++++++++++++ src/Umbraco.Core/ConfigsExtensions.cs | 2 +- .../Configuration/Grid/GridConfig.cs | 2 +- .../Configuration/Grid/GridEditorsConfig.cs | 4 +-- src/Umbraco.Core/Manifest/IManifestParser.cs | 23 ++++++++++++++ src/Umbraco.Core/Manifest/ManifestParser.cs | 6 ++-- .../IDataEditor.cs | 1 - .../ParameterEditorCollection.cs | 6 ++-- .../PropertyEditorCollection.cs | 6 ++-- .../Runtime/CoreInitialComposer.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 25 +++------------ .../Manifest/ManifestParserTests.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 3 +- .../ContentAppFactoryCollectionBuilder.cs | 2 +- .../Dashboards/DashboardCollectionBuilder.cs | 2 +- .../Editors/BackOfficeController.cs | 4 +-- .../JavaScript/CssInitialization.cs | 4 +-- .../JavaScript/JsInitialization.cs | 4 +-- .../Sections/SectionCollectionBuilder.cs | 2 +- src/umbraco.sln | 6 ++++ 39 files changed, 94 insertions(+), 56 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Composing/ComponentCollection.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Composing/ComponentCollectionBuilder.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/CancellableEnumerableObjectEventArgs.cs (99%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/CancellableObjectEventArgsOfTEventObject.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/CopyEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/DeleteEventArgs.cs (99%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/DeleteRevisionsEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/EventExtensions.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/MoveEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/NewEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/PublishEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/RecycleBinEventArgs.cs (95%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/RolesEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/RollbackEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/SaveEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/SendToPublishEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/TransientEventMessagesFactory.cs (81%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PropertyEditors/IIgnoreUserStartNodesConfig.cs (82%) create mode 100644 src/Umbraco.Configuration/Umbraco.Configuration.csproj create mode 100644 src/Umbraco.Core/Manifest/IManifestParser.cs rename src/Umbraco.Core/{PropertyEditors => Models}/IDataEditor.cs (99%) diff --git a/src/Umbraco.Core/Composing/ComponentCollection.cs b/src/Umbraco.Abstractions/Composing/ComponentCollection.cs similarity index 100% rename from src/Umbraco.Core/Composing/ComponentCollection.cs rename to src/Umbraco.Abstractions/Composing/ComponentCollection.cs diff --git a/src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs b/src/Umbraco.Abstractions/Composing/ComponentCollectionBuilder.cs similarity index 100% rename from src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs rename to src/Umbraco.Abstractions/Composing/ComponentCollectionBuilder.cs diff --git a/src/Umbraco.Abstractions/Composing/Current.cs b/src/Umbraco.Abstractions/Composing/Current.cs index 39a7f5c8be..9f8168f1a9 100644 --- a/src/Umbraco.Abstractions/Composing/Current.cs +++ b/src/Umbraco.Abstractions/Composing/Current.cs @@ -38,7 +38,7 @@ namespace Umbraco.Core.Composing } } - internal static bool HasFactory => _factory != null; + public static bool HasFactory => _factory != null; #region Getters diff --git a/src/Umbraco.Core/Events/CancellableEnumerableObjectEventArgs.cs b/src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs similarity index 99% rename from src/Umbraco.Core/Events/CancellableEnumerableObjectEventArgs.cs rename to src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs index 1d52d0d847..5ac77d6253 100644 --- a/src/Umbraco.Core/Events/CancellableEnumerableObjectEventArgs.cs +++ b/src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs @@ -6,7 +6,6 @@ namespace Umbraco.Core.Events { /// /// Represents event data, for events that support cancellation, and expose impacted objects. - /// /// The type of the exposed, impacted objects. public class CancellableEnumerableObjectEventArgs : CancellableObjectEventArgs>, IEquatable> { diff --git a/src/Umbraco.Core/Events/CancellableObjectEventArgsOfTEventObject.cs b/src/Umbraco.Abstractions/Events/CancellableObjectEventArgsOfTEventObject.cs similarity index 100% rename from src/Umbraco.Core/Events/CancellableObjectEventArgsOfTEventObject.cs rename to src/Umbraco.Abstractions/Events/CancellableObjectEventArgsOfTEventObject.cs diff --git a/src/Umbraco.Core/Events/CopyEventArgs.cs b/src/Umbraco.Abstractions/Events/CopyEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/CopyEventArgs.cs rename to src/Umbraco.Abstractions/Events/CopyEventArgs.cs diff --git a/src/Umbraco.Core/Events/DeleteEventArgs.cs b/src/Umbraco.Abstractions/Events/DeleteEventArgs.cs similarity index 99% rename from src/Umbraco.Core/Events/DeleteEventArgs.cs rename to src/Umbraco.Abstractions/Events/DeleteEventArgs.cs index 07bbe562db..5be669886e 100644 --- a/src/Umbraco.Core/Events/DeleteEventArgs.cs +++ b/src/Umbraco.Abstractions/Events/DeleteEventArgs.cs @@ -100,7 +100,7 @@ namespace Umbraco.Core.Events public IEnumerable DeletedEntities { get => EventObject; - internal set => EventObject = value; + set => EventObject = value; } /// diff --git a/src/Umbraco.Core/Events/DeleteRevisionsEventArgs.cs b/src/Umbraco.Abstractions/Events/DeleteRevisionsEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/DeleteRevisionsEventArgs.cs rename to src/Umbraco.Abstractions/Events/DeleteRevisionsEventArgs.cs diff --git a/src/Umbraco.Core/Events/EventExtensions.cs b/src/Umbraco.Abstractions/Events/EventExtensions.cs similarity index 100% rename from src/Umbraco.Core/Events/EventExtensions.cs rename to src/Umbraco.Abstractions/Events/EventExtensions.cs diff --git a/src/Umbraco.Core/Events/MoveEventArgs.cs b/src/Umbraco.Abstractions/Events/MoveEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/MoveEventArgs.cs rename to src/Umbraco.Abstractions/Events/MoveEventArgs.cs diff --git a/src/Umbraco.Core/Events/NewEventArgs.cs b/src/Umbraco.Abstractions/Events/NewEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/NewEventArgs.cs rename to src/Umbraco.Abstractions/Events/NewEventArgs.cs diff --git a/src/Umbraco.Core/Events/PublishEventArgs.cs b/src/Umbraco.Abstractions/Events/PublishEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/PublishEventArgs.cs rename to src/Umbraco.Abstractions/Events/PublishEventArgs.cs diff --git a/src/Umbraco.Core/Events/RecycleBinEventArgs.cs b/src/Umbraco.Abstractions/Events/RecycleBinEventArgs.cs similarity index 95% rename from src/Umbraco.Core/Events/RecycleBinEventArgs.cs rename to src/Umbraco.Abstractions/Events/RecycleBinEventArgs.cs index 796952de98..3f0f3784a2 100644 --- a/src/Umbraco.Core/Events/RecycleBinEventArgs.cs +++ b/src/Umbraco.Abstractions/Events/RecycleBinEventArgs.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using Umbraco.Core.Models; namespace Umbraco.Core.Events { diff --git a/src/Umbraco.Core/Events/RolesEventArgs.cs b/src/Umbraco.Abstractions/Events/RolesEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/RolesEventArgs.cs rename to src/Umbraco.Abstractions/Events/RolesEventArgs.cs diff --git a/src/Umbraco.Core/Events/RollbackEventArgs.cs b/src/Umbraco.Abstractions/Events/RollbackEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/RollbackEventArgs.cs rename to src/Umbraco.Abstractions/Events/RollbackEventArgs.cs diff --git a/src/Umbraco.Core/Events/SaveEventArgs.cs b/src/Umbraco.Abstractions/Events/SaveEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/SaveEventArgs.cs rename to src/Umbraco.Abstractions/Events/SaveEventArgs.cs diff --git a/src/Umbraco.Core/Events/SendToPublishEventArgs.cs b/src/Umbraco.Abstractions/Events/SendToPublishEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/SendToPublishEventArgs.cs rename to src/Umbraco.Abstractions/Events/SendToPublishEventArgs.cs diff --git a/src/Umbraco.Core/Events/TransientEventMessagesFactory.cs b/src/Umbraco.Abstractions/Events/TransientEventMessagesFactory.cs similarity index 81% rename from src/Umbraco.Core/Events/TransientEventMessagesFactory.cs rename to src/Umbraco.Abstractions/Events/TransientEventMessagesFactory.cs index bd2e12dc17..7a0947c990 100644 --- a/src/Umbraco.Core/Events/TransientEventMessagesFactory.cs +++ b/src/Umbraco.Abstractions/Events/TransientEventMessagesFactory.cs @@ -3,7 +3,7 @@ /// /// A simple/default transient messages factory /// - internal class TransientEventMessagesFactory : IEventMessagesFactory + public class TransientEventMessagesFactory : IEventMessagesFactory { public EventMessages Get() { diff --git a/src/Umbraco.Core/PropertyEditors/IIgnoreUserStartNodesConfig.cs b/src/Umbraco.Abstractions/PropertyEditors/IIgnoreUserStartNodesConfig.cs similarity index 82% rename from src/Umbraco.Core/PropertyEditors/IIgnoreUserStartNodesConfig.cs rename to src/Umbraco.Abstractions/PropertyEditors/IIgnoreUserStartNodesConfig.cs index bef3f42f46..28ce8654c3 100644 --- a/src/Umbraco.Core/PropertyEditors/IIgnoreUserStartNodesConfig.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/IIgnoreUserStartNodesConfig.cs @@ -3,7 +3,7 @@ /// /// Marker interface for any editor configuration that supports Ignoring user start nodes /// - internal interface IIgnoreUserStartNodesConfig + public interface IIgnoreUserStartNodesConfig { bool IgnoreUserStartNodes { get; set; } } diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj new file mode 100644 index 0000000000..15c6ac263f --- /dev/null +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -0,0 +1,31 @@ + + + + netstandard2.0 + + + + + + + + + + + + + + + + <_UnmanagedRegistrationCache Remove="obj\Umbraco.Configuration.csproj.UnmanagedRegistration.cache" /> + + + + + + + + + + + diff --git a/src/Umbraco.Core/ConfigsExtensions.cs b/src/Umbraco.Core/ConfigsExtensions.cs index d1672c6c7f..5699540389 100644 --- a/src/Umbraco.Core/ConfigsExtensions.cs +++ b/src/Umbraco.Core/ConfigsExtensions.cs @@ -46,7 +46,7 @@ namespace Umbraco.Core factory.GetInstance(), factory.GetInstance(), configDir, - factory.GetInstance(), + factory.GetInstance(), factory.GetInstance().Debug)); } } diff --git a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridConfig.cs index 9aead74886..9691c749df 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridConfig.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Configuration.Grid { class GridConfig : IGridConfig { - public GridConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, ManifestParser manifestParser, bool isDebug) + public GridConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, IManifestParser manifestParser, bool isDebug) { EditorsConfig = new GridEditorsConfig(logger, appCaches, configFolder, manifestParser, isDebug); } diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs index d434da8c70..cab58a6d63 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs @@ -13,10 +13,10 @@ namespace Umbraco.Core.Configuration.Grid private readonly ILogger _logger; private readonly AppCaches _appCaches; private readonly DirectoryInfo _configFolder; - private readonly ManifestParser _manifestParser; + private readonly IManifestParser _manifestParser; private readonly bool _isDebug; - public GridEditorsConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, ManifestParser manifestParser, bool isDebug) + public GridEditorsConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, IManifestParser manifestParser, bool isDebug) { _logger = logger; _appCaches = appCaches; diff --git a/src/Umbraco.Core/Manifest/IManifestParser.cs b/src/Umbraco.Core/Manifest/IManifestParser.cs new file mode 100644 index 0000000000..3641396e0a --- /dev/null +++ b/src/Umbraco.Core/Manifest/IManifestParser.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Core.Manifest +{ + public interface IManifestParser + { + string Path { get; set; } + + /// + /// Gets all manifests, merged into a single manifest object. + /// + /// + PackageManifest Manifest { get; } + + /// + /// Parses a manifest. + /// + PackageManifest ParseManifest(string text); + + IEnumerable ParseGridEditors(string text); + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index efd9e92b1f..2e55d07059 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Manifest /// /// Parses the Main.js file and replaces all tokens accordingly. /// - public class ManifestParser + public class ManifestParser : IManifestParser { private static readonly string Utf8Preamble = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); @@ -153,7 +153,7 @@ namespace Umbraco.Core.Manifest /// /// Parses a manifest. /// - internal PackageManifest ParseManifest(string text) + public PackageManifest ParseManifest(string text) { if (string.IsNullOrWhiteSpace(text)) throw new ArgumentNullOrEmptyException(nameof(text)); @@ -179,7 +179,7 @@ namespace Umbraco.Core.Manifest } // purely for tests - internal IEnumerable ParseGridEditors(string text) + public IEnumerable ParseGridEditors(string text) { return JsonConvert.DeserializeObject>(text); } diff --git a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs b/src/Umbraco.Core/Models/IDataEditor.cs similarity index 99% rename from src/Umbraco.Core/PropertyEditors/IDataEditor.cs rename to src/Umbraco.Core/Models/IDataEditor.cs index 3685cc6494..5d1aece6e5 100644 --- a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs +++ b/src/Umbraco.Core/Models/IDataEditor.cs @@ -52,7 +52,6 @@ namespace Umbraco.Core.PropertyEditors /// Gets a configured value editor. /// IDataValueEditor GetValueEditor(object configuration); - /// /// Gets the configuration for the value editor. /// diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs index 4dd4a75c22..dacda815ec 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.PropertyEditors { public class ParameterEditorCollection : BuilderCollectionBase { - public ParameterEditorCollection(DataEditorCollection dataEditors, ManifestParser manifestParser) + public ParameterEditorCollection(DataEditorCollection dataEditors, IManifestParser manifestParser) : base(dataEditors .Where(x => (x.Type & EditorType.MacroParameter) > 0) .Union(manifestParser.Manifest.PropertyEditors)) @@ -15,11 +15,11 @@ namespace Umbraco.Core.PropertyEditors // note: virtual so it can be mocked public virtual IDataEditor this[string alias] => this.SingleOrDefault(x => x.Alias == alias); - + public virtual bool TryGet(string alias, out IDataEditor editor) { editor = this.FirstOrDefault(x => x.Alias == alias); return editor != null; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs index 712a66e55d..86cfde2ee4 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.PropertyEditors { public class PropertyEditorCollection : BuilderCollectionBase { - public PropertyEditorCollection(DataEditorCollection dataEditors, ManifestParser manifestParser) + public PropertyEditorCollection(DataEditorCollection dataEditors, IManifestParser manifestParser) : base(dataEditors .Where(x => (x.Type & EditorType.PropertyValue) > 0) .Union(manifestParser.Manifest.PropertyEditors)) @@ -20,11 +20,11 @@ namespace Umbraco.Core.PropertyEditors // note: virtual so it can be mocked public virtual IDataEditor this[string alias] => this.SingleOrDefault(x => x.Alias == alias); - + public virtual bool TryGet(string alias, out IDataEditor editor) { editor = this.FirstOrDefault(x => x.Alias == alias); return editor != null; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs index 1f004846d0..7ae5211876 100644 --- a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs @@ -55,7 +55,7 @@ namespace Umbraco.Core.Runtime composition.Register(); // register manifest parser, will be injected in collection builders where needed - composition.RegisterUnique(); + composition.RegisterUnique(); // register our predefined validators composition.ManifestValueValidators() diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 25de78105f..7fd5ebd75e 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -166,8 +166,6 @@ - - @@ -178,24 +176,14 @@ - - - - - - - - - - @@ -208,6 +196,7 @@ + @@ -248,6 +237,7 @@ + @@ -288,8 +278,9 @@ + + - @@ -297,12 +288,9 @@ - - - @@ -381,8 +369,6 @@ - - @@ -551,10 +537,7 @@ - - - diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index 1c90f68d62..0a187c5a8a 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -19,7 +19,7 @@ namespace Umbraco.Tests.Manifest [TestFixture] public class ManifestParserTests { - private ManifestParser _parser; + private IManifestParser _parser; [SetUp] public void Setup() diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 2f86bddb3b..75522112b8 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -365,7 +365,8 @@ namespace Umbraco.Tests.Testing // somehow property editor ends up wanting this Composition.WithCollectionBuilder(); - Composition.RegisterUnique(); + + Composition.RegisterUnique(); // note - don't register collections, use builders Composition.WithCollectionBuilder(); diff --git a/src/Umbraco.Web/ContentApps/ContentAppFactoryCollectionBuilder.cs b/src/Umbraco.Web/ContentApps/ContentAppFactoryCollectionBuilder.cs index 170b9169ef..233a5f5ac6 100644 --- a/src/Umbraco.Web/ContentApps/ContentAppFactoryCollectionBuilder.cs +++ b/src/Umbraco.Web/ContentApps/ContentAppFactoryCollectionBuilder.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.ContentApps // get the manifest parser just-in-time - injecting it in the ctor would mean that // simply getting the builder in order to configure the collection, would require // its dependencies too, and that can create cycles or other oddities - var manifestParser = factory.GetInstance(); + var manifestParser = factory.GetInstance(); return base.CreateItems(factory).Concat(manifestParser.Manifest.ContentApps.Select(x => new ManifestContentAppFactory(x))); } diff --git a/src/Umbraco.Web/Dashboards/DashboardCollectionBuilder.cs b/src/Umbraco.Web/Dashboards/DashboardCollectionBuilder.cs index 36a417e957..d790b04d46 100644 --- a/src/Umbraco.Web/Dashboards/DashboardCollectionBuilder.cs +++ b/src/Umbraco.Web/Dashboards/DashboardCollectionBuilder.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.Dashboards // get the manifest parser just-in-time - injecting it in the ctor would mean that // simply getting the builder in order to configure the collection, would require // its dependencies too, and that can create cycles or other oddities - var manifestParser = factory.GetInstance(); + var manifestParser = factory.GetInstance(); var dashboardSections = Merge(base.CreateItems(factory), manifestParser.Manifest.Dashboards); diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index e77a1b70f2..68f234a22a 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -39,13 +39,13 @@ namespace Umbraco.Web.Editors [DisableBrowserCache] public class BackOfficeController : UmbracoController { - private readonly ManifestParser _manifestParser; + private readonly IManifestParser _manifestParser; private readonly UmbracoFeatures _features; private readonly IRuntimeState _runtimeState; private BackOfficeUserManager _userManager; private BackOfficeSignInManager _signInManager; - public BackOfficeController(ManifestParser manifestParser, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) + public BackOfficeController(IManifestParser manifestParser, UmbracoFeatures features, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) : base(globalSettings, umbracoContextAccessor, services, appCaches, profilingLogger, umbracoHelper) { _manifestParser = manifestParser; diff --git a/src/Umbraco.Web/JavaScript/CssInitialization.cs b/src/Umbraco.Web/JavaScript/CssInitialization.cs index 172244038d..8cf9067606 100644 --- a/src/Umbraco.Web/JavaScript/CssInitialization.cs +++ b/src/Umbraco.Web/JavaScript/CssInitialization.cs @@ -10,9 +10,9 @@ namespace Umbraco.Web.JavaScript { internal class CssInitialization : AssetInitialization { - private readonly ManifestParser _parser; + private readonly IManifestParser _parser; - public CssInitialization(ManifestParser parser) + public CssInitialization(IManifestParser parser) { _parser = parser; } diff --git a/src/Umbraco.Web/JavaScript/JsInitialization.cs b/src/Umbraco.Web/JavaScript/JsInitialization.cs index 17e4f7b094..6956864ea3 100644 --- a/src/Umbraco.Web/JavaScript/JsInitialization.cs +++ b/src/Umbraco.Web/JavaScript/JsInitialization.cs @@ -17,9 +17,9 @@ namespace Umbraco.Web.JavaScript /// internal class JsInitialization : AssetInitialization { - private readonly ManifestParser _parser; + private readonly IManifestParser _parser; - public JsInitialization(ManifestParser parser) + public JsInitialization(IManifestParser parser) { _parser = parser; } diff --git a/src/Umbraco.Web/Sections/SectionCollectionBuilder.cs b/src/Umbraco.Web/Sections/SectionCollectionBuilder.cs index e38da85cfa..de883db83a 100644 --- a/src/Umbraco.Web/Sections/SectionCollectionBuilder.cs +++ b/src/Umbraco.Web/Sections/SectionCollectionBuilder.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.Sections // get the manifest parser just-in-time - injecting it in the ctor would mean that // simply getting the builder in order to configure the collection, would require // its dependencies too, and that can create cycles or other oddities - var manifestParser = factory.GetInstance(); + var manifestParser = factory.GetInstance(); return base.CreateItems(factory).Concat(manifestParser.Manifest.Sections); } diff --git a/src/umbraco.sln b/src/umbraco.sln index b89daf1925..07ed63c7a3 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -111,6 +111,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.ModelsBuilder.Embed EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Infrastructure", "Umbraco.Infrastructure\Umbraco.Infrastructure.csproj", "{3AE7BF57-966B-45A5-910A-954D7C554441}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Configuration", "Umbraco.Configuration\Umbraco.Configuration.csproj", "{FBE7C065-DAC0-4025-A78B-63B24D3AB00B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -155,6 +157,10 @@ Global {3AE7BF57-966B-45A5-910A-954D7C554441}.Debug|Any CPU.Build.0 = Debug|Any CPU {3AE7BF57-966B-45A5-910A-954D7C554441}.Release|Any CPU.ActiveCfg = Release|Any CPU {3AE7BF57-966B-45A5-910A-954D7C554441}.Release|Any CPU.Build.0 = Release|Any CPU + {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBE7C065-DAC0-4025-A78B-63B24D3AB00B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 99da374fbf32f9d7aa4b61ba5ef75a795f19877a Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 14:18:06 +0100 Subject: [PATCH 13/61] Move slim entities --- .../Models/Entities/EntityExtensions.cs | 7 +++---- .../Models/Entities/IMediaEntitySlim.cs | 0 .../Models/Entities/IMemberEntitySlim.cs | 0 .../Models/Entities/MediaEntitySlim.cs | 0 .../Models/Entities/MemberEntitySlim.cs | 0 src/Umbraco.Core/Umbraco.Core.csproj | 9 ++------- 6 files changed, 5 insertions(+), 11 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/EntityExtensions.cs (86%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/IMediaEntitySlim.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/IMemberEntitySlim.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/MediaEntitySlim.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/Entities/MemberEntitySlim.cs (100%) diff --git a/src/Umbraco.Core/Models/Entities/EntityExtensions.cs b/src/Umbraco.Abstractions/Models/Entities/EntityExtensions.cs similarity index 86% rename from src/Umbraco.Core/Models/Entities/EntityExtensions.cs rename to src/Umbraco.Abstractions/Models/Entities/EntityExtensions.cs index 2ee6a2d5ed..2df08f207d 100644 --- a/src/Umbraco.Core/Models/Entities/EntityExtensions.cs +++ b/src/Umbraco.Abstractions/Models/Entities/EntityExtensions.cs @@ -2,16 +2,15 @@ namespace Umbraco.Core.Models.Entities { - internal static class EntityExtensions + public static class EntityExtensions { /// /// Updates the entity when it is being saved. /// - internal static void UpdatingEntity(this IEntity entity) + public static void UpdatingEntity(this IEntity entity) { var now = DateTime.Now; - // just in case if (entity.CreateDate == default) { entity.CreateDate = now; @@ -27,7 +26,7 @@ namespace Umbraco.Core.Models.Entities /// /// Updates the entity when it is being saved for the first time. /// - internal static void AddingEntity(this IEntity entity) + public static void AddingEntity(this IEntity entity) { var now = DateTime.Now; var canBeDirty = entity as ICanBeDirty; diff --git a/src/Umbraco.Core/Models/Entities/IMediaEntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/IMediaEntitySlim.cs similarity index 100% rename from src/Umbraco.Core/Models/Entities/IMediaEntitySlim.cs rename to src/Umbraco.Abstractions/Models/Entities/IMediaEntitySlim.cs diff --git a/src/Umbraco.Core/Models/Entities/IMemberEntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/IMemberEntitySlim.cs similarity index 100% rename from src/Umbraco.Core/Models/Entities/IMemberEntitySlim.cs rename to src/Umbraco.Abstractions/Models/Entities/IMemberEntitySlim.cs diff --git a/src/Umbraco.Core/Models/Entities/MediaEntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/MediaEntitySlim.cs similarity index 100% rename from src/Umbraco.Core/Models/Entities/MediaEntitySlim.cs rename to src/Umbraco.Abstractions/Models/Entities/MediaEntitySlim.cs diff --git a/src/Umbraco.Core/Models/Entities/MemberEntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/MemberEntitySlim.cs similarity index 100% rename from src/Umbraco.Core/Models/Entities/MemberEntitySlim.cs rename to src/Umbraco.Abstractions/Models/Entities/MemberEntitySlim.cs diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 7fd5ebd75e..bb2ad5dec4 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -220,7 +220,6 @@ - @@ -258,10 +257,6 @@ - - - - @@ -274,10 +269,10 @@ - - + + From b004bf8920d11539ea82faa0ca1d9f6404a13b82 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Nov 2019 15:37:03 +0100 Subject: [PATCH 14/61] Move Configs to abstractions, and injected factory all over to create one because we need to inject stuff from system.configuration --- src/Umbraco.Abstractions/Composing/Current.cs | 2 ++ .../RegisterExtensions.cs | 0 src/Umbraco.Core/Composing/Composition.cs | 9 +----- src/Umbraco.Core/Composing/ConfigsFactory.cs | 14 +++++++++ src/Umbraco.Core/Composing/Current.cs | 4 +-- src/Umbraco.Core/Composing/IConfigsFactory.cs | 9 ++++++ src/Umbraco.Core/Runtime/CoreRuntime.cs | 5 ++-- src/Umbraco.Core/Umbraco.Core.csproj | 6 ++-- .../DistributedCache/DistributedCacheTests.cs | 2 +- .../Components/ComponentTests.cs | 30 ++++++++++--------- .../Composing/CollectionBuildersTests.cs | 2 +- .../Composing/CompositionTests.cs | 2 +- .../Composing/LazyCollectionBuilderTests.cs | 10 +++---- .../Composing/PackageActionCollectionTests.cs | 4 +-- src/Umbraco.Tests/IO/FileSystemsTests.cs | 2 +- src/Umbraco.Tests/Macros/MacroTests.cs | 2 +- src/Umbraco.Tests/Models/MacroTests.cs | 2 +- src/Umbraco.Tests/Models/MemberTests.cs | 2 +- src/Umbraco.Tests/Models/UserTests.cs | 2 +- src/Umbraco.Tests/Models/VariationTests.cs | 8 ++--- .../PropertyEditors/ImageCropperTest.cs | 2 +- .../PropertyEditorValueEditorTests.cs | 2 +- .../Published/ConvertersTests.cs | 2 +- .../PublishedContent/NuCacheChildrenTests.cs | 12 ++++---- .../PublishedContent/NuCacheTests.cs | 2 +- .../Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 6 ++-- .../Scoping/ScopeEventDispatcherTests.cs | 2 +- .../TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- 30 files changed, 87 insertions(+), 64 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/RegisterExtensions.cs (100%) create mode 100644 src/Umbraco.Core/Composing/ConfigsFactory.cs create mode 100644 src/Umbraco.Core/Composing/IConfigsFactory.cs diff --git a/src/Umbraco.Abstractions/Composing/Current.cs b/src/Umbraco.Abstractions/Composing/Current.cs index 9f8168f1a9..a1ae87d49f 100644 --- a/src/Umbraco.Abstractions/Composing/Current.cs +++ b/src/Umbraco.Abstractions/Composing/Current.cs @@ -1,5 +1,6 @@ using System; using Umbraco.Core.Logging; +using Umbraco.Core.Strings; namespace Umbraco.Core.Composing { @@ -42,6 +43,7 @@ namespace Umbraco.Core.Composing #region Getters + public static ILogger Logger => _logger ?? (_logger = _factory?.TryGetInstance() ?? throw new Exception("TODO Fix")); //?? new DebugDiagnosticsLogger(new MessageTemplates())); diff --git a/src/Umbraco.Core/RegisterExtensions.cs b/src/Umbraco.Abstractions/RegisterExtensions.cs similarity index 100% rename from src/Umbraco.Core/RegisterExtensions.cs rename to src/Umbraco.Abstractions/RegisterExtensions.cs diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Core/Composing/Composition.cs index 34c5296dce..7ff8901fc1 100644 --- a/src/Umbraco.Core/Composing/Composition.cs +++ b/src/Umbraco.Core/Composing/Composition.cs @@ -27,19 +27,12 @@ namespace Umbraco.Core.Composing /// A logger. /// The runtime state. /// Optional configs. - public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs = null) + public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs) { _register = register; TypeLoader = typeLoader; Logger = logger; RuntimeState = runtimeState; - - if (configs == null) - { - configs = new Configs(); - configs.AddCoreConfigs(); - } - Configs = configs; } diff --git a/src/Umbraco.Core/Composing/ConfigsFactory.cs b/src/Umbraco.Core/Composing/ConfigsFactory.cs new file mode 100644 index 0000000000..995ab4e3aa --- /dev/null +++ b/src/Umbraco.Core/Composing/ConfigsFactory.cs @@ -0,0 +1,14 @@ +using System.Configuration; +using Umbraco.Core.Configuration; + +namespace Umbraco.Core.Composing +{ + public class ConfigsFactory : IConfigsFactory + { + public Configs Create() { + var configs = new Configs(section => ConfigurationManager.GetSection(section)); + configs.AddCoreConfigs(); + return configs; + } + } +} diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index ed64347816..01fcbaa9e8 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -93,11 +93,11 @@ namespace Umbraco.Core.Composing /// Unlocks so that it is possible to add configurations /// directly to without having to wire composition. /// - public static void UnlockConfigs() + public static void UnlockConfigs(IConfigsFactory configsFactory) { if (_factory != null) throw new InvalidOperationException("Cannot unlock configs when a factory has been set."); - _configs = new Configs(); + _configs = configsFactory.Create(); } internal static event EventHandler Resetted; diff --git a/src/Umbraco.Core/Composing/IConfigsFactory.cs b/src/Umbraco.Core/Composing/IConfigsFactory.cs new file mode 100644 index 0000000000..1b12f5e157 --- /dev/null +++ b/src/Umbraco.Core/Composing/IConfigsFactory.cs @@ -0,0 +1,9 @@ +using Umbraco.Core.Configuration; + +namespace Umbraco.Core.Composing +{ + public interface IConfigsFactory + { + Configs Create(); + } +} diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 5b069641c4..d9c8ff05d3 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Diagnostics; using System.Web; using System.Web.Hosting; @@ -345,8 +346,8 @@ namespace Umbraco.Core.Runtime /// protected virtual Configs GetConfigs() { - var configs = new Configs(); - configs.AddCoreConfigs(); + var configs = new ConfigsFactory().Create(); + return configs; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index bb2ad5dec4..f40f81ef71 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -158,7 +158,9 @@ + + @@ -254,6 +256,7 @@ + @@ -316,7 +319,6 @@ - @@ -361,7 +363,6 @@ - @@ -596,7 +597,6 @@ - diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index 650cc64720..54318ace15 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -25,7 +25,7 @@ namespace Umbraco.Tests.Cache.DistributedCache { var register = RegisterFactory.Create(); - var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.RegisterUnique(_ => new TestServerRegistrar()); composition.RegisterUnique(_ => new TestServerMessenger()); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 2ba94d8c78..73fc4bb4af 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Compose; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; @@ -23,6 +24,7 @@ namespace Umbraco.Tests.Components private static readonly List Composed = new List(); private static readonly List Initialized = new List(); private static readonly List Terminated = new List(); + private static readonly Configs Configs = new ConfigsFactory().Create(); private static IFactory MockFactory(Action> setup = null) { @@ -65,7 +67,7 @@ namespace Umbraco.Tests.Components public void Boot1A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -104,7 +106,7 @@ namespace Umbraco.Tests.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -120,7 +122,7 @@ namespace Umbraco.Tests.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -135,7 +137,7 @@ namespace Umbraco.Tests.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -152,7 +154,7 @@ namespace Umbraco.Tests.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -175,7 +177,7 @@ namespace Umbraco.Tests.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -210,7 +212,7 @@ namespace Umbraco.Tests.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Mock.Of()); @@ -236,7 +238,7 @@ namespace Umbraco.Tests.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Mock.Of()); @@ -251,7 +253,7 @@ namespace Umbraco.Tests.Components public void Requires2A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Mock.Of()); @@ -268,7 +270,7 @@ namespace Umbraco.Tests.Components { var register = MockRegister(); var factory = MockFactory(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), Configs); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Mock.Of()); @@ -287,7 +289,7 @@ namespace Umbraco.Tests.Components public void WeakDependencies() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); var types = new[] { typeof(Composer10) }; var composers = new Composers(composition, types, Mock.Of()); @@ -326,7 +328,7 @@ namespace Umbraco.Tests.Components public void DisableMissing() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); var types = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list var composers = new Composers(composition, types, Mock.Of()); @@ -341,7 +343,7 @@ namespace Umbraco.Tests.Components public void AttributesPriorities() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown)); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), Configs); var types = new[] { typeof(Composer26) }; // 26 disabled by assembly attribute var composers = new Composers(composition, types, Mock.Of()); @@ -364,7 +366,7 @@ namespace Umbraco.Tests.Components var typeLoader = new TypeLoader(AppCaches.Disabled.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), Mock.Of()); var register = MockRegister(); - var composition = new Composition(register, typeLoader, Mock.Of(), MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, typeLoader, Mock.Of(), MockRuntimeState(RuntimeLevel.Run), Configs); var types = typeLoader.GetTypes().Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web")); var composers = new Composers(composition, types, Mock.Of()); diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index ec757e09f0..4303f59916 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -21,7 +21,7 @@ namespace Umbraco.Tests.Composing Current.Reset(); var register = RegisterFactory.Create(); - _composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + _composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); } [TearDown] diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index 33855a8bfb..72f7e99ca6 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -37,7 +37,7 @@ namespace Umbraco.Tests.Composing var logger = new ProfilingLogger(Mock.Of(), Mock.Of()); var typeLoader = new TypeLoader(Mock.Of(), IOHelper.MapPath("~/App_Data/TEMP"), logger); - var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of()); + var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of(), new ConfigsFactory().Create()); // create the factory, ensure it is the mocked factory var factory = composition.CreateFactory(); diff --git a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs index 3996eba89f..69e8524b7c 100644 --- a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs @@ -40,7 +40,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypes() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add() @@ -66,7 +66,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesProducers() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add(() => new[] { typeof(TransientObject3), typeof(TransientObject2) }) @@ -91,7 +91,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderHandlesTypesAndProducers() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add() @@ -117,7 +117,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderThrowsOnIllegalTypes() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add() @@ -139,7 +139,7 @@ namespace Umbraco.Tests.Composing public void LazyCollectionBuilderCanExcludeTypes() { var container = CreateRegister(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add() diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index 07db4be3d3..57f691eea5 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -19,8 +19,8 @@ namespace Umbraco.Tests.Composing public void PackageActionCollectionBuilderWorks() { var container = RegisterFactory.Create(); - - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Add(() => TypeLoader.GetPackageActions()); diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index b21faec586..28c1817862 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -28,7 +28,7 @@ namespace Umbraco.Tests.IO { _register = RegisterFactory.Create(); - var composition = new Composition(_register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(_register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.Register(_ => Mock.Of()); composition.Register(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index 9cc1d14954..4700edc64b 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.Macros //Current.ApplicationContext = new ApplicationContext(cacheHelper, new ProfilingLogger(Mock.Of(), Mock.Of())); Current.Reset(); - Current.UnlockConfigs(); + Current.UnlockConfigs(new ConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/MacroTests.cs b/src/Umbraco.Tests/Models/MacroTests.cs index d980cd1d58..117301815e 100644 --- a/src/Umbraco.Tests/Models/MacroTests.cs +++ b/src/Umbraco.Tests/Models/MacroTests.cs @@ -15,7 +15,7 @@ namespace Umbraco.Tests.Models public void Init() { Current.Reset(); - Current.UnlockConfigs(); + Current.UnlockConfigs(new ConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/MemberTests.cs b/src/Umbraco.Tests/Models/MemberTests.cs index 5e92ad7ccf..9b478304d1 100644 --- a/src/Umbraco.Tests/Models/MemberTests.cs +++ b/src/Umbraco.Tests/Models/MemberTests.cs @@ -17,7 +17,7 @@ namespace Umbraco.Tests.Models public void Setup() { Current.Reset(); - Current.UnlockConfigs(); + Current.UnlockConfigs(new ConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index 797b79381a..8cc66d5eb0 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -16,7 +16,7 @@ namespace Umbraco.Tests.Models public void Setup() { Current.Reset(); - Current.UnlockConfigs(); + Current.UnlockConfigs(new ConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); } diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index ab5f726894..ce78287d6d 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Models Current.Reset(); - var configs = new Configs(); + var configs = new ConfigsFactory().Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); @@ -75,7 +75,7 @@ namespace Umbraco.Tests.Models // 1. if exact is set to true: culture cannot be null when the ContentVariation.Culture flag is set // 2. if wildcards is set to false: fail when "*" is passed in as either culture or segment. // 3. ContentVariation flag is ignored when wildcards are used. - // 4. Empty string is considered the same as null + // 4. Empty string is considered the same as null #region Nothing @@ -141,7 +141,7 @@ namespace Umbraco.Tests.Models #endregion #region CultureAndSegment - + Assert4B(ContentVariation.CultureAndSegment, null, null, false, true, false, true); Assert4B(ContentVariation.CultureAndSegment, null, "", false, true, false, true); Assert4B(ContentVariation.CultureAndSegment, null, "*", false, false, false, true); @@ -163,7 +163,7 @@ namespace Umbraco.Tests.Models } /// - /// Asserts the result of + /// Asserts the result of /// /// /// diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index 8d2ab84d35..dcf225d952 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -70,7 +70,7 @@ namespace Umbraco.Tests.PropertyEditors try { var container = RegisterFactory.Create(); - var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder(); diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 764f6ac4a4..348305fbf5 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -24,7 +24,7 @@ namespace Umbraco.Tests.PropertyEditors Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; var register = RegisterFactory.Create(); - var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); register.Register(_ => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings()))); diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index 671129848c..f3dd459ba3 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -178,7 +178,7 @@ namespace Umbraco.Tests.Published Current.Reset(); var register = RegisterFactory.Create(); - var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.WithCollectionBuilder() .Append() diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index 5d32606ee7..f08d77a80f 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -54,7 +54,7 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = new Configs(); + var configs = new ConfigsFactory().Create(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); var globalSettings = new GlobalSettings(); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); @@ -1114,7 +1114,7 @@ namespace Umbraco.Tests.PublishedContent _snapshotService.Notify(new[] { - new ContentCacheRefresher.JsonPayload(1, Guid.Empty, TreeChangeTypes.RefreshNode) + new ContentCacheRefresher.JsonPayload(1, Guid.Empty, TreeChangeTypes.RefreshNode) }, out _, out _); Assert.AreEqual(2, contentStore.Test.LiveGen); @@ -1134,7 +1134,7 @@ namespace Umbraco.Tests.PublishedContent /// 2) Save and publish it /// 3) Publish it with descendants /// 4) Repeat steps 2 and 3 - /// + /// /// Which has caused an exception. To replicate this test: /// 1) RefreshBranch with kits for a branch where the top most node is unpublished /// 2) RefreshBranch with kits for the branch where the top most node is published @@ -1162,7 +1162,7 @@ namespace Umbraco.Tests.PublishedContent //children of 1 yield return CreateInvariantKit(20, 1, 1, paths); - yield return CreateInvariantKit(30, 1, 2, paths); + yield return CreateInvariantKit(30, 1, 2, paths); yield return CreateInvariantKit(40, 1, 3, paths); } @@ -1199,12 +1199,12 @@ namespace Umbraco.Tests.PublishedContent var (gen, contentNode) = contentStore.Test.GetValues(1)[0]; Assert.AreEqual(assertGen, gen); //even when unpublishing/re-publishing/etc... the linked list is always maintained - AssertLinkedNode(contentNode, 100, 2, 3, 20, 40); + AssertLinkedNode(contentNode, 100, 2, 3, 20, 40); } //unpublish the root ChangePublishFlagOfRoot(false, 2, TreeChangeTypes.RefreshBranch); - + //publish the root (since it's not published, it will cause a RefreshBranch) ChangePublishFlagOfRoot(true, 3, TreeChangeTypes.RefreshBranch); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 0e05e6baad..7dba201b0a 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -49,7 +49,7 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = new Configs(); + var configs = new ConfigsFactory().Create(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); var globalSettings = new GlobalSettings(); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 7cf3c008f1..449cddfcc6 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -104,7 +104,7 @@ namespace Umbraco.Tests.Runtimes protected override Configs GetConfigs() { - var configs = new Configs(); + var configs = new ConfigsFactory().Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); return configs; diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index fdeb743b6c..60e86ad5b0 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -64,10 +64,11 @@ namespace Umbraco.Tests.Runtimes var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var mainDom = new SimpleMainDom(); var runtimeState = new RuntimeState(logger, null, null, new Lazy(() => mainDom), new Lazy(() => factory.GetInstance())); + var configs = new ConfigsFactory().Create(); // create the register and the composition var register = RegisterFactory.Create(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState); // create the core runtime and have it compose itself @@ -254,10 +255,11 @@ namespace Umbraco.Tests.Runtimes Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run); var mainDom = Mock.Of(); Mock.Get(mainDom).Setup(x => x.IsMainDom).Returns(true); + var configs = new ConfigsFactory().Create(); // create the register and the composition var register = RegisterFactory.Create(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState); // create the core runtime and have it compose itself diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index 001553a8ae..b964f89be8 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Tests.Scoping var register = RegisterFactory.Create(); - var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(register, new TypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); _testObjects = new TestObjects(register); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index f62effcb62..a042803639 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -42,7 +42,7 @@ namespace Umbraco.Tests.TestHelpers logger, false); - var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); composition.RegisterUnique(_ => Mock.Of()); composition.RegisterUnique(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 75522112b8..5e21f5de63 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -134,7 +134,7 @@ namespace Umbraco.Tests.Testing var register = RegisterFactory.Create(); - Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run)); + Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); Composition.RegisterUnique(typeLoader); Composition.RegisterUnique(logger); From 48437adb4701deef12a5580a06607f6c6362c612 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 08:00:48 +0100 Subject: [PATCH 15/61] Move Configs to abstractions --- .../Configuration/Configs.cs | 20 ++++++++++++------- .../Configuration}/IConfigsFactory.cs | 4 +--- src/Umbraco.Abstractions/Services/IRuntime.cs | 3 ++- .../ConfigsFactory.cs | 3 +-- src/Umbraco.Core/Configuration/CoreDebug.cs | 3 ++- src/Umbraco.Core/Runtime/CoreRuntime.cs | 12 +++++------ src/Umbraco.Core/Umbraco.Core.csproj | 3 +-- .../DistributedCache/DistributedCacheTests.cs | 1 + .../Composing/CollectionBuildersTests.cs | 1 + .../Composing/CompositionTests.cs | 1 + .../Composing/PackageActionCollectionTests.cs | 1 + src/Umbraco.Tests/IO/FileSystemsTests.cs | 1 + src/Umbraco.Tests/Macros/MacroTests.cs | 1 + src/Umbraco.Tests/Models/MacroTests.cs | 1 + src/Umbraco.Tests/Models/MemberTests.cs | 1 + src/Umbraco.Tests/Models/UserTests.cs | 1 + .../PropertyEditorValueEditorTests.cs | 1 + .../Published/ConvertersTests.cs | 1 + .../Runtimes/CoreRuntimeTests.cs | 8 ++++---- .../Scoping/ScopeEventDispatcherTests.cs | 1 + src/Umbraco.Web/Runtime/WebRuntime.cs | 4 ++-- src/Umbraco.Web/UmbracoApplicationBase.cs | 3 ++- 22 files changed, 46 insertions(+), 29 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Configuration/Configs.cs (83%) rename src/{Umbraco.Core/Composing => Umbraco.Abstractions/Configuration}/IConfigsFactory.cs (53%) rename src/Umbraco.Core/{Composing => Configuration}/ConfigsFactory.cs (81%) diff --git a/src/Umbraco.Core/Configuration/Configs.cs b/src/Umbraco.Abstractions/Configuration/Configs.cs similarity index 83% rename from src/Umbraco.Core/Configuration/Configs.cs rename to src/Umbraco.Abstractions/Configuration/Configs.cs index 51e1a327a0..e08c4097e4 100644 --- a/src/Umbraco.Core/Configuration/Configs.cs +++ b/src/Umbraco.Abstractions/Configuration/Configs.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Configuration; using Umbraco.Core.Composing; -using Umbraco.Core.Logging; namespace Umbraco.Core.Configuration { @@ -15,6 +13,13 @@ namespace Umbraco.Core.Configuration /// public class Configs { + private readonly Func _configGetter; + + public Configs(Func configGetter) + { + _configGetter = configGetter; + } + private readonly Dictionary> _configs = new Dictionary>(); private Dictionary> _registerings = new Dictionary>(); @@ -60,7 +65,7 @@ namespace Umbraco.Core.Configuration _configs[typeOfConfig] = new Lazy(() => { - if (Current.HasFactory) return Current.Factory.GetInstance(); + if (CurrentCore.HasFactory) return CurrentCore.Factory.GetInstance(); throw new InvalidOperationException($"Cannot get configuration of type {typeOfConfig} during composition."); }); _registerings[typeOfConfig] = register => register.Register(configFactory, Lifetime.Singleton); @@ -75,7 +80,7 @@ namespace Umbraco.Core.Configuration Add(() => GetConfig(sectionName)); } - private static TConfig GetConfig(string sectionName) + private TConfig GetConfig(string sectionName) where TConfig : class { // note: need to use SafeCallContext here because ConfigurationManager.GetSection ends up getting AppDomain.Evidence @@ -83,10 +88,11 @@ namespace Umbraco.Core.Configuration using (new SafeCallContext()) { - if ((ConfigurationManager.GetSection(sectionName) is TConfig config)) + if ((_configGetter(sectionName) is TConfig config)) return config; - var ex = new ConfigurationErrorsException($"Could not get configuration section \"{sectionName}\" from config files."); - Current.Logger.Error(ex, "Config error"); +// var ex = new ConfigurationErrorsException($"Could not get configuration section \"{sectionName}\" from config files."); + var ex = new Exception($"Could not get configuration section \"{sectionName}\" from config files."); +// Current.Logger.Error(ex, "Config error"); throw ex; } } diff --git a/src/Umbraco.Core/Composing/IConfigsFactory.cs b/src/Umbraco.Abstractions/Configuration/IConfigsFactory.cs similarity index 53% rename from src/Umbraco.Core/Composing/IConfigsFactory.cs rename to src/Umbraco.Abstractions/Configuration/IConfigsFactory.cs index 1b12f5e157..3e36f3fb55 100644 --- a/src/Umbraco.Core/Composing/IConfigsFactory.cs +++ b/src/Umbraco.Abstractions/Configuration/IConfigsFactory.cs @@ -1,6 +1,4 @@ -using Umbraco.Core.Configuration; - -namespace Umbraco.Core.Composing +namespace Umbraco.Core.Configuration { public interface IConfigsFactory { diff --git a/src/Umbraco.Abstractions/Services/IRuntime.cs b/src/Umbraco.Abstractions/Services/IRuntime.cs index d433dde12d..a7944ad256 100644 --- a/src/Umbraco.Abstractions/Services/IRuntime.cs +++ b/src/Umbraco.Abstractions/Services/IRuntime.cs @@ -1,4 +1,5 @@ using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; namespace Umbraco.Core { @@ -12,7 +13,7 @@ namespace Umbraco.Core /// /// The application register. /// The application factory. - IFactory Boot(IRegister register); + IFactory Boot(IRegister register, IConfigsFactory configsFactory); /// /// Gets the runtime state. diff --git a/src/Umbraco.Core/Composing/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs similarity index 81% rename from src/Umbraco.Core/Composing/ConfigsFactory.cs rename to src/Umbraco.Core/Configuration/ConfigsFactory.cs index 995ab4e3aa..aeeef1e653 100644 --- a/src/Umbraco.Core/Composing/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -1,7 +1,6 @@ using System.Configuration; -using Umbraco.Core.Configuration; -namespace Umbraco.Core.Composing +namespace Umbraco.Core.Configuration { public class ConfigsFactory : IConfigsFactory { diff --git a/src/Umbraco.Core/Configuration/CoreDebug.cs b/src/Umbraco.Core/Configuration/CoreDebug.cs index b24e8a3329..aa95a25990 100644 --- a/src/Umbraco.Core/Configuration/CoreDebug.cs +++ b/src/Umbraco.Core/Configuration/CoreDebug.cs @@ -1,4 +1,5 @@ using System; +using System.Configuration; namespace Umbraco.Core.Configuration { @@ -6,7 +7,7 @@ namespace Umbraco.Core.Configuration { public CoreDebug() { - var appSettings = System.Configuration.ConfigurationManager.AppSettings; + var appSettings = ConfigurationManager.AppSettings; LogUncompletedScopes = string.Equals("true", appSettings[Constants.AppSettings.Debug.LogUncompletedScopes], StringComparison.OrdinalIgnoreCase); DumpOnTimeoutThreadAbort = string.Equals("true", appSettings[Constants.AppSettings.Debug.DumpOnTimeoutThreadAbort], StringComparison.OrdinalIgnoreCase); } diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index d9c8ff05d3..237dcece64 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -47,7 +47,7 @@ namespace Umbraco.Core.Runtime public IRuntimeState State => _state; /// - public virtual IFactory Boot(IRegister register) + public virtual IFactory Boot(IRegister register, IConfigsFactory configsFactory) { // create and register the essential services // ie the bare minimum required to boot @@ -82,7 +82,7 @@ namespace Umbraco.Core.Runtime ConfigureUnhandledException(); ConfigureApplicationRootPath(); - Boot(register, timer); + Boot(register, timer, configsFactory); } return _factory; @@ -91,7 +91,7 @@ namespace Umbraco.Core.Runtime /// /// Boots the runtime within a timer. /// - protected virtual IFactory Boot(IRegister register, DisposableTimer timer) + protected virtual IFactory Boot(IRegister register, DisposableTimer timer, IConfigsFactory configsFactory) { Composition composition = null; @@ -110,7 +110,7 @@ namespace Umbraco.Core.Runtime var databaseFactory = GetDatabaseFactory(); // configs - var configs = GetConfigs(); + var configs = GetConfigs(configsFactory); // type loader var typeLoader = new TypeLoader(appCaches.RuntimeCache, configs.Global().LocalTempPath, ProfilingLogger); @@ -344,9 +344,9 @@ namespace Umbraco.Core.Runtime /// /// Gets the configurations. /// - protected virtual Configs GetConfigs() + protected virtual Configs GetConfigs(IConfigsFactory configsFactory) { - var configs = new ConfigsFactory().Create(); + var configs = configsFactory.Create(); return configs; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index f40f81ef71..5755532cd6 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -158,9 +158,7 @@ - - @@ -176,6 +174,7 @@ + diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index 54318ace15..b752cb6a90 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Sync; using Umbraco.Tests.Components; diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index 4303f59916..25d46a3cdc 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -5,6 +5,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Tests.Components; diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index 72f7e99ca6..06c9c0b786 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index 57f691eea5..0073a4d624 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -6,6 +6,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.PackageActions; using Umbraco.Tests.Components; diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 28c1817862..2a32a1bc27 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Services; using Umbraco.Tests.Components; using Umbraco.Tests.TestHelpers; using Umbraco.Core.Composing.CompositionExtensions; +using Umbraco.Core.Configuration; using FileSystems = Umbraco.Core.IO.FileSystems; namespace Umbraco.Tests.IO diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index 4700edc64b..e813424ad6 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -2,6 +2,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Tests.TestHelpers; using Umbraco.Web.Macros; diff --git a/src/Umbraco.Tests/Models/MacroTests.cs b/src/Umbraco.Tests/Models/MacroTests.cs index 117301815e..e96a8c7915 100644 --- a/src/Umbraco.Tests/Models/MacroTests.cs +++ b/src/Umbraco.Tests/Models/MacroTests.cs @@ -2,6 +2,7 @@ using System.Linq; using NUnit.Framework; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Tests.TestHelpers; diff --git a/src/Umbraco.Tests/Models/MemberTests.cs b/src/Umbraco.Tests/Models/MemberTests.cs index 9b478304d1..666b9a8ab1 100644 --- a/src/Umbraco.Tests/Models/MemberTests.cs +++ b/src/Umbraco.Tests/Models/MemberTests.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Linq; using NUnit.Framework; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Serialization; using Umbraco.Tests.TestHelpers; diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index 8cc66d5eb0..b8151fc944 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Linq; using NUnit.Framework; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Models.Membership; using Umbraco.Core.Serialization; using Umbraco.Tests.TestHelpers; diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index 348305fbf5..c1b80b97b1 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -4,6 +4,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index f3dd459ba3..01e14edf12 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -5,6 +5,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 449cddfcc6..daf4f4afe6 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -102,9 +102,9 @@ namespace Umbraco.Tests.Runtimes return mock.Object; } - protected override Configs GetConfigs() + protected override Configs GetConfigs(IConfigsFactory configsFactory) { - var configs = new ConfigsFactory().Create(); + var configs = configsFactory.Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); return configs; @@ -142,9 +142,9 @@ namespace Umbraco.Tests.Runtimes private IMainDom _mainDom; - public override IFactory Boot(IRegister container) + public override IFactory Boot(IRegister container, IConfigsFactory configsFactory) { - var factory = base.Boot(container); + var factory = base.Boot(container, configsFactory); _mainDom = factory.GetInstance(); return factory; } diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index b964f89be8..1597ef35cc 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -11,6 +11,7 @@ using Umbraco.Core.Scoping; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Services; using Umbraco.Tests.Components; diff --git a/src/Umbraco.Web/Runtime/WebRuntime.cs b/src/Umbraco.Web/Runtime/WebRuntime.cs index 13cd717fd1..ede500e599 100644 --- a/src/Umbraco.Web/Runtime/WebRuntime.cs +++ b/src/Umbraco.Web/Runtime/WebRuntime.cs @@ -27,7 +27,7 @@ namespace Umbraco.Web.Runtime } /// - public override IFactory Boot(IRegister register) + public override IFactory Boot(IRegister register, IConfigsFactory configsFactory) { // create and start asap to profile boot var debug = GlobalSettings.DebugMode; @@ -43,7 +43,7 @@ namespace Umbraco.Web.Runtime _webProfiler = new VoidProfiler(); } - var factory = base.Boot(register); + var factory = base.Boot(register, configsFactory); // now (and only now) is the time to switch over to perWebRequest scopes. // up until that point we may not have a request, and scoped services would diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 59b5b1779b..24800500a8 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -5,6 +5,7 @@ using System.Web; using System.Web.Hosting; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; @@ -62,7 +63,7 @@ namespace Umbraco.Web // the boot manager is responsible for registrations var register = GetRegister(); _runtime = GetRuntime(); - _runtime.Boot(register); + _runtime.Boot(register, new ConfigsFactory()); } // called by ASP.NET (auto event wireup) once per app domain From 3913742b981d724df43255518b41fe3c43bf8686 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 18:29:16 +1100 Subject: [PATCH 16/61] Removes totally unused CacheItemRemovedCallback --- src/Umbraco.Core/Cache/AppCacheExtensions.cs | 4 +- src/Umbraco.Core/Cache/DeepCloneAppCache.cs | 8 ++-- src/Umbraco.Core/Cache/IAppPolicyCache.cs | 4 -- src/Umbraco.Core/Cache/NoAppCache.cs | 4 +- src/Umbraco.Core/Cache/ObjectCacheAppCache.cs | 38 +++---------------- src/Umbraco.Core/Cache/WebCachingAppCache.cs | 16 ++++---- src/Umbraco.Core/Umbraco.Core.csproj | 2 +- .../Cache/DefaultCachePolicyTests.cs | 4 +- .../Cache/FullDataSetCachePolicyTests.cs | 6 +-- .../Cache/SingleItemsOnlyCachePolicyTests.cs | 4 +- 10 files changed, 29 insertions(+), 61 deletions(-) diff --git a/src/Umbraco.Core/Cache/AppCacheExtensions.cs b/src/Umbraco.Core/Cache/AppCacheExtensions.cs index ddba8be1b2..286b6bd54d 100644 --- a/src/Umbraco.Core/Cache/AppCacheExtensions.cs +++ b/src/Umbraco.Core/Cache/AppCacheExtensions.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Cache CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { - var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, priority, removedCallback, dependentFiles); + var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, priority, dependentFiles); return result == null ? default(T) : result.TryConvertTo().Result; } @@ -32,7 +32,7 @@ namespace Umbraco.Core.Cache CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { - provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, priority, removedCallback, dependentFiles); + provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, priority, dependentFiles); } public static IEnumerable GetCacheItemsByKeySearch(this IAppCache provider, string keyStartsWith) diff --git a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs index eff06e2aad..a934f32dbf 100644 --- a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs +++ b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs @@ -67,7 +67,7 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { var cached = InnerCache.Get(key, () => { @@ -77,14 +77,14 @@ namespace Umbraco.Core.Cache return value == null ? null : CheckCloneableAndTracksChanges(value); // clone / reset to go into the cache - }, timeout, isSliding, priority, removedCallback, dependentFiles); + }, timeout, isSliding, priority, dependentFiles); // clone / reset to go into the cache return CheckCloneableAndTracksChanges(cached); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { InnerCache.Insert(key, () => { @@ -92,7 +92,7 @@ namespace Umbraco.Core.Cache var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); - }, timeout, isSliding, priority, removedCallback, dependentFiles); + }, timeout, isSliding, priority, dependentFiles); } /// diff --git a/src/Umbraco.Core/Cache/IAppPolicyCache.cs b/src/Umbraco.Core/Cache/IAppPolicyCache.cs index dd162b990d..6b09037fa1 100644 --- a/src/Umbraco.Core/Cache/IAppPolicyCache.cs +++ b/src/Umbraco.Core/Cache/IAppPolicyCache.cs @@ -18,7 +18,6 @@ namespace Umbraco.Core.Cache /// An optional cache timeout. /// An optional value indicating whether the cache timeout is sliding (default is false). /// An optional cache priority (default is Normal). - /// An optional callback to handle removals. /// Files the cache entry depends on. /// The item. object Get( @@ -27,7 +26,6 @@ namespace Umbraco.Core.Cache TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null); /// @@ -38,7 +36,6 @@ namespace Umbraco.Core.Cache /// An optional cache timeout. /// An optional value indicating whether the cache timeout is sliding (default is false). /// An optional cache priority (default is Normal). - /// An optional callback to handle removals. /// Files the cache entry depends on. void Insert( string key, @@ -46,7 +43,6 @@ namespace Umbraco.Core.Cache TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null); } } diff --git a/src/Umbraco.Core/Cache/NoAppCache.cs b/src/Umbraco.Core/Cache/NoAppCache.cs index d3359a30ba..336948bc83 100644 --- a/src/Umbraco.Core/Cache/NoAppCache.cs +++ b/src/Umbraco.Core/Cache/NoAppCache.cs @@ -42,13 +42,13 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { return factory(); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { } /// diff --git a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs index 5c4f76f51d..2701313423 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs @@ -103,7 +103,7 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { // see notes in HttpRuntimeAppCache @@ -115,7 +115,7 @@ namespace Umbraco.Core.Cache if (result == null || FastDictionaryAppCacheBase.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { result = FastDictionaryAppCacheBase.GetSafeLazy(factory); - var policy = GetPolicy(timeout, isSliding, removedCallback, dependentFiles); + var policy = GetPolicy(timeout, isSliding, dependentFiles); lck.UpgradeToWriteLock(); //NOTE: This does an add or update @@ -131,7 +131,7 @@ namespace Umbraco.Core.Cache } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. @@ -140,7 +140,7 @@ namespace Umbraco.Core.Cache var value = result.Value; // force evaluation now if (value == null) return; // do not store null values (backward compat) - var policy = GetPolicy(timeout, isSliding, removedCallback, dependentFiles); + var policy = GetPolicy(timeout, isSliding, dependentFiles); //NOTE: This does an add or update MemoryCache.Set(key, result, policy); } @@ -314,7 +314,7 @@ namespace Umbraco.Core.Cache } } - private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { var absolute = isSliding ? ObjectCache.InfiniteAbsoluteExpiration : (timeout == null ? ObjectCache.InfiniteAbsoluteExpiration : DateTime.Now.Add(timeout.Value)); var sliding = isSliding == false ? ObjectCache.NoSlidingExpiration : (timeout ?? ObjectCache.NoSlidingExpiration); @@ -330,34 +330,6 @@ namespace Umbraco.Core.Cache policy.ChangeMonitors.Add(new HostFileChangeMonitor(dependentFiles.ToList())); } - if (removedCallback != null) - { - policy.RemovedCallback = arguments => - { - //convert the reason - var reason = CacheItemRemovedReason.Removed; - switch (arguments.RemovedReason) - { - case CacheEntryRemovedReason.Removed: - reason = CacheItemRemovedReason.Removed; - break; - case CacheEntryRemovedReason.Expired: - reason = CacheItemRemovedReason.Expired; - break; - case CacheEntryRemovedReason.Evicted: - reason = CacheItemRemovedReason.Underused; - break; - case CacheEntryRemovedReason.ChangeMonitorChanged: - reason = CacheItemRemovedReason.Expired; - break; - case CacheEntryRemovedReason.CacheSpecificEviction: - reason = CacheItemRemovedReason.Underused; - break; - } - //call the callback - removedCallback(arguments.CacheItem.Key, arguments.CacheItem.Value, reason); - }; - } return policy; } } diff --git a/src/Umbraco.Core/Cache/WebCachingAppCache.cs b/src/Umbraco.Core/Cache/WebCachingAppCache.cs index c6e104221a..da3b5def1e 100644 --- a/src/Umbraco.Core/Cache/WebCachingAppCache.cs +++ b/src/Umbraco.Core/Cache/WebCachingAppCache.cs @@ -35,25 +35,25 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { CacheDependency dependency = null; if (dependentFiles != null && dependentFiles.Any()) { dependency = new CacheDependency(dependentFiles); } - return Get(key, factory, timeout, isSliding, priority, removedCallback, dependency); + return GetImpl(key, factory, timeout, isSliding, priority, dependency); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { CacheDependency dependency = null; if (dependentFiles != null && dependentFiles.Any()) { dependency = new CacheDependency(dependentFiles); } - Insert(key, factory, timeout, isSliding, priority, removedCallback, dependency); + InsertImpl(key, factory, timeout, isSliding, priority, dependency); } #region Dictionary @@ -103,7 +103,7 @@ namespace Umbraco.Core.Cache #endregion - private object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, CacheDependency dependency = null) + private object GetImpl(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheDependency dependency = null) { key = GetCacheKey(key); @@ -164,7 +164,7 @@ namespace Umbraco.Core.Cache lck.UpgradeToWriteLock(); //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update! - _cache.Insert(key, result, dependency, absolute, sliding, priority, removedCallback); + _cache.Insert(key, result, dependency, absolute, sliding, priority, null); } } @@ -180,7 +180,7 @@ namespace Umbraco.Core.Cache return value; } - private void Insert(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, CacheDependency dependency = null) + private void InsertImpl(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheDependency dependency = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. @@ -198,7 +198,7 @@ namespace Umbraco.Core.Cache { _locker.EnterWriteLock(); //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update! - _cache.Insert(cacheKey, result, dependency, absolute, sliding, priority, removedCallback); + _cache.Insert(cacheKey, result, dependency, absolute, sliding, priority, null); } finally { diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 5755532cd6..db82b976e0 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -125,6 +125,7 @@ --> + @@ -140,7 +141,6 @@ - diff --git a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs index 4161f576c9..ca91c63621 100644 --- a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Cache var isCached = false; var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; @@ -60,7 +60,7 @@ namespace Umbraco.Tests.Cache var cached = new List(); var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); diff --git a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs index a4fbdf2224..f48974657c 100644 --- a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs @@ -39,7 +39,7 @@ namespace Umbraco.Tests.Cache var isCached = false; var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; @@ -80,7 +80,7 @@ namespace Umbraco.Tests.Cache var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); @@ -123,7 +123,7 @@ namespace Umbraco.Tests.Cache var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); diff --git a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs index 2525eab45b..ea68873525 100644 --- a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Cache var cached = new List(); var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); @@ -54,7 +54,7 @@ namespace Umbraco.Tests.Cache var isCached = false; var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; From c7cf7f60e896744508ca437e2706dc6a4644d485 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 18:34:05 +1100 Subject: [PATCH 17/61] Removes CacheItemPriority since this wasn't used, or was used in one place innapropriately. --- src/Umbraco.Core/Cache/AppCacheExtensions.cs | 4 ++-- src/Umbraco.Core/Cache/DeepCloneAppCache.cs | 9 ++++----- src/Umbraco.Core/Cache/IAppPolicyCache.cs | 5 ----- src/Umbraco.Core/Cache/NoAppCache.cs | 5 ++--- src/Umbraco.Core/Cache/ObjectCacheAppCache.cs | 4 ++-- src/Umbraco.Core/Cache/WebCachingAppCache.cs | 16 ++++++++-------- .../Cache/DefaultCachePolicyTests.cs | 6 ++---- .../Cache/FullDataSetCachePolicyTests.cs | 9 +++------ .../Cache/SingleItemsOnlyCachePolicyTests.cs | 6 ++---- src/Umbraco.Web/Macros/MacroRenderer.cs | 4 +--- 10 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/Umbraco.Core/Cache/AppCacheExtensions.cs b/src/Umbraco.Core/Cache/AppCacheExtensions.cs index 286b6bd54d..a4edf6479e 100644 --- a/src/Umbraco.Core/Cache/AppCacheExtensions.cs +++ b/src/Umbraco.Core/Cache/AppCacheExtensions.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Cache CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { - var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, priority, dependentFiles); + var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles); return result == null ? default(T) : result.TryConvertTo().Result; } @@ -32,7 +32,7 @@ namespace Umbraco.Core.Cache CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { - provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, priority, dependentFiles); + provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles); } public static IEnumerable GetCacheItemsByKeySearch(this IAppCache provider, string keyStartsWith) diff --git a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs index a934f32dbf..29d147ba57 100644 --- a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs +++ b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web.Caching; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -67,7 +66,7 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) { var cached = InnerCache.Get(key, () => { @@ -77,14 +76,14 @@ namespace Umbraco.Core.Cache return value == null ? null : CheckCloneableAndTracksChanges(value); // clone / reset to go into the cache - }, timeout, isSliding, priority, dependentFiles); + }, timeout, isSliding, dependentFiles); // clone / reset to go into the cache return CheckCloneableAndTracksChanges(cached); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { InnerCache.Insert(key, () => { @@ -92,7 +91,7 @@ namespace Umbraco.Core.Cache var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); - }, timeout, isSliding, priority, dependentFiles); + }, timeout, isSliding, dependentFiles); } /// diff --git a/src/Umbraco.Core/Cache/IAppPolicyCache.cs b/src/Umbraco.Core/Cache/IAppPolicyCache.cs index 6b09037fa1..9746e80804 100644 --- a/src/Umbraco.Core/Cache/IAppPolicyCache.cs +++ b/src/Umbraco.Core/Cache/IAppPolicyCache.cs @@ -1,5 +1,4 @@ using System; -using System.Web.Caching; namespace Umbraco.Core.Cache { @@ -17,7 +16,6 @@ namespace Umbraco.Core.Cache /// A factory function that can create the item. /// An optional cache timeout. /// An optional value indicating whether the cache timeout is sliding (default is false). - /// An optional cache priority (default is Normal). /// Files the cache entry depends on. /// The item. object Get( @@ -25,7 +23,6 @@ namespace Umbraco.Core.Cache Func factory, TimeSpan? timeout, bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null); /// @@ -35,14 +32,12 @@ namespace Umbraco.Core.Cache /// A factory function that can create the item. /// An optional cache timeout. /// An optional value indicating whether the cache timeout is sliding (default is false). - /// An optional cache priority (default is Normal). /// Files the cache entry depends on. void Insert( string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null); } } diff --git a/src/Umbraco.Core/Cache/NoAppCache.cs b/src/Umbraco.Core/Cache/NoAppCache.cs index 336948bc83..24c51c935a 100644 --- a/src/Umbraco.Core/Cache/NoAppCache.cs +++ b/src/Umbraco.Core/Cache/NoAppCache.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web.Caching; namespace Umbraco.Core.Cache { @@ -42,13 +41,13 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) { return factory(); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { } /// diff --git a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs index 2701313423..016c5c3083 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs @@ -103,7 +103,7 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) { // see notes in HttpRuntimeAppCache @@ -131,7 +131,7 @@ namespace Umbraco.Core.Cache } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. diff --git a/src/Umbraco.Core/Cache/WebCachingAppCache.cs b/src/Umbraco.Core/Cache/WebCachingAppCache.cs index da3b5def1e..8711a025e0 100644 --- a/src/Umbraco.Core/Cache/WebCachingAppCache.cs +++ b/src/Umbraco.Core/Cache/WebCachingAppCache.cs @@ -35,25 +35,25 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) { CacheDependency dependency = null; if (dependentFiles != null && dependentFiles.Any()) { dependency = new CacheDependency(dependentFiles); } - return GetImpl(key, factory, timeout, isSliding, priority, dependency); + return GetImpl(key, factory, timeout, isSliding, dependency); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { CacheDependency dependency = null; if (dependentFiles != null && dependentFiles.Any()) { dependency = new CacheDependency(dependentFiles); } - InsertImpl(key, factory, timeout, isSliding, priority, dependency); + InsertImpl(key, factory, timeout, isSliding, dependency); } #region Dictionary @@ -103,7 +103,7 @@ namespace Umbraco.Core.Cache #endregion - private object GetImpl(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheDependency dependency = null) + private object GetImpl(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheDependency dependency = null) { key = GetCacheKey(key); @@ -164,7 +164,7 @@ namespace Umbraco.Core.Cache lck.UpgradeToWriteLock(); //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update! - _cache.Insert(key, result, dependency, absolute, sliding, priority, null); + _cache.Insert(key, result, dependency, absolute, sliding, CacheItemPriority.Normal, null); } } @@ -180,7 +180,7 @@ namespace Umbraco.Core.Cache return value; } - private void InsertImpl(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheDependency dependency = null) + private void InsertImpl(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheDependency dependency = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. @@ -198,7 +198,7 @@ namespace Umbraco.Core.Cache { _locker.EnterWriteLock(); //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update! - _cache.Insert(cacheKey, result, dependency, absolute, sliding, priority, null); + _cache.Insert(cacheKey, result, dependency, absolute, sliding, CacheItemPriority.Normal, null); } finally { diff --git a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs index ca91c63621..5f9e94a4fc 100644 --- a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs @@ -29,8 +29,7 @@ namespace Umbraco.Tests.Cache { var isCached = false; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; @@ -59,8 +58,7 @@ namespace Umbraco.Tests.Cache { var cached = new List(); var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); diff --git a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs index f48974657c..e0ffb7e4cd 100644 --- a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs @@ -38,8 +38,7 @@ namespace Umbraco.Tests.Cache var isCached = false; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; @@ -79,8 +78,7 @@ namespace Umbraco.Tests.Cache IList list = null; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); @@ -122,8 +120,7 @@ namespace Umbraco.Tests.Cache IList list = null; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); diff --git a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs index ea68873525..f34f4082bd 100644 --- a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs @@ -29,8 +29,7 @@ namespace Umbraco.Tests.Cache { var cached = new List(); var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); @@ -53,8 +52,7 @@ namespace Umbraco.Tests.Cache { var isCached = false; var cache = new Mock(); - cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny())) + cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index 3368def084..038a4d2431 100755 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using System.Web.Caching; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.UmbracoSettings; @@ -139,8 +138,7 @@ namespace Umbraco.Web.Macros cache.Insert( CacheKeys.MacroContentCacheKey + model.CacheIdentifier, () => macroContent, - new TimeSpan(0, 0, model.CacheDuration), - priority: CacheItemPriority.NotRemovable + new TimeSpan(0, 0, model.CacheDuration) ); _plogger.Debug("Macro content saved to cache '{MacroCacheId}'", model.CacheIdentifier); From 57fab1d34b8f50a096141a2af53b8ae4ec493602 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 18:35:21 +1100 Subject: [PATCH 18/61] Moves IAppPolicyCache --- .../Cache/IAppPolicyCache.cs | 0 src/Umbraco.Core/Umbraco.Core.csproj | 1 - 2 files changed, 1 deletion(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/IAppPolicyCache.cs (100%) diff --git a/src/Umbraco.Core/Cache/IAppPolicyCache.cs b/src/Umbraco.Abstractions/Cache/IAppPolicyCache.cs similarity index 100% rename from src/Umbraco.Core/Cache/IAppPolicyCache.cs rename to src/Umbraco.Abstractions/Cache/IAppPolicyCache.cs diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index db82b976e0..c62de7a2b6 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -125,7 +125,6 @@ --> - From 93c75372e71b4dfbe06b6fd4133a8d94b92cbef0 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 18:36:29 +1100 Subject: [PATCH 19/61] Moves IRepositoryCachePolicy --- .../Cache/IRepositoryCachePolicy.cs | 0 src/Umbraco.Core/Umbraco.Core.csproj | 1 - 2 files changed, 1 deletion(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/IRepositoryCachePolicy.cs (100%) diff --git a/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs b/src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs similarity index 100% rename from src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs rename to src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index c62de7a2b6..34fd5349ee 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -139,7 +139,6 @@ - From 0463f2a43bde6c9dd0d8e48991b0f914afcd4645 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 18:50:14 +1100 Subject: [PATCH 20/61] Moves more cache classes --- .../Cache/AppCacheExtensions.cs | 5 ----- .../Cache/AppPolicedCacheDictionary.cs | 12 ++++++------ .../Cache/IRepositoryCachePolicy.cs | 2 +- .../Cache/IsolatedCaches.cs | 0 .../Cache/NoAppCache.cs | 0 .../Cache/NoCacheRepositoryCachePolicy.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 5 ----- src/Umbraco.Web/CacheHelperExtensions.cs | 2 -- 8 files changed, 8 insertions(+), 20 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/AppCacheExtensions.cs (88%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/AppPolicedCacheDictionary.cs (87%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/IsolatedCaches.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/NoAppCache.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/NoCacheRepositoryCachePolicy.cs (93%) diff --git a/src/Umbraco.Core/Cache/AppCacheExtensions.cs b/src/Umbraco.Abstractions/Cache/AppCacheExtensions.cs similarity index 88% rename from src/Umbraco.Core/Cache/AppCacheExtensions.cs rename to src/Umbraco.Abstractions/Cache/AppCacheExtensions.cs index a4edf6479e..cbefb5d5c0 100644 --- a/src/Umbraco.Core/Cache/AppCacheExtensions.cs +++ b/src/Umbraco.Abstractions/Cache/AppCacheExtensions.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Web.Caching; namespace Umbraco.Core.Cache { @@ -15,8 +14,6 @@ namespace Umbraco.Core.Cache Func getCacheItem, TimeSpan? timeout, bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles); @@ -28,8 +25,6 @@ namespace Umbraco.Core.Cache Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, - CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles); diff --git a/src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs b/src/Umbraco.Abstractions/Cache/AppPolicedCacheDictionary.cs similarity index 87% rename from src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs rename to src/Umbraco.Abstractions/Cache/AppPolicedCacheDictionary.cs index 5c60dededa..fa13ebf088 100644 --- a/src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs +++ b/src/Umbraco.Abstractions/Cache/AppPolicedCacheDictionary.cs @@ -17,24 +17,24 @@ namespace Umbraco.Core.Cache /// protected AppPolicedCacheDictionary(Func cacheFactory) { - CacheFactory = cacheFactory; + _cacheFactory = cacheFactory; } /// /// Gets the internal cache factory, for tests only! /// - internal readonly Func CacheFactory; + private readonly Func _cacheFactory; /// /// Gets or creates a cache. /// public IAppPolicyCache GetOrCreate(TKey key) - => _caches.GetOrAdd(key, k => CacheFactory(k)); + => _caches.GetOrAdd(key, k => _cacheFactory(k)); /// /// Tries to get a cache. /// - public Attempt Get(TKey key) + protected Attempt Get(TKey key) => _caches.TryGetValue(key, out var cache) ? Attempt.Succeed(cache) : Attempt.Fail(); /// @@ -56,7 +56,7 @@ namespace Umbraco.Core.Cache /// /// Clears a cache. /// - public void ClearCache(TKey key) + protected void ClearCache(TKey key) { if (_caches.TryGetValue(key, out var cache)) cache.Clear(); @@ -71,4 +71,4 @@ namespace Umbraco.Core.Cache cache.Clear(); } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs b/src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs index 020f4f7dd9..a31e715383 100644 --- a/src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs +++ b/src/Umbraco.Abstractions/Cache/IRepositoryCachePolicy.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Scoping; namespace Umbraco.Core.Cache { - internal interface IRepositoryCachePolicy + public interface IRepositoryCachePolicy where TEntity : class, IEntity { /// diff --git a/src/Umbraco.Core/Cache/IsolatedCaches.cs b/src/Umbraco.Abstractions/Cache/IsolatedCaches.cs similarity index 100% rename from src/Umbraco.Core/Cache/IsolatedCaches.cs rename to src/Umbraco.Abstractions/Cache/IsolatedCaches.cs diff --git a/src/Umbraco.Core/Cache/NoAppCache.cs b/src/Umbraco.Abstractions/Cache/NoAppCache.cs similarity index 100% rename from src/Umbraco.Core/Cache/NoAppCache.cs rename to src/Umbraco.Abstractions/Cache/NoAppCache.cs diff --git a/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs b/src/Umbraco.Abstractions/Cache/NoCacheRepositoryCachePolicy.cs similarity index 93% rename from src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs rename to src/Umbraco.Abstractions/Cache/NoCacheRepositoryCachePolicy.cs index fecab66d84..20b57c49ff 100644 --- a/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs +++ b/src/Umbraco.Abstractions/Cache/NoCacheRepositoryCachePolicy.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Cache { - internal class NoCacheRepositoryCachePolicy : IRepositoryCachePolicy + public class NoCacheRepositoryCachePolicy : IRepositoryCachePolicy where TEntity : class, IEntity { private NoCacheRepositoryCachePolicy() { } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 34fd5349ee..644d30d38e 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -124,10 +124,8 @@ Constants.cs --> - - @@ -139,10 +137,7 @@ - - - diff --git a/src/Umbraco.Web/CacheHelperExtensions.cs b/src/Umbraco.Web/CacheHelperExtensions.cs index ae8df63415..615e6a3982 100644 --- a/src/Umbraco.Web/CacheHelperExtensions.cs +++ b/src/Umbraco.Web/CacheHelperExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Web; -using System.Web.Caching; using System.Web.Mvc; using System.Web.Mvc.Html; using Umbraco.Core.Cache; @@ -46,7 +45,6 @@ namespace Umbraco.Web return appCaches.RuntimeCache.GetCacheItem( PartialViewCacheKey + cacheKey, () => htmlHelper.Partial(partialViewName, model, viewData), - priority: CacheItemPriority.NotRemovable, //not removable, the same as macros (apparently issue #27610) timeout: new TimeSpan(0, 0, 0, cachedSeconds)); } From 235f6fbc54d1852abc85ffbb47bd241ccd452e95 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 18:57:40 +1100 Subject: [PATCH 21/61] moves DictionaryAppCache --- .../Cache/DictionaryAppCache.cs | 26 ++++++++++--------- src/Umbraco.Core/Umbraco.Core.csproj | 1 - .../Cache/HttpRequestAppCacheTests.cs | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/DictionaryAppCache.cs (71%) diff --git a/src/Umbraco.Core/Cache/DictionaryAppCache.cs b/src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs similarity index 71% rename from src/Umbraco.Core/Cache/DictionaryAppCache.cs rename to src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs index 8889630ff0..6e528165a0 100644 --- a/src/Umbraco.Core/Cache/DictionaryAppCache.cs +++ b/src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs @@ -13,25 +13,27 @@ namespace Umbraco.Core.Cache /// /// Gets the internal items dictionary, for tests only! /// - internal readonly ConcurrentDictionary Items = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _items = new ConcurrentDictionary(); + + public int Count => _items.Count; /// public virtual object Get(string key) { - return Items.TryGetValue(key, out var value) ? value : null; + return _items.TryGetValue(key, out var value) ? value : null; } /// public virtual object Get(string key, Func factory) { - return Items.GetOrAdd(key, _ => factory()); + return _items.GetOrAdd(key, _ => factory()); } /// public virtual IEnumerable SearchByKey(string keyStartsWith) { var items = new List(); - foreach (var (key, value) in Items) + foreach (var (key, value) in _items) if (key.InvariantStartsWith(keyStartsWith)) items.Add(value); return items; @@ -42,7 +44,7 @@ namespace Umbraco.Core.Cache { var compiled = new Regex(regex, RegexOptions.Compiled); var items = new List(); - foreach (var (key, value) in Items) + foreach (var (key, value) in _items) if (compiled.IsMatch(key)) items.Add(value); return items; @@ -51,46 +53,46 @@ namespace Umbraco.Core.Cache /// public virtual void Clear() { - Items.Clear(); + _items.Clear(); } /// public virtual void Clear(string key) { - Items.TryRemove(key, out _); + _items.TryRemove(key, out _); } /// public virtual void ClearOfType(string typeName) { - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType().ToString().InvariantEquals(typeName)); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType().ToString().InvariantEquals(typeName)); } /// public virtual void ClearOfType() { var typeOfT = typeof(T); - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT); } /// public virtual void ClearOfType(Func predicate) { var typeOfT = typeof(T); - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT && predicate(kvp.Key, (T)kvp.Value)); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT && predicate(kvp.Key, (T)kvp.Value)); } /// public virtual void ClearByKey(string keyStartsWith) { - Items.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)); + _items.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)); } /// public virtual void ClearByRegex(string regex) { var compiled = new Regex(regex, RegexOptions.Compiled); - Items.RemoveAll(kvp => compiled.IsMatch(kvp.Key)); + _items.RemoveAll(kvp => compiled.IsMatch(kvp.Key)); } } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 644d30d38e..b8ebde64cf 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -143,7 +143,6 @@ - diff --git a/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs index 0be38d2c55..042830e059 100644 --- a/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs +++ b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Cache protected override int GetTotalItemCount { - get { return _appCache.Items.Count; } + get { return _appCache.Count; } } } } From 7f9a3a7868c81c7806ac25f93c46011a9f24b05b Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 19:16:45 +1100 Subject: [PATCH 22/61] Creates SafeLazy to be used by all caching things instead of relying on the base class as a static that cannot be moved right now. --- src/Umbraco.Abstractions/Cache/SafeLazy.cs | 63 +++++++++++++++++ src/Umbraco.Core/Cache/DeepCloneAppCache.cs | 6 +- .../Cache/FastDictionaryAppCache.cs | 16 ++--- .../Cache/FastDictionaryAppCacheBase.cs | 68 ++----------------- src/Umbraco.Core/Cache/HttpRequestAppCache.cs | 6 +- src/Umbraco.Core/Cache/ObjectCacheAppCache.cs | 22 +++--- src/Umbraco.Core/Cache/WebCachingAppCache.cs | 10 +-- src/Umbraco.Core/Umbraco.Core.csproj | 4 +- 8 files changed, 101 insertions(+), 94 deletions(-) create mode 100644 src/Umbraco.Abstractions/Cache/SafeLazy.cs diff --git a/src/Umbraco.Abstractions/Cache/SafeLazy.cs b/src/Umbraco.Abstractions/Cache/SafeLazy.cs new file mode 100644 index 0000000000..d901a534c6 --- /dev/null +++ b/src/Umbraco.Abstractions/Cache/SafeLazy.cs @@ -0,0 +1,63 @@ +using System; +using System.Runtime.ExceptionServices; + +namespace Umbraco.Core.Cache +{ + public static class SafeLazy + { + // an object that represent a value that has not been created yet + internal static readonly object ValueNotCreated = new object(); + + public static Lazy GetSafeLazy(Func getCacheItem) + { + // try to generate the value and if it fails, + // wrap in an ExceptionHolder - would be much simpler + // to just use lazy.IsValueFaulted alas that field is + // internal + return new Lazy(() => + { + try + { + return getCacheItem(); + } + catch (Exception e) + { + return new ExceptionHolder(ExceptionDispatchInfo.Capture(e)); + } + }); + } + + public static object GetSafeLazyValue(Lazy lazy, bool onlyIfValueIsCreated = false) + { + // if onlyIfValueIsCreated, do not trigger value creation + // must return something, though, to differentiate from null values + if (onlyIfValueIsCreated && lazy.IsValueCreated == false) return ValueNotCreated; + + // if execution has thrown then lazy.IsValueCreated is false + // and lazy.IsValueFaulted is true (but internal) so we use our + // own exception holder (see Lazy source code) to return null + if (lazy.Value is ExceptionHolder) return null; + + // we have a value and execution has not thrown so returning + // here does not throw - unless we're re-entering, take care of it + try + { + return lazy.Value; + } + catch (InvalidOperationException e) + { + throw new InvalidOperationException("The method that computes a value for the cache has tried to read that value from the cache.", e); + } + } + + public class ExceptionHolder + { + public ExceptionHolder(ExceptionDispatchInfo e) + { + Exception = e; + } + + public ExceptionDispatchInfo Exception { get; } + } + } +} diff --git a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs index 29d147ba57..90367e0627 100644 --- a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs +++ b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs @@ -43,7 +43,7 @@ namespace Umbraco.Core.Cache { var cached = InnerCache.Get(key, () => { - var result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + var result = SafeLazy.GetSafeLazy(factory); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); @@ -70,7 +70,7 @@ namespace Umbraco.Core.Cache { var cached = InnerCache.Get(key, () => { - var result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + var result = SafeLazy.GetSafeLazy(factory); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); @@ -87,7 +87,7 @@ namespace Umbraco.Core.Cache { InnerCache.Insert(key, () => { - var result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + var result = SafeLazy.GetSafeLazy(factory); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); diff --git a/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs b/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs index bd545694f7..b38f36a7d8 100644 --- a/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs +++ b/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs @@ -21,16 +21,16 @@ namespace Umbraco.Core.Cache public object Get(string cacheKey) { Items.TryGetValue(cacheKey, out var result); // else null - return result == null ? null : FastDictionaryAppCacheBase.GetSafeLazyValue(result); // return exceptions as null + return result == null ? null : SafeLazy.GetSafeLazyValue(result); // return exceptions as null } /// public object Get(string cacheKey, Func getCacheItem) { - var result = Items.GetOrAdd(cacheKey, k => FastDictionaryAppCacheBase.GetSafeLazy(getCacheItem)); + var result = Items.GetOrAdd(cacheKey, k => SafeLazy.GetSafeLazy(getCacheItem)); var value = result.Value; // will not throw (safe lazy) - if (!(value is FastDictionaryAppCacheBase.ExceptionHolder eh)) + if (!(value is SafeLazy.ExceptionHolder eh)) return value; // and... it's in the cache anyway - so contrary to other cache providers, @@ -47,7 +47,7 @@ namespace Umbraco.Core.Cache { return Items .Where(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)) - .Select(kvp => FastDictionaryAppCacheBase.GetSafeLazyValue(kvp.Value)) + .Select(kvp => SafeLazy.GetSafeLazyValue(kvp.Value)) .Where(x => x != null); } @@ -57,7 +57,7 @@ namespace Umbraco.Core.Cache var compiled = new Regex(regex, RegexOptions.Compiled); return Items .Where(kvp => compiled.IsMatch(kvp.Key)) - .Select(kvp => FastDictionaryAppCacheBase.GetSafeLazyValue(kvp.Value)) + .Select(kvp => SafeLazy.GetSafeLazyValue(kvp.Value)) .Where(x => x != null); } @@ -86,7 +86,7 @@ namespace Umbraco.Core.Cache // entry.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue(x.Value, true); + var value = SafeLazy.GetSafeLazyValue(x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -108,7 +108,7 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue(x.Value, true); + var value = SafeLazy.GetSafeLazyValue(x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -130,7 +130,7 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue(x.Value, true); + var value = SafeLazy.GetSafeLazyValue(x.Value, true); if (value == null) return true; // if T is an interface remove anything that implements that interface diff --git a/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs b/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs index 21e2b63597..eb84423f32 100644 --- a/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs +++ b/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Runtime.ExceptionServices; using System.Text.RegularExpressions; using Umbraco.Core.Composing; @@ -16,9 +15,6 @@ namespace Umbraco.Core.Cache // prefix cache keys so we know which one are ours protected const string CacheItemPrefix = "umbrtmche"; - // an object that represent a value that has not been created yet - protected internal static readonly object ValueNotCreated = new object(); - #region IAppCache /// @@ -35,7 +31,7 @@ namespace Umbraco.Core.Cache { ExitReadLock(); } - return result == null ? null : GetSafeLazyValue(result); // return exceptions as null + return result == null ? null : SafeLazy.GetSafeLazyValue(result); // return exceptions as null } /// @@ -59,7 +55,7 @@ namespace Umbraco.Core.Cache } return entries - .Select(x => GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null); // backward compat, don't store null values in the cache } @@ -82,7 +78,7 @@ namespace Umbraco.Core.Cache ExitReadLock(); } return entries - .Select(x => GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null); // backward compatible, don't store null values in the cache } @@ -132,7 +128,7 @@ namespace Umbraco.Core.Cache // entry.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -162,7 +158,7 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -193,7 +189,7 @@ namespace Umbraco.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); if (value == null) return true; // if T is an interface remove anything that implements that interface @@ -272,57 +268,7 @@ namespace Umbraco.Core.Cache return $"{CacheItemPrefix}-{key}"; } - protected internal static Lazy GetSafeLazy(Func getCacheItem) - { - // try to generate the value and if it fails, - // wrap in an ExceptionHolder - would be much simpler - // to just use lazy.IsValueFaulted alas that field is - // internal - return new Lazy(() => - { - try - { - return getCacheItem(); - } - catch (Exception e) - { - return new ExceptionHolder(ExceptionDispatchInfo.Capture(e)); - } - }); - } - - protected internal static object GetSafeLazyValue(Lazy lazy, bool onlyIfValueIsCreated = false) - { - // if onlyIfValueIsCreated, do not trigger value creation - // must return something, though, to differentiate from null values - if (onlyIfValueIsCreated && lazy.IsValueCreated == false) return ValueNotCreated; - - // if execution has thrown then lazy.IsValueCreated is false - // and lazy.IsValueFaulted is true (but internal) so we use our - // own exception holder (see Lazy source code) to return null - if (lazy.Value is ExceptionHolder) return null; - - // we have a value and execution has not thrown so returning - // here does not throw - unless we're re-entering, take care of it - try - { - return lazy.Value; - } - catch (InvalidOperationException e) - { - throw new InvalidOperationException("The method that computes a value for the cache has tried to read that value from the cache.", e); - } - } - - internal class ExceptionHolder - { - public ExceptionHolder(ExceptionDispatchInfo e) - { - Exception = e; - } - - public ExceptionDispatchInfo Exception { get; } - } + #endregion } diff --git a/src/Umbraco.Core/Cache/HttpRequestAppCache.cs b/src/Umbraco.Core/Cache/HttpRequestAppCache.cs index eeebcd2622..018726538b 100644 --- a/src/Umbraco.Core/Cache/HttpRequestAppCache.cs +++ b/src/Umbraco.Core/Cache/HttpRequestAppCache.cs @@ -60,9 +60,9 @@ namespace Umbraco.Core.Cache // do nothing here - means that if creation throws, a race condition could cause // more than one thread to reach the return statement below and throw - accepted. - if (result == null || GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null + if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { - result = GetSafeLazy(factory); + result = SafeLazy.GetSafeLazy(factory); ContextItems[key] = result; } } @@ -79,7 +79,7 @@ namespace Umbraco.Core.Cache //return result.Value; var value = result.Value; // will not throw (safe lazy) - if (value is ExceptionHolder eh) eh.Exception.Throw(); // throw once! + if (value is SafeLazy.ExceptionHolder eh) eh.Exception.Throw(); // throw once! return value; } diff --git a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs index 016c5c3083..ad7f3d6bf7 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs @@ -4,9 +4,7 @@ using System.Linq; using System.Runtime.Caching; using System.Text.RegularExpressions; using System.Threading; -using System.Web.Caching; using Umbraco.Core.Composing; -using CacheItemPriority = System.Web.Caching.CacheItemPriority; namespace Umbraco.Core.Cache { @@ -47,7 +45,7 @@ namespace Umbraco.Core.Cache if (_locker.IsReadLockHeld) _locker.ExitReadLock(); } - return result == null ? null : FastDictionaryAppCacheBase.GetSafeLazyValue(result); // return exceptions as null + return result == null ? null : SafeLazy.GetSafeLazyValue(result); // return exceptions as null } /// @@ -73,7 +71,7 @@ namespace Umbraco.Core.Cache _locker.ExitReadLock(); } return entries - .Select(x => FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null) // backward compat, don't store null values in the cache .ToList(); } @@ -97,7 +95,7 @@ namespace Umbraco.Core.Cache _locker.ExitReadLock(); } return entries - .Select(x => FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null) // backward compat, don't store null values in the cache .ToList(); } @@ -112,9 +110,9 @@ namespace Umbraco.Core.Cache using (var lck = new UpgradeableReadLock(_locker)) { result = MemoryCache.Get(key) as Lazy; - if (result == null || FastDictionaryAppCacheBase.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null + if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { - result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + result = SafeLazy.GetSafeLazy(factory); var policy = GetPolicy(timeout, isSliding, dependentFiles); lck.UpgradeToWriteLock(); @@ -126,7 +124,7 @@ namespace Umbraco.Core.Cache //return result.Value; var value = result.Value; // will not throw (safe lazy) - if (value is FastDictionaryAppCacheBase.ExceptionHolder eh) eh.Exception.Throw(); // throw once! + if (value is SafeLazy.ExceptionHolder eh) eh.Exception.Throw(); // throw once! return value; } @@ -136,7 +134,7 @@ namespace Umbraco.Core.Cache // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. - var result = FastDictionaryAppCacheBase.GetSafeLazy(factory); + var result = SafeLazy.GetSafeLazy(factory); var value = result.Value; // force evaluation now if (value == null) return; // do not store null values (backward compat) @@ -192,7 +190,7 @@ namespace Umbraco.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -223,7 +221,7 @@ namespace Umbraco.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -255,7 +253,7 @@ namespace Umbraco.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = FastDictionaryAppCacheBase.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); if (value == null) return true; // if T is an interface remove anything that implements that interface diff --git a/src/Umbraco.Core/Cache/WebCachingAppCache.cs b/src/Umbraco.Core/Cache/WebCachingAppCache.cs index 8711a025e0..362df8f603 100644 --- a/src/Umbraco.Core/Cache/WebCachingAppCache.cs +++ b/src/Umbraco.Core/Cache/WebCachingAppCache.cs @@ -145,7 +145,7 @@ namespace Umbraco.Core.Cache if (_locker.IsReadLockHeld) _locker.ExitReadLock(); } - var value = result == null ? null : GetSafeLazyValue(result); + var value = result == null ? null : SafeLazy.GetSafeLazyValue(result); if (value != null) return value; using (var lck = new UpgradeableReadLock(_locker)) @@ -156,9 +156,9 @@ namespace Umbraco.Core.Cache // do nothing here - means that if creation throws, a race condition could cause // more than one thread to reach the return statement below and throw - accepted. - if (result == null || GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null + if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { - result = GetSafeLazy(factory); + result = SafeLazy.GetSafeLazy(factory); var absolute = isSliding ? System.Web.Caching.Cache.NoAbsoluteExpiration : (timeout == null ? System.Web.Caching.Cache.NoAbsoluteExpiration : DateTime.Now.Add(timeout.Value)); var sliding = isSliding == false ? System.Web.Caching.Cache.NoSlidingExpiration : (timeout ?? System.Web.Caching.Cache.NoSlidingExpiration); @@ -176,7 +176,7 @@ namespace Umbraco.Core.Cache //return result.Value; value = result.Value; // will not throw (safe lazy) - if (value is ExceptionHolder eh) eh.Exception.Throw(); // throw once! + if (value is SafeLazy.ExceptionHolder eh) eh.Exception.Throw(); // throw once! return value; } @@ -185,7 +185,7 @@ namespace Umbraco.Core.Cache // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. - var result = GetSafeLazy(getCacheItem); + var result = SafeLazy.GetSafeLazy(getCacheItem); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache if (value == null) return; // do not store null values (backward compat) diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index b8ebde64cf..9a2040fe00 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -124,6 +124,8 @@ Constants.cs --> + + @@ -133,12 +135,10 @@ - - From fdda90c2bfa159733d25d76110efef471295f902 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 19:39:20 +1100 Subject: [PATCH 23/61] Installs runtime cache nuget into abstractions, moves more cache classes and preps AppCaches to not rely on system.web. --- .../Cache/CacheRefresherEventArgs.cs | 0 .../Cache/DeepCloneAppCache.cs | 4 ++-- .../Cache/RepositoryCachePolicyOptions.cs | 2 +- .../Umbraco.Abstractions.csproj | 4 ++++ src/Umbraco.Core/Cache/AppCaches.cs | 18 ------------------ .../Cache/DefaultRepositoryCachePolicy.cs | 2 +- .../Cache/RepositoryCachePolicyBase.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 7 ++----- .../ServerRegistrationRepositoryTest.cs | 2 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 2 +- 10 files changed, 13 insertions(+), 30 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/CacheRefresherEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/DeepCloneAppCache.cs (98%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/RepositoryCachePolicyOptions.cs (97%) diff --git a/src/Umbraco.Core/Cache/CacheRefresherEventArgs.cs b/src/Umbraco.Abstractions/Cache/CacheRefresherEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Cache/CacheRefresherEventArgs.cs rename to src/Umbraco.Abstractions/Cache/CacheRefresherEventArgs.cs diff --git a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs b/src/Umbraco.Abstractions/Cache/DeepCloneAppCache.cs similarity index 98% rename from src/Umbraco.Core/Cache/DeepCloneAppCache.cs rename to src/Umbraco.Abstractions/Cache/DeepCloneAppCache.cs index 90367e0627..452f897372 100644 --- a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs +++ b/src/Umbraco.Abstractions/Cache/DeepCloneAppCache.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Cache /// instance, and ensuring that all inserts and returns are deep cloned copies of the cache item, /// when the item is deep-cloneable. /// - internal class DeepCloneAppCache : IAppPolicyCache + public class DeepCloneAppCache : IAppPolicyCache { /// /// Initializes a new instance of the class. @@ -29,7 +29,7 @@ namespace Umbraco.Core.Cache /// /// Gets the inner cache. /// - public IAppPolicyCache InnerCache { get; } + private IAppPolicyCache InnerCache { get; } /// public object Get(string key) diff --git a/src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs b/src/Umbraco.Abstractions/Cache/RepositoryCachePolicyOptions.cs similarity index 97% rename from src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs rename to src/Umbraco.Abstractions/Cache/RepositoryCachePolicyOptions.cs index 72baa05564..06095f058d 100644 --- a/src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs +++ b/src/Umbraco.Abstractions/Cache/RepositoryCachePolicyOptions.cs @@ -5,7 +5,7 @@ namespace Umbraco.Core.Cache /// /// Specifies how a repository cache policy should cache entities. /// - internal class RepositoryCachePolicyOptions + public class RepositoryCachePolicyOptions { /// /// Ctor - sets GetAllCacheValidateCount = true diff --git a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj index 4a3654ede6..a5e5a94520 100644 --- a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj +++ b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj @@ -6,4 +6,8 @@ Umbraco.Core + + + + diff --git a/src/Umbraco.Core/Cache/AppCaches.cs b/src/Umbraco.Core/Cache/AppCaches.cs index fbfc4c8c82..5e8c460ae4 100644 --- a/src/Umbraco.Core/Cache/AppCaches.cs +++ b/src/Umbraco.Core/Cache/AppCaches.cs @@ -1,5 +1,4 @@ using System; -using System.Web; namespace Umbraco.Core.Cache { @@ -8,23 +7,6 @@ namespace Umbraco.Core.Cache /// public class AppCaches { - /// - /// Initializes a new instance of the for use in a web application. - /// - public AppCaches() - : this(HttpRuntime.Cache) - { } - - /// - /// Initializes a new instance of the for use in a web application. - /// - public AppCaches(System.Web.Caching.Cache cache) - : this( - new WebCachingAppCache(cache), - new HttpRequestAppCache(), - new IsolatedCaches(t => new ObjectCacheAppCache())) - { } - /// /// Initializes a new instance of the with cache providers. /// diff --git a/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs index c11309c827..e4102e8684 100644 --- a/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core.Cache /// If options.GetAllCacheAllowZeroCount then a 'zero-count' array is cached when GetAll finds nothing. /// If options.GetAllCacheValidateCount then we check against the db when getting many entities. /// - internal class DefaultRepositoryCachePolicy : RepositoryCachePolicyBase + public class DefaultRepositoryCachePolicy : RepositoryCachePolicyBase where TEntity : class, IEntity { private static readonly TEntity[] EmptyEntities = new TEntity[0]; // const diff --git a/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs b/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs index 27fe4e3035..33258cbf06 100644 --- a/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs +++ b/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Cache /// /// The type of the entity. /// The type of the identifier. - internal abstract class RepositoryCachePolicyBase : IRepositoryCachePolicy + public abstract class RepositoryCachePolicyBase : IRepositoryCachePolicy where TEntity : class, IEntity { private readonly IAppPolicyCache _globalCache; diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 9a2040fe00..190c5f7434 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -124,16 +124,14 @@ Constants.cs --> + + - - - - @@ -141,7 +139,6 @@ - diff --git a/src/Umbraco.Tests/Persistence/Repositories/ServerRegistrationRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ServerRegistrationRepositoryTest.cs index e2fc4b4705..b84a79b3d1 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ServerRegistrationRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ServerRegistrationRepositoryTest.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Persistence.Repositories { base.SetUp(); - _appCaches = new AppCaches(); + _appCaches = AppCaches.Disabled; CreateTestData(); } diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 60e86ad5b0..b1e2f24564 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -59,7 +59,7 @@ namespace Umbraco.Tests.Runtimes var logger = new ConsoleLogger(new MessageTemplates()); var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); - var appCaches = new AppCaches(); // FIXME: has HttpRuntime stuff? + var appCaches = AppCaches.Disabled; var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy(() => factory.GetInstance())); var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var mainDom = new SimpleMainDom(); From f11ce3b9d9f18acd06737faab71f80b519a9f1fa Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 19:56:49 +1100 Subject: [PATCH 24/61] Moves AppCaches and cache refresher bases --- src/{Umbraco.Core => Umbraco.Abstractions}/Cache/AppCaches.cs | 0 .../Cache/CacheRefresherBase.cs | 0 .../Cache/JsonCacheRefresherBase.cs | 0 src/Umbraco.Core/Serialization/JsonNetSerializer.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 3 --- 5 files changed, 1 insertion(+), 4 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/AppCaches.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/CacheRefresherBase.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/JsonCacheRefresherBase.cs (100%) diff --git a/src/Umbraco.Core/Cache/AppCaches.cs b/src/Umbraco.Abstractions/Cache/AppCaches.cs similarity index 100% rename from src/Umbraco.Core/Cache/AppCaches.cs rename to src/Umbraco.Abstractions/Cache/AppCaches.cs diff --git a/src/Umbraco.Core/Cache/CacheRefresherBase.cs b/src/Umbraco.Abstractions/Cache/CacheRefresherBase.cs similarity index 100% rename from src/Umbraco.Core/Cache/CacheRefresherBase.cs rename to src/Umbraco.Abstractions/Cache/CacheRefresherBase.cs diff --git a/src/Umbraco.Core/Cache/JsonCacheRefresherBase.cs b/src/Umbraco.Abstractions/Cache/JsonCacheRefresherBase.cs similarity index 100% rename from src/Umbraco.Core/Cache/JsonCacheRefresherBase.cs rename to src/Umbraco.Abstractions/Cache/JsonCacheRefresherBase.cs diff --git a/src/Umbraco.Core/Serialization/JsonNetSerializer.cs b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs index 46f23ca35e..a8f97a52b0 100644 --- a/src/Umbraco.Core/Serialization/JsonNetSerializer.cs +++ b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs @@ -31,7 +31,7 @@ namespace Umbraco.Core.Serialization _settings.NullValueHandling = NullValueHandling.Include; _settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; - _settings.TypeNameHandling = TypeNameHandling.Objects; + _settings.TypeNameHandling = TypeNameHandling.Objects; // FIXME: Is this intended?? This is a security issue _settings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 190c5f7434..f80066bef8 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -124,19 +124,16 @@ Constants.cs --> - - - From c6ca955d5aa43ed191f5793995064c69698a3824 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 10:08:16 +0100 Subject: [PATCH 25/61] Move some of the config to Umbraco.Configuration --- build/NuSpecs/tools/Web.config.install.xdt | 4 +- .../Properties/AssemblyInfo.cs | 35 +++++++++++ .../Umbraco.Abstractions.csproj | 4 ++ .../CaseInsensitiveEnumConfigConverter.cs | 0 .../CommaDelimitedConfigurationElement.cs | 2 +- .../DisabledHealthCheckElement.cs | 0 .../DisabledHealthChecksElementCollection.cs | 0 .../HealthCheckNotificationSettingsElement.cs | 0 .../HealthCheckNotificationVerbosity.cs | 0 .../HealthChecks/HealthChecksSection.cs | 0 .../HealthChecks/IDisabledHealthCheck.cs | 0 .../IHealthCheckNotificationSettings.cs | 0 .../HealthChecks/IHealthChecks.cs | 0 .../HealthChecks/INotificationMethod.cs | 0 .../INotificationMethodSettings.cs | 0 .../HealthChecks/NotificationMethodElement.cs | 0 .../NotificationMethodSettingsElement.cs | 0 ...ficationMethodSettingsElementCollection.cs | 0 .../NotificationMethodsElementCollection.cs | 0 ...ionalCommaDelimitedConfigurationElement.cs | 2 +- .../OptionalInnerTextConfigurationElement.cs | 2 +- .../Properties/AssemblyInfo.cs | 10 ++++ .../RawXmlConfigurationElement.cs | 2 +- .../Umbraco.Configuration.csproj | 8 +++ .../UmbracoConfigurationSection.cs | 0 .../UmbracoSettings/BackOfficeElement.cs | 2 +- .../UmbracoSettings/CharCollection.cs | 2 +- .../UmbracoSettings/CharElement.cs | 2 +- .../UmbracoSettings/ContentElement.cs | 4 +- .../ContentError404Collection.cs | 2 +- .../ContentErrorPageElement.cs | 2 +- .../UmbracoSettings/ContentErrorsElement.cs | 2 +- .../ContentSectionExtensions.cs | 0 .../ImagingAutoFillPropertiesCollection.cs | 2 +- .../ImagingAutoFillUploadFieldElement.cs | 2 +- .../UmbracoSettings/LoggingElement.cs | 2 +- .../UmbracoSettings/NotificationsElement.cs | 2 +- .../UmbracoSettings/SecurityElement.cs | 2 +- .../UmbracoSettings/TourConfigElement.cs | 2 +- .../UmbracoConfigurationElement.cs | 2 +- .../UmbracoSettings/UmbracoSettingsSection.cs | 12 ++-- .../UmbracoSettings/UrlReplacingElement.cs | 2 +- .../UmbracoSettings/WebRoutingElement.cs | 2 +- .../UmbracoVersion.cs | 2 +- .../Configuration/ConfigsExtensions.cs | 34 +++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 60 ++++--------------- .../Configurations/UmbracoSettings/web.config | 8 +-- src/Umbraco.Tests/Umbraco.Tests.csproj | 5 ++ src/Umbraco.Web.UI/web.Template.config | 4 +- src/Umbraco.Web/Umbraco.Web.csproj | 4 ++ 50 files changed, 146 insertions(+), 86 deletions(-) create mode 100644 src/Umbraco.Abstractions/Properties/AssemblyInfo.cs rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/CaseInsensitiveEnumConfigConverter.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/CommaDelimitedConfigurationElement.cs (93%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/DisabledHealthCheckElement.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/DisabledHealthChecksElementCollection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/HealthCheckNotificationSettingsElement.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/HealthCheckNotificationVerbosity.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/HealthChecksSection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/IDisabledHealthCheck.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/IHealthCheckNotificationSettings.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/IHealthChecks.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/INotificationMethod.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/INotificationMethodSettings.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/NotificationMethodElement.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/NotificationMethodSettingsElement.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/NotificationMethodSettingsElementCollection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/HealthChecks/NotificationMethodsElementCollection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/OptionalCommaDelimitedConfigurationElement.cs (92%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/OptionalInnerTextConfigurationElement.cs (88%) create mode 100644 src/Umbraco.Configuration/Properties/AssemblyInfo.cs rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/RawXmlConfigurationElement.cs (90%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoConfigurationSection.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/BackOfficeElement.cs (76%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/CharCollection.cs (90%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/CharElement.cs (87%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentElement.cs (98%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentError404Collection.cs (89%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentErrorPageElement.cs (92%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentErrorsElement.cs (95%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentSectionExtensions.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs (88%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs (93%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/LoggingElement.cs (80%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/NotificationsElement.cs (86%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/SecurityElement.cs (97%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/TourConfigElement.cs (85%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/UmbracoConfigurationElement.cs (95%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/UmbracoSettingsSection.cs (64%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/UrlReplacingElement.cs (92%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/WebRoutingElement.cs (94%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoVersion.cs (98%) create mode 100644 src/Umbraco.Core/Configuration/ConfigsExtensions.cs diff --git a/build/NuSpecs/tools/Web.config.install.xdt b/build/NuSpecs/tools/Web.config.install.xdt index 2b79f95c70..f118fa8c3a 100644 --- a/build/NuSpecs/tools/Web.config.install.xdt +++ b/build/NuSpecs/tools/Web.config.install.xdt @@ -5,9 +5,9 @@ -
+
-
+
diff --git a/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs b/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..6d5520f975 --- /dev/null +++ b/src/Umbraco.Abstractions/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: ComVisible(false)] +[assembly: Guid("DA322714-FB89-4943-92BD-BB122B82F66B")] + +// Umbraco Cms +[assembly: InternalsVisibleTo("Umbraco.Web")] +[assembly: InternalsVisibleTo("Umbraco.Web.UI")] +[assembly: InternalsVisibleTo("Umbraco.Examine")] +[assembly: InternalsVisibleTo("Umbraco.ModelsBuilder.Embedded")] + +[assembly: InternalsVisibleTo("Umbraco.Tests")] +[assembly: InternalsVisibleTo("Umbraco.Tests.Benchmarks")] + +// Allow this to be mocked in our unit tests +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] + +// Umbraco Deploy +[assembly: InternalsVisibleTo("Umbraco.Deploy")] +[assembly: InternalsVisibleTo("Umbraco.Deploy.UI")] +[assembly: InternalsVisibleTo("Umbraco.Deploy.Cloud")] + +// Umbraco Forms +[assembly: InternalsVisibleTo("Umbraco.Forms.Core")] +[assembly: InternalsVisibleTo("Umbraco.Forms.Core.Providers")] +[assembly: InternalsVisibleTo("Umbraco.Forms.Web")] + +// Umbraco Headless +[assembly: InternalsVisibleTo("Umbraco.Cloud.Headless")] + +// code analysis +// IDE1006 is broken, wants _value syntax for consts, etc - and it's even confusing ppl at MS, kill it +[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "~_~")] diff --git a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj index a5e5a94520..1b52570acf 100644 --- a/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj +++ b/src/Umbraco.Abstractions/Umbraco.Abstractions.csproj @@ -4,6 +4,10 @@ netstandard2.0 7.3 Umbraco.Core + 9.0.0 + 9.0.0 + 9.0.0 + Umbraco CMS diff --git a/src/Umbraco.Core/Configuration/CaseInsensitiveEnumConfigConverter.cs b/src/Umbraco.Configuration/CaseInsensitiveEnumConfigConverter.cs similarity index 100% rename from src/Umbraco.Core/Configuration/CaseInsensitiveEnumConfigConverter.cs rename to src/Umbraco.Configuration/CaseInsensitiveEnumConfigConverter.cs diff --git a/src/Umbraco.Core/Configuration/CommaDelimitedConfigurationElement.cs b/src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs similarity index 93% rename from src/Umbraco.Core/Configuration/CommaDelimitedConfigurationElement.cs rename to src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs index 3ced2fab46..00dde5f206 100644 --- a/src/Umbraco.Core/Configuration/CommaDelimitedConfigurationElement.cs +++ b/src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Configuration /// /// Defines a configuration section that contains inner text that is comma delimited /// - internal class CommaDelimitedConfigurationElement : InnerTextConfigurationElement, IEnumerable + public class CommaDelimitedConfigurationElement : InnerTextConfigurationElement, IEnumerable { public override CommaDelimitedStringCollection Value { diff --git a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheckElement.cs b/src/Umbraco.Configuration/HealthChecks/DisabledHealthCheckElement.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthCheckElement.cs rename to src/Umbraco.Configuration/HealthChecks/DisabledHealthCheckElement.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs rename to src/Umbraco.Configuration/HealthChecks/DisabledHealthChecksElementCollection.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs b/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs rename to src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs b/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs rename to src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthChecksSection.cs b/src/Umbraco.Configuration/HealthChecks/HealthChecksSection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/HealthChecksSection.cs rename to src/Umbraco.Configuration/HealthChecks/HealthChecksSection.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs b/src/Umbraco.Configuration/HealthChecks/IDisabledHealthCheck.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/IDisabledHealthCheck.cs rename to src/Umbraco.Configuration/HealthChecks/IDisabledHealthCheck.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs b/src/Umbraco.Configuration/HealthChecks/IHealthCheckNotificationSettings.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs rename to src/Umbraco.Configuration/HealthChecks/IHealthCheckNotificationSettings.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/IHealthChecks.cs b/src/Umbraco.Configuration/HealthChecks/IHealthChecks.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/IHealthChecks.cs rename to src/Umbraco.Configuration/HealthChecks/IHealthChecks.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethod.cs b/src/Umbraco.Configuration/HealthChecks/INotificationMethod.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/INotificationMethod.cs rename to src/Umbraco.Configuration/HealthChecks/INotificationMethod.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettings.cs b/src/Umbraco.Configuration/HealthChecks/INotificationMethodSettings.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/INotificationMethodSettings.cs rename to src/Umbraco.Configuration/HealthChecks/INotificationMethodSettings.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodElement.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodElement.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodElement.cs rename to src/Umbraco.Configuration/HealthChecks/NotificationMethodElement.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElement.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElement.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElement.cs rename to src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElement.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs rename to src/Umbraco.Configuration/HealthChecks/NotificationMethodSettingsElementCollection.cs diff --git a/src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodsElementCollection.cs b/src/Umbraco.Configuration/HealthChecks/NotificationMethodsElementCollection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/HealthChecks/NotificationMethodsElementCollection.cs rename to src/Umbraco.Configuration/HealthChecks/NotificationMethodsElementCollection.cs diff --git a/src/Umbraco.Core/Configuration/OptionalCommaDelimitedConfigurationElement.cs b/src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs similarity index 92% rename from src/Umbraco.Core/Configuration/OptionalCommaDelimitedConfigurationElement.cs rename to src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs index 610067d2db..b6771f98b0 100644 --- a/src/Umbraco.Core/Configuration/OptionalCommaDelimitedConfigurationElement.cs +++ b/src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration /// /// Used for specifying default values for comma delimited config /// - internal class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement + public class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement { private readonly CommaDelimitedConfigurationElement _wrapped; private readonly string[] _defaultValue; diff --git a/src/Umbraco.Core/Configuration/OptionalInnerTextConfigurationElement.cs b/src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs similarity index 88% rename from src/Umbraco.Core/Configuration/OptionalInnerTextConfigurationElement.cs rename to src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs index b15e33019d..08dffd5975 100644 --- a/src/Umbraco.Core/Configuration/OptionalInnerTextConfigurationElement.cs +++ b/src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs @@ -4,7 +4,7 @@ /// This is used to supply optional/default values when using InnerTextConfigurationElement /// /// - internal class OptionalInnerTextConfigurationElement : InnerTextConfigurationElement + public class OptionalInnerTextConfigurationElement : InnerTextConfigurationElement { private readonly InnerTextConfigurationElement _wrapped; private readonly T _defaultValue; diff --git a/src/Umbraco.Configuration/Properties/AssemblyInfo.cs b/src/Umbraco.Configuration/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..d10dd929da --- /dev/null +++ b/src/Umbraco.Configuration/Properties/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Umbraco Cms +[assembly: InternalsVisibleTo("Umbraco.Tests")] +[assembly: InternalsVisibleTo("Umbraco.Tests.Benchmarks")] + +// Allow this to be mocked in our unit tests +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/Umbraco.Core/Configuration/RawXmlConfigurationElement.cs b/src/Umbraco.Configuration/RawXmlConfigurationElement.cs similarity index 90% rename from src/Umbraco.Core/Configuration/RawXmlConfigurationElement.cs rename to src/Umbraco.Configuration/RawXmlConfigurationElement.cs index 5bc6ad3d32..d7f0ed0332 100644 --- a/src/Umbraco.Core/Configuration/RawXmlConfigurationElement.cs +++ b/src/Umbraco.Configuration/RawXmlConfigurationElement.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Configuration /// A configuration section that simply exposes the entire raw xml of the section itself which inheritors can use /// to do with as they please. /// - internal abstract class RawXmlConfigurationElement : ConfigurationElement + public abstract class RawXmlConfigurationElement : ConfigurationElement { protected RawXmlConfigurationElement() { diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj index 15c6ac263f..04f8eb14d3 100644 --- a/src/Umbraco.Configuration/Umbraco.Configuration.csproj +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -18,6 +18,8 @@ <_UnmanagedRegistrationCache Remove="obj\Umbraco.Configuration.csproj.UnmanagedRegistration.cache" /> + <_UnmanagedRegistrationCache Remove="obj\Umbraco.Configuration.csproj.UnmanagedRegistration.cache" /> + <_UnmanagedRegistrationCache Remove="obj\Umbraco.Configuration.csproj.UnmanagedRegistration.cache" /> @@ -28,4 +30,10 @@ + + + C:\Users\Bjarke\AppData\Local\Temp\Temporary ASP.NET Files\root\408beac9\de517473\assembly\dl3\77bf709f\48ac59e4_3595d501\Umbraco.Core.dll + + + diff --git a/src/Umbraco.Core/Configuration/UmbracoConfigurationSection.cs b/src/Umbraco.Configuration/UmbracoConfigurationSection.cs similarity index 100% rename from src/Umbraco.Core/Configuration/UmbracoConfigurationSection.cs rename to src/Umbraco.Configuration/UmbracoConfigurationSection.cs diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/BackOfficeElement.cs b/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs similarity index 76% rename from src/Umbraco.Core/Configuration/UmbracoSettings/BackOfficeElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs index 79bff51d05..1a939d4c9e 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/BackOfficeElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class BackOfficeElement : UmbracoConfigurationElement, IBackOfficeSection + public class BackOfficeElement : UmbracoConfigurationElement, IBackOfficeSection { [ConfigurationProperty("tours")] internal TourConfigElement Tours => (TourConfigElement)this["tours"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/CharCollection.cs b/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs similarity index 90% rename from src/Umbraco.Core/Configuration/UmbracoSettings/CharCollection.cs rename to src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs index 7b62fcc123..3926e700c1 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/CharCollection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class CharCollection : ConfigurationElementCollection, IEnumerable + public class CharCollection : ConfigurationElementCollection, IEnumerable { internal void Add(CharElement c) { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/CharElement.cs b/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs similarity index 87% rename from src/Umbraco.Core/Configuration/UmbracoSettings/CharElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/CharElement.cs index 1ff63ac017..2971228d9e 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/CharElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs @@ -1,6 +1,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class CharElement : InnerTextConfigurationElement, IChar + public class CharElement : InnerTextConfigurationElement, IChar { private string _char; private string _replacement; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs similarity index 98% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs index 77ad7df0dc..1e1ecb4d0c 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Macros; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentElement : UmbracoConfigurationElement, IContentSection + public class ContentElement : UmbracoConfigurationElement, IContentSection { private const string DefaultPreviewBadge = @"
Preview modeClick to end
"; @@ -33,7 +33,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings [ConfigurationProperty("allowedUploadFiles")] internal CommaDelimitedConfigurationElement AllowedUploadFiles => GetOptionalDelimitedElement("allowedUploadFiles", new string[0]); - + [ConfigurationProperty("showDeprecatedPropertyEditors")] internal InnerTextConfigurationElement ShowDeprecatedPropertyEditors => GetOptionalTextElement("showDeprecatedPropertyEditors", false); diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentError404Collection.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs similarity index 89% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentError404Collection.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs index bdbcb27b4c..da146b14ec 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentError404Collection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentError404Collection : ConfigurationElementCollection, IEnumerable + public class ContentError404Collection : ConfigurationElementCollection, IEnumerable { internal void Add(ContentErrorPageElement element) { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorPageElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs similarity index 92% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorPageElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs index 96cea71a8e..8f5a5b3259 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorPageElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs @@ -3,7 +3,7 @@ using System.Xml.Linq; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentErrorPageElement : InnerTextConfigurationElement, IContentErrorPage + public class ContentErrorPageElement : InnerTextConfigurationElement, IContentErrorPage { public ContentErrorPageElement(XElement rawXml) : base(rawXml) diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorsElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs similarity index 95% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorsElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs index 5b5b54380d..a393267b9d 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentErrorsElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs @@ -3,7 +3,7 @@ using System.Linq; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentErrorsElement : RawXmlConfigurationElement + public class ContentErrorsElement : RawXmlConfigurationElement { public IEnumerable Error404Collection diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentSectionExtensions.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentSectionExtensions.cs similarity index 100% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentSectionExtensions.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentSectionExtensions.cs diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs similarity index 88% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs rename to src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs index 0bac9721a3..69680251af 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ImagingAutoFillPropertiesCollection : ConfigurationElementCollection, IEnumerable + public class ImagingAutoFillPropertiesCollection : ConfigurationElementCollection, IEnumerable { protected override ConfigurationElement CreateNewElement() diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs similarity index 93% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs index 9b4c45b5c6..ec3dc43caf 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ImagingAutoFillUploadFieldElement : UmbracoConfigurationElement, IImagingAutoFillUploadField + public class ImagingAutoFillUploadFieldElement : UmbracoConfigurationElement, IImagingAutoFillUploadField { /// /// Allow setting internally so we can create a default diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/LoggingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs similarity index 80% rename from src/Umbraco.Core/Configuration/UmbracoSettings/LoggingElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs index 106b6cc134..daa45cf114 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/LoggingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class LoggingElement : UmbracoConfigurationElement, ILoggingSection + public class LoggingElement : UmbracoConfigurationElement, ILoggingSection { [ConfigurationProperty("maxLogAge")] diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/NotificationsElement.cs b/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs similarity index 86% rename from src/Umbraco.Core/Configuration/UmbracoSettings/NotificationsElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs index afadff5654..cc76b2cb00 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/NotificationsElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class NotificationsElement : UmbracoConfigurationElement + public class NotificationsElement : UmbracoConfigurationElement { [ConfigurationProperty("email")] internal InnerTextConfigurationElement NotificationEmailAddress => (InnerTextConfigurationElement)this["email"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/SecurityElement.cs b/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs similarity index 97% rename from src/Umbraco.Core/Configuration/UmbracoSettings/SecurityElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs index d45a3e7d85..42bafe4bd1 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/SecurityElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class SecurityElement : UmbracoConfigurationElement, ISecuritySection + public class SecurityElement : UmbracoConfigurationElement, ISecuritySection { [ConfigurationProperty("keepUserLoggedIn")] internal InnerTextConfigurationElement KeepUserLoggedIn => GetOptionalTextElement("keepUserLoggedIn", true); diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/TourConfigElement.cs b/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs similarity index 85% rename from src/Umbraco.Core/Configuration/UmbracoSettings/TourConfigElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs index dab69f3da0..f62d766d76 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/TourConfigElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class TourConfigElement : UmbracoConfigurationElement, ITourSection + public class TourConfigElement : UmbracoConfigurationElement, ITourSection { //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 ? diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoConfigurationElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs similarity index 95% rename from src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoConfigurationElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs index 670f620b15..30cc33a260 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoConfigurationElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings /// /// Base class with shared helper methods /// - internal class UmbracoConfigurationElement : ConfigurationElement + public class UmbracoConfigurationElement : ConfigurationElement { /// /// Used so the RawElement types are not re-created every time they are accessed diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs similarity index 64% rename from src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs rename to src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs index 7cf8096345..bc91dfd48a 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs @@ -5,23 +5,23 @@ namespace Umbraco.Core.Configuration.UmbracoSettings public class UmbracoSettingsSection : ConfigurationSection, IUmbracoSettingsSection { [ConfigurationProperty("backOffice")] - internal BackOfficeElement BackOffice => (BackOfficeElement)this["backOffice"]; + public BackOfficeElement BackOffice => (BackOfficeElement)this["backOffice"]; [ConfigurationProperty("content")] - internal ContentElement Content => (ContentElement)this["content"]; + public ContentElement Content => (ContentElement)this["content"]; [ConfigurationProperty("security")] - internal SecurityElement Security => (SecurityElement)this["security"]; + public SecurityElement Security => (SecurityElement)this["security"]; [ConfigurationProperty("requestHandler")] - internal RequestHandlerElement RequestHandler => (RequestHandlerElement)this["requestHandler"]; + public RequestHandlerElement RequestHandler => (RequestHandlerElement)this["requestHandler"]; [ConfigurationProperty("logging")] - internal LoggingElement Logging => (LoggingElement)this["logging"]; + public LoggingElement Logging => (LoggingElement)this["logging"]; [ConfigurationProperty("web.routing")] - internal WebRoutingElement WebRouting => (WebRoutingElement)this["web.routing"]; + public WebRoutingElement WebRouting => (WebRoutingElement)this["web.routing"]; IContentSection IUmbracoSettingsSection.Content => Content; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/UrlReplacingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs similarity index 92% rename from src/Umbraco.Core/Configuration/UmbracoSettings/UrlReplacingElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs index 3e12d106ff..45fe2c4294 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/UrlReplacingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class UrlReplacingElement : ConfigurationElement + public class UrlReplacingElement : ConfigurationElement { [ConfigurationProperty("removeDoubleDashes", DefaultValue = true)] internal bool RemoveDoubleDashes => (bool) base["removeDoubleDashes"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs similarity index 94% rename from src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs index 7b7102f2e7..4c74398e25 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class WebRoutingElement : ConfigurationElement, IWebRoutingSection + public class WebRoutingElement : ConfigurationElement, IWebRoutingSection { [ConfigurationProperty("trySkipIisCustomErrors", DefaultValue = "false")] public bool TrySkipIisCustomErrors => (bool) base["trySkipIisCustomErrors"]; diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Configuration/UmbracoVersion.cs similarity index 98% rename from src/Umbraco.Core/Configuration/UmbracoVersion.cs rename to src/Umbraco.Configuration/UmbracoVersion.cs index 2f615d26b3..d7058fda01 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Configuration/UmbracoVersion.cs @@ -12,7 +12,7 @@ namespace Umbraco.Core.Configuration { static UmbracoVersion() { - var umbracoCoreAssembly = typeof(UmbracoVersion).Assembly; + var umbracoCoreAssembly = typeof(SemVersion).Assembly; // gets the value indicated by the AssemblyVersion attribute AssemblyVersion = umbracoCoreAssembly.GetName().Version; diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs new file mode 100644 index 0000000000..4761b14d1e --- /dev/null +++ b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs @@ -0,0 +1,34 @@ +using System.IO; +using Umbraco.Core.Cache; +using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Grid; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; +using Umbraco.Core.Manifest; + +namespace Umbraco.Core +{ + /// + /// Provides extension methods for the class. + /// + public static class ConfigsExtensions + { + + + + public static void AddCoreConfigs(this Configs configs) + { + var configDir = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config)); + + // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition + configs.Add(factory => new GridConfig( + factory.GetInstance(), + factory.GetInstance(), + configDir, + factory.GetInstance(), + factory.GetInstance().Debug)); + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index f80066bef8..a0e50032b2 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -160,8 +160,11 @@ - - + + + + + @@ -261,6 +264,7 @@ + @@ -301,53 +305,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -977,7 +934,6 @@ - @@ -1169,6 +1125,10 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions + + {fbe7c065-dac0-4025-a78b-63b24d3ab00b} + Umbraco.Configuration + \ No newline at end of file diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/web.config b/src/Umbraco.Tests/Configurations/UmbracoSettings/web.config index 3b247ecbff..5ac2d56d14 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/web.config +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/web.config @@ -1,10 +1,10 @@  - + -
-
+
+
@@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index de76b94ff1..4f4a20d94e 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -107,6 +107,7 @@ + @@ -552,6 +553,10 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions + + {fbe7c065-dac0-4025-a78b-63b24d3ab00b} + Umbraco.Configuration + {31785BC3-256C-4613-B2F5-A1B0BDDED8C1} Umbraco.Core diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config index 6d68ea845a..e694afe5ff 100644 --- a/src/Umbraco.Web.UI/web.Template.config +++ b/src/Umbraco.Web.UI/web.Template.config @@ -11,8 +11,8 @@
-
-
+
+
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 317786b970..788a6dd737 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -104,6 +104,10 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions + + {fbe7c065-dac0-4025-a78b-63b24d3ab00b} + Umbraco.Configuration + {31785bc3-256c-4613-b2f5-a1b0bdded8c1} Umbraco.Core From c77d910e9599f636de862533f1247a5aaa15100e Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 10:10:12 +0100 Subject: [PATCH 26/61] Move some of the config to Umbraco.Configuration --- .../ConfigsExtensions.cs | 28 ++++++++++ src/Umbraco.Configuration/ConfigsFactory.cs | 21 ++++++++ .../CoreDebug.cs | 2 +- .../InnerTextConfigurationElement.cs | 2 +- .../UmbracoSettings/ContentImagingElement.cs | 6 +-- .../UmbracoSettings/RequestHandlerElement.cs | 4 +- src/Umbraco.Core/ConfigsExtensions.cs | 53 ------------------- .../Configuration/ConfigsFactory.cs | 13 ----- 8 files changed, 56 insertions(+), 73 deletions(-) create mode 100644 src/Umbraco.Configuration/ConfigsExtensions.cs create mode 100644 src/Umbraco.Configuration/ConfigsFactory.cs rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/CoreDebug.cs (97%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/InnerTextConfigurationElement.cs (96%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/ContentImagingElement.cs (91%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/UmbracoSettings/RequestHandlerElement.cs (95%) delete mode 100644 src/Umbraco.Core/ConfigsExtensions.cs delete mode 100644 src/Umbraco.Core/Configuration/ConfigsFactory.cs diff --git a/src/Umbraco.Configuration/ConfigsExtensions.cs b/src/Umbraco.Configuration/ConfigsExtensions.cs new file mode 100644 index 0000000000..0ecfc46896 --- /dev/null +++ b/src/Umbraco.Configuration/ConfigsExtensions.cs @@ -0,0 +1,28 @@ +using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Grid; +using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Core +{ + /// + /// Provides extension methods for the class. + /// + public static class ConfigsExtensions + { + public static IGlobalSettings Global(this Configs configs) + => configs.GetConfig(); + + public static IUmbracoSettingsSection Settings(this Configs configs) + => configs.GetConfig(); + + public static IHealthChecks HealthChecks(this Configs configs) + => configs.GetConfig(); + + public static IGridConfig Grids(this Configs configs) + => configs.GetConfig(); + + public static CoreDebug CoreDebug(this Configs configs) + => configs.GetConfig(); + } +} diff --git a/src/Umbraco.Configuration/ConfigsFactory.cs b/src/Umbraco.Configuration/ConfigsFactory.cs new file mode 100644 index 0000000000..fbfefc132e --- /dev/null +++ b/src/Umbraco.Configuration/ConfigsFactory.cs @@ -0,0 +1,21 @@ +using System.Configuration; +using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Core.Configuration +{ + public class ConfigsFactory : IConfigsFactory + { + public Configs Create() { + var configs = new Configs(section => ConfigurationManager.GetSection(section)); + configs.Add(() => new GlobalSettings()); + configs.Add("umbracoConfiguration/settings"); + configs.Add("umbracoConfiguration/HealthChecks"); + + configs.Add(() => new CoreDebug()); + configs.Add("umbracoConfiguration/HealthChecks"); + configs.AddCoreConfigs(); + return configs; + } + } +} diff --git a/src/Umbraco.Core/Configuration/CoreDebug.cs b/src/Umbraco.Configuration/CoreDebug.cs similarity index 97% rename from src/Umbraco.Core/Configuration/CoreDebug.cs rename to src/Umbraco.Configuration/CoreDebug.cs index aa95a25990..e81ca14873 100644 --- a/src/Umbraco.Core/Configuration/CoreDebug.cs +++ b/src/Umbraco.Configuration/CoreDebug.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration { - internal class CoreDebug + public class CoreDebug { public CoreDebug() { diff --git a/src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs b/src/Umbraco.Configuration/InnerTextConfigurationElement.cs similarity index 96% rename from src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs rename to src/Umbraco.Configuration/InnerTextConfigurationElement.cs index 6a125f2c1b..3ff0c4d735 100644 --- a/src/Umbraco.Core/Configuration/InnerTextConfigurationElement.cs +++ b/src/Umbraco.Configuration/InnerTextConfigurationElement.cs @@ -9,7 +9,7 @@ namespace Umbraco.Core.Configuration /// {element}MyValue{/element} instead of as attribute values. ///
/// - internal class InnerTextConfigurationElement : RawXmlConfigurationElement + public class InnerTextConfigurationElement : RawXmlConfigurationElement { public InnerTextConfigurationElement() { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentImagingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs similarity index 91% rename from src/Umbraco.Core/Configuration/UmbracoSettings/ContentImagingElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs index 67562c411a..91eb180d08 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/ContentImagingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class ContentImagingElement : ConfigurationElement + public class ContentImagingElement : ConfigurationElement { [ConfigurationProperty("imageFileTypes")] @@ -12,7 +12,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings //set the default GetDefaultImageFileTypes()); - internal static string[] GetDefaultImageFileTypes() + public static string[] GetDefaultImageFileTypes() { return new[] {"jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif"}; } @@ -49,7 +49,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings } } - internal static ImagingAutoFillPropertiesCollection GetDefaultImageAutoFillProperties() + public static ImagingAutoFillPropertiesCollection GetDefaultImageAutoFillProperties() { return new ImagingAutoFillPropertiesCollection { diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/RequestHandlerElement.cs b/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs similarity index 95% rename from src/Umbraco.Core/Configuration/UmbracoSettings/RequestHandlerElement.cs rename to src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs index 263a822381..e5350bf596 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/RequestHandlerElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace Umbraco.Core.Configuration.UmbracoSettings { - internal class RequestHandlerElement : UmbracoConfigurationElement, IRequestHandlerSection + public class RequestHandlerElement : UmbracoConfigurationElement, IRequestHandlerSection { [ConfigurationProperty("addTrailingSlash")] public InnerTextConfigurationElement AddTrailingSlash => GetOptionalTextElement("addTrailingSlash", true); @@ -38,7 +38,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings } } - internal static CharCollection GetDefaultCharReplacements() + public static CharCollection GetDefaultCharReplacements() { var dictionary = new Dictionary() { diff --git a/src/Umbraco.Core/ConfigsExtensions.cs b/src/Umbraco.Core/ConfigsExtensions.cs deleted file mode 100644 index 5699540389..0000000000 --- a/src/Umbraco.Core/ConfigsExtensions.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.IO; -using Umbraco.Core.Cache; -using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Grid; -using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.IO; -using Umbraco.Core.Logging; -using Umbraco.Core.Manifest; - -namespace Umbraco.Core -{ - /// - /// Provides extension methods for the class. - /// - public static class ConfigsExtensions - { - public static IGlobalSettings Global(this Configs configs) - => configs.GetConfig(); - - public static IUmbracoSettingsSection Settings(this Configs configs) - => configs.GetConfig(); - - public static IHealthChecks HealthChecks(this Configs configs) - => configs.GetConfig(); - - public static IGridConfig Grids(this Configs configs) - => configs.GetConfig(); - - internal static CoreDebug CoreDebug(this Configs configs) - => configs.GetConfig(); - - public static void AddCoreConfigs(this Configs configs) - { - var configDir = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config)); - - configs.Add(() => new GlobalSettings()); - configs.Add("umbracoConfiguration/settings"); - configs.Add("umbracoConfiguration/HealthChecks"); - - configs.Add(() => new CoreDebug()); - - // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition - configs.Add(factory => new GridConfig( - factory.GetInstance(), - factory.GetInstance(), - configDir, - factory.GetInstance(), - factory.GetInstance().Debug)); - } - } -} diff --git a/src/Umbraco.Core/Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs deleted file mode 100644 index aeeef1e653..0000000000 --- a/src/Umbraco.Core/Configuration/ConfigsFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Configuration; - -namespace Umbraco.Core.Configuration -{ - public class ConfigsFactory : IConfigsFactory - { - public Configs Create() { - var configs = new Configs(section => ConfigurationManager.GetSection(section)); - configs.AddCoreConfigs(); - return configs; - } - } -} From 15bf971f04ffe85aa615471098b3efe303b16374 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 21:07:09 +1100 Subject: [PATCH 27/61] Removes weird serialization implementation. --- .../AbstractSerializationService.cs | 33 --------- .../Serialization/Formatter.cs | 21 ------ .../Serialization/IFormatter.cs | 9 --- .../Serialization/ISerializer.cs | 12 ---- .../Serialization/IStreamedResult.cs | 10 --- .../Serialization/SerializationService.cs | 45 ------------ .../Serialization/StreamResultExtensions.cs | 22 ------ .../Serialization/StreamedResult.cs | 21 ------ .../Serialization/JsonNetSerializer.cs | 72 ------------------- .../Serialization/SerializationExtensions.cs | 40 ----------- src/Umbraco.Core/Umbraco.Core.csproj | 2 - src/Umbraco.Tests/Models/ContentTests.cs | 6 +- src/Umbraco.Tests/Models/ContentTypeTests.cs | 16 ++--- src/Umbraco.Tests/Models/DataTypeTests.cs | 6 +- .../Models/DictionaryItemTests.cs | 7 +- .../Models/DictionaryTranslationTests.cs | 6 +- src/Umbraco.Tests/Models/LanguageTests.cs | 6 +- src/Umbraco.Tests/Models/LightEntityTest.cs | 6 +- src/Umbraco.Tests/Models/MemberGroupTests.cs | 6 +- src/Umbraco.Tests/Models/MemberTests.cs | 6 +- .../Models/PropertyGroupTests.cs | 6 +- src/Umbraco.Tests/Models/PropertyTypeTests.cs | 6 +- src/Umbraco.Tests/Models/RelationTests.cs | 6 +- src/Umbraco.Tests/Models/RelationTypeTests.cs | 6 +- src/Umbraco.Tests/Models/StylesheetTests.cs | 6 +- src/Umbraco.Tests/Models/TemplateTests.cs | 6 +- src/Umbraco.Tests/Models/UserTests.cs | 6 +- 27 files changed, 35 insertions(+), 359 deletions(-) delete mode 100644 src/Umbraco.Abstractions/Serialization/AbstractSerializationService.cs delete mode 100644 src/Umbraco.Abstractions/Serialization/Formatter.cs delete mode 100644 src/Umbraco.Abstractions/Serialization/IFormatter.cs delete mode 100644 src/Umbraco.Abstractions/Serialization/ISerializer.cs delete mode 100644 src/Umbraco.Abstractions/Serialization/IStreamedResult.cs delete mode 100644 src/Umbraco.Abstractions/Serialization/SerializationService.cs delete mode 100644 src/Umbraco.Abstractions/Serialization/StreamResultExtensions.cs delete mode 100644 src/Umbraco.Abstractions/Serialization/StreamedResult.cs delete mode 100644 src/Umbraco.Core/Serialization/JsonNetSerializer.cs delete mode 100644 src/Umbraco.Core/Serialization/SerializationExtensions.cs diff --git a/src/Umbraco.Abstractions/Serialization/AbstractSerializationService.cs b/src/Umbraco.Abstractions/Serialization/AbstractSerializationService.cs deleted file mode 100644 index db4afba3e8..0000000000 --- a/src/Umbraco.Abstractions/Serialization/AbstractSerializationService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public abstract class AbstractSerializationService - { - /// - /// A sequence of registered with this serialization service. - /// - public IEnumerable Formatters { get; set; } - - /// - /// Finds an with a matching , and deserializes the to an object graph. - /// - /// - /// - /// - /// - public abstract object FromStream(Stream input, Type outputType, string intent = null); - - /// - /// Finds an with a matching , and serializes the object graph to an . - /// - /// - /// - /// - public abstract IStreamedResult ToStream(object input, string intent = null); - } -} diff --git a/src/Umbraco.Abstractions/Serialization/Formatter.cs b/src/Umbraco.Abstractions/Serialization/Formatter.cs deleted file mode 100644 index bfdabbe13f..0000000000 --- a/src/Umbraco.Abstractions/Serialization/Formatter.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace Umbraco.Core.Serialization -{ - public class Formatter : IFormatter - { - #region Implementation of IFormatter - - public string Intent - { - get { throw new NotImplementedException(); } - } - - public ISerializer Serializer - { - get { throw new NotImplementedException(); } - } - - #endregion - } -} diff --git a/src/Umbraco.Abstractions/Serialization/IFormatter.cs b/src/Umbraco.Abstractions/Serialization/IFormatter.cs deleted file mode 100644 index 5c34819a18..0000000000 --- a/src/Umbraco.Abstractions/Serialization/IFormatter.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Umbraco.Core.Serialization -{ - public interface IFormatter - { - string Intent { get; } - - ISerializer Serializer { get; } - } -} diff --git a/src/Umbraco.Abstractions/Serialization/ISerializer.cs b/src/Umbraco.Abstractions/Serialization/ISerializer.cs deleted file mode 100644 index 329d7a9109..0000000000 --- a/src/Umbraco.Abstractions/Serialization/ISerializer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public interface ISerializer - { - object FromStream(Stream input, Type outputType); - - IStreamedResult ToStream(object input); - } -} diff --git a/src/Umbraco.Abstractions/Serialization/IStreamedResult.cs b/src/Umbraco.Abstractions/Serialization/IStreamedResult.cs deleted file mode 100644 index 0c6e6078cb..0000000000 --- a/src/Umbraco.Abstractions/Serialization/IStreamedResult.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public interface IStreamedResult - { - Stream ResultStream { get; } - bool Success { get; } - } -} diff --git a/src/Umbraco.Abstractions/Serialization/SerializationService.cs b/src/Umbraco.Abstractions/Serialization/SerializationService.cs deleted file mode 100644 index dee9712552..0000000000 --- a/src/Umbraco.Abstractions/Serialization/SerializationService.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public class SerializationService : AbstractSerializationService - { - private readonly ISerializer _serializer; - - public SerializationService(ISerializer serializer) - { - _serializer = serializer; - } - - #region Overrides of AbstractSerializationService - - /// - /// Finds an with a matching , and deserializes the to an object graph. - /// - /// - /// - /// - /// - public override object FromStream(Stream input, Type outputType, string intent = null) - { - if (input.CanSeek && input.Position > 0) input.Seek(0, SeekOrigin.Begin); - return _serializer.FromStream(input, outputType); - } - - /// - /// Finds an with a matching , and serializes the object graph to an . - /// - /// - /// - /// - public override IStreamedResult ToStream(object input, string intent = null) - { - return _serializer.ToStream(input); - } - - #endregion - } -} diff --git a/src/Umbraco.Abstractions/Serialization/StreamResultExtensions.cs b/src/Umbraco.Abstractions/Serialization/StreamResultExtensions.cs deleted file mode 100644 index 3d8d2cb924..0000000000 --- a/src/Umbraco.Abstractions/Serialization/StreamResultExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.IO; -using System.Text; -using System.Xml.Linq; - -namespace Umbraco.Core.Serialization -{ - public static class StreamResultExtensions - { - public static string ToJsonString(this Stream stream) - { - byte[] bytes = new byte[stream.Length]; - stream.Position = 0; - stream.Read(bytes, 0, (int)stream.Length); - return Encoding.UTF8.GetString(bytes); - } - - public static XDocument ToXDoc(this Stream stream) - { - return XDocument.Load(stream); - } - } -} diff --git a/src/Umbraco.Abstractions/Serialization/StreamedResult.cs b/src/Umbraco.Abstractions/Serialization/StreamedResult.cs deleted file mode 100644 index d1c42e976c..0000000000 --- a/src/Umbraco.Abstractions/Serialization/StreamedResult.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.IO; - -namespace Umbraco.Core.Serialization -{ - public class StreamedResult : IStreamedResult - { - public StreamedResult(Stream stream, bool success) - { - ResultStream = stream; - Success = success; - } - - #region Implementation of IStreamedResult - - public Stream ResultStream { get; protected set; } - - public bool Success { get; protected set; } - - #endregion - } -} diff --git a/src/Umbraco.Core/Serialization/JsonNetSerializer.cs b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs deleted file mode 100644 index a8f97a52b0..0000000000 --- a/src/Umbraco.Core/Serialization/JsonNetSerializer.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.IO; -using System.Reflection; -using System.Text; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -namespace Umbraco.Core.Serialization -{ - internal class JsonNetSerializer : ISerializer - { - private readonly JsonSerializerSettings _settings; - - public JsonNetSerializer() - { - _settings = new JsonSerializerSettings(); - - //var customResolver = new CustomIgnoreResolver - // { - // DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.Public - // }; - //_settings.ContractResolver = customResolver; - - var javaScriptDateTimeConverter = new JavaScriptDateTimeConverter(); - - _settings.Converters.Add(javaScriptDateTimeConverter); - _settings.Converters.Add(new EntityKeyMemberConverter()); - _settings.Converters.Add(new KeyValuePairConverter()); - _settings.Converters.Add(new ExpandoObjectConverter()); - _settings.Converters.Add(new XmlNodeConverter()); - - _settings.NullValueHandling = NullValueHandling.Include; - _settings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; - _settings.TypeNameHandling = TypeNameHandling.Objects; // FIXME: Is this intended?? This is a security issue - _settings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor; - } - - #region Implementation of ISerializer - - /// - /// Deserialize input stream to object - /// - /// - /// - /// - public object FromStream(Stream input, Type outputType) - { - byte[] bytes = new byte[input.Length]; - input.Position = 0; - input.Read(bytes, 0, (int)input.Length); - string s = Encoding.UTF8.GetString(bytes); - - return JsonConvert.DeserializeObject(s, outputType, _settings); - } - - /// - /// Serialize object to streamed result - /// - /// - /// - public IStreamedResult ToStream(object input) - { - string s = JsonConvert.SerializeObject(input, Formatting.None, _settings); - byte[] bytes = Encoding.UTF8.GetBytes(s); - MemoryStream ms = new MemoryStream(bytes); - - return new StreamedResult(ms, true); - } - - #endregion - } -} diff --git a/src/Umbraco.Core/Serialization/SerializationExtensions.cs b/src/Umbraco.Core/Serialization/SerializationExtensions.cs deleted file mode 100644 index c88641a337..0000000000 --- a/src/Umbraco.Core/Serialization/SerializationExtensions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.IO; -using System.Text; - -namespace Umbraco.Core.Serialization -{ - public static class SerializationExtensions - { - public static T FromJson(this AbstractSerializationService service, string json, string intent = null) - { - if (string.IsNullOrWhiteSpace(json)) return default(T); - return (T)service.FromJson(json, typeof(T), intent); - } - - public static T FromJson(this ISerializer serializer, string json, string intent = null) - { - if (string.IsNullOrWhiteSpace(json)) return default(T); - return (T)serializer.FromJson(json, typeof(T)); - } - - public static object FromJson(this ISerializer serializer, string json, Type outputType) - { - if (string.IsNullOrWhiteSpace(json)) return outputType.GetDefaultValue(); - var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); - return serializer.FromStream(stream, outputType); - } - - public static object FromJson(this AbstractSerializationService service, string json, Type outputType, string intent = null) - { - if (string.IsNullOrWhiteSpace(json)) return outputType.GetDefaultValue(); - var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); - return service.FromStream(stream, outputType, intent); - } - - public static string ToJson(this AbstractSerializationService service, object input, string intent = null) - { - return StreamResultExtensions.ToJsonString(service.ToStream(input, intent).ResultStream); - } - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index a0e50032b2..754cc1c8d5 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -284,7 +284,6 @@ - @@ -1005,7 +1004,6 @@ - diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index 8dded05eab..b7aca9df66 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Linq; using System.Threading; using Moq; +using Newtonsoft.Json; using Umbraco.Core; using NUnit.Framework; using Umbraco.Core.Cache; @@ -476,8 +477,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); contentType.Id = 99; @@ -503,8 +502,7 @@ namespace Umbraco.Tests.Models content.UpdateDate = DateTime.Now; content.WriterId = 23; - var result = ss.ToStream(content); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(content); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/ContentTypeTests.cs b/src/Umbraco.Tests/Models/ContentTypeTests.cs index 74229dd5d6..afb9ea1bdf 100644 --- a/src/Umbraco.Tests/Models/ContentTypeTests.cs +++ b/src/Umbraco.Tests/Models/ContentTypeTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -287,8 +288,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Content_Type_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - // Arrange var contentType = MockedContentTypes.CreateTextPageContentType(); contentType.Id = 99; @@ -318,8 +317,7 @@ namespace Umbraco.Tests.Models contentType.Trashed = false; contentType.UpdateDate = DateTime.Now; - var result = ss.ToStream(contentType); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(contentType); Debug.Print(json); } @@ -391,8 +389,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Media_Type_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - // Arrange var contentType = MockedContentTypes.CreateImageMediaType(); contentType.Id = 99; @@ -416,8 +412,7 @@ namespace Umbraco.Tests.Models contentType.Trashed = false; contentType.UpdateDate = DateTime.Now; - var result = ss.ToStream(contentType); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(contentType); Debug.Print(json); } @@ -492,8 +487,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Member_Type_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - // Arrange var contentType = MockedContentTypes.CreateSimpleMemberType(); contentType.Id = 99; @@ -519,8 +512,7 @@ namespace Umbraco.Tests.Models contentType.SetMemberCanEditProperty("title", true); contentType.SetMemberCanViewProperty("bodyText", true); - var result = ss.ToStream(contentType); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(contentType); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/DataTypeTests.cs b/src/Umbraco.Tests/Models/DataTypeTests.cs index 6a943c9695..50d9f6e21b 100644 --- a/src/Umbraco.Tests/Models/DataTypeTests.cs +++ b/src/Umbraco.Tests/Models/DataTypeTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using Moq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -58,8 +59,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var dtd = new DataType(new VoidEditor(Mock.Of()), 9) { CreateDate = DateTime.Now, @@ -76,8 +75,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(dtd); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(dtd); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/DictionaryItemTests.cs b/src/Umbraco.Tests/Models/DictionaryItemTests.cs index 924216f7d3..70d1efda87 100644 --- a/src/Umbraco.Tests/Models/DictionaryItemTests.cs +++ b/src/Umbraco.Tests/Models/DictionaryItemTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -84,8 +85,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new DictionaryItem("blah") { CreateDate = DateTime.Now, @@ -129,8 +128,8 @@ namespace Umbraco.Tests.Models } }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs b/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs index d7fcea71f0..7999537e7a 100644 --- a/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs +++ b/src/Umbraco.Tests/Models/DictionaryTranslationTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -55,8 +56,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new DictionaryTranslation(new Language("en-AU") { CreateDate = DateTime.Now, @@ -73,8 +72,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/LanguageTests.cs b/src/Umbraco.Tests/Models/LanguageTests.cs index 5f8d858007..8e41b28b08 100644 --- a/src/Umbraco.Tests/Models/LanguageTests.cs +++ b/src/Umbraco.Tests/Models/LanguageTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -43,8 +44,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new Language("en-AU") { CreateDate = DateTime.Now, @@ -55,8 +54,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/LightEntityTest.cs b/src/Umbraco.Tests/Models/LightEntityTest.cs index 41ce830cff..43513e2d3e 100644 --- a/src/Umbraco.Tests/Models/LightEntityTest.cs +++ b/src/Umbraco.Tests/Models/LightEntityTest.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -13,8 +14,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new DocumentEntitySlim() { Id = 3, @@ -38,8 +37,7 @@ namespace Umbraco.Tests.Models item.AdditionalData.Add("test1", 3); item.AdditionalData.Add("test2", "valuie"); - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); // FIXME: compare with v7 } } diff --git a/src/Umbraco.Tests/Models/MemberGroupTests.cs b/src/Umbraco.Tests/Models/MemberGroupTests.cs index fc76980890..c3cf1c8c76 100644 --- a/src/Umbraco.Tests/Models/MemberGroupTests.cs +++ b/src/Umbraco.Tests/Models/MemberGroupTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -51,8 +52,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var group = new MemberGroup() { CreateDate = DateTime.Now, @@ -65,8 +64,7 @@ namespace Umbraco.Tests.Models group.AdditionalData.Add("test1", 123); group.AdditionalData.Add("test2", "hello"); - var result = ss.ToStream(group); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(group); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/MemberTests.cs b/src/Umbraco.Tests/Models/MemberTests.cs index 666b9a8ab1..2a55268c48 100644 --- a/src/Umbraco.Tests/Models/MemberTests.cs +++ b/src/Umbraco.Tests/Models/MemberTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -114,8 +115,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var memberType = MockedContentTypes.CreateSimpleMemberType("memberType", "Member Type"); memberType.Id = 99; var member = MockedMember.CreateSimpleMember(memberType, "Name", "email@email.com", "pass", "user", Guid.NewGuid()); @@ -148,8 +147,7 @@ namespace Umbraco.Tests.Models member.AdditionalData.Add("test1", 123); member.AdditionalData.Add("test2", "hello"); - var result = ss.ToStream(member); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(member); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/PropertyGroupTests.cs b/src/Umbraco.Tests/Models/PropertyGroupTests.cs index 0552acf930..a68b526951 100644 --- a/src/Umbraco.Tests/Models/PropertyGroupTests.cs +++ b/src/Umbraco.Tests/Models/PropertyGroupTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -88,8 +89,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var pg = new PropertyGroup( new PropertyTypeCollection(false, new[] { @@ -135,8 +134,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(pg); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(pg); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/PropertyTypeTests.cs b/src/Umbraco.Tests/Models/PropertyTypeTests.cs index 568d12264d..1bc99162af 100644 --- a/src/Umbraco.Tests/Models/PropertyTypeTests.cs +++ b/src/Umbraco.Tests/Models/PropertyTypeTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -60,8 +61,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var pt = new PropertyType("TestPropertyEditor", ValueStorageType.Nvarchar, "test") { Id = 3, @@ -79,8 +78,7 @@ namespace Umbraco.Tests.Models ValueStorageType = ValueStorageType.Nvarchar }; - var result = ss.ToStream(pt); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(pt); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/RelationTests.cs b/src/Umbraco.Tests/Models/RelationTests.cs index c62dcdc6eb..1e0c7ccb59 100644 --- a/src/Umbraco.Tests/Models/RelationTests.cs +++ b/src/Umbraco.Tests/Models/RelationTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -50,8 +51,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new Relation(9, 8, new RelationType(Guid.NewGuid(), Guid.NewGuid(), "test") { Id = 66 @@ -64,8 +63,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/RelationTypeTests.cs b/src/Umbraco.Tests/Models/RelationTypeTests.cs index 9d8fdcdf25..765ac26f7f 100644 --- a/src/Umbraco.Tests/Models/RelationTypeTests.cs +++ b/src/Umbraco.Tests/Models/RelationTypeTests.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -46,8 +47,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new RelationType(Guid.NewGuid(), Guid.NewGuid(), "test") { Id = 66, @@ -58,8 +57,7 @@ namespace Umbraco.Tests.Models UpdateDate = DateTime.Now }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/StylesheetTests.cs b/src/Umbraco.Tests/Models/StylesheetTests.cs index b8990f6d29..f76e0083dc 100644 --- a/src/Umbraco.Tests/Models/StylesheetTests.cs +++ b/src/Umbraco.Tests/Models/StylesheetTests.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -101,8 +102,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var stylesheet = new Stylesheet("/css/styles.css"); stylesheet.Content = @"@media screen and (min-width: 600px) and (min-width: 900px) { .class { @@ -110,8 +109,7 @@ namespace Umbraco.Tests.Models } }"; - var result = ss.ToStream(stylesheet); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(stylesheet); Debug.Print(json); } } diff --git a/src/Umbraco.Tests/Models/TemplateTests.cs b/src/Umbraco.Tests/Models/TemplateTests.cs index 0813bc9f4e..b73b8d9fa0 100644 --- a/src/Umbraco.Tests/Models/TemplateTests.cs +++ b/src/Umbraco.Tests/Models/TemplateTests.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Linq; using System.Reflection; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Serialization; @@ -61,8 +62,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new Template("Test", "test") { Id = 3, @@ -74,8 +73,7 @@ namespace Umbraco.Tests.Models MasterTemplateId = new Lazy(() => 88) }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index b8151fc944..48e8de3fab 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Linq; +using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -69,8 +70,6 @@ namespace Umbraco.Tests.Models [Test] public void Can_Serialize_Without_Error() { - var ss = new SerializationService(new JsonNetSerializer()); - var item = new User { Id = 3, @@ -98,8 +97,7 @@ namespace Umbraco.Tests.Models Username = "username" }; - var result = ss.ToStream(item); - var json = result.ResultStream.ToJsonString(); + var json = JsonConvert.SerializeObject(item); Debug.Print(json); } } From 69c2b732ce7082d177ea25a4c7d601feff2ae96d Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 21:28:56 +1100 Subject: [PATCH 28/61] new IJsonSerializer, moves other base cache refresher classes --- .../Cache/CacheRefresherCollection.cs | 0 .../Cache/PayloadCacheRefresherBase.cs | 14 ++++++++---- .../Cache/TypedCacheRefresherBase.cs | 0 .../Serialization/IJsonSerializer.cs | 9 ++++++++ .../Runtime/CoreInitialComposer.cs | 3 +++ .../Serialization/JsonNetSerializer.cs | 22 +++++++++++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 4 +--- .../Cache/ContentCacheRefresher.cs | 5 +++-- .../Cache/ContentTypeCacheRefresher.cs | 5 +++-- .../Cache/DataTypeCacheRefresher.cs | 5 +++-- src/Umbraco.Web/Cache/DomainCacheRefresher.cs | 5 +++-- .../Cache/LanguageCacheRefresher.cs | 5 +++-- src/Umbraco.Web/Cache/MediaCacheRefresher.cs | 5 +++-- 13 files changed, 63 insertions(+), 19 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/CacheRefresherCollection.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/PayloadCacheRefresherBase.cs (79%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/TypedCacheRefresherBase.cs (100%) create mode 100644 src/Umbraco.Abstractions/Serialization/IJsonSerializer.cs create mode 100644 src/Umbraco.Core/Serialization/JsonNetSerializer.cs diff --git a/src/Umbraco.Core/Cache/CacheRefresherCollection.cs b/src/Umbraco.Abstractions/Cache/CacheRefresherCollection.cs similarity index 100% rename from src/Umbraco.Core/Cache/CacheRefresherCollection.cs rename to src/Umbraco.Abstractions/Cache/CacheRefresherCollection.cs diff --git a/src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs b/src/Umbraco.Abstractions/Cache/PayloadCacheRefresherBase.cs similarity index 79% rename from src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs rename to src/Umbraco.Abstractions/Cache/PayloadCacheRefresherBase.cs index 4a3a03a0d6..1ee804bc82 100644 --- a/src/Umbraco.Core/Cache/PayloadCacheRefresherBase.cs +++ b/src/Umbraco.Abstractions/Cache/PayloadCacheRefresherBase.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System; +using Umbraco.Core.Serialization; using Umbraco.Core.Sync; namespace Umbraco.Core.Cache @@ -12,12 +13,17 @@ namespace Umbraco.Core.Cache public abstract class PayloadCacheRefresherBase : JsonCacheRefresherBase, IPayloadCacheRefresher where TInstanceType : class, ICacheRefresher { + private readonly IJsonSerializer _serializer; + /// /// Initializes a new instance of the . /// /// A cache helper. - protected PayloadCacheRefresherBase(AppCaches appCaches) : base(appCaches) - { } + /// + protected PayloadCacheRefresherBase(AppCaches appCaches, IJsonSerializer serializer) : base(appCaches) + { + _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); + } #region Json @@ -28,7 +34,7 @@ namespace Umbraco.Core.Cache /// The deserialized object payload. protected virtual TPayload[] Deserialize(string json) { - return JsonConvert.DeserializeObject(json); + return _serializer.Deserialize(json); } #endregion diff --git a/src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs b/src/Umbraco.Abstractions/Cache/TypedCacheRefresherBase.cs similarity index 100% rename from src/Umbraco.Core/Cache/TypedCacheRefresherBase.cs rename to src/Umbraco.Abstractions/Cache/TypedCacheRefresherBase.cs diff --git a/src/Umbraco.Abstractions/Serialization/IJsonSerializer.cs b/src/Umbraco.Abstractions/Serialization/IJsonSerializer.cs new file mode 100644 index 0000000000..c619f173fe --- /dev/null +++ b/src/Umbraco.Abstractions/Serialization/IJsonSerializer.cs @@ -0,0 +1,9 @@ +namespace Umbraco.Core.Serialization +{ + public interface IJsonSerializer + { + string Serialize(object input); + + T Deserialize(string input); + } +} diff --git a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs index 7ae5211876..445747f299 100644 --- a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs @@ -17,6 +17,7 @@ using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; using Umbraco.Core.Scoping; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Strings; using Umbraco.Core.Sync; @@ -50,6 +51,8 @@ namespace Umbraco.Core.Runtime composition.RegisterUnique(f => f.GetInstance()); composition.RegisterUnique(f => f.GetInstance()); + composition.RegisterUnique(); + // register database builder // *not* a singleton, don't want to keep it around composition.Register(); diff --git a/src/Umbraco.Core/Serialization/JsonNetSerializer.cs b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs new file mode 100644 index 0000000000..a2a5f19082 --- /dev/null +++ b/src/Umbraco.Core/Serialization/JsonNetSerializer.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace Umbraco.Core.Serialization +{ + public class JsonNetSerializer : IJsonSerializer + { + public string Serialize(object input) + { + return JsonConvert.SerializeObject(input); + } + + public T Deserialize(string input) + { + return JsonConvert.DeserializeObject(input); + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 754cc1c8d5..54a59d2162 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -128,16 +128,13 @@ - - - @@ -284,6 +281,7 @@ + diff --git a/src/Umbraco.Web/Cache/ContentCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentCacheRefresher.cs index d9a6518493..0422d3c674 100644 --- a/src/Umbraco.Web/Cache/ContentCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentCacheRefresher.cs @@ -7,6 +7,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Web.Composing; @@ -20,8 +21,8 @@ namespace Umbraco.Web.Cache private readonly IdkMap _idkMap; private readonly IDomainService _domainService; - public ContentCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap, IDomainService domainService) - : base(appCaches) + public ContentCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap, IDomainService domainService) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _idkMap = idkMap; diff --git a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs index 63cfe0df9e..655baf18bf 100644 --- a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs @@ -5,6 +5,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence.Repositories; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Web.PublishedCache; @@ -18,8 +19,8 @@ namespace Umbraco.Web.Cache private readonly IContentTypeCommonRepository _contentTypeCommonRepository; private readonly IdkMap _idkMap; - public ContentTypeCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) - : base(appCaches) + public ContentTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; diff --git a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs index c9caf5aaa7..3c83ff3027 100644 --- a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs @@ -4,6 +4,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors.ValueConverters; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Web.PublishedCache; @@ -16,8 +17,8 @@ namespace Umbraco.Web.Cache private readonly IPublishedModelFactory _publishedModelFactory; private readonly IdkMap _idkMap; - public DataTypeCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) - : base(appCaches) + public DataTypeCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IPublishedModelFactory publishedModelFactory, IdkMap idkMap) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _publishedModelFactory = publishedModelFactory; diff --git a/src/Umbraco.Web/Cache/DomainCacheRefresher.cs b/src/Umbraco.Web/Cache/DomainCacheRefresher.cs index 4ffe4e2717..7958728765 100644 --- a/src/Umbraco.Web/Cache/DomainCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DomainCacheRefresher.cs @@ -1,6 +1,7 @@ using System; using Umbraco.Core.Cache; using Umbraco.Core.Models; +using Umbraco.Core.Serialization; using Umbraco.Core.Services.Changes; using Umbraco.Web.PublishedCache; @@ -10,8 +11,8 @@ namespace Umbraco.Web.Cache { private readonly IPublishedSnapshotService _publishedSnapshotService; - public DomainCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService) - : base(appCaches) + public DomainCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; } diff --git a/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs b/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs index b1fc0a9e55..dfb85aad6a 100644 --- a/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/LanguageCacheRefresher.cs @@ -2,6 +2,7 @@ using System.Linq; using Umbraco.Core.Cache; using Umbraco.Core.Models; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Web.PublishedCache; @@ -13,8 +14,8 @@ namespace Umbraco.Web.Cache //CacheRefresherBase { - public LanguageCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService) - : base(appCaches) + public LanguageCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; } diff --git a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs index 1f54b62c5b..8da643c279 100644 --- a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs @@ -6,6 +6,7 @@ using Umbraco.Core.Persistence.Repositories; using System.Linq; using System.Xml.Linq; using Umbraco.Core.Persistence.Repositories.Implement; +using Umbraco.Core.Serialization; using Umbraco.Core.Services; using Umbraco.Core.Services.Changes; using Umbraco.Web.Composing; @@ -18,8 +19,8 @@ namespace Umbraco.Web.Cache private readonly IPublishedSnapshotService _publishedSnapshotService; private readonly IdkMap _idkMap; - public MediaCacheRefresher(AppCaches appCaches, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap) - : base(appCaches) + public MediaCacheRefresher(AppCaches appCaches, IJsonSerializer serializer, IPublishedSnapshotService publishedSnapshotService, IdkMap idkMap) + : base(appCaches, serializer) { _publishedSnapshotService = publishedSnapshotService; _idkMap = idkMap; From a3d142831e3bf598a669e129d2fd9353a2095546 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 21:46:04 +1100 Subject: [PATCH 29/61] fixing tests --- src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs | 2 +- src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs | 4 ++-- src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs | 2 +- src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs | 2 +- .../ControllerTesting/TestControllerActivatorBase.cs | 2 +- src/Umbraco.Tests/Testing/TestingTests/MockTests.cs | 4 ++-- src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs index 5f9e94a4fc..74aba2b824 100644 --- a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs @@ -59,7 +59,7 @@ namespace Umbraco.Tests.Cache var cached = new List(); var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => + .Callback((string cacheKey, Func o, TimeSpan? t, bool b, string[] s) => { cached.Add(cacheKey); }); diff --git a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs index e0ffb7e4cd..027f6d2d69 100644 --- a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs @@ -79,7 +79,7 @@ namespace Umbraco.Tests.Cache var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => + .Callback((string cacheKey, Func o, TimeSpan? t, bool b, string[] s) => { cached.Add(cacheKey); @@ -121,7 +121,7 @@ namespace Umbraco.Tests.Cache var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => + .Callback((string cacheKey, Func o, TimeSpan? t, bool b, string[] s) => { cached.Add(cacheKey); diff --git a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs index f34f4082bd..335335e391 100644 --- a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Cache var cached = new List(); var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => + .Callback((string cacheKey, Func o, TimeSpan? t, bool b, string[] s) => { cached.Add(cacheKey); }); diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index 340f24ef28..ac402ad77d 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -146,7 +146,7 @@ namespace Umbraco.Tests.Routing var handler = new RenderRouteHandler(umbracoContext, new TestControllerFactory(umbracoContextAccessor, Mock.Of(), context => { var membershipHelper = new MembershipHelper( - umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); + umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of()); return new CustomDocumentController(Factory.GetInstance(), umbracoContextAccessor, Factory.GetInstance(), diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs index e52d338ca6..4b41d4fbc4 100644 --- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs +++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs @@ -150,7 +150,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting urlHelper.Setup(provider => provider.GetUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(UrlInfo.Url("/hello/world/1234")); - var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); + var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of()); var umbHelper = new UmbracoHelper(Mock.Of(), Mock.Of(), diff --git a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs index ee91427a63..7096158aa8 100644 --- a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs +++ b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs @@ -70,7 +70,7 @@ namespace Umbraco.Tests.Testing.TestingTests Mock.Of(), Mock.Of(), Mock.Of(), - new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())); + new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of())); Assert.Pass(); } @@ -98,7 +98,7 @@ namespace Umbraco.Tests.Testing.TestingTests { var umbracoContext = TestObjects.GetUmbracoContextMock(); - var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of()); + var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of()); var umbracoHelper = new UmbracoHelper(Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), membershipHelper); var umbracoMapper = new UmbracoMapper(new MapDefinitionCollection(new[] { Mock.Of() })); diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index a9c405237b..f051d2eef4 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -120,7 +120,7 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), Mock.Of(), Mock.Of(query => query.Content(2) == content.Object), - new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of())); + new MembershipHelper(umbracoContext.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of())); var ctrl = new TestSurfaceController(umbracoContextAccessor, helper); var result = ctrl.GetContent(2) as PublishedContentResult; @@ -178,7 +178,7 @@ namespace Umbraco.Tests.Web.Mvc public class TestSurfaceController : SurfaceController { public TestSurfaceController(IUmbracoContextAccessor umbracoContextAccessor, UmbracoHelper helper = null) - : base(umbracoContextAccessor, null, ServiceContext.CreatePartial(), Mock.Of(), null, null, helper) + : base(umbracoContextAccessor, null, ServiceContext.CreatePartial(), AppCaches.Disabled, null, null, helper) { } From 39880f885a03af802224fe02625cac7419098b38 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 22:22:09 +1100 Subject: [PATCH 30/61] fixing tests --- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 5e21f5de63..a45ac1caa7 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -37,6 +37,7 @@ using Umbraco.Web.Routing; using Umbraco.Web.Trees; using Umbraco.Core.Composing.CompositionExtensions; using Umbraco.Core.Mapping; +using Umbraco.Core.Serialization; using Umbraco.Web.Composing.CompositionExtensions; using Umbraco.Web.Sections; using Current = Umbraco.Core.Composing.Current; @@ -327,6 +328,8 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(factory => ExamineManager.Instance); + Composition.RegisterUnique(); + // register filesystems Composition.RegisterUnique(factory => TestObjects.GetFileSystemsMock()); From a3e73b59bf32f57b5c2fd59f86f58e44a7bead74 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 12:58:56 +0100 Subject: [PATCH 31/61] More config movement --- .../Configuration/ConfigsExtensions.cs | 2 - .../Configuration}/ConfigsFactory.cs | 1 - .../Configuration/Grid/GridEditorsConfig.cs | 6 +- src/Umbraco.Core/Manifest/IManifestFilter.cs | 2 +- src/Umbraco.Core/Manifest/IManifestParser.cs | 9 +- src/Umbraco.Core/Manifest/IPackageManifest.cs | 65 ++++++++ .../Manifest/ManifestFilterCollection.cs | 2 +- src/Umbraco.Core/Manifest/ManifestParser.cs | 15 +- src/Umbraco.Core/Manifest/PackageManifest.cs | 140 +++++++++--------- src/Umbraco.Core/Umbraco.Core.csproj | 2 + src/Umbraco.Tests/Published/ModelTypeTests.cs | 2 +- 11 files changed, 156 insertions(+), 90 deletions(-) rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/ConfigsFactory.cs (90%) create mode 100644 src/Umbraco.Core/Manifest/IPackageManifest.cs diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs index 4761b14d1e..e54e360021 100644 --- a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs @@ -16,8 +16,6 @@ namespace Umbraco.Core public static class ConfigsExtensions { - - public static void AddCoreConfigs(this Configs configs) { var configDir = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config)); diff --git a/src/Umbraco.Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs similarity index 90% rename from src/Umbraco.Configuration/ConfigsFactory.cs rename to src/Umbraco.Core/Configuration/ConfigsFactory.cs index fbfefc132e..c0e80d3798 100644 --- a/src/Umbraco.Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -13,7 +13,6 @@ namespace Umbraco.Core.Configuration configs.Add("umbracoConfiguration/HealthChecks"); configs.Add(() => new CoreDebug()); - configs.Add("umbracoConfiguration/HealthChecks"); configs.AddCoreConfigs(); return configs; } diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs index cab58a6d63..a1ebf008fc 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs @@ -29,9 +29,9 @@ namespace Umbraco.Core.Configuration.Grid { get { - List GetResult() + List GetResult() { - var editors = new List(); + var editors = new List(); var gridConfig = Path.Combine(_configFolder.FullName, "grid.editors.config.js"); if (File.Exists(gridConfig)) { @@ -59,7 +59,7 @@ namespace Umbraco.Core.Configuration.Grid //cache the result if debugging is disabled var result = _isDebug ? GetResult() - : _appCaches.RuntimeCache.GetCacheItem>(typeof(GridEditorsConfig) + ".Editors",GetResult, TimeSpan.FromMinutes(10)); + : _appCaches.RuntimeCache.GetCacheItem>(typeof(GridEditorsConfig) + ".Editors",GetResult, TimeSpan.FromMinutes(10)); return result; } diff --git a/src/Umbraco.Core/Manifest/IManifestFilter.cs b/src/Umbraco.Core/Manifest/IManifestFilter.cs index 505f13d385..f1e2c633c8 100644 --- a/src/Umbraco.Core/Manifest/IManifestFilter.cs +++ b/src/Umbraco.Core/Manifest/IManifestFilter.cs @@ -14,6 +14,6 @@ namespace Umbraco.Core.Manifest /// /// It is possible to remove, change, or add manifests. /// - void Filter(List manifests); + void Filter(List manifests); } } diff --git a/src/Umbraco.Core/Manifest/IManifestParser.cs b/src/Umbraco.Core/Manifest/IManifestParser.cs index 3641396e0a..367ee3be77 100644 --- a/src/Umbraco.Core/Manifest/IManifestParser.cs +++ b/src/Umbraco.Core/Manifest/IManifestParser.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Umbraco.Core.Configuration.Grid; using Umbraco.Core.PropertyEditors; namespace Umbraco.Core.Manifest @@ -11,13 +12,13 @@ namespace Umbraco.Core.Manifest /// Gets all manifests, merged into a single manifest object. /// /// - PackageManifest Manifest { get; } + IPackageManifest Manifest { get; } /// /// Parses a manifest. /// - PackageManifest ParseManifest(string text); + IPackageManifest ParseManifest(string text); - IEnumerable ParseGridEditors(string text); + IEnumerable ParseGridEditors(string text); } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Manifest/IPackageManifest.cs b/src/Umbraco.Core/Manifest/IPackageManifest.cs new file mode 100644 index 0000000000..01b0be70db --- /dev/null +++ b/src/Umbraco.Core/Manifest/IPackageManifest.cs @@ -0,0 +1,65 @@ +using System.Runtime.Serialization; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Core.Manifest +{ + public interface IPackageManifest + { + /// + /// Gets the source path of the manifest. + /// + /// + /// Gets the full absolute file path of the manifest, + /// using system directory separators. + /// + string Source { get; set; } + + /// + /// Gets or sets the scripts listed in the manifest. + /// + [DataMember(Name = "javascript")] + string[] Scripts { get; set; } + + /// + /// Gets or sets the stylesheets listed in the manifest. + /// + [DataMember(Name = "css")] + string[] Stylesheets { get; set; } + + /// + /// Gets or sets the property editors listed in the manifest. + /// + [DataMember(Name = "propertyEditors")] + IDataEditor[] PropertyEditors { get; set; } + + /// + /// Gets or sets the parameter editors listed in the manifest. + /// + [DataMember(Name = "parameterEditors")] + IDataEditor[] ParameterEditors { get; set; } + + /// + /// Gets or sets the grid editors listed in the manifest. + /// + [DataMember(Name = "gridEditors")] + GridEditor[] GridEditors { get; set; } + + /// + /// Gets or sets the content apps listed in the manifest. + /// + [DataMember(Name = "contentApps")] + ManifestContentAppDefinition[] ContentApps { get; set; } + + /// + /// Gets or sets the dashboards listed in the manifest. + /// + [DataMember(Name = "dashboards")] + ManifestDashboard[] Dashboards { get; set; } + + /// + /// Gets or sets the sections listed in the manifest. + /// + [DataMember(Name = "sections")] + ManifestSection[] Sections { get; set; } + } +} diff --git a/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs b/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs index febdb7e356..0f49c96094 100644 --- a/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs +++ b/src/Umbraco.Core/Manifest/ManifestFilterCollection.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Manifest /// Filters package manifests. /// /// The package manifests. - public void Filter(List manifests) + public void Filter(List manifests) { foreach (var filter in this) filter.Filter(manifests); diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index 2e55d07059..4e2ca1f2b6 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using Newtonsoft.Json; using Umbraco.Core.Cache; +using Umbraco.Core.Configuration.Grid; using Umbraco.Core.Exceptions; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -57,8 +58,8 @@ namespace Umbraco.Core.Manifest /// Gets all manifests, merged into a single manifest object. /// /// - public PackageManifest Manifest - => _cache.GetCacheItem("Umbraco.Core.Manifest.ManifestParser::Manifests", () => + public IPackageManifest Manifest + => _cache.GetCacheItem("Umbraco.Core.Manifest.ManifestParser::Manifests", () => { var manifests = GetManifests(); return MergeManifests(manifests); @@ -67,9 +68,9 @@ namespace Umbraco.Core.Manifest /// /// Gets all manifests. /// - private IEnumerable GetManifests() + private IEnumerable GetManifests() { - var manifests = new List(); + var manifests = new List(); foreach (var path in GetManifestFiles()) { @@ -97,7 +98,7 @@ namespace Umbraco.Core.Manifest /// /// Merges all manifests into one. /// - private static PackageManifest MergeManifests(IEnumerable manifests) + private static IPackageManifest MergeManifests(IEnumerable manifests) { var scripts = new HashSet(); var stylesheets = new HashSet(); @@ -153,7 +154,7 @@ namespace Umbraco.Core.Manifest /// /// Parses a manifest. /// - public PackageManifest ParseManifest(string text) + public IPackageManifest ParseManifest(string text) { if (string.IsNullOrWhiteSpace(text)) throw new ArgumentNullOrEmptyException(nameof(text)); @@ -179,7 +180,7 @@ namespace Umbraco.Core.Manifest } // purely for tests - public IEnumerable ParseGridEditors(string text) + public IEnumerable ParseGridEditors(string text) { return JsonConvert.DeserializeObject>(text); } diff --git a/src/Umbraco.Core/Manifest/PackageManifest.cs b/src/Umbraco.Core/Manifest/PackageManifest.cs index e50eb69467..a81021432d 100644 --- a/src/Umbraco.Core/Manifest/PackageManifest.cs +++ b/src/Umbraco.Core/Manifest/PackageManifest.cs @@ -1,70 +1,70 @@ -using System; -using Newtonsoft.Json; -using Umbraco.Core.PropertyEditors; - -namespace Umbraco.Core.Manifest -{ - /// - /// Represents the content of a package manifest. - /// - public class PackageManifest - { - /// - /// Gets the source path of the manifest. - /// - /// - /// Gets the full absolute file path of the manifest, - /// using system directory separators. - /// - [JsonIgnore] - public string Source { get; set; } - - /// - /// Gets or sets the scripts listed in the manifest. - /// - [JsonProperty("javascript")] - public string[] Scripts { get; set; } = Array.Empty(); - - /// - /// Gets or sets the stylesheets listed in the manifest. - /// - [JsonProperty("css")] - public string[] Stylesheets { get; set; } = Array.Empty(); - - /// - /// Gets or sets the property editors listed in the manifest. - /// - [JsonProperty("propertyEditors")] - public IDataEditor[] PropertyEditors { get; set; } = Array.Empty(); - - /// - /// Gets or sets the parameter editors listed in the manifest. - /// - [JsonProperty("parameterEditors")] - public IDataEditor[] ParameterEditors { get; set; } = Array.Empty(); - - /// - /// Gets or sets the grid editors listed in the manifest. - /// - [JsonProperty("gridEditors")] - public GridEditor[] GridEditors { get; set; } = Array.Empty(); - - /// - /// Gets or sets the content apps listed in the manifest. - /// - [JsonProperty("contentApps")] - public ManifestContentAppDefinition[] ContentApps { get; set; } = Array.Empty(); - - /// - /// Gets or sets the dashboards listed in the manifest. - /// - [JsonProperty("dashboards")] - public ManifestDashboard[] Dashboards { get; set; } = Array.Empty(); - - /// - /// Gets or sets the sections listed in the manifest. - /// - [JsonProperty("sections")] - public ManifestSection[] Sections { get; set; } = Array.Empty(); - } -} +using System; +using Newtonsoft.Json; +using Umbraco.Core.PropertyEditors; + +namespace Umbraco.Core.Manifest +{ + /// + /// Represents the content of a package manifest. + /// + public class PackageManifest : IPackageManifest + { + /// + /// Gets the source path of the manifest. + /// + /// + /// Gets the full absolute file path of the manifest, + /// using system directory separators. + /// + [JsonIgnore] + public string Source { get; set; } + + /// + /// Gets or sets the scripts listed in the manifest. + /// + [JsonProperty("javascript")] + public string[] Scripts { get; set; } = Array.Empty(); + + /// + /// Gets or sets the stylesheets listed in the manifest. + /// + [JsonProperty("css")] + public string[] Stylesheets { get; set; } = Array.Empty(); + + /// + /// Gets or sets the property editors listed in the manifest. + /// + [JsonProperty("propertyEditors")] + public IDataEditor[] PropertyEditors { get; set; } = Array.Empty(); + + /// + /// Gets or sets the parameter editors listed in the manifest. + /// + [JsonProperty("parameterEditors")] + public IDataEditor[] ParameterEditors { get; set; } = Array.Empty(); + + /// + /// Gets or sets the grid editors listed in the manifest. + /// + [JsonProperty("gridEditors")] + public GridEditor[] GridEditors { get; set; } = Array.Empty(); + + /// + /// Gets or sets the content apps listed in the manifest. + /// + [JsonProperty("contentApps")] + public ManifestContentAppDefinition[] ContentApps { get; set; } = Array.Empty(); + + /// + /// Gets or sets the dashboards listed in the manifest. + /// + [JsonProperty("dashboards")] + public ManifestDashboard[] Dashboards { get; set; } = Array.Empty(); + + /// + /// Gets or sets the sections listed in the manifest. + /// + [JsonProperty("sections")] + public ManifestSection[] Sections { get; set; } = Array.Empty(); + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 54a59d2162..aee3bc6864 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -158,6 +158,7 @@ + @@ -184,6 +185,7 @@ + diff --git a/src/Umbraco.Tests/Published/ModelTypeTests.cs b/src/Umbraco.Tests/Published/ModelTypeTests.cs index 622bebdf78..1dab67b351 100644 --- a/src/Umbraco.Tests/Published/ModelTypeTests.cs +++ b/src/Umbraco.Tests/Published/ModelTypeTests.cs @@ -53,7 +53,7 @@ namespace Umbraco.Tests.Published // there's an "*" there because the arrays are not true SZArray - but that changes when we map Assert.AreEqual("{alias1}[*]", ModelType.For("alias1").MakeArrayType().FullName); // note the inner assembly qualified name - Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[{alias1}[*], Umbraco.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]", typeof(IEnumerable<>).MakeGenericType(ModelType.For("alias1").MakeArrayType()).FullName); + Assert.AreEqual("System.Collections.Generic.IEnumerable`1[[{alias1}[*], Umbraco.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=null]]", typeof(IEnumerable<>).MakeGenericType(ModelType.For("alias1").MakeArrayType()).FullName); } [Test] From 4529cd408a76b61c137bcfabc950e32239dd5878 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 Nov 2019 14:08:07 +0100 Subject: [PATCH 32/61] Init CurrentCore --- src/Umbraco.Core/Runtime/CoreRuntime.cs | 4 ++-- .../Cache/DistributedCache/DistributedCacheTests.cs | 1 + src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs | 1 + src/Umbraco.Tests/CoreThings/UdiTests.cs | 1 + src/Umbraco.Tests/IO/FileSystemsTests.cs | 1 + src/Umbraco.Tests/Manifest/ManifestParserTests.cs | 1 + src/Umbraco.Tests/Models/VariationTests.cs | 1 + src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs | 1 + .../PropertyEditors/PropertyEditorValueEditorTests.cs | 1 + src/Umbraco.Tests/Published/ConvertersTests.cs | 1 + src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs | 1 + src/Umbraco.Tests/PublishedContent/NuCacheTests.cs | 1 + src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 4 ++-- src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- .../Web/Mvc/RenderIndexActionSelectorAttributeTests.cs | 1 + src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs | 2 +- src/Umbraco.Tests/Web/UmbracoHelperTests.cs | 2 +- 19 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 237dcece64..70ee3ce0bd 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -153,7 +153,7 @@ namespace Umbraco.Core.Runtime composers.Compose(); // create the factory - _factory = Current.Factory = composition.CreateFactory(); + _factory = Current.Factory = CurrentCore.Factory = composition.CreateFactory(); // create & initialize the components _components = _factory.GetInstance(); @@ -178,7 +178,7 @@ namespace Umbraco.Core.Runtime { try { - _factory = Current.Factory = composition?.CreateFactory(); + _factory = Current.Factory = CurrentCore.Factory = composition?.CreateFactory(); } catch { /* yea */ } } diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index b752cb6a90..33a1aa16a5 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -35,6 +35,7 @@ namespace Umbraco.Tests.Cache.DistributedCache .Add(); Current.Factory = composition.CreateFactory(); + CurrentCore.Factory = composition.CreateFactory(); _distributedCache = new Umbraco.Web.Cache.DistributedCache(); } diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index 0073a4d624..bf79b340dc 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -27,6 +27,7 @@ namespace Umbraco.Tests.Composing .Add(() => TypeLoader.GetPackageActions()); Current.Factory = composition.CreateFactory(); + CurrentCore.Factory = composition.CreateFactory(); var actions = Current.PackageActions; Assert.AreEqual(2, actions.Count()); diff --git a/src/Umbraco.Tests/CoreThings/UdiTests.cs b/src/Umbraco.Tests/CoreThings/UdiTests.cs index 2770803bea..8a5450a5ab 100644 --- a/src/Umbraco.Tests/CoreThings/UdiTests.cs +++ b/src/Umbraco.Tests/CoreThings/UdiTests.cs @@ -29,6 +29,7 @@ namespace Umbraco.Tests.CoreThings container.Setup(x => x.GetInstance(typeof(TypeLoader))).Returns( new TypeLoader(NoAppCache.Instance, IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of(), Mock.Of()))); Current.Factory = container.Object; + CurrentCore.Factory = container.Object; Udi.ResetUdiTypes(); } diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 2a32a1bc27..bcbaca3917 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -47,6 +47,7 @@ namespace Umbraco.Tests.IO Current.Reset(); Current.Factory = _factory; + CurrentCore.Factory = _factory; // make sure we start clean // because some tests will create corrupt or weird filesystems diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index 0a187c5a8a..f01e307b4b 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -27,6 +27,7 @@ namespace Umbraco.Tests.Manifest Current.Reset(); var factory = Mock.Of(); Current.Factory = factory; + CurrentCore.Factory = factory; var serviceContext = ServiceContext.CreatePartial( localizedTextService: Mock.Of()); diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index ce78287d6d..ef788bcdbe 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -34,6 +34,7 @@ namespace Umbraco.Tests.Models var factory = Mock.Of(); Current.Factory = factory; + CurrentCore.Factory = factory; var dataEditors = new DataEditorCollection(new IDataEditor[] { diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index dcf225d952..7a7c8ae2ec 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -75,6 +75,7 @@ namespace Umbraco.Tests.PropertyEditors composition.WithCollectionBuilder(); Current.Factory = composition.CreateFactory(); + CurrentCore.Factory = composition.CreateFactory(); var logger = Mock.Of(); var scheme = Mock.Of(); diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index c1b80b97b1..19549f66fe 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -31,6 +31,7 @@ namespace Umbraco.Tests.PropertyEditors => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(SettingsForTests.GetDefaultUmbracoSettings()))); Current.Factory = composition.CreateFactory(); + CurrentCore.Factory = composition.CreateFactory(); } [TearDown] diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index 01e14edf12..061736a884 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -193,6 +193,7 @@ namespace Umbraco.Tests.Published register.Register(f => factory); Current.Factory = composition.CreateFactory(); + CurrentCore.Factory = composition.CreateFactory(); var cacheMock = new Mock(); var cacheContent = new Dictionary(); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index f08d77a80f..7dd1241951 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -53,6 +53,7 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; + CurrentCore.Factory = factory; var configs = new ConfigsFactory().Create(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 7dba201b0a..782bb2bfa3 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -48,6 +48,7 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; + CurrentCore.Factory = factory; var configs = new ConfigsFactory().Create(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index b1e2f24564..16908e027d 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -59,7 +59,7 @@ namespace Umbraco.Tests.Runtimes var logger = new ConsoleLogger(new MessageTemplates()); var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); - var appCaches = AppCaches.Disabled; + var appCaches = AppCaches.Disabled; var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy(() => factory.GetInstance())); var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var mainDom = new SimpleMainDom(); @@ -116,7 +116,7 @@ namespace Umbraco.Tests.Runtimes composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); // create and register the factory - Current.Factory = factory = composition.CreateFactory(); + Current.Factory = CurrentCore.Factory = factory = composition.CreateFactory(); // instantiate and initialize components var components = factory.GetInstance(); diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index 1597ef35cc..921c62e11f 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -44,7 +44,7 @@ namespace Umbraco.Tests.Scoping composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); Current.Reset(); - Current.Factory = composition.CreateFactory(); + Current.Factory = CurrentCore.Factory = composition.CreateFactory(); SettingsForTests.Reset(); // ensure we have configuration } diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index a042803639..2a4db7dcef 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -54,7 +54,7 @@ namespace Umbraco.Tests.TestHelpers composition.RegisterUnique(_ => SqlContext); - var factory = Current.Factory = composition.CreateFactory(); + var factory = Current.Factory = CurrentCore.Factory = composition.CreateFactory(); var pocoMappers = new NPoco.MapperCollection { new PocoMapper() }; var pocoDataFactory = new FluentPocoDataFactory((type, iPocoDataFactory) => new PocoDataBuilder(type, pocoMappers).Init()); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index a45ac1caa7..d337108cc9 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -145,7 +145,7 @@ namespace Umbraco.Tests.Testing TestObjects = new TestObjects(register); Compose(); - Current.Factory = Factory = Composition.CreateFactory(); + Current.Factory = CurrentCore.Factory = Factory = Composition.CreateFactory(); Initialize(); } diff --git a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs index eeb1eb4b37..ba66b04a6e 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs @@ -34,6 +34,7 @@ namespace Umbraco.Tests.Web.Mvc { Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); Core.Composing.Current.Factory = Mock.Of(); + Core.Composing.CurrentCore.Factory = Mock.Of(); } [TearDown] diff --git a/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs b/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs index 3a5405548b..3fcd22cb5a 100644 --- a/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs +++ b/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Web var settings = SettingsForTests.GetDefaultUmbracoSettings(); factory.Setup(x => x.GetInstance(typeof(IUmbracoSettingsSection))).Returns(settings); - Current.Factory = factory.Object; + Current.Factory = CurrentCore.Factory = factory.Object; Umbraco.Web.Composing.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); diff --git a/src/Umbraco.Tests/Web/UmbracoHelperTests.cs b/src/Umbraco.Tests/Web/UmbracoHelperTests.cs index 26d85f60cf..1841c06adb 100644 --- a/src/Umbraco.Tests/Web/UmbracoHelperTests.cs +++ b/src/Umbraco.Tests/Web/UmbracoHelperTests.cs @@ -270,7 +270,7 @@ namespace Umbraco.Tests.Web ) ); - Current.Factory = container.Object; + Current.Factory = CurrentCore.Factory = container.Object; } } } From 80b17e388fd56e1e6355ea60cbbe2b8ad36f5ecf Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 8 Nov 2019 08:24:34 +0100 Subject: [PATCH 33/61] Using IIOHelper in ManifestParser --- src/Umbraco.Abstractions/Composing/Current.cs | 16 ++++++++++++++++ .../Configuration/ConfigsExtensions.cs | 6 ++---- src/Umbraco.Core/Configuration/ConfigsFactory.cs | 5 ++++- src/Umbraco.Core/Manifest/ManifestParser.cs | 16 +++++++++------- src/Umbraco.Core/Umbraco.Core.csproj | 8 +++----- .../Manifest/ManifestParserTests.cs | 4 +++- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Abstractions/Composing/Current.cs b/src/Umbraco.Abstractions/Composing/Current.cs index a1ae87d49f..a01302f3e3 100644 --- a/src/Umbraco.Abstractions/Composing/Current.cs +++ b/src/Umbraco.Abstractions/Composing/Current.cs @@ -39,6 +39,22 @@ namespace Umbraco.Core.Composing } } + /// + /// Resets . Indented for testing only, and not supported in production code. + /// + /// + /// For UNIT TESTS exclusively. + /// Resets everything that is 'current'. + /// + public static void Reset() + { + _factory.DisposeIfDisposable(); + _factory = null; + + _logger = null; + _profiler = null; + _profilingLogger = null; + } public static bool HasFactory => _factory != null; #region Getters diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs index 19fd899a0f..ae3341aff8 100644 --- a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Core/Configuration/ConfigsExtensions.cs @@ -1,9 +1,7 @@ using System.IO; using Umbraco.Core.Cache; -using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Grid; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; @@ -16,9 +14,9 @@ namespace Umbraco.Core public static class ConfigsExtensions { - public static void AddCoreConfigs(this Configs configs) + public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper) { - var configDir = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Config)); + var configDir = new DirectoryInfo(ioHelper.MapPath(SystemDirectories.Config)); // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition configs.Add(factory => new GridConfig( diff --git a/src/Umbraco.Core/Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs index c0e80d3798..4d8b1cd3aa 100644 --- a/src/Umbraco.Core/Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -1,4 +1,5 @@ using System.Configuration; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; @@ -6,6 +7,8 @@ namespace Umbraco.Core.Configuration { public class ConfigsFactory : IConfigsFactory { + + public Configs Create() { var configs = new Configs(section => ConfigurationManager.GetSection(section)); configs.Add(() => new GlobalSettings()); @@ -13,7 +16,7 @@ namespace Umbraco.Core.Configuration configs.Add("umbracoConfiguration/HealthChecks"); configs.Add(() => new CoreDebug()); - configs.AddCoreConfigs(); + configs.AddCoreConfigs(Current.IOHelper); return configs; } } diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index 21f1d71196..c3251da7f5 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -6,7 +6,6 @@ using System.Text; using Newtonsoft.Json; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.Grid; -using Umbraco.Core.Composing; using Umbraco.Core.Exceptions; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -23,6 +22,7 @@ namespace Umbraco.Core.Manifest private readonly IAppPolicyCache _cache; private readonly ILogger _logger; + private readonly IIOHelper _ioHelper; private readonly ManifestValueValidatorCollection _validators; private readonly ManifestFilterCollection _filters; @@ -31,28 +31,30 @@ namespace Umbraco.Core.Manifest /// /// Initializes a new instance of the class. /// - public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger) - : this(appCaches, validators, filters, "~/App_Plugins", logger) + public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger, IIOHelper ioHelper) + : this(appCaches, validators, filters, SystemDirectories.AppPlugins, logger, ioHelper) { } /// /// Initializes a new instance of the class. /// - private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger) + private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger, IIOHelper ioHelper) { if (appCaches == null) throw new ArgumentNullException(nameof(appCaches)); _cache = appCaches.RuntimeCache; _validators = validators ?? throw new ArgumentNullException(nameof(validators)); _filters = filters ?? throw new ArgumentNullException(nameof(filters)); if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullOrEmptyException(nameof(path)); + _ioHelper = ioHelper; Path = path; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } public string Path { get => _path; - set => _path = value.StartsWith("~/") ? Current.IOHelper.MapPath(value) : value; + set => _path = value.StartsWith("~/") ? _ioHelper.MapPath(value) : value; } /// @@ -167,9 +169,9 @@ namespace Umbraco.Core.Manifest // scripts and stylesheets are raw string, must process here for (var i = 0; i < manifest.Scripts.Length; i++) - manifest.Scripts[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Scripts[i]); + manifest.Scripts[i] = _ioHelper.ResolveVirtualUrl(manifest.Scripts[i]); for (var i = 0; i < manifest.Stylesheets.Length; i++) - manifest.Stylesheets[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Stylesheets[i]); + manifest.Stylesheets[i] = _ioHelper.ResolveVirtualUrl(manifest.Stylesheets[i]); // add property editors that are also parameter editors, to the parameter editors list // (the manifest format is kinda legacy) diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 6852a95a3b..412458915b 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -244,7 +244,10 @@ + + + @@ -538,11 +541,6 @@ - - - - - diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index f01e307b4b..bf4ee433ee 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -13,6 +13,7 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; using Umbraco.Core.Services; using Umbraco.Core.Dashboards; +using Umbraco.Core.IO; namespace Umbraco.Tests.Manifest { @@ -25,6 +26,7 @@ namespace Umbraco.Tests.Manifest public void Setup() { Current.Reset(); + CurrentCore.Reset(); var factory = Mock.Of(); Current.Factory = factory; CurrentCore.Factory = factory; @@ -45,7 +47,7 @@ namespace Umbraco.Tests.Manifest new RequiredValidator(Mock.Of()), new RegexValidator(Mock.Of(), null) }; - _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), Mock.Of()); + _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), Mock.Of(), Mock.Of()); } [Test] From 3a9686d56b6882570ce31a0ed7fb6425b761e275 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 12 Nov 2019 14:42:57 +0100 Subject: [PATCH 34/61] AB3594 - Moved more config stuff --- .../Configuration/Grid/GridConfig.cs | 2 +- .../Configuration/Grid/GridEditorsConfig.cs | 0 src/Umbraco.Core/Umbraco.Core.csproj | 3 --- 3 files changed, 1 insertion(+), 4 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Configuration/Grid/GridConfig.cs (92%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Configuration/Grid/GridEditorsConfig.cs (100%) diff --git a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs b/src/Umbraco.Abstractions/Configuration/Grid/GridConfig.cs similarity index 92% rename from src/Umbraco.Core/Configuration/Grid/GridConfig.cs rename to src/Umbraco.Abstractions/Configuration/Grid/GridConfig.cs index 9691c749df..de4f7ccd5a 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs +++ b/src/Umbraco.Abstractions/Configuration/Grid/GridConfig.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Manifest; namespace Umbraco.Core.Configuration.Grid { - class GridConfig : IGridConfig + public class GridConfig : IGridConfig { public GridConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, IManifestParser manifestParser, bool isDebug) { diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Abstractions/Configuration/Grid/GridEditorsConfig.cs similarity index 100% rename from src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs rename to src/Umbraco.Abstractions/Configuration/Grid/GridEditorsConfig.cs diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index dcf4214ab1..6eefa3b8c3 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -157,8 +157,6 @@ - - @@ -1035,6 +1033,5 @@ Umbraco.Configuration - \ No newline at end of file From 3ffa7700ffe0eec05f5bb7b656b509d7853f6fcf Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 12 Nov 2019 14:46:56 +0100 Subject: [PATCH 35/61] AB3594 - missing xmldoc end --- .../Events/CancellableEnumerableObjectEventArgs.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs b/src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs index 5ac77d6253..1d52d0d847 100644 --- a/src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs +++ b/src/Umbraco.Abstractions/Events/CancellableEnumerableObjectEventArgs.cs @@ -6,6 +6,7 @@ namespace Umbraco.Core.Events { /// /// Represents event data, for events that support cancellation, and expose impacted objects. + /// /// The type of the exposed, impacted objects. public class CancellableEnumerableObjectEventArgs : CancellableObjectEventArgs>, IEquatable> { From ad91b2d9fc661a0a70ea7997851ad065c83ff42a Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 13 Nov 2019 10:48:51 +0100 Subject: [PATCH 36/61] More movement --- .../Configuration/ConfigsExtensions.cs | 5 +++-- .../Configuration/GlobalSettingsExtensions.cs | 17 +++++--------- src/Umbraco.Abstractions/Services/IRuntime.cs | 2 +- .../Configuration/ConfigsFactory.cs | 13 ++++++++--- .../Configuration/GlobalSettings.cs | 22 +++++++++++++------ src/Umbraco.Core/ConventionsHelper.cs | 18 ++++++++++----- src/Umbraco.Core/Runtime/CoreRuntime.cs | 19 +++++++++++----- src/Umbraco.Core/Umbraco.Core.csproj | 2 -- src/Umbraco.Core/UriExtensions.cs | 13 ++++++----- .../Components/ComponentTests.cs | 19 ++++++++-------- .../Configurations/GlobalSettingsTests.cs | 2 +- src/Umbraco.Tests/Macros/MacroTests.cs | 2 +- src/Umbraco.Tests/Models/MacroTests.cs | 2 +- src/Umbraco.Tests/Models/MemberTests.cs | 2 +- src/Umbraco.Tests/Models/UserTests.cs | 2 +- src/Umbraco.Tests/Models/VariationTests.cs | 2 +- .../PublishedContent/NuCacheChildrenTests.cs | 5 +++-- .../PublishedContent/NuCacheTests.cs | 5 +++-- .../Runtimes/CoreRuntimeTests.cs | 10 +++++---- .../TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 9 +++++++- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 3 ++- src/Umbraco.Web/AppBuilderExtensions.cs | 3 ++- .../Editors/AuthenticationController.cs | 2 +- .../Editors/BackOfficeController.cs | 2 +- src/Umbraco.Web/Editors/UsersController.cs | 2 +- .../InstallSteps/DatabaseInstallStep.cs | 3 ++- .../Mvc/AreaRegistrationExtensions.cs | 3 ++- src/Umbraco.Web/Mvc/BackOfficeArea.cs | 8 ++++--- .../Runtime/WebInitialComponent.cs | 4 ++-- src/Umbraco.Web/Runtime/WebRuntime.cs | 4 ++-- src/Umbraco.Web/UmbracoApplicationBase.cs | 2 +- 32 files changed, 124 insertions(+), 85 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Configuration/ConfigsExtensions.cs (85%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Configuration/GlobalSettingsExtensions.cs (76%) diff --git a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs similarity index 85% rename from src/Umbraco.Core/Configuration/ConfigsExtensions.cs rename to src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs index ae3341aff8..275606e8bb 100644 --- a/src/Umbraco.Core/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs @@ -1,5 +1,6 @@ using System.IO; using Umbraco.Core.Cache; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Grid; using Umbraco.Core.IO; @@ -14,9 +15,9 @@ namespace Umbraco.Core public static class ConfigsExtensions { - public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper) + public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper, ISystemDirectories systemDirectories) { - var configDir = new DirectoryInfo(ioHelper.MapPath(SystemDirectories.Config)); + var configDir = new DirectoryInfo(ioHelper.MapPath(systemDirectories.Config)); // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition configs.Add(factory => new GridConfig( diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs similarity index 76% rename from src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs rename to src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs index 2bc1e8d8c2..6f07c474b5 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs @@ -1,11 +1,4 @@ using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Web; -using System.Web.Routing; -using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Core.Configuration @@ -26,16 +19,16 @@ namespace Umbraco.Core.Configuration /// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something /// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco". /// - public static string GetUmbracoMvcArea(this IGlobalSettings globalSettings) + public static string GetUmbracoMvcArea(this IGlobalSettings globalSettings, ISystemDirectories systemDirectories) { if (_mvcArea != null) return _mvcArea; - _mvcArea = GetUmbracoMvcAreaNoCache(globalSettings); + _mvcArea = GetUmbracoMvcAreaNoCache(globalSettings, systemDirectories); return _mvcArea; } - internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings) + internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings, ISystemDirectories systemDirectories) { if (globalSettings.Path.IsNullOrWhiteSpace()) { @@ -43,8 +36,8 @@ namespace Umbraco.Core.Configuration } var path = globalSettings.Path; - if (path.StartsWith(Current.SystemDirectories.Root)) // beware of TrimStart, see U4-2518 - path = path.Substring(Current.SystemDirectories.Root.Length); + if (path.StartsWith(systemDirectories.Root)) // beware of TrimStart, see U4-2518 + path = path.Substring(systemDirectories.Root.Length); return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower(); } diff --git a/src/Umbraco.Abstractions/Services/IRuntime.cs b/src/Umbraco.Abstractions/Services/IRuntime.cs index a7944ad256..e846342dbc 100644 --- a/src/Umbraco.Abstractions/Services/IRuntime.cs +++ b/src/Umbraco.Abstractions/Services/IRuntime.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core /// /// The application register. /// The application factory. - IFactory Boot(IRegister register, IConfigsFactory configsFactory); + IFactory Boot(IRegister register); /// /// Gets the runtime state. diff --git a/src/Umbraco.Core/Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs index 4d8b1cd3aa..1a0cb8d7c5 100644 --- a/src/Umbraco.Core/Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -1,22 +1,29 @@ using System.Configuration; -using Umbraco.Core.Composing; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; namespace Umbraco.Core.Configuration { public class ConfigsFactory : IConfigsFactory { + private readonly IIOHelper _ioHelper; + private readonly ISystemDirectories _systemDirectories; + public ConfigsFactory(IIOHelper ioHelper, ISystemDirectories systemDirectories) + { + _ioHelper = ioHelper; + _systemDirectories = systemDirectories; + } public Configs Create() { var configs = new Configs(section => ConfigurationManager.GetSection(section)); - configs.Add(() => new GlobalSettings()); + configs.Add(() => new GlobalSettings(_ioHelper, _systemDirectories)); configs.Add("umbracoConfiguration/settings"); configs.Add("umbracoConfiguration/HealthChecks"); configs.Add(() => new CoreDebug()); - configs.AddCoreConfigs(Current.IOHelper); + configs.AddCoreConfigs(_ioHelper, _systemDirectories); return configs; } } diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index 0e024346af..ee64cc3842 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -19,6 +19,8 @@ namespace Umbraco.Core.Configuration /// public class GlobalSettings : IGlobalSettings { + private readonly IIOHelper _ioHelper; + private readonly ISystemDirectories _systemDirectories; private string _localTempPath; // TODO these should not be static @@ -29,6 +31,12 @@ namespace Umbraco.Core.Configuration internal const string StaticReservedPaths = "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; //must end with a comma! internal const string StaticReservedUrls = "~/config/splashes/noNodes.aspx,~/.well-known,"; //must end with a comma! + public GlobalSettings(IIOHelper ioHelper, ISystemDirectories systemDirectories) + { + _ioHelper = ioHelper; + _systemDirectories = systemDirectories; + } + /// /// Used in unit testing to reset all config items that were set with property setters (i.e. did not come from config) /// @@ -141,7 +149,7 @@ namespace Umbraco.Core.Configuration get { return ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.Path) - ? Current.IOHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path]) + ? _ioHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path]) : string.Empty; } } @@ -160,7 +168,7 @@ namespace Umbraco.Core.Configuration } set { - SaveSetting(Constants.AppSettings.ConfigurationStatus, value); + SaveSetting(Constants.AppSettings.ConfigurationStatus, value, _ioHelper, _systemDirectories); } } @@ -169,9 +177,9 @@ namespace Umbraco.Core.Configuration /// /// Key of the setting to be saved. /// Value of the setting to be saved. - internal static void SaveSetting(string key, string value) + internal static void SaveSetting(string key, string value, IIOHelper ioHelper, ISystemDirectories systemDirectories) { - var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", Current.SystemDirectories.Root)); + var fileName = ioHelper.MapPath(string.Format("{0}/web.config", systemDirectories.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -191,9 +199,9 @@ namespace Umbraco.Core.Configuration /// Removes a setting from the configuration file. /// /// Key of the setting to be removed. - internal static void RemoveSetting(string key) + internal static void RemoveSetting(string key, IIOHelper ioHelper, ISystemDirectories systemDirectories) { - var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", Current.SystemDirectories.Root)); + var fileName = ioHelper.MapPath(string.Format("{0}/web.config", systemDirectories.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -320,7 +328,7 @@ namespace Umbraco.Core.Configuration //case LocalTempStorage.Default: //case LocalTempStorage.Unknown: default: - return _localTempPath = Current.IOHelper.MapPath("~/App_Data/TEMP"); + return _localTempPath = _ioHelper.MapPath("~/App_Data/TEMP"); } } } diff --git a/src/Umbraco.Core/ConventionsHelper.cs b/src/Umbraco.Core/ConventionsHelper.cs index 16ad95b95e..834078f84d 100644 --- a/src/Umbraco.Core/ConventionsHelper.cs +++ b/src/Umbraco.Core/ConventionsHelper.cs @@ -21,7 +21,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Integer, true, Constants.Conventions.Member.FailedPasswordAttempts) { - Name = Constants.Conventions.Member.FailedPasswordAttemptsLabel + Name = Constants.Conventions.Member.FailedPasswordAttemptsLabel, + DataTypeId = Constants.DataTypes.LabelInt } }, { @@ -45,7 +46,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Date, true, Constants.Conventions.Member.LastLockoutDate) { - Name = Constants.Conventions.Member.LastLockoutDateLabel + Name = Constants.Conventions.Member.LastLockoutDateLabel, + DataTypeId = Constants.DataTypes.LabelDateTime } }, { @@ -53,7 +55,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Date, true, Constants.Conventions.Member.LastLoginDate) { - Name = Constants.Conventions.Member.LastLoginDateLabel + Name = Constants.Conventions.Member.LastLoginDateLabel, + DataTypeId = Constants.DataTypes.LabelDateTime } }, { @@ -61,7 +64,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Date, true, Constants.Conventions.Member.LastPasswordChangeDate) { - Name = Constants.Conventions.Member.LastPasswordChangeDateLabel + Name = Constants.Conventions.Member.LastPasswordChangeDateLabel, + DataTypeId = Constants.DataTypes.LabelDateTime } }, { @@ -69,7 +73,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Nvarchar, true, Constants.Conventions.Member.PasswordAnswer) { - Name = Constants.Conventions.Member.PasswordAnswerLabel + Name = Constants.Conventions.Member.PasswordAnswerLabel, + DataTypeId = Constants.DataTypes.LabelString } }, { @@ -77,7 +82,8 @@ namespace Umbraco.Core new PropertyType(Constants.PropertyEditors.Aliases.Label, ValueStorageType.Nvarchar, true, Constants.Conventions.Member.PasswordQuestion) { - Name = Constants.Conventions.Member.PasswordQuestionLabel + Name = Constants.Conventions.Member.PasswordQuestionLabel, + DataTypeId = Constants.DataTypes.LabelString } } }; diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 6918c16295..123793edae 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -53,12 +53,13 @@ namespace Umbraco.Core.Runtime /// Gets the /// protected IIOHelper IOHelper { get; private set; } + protected ISystemDirectories SystemDirectories { get; private set; } /// public IRuntimeState State => _state; /// - public virtual IFactory Boot(IRegister register, IConfigsFactory configsFactory) + public virtual IFactory Boot(IRegister register) { // create and register the essential services // ie the bare minimum required to boot @@ -81,6 +82,10 @@ namespace Umbraco.Core.Runtime if (TypeFinder == null) throw new InvalidOperationException($"The object returned from {nameof(GetTypeFinder)} cannot be null"); + SystemDirectories = GetSystemDirectories(); + if (SystemDirectories == null) + throw new InvalidOperationException($"The object returned from {nameof(GetSystemDirectories)} cannot be null"); + // the boot loader boots using a container scope, so anything that is PerScope will // be disposed after the boot loader has booted, and anything else will remain. // note that this REQUIRES that perWebRequestScope has NOT been enabled yet, else @@ -106,7 +111,7 @@ namespace Umbraco.Core.Runtime ConfigureUnhandledException(); ConfigureApplicationRootPath(); - Boot(register, timer, configsFactory); + Boot(register, timer); } return _factory; @@ -115,7 +120,7 @@ namespace Umbraco.Core.Runtime /// /// Boots the runtime within a timer. /// - protected virtual IFactory Boot(IRegister register, DisposableTimer timer, IConfigsFactory configsFactory) + protected virtual IFactory Boot(IRegister register, DisposableTimer timer) { Composition composition = null; @@ -134,7 +139,7 @@ namespace Umbraco.Core.Runtime var databaseFactory = GetDatabaseFactory(); // configs - var configs = GetConfigs(configsFactory); + var configs = GetConfigs(); // type finder/loader var typeLoader = new TypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(configs.Global().LocalTempPath), ProfilingLogger); @@ -350,6 +355,8 @@ namespace Umbraco.Core.Runtime /// protected virtual IIOHelper GetIOHelper() => Umbraco.Core.IO.IOHelper.Default; + protected virtual ISystemDirectories GetSystemDirectories() + => new SystemDirectories(); /// /// Gets the application caches. @@ -381,9 +388,9 @@ namespace Umbraco.Core.Runtime /// /// Gets the configurations. /// - protected virtual Configs GetConfigs(IConfigsFactory configsFactory) + protected virtual Configs GetConfigs() { - var configs = configsFactory.Create(); + var configs = new ConfigsFactory(IOHelper, SystemDirectories).Create(); return configs; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 6eefa3b8c3..4ac93262da 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -153,10 +153,8 @@ - - diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 9fd1bf46dc..2cd7bef26d 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -52,9 +52,10 @@ namespace Umbraco.Core //if not, then def not back office if (isUmbracoPath == false) return false; + var mvcArea = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); //if its the normal /umbraco path - if (urlPath.InvariantEquals("/" + globalSettings.GetUmbracoMvcArea()) - || urlPath.InvariantEquals("/" + globalSettings.GetUmbracoMvcArea() + "/")) + if (urlPath.InvariantEquals("/" + mvcArea) + || urlPath.InvariantEquals("/" + mvcArea + "/")) { return true; } @@ -75,15 +76,15 @@ namespace Umbraco.Core } //check for special back office paths - if (urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/BackOffice/") - || urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Preview/")) + if (urlPath.InvariantStartsWith("/" + mvcArea + "/BackOffice/") + || urlPath.InvariantStartsWith("/" + mvcArea + "/Preview/")) { return true; } //check for special front-end paths - if (urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Surface/") - || urlPath.InvariantStartsWith("/" + globalSettings.GetUmbracoMvcArea() + "/Api/")) + if (urlPath.InvariantStartsWith("/" + mvcArea + "/Surface/") + || urlPath.InvariantStartsWith("/" + mvcArea + "/Api/")) { return false; } diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index a57eb9a823..9227d84579 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -14,6 +14,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Scoping; +using Umbraco.Tests.TestHelpers; [assembly:DisableComposer(typeof(Umbraco.Tests.Components.ComponentTests.Composer26))] @@ -25,7 +26,7 @@ namespace Umbraco.Tests.Components private static readonly List Composed = new List(); private static readonly List Initialized = new List(); private static readonly List Terminated = new List(); - private static readonly Configs Configs = new ConfigsFactory().Create(); + private static readonly Configs Configs = TestHelper.GetConfigs(); private static IFactory MockFactory(Action> setup = null) { @@ -70,7 +71,7 @@ namespace Umbraco.Tests.Components public void Boot1A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -109,7 +110,7 @@ namespace Umbraco.Tests.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -125,7 +126,7 @@ namespace Umbraco.Tests.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -140,7 +141,7 @@ namespace Umbraco.Tests.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -157,7 +158,7 @@ namespace Umbraco.Tests.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -180,7 +181,7 @@ namespace Umbraco.Tests.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = TypeArray(); var composers = new Composers(composition, types, Mock.Of()); @@ -215,7 +216,7 @@ namespace Umbraco.Tests.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Mock.Of()); @@ -241,7 +242,7 @@ namespace Umbraco.Tests.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), new ConfigsFactory().Create()); + var composition = new Composition(register, MockTypeLoader(), Mock.Of(), MockRuntimeState(RuntimeLevel.Unknown), TestHelper.GetConfigs()); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Mock.Of()); diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index bab6a13dad..722260fba7 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -52,7 +52,7 @@ namespace Umbraco.Tests.Configurations globalSettingsMock.Setup(x => x.Path).Returns(() => Current.IOHelper.ResolveUrl(path)); Current.SystemDirectories.Root = rootPath; - Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache()); + Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(new SystemDirectories())); } diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index f15795e299..6bf7e808a9 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.Macros //Current.ApplicationContext = new ApplicationContext(cacheHelper, new ProfilingLogger(Mock.Of(), Mock.Of())); Current.Reset(); - Current.UnlockConfigs(new ConfigsFactory()); + Current.UnlockConfigs(TestHelper.GetConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/MacroTests.cs b/src/Umbraco.Tests/Models/MacroTests.cs index e96a8c7915..e263d99cec 100644 --- a/src/Umbraco.Tests/Models/MacroTests.cs +++ b/src/Umbraco.Tests/Models/MacroTests.cs @@ -16,7 +16,7 @@ namespace Umbraco.Tests.Models public void Init() { Current.Reset(); - Current.UnlockConfigs(new ConfigsFactory()); + Current.UnlockConfigs(TestHelper.GetConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/MemberTests.cs b/src/Umbraco.Tests/Models/MemberTests.cs index 2a55268c48..836ce54afa 100644 --- a/src/Umbraco.Tests/Models/MemberTests.cs +++ b/src/Umbraco.Tests/Models/MemberTests.cs @@ -19,7 +19,7 @@ namespace Umbraco.Tests.Models public void Setup() { Current.Reset(); - Current.UnlockConfigs(new ConfigsFactory()); + Current.UnlockConfigs(TestHelper.GetConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); Current.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); } diff --git a/src/Umbraco.Tests/Models/UserTests.cs b/src/Umbraco.Tests/Models/UserTests.cs index 48e8de3fab..603cd84a1a 100644 --- a/src/Umbraco.Tests/Models/UserTests.cs +++ b/src/Umbraco.Tests/Models/UserTests.cs @@ -18,7 +18,7 @@ namespace Umbraco.Tests.Models public void Setup() { Current.Reset(); - Current.UnlockConfigs(new ConfigsFactory()); + Current.UnlockConfigs(TestHelper.GetConfigsFactory()); Current.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); } diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs index 32ff48ab12..c2651a6ff6 100644 --- a/src/Umbraco.Tests/Models/VariationTests.cs +++ b/src/Umbraco.Tests/Models/VariationTests.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Models Current.Reset(); - var configs = new ConfigsFactory().Create(); + var configs = TestHelper.GetConfigs(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index 7c3bd73692..59f324387a 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -10,6 +10,7 @@ using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; @@ -54,9 +55,9 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = new ConfigsFactory().Create(); + var configs = TestHelper.GetConfigs(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); - var globalSettings = new GlobalSettings(); + var globalSettings = new GlobalSettings(IOHelper.Default, new SystemDirectories()); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); configs.Add(() => globalSettings); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 32f5d06e74..f6ad657a75 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -8,6 +8,7 @@ using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; @@ -49,9 +50,9 @@ namespace Umbraco.Tests.PublishedContent var factory = Mock.Of(); Current.Factory = factory; - var configs = new ConfigsFactory().Create(); + var configs = TestHelper.GetConfigs(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); - var globalSettings = new GlobalSettings(); + var globalSettings = new GlobalSettings(IOHelper.Default, new SystemDirectories()); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); configs.Add(() => globalSettings); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index daf4f4afe6..b29d86f56b 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -4,6 +4,7 @@ using System.Data; using System.Web.Hosting; using Examine; using Moq; +using NPoco.Expressions; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Compose; @@ -11,6 +12,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.Exceptions; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Runtime; @@ -102,9 +104,9 @@ namespace Umbraco.Tests.Runtimes return mock.Object; } - protected override Configs GetConfigs(IConfigsFactory configsFactory) + protected override Configs GetConfigs() { - var configs = configsFactory.Create(); + var configs = new ConfigsFactory(Umbraco.Core.IO.IOHelper.Default, new SystemDirectories()).Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); return configs; @@ -142,9 +144,9 @@ namespace Umbraco.Tests.Runtimes private IMainDom _mainDom; - public override IFactory Boot(IRegister container, IConfigsFactory configsFactory) + public override IFactory Boot(IRegister container) { - var factory = base.Boot(container, configsFactory); + var factory = base.Boot(container); _mainDom = factory.GetInstance(); return factory; } diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index 3aa4495601..305143ec0f 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -45,7 +45,7 @@ namespace Umbraco.Tests.TestHelpers logger, false); - var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); + var composition = new Composition(container, typeLoader, Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); composition.RegisterUnique(_ => Mock.Of()); composition.RegisterUnique(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 9e5995cfb5..c5f169a232 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -36,7 +36,12 @@ namespace Umbraco.Tests.TestHelpers public static Configs GetConfigs() { - return new ConfigsFactory().Create(); + return GetConfigsFactory().Create(); + } + + public static IConfigsFactory GetConfigsFactory() + { + return new ConfigsFactory(IOHelper.Default, new SystemDirectories()); } /// @@ -269,5 +274,7 @@ namespace Umbraco.Tests.TestHelpers ); } + + } } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index d11bf8e5d7..fdc43fee59 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -141,7 +141,7 @@ namespace Umbraco.Tests.Testing var register = RegisterFactory.Create(); - Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), new ConfigsFactory().Create()); + Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); Composition.RegisterUnique(IOHelper); @@ -229,6 +229,7 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(); Composition.RegisterUnique(); Composition.RegisterUnique(); + Composition.RegisterUnique(); // register back office sections in the order we want them rendered Composition.WithCollectionBuilder().Append() diff --git a/src/Umbraco.Web/AppBuilderExtensions.cs b/src/Umbraco.Web/AppBuilderExtensions.cs index 04226d81f2..4259c8ebae 100644 --- a/src/Umbraco.Web/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/AppBuilderExtensions.cs @@ -9,6 +9,7 @@ using Microsoft.Owin.Logging; using Owin; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; +using Umbraco.Web.Composing; using Umbraco.Web.SignalR; namespace Umbraco.Web @@ -50,7 +51,7 @@ namespace Umbraco.Web /// public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr"; return app.MapSignalR(signalrPath, new HubConfiguration { EnableDetailedErrors = true }); } diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index c2c481e8e4..5da28bd0a5 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -514,7 +514,7 @@ namespace Umbraco.Web.Editors var action = urlHelper.Action("ValidatePasswordResetCode", "BackOffice", new { - area = GlobalSettings.GetUmbracoMvcArea(), + area = GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories), u = userId, r = code }); diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 68f234a22a..028eea60e8 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -352,7 +352,7 @@ namespace Umbraco.Web.Editors if (defaultResponse == null) throw new ArgumentNullException("defaultResponse"); if (externalSignInResponse == null) throw new ArgumentNullException("externalSignInResponse"); - ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea()); + ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories)); //check if there is the TempData with the any token name specified, if so, assign to view bag and render the view if (ViewData.FromTempData(TempData, ViewDataExtensions.TokenExternalSignInError) || diff --git a/src/Umbraco.Web/Editors/UsersController.cs b/src/Umbraco.Web/Editors/UsersController.cs index cf81907dda..874bc6bbfa 100644 --- a/src/Umbraco.Web/Editors/UsersController.cs +++ b/src/Umbraco.Web/Editors/UsersController.cs @@ -456,7 +456,7 @@ namespace Umbraco.Web.Editors var action = urlHelper.Action("VerifyInvite", "BackOffice", new { - area = GlobalSettings.GetUmbracoMvcArea(), + area = GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories), invite = inviteToken }); diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs index c680b6e41a..04abb51b6f 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; +using Umbraco.Web.Composing; using Umbraco.Web.Install.Models; namespace Umbraco.Web.Install.InstallSteps @@ -55,7 +56,7 @@ namespace Umbraco.Web.Install.InstallSteps // Remove legacy umbracoDbDsn configuration setting if it exists and connectionstring also exists if (ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName] != null) { - GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName); + GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName, Current.IOHelper, Current.SystemDirectories); } else { diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index 61a659615f..6c02d18822 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -7,6 +7,7 @@ using System.Web.SessionState; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Exceptions; +using Umbraco.Web.Composing; using Umbraco.Web.WebApi; namespace Umbraco.Web.Mvc @@ -55,7 +56,7 @@ namespace Umbraco.Web.Mvc if (routes == null) throw new ArgumentNullException(nameof(routes)); if (defaultId == null) throw new ArgumentNullException(nameof(defaultId)); - var umbracoArea = globalSettings.GetUmbracoMvcArea(); + var umbracoArea = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); //routes are explicitly named with controller names and IDs var url = umbracoArea + "/" + diff --git a/src/Umbraco.Web/Mvc/BackOfficeArea.cs b/src/Umbraco.Web/Mvc/BackOfficeArea.cs index e72f2cc81a..747ebe61e1 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -1,4 +1,5 @@ using System.Web.Mvc; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Web.Editors; @@ -26,15 +27,16 @@ namespace Umbraco.Web.Mvc /// public override void RegisterArea(AreaRegistrationContext context) { + context.MapRoute( "Umbraco_preview", - _globalSettings.GetUmbracoMvcArea() + "/preview/{action}/{editor}", + AreaName + "/preview/{action}/{editor}", new {controller = "Preview", action = "Index", editor = UrlParameter.Optional}, new[] { "Umbraco.Web.Editors" }); context.MapRoute( "Umbraco_back_office", - _globalSettings.GetUmbracoMvcArea() + "/{action}/{id}", + AreaName + "/{action}/{id}", new {controller = "BackOffice", action = "Default", id = UrlParameter.Optional}, //limit the action/id to only allow characters - this is so this route doesn't hog all other // routes like: /umbraco/channels/word.aspx, etc... @@ -46,6 +48,6 @@ namespace Umbraco.Web.Mvc new[] {typeof (BackOfficeController).Namespace}); } - public override string AreaName => _globalSettings.GetUmbracoMvcArea(); + public override string AreaName => _globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); } } diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index e5ad0c0665..4ba1977eb4 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -150,7 +150,7 @@ namespace Umbraco.Web.Runtime SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); // create the front-end route var defaultRoute = RouteTable.Routes.MapRoute( @@ -175,7 +175,7 @@ namespace Umbraco.Web.Runtime SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); // need to find the plugin controllers and route them var pluginControllers = surfaceControllerTypes.Concat(apiControllerTypes).ToArray(); diff --git a/src/Umbraco.Web/Runtime/WebRuntime.cs b/src/Umbraco.Web/Runtime/WebRuntime.cs index ce420e88c6..2f1ef43e4c 100644 --- a/src/Umbraco.Web/Runtime/WebRuntime.cs +++ b/src/Umbraco.Web/Runtime/WebRuntime.cs @@ -30,7 +30,7 @@ namespace Umbraco.Web.Runtime } /// - public override IFactory Boot(IRegister register, IConfigsFactory configsFactory) + public override IFactory Boot(IRegister register) { // create and start asap to profile boot var debug = GlobalSettings.DebugMode; @@ -46,7 +46,7 @@ namespace Umbraco.Web.Runtime _webProfiler = new VoidProfiler(); } - var factory = base.Boot(register, configsFactory); + var factory = base.Boot(register); // now (and only now) is the time to switch over to perWebRequest scopes. // up until that point we may not have a request, and scoped services would diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 24800500a8..dba7798559 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -63,7 +63,7 @@ namespace Umbraco.Web // the boot manager is responsible for registrations var register = GetRegister(); _runtime = GetRuntime(); - _runtime.Boot(register, new ConfigsFactory()); + _runtime.Boot(register); } // called by ASP.NET (auto event wireup) once per app domain From 0be396c4fd2123260548ed96a268b4316e6e761e Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 13 Nov 2019 12:53:01 +0100 Subject: [PATCH 37/61] Post merge fixes --- .../Configuration/ConfigsExtensions.cs | 4 ++-- .../Configuration/GlobalSettingsExtensions.cs | 10 +++++----- src/Umbraco.Abstractions/IO/IIOHelper.cs | 3 +-- src/Umbraco.Core/Configuration/ConfigsFactory.cs | 8 +++----- src/Umbraco.Core/Configuration/GlobalSettings.cs | 14 ++++++-------- src/Umbraco.Core/IO/IOHelper.cs | 4 ++-- src/Umbraco.Core/Runtime/CoreRuntime.cs | 10 +--------- src/Umbraco.Core/UriExtensions.cs | 2 +- .../Configurations/GlobalSettingsTests.cs | 8 ++++---- .../PublishedContent/NuCacheChildrenTests.cs | 2 +- src/Umbraco.Tests/PublishedContent/NuCacheTests.cs | 2 +- src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 1 - src/Umbraco.Tests/Views/textpage.cshtml | 4 ---- src/Umbraco.Web/AppBuilderExtensions.cs | 2 +- .../Editors/AuthenticationController.cs | 2 +- src/Umbraco.Web/Editors/BackOfficeController.cs | 2 +- src/Umbraco.Web/Editors/UsersController.cs | 2 +- .../Install/InstallSteps/DatabaseInstallStep.cs | 2 +- src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs | 2 +- src/Umbraco.Web/Mvc/BackOfficeArea.cs | 2 +- src/Umbraco.Web/Runtime/WebInitialComponent.cs | 4 ++-- 23 files changed, 38 insertions(+), 56 deletions(-) delete mode 100644 src/Umbraco.Tests/Views/textpage.cshtml diff --git a/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs index 275606e8bb..c955cc4796 100644 --- a/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs @@ -15,9 +15,9 @@ namespace Umbraco.Core public static class ConfigsExtensions { - public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper, ISystemDirectories systemDirectories) + public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper) { - var configDir = new DirectoryInfo(ioHelper.MapPath(systemDirectories.Config)); + var configDir = new DirectoryInfo(ioHelper.MapPath(Constants.SystemDirectories.Config)); // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition configs.Add(factory => new GridConfig( diff --git a/src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs index 6f07c474b5..4d8039dfbb 100644 --- a/src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Abstractions/Configuration/GlobalSettingsExtensions.cs @@ -19,16 +19,16 @@ namespace Umbraco.Core.Configuration /// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something /// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco". /// - public static string GetUmbracoMvcArea(this IGlobalSettings globalSettings, ISystemDirectories systemDirectories) + public static string GetUmbracoMvcArea(this IGlobalSettings globalSettings, IIOHelper ioHelper) { if (_mvcArea != null) return _mvcArea; - _mvcArea = GetUmbracoMvcAreaNoCache(globalSettings, systemDirectories); + _mvcArea = GetUmbracoMvcAreaNoCache(globalSettings, ioHelper); return _mvcArea; } - internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings, ISystemDirectories systemDirectories) + internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings, IIOHelper ioHelper) { if (globalSettings.Path.IsNullOrWhiteSpace()) { @@ -36,8 +36,8 @@ namespace Umbraco.Core.Configuration } var path = globalSettings.Path; - if (path.StartsWith(systemDirectories.Root)) // beware of TrimStart, see U4-2518 - path = path.Substring(systemDirectories.Root.Length); + if (path.StartsWith(ioHelper.Root)) // beware of TrimStart, see U4-2518 + path = path.Substring(ioHelper.Root.Length); return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower(); } diff --git a/src/Umbraco.Abstractions/IO/IIOHelper.cs b/src/Umbraco.Abstractions/IO/IIOHelper.cs index 80e06b0062..3266426cc5 100644 --- a/src/Umbraco.Abstractions/IO/IIOHelper.cs +++ b/src/Umbraco.Abstractions/IO/IIOHelper.cs @@ -18,8 +18,7 @@ namespace Umbraco.Core.IO Attempt TryResolveUrl(string virtualPath); string MapPath(string path, bool useHttpContext); string MapPath(string path); - string ReturnPath(string settingsKey, string standardPath, bool useTilde); - string ReturnPath(string settingsKey, string standardPath); + /// /// Verifies that the current filepath matches a directory where the user is allowed to edit a file. diff --git a/src/Umbraco.Core/Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs index 1a0cb8d7c5..89a31ce10b 100644 --- a/src/Umbraco.Core/Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -8,22 +8,20 @@ namespace Umbraco.Core.Configuration public class ConfigsFactory : IConfigsFactory { private readonly IIOHelper _ioHelper; - private readonly ISystemDirectories _systemDirectories; - public ConfigsFactory(IIOHelper ioHelper, ISystemDirectories systemDirectories) + public ConfigsFactory(IIOHelper ioHelper) { _ioHelper = ioHelper; - _systemDirectories = systemDirectories; } public Configs Create() { var configs = new Configs(section => ConfigurationManager.GetSection(section)); - configs.Add(() => new GlobalSettings(_ioHelper, _systemDirectories)); + configs.Add(() => new GlobalSettings(_ioHelper)); configs.Add("umbracoConfiguration/settings"); configs.Add("umbracoConfiguration/HealthChecks"); configs.Add(() => new CoreDebug()); - configs.AddCoreConfigs(_ioHelper, _systemDirectories); + configs.AddCoreConfigs(_ioHelper); return configs; } } diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index ee64cc3842..76d6c2e1c1 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -20,7 +20,6 @@ namespace Umbraco.Core.Configuration public class GlobalSettings : IGlobalSettings { private readonly IIOHelper _ioHelper; - private readonly ISystemDirectories _systemDirectories; private string _localTempPath; // TODO these should not be static @@ -31,10 +30,9 @@ namespace Umbraco.Core.Configuration internal const string StaticReservedPaths = "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; //must end with a comma! internal const string StaticReservedUrls = "~/config/splashes/noNodes.aspx,~/.well-known,"; //must end with a comma! - public GlobalSettings(IIOHelper ioHelper, ISystemDirectories systemDirectories) + public GlobalSettings(IIOHelper ioHelper) { _ioHelper = ioHelper; - _systemDirectories = systemDirectories; } /// @@ -168,7 +166,7 @@ namespace Umbraco.Core.Configuration } set { - SaveSetting(Constants.AppSettings.ConfigurationStatus, value, _ioHelper, _systemDirectories); + SaveSetting(Constants.AppSettings.ConfigurationStatus, value, _ioHelper); } } @@ -177,9 +175,9 @@ namespace Umbraco.Core.Configuration /// /// Key of the setting to be saved. /// Value of the setting to be saved. - internal static void SaveSetting(string key, string value, IIOHelper ioHelper, ISystemDirectories systemDirectories) + internal static void SaveSetting(string key, string value, IIOHelper ioHelper) { - var fileName = ioHelper.MapPath(string.Format("{0}/web.config", systemDirectories.Root)); + var fileName = ioHelper.MapPath(string.Format("{0}/web.config", ioHelper.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -199,9 +197,9 @@ namespace Umbraco.Core.Configuration /// Removes a setting from the configuration file. /// /// Key of the setting to be removed. - internal static void RemoveSetting(string key, IIOHelper ioHelper, ISystemDirectories systemDirectories) + internal static void RemoveSetting(string key, IIOHelper ioHelper) { - var fileName = ioHelper.MapPath(string.Format("{0}/web.config", systemDirectories.Root)); + var fileName = ioHelper.MapPath(string.Format("{0}/web.config", ioHelper.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 50fad1b6d5..370f9d1f7a 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -115,7 +115,7 @@ namespace Umbraco.Core.IO } //use a tilde character instead of the complete path - public string ReturnPath(string settingsKey, string standardPath, bool useTilde) + private string ReturnPath(string settingsKey, string standardPath, bool useTilde) { var retval = ConfigurationManager.AppSettings[settingsKey]; @@ -125,7 +125,7 @@ namespace Umbraco.Core.IO return retval.TrimEnd('/'); } - public string ReturnPath(string settingsKey, string standardPath) + private string ReturnPath(string settingsKey, string standardPath) { return ReturnPath(settingsKey, standardPath, false); diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 123793edae..d4647cbdd2 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -53,8 +53,6 @@ namespace Umbraco.Core.Runtime /// Gets the /// protected IIOHelper IOHelper { get; private set; } - protected ISystemDirectories SystemDirectories { get; private set; } - /// public IRuntimeState State => _state; @@ -82,10 +80,6 @@ namespace Umbraco.Core.Runtime if (TypeFinder == null) throw new InvalidOperationException($"The object returned from {nameof(GetTypeFinder)} cannot be null"); - SystemDirectories = GetSystemDirectories(); - if (SystemDirectories == null) - throw new InvalidOperationException($"The object returned from {nameof(GetSystemDirectories)} cannot be null"); - // the boot loader boots using a container scope, so anything that is PerScope will // be disposed after the boot loader has booted, and anything else will remain. // note that this REQUIRES that perWebRequestScope has NOT been enabled yet, else @@ -355,8 +349,6 @@ namespace Umbraco.Core.Runtime /// protected virtual IIOHelper GetIOHelper() => Umbraco.Core.IO.IOHelper.Default; - protected virtual ISystemDirectories GetSystemDirectories() - => new SystemDirectories(); /// /// Gets the application caches. @@ -390,7 +382,7 @@ namespace Umbraco.Core.Runtime /// protected virtual Configs GetConfigs() { - var configs = new ConfigsFactory(IOHelper, SystemDirectories).Create(); + var configs = new ConfigsFactory(IOHelper).Create(); return configs; } diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 2cd7bef26d..8aedd8f263 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -52,7 +52,7 @@ namespace Umbraco.Core //if not, then def not back office if (isUmbracoPath == false) return false; - var mvcArea = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); + var mvcArea = globalSettings.GetUmbracoMvcArea(Current.IOHelper); //if its the normal /umbraco path if (urlPath.InvariantEquals("/" + mvcArea) || urlPath.InvariantEquals("/" + mvcArea + "/")) diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index 722260fba7..c80b917784 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -17,13 +17,13 @@ namespace Umbraco.Tests.Configurations public override void SetUp() { base.SetUp(); - _root = Current.SystemDirectories.Root; + _root = Current.IOHelper.Root; } public override void TearDown() { base.TearDown(); - Current.SystemDirectories.Root = _root; + Current.IOHelper.Root = _root; } [Test] @@ -51,8 +51,8 @@ namespace Umbraco.Tests.Configurations var globalSettingsMock = Mock.Get(globalSettings); globalSettingsMock.Setup(x => x.Path).Returns(() => Current.IOHelper.ResolveUrl(path)); - Current.SystemDirectories.Root = rootPath; - Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(new SystemDirectories())); + Current.IOHelper.Root = rootPath; + Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(Core.IO.IOHelper.Default)); } diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index 59f324387a..31cfcb7dc8 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -57,7 +57,7 @@ namespace Umbraco.Tests.PublishedContent var configs = TestHelper.GetConfigs(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); - var globalSettings = new GlobalSettings(IOHelper.Default, new SystemDirectories()); + var globalSettings = new GlobalSettings(IOHelper.Default); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); configs.Add(() => globalSettings); diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index f6ad657a75..25ff5e233b 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -52,7 +52,7 @@ namespace Umbraco.Tests.PublishedContent var configs = TestHelper.GetConfigs(); Mock.Get(factory).Setup(x => x.GetInstance(typeof(Configs))).Returns(configs); - var globalSettings = new GlobalSettings(IOHelper.Default, new SystemDirectories()); + var globalSettings = new GlobalSettings(IOHelper.Default); configs.Add(SettingsForTests.GenerateMockUmbracoSettings); configs.Add(() => globalSettings); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index b29d86f56b..de8322d737 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -106,7 +106,7 @@ namespace Umbraco.Tests.Runtimes protected override Configs GetConfigs() { - var configs = new ConfigsFactory(Umbraco.Core.IO.IOHelper.Default, new SystemDirectories()).Create(); + var configs = new ConfigsFactory(Umbraco.Core.IO.IOHelper.Default).Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); return configs; diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 5ced1d66c9..6551ebf87a 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.TestHelpers public static IConfigsFactory GetConfigsFactory() { - return new ConfigsFactory(IOHelper.Default, new SystemDirectories()); + return new ConfigsFactory(IOHelper.Default); } /// diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index fdc43fee59..c963633aa0 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -229,7 +229,6 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(); Composition.RegisterUnique(); Composition.RegisterUnique(); - Composition.RegisterUnique(); // register back office sections in the order we want them rendered Composition.WithCollectionBuilder().Append() diff --git a/src/Umbraco.Tests/Views/textpage.cshtml b/src/Umbraco.Tests/Views/textpage.cshtml deleted file mode 100644 index d7b4dce307..0000000000 --- a/src/Umbraco.Tests/Views/textpage.cshtml +++ /dev/null @@ -1,4 +0,0 @@ -@inherits Umbraco.Web.Mvc.UmbracoViewPage -@{ - Layout = null; -} \ No newline at end of file diff --git a/src/Umbraco.Web/AppBuilderExtensions.cs b/src/Umbraco.Web/AppBuilderExtensions.cs index 4259c8ebae..f740d57b79 100644 --- a/src/Umbraco.Web/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/AppBuilderExtensions.cs @@ -51,7 +51,7 @@ namespace Umbraco.Web /// public static IAppBuilder UseSignalR(this IAppBuilder app, IGlobalSettings globalSettings) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.IOHelper); var signalrPath = HttpRuntime.AppDomainAppVirtualPath + umbracoPath + "/BackOffice/signalr"; return app.MapSignalR(signalrPath, new HubConfiguration { EnableDetailedErrors = true }); } diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index 5da28bd0a5..363d3bb732 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -514,7 +514,7 @@ namespace Umbraco.Web.Editors var action = urlHelper.Action("ValidatePasswordResetCode", "BackOffice", new { - area = GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories), + area = GlobalSettings.GetUmbracoMvcArea(Current.IOHelper), u = userId, r = code }); diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 028eea60e8..1276cc41d5 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -352,7 +352,7 @@ namespace Umbraco.Web.Editors if (defaultResponse == null) throw new ArgumentNullException("defaultResponse"); if (externalSignInResponse == null) throw new ArgumentNullException("externalSignInResponse"); - ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories)); + ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(Current.IOHelper)); //check if there is the TempData with the any token name specified, if so, assign to view bag and render the view if (ViewData.FromTempData(TempData, ViewDataExtensions.TokenExternalSignInError) || diff --git a/src/Umbraco.Web/Editors/UsersController.cs b/src/Umbraco.Web/Editors/UsersController.cs index 9fcb1fc828..2cd284e307 100644 --- a/src/Umbraco.Web/Editors/UsersController.cs +++ b/src/Umbraco.Web/Editors/UsersController.cs @@ -456,7 +456,7 @@ namespace Umbraco.Web.Editors var action = urlHelper.Action("VerifyInvite", "BackOffice", new { - area = GlobalSettings.GetUmbracoMvcArea(Current.SystemDirectories), + area = GlobalSettings.GetUmbracoMvcArea(Current.IOHelper), invite = inviteToken }); diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs index 04abb51b6f..7d8c7f1226 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseInstallStep.cs @@ -56,7 +56,7 @@ namespace Umbraco.Web.Install.InstallSteps // Remove legacy umbracoDbDsn configuration setting if it exists and connectionstring also exists if (ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName] != null) { - GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName, Current.IOHelper, Current.SystemDirectories); + GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName, Current.IOHelper); } else { diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index 6c02d18822..8b4f84c2dd 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -56,7 +56,7 @@ namespace Umbraco.Web.Mvc if (routes == null) throw new ArgumentNullException(nameof(routes)); if (defaultId == null) throw new ArgumentNullException(nameof(defaultId)); - var umbracoArea = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); + var umbracoArea = globalSettings.GetUmbracoMvcArea(Current.IOHelper); //routes are explicitly named with controller names and IDs var url = umbracoArea + "/" + diff --git a/src/Umbraco.Web/Mvc/BackOfficeArea.cs b/src/Umbraco.Web/Mvc/BackOfficeArea.cs index 747ebe61e1..5f257a9860 100644 --- a/src/Umbraco.Web/Mvc/BackOfficeArea.cs +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -48,6 +48,6 @@ namespace Umbraco.Web.Mvc new[] {typeof (BackOfficeController).Namespace}); } - public override string AreaName => _globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); + public override string AreaName => _globalSettings.GetUmbracoMvcArea(Current.IOHelper); } } diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index 247f2ce2c9..6edb1f0039 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -150,7 +150,7 @@ namespace Umbraco.Web.Runtime SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.IOHelper); // create the front-end route var defaultRoute = RouteTable.Routes.MapRoute( @@ -175,7 +175,7 @@ namespace Umbraco.Web.Runtime SurfaceControllerTypeCollection surfaceControllerTypes, UmbracoApiControllerTypeCollection apiControllerTypes) { - var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.SystemDirectories); + var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.IOHelper); // need to find the plugin controllers and route them var pluginControllers = surfaceControllerTypes.Concat(apiControllerTypes).ToArray(); From b50ffb11bd6348f986619f64468c16d0d397db09 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 13 Nov 2019 15:52:18 +0100 Subject: [PATCH 38/61] post merge --- src/Umbraco.Core/Configuration/GlobalSettings.cs | 1 - .../Persistence/Repositories/ScriptRepositoryTest.cs | 2 +- .../Persistence/Repositories/StylesheetRepositoryTest.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 4 ++-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index fa46bfbfbf..e4e9a3c4d7 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -6,7 +6,6 @@ using System.Web; using System.Web.Configuration; using System.Web.Hosting; using System.Xml.Linq; -using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Core.Configuration diff --git a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs index 1c82287842..997b275655 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(new GlobalSettings().UmbracoScriptsPath); + _fileSystem = new PhysicalFileSystem(SettingsForTests.GenerateMockGlobalSettings().UmbracoScriptsPath); Mock.Get(_fileSystems).Setup(x => x.ScriptsFileSystem).Returns(_fileSystem); using (var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");")) { diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index ef28b42f05..a1f0662ebd 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(new GlobalSettings().UmbracoCssPath); + _fileSystem = new PhysicalFileSystem(SettingsForTests.GenerateMockGlobalSettings().UmbracoCssPath); Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 6ee0bd70c9..5cd9359d5a 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -74,12 +74,12 @@ namespace Umbraco.Tests.TestHelpers public static void InitializeContentDirectories() { - CreateDirectories(new[] { Constants.SystemDirectories.MvcViews, new GlobalSettings().UmbracoMediaPath, Constants.SystemDirectories.AppPlugins }); + CreateDirectories(new[] { Constants.SystemDirectories.MvcViews, SettingsForTests.GenerateMockGlobalSettings().UmbracoMediaPath, Constants.SystemDirectories.AppPlugins }); } public static void CleanContentDirectories() { - CleanDirectories(new[] { Constants.SystemDirectories.MvcViews, new GlobalSettings().UmbracoMediaPath }); + CleanDirectories(new[] { Constants.SystemDirectories.MvcViews, SettingsForTests.GenerateMockGlobalSettings().UmbracoMediaPath }); } public static void CreateDirectories(string[] directories) From 126380dceeed78c2d5465fb3947578f5fef88c86 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 14 Nov 2019 11:47:34 +0100 Subject: [PATCH 39/61] AB3594 - Removed references from core to configuration --- .../Composing/Composition.cs | 0 .../Composing/IComposer.cs | 0 .../Composing/ICoreComposer.cs | 0 .../CompositionExtensions_Uniques.cs | 0 .../Configuration/ConfigsExtensions.cs | 17 ++++++ .../HealthCheckNotificationVerbosity.cs | 5 +- .../HealthChecks/IDisabledHealthCheck.cs | 0 .../IHealthCheckNotificationSettings.cs | 0 .../HealthChecks/IHealthChecks.cs | 0 .../HealthChecks/INotificationMethod.cs | 0 .../INotificationMethodSettings.cs | 0 .../Configuration/ICoreDebug.cs | 8 +++ .../Configuration/IUmbracoVersion.cs | 56 +++++++++++++++++++ .../Configuration}/UmbracoVersion.cs | 40 +++++++------ .../ConfigsExtensions.cs | 28 ---------- .../ConfigurationComposer.cs | 17 ++++++ .../UmbracoVersionExtensions.cs | 33 +++++++++++ src/Umbraco.Core/Composing/Current.cs | 3 + .../CompositionExtensions_Essentials.cs | 5 +- .../Configuration/ConfigsFactory.cs | 2 +- .../Configuration}/CoreDebug.cs | 2 +- .../Migrations/Upgrade/UmbracoPlan.cs | 2 + .../Models/Packaging/PackageDefinition.cs | 7 ++- .../Packaging/PackagesRepository.cs | 7 ++- src/Umbraco.Core/Runtime/CoreRuntime.cs | 15 ++++- src/Umbraco.Core/RuntimeState.cs | 13 +++-- .../Services/Implement/KeyValueService.cs | 7 +-- src/Umbraco.Core/Umbraco.Core.csproj | 9 +-- .../Configurations/GlobalSettingsTests.cs | 2 +- .../Misc/ApplicationUrlHelperTests.cs | 8 +-- .../Routing/UmbracoModuleTests.cs | 5 +- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 8 ++- .../TestHelpers/SettingsForTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 4 ++ src/Umbraco.Tests/TestHelpers/TestObjects.cs | 1 + .../TestHelpers/TestWithDatabaseBase.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 4 ++ src/Umbraco.Web/Composing/Current.cs | 1 + .../Editors/BackOfficeServerVariables.cs | 4 +- .../Editors/DashboardController.cs | 3 +- .../Editors/PackageInstallController.cs | 8 +-- .../Editors/UpdateCheckController.cs | 8 +-- .../Install/Controllers/InstallController.cs | 2 +- src/Umbraco.Web/Install/InstallHelper.cs | 10 ++-- .../InstallSteps/SetUmbracoVersionStep.cs | 2 +- .../InstallSteps/StarterKitDownloadStep.cs | 2 +- .../Install/InstallSteps/UpgradeStep.cs | 4 +- .../Models/UpgradeCheckResponse.cs | 3 +- .../Providers/UmbracoMembershipProvider.cs | 4 +- src/umbraco.sln | 3 - 50 files changed, 248 insertions(+), 118 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Composing/Composition.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Composing/IComposer.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Composing/ICoreComposer.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/CompositionExtensions_Uniques.cs (100%) rename src/{Umbraco.Configuration => Umbraco.Abstractions/Configuration}/HealthChecks/HealthCheckNotificationVerbosity.cs (52%) rename src/{Umbraco.Configuration => Umbraco.Abstractions/Configuration}/HealthChecks/IDisabledHealthCheck.cs (100%) rename src/{Umbraco.Configuration => Umbraco.Abstractions/Configuration}/HealthChecks/IHealthCheckNotificationSettings.cs (100%) rename src/{Umbraco.Configuration => Umbraco.Abstractions/Configuration}/HealthChecks/IHealthChecks.cs (100%) rename src/{Umbraco.Configuration => Umbraco.Abstractions/Configuration}/HealthChecks/INotificationMethod.cs (100%) rename src/{Umbraco.Configuration => Umbraco.Abstractions/Configuration}/HealthChecks/INotificationMethodSettings.cs (100%) create mode 100644 src/Umbraco.Abstractions/Configuration/ICoreDebug.cs create mode 100644 src/Umbraco.Abstractions/Configuration/IUmbracoVersion.cs rename src/{Umbraco.Configuration => Umbraco.Abstractions/Configuration}/UmbracoVersion.cs (76%) delete mode 100644 src/Umbraco.Configuration/ConfigsExtensions.cs create mode 100644 src/Umbraco.Configuration/ConfigurationComposer.cs create mode 100644 src/Umbraco.Configuration/UmbracoVersionExtensions.cs rename src/{Umbraco.Configuration => Umbraco.Core/Configuration}/CoreDebug.cs (96%) diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Abstractions/Composing/Composition.cs similarity index 100% rename from src/Umbraco.Core/Composing/Composition.cs rename to src/Umbraco.Abstractions/Composing/Composition.cs diff --git a/src/Umbraco.Core/Composing/IComposer.cs b/src/Umbraco.Abstractions/Composing/IComposer.cs similarity index 100% rename from src/Umbraco.Core/Composing/IComposer.cs rename to src/Umbraco.Abstractions/Composing/IComposer.cs diff --git a/src/Umbraco.Core/Composing/ICoreComposer.cs b/src/Umbraco.Abstractions/Composing/ICoreComposer.cs similarity index 100% rename from src/Umbraco.Core/Composing/ICoreComposer.cs rename to src/Umbraco.Abstractions/Composing/ICoreComposer.cs diff --git a/src/Umbraco.Core/CompositionExtensions_Uniques.cs b/src/Umbraco.Abstractions/CompositionExtensions_Uniques.cs similarity index 100% rename from src/Umbraco.Core/CompositionExtensions_Uniques.cs rename to src/Umbraco.Abstractions/CompositionExtensions_Uniques.cs diff --git a/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs index c955cc4796..a7492fa9da 100644 --- a/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs @@ -3,6 +3,8 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Grid; +using Umbraco.Core.Configuration.HealthChecks; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; @@ -14,11 +16,26 @@ namespace Umbraco.Core /// public static class ConfigsExtensions { + public static IGlobalSettings Global(this Configs configs) + => configs.GetConfig(); + + public static IUmbracoSettingsSection Settings(this Configs configs) + => configs.GetConfig(); + + public static IHealthChecks HealthChecks(this Configs configs) + => configs.GetConfig(); + + public static IGridConfig Grids(this Configs configs) + => configs.GetConfig(); + + public static ICoreDebug CoreDebug(this Configs configs) + => configs.GetConfig(); public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper) { var configDir = new DirectoryInfo(ioHelper.MapPath(Constants.SystemDirectories.Config)); + // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition configs.Add(factory => new GridConfig( factory.GetInstance(), diff --git a/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs b/src/Umbraco.Abstractions/Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs similarity index 52% rename from src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs rename to src/Umbraco.Abstractions/Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs index 6556c19c32..95e5ca8e03 100644 --- a/src/Umbraco.Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs +++ b/src/Umbraco.Abstractions/Configuration/HealthChecks/HealthCheckNotificationVerbosity.cs @@ -1,7 +1,10 @@ -namespace Umbraco.Core.Configuration.HealthChecks +using System.Runtime.Serialization; + +namespace Umbraco.Core.Configuration.HealthChecks { public enum HealthCheckNotificationVerbosity { + Summary, Detailed } diff --git a/src/Umbraco.Configuration/HealthChecks/IDisabledHealthCheck.cs b/src/Umbraco.Abstractions/Configuration/HealthChecks/IDisabledHealthCheck.cs similarity index 100% rename from src/Umbraco.Configuration/HealthChecks/IDisabledHealthCheck.cs rename to src/Umbraco.Abstractions/Configuration/HealthChecks/IDisabledHealthCheck.cs diff --git a/src/Umbraco.Configuration/HealthChecks/IHealthCheckNotificationSettings.cs b/src/Umbraco.Abstractions/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs similarity index 100% rename from src/Umbraco.Configuration/HealthChecks/IHealthCheckNotificationSettings.cs rename to src/Umbraco.Abstractions/Configuration/HealthChecks/IHealthCheckNotificationSettings.cs diff --git a/src/Umbraco.Configuration/HealthChecks/IHealthChecks.cs b/src/Umbraco.Abstractions/Configuration/HealthChecks/IHealthChecks.cs similarity index 100% rename from src/Umbraco.Configuration/HealthChecks/IHealthChecks.cs rename to src/Umbraco.Abstractions/Configuration/HealthChecks/IHealthChecks.cs diff --git a/src/Umbraco.Configuration/HealthChecks/INotificationMethod.cs b/src/Umbraco.Abstractions/Configuration/HealthChecks/INotificationMethod.cs similarity index 100% rename from src/Umbraco.Configuration/HealthChecks/INotificationMethod.cs rename to src/Umbraco.Abstractions/Configuration/HealthChecks/INotificationMethod.cs diff --git a/src/Umbraco.Configuration/HealthChecks/INotificationMethodSettings.cs b/src/Umbraco.Abstractions/Configuration/HealthChecks/INotificationMethodSettings.cs similarity index 100% rename from src/Umbraco.Configuration/HealthChecks/INotificationMethodSettings.cs rename to src/Umbraco.Abstractions/Configuration/HealthChecks/INotificationMethodSettings.cs diff --git a/src/Umbraco.Abstractions/Configuration/ICoreDebug.cs b/src/Umbraco.Abstractions/Configuration/ICoreDebug.cs new file mode 100644 index 0000000000..41476f4920 --- /dev/null +++ b/src/Umbraco.Abstractions/Configuration/ICoreDebug.cs @@ -0,0 +1,8 @@ +namespace Umbraco.Core.Configuration +{ + public interface ICoreDebug + { + bool LogUncompletedScopes { get; } + bool DumpOnTimeoutThreadAbort { get; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Abstractions/Configuration/IUmbracoVersion.cs b/src/Umbraco.Abstractions/Configuration/IUmbracoVersion.cs new file mode 100644 index 0000000000..1bdce0ec7c --- /dev/null +++ b/src/Umbraco.Abstractions/Configuration/IUmbracoVersion.cs @@ -0,0 +1,56 @@ +using System; +using Semver; + +namespace Umbraco.Core.Configuration +{ + public interface IUmbracoVersion + { + /// + /// Gets the non-semantic version of the Umbraco code. + /// + Version Current { get; } + + /// + /// Gets the semantic version comments of the Umbraco code. + /// + string Comment { get; } + + /// + /// Gets the assembly version of the Umbraco code. + /// + /// + /// The assembly version is the value of the . + /// Is the one that the CLR checks for compatibility. Therefore, it changes only on + /// hard-breaking changes (for instance, on new major versions). + /// + Version AssemblyVersion { get; } + + /// + /// Gets the assembly file version of the Umbraco code. + /// + /// + /// The assembly version is the value of the . + /// + Version AssemblyFileVersion { get; } + + /// + /// Gets the semantic version of the Umbraco code. + /// + /// + /// The semantic version is the value of the . + /// It is the full version of Umbraco, including comments. + /// + SemVersion SemanticVersion { get; } + + /// + /// Gets the "local" version of the site. + /// + /// + /// Three things have a version, really: the executing code, the database model, + /// and the site/files. The database model version is entirely managed via migrations, + /// and changes during an upgrade. The executing code version changes when new code is + /// deployed. The site/files version changes during an upgrade. + /// + SemVersion LocalVersion { get; } + } +} diff --git a/src/Umbraco.Configuration/UmbracoVersion.cs b/src/Umbraco.Abstractions/Configuration/UmbracoVersion.cs similarity index 76% rename from src/Umbraco.Configuration/UmbracoVersion.cs rename to src/Umbraco.Abstractions/Configuration/UmbracoVersion.cs index d7058fda01..dd96e6edd7 100644 --- a/src/Umbraco.Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Abstractions/Configuration/UmbracoVersion.cs @@ -8,9 +8,17 @@ namespace Umbraco.Core.Configuration /// /// Represents the version of the executing code. /// - public static class UmbracoVersion + public class UmbracoVersion : IUmbracoVersion { - static UmbracoVersion() + private readonly IGlobalSettings _globalSettings; + + public UmbracoVersion(IGlobalSettings globalSettings) + :this() + { + _globalSettings = globalSettings; + } + + public UmbracoVersion() { var umbracoCoreAssembly = typeof(SemVersion).Assembly; @@ -32,12 +40,12 @@ namespace Umbraco.Core.Configuration /// Gets the non-semantic version of the Umbraco code. /// // TODO: rename to Version - public static Version Current { get; } + public Version Current { get; } /// /// Gets the semantic version comments of the Umbraco code. /// - public static string Comment => SemanticVersion.Prerelease; + public string Comment => SemanticVersion.Prerelease; /// /// Gets the assembly version of the Umbraco code. @@ -47,7 +55,7 @@ namespace Umbraco.Core.Configuration /// Is the one that the CLR checks for compatibility. Therefore, it changes only on /// hard-breaking changes (for instance, on new major versions). /// - public static Version AssemblyVersion {get; } + public Version AssemblyVersion {get; } /// /// Gets the assembly file version of the Umbraco code. @@ -55,7 +63,7 @@ namespace Umbraco.Core.Configuration /// /// The assembly version is the value of the . /// - public static Version AssemblyFileVersion { get; } + public Version AssemblyFileVersion { get; } /// /// Gets the semantic version of the Umbraco code. @@ -64,7 +72,7 @@ namespace Umbraco.Core.Configuration /// The semantic version is the value of the . /// It is the full version of Umbraco, including comments. /// - public static SemVersion SemanticVersion { get; } + public SemVersion SemanticVersion { get; } /// /// Gets the "local" version of the site. @@ -75,21 +83,11 @@ namespace Umbraco.Core.Configuration /// and changes during an upgrade. The executing code version changes when new code is /// deployed. The site/files version changes during an upgrade. /// - public static SemVersion LocalVersion - { + public SemVersion LocalVersion { get { - try - { - // TODO: https://github.com/umbraco/Umbraco-CMS/issues/4238 - stop having version in web.config appSettings - var value = ConfigurationManager.AppSettings[Constants.AppSettings.ConfigurationStatus]; - return value.IsNullOrWhiteSpace() ? null : SemVersion.TryParse(value, out var semver) ? semver : null; - } - catch - { - return null; - } - } - } + var value = _globalSettings.ConfigurationStatus; + return value.IsNullOrWhiteSpace() ? null : SemVersion.TryParse(value, out var semver) ? semver : null; + } } } } diff --git a/src/Umbraco.Configuration/ConfigsExtensions.cs b/src/Umbraco.Configuration/ConfigsExtensions.cs deleted file mode 100644 index 0ecfc46896..0000000000 --- a/src/Umbraco.Configuration/ConfigsExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Umbraco.Core.Configuration; -using Umbraco.Core.Configuration.Grid; -using Umbraco.Core.Configuration.HealthChecks; -using Umbraco.Core.Configuration.UmbracoSettings; - -namespace Umbraco.Core -{ - /// - /// Provides extension methods for the class. - /// - public static class ConfigsExtensions - { - public static IGlobalSettings Global(this Configs configs) - => configs.GetConfig(); - - public static IUmbracoSettingsSection Settings(this Configs configs) - => configs.GetConfig(); - - public static IHealthChecks HealthChecks(this Configs configs) - => configs.GetConfig(); - - public static IGridConfig Grids(this Configs configs) - => configs.GetConfig(); - - public static CoreDebug CoreDebug(this Configs configs) - => configs.GetConfig(); - } -} diff --git a/src/Umbraco.Configuration/ConfigurationComposer.cs b/src/Umbraco.Configuration/ConfigurationComposer.cs new file mode 100644 index 0000000000..021657876f --- /dev/null +++ b/src/Umbraco.Configuration/ConfigurationComposer.cs @@ -0,0 +1,17 @@ + +using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; + +namespace Umbraco.Core.Logging.Viewer +{ + [RuntimeLevel(MinLevel = RuntimeLevel.Run)] + // ReSharper disable once UnusedMember.Global + public class ConfigurationComposer : ICoreComposer + { + public void Compose(Composition composition) + { + composition.RegisterUnique(); + } + + } +} diff --git a/src/Umbraco.Configuration/UmbracoVersionExtensions.cs b/src/Umbraco.Configuration/UmbracoVersionExtensions.cs new file mode 100644 index 0000000000..168bb16f57 --- /dev/null +++ b/src/Umbraco.Configuration/UmbracoVersionExtensions.cs @@ -0,0 +1,33 @@ +using System.Configuration; +using Semver; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Configuration +{ + public static class UmbracoVersionExtensions + { + /// + /// Gets the "local" version of the site. + /// + /// + /// Three things have a version, really: the executing code, the database model, + /// and the site/files. The database model version is entirely managed via migrations, + /// and changes during an upgrade. The executing code version changes when new code is + /// deployed. The site/files version changes during an upgrade. + /// + public static SemVersion LocalVersion(this IUmbracoVersion umbracoVersion) + { + try + { + // TODO: https://github.com/umbraco/Umbraco-CMS/issues/4238 - stop having version in web.config appSettings + var value = ConfigurationManager.AppSettings[Constants.AppSettings.ConfigurationStatus]; + return value.IsNullOrWhiteSpace() ? null : SemVersion.TryParse(value, out var semver) ? semver : null; + } + catch + { + return null; + } + } + } +} diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index 3ddc0f5dc1..e70763d0cc 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -207,6 +207,9 @@ namespace Umbraco.Core.Composing public static readonly IIOHelper IOHelper = Umbraco.Core.IO.IOHelper.Default; + public static IUmbracoVersion UmbracoVersion + => Factory.GetInstance(); + #endregion } } diff --git a/src/Umbraco.Core/CompositionExtensions_Essentials.cs b/src/Umbraco.Core/CompositionExtensions_Essentials.cs index 20c1646629..3174f07468 100644 --- a/src/Umbraco.Core/CompositionExtensions_Essentials.cs +++ b/src/Umbraco.Core/CompositionExtensions_Essentials.cs @@ -1,5 +1,6 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; @@ -22,7 +23,8 @@ namespace Umbraco.Core TypeLoader typeLoader, IRuntimeState state, ITypeFinder typeFinder, - IIOHelper ioHelper) + IIOHelper ioHelper, + IUmbracoVersion umbracoVersion) { composition.RegisterUnique(logger); composition.RegisterUnique(profiler); @@ -35,6 +37,7 @@ namespace Umbraco.Core composition.RegisterUnique(state); composition.RegisterUnique(typeFinder); composition.RegisterUnique(ioHelper); + composition.RegisterUnique(umbracoVersion); } } } diff --git a/src/Umbraco.Core/Configuration/ConfigsFactory.cs b/src/Umbraco.Core/Configuration/ConfigsFactory.cs index 89a31ce10b..0e75cea39b 100644 --- a/src/Umbraco.Core/Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Core/Configuration/ConfigsFactory.cs @@ -20,7 +20,7 @@ namespace Umbraco.Core.Configuration configs.Add("umbracoConfiguration/settings"); configs.Add("umbracoConfiguration/HealthChecks"); - configs.Add(() => new CoreDebug()); + configs.Add(() => new CoreDebug()); configs.AddCoreConfigs(_ioHelper); return configs; } diff --git a/src/Umbraco.Configuration/CoreDebug.cs b/src/Umbraco.Core/Configuration/CoreDebug.cs similarity index 96% rename from src/Umbraco.Configuration/CoreDebug.cs rename to src/Umbraco.Core/Configuration/CoreDebug.cs index e81ca14873..43238b2980 100644 --- a/src/Umbraco.Configuration/CoreDebug.cs +++ b/src/Umbraco.Core/Configuration/CoreDebug.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration { - public class CoreDebug + public class CoreDebug : ICoreDebug { public CoreDebug() { diff --git a/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs index e8fd3414ec..d61397155a 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs @@ -1,6 +1,7 @@ using System; using System.Configuration; using Semver; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Migrations.Upgrade.Common; using Umbraco.Core.Migrations.Upgrade.V_8_0_0; @@ -17,6 +18,7 @@ namespace Umbraco.Core.Migrations.Upgrade private const string InitPrefix = "{init-"; private const string InitSuffix = "}"; + private IUmbracoVersion UmbracoVersion => Current.UmbracoVersion; /// /// Initializes a new instance of the class. /// diff --git a/src/Umbraco.Core/Models/Packaging/PackageDefinition.cs b/src/Umbraco.Core/Models/Packaging/PackageDefinition.cs index 070d0773d2..e12a722b37 100644 --- a/src/Umbraco.Core/Models/Packaging/PackageDefinition.cs +++ b/src/Umbraco.Core/Models/Packaging/PackageDefinition.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Runtime.Serialization; +using Umbraco.Core.Composing; namespace Umbraco.Core.Models.Packaging { @@ -69,8 +70,8 @@ namespace Umbraco.Core.Models.Packaging /// The minimum umbraco version that this package requires /// [DataMember(Name = "umbracoVersion")] - public Version UmbracoVersion { get; set; } = Configuration.UmbracoVersion.Current; - + public Version UmbracoVersion { get; set; } = Current.UmbracoVersion.Current; + [DataMember(Name = "author")] [Required] public string Author { get; set; } = string.Empty; @@ -131,7 +132,7 @@ namespace Umbraco.Core.Models.Packaging [DataMember(Name = "iconUrl")] public string IconUrl { get; set; } = string.Empty; - + } diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index cdfb532a39..1dfd6488ba 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -548,6 +548,7 @@ namespace Umbraco.Core.Packaging private static XElement GetPackageInfoXml(PackageDefinition definition) { + var info = new XElement("info"); //Package info @@ -564,9 +565,9 @@ namespace Umbraco.Core.Packaging var requirements = new XElement("requirements"); - requirements.Add(new XElement("major", definition.UmbracoVersion == null ? UmbracoVersion.SemanticVersion.Major.ToInvariantString() : definition.UmbracoVersion.Major.ToInvariantString())); - requirements.Add(new XElement("minor", definition.UmbracoVersion == null ? UmbracoVersion.SemanticVersion.Minor.ToInvariantString() : definition.UmbracoVersion.Minor.ToInvariantString())); - requirements.Add(new XElement("patch", definition.UmbracoVersion == null ? UmbracoVersion.SemanticVersion.Patch.ToInvariantString() : definition.UmbracoVersion.Build.ToInvariantString())); + requirements.Add(new XElement("major", definition.UmbracoVersion == null ? Current.UmbracoVersion.SemanticVersion.Major.ToInvariantString() : definition.UmbracoVersion.Major.ToInvariantString())); + requirements.Add(new XElement("minor", definition.UmbracoVersion == null ? Current.UmbracoVersion.SemanticVersion.Minor.ToInvariantString() : definition.UmbracoVersion.Minor.ToInvariantString())); + requirements.Add(new XElement("patch", definition.UmbracoVersion == null ? Current.UmbracoVersion.SemanticVersion.Patch.ToInvariantString() : definition.UmbracoVersion.Build.ToInvariantString())); if (definition.UmbracoVersion != null) requirements.Add(new XAttribute("type", RequirementsType.Strict.ToString())); diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index d4647cbdd2..99b8997ce5 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.IO; using System.Web; using System.Web.Hosting; +using Semver; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -89,8 +90,9 @@ namespace Umbraco.Core.Runtime // are NOT disposed - which is not a big deal as long as they remain lightweight // objects. + var umbracoVersion = new UmbracoVersion(); using (var timer = profilingLogger.TraceDuration( - $"Booting Umbraco {UmbracoVersion.SemanticVersion.ToSemanticString()}.", + $"Booting Umbraco {umbracoVersion.SemanticVersion.ToSemanticString()}.", "Booted.", "Boot failed.")) { @@ -135,6 +137,7 @@ namespace Umbraco.Core.Runtime // configs var configs = GetConfigs(); + var umbracoVersion = GetUmbracoVersion(configs.Global()); // type finder/loader var typeLoader = new TypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(configs.Global().LocalTempPath), ProfilingLogger); @@ -144,7 +147,8 @@ namespace Umbraco.Core.Runtime _state = new RuntimeState(Logger, configs.Settings(), configs.Global(), new Lazy(() => _factory.GetInstance()), - new Lazy(() => _factory.GetInstance())) + new Lazy(() => _factory.GetInstance()), + umbracoVersion) { Level = RuntimeLevel.Boot }; @@ -154,7 +158,7 @@ namespace Umbraco.Core.Runtime // create the composition composition = new Composition(register, typeLoader, ProfilingLogger, _state, configs); - composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, mainDom, appCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper); + composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, mainDom, appCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper, umbracoVersion); // run handlers RuntimeOptions.DoRuntimeEssentials(composition, appCaches, typeLoader, databaseFactory); @@ -218,6 +222,11 @@ namespace Umbraco.Core.Runtime return _factory; } + private IUmbracoVersion GetUmbracoVersion(IGlobalSettings globalSettings) + { + return new UmbracoVersion(globalSettings); + } + protected virtual void ConfigureUnhandledException() { //take care of unhandled exceptions - there is nothing we can do to diff --git a/src/Umbraco.Core/RuntimeState.cs b/src/Umbraco.Core/RuntimeState.cs index 5d34fe70a1..a73c1d9170 100644 --- a/src/Umbraco.Core/RuntimeState.cs +++ b/src/Umbraco.Core/RuntimeState.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading; using System.Web; using Semver; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Exceptions; @@ -25,18 +26,20 @@ namespace Umbraco.Core private readonly HashSet _applicationUrls = new HashSet(); private readonly Lazy _mainDom; private readonly Lazy _serverRegistrar; + private readonly IUmbracoVersion _umbracoVersion; /// /// Initializes a new instance of the class. /// public RuntimeState(ILogger logger, IUmbracoSettingsSection settings, IGlobalSettings globalSettings, - Lazy mainDom, Lazy serverRegistrar) + Lazy mainDom, Lazy serverRegistrar, IUmbracoVersion umbracoVersion) { _logger = logger; _settings = settings; _globalSettings = globalSettings; _mainDom = mainDom; _serverRegistrar = serverRegistrar; + _umbracoVersion = umbracoVersion; } /// @@ -56,13 +59,13 @@ namespace Umbraco.Core public IMainDom MainDom => _mainDom.Value; /// - public Version Version => UmbracoVersion.Current; + public Version Version => _umbracoVersion.Current; /// - public string VersionComment => UmbracoVersion.Comment; + public string VersionComment => _umbracoVersion.Comment; /// - public SemVersion SemanticVersion => UmbracoVersion.SemanticVersion; + public SemVersion SemanticVersion => _umbracoVersion.SemanticVersion; /// public bool Debug { get; } = GlobalSettings.DebugMode; @@ -125,7 +128,7 @@ namespace Umbraco.Core /// public void DetermineRuntimeLevel(IUmbracoDatabaseFactory databaseFactory, ILogger logger) { - var localVersion = UmbracoVersion.LocalVersion; // the local, files, version + var localVersion = _umbracoVersion.LocalVersion; // the local, files, version var codeVersion = SemanticVersion; // the executing code version var connect = false; diff --git a/src/Umbraco.Core/Services/Implement/KeyValueService.cs b/src/Umbraco.Core/Services/Implement/KeyValueService.cs index b3f3f2468d..57e7c9ba74 100644 --- a/src/Umbraco.Core/Services/Implement/KeyValueService.cs +++ b/src/Umbraco.Core/Services/Implement/KeyValueService.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Migrations; @@ -39,7 +40,7 @@ namespace Umbraco.Core.Services.Implement // if already running 8, either following an upgrade or an install, // then everything should be ok (the table should exist, etc) - if (UmbracoVersion.LocalVersion != null && UmbracoVersion.LocalVersion.Major >= 8) + if (Current.UmbracoVersion.LocalVersion != null && Current.UmbracoVersion.LocalVersion.Major >= 8) { _initialized = true; return; @@ -202,9 +203,7 @@ namespace Umbraco.Core.Services.Implement /// Used by to determine the runtime state. internal static string GetValue(IUmbracoDatabase database, string key) { - // not 8 yet = no key/value table, no value - if (UmbracoVersion.LocalVersion.Major < 8) - return null; + if (database is null) return null; var sql = database.SqlContext.Sql() .Select() diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 52d7ae7f9a..59e9c40d00 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -136,11 +136,8 @@ - - - @@ -152,8 +149,8 @@ - + @@ -1020,10 +1017,6 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions - - {fbe7c065-dac0-4025-a78b-63b24d3ab00b} - Umbraco.Configuration - \ No newline at end of file diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index c80b917784..b836dda1e5 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Configurations [Test] public void Is_Version_From_Assembly_Correct() { - Assert.That(UmbracoVersion.SemanticVersion, Is.EqualTo("6.0.0")); + Assert.That(Current.UmbracoVersion.SemanticVersion, Is.EqualTo("6.0.0")); } [TestCase("~/umbraco", "/", "umbraco")] diff --git a/src/Umbraco.Tests/Misc/ApplicationUrlHelperTests.cs b/src/Umbraco.Tests/Misc/ApplicationUrlHelperTests.cs index 79878a59a1..8283b0b65a 100644 --- a/src/Umbraco.Tests/Misc/ApplicationUrlHelperTests.cs +++ b/src/Umbraco.Tests/Misc/ApplicationUrlHelperTests.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.Misc [Test] public void NoApplicationUrlByDefault() { - var state = new RuntimeState(Mock.Of(), Mock.Of(), Mock.Of(), new Lazy(), new Lazy()); + var state = new RuntimeState(Mock.Of(), Mock.Of(), Mock.Of(), new Lazy(), new Lazy(), TestHelper.GetUmbracoVersion()); Assert.IsNull(state.ApplicationUrl); } @@ -45,7 +45,7 @@ namespace Umbraco.Tests.Misc var registrar = new Mock(); registrar.Setup(x => x.GetCurrentServerUmbracoApplicationUrl()).Returns("http://server1.com/umbraco"); - var state = new RuntimeState(Mock.Of(), settings, globalConfig.Object, new Lazy(), new Lazy(() => registrar.Object)); + var state = new RuntimeState(Mock.Of(), settings, globalConfig.Object, new Lazy(), new Lazy(() => registrar.Object), TestHelper.GetUmbracoVersion()); state.EnsureApplicationUrl(); @@ -67,7 +67,7 @@ namespace Umbraco.Tests.Misc - var state = new RuntimeState(Mock.Of(), settings, globalConfig.Object, new Lazy(), new Lazy(() => Mock.Of())); + var state = new RuntimeState(Mock.Of(), settings, globalConfig.Object, new Lazy(), new Lazy(() => Mock.Of()), TestHelper.GetUmbracoVersion()); state.EnsureApplicationUrl(); @@ -90,7 +90,7 @@ namespace Umbraco.Tests.Misc // still NOT set Assert.IsNull(url); } - + [Test] public void SetApplicationUrlFromWrSettingsSsl() { diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index e95fdfc87c..aed4dba493 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -32,8 +32,9 @@ namespace Umbraco.Tests.Routing //create the module var logger = Mock.Of(); var globalSettings = TestObjects.GetGlobalSettings(); + var umbracoVersion = TestHelper.GetUmbracoVersion(); var runtime = new RuntimeState(logger, Mock.Of(), globalSettings, - new Lazy(), new Lazy()); + new Lazy(), new Lazy(), umbracoVersion); _module = new UmbracoInjectedModule ( @@ -62,7 +63,7 @@ namespace Umbraco.Tests.Routing // do not test for /base here as it's handled before EnsureUmbracoRoutablePage is called [TestCase("/umbraco_client/Tree/treeIcons.css", false)] - [TestCase("/umbraco_client/Tree/Themes/umbraco/style.css?cdv=37", false)] + [TestCase("/umbraco_client/Tree/Themes/umbraco/style.css?cdv=37", false)] [TestCase("/umbraco/editContent.aspx", false)] [TestCase("/install/default.aspx", false)] [TestCase("/install/?installStep=license", false)] diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 38a2d68e13..e799c4e638 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -65,12 +65,13 @@ namespace Umbraco.Tests.Runtimes var ioHelper = IOHelper.Default; var typeLoader = new TypeLoader(ioHelper, typeFinder, appCaches.RuntimeCache, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), profilingLogger); var mainDom = new SimpleMainDom(); - var runtimeState = new RuntimeState(logger, null, null, new Lazy(() => mainDom), new Lazy(() => factory.GetInstance())); + var umbracoVersion = TestHelper.GetUmbracoVersion(); + var runtimeState = new RuntimeState(logger, null, null, new Lazy(() => mainDom), new Lazy(() => factory.GetInstance()), umbracoVersion); // create the register and the composition var register = RegisterFactory.Create(); var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, TestHelper.GetConfigs()); - composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper); + composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion); // create the core runtime and have it compose itself var coreRuntime = new CoreRuntime(); @@ -262,7 +263,8 @@ namespace Umbraco.Tests.Runtimes // create the register and the composition var register = RegisterFactory.Create(); var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, TestHelper.GetConfigs()); - composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper); + var umbracoVersion = TestHelper.GetUmbracoVersion(); + composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion); // create the core runtime and have it compose itself var coreRuntime = new CoreRuntime(); diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index d04ad98f6d..7dc2aec8ea 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -15,7 +15,7 @@ namespace Umbraco.Tests.TestHelpers { var config = Mock.Of( settings => - settings.ConfigurationStatus == UmbracoVersion.SemanticVersion.ToSemanticString() && + settings.ConfigurationStatus == TestHelper.GetUmbracoVersion().SemanticVersion.ToSemanticString() && settings.UseHttps == false && settings.HideTopLevelNodeFromPath == false && settings.Path == Current.IOHelper.ResolveUrl("~/umbraco") && diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 5cd9359d5a..9dc24e4989 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -276,5 +276,9 @@ namespace Umbraco.Tests.TestHelpers } + public static IUmbracoVersion GetUmbracoVersion() + { + return new UmbracoVersion(GetConfigs().Global()); + } } } diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 6d90d2e7d0..41395b465a 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -246,5 +246,6 @@ namespace Umbraco.Tests.TestHelpers var scopeProvider = new ScopeProvider(databaseFactory, fileSystems, logger, typeFinder); return scopeProvider; } + } } diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index 050de4fcb9..9ced8d8a5d 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -132,7 +132,7 @@ namespace Umbraco.Tests.TestHelpers // ensure the configuration matches the current version for tests var globalSettingsMock = Mock.Get(Factory.GetInstance()); //this will modify the IGlobalSettings instance stored in the container - globalSettingsMock.Setup(x => x.ConfigurationStatus).Returns(UmbracoVersion.Current.ToString(3)); + globalSettingsMock.Setup(x => x.ConfigurationStatus).Returns(Current.UmbracoVersion.Current.ToString(3)); using (ProfilingLogger.TraceDuration("Initialize database.")) { diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index c963633aa0..f7804f33f0 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -100,6 +100,7 @@ namespace Umbraco.Tests.Testing protected ILogger Logger => Factory.GetInstance(); protected IIOHelper IOHelper { get; private set; } + protected IUmbracoVersion UmbracoVersion { get; private set; } protected ITypeFinder TypeFinder { get; private set; } @@ -134,9 +135,11 @@ namespace Umbraco.Tests.Testing var (logger, profiler) = GetLoggers(Options.Logger); var proflogger = new ProfilingLogger(logger, profiler); IOHelper = Umbraco.Core.IO.IOHelper.Default; + TypeFinder = new TypeFinder(logger); var appCaches = GetAppCaches(); var globalSettings = SettingsForTests.GetDefaultGlobalSettings(); + UmbracoVersion = new UmbracoVersion(globalSettings); var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, globalSettings, proflogger, Options.TypeLoader); var register = RegisterFactory.Create(); @@ -145,6 +148,7 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(IOHelper); + Composition.RegisterUnique(UmbracoVersion); Composition.RegisterUnique(TypeFinder); Composition.RegisterUnique(typeLoader); Composition.RegisterUnique(logger); diff --git a/src/Umbraco.Web/Composing/Current.cs b/src/Umbraco.Web/Composing/Current.cs index 026dedca7d..a3cdc599a3 100644 --- a/src/Umbraco.Web/Composing/Current.cs +++ b/src/Umbraco.Web/Composing/Current.cs @@ -227,6 +227,7 @@ namespace Umbraco.Web.Composing public static IVariationContextAccessor VariationContextAccessor => CoreCurrent.VariationContextAccessor; public static IIOHelper IOHelper => CoreCurrent.IOHelper; + public static IUmbracoVersion UmbracoVersion => CoreCurrent.UmbracoVersion; #endregion } diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 43d0bd3b6b..1b963f1a62 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -442,10 +442,10 @@ namespace Umbraco.Web.Editors // add versions - see UmbracoVersion for details & differences // the complete application version (eg "8.1.2-alpha.25") - { "version", UmbracoVersion.SemanticVersion.ToSemanticString() }, + { "version", Current.UmbracoVersion.SemanticVersion.ToSemanticString() }, // the assembly version (eg "8.0.0") - { "assemblyVersion", UmbracoVersion.AssemblyVersion.ToString() } + { "assemblyVersion", Current.UmbracoVersion.AssemblyVersion.ToString() } }; var version = _runtimeState.SemanticVersion.ToSemanticString(); diff --git a/src/Umbraco.Web/Editors/DashboardController.cs b/src/Umbraco.Web/Editors/DashboardController.cs index eef0b5df93..cfa92003bd 100644 --- a/src/Umbraco.Web/Editors/DashboardController.cs +++ b/src/Umbraco.Web/Editors/DashboardController.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Net; using System.Text; using Umbraco.Core.Cache; +using Umbraco.Core.Composing; using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Filters; using Umbraco.Core.Logging; @@ -51,7 +52,7 @@ namespace Umbraco.Web.Editors var user = Security.CurrentUser; var allowedSections = string.Join(",", user.AllowedSections); var language = user.Language; - var version = UmbracoVersion.SemanticVersion.ToSemanticString(); + var version = Current.UmbracoVersion.SemanticVersion.ToSemanticString(); var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}", section, allowedSections, language, version); var key = "umbraco-dynamic-dashboard-" + language + allowedSections.Replace(",", "-") + section; diff --git a/src/Umbraco.Web/Editors/PackageInstallController.cs b/src/Umbraco.Web/Editors/PackageInstallController.cs index 7dc4008d91..932a86c082 100644 --- a/src/Umbraco.Web/Editors/PackageInstallController.cs +++ b/src/Umbraco.Web/Editors/PackageInstallController.cs @@ -118,7 +118,7 @@ namespace Umbraco.Web.Editors if (ins.UmbracoVersionRequirementsType == RequirementsType.Strict) { var packageMinVersion = ins.UmbracoVersion; - if (UmbracoVersion.Current < packageMinVersion) + if (Current.UmbracoVersion.Current < packageMinVersion) { model.IsCompatible = false; } @@ -215,7 +215,7 @@ namespace Umbraco.Web.Editors { var packageFile = await Services.PackagingService.FetchPackageFileAsync( Guid.Parse(packageGuid), - UmbracoVersion.Current, + Current.UmbracoVersion.Current, Security.GetUserId().ResultOr(0)); fileName = packageFile.Name; @@ -259,7 +259,7 @@ namespace Umbraco.Web.Editors if (packageInfo.UmbracoVersionRequirementsType == RequirementsType.Strict) { var packageMinVersion = packageInfo.UmbracoVersion; - if (UmbracoVersion.Current < packageMinVersion) + if (Current.UmbracoVersion.Current < packageMinVersion) throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("packager/targetVersionMismatch", new[] {packageMinVersion.ToString()}))); } @@ -366,7 +366,7 @@ namespace Umbraco.Web.Editors //bump cdf to be safe var clientDependencyConfig = new ClientDependencyConfiguration(Logger); var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumber( - UmbracoVersion.SemanticVersion, DateTime.UtcNow, "yyyyMMdd"); + Current.UmbracoVersion.SemanticVersion, DateTime.UtcNow, "yyyyMMdd"); var redirectUrl = ""; if (!packageInfo.PackageView.IsNullOrWhiteSpace()) diff --git a/src/Umbraco.Web/Editors/UpdateCheckController.cs b/src/Umbraco.Web/Editors/UpdateCheckController.cs index 132526576b..b3f8676821 100644 --- a/src/Umbraco.Web/Editors/UpdateCheckController.cs +++ b/src/Umbraco.Web/Editors/UpdateCheckController.cs @@ -26,10 +26,10 @@ namespace Umbraco.Web.Editors { var check = new org.umbraco.update.CheckForUpgrade { Timeout = 2000 }; - var result = check.CheckUpgrade(UmbracoVersion.Current.Major, - UmbracoVersion.Current.Minor, - UmbracoVersion.Current.Build, - UmbracoVersion.Comment); + var result = check.CheckUpgrade(Current.UmbracoVersion.Current.Major, + Current.UmbracoVersion.Current.Minor, + Current.UmbracoVersion.Current.Build, + Current.UmbracoVersion.Comment); return new UpgradeCheckResponse(result.UpgradeType.ToString(), result.Comment, result.UpgradeUrl); } diff --git a/src/Umbraco.Web/Install/Controllers/InstallController.cs b/src/Umbraco.Web/Install/Controllers/InstallController.cs index 4b99c2ccba..96583cf4e0 100644 --- a/src/Umbraco.Web/Install/Controllers/InstallController.cs +++ b/src/Umbraco.Web/Install/Controllers/InstallController.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web.Install.Controllers // Update ClientDependency version var clientDependencyConfig = new ClientDependencyConfiguration(_logger); var clientDependencyUpdated = clientDependencyConfig.UpdateVersionNumber( - UmbracoVersion.SemanticVersion, DateTime.UtcNow, "yyyyMMdd"); + Current.UmbracoVersion.SemanticVersion, DateTime.UtcNow, "yyyyMMdd"); // Delete ClientDependency temp directories to make sure we get fresh caches var clientDependencyTempFilesDeleted = clientDependencyConfig.ClearTempFiles(HttpContext); diff --git a/src/Umbraco.Web/Install/InstallHelper.cs b/src/Umbraco.Web/Install/InstallHelper.cs index effb46c9b7..2cfd4b8c4d 100644 --- a/src/Umbraco.Web/Install/InstallHelper.cs +++ b/src/Umbraco.Web/Install/InstallHelper.cs @@ -75,10 +75,10 @@ namespace Umbraco.Web.Install IsBrandNewInstall == false, isCompleted, DateTime.Now, - UmbracoVersion.Current.Major, - UmbracoVersion.Current.Minor, - UmbracoVersion.Current.Build, - UmbracoVersion.Comment, + Current.UmbracoVersion.Current.Major, + Current.UmbracoVersion.Current.Minor, + Current.UmbracoVersion.Current.Build, + Current.UmbracoVersion.Comment, errorMsg, userAgent, dbProvider); @@ -141,7 +141,7 @@ namespace Umbraco.Web.Install var packages = new List(); try { - var requestUri = $"https://our.umbraco.com/webapi/StarterKit/Get/?umbracoVersion={UmbracoVersion.Current}"; + var requestUri = $"https://our.umbraco.com/webapi/StarterKit/Get/?umbracoVersion={Current.UmbracoVersion.Current}"; using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri)) { diff --git a/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs b/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs index b5fdea32b7..a5b36d8033 100644 --- a/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs @@ -61,7 +61,7 @@ namespace Umbraco.Web.Install.InstallSteps } // Update configurationStatus - _globalSettings.ConfigurationStatus = UmbracoVersion.SemanticVersion.ToSemanticString(); + _globalSettings.ConfigurationStatus = Current.UmbracoVersion.SemanticVersion.ToSemanticString(); //reports the ended install _installHelper.InstallStatus(true, ""); diff --git a/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs b/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs index 78b58a509e..20503316cf 100644 --- a/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs @@ -64,7 +64,7 @@ namespace Umbraco.Web.Install.InstallSteps private async Task<(string packageFile, int packageId)> DownloadPackageFilesAsync(Guid kitGuid) { //Go get the package file from the package repo - var packageFile = await _packageService.FetchPackageFileAsync(kitGuid, UmbracoVersion.Current, _umbracoContextAccessor.UmbracoContext.Security.GetUserId().ResultOr(0)); + var packageFile = await _packageService.FetchPackageFileAsync(kitGuid, Current.UmbracoVersion.Current, _umbracoContextAccessor.UmbracoContext.Security.GetUserId().ResultOr(0)); if (packageFile == null) throw new InvalidOperationException("Could not fetch package file " + kitGuid); //add an entry to the installedPackages.config diff --git a/src/Umbraco.Web/Install/InstallSteps/UpgradeStep.cs b/src/Umbraco.Web/Install/InstallSteps/UpgradeStep.cs index 3cab550a87..23a3c9062d 100644 --- a/src/Umbraco.Web/Install/InstallSteps/UpgradeStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/UpgradeStep.cs @@ -25,9 +25,9 @@ namespace Umbraco.Web.Install.InstallSteps // that was a "normal" way to force the upgrader to execute, and we would detect the current // version via the DB like DatabaseSchemaResult.DetermineInstalledVersion - magic, do we really // need this now? - var currentVersion = (UmbracoVersion.LocalVersion ?? new Semver.SemVersion(0)).ToString(); + var currentVersion = (Current.UmbracoVersion.LocalVersion ?? new Semver.SemVersion(0)).ToString(); - var newVersion = UmbracoVersion.SemanticVersion.ToString(); + var newVersion = Current.UmbracoVersion.SemanticVersion.ToString(); string FormatGuidState(string value) { diff --git a/src/Umbraco.Web/Models/UpgradeCheckResponse.cs b/src/Umbraco.Web/Models/UpgradeCheckResponse.cs index df384a51cd..ddbeac4989 100644 --- a/src/Umbraco.Web/Models/UpgradeCheckResponse.cs +++ b/src/Umbraco.Web/Models/UpgradeCheckResponse.cs @@ -5,6 +5,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using System.Web; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; namespace Umbraco.Web.Models @@ -26,7 +27,7 @@ namespace Umbraco.Web.Models { Type = upgradeType; Comment = upgradeComment; - Url = upgradeUrl + "?version=" + HttpUtility.UrlEncode(UmbracoVersion.Current.ToString(3)); + Url = upgradeUrl + "?version=" + HttpUtility.UrlEncode(Current.UmbracoVersion.Current.ToString(3)); } } } diff --git a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs index 1f7e2c8084..92289f8174 100644 --- a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs @@ -355,7 +355,7 @@ namespace Umbraco.Web.Security.Providers // http://issues.umbraco.org/issue/U4-3451 // when upgrading from 7.2 to 7.3 trying to save will throw - if (UmbracoVersion.Current >= new Version(7, 3, 0, 0)) + if (Current.UmbracoVersion.Current >= new Version(7, 3, 0, 0)) MemberService.Save(member, false); } @@ -595,7 +595,7 @@ namespace Umbraco.Web.Security.Providers // for this type of thing (i.e. UpdateLastLogin or similar). // when upgrading from 7.2 to 7.3 trying to save will throw - if (UmbracoVersion.Current >= new Version(7, 3, 0, 0)) + if (Current.UmbracoVersion.Current >= new Version(7, 3, 0, 0)) MemberService.Save(member, false); return new ValidateUserResult diff --git a/src/umbraco.sln b/src/umbraco.sln index 07ed63c7a3..c70f10bdb3 100644 --- a/src/umbraco.sln +++ b/src/umbraco.sln @@ -1,7 +1,4 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27004.2005 -Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29209.152 MinimumVisualStudioVersion = 10.0.40219.1 From 603ec0ccfbab680ac413808857efc0fc22451b44 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 15 Nov 2019 11:07:37 +0100 Subject: [PATCH 40/61] AB3594 - Moved the composition root out to UmbracoApplicationBase, and injecting the needed parts from there. Also remove usages of ConfigurationManager from Umbraco.Core --- .../Configuration/ConfigConnectionString.cs | 16 +++ .../Configuration/Configs.cs | 2 + .../Configuration/ConfigsExtensions.cs | 5 +- .../Configuration/IConnectionStrings.cs | 10 ++ .../Configuration/IGlobalSettings.cs | 35 ++++- src/Umbraco.Abstractions/DatabaseHelper.cs | 41 ++++++ .../NameValueCollectionExtensions.cs | 2 +- .../ConfigsFactory.cs | 10 +- .../ConfigurationComposer.cs | 17 --- .../ConnectionStrings.cs | 21 +++ .../CoreDebug.cs | 0 .../GlobalSettings.cs | 127 ++++++++---------- src/Umbraco.Core/Composing/RegisterFactory.cs | 6 +- .../Configuration/GlobalSettingsExtensions.cs | 57 ++++++++ src/Umbraco.Core/EmailSender.cs | 3 +- src/Umbraco.Core/IO/MediaFileSystem.cs | 3 - src/Umbraco.Core/IO/SystemFiles.cs | 2 +- .../Migrations/Install/DatabaseBuilder.cs | 31 ----- .../Migrations/Upgrade/UmbracoPlan.cs | 3 +- .../Persistence/UmbracoDatabaseFactory.cs | 14 +- .../Runtime/CoreInitialComposer.cs | 8 +- src/Umbraco.Core/Runtime/CoreRuntime.cs | 88 +++++------- src/Umbraco.Core/RuntimeOptions.cs | 39 ------ src/Umbraco.Core/RuntimeState.cs | 9 +- .../Security/MembershipProviderBase.cs | 2 - .../Sync/DatabaseServerMessenger.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 5 +- .../DistributedCache/DistributedCacheTests.cs | 2 +- .../Components/ComponentTests.cs | 2 +- .../Composing/CollectionBuildersTests.cs | 2 +- .../Composing/ContainerConformingTests.cs | 3 +- .../Composing/LazyCollectionBuilderTests.cs | 2 +- .../Composing/PackageActionCollectionTests.cs | 2 +- .../Configurations/GlobalSettingsTests.cs | 6 - src/Umbraco.Tests/IO/FileSystemsTests.cs | 2 +- .../Persistence/DatabaseContextTests.cs | 2 +- .../PropertyEditors/ImageCropperTest.cs | 2 +- .../PropertyEditorValueEditorTests.cs | 2 +- .../Published/ConvertersTests.cs | 2 +- .../PublishedContentSnapshotTestBase.cs | 2 +- .../PublishedContent/PublishedContentTests.cs | 2 +- .../Routing/RenderRouteHandlerTests.cs | 10 +- .../Runtimes/CoreRuntimeTests.cs | 30 +++-- src/Umbraco.Tests/Runtimes/StandaloneTests.cs | 17 +-- .../Scoping/ScopeEventDispatcherTests.cs | 2 +- .../TestHelpers/BaseUsingSqlCeSyntax.cs | 2 +- .../TestHelpers/SettingsForTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 5 + src/Umbraco.Tests/TestHelpers/TestObjects.cs | 4 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 7 +- src/Umbraco.Web/Install/InstallHelper.cs | 9 +- .../InstallSteps/DatabaseConfigureStep.cs | 6 +- .../InstallSteps/DatabaseUpgradeStep.cs | 10 +- .../Install/InstallSteps/NewInstallStep.cs | 6 +- .../Profiling/WebProfilingController.cs | 18 ++- .../NuCache/PublishedSnapshotService.cs | 2 +- .../Runtime/WebInitialComponent.cs | 2 +- src/Umbraco.Web/Runtime/WebRuntime.cs | 7 +- src/Umbraco.Web/Umbraco.Web.csproj | 2 +- src/Umbraco.Web/UmbracoApplication.cs | 7 +- src/Umbraco.Web/UmbracoApplicationBase.cs | 34 ++++- src/Umbraco.Web/UmbracoContext.cs | 5 +- src/Umbraco.Web/UrlHelperExtensions.cs | 2 +- 63 files changed, 441 insertions(+), 339 deletions(-) create mode 100644 src/Umbraco.Abstractions/Configuration/ConfigConnectionString.cs create mode 100644 src/Umbraco.Abstractions/Configuration/IConnectionStrings.cs create mode 100644 src/Umbraco.Abstractions/DatabaseHelper.cs rename src/{Umbraco.Core => Umbraco.Abstractions}/NameValueCollectionExtensions.cs (95%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/ConfigsFactory.cs (72%) delete mode 100644 src/Umbraco.Configuration/ConfigurationComposer.cs create mode 100644 src/Umbraco.Configuration/ConnectionStrings.cs rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/CoreDebug.cs (100%) rename src/{Umbraco.Core/Configuration => Umbraco.Configuration}/GlobalSettings.cs (78%) create mode 100644 src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs diff --git a/src/Umbraco.Abstractions/Configuration/ConfigConnectionString.cs b/src/Umbraco.Abstractions/Configuration/ConfigConnectionString.cs new file mode 100644 index 0000000000..e9ac944b85 --- /dev/null +++ b/src/Umbraco.Abstractions/Configuration/ConfigConnectionString.cs @@ -0,0 +1,16 @@ +namespace Umbraco.Core.Configuration +{ + public class ConfigConnectionString + { + public ConfigConnectionString(string connectionString, string providerName, string name) + { + ConnectionString = connectionString; + ProviderName = providerName; + Name = name; + } + + public string ConnectionString { get; } + public string ProviderName { get; } + public string Name { get; } + } +} diff --git a/src/Umbraco.Abstractions/Configuration/Configs.cs b/src/Umbraco.Abstractions/Configuration/Configs.cs index e08c4097e4..b2dde785b2 100644 --- a/src/Umbraco.Abstractions/Configuration/Configs.cs +++ b/src/Umbraco.Abstractions/Configuration/Configs.cs @@ -114,5 +114,7 @@ namespace Umbraco.Core.Configuration // no need to keep them around _registerings = null; } + + } } diff --git a/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs index a7492fa9da..3beb7ee3cd 100644 --- a/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs +++ b/src/Umbraco.Abstractions/Configuration/ConfigsExtensions.cs @@ -19,6 +19,9 @@ namespace Umbraco.Core public static IGlobalSettings Global(this Configs configs) => configs.GetConfig(); + public static IConnectionStrings ConnectionStrings(this Configs configs) + => configs.GetConfig(); + public static IUmbracoSettingsSection Settings(this Configs configs) => configs.GetConfig(); @@ -35,7 +38,7 @@ namespace Umbraco.Core { var configDir = new DirectoryInfo(ioHelper.MapPath(Constants.SystemDirectories.Config)); - + // GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition configs.Add(factory => new GridConfig( factory.GetInstance(), diff --git a/src/Umbraco.Abstractions/Configuration/IConnectionStrings.cs b/src/Umbraco.Abstractions/Configuration/IConnectionStrings.cs new file mode 100644 index 0000000000..0d33378669 --- /dev/null +++ b/src/Umbraco.Abstractions/Configuration/IConnectionStrings.cs @@ -0,0 +1,10 @@ +namespace Umbraco.Core.Configuration +{ + public interface IConnectionStrings + { + ConfigConnectionString this[string key] + { + get; + } + } +} diff --git a/src/Umbraco.Abstractions/Configuration/IGlobalSettings.cs b/src/Umbraco.Abstractions/Configuration/IGlobalSettings.cs index 48371bd11b..077f853a97 100644 --- a/src/Umbraco.Abstractions/Configuration/IGlobalSettings.cs +++ b/src/Umbraco.Abstractions/Configuration/IGlobalSettings.cs @@ -63,14 +63,39 @@ /// LocalTempStorage LocalTempStorageLocation { get; } - /// - /// Gets the location of temporary files. - /// - string LocalTempPath { get; } - string UmbracoPath { get; } string UmbracoCssPath { get; } string UmbracoScriptsPath { get; } string UmbracoMediaPath { get; } + bool DebugMode { get; } + + bool IsSmtpServerConfigured { get; } + + /// + /// Gets a value indicating whether the runtime should enter Install level when the database is missing. + /// + /// + /// By default, when a database connection string is configured but it is not possible to + /// connect to the database, the runtime enters the BootFailed level. If this options is set to true, + /// it enters the Install level instead. + /// It is then up to the implementor, that is setting this value, to take over the installation + /// sequence. + /// + bool InstallMissingDatabase { get; } + + /// + /// Gets a value indicating whether the runtime should enter Install level when the database is empty. + /// + /// + /// By default, when a database connection string is configured and it is possible to connect to + /// the database, but the database is empty, the runtime enters the BootFailed level. If this options + /// is set to true, it enters the Install level instead. + /// It is then up to the implementor, that is setting this value, to take over the installation + /// sequence. + /// + bool InstallEmptyDatabase { get; } + bool DisableElectionForSingleServer { get; } + string RegisterType { get; } + string DatabaseFactoryServerVersion { get; } } } diff --git a/src/Umbraco.Abstractions/DatabaseHelper.cs b/src/Umbraco.Abstractions/DatabaseHelper.cs new file mode 100644 index 0000000000..70c2d64774 --- /dev/null +++ b/src/Umbraco.Abstractions/DatabaseHelper.cs @@ -0,0 +1,41 @@ +using System; +using System.IO; +using System.Linq; +using Umbraco.Core; +using Umbraco.Core.Configuration; + +namespace Umbraco.Core +{ + + public static class DatabaseHelper + { + public static bool IsConnectionStringConfigured(ConfigConnectionString databaseSettings) + { + var dbIsSqlCe = false; + if (databaseSettings?.ProviderName != null) + dbIsSqlCe = databaseSettings.ProviderName == Constants.DbProviderNames.SqlCe; + var sqlCeDatabaseExists = false; + if (dbIsSqlCe) + { + var parts = databaseSettings.ConnectionString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + var dataSourcePart = parts.FirstOrDefault(x => x.InvariantStartsWith("Data Source=")); + if (dataSourcePart != null) + { + var datasource = dataSourcePart.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory").ToString()); + var filePath = datasource.Replace("Data Source=", string.Empty); + sqlCeDatabaseExists = File.Exists(filePath); + } + } + + // Either the connection details are not fully specified or it's a SQL CE database that doesn't exist yet + if (databaseSettings == null + || string.IsNullOrWhiteSpace(databaseSettings.ConnectionString) || string.IsNullOrWhiteSpace(databaseSettings.ProviderName) + || (dbIsSqlCe && sqlCeDatabaseExists == false)) + { + return false; + } + + return true; + } + } +} diff --git a/src/Umbraco.Core/NameValueCollectionExtensions.cs b/src/Umbraco.Abstractions/NameValueCollectionExtensions.cs similarity index 95% rename from src/Umbraco.Core/NameValueCollectionExtensions.cs rename to src/Umbraco.Abstractions/NameValueCollectionExtensions.cs index 3c52989019..b7272c042d 100644 --- a/src/Umbraco.Core/NameValueCollectionExtensions.cs +++ b/src/Umbraco.Abstractions/NameValueCollectionExtensions.cs @@ -6,7 +6,7 @@ using System.Text; namespace Umbraco.Core { - internal static class NameValueCollectionExtensions + public static class NameValueCollectionExtensions { public static IEnumerable> AsEnumerable(this NameValueCollection nvc) { diff --git a/src/Umbraco.Core/Configuration/ConfigsFactory.cs b/src/Umbraco.Configuration/ConfigsFactory.cs similarity index 72% rename from src/Umbraco.Core/Configuration/ConfigsFactory.cs rename to src/Umbraco.Configuration/ConfigsFactory.cs index 0e75cea39b..c016c3171d 100644 --- a/src/Umbraco.Core/Configuration/ConfigsFactory.cs +++ b/src/Umbraco.Configuration/ConfigsFactory.cs @@ -12,15 +12,21 @@ namespace Umbraco.Core.Configuration public ConfigsFactory(IIOHelper ioHelper) { _ioHelper = ioHelper; + GlobalSettings = new GlobalSettings(_ioHelper); } - public Configs Create() { + public IGlobalSettings GlobalSettings { get; } + + public Configs Create() + { var configs = new Configs(section => ConfigurationManager.GetSection(section)); - configs.Add(() => new GlobalSettings(_ioHelper)); + configs.Add(() => GlobalSettings); + configs.Add("umbracoConfiguration/settings"); configs.Add("umbracoConfiguration/HealthChecks"); configs.Add(() => new CoreDebug()); + configs.Add(() => new ConnectionStrings()); configs.AddCoreConfigs(_ioHelper); return configs; } diff --git a/src/Umbraco.Configuration/ConfigurationComposer.cs b/src/Umbraco.Configuration/ConfigurationComposer.cs deleted file mode 100644 index 021657876f..0000000000 --- a/src/Umbraco.Configuration/ConfigurationComposer.cs +++ /dev/null @@ -1,17 +0,0 @@ - -using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; - -namespace Umbraco.Core.Logging.Viewer -{ - [RuntimeLevel(MinLevel = RuntimeLevel.Run)] - // ReSharper disable once UnusedMember.Global - public class ConfigurationComposer : ICoreComposer - { - public void Compose(Composition composition) - { - composition.RegisterUnique(); - } - - } -} diff --git a/src/Umbraco.Configuration/ConnectionStrings.cs b/src/Umbraco.Configuration/ConnectionStrings.cs new file mode 100644 index 0000000000..1842ff6627 --- /dev/null +++ b/src/Umbraco.Configuration/ConnectionStrings.cs @@ -0,0 +1,21 @@ +using System; +using System.Configuration; +using System.Linq; +using System.Xml.Linq; +using Umbraco.Core.IO; + +namespace Umbraco.Core.Configuration +{ + public class ConnectionStrings : IConnectionStrings + { + public ConfigConnectionString this[string key] + { + get + { + var settings = ConfigurationManager.ConnectionStrings[key]; + + return new ConfigConnectionString(settings.ConnectionString, settings.ProviderName, settings.Name); + } + } + } +} diff --git a/src/Umbraco.Core/Configuration/CoreDebug.cs b/src/Umbraco.Configuration/CoreDebug.cs similarity index 100% rename from src/Umbraco.Core/Configuration/CoreDebug.cs rename to src/Umbraco.Configuration/CoreDebug.cs diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Configuration/GlobalSettings.cs similarity index 78% rename from src/Umbraco.Core/Configuration/GlobalSettings.cs rename to src/Umbraco.Configuration/GlobalSettings.cs index e4e9a3c4d7..0d1bb2a494 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Configuration/GlobalSettings.cs @@ -1,10 +1,6 @@ using System; using System.Configuration; using System.Linq; -using System.Net.Configuration; -using System.Web; -using System.Web.Configuration; -using System.Web.Hosting; using System.Xml.Linq; using Umbraco.Core.IO; @@ -52,20 +48,42 @@ namespace Umbraco.Core.Configuration { ResetInternal(); } - - public static bool HasSmtpServerConfigured(string appPath) + public bool IsSmtpServerConfigured { - if (HasSmtpServer.HasValue) return HasSmtpServer.Value; + get + { + var smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as ConfigurationSection; + if (smtpSection is null) return false; - var config = WebConfigurationManager.OpenWebConfiguration(appPath); - var settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings"); - // note: "noreply@example.com" is/was the sample SMTP from email - we'll regard that as "not configured" - if (settings == null || settings.Smtp == null || "noreply@example.com".Equals(settings.Smtp.From, StringComparison.OrdinalIgnoreCase)) return false; - if (settings.Smtp.SpecifiedPickupDirectory != null && string.IsNullOrEmpty(settings.Smtp.SpecifiedPickupDirectory.PickupDirectoryLocation) == false) - return true; - if (settings.Smtp.Network != null && string.IsNullOrEmpty(settings.Smtp.Network.Host) == false) - return true; - return false; + var from = smtpSection.ElementInformation.Properties["from"]; + if (@from != null + && @from.Value is string fromPropValue + && string.IsNullOrEmpty(fromPropValue) == false + && !string.Equals("noreply@example.com", fromPropValue, StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + var networkSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp/network") as ConfigurationSection; + var host = networkSection?.ElementInformation.Properties["host"]; + if (host != null + && host.Value is string hostPropValue + && string.IsNullOrEmpty(hostPropValue) == false) + { + return true; + } + + var specifiedPickupDirectorySection = ConfigurationManager.GetSection("system.net/mailSettings/smtp/specifiedPickupDirectory") as ConfigurationSection; + var pickupDirectoryLocation = specifiedPickupDirectorySection?.ElementInformation.Properties["pickupDirectoryLocation"]; + if (pickupDirectoryLocation != null + && pickupDirectoryLocation.Value is string pickupDirectoryLocationPropValue + && string.IsNullOrEmpty(pickupDirectoryLocationPropValue) == false) + { + return true; + } + + return false; + } } /// @@ -196,7 +214,7 @@ namespace Umbraco.Core.Configuration /// Removes a setting from the configuration file. /// /// Key of the setting to be removed. - internal static void RemoveSetting(string key, IIOHelper ioHelper) + public static void RemoveSetting(string key, IIOHelper ioHelper) { var fileName = ioHelper.MapPath(string.Format("{0}/web.config", ioHelper.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); @@ -212,28 +230,25 @@ namespace Umbraco.Core.Configuration } } - /// - /// Gets a value indicating whether umbraco is running in [debug mode]. - /// - /// true if [debug mode]; otherwise, false. - public static bool DebugMode + public bool DebugMode { get { try { - if (HttpContext.Current != null) + if (ConfigurationManager.GetSection("system.web/compilation") is ConfigurationSection compilation) { - return HttpContext.Current.IsDebuggingEnabled; + var debugElement = compilation.ElementInformation.Properties["debug"]; + + return debugElement != null && (debugElement.Value is bool debug && debug); } - //go and get it from config directly - var section = ConfigurationManager.GetSection("system.web/compilation") as CompilationSection; - return section != null && section.Debug; } catch { - return false; + // ignored } + + return false; } } @@ -288,47 +303,6 @@ namespace Umbraco.Core.Configuration } } - /// - public string LocalTempPath - { - get - { - if (_localTempPath != null) - return _localTempPath; - - switch (LocalTempStorageLocation) - { - case LocalTempStorage.AspNetTemp: - return _localTempPath = System.IO.Path.Combine(HttpRuntime.CodegenDir, "UmbracoData"); - - case LocalTempStorage.EnvironmentTemp: - - // environment temp is unique, we need a folder per site - - // use a hash - // combine site name and application id - // site name is a Guid on Cloud - // application id is eg /LM/W3SVC/123456/ROOT - // the combination is unique on one server - // and, if a site moves from worker A to B and then back to A... - // hopefully it gets a new Guid or new application id? - - var siteName = HostingEnvironment.SiteName; - var applicationId = HostingEnvironment.ApplicationID; // ie HttpRuntime.AppDomainAppId - - var hashString = siteName + "::" + applicationId; - var hash = hashString.GenerateHash(); - var siteTemp = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoData", hash); - - return _localTempPath = siteTemp; - - //case LocalTempStorage.Default: - //case LocalTempStorage.Unknown: - default: - return _localTempPath = _ioHelper.MapPath("~/App_Data/TEMP"); - } - } - } /// /// Gets the default UI language. @@ -396,6 +370,21 @@ namespace Umbraco.Core.Configuration private string _umbracoPath = null; public string UmbracoPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoPath, "~/umbraco", ref _umbracoPath); + private bool _installMissingDatabase; + public bool InstallMissingDatabase => GetterWithDefaultValue("Umbraco.Core.RuntimeState.InstallMissingDatabase", false, ref _installMissingDatabase); + + private bool _installEmptyDatabase; + public bool InstallEmptyDatabase => GetterWithDefaultValue("Umbraco.Core.RuntimeState.InstallEmptyDatabase", false, ref _installEmptyDatabase); + + private bool _disableElectionForSingleServer; + public bool DisableElectionForSingleServer => GetterWithDefaultValue(Constants.AppSettings.DisableElectionForSingleServer, false, ref _disableElectionForSingleServer); + + private string _registerType; + public string RegisterType => GetterWithDefaultValue(Constants.AppSettings.RegisterType, string.Empty, ref _registerType); + + private string _databaseFactoryServerVersion; + public string DatabaseFactoryServerVersion => GetterWithDefaultValue(Constants.AppSettings.Debug.DatabaseFactoryServerVersion, string.Empty, ref _databaseFactoryServerVersion); + private T GetterWithDefaultValue(string appSettingKey, T defaultValue, ref T backingField) { if (backingField != null) return backingField; diff --git a/src/Umbraco.Core/Composing/RegisterFactory.cs b/src/Umbraco.Core/Composing/RegisterFactory.cs index ea25d6a135..8f842e14fe 100644 --- a/src/Umbraco.Core/Composing/RegisterFactory.cs +++ b/src/Umbraco.Core/Composing/RegisterFactory.cs @@ -1,6 +1,6 @@ using System; -using System.Configuration; using System.Reflection; +using Umbraco.Core.Configuration; namespace Umbraco.Core.Composing { @@ -21,11 +21,11 @@ namespace Umbraco.Core.Composing /// To override the default LightInjectContainer, add an appSetting named 'Umbraco.Core.RegisterType' with /// a fully qualified type name to a class with a static method "Create" returning an IRegister. /// - public static IRegister Create() + public static IRegister Create(IGlobalSettings globalSettings) { Type type; - var configuredTypeName = ConfigurationManager.AppSettings[Constants.AppSettings.RegisterType]; + var configuredTypeName = globalSettings.RegisterType; if (configuredTypeName.IsNullOrWhiteSpace()) { // try to get the web LightInject container type, diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs new file mode 100644 index 0000000000..65b1a0d9ea --- /dev/null +++ b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs @@ -0,0 +1,57 @@ +using System; +using System.Web; +using System.Web.Hosting; +using Umbraco.Core.IO; + +namespace Umbraco.Core.Configuration +{ + + public static class GlobalSettingsExtensions + { + private static string _localTempPath; + + /// + /// Gets the location of temporary files. + /// + public static string LocalTempPath(this IGlobalSettings globalSettings, IIOHelper ioHelper) + { + + if (_localTempPath != null) + return _localTempPath; + + switch (globalSettings.LocalTempStorageLocation) + { + case LocalTempStorage.AspNetTemp: + return _localTempPath = System.IO.Path.Combine(HttpRuntime.CodegenDir, "UmbracoData"); + + case LocalTempStorage.EnvironmentTemp: + + // environment temp is unique, we need a folder per site + + // use a hash + // combine site name and application id + // site name is a Guid on Cloud + // application id is eg /LM/W3SVC/123456/ROOT + // the combination is unique on one server + // and, if a site moves from worker A to B and then back to A... + // hopefully it gets a new Guid or new application id? + + var siteName = HostingEnvironment.SiteName; + var applicationId = HostingEnvironment.ApplicationID; // ie HttpRuntime.AppDomainAppId + + var hashString = siteName + "::" + applicationId; + var hash = hashString.GenerateHash(); + var siteTemp = System.IO.Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoData", hash); + + return _localTempPath = siteTemp; + + //case LocalTempStorage.Default: + //case LocalTempStorage.Unknown: + default: + return _localTempPath = ioHelper.MapPath("~/App_Data/TEMP"); + } + + } + + } +} diff --git a/src/Umbraco.Core/EmailSender.cs b/src/Umbraco.Core/EmailSender.cs index e876d5b0c8..7dc75b116d 100644 --- a/src/Umbraco.Core/EmailSender.cs +++ b/src/Umbraco.Core/EmailSender.cs @@ -2,6 +2,7 @@ using System.Net.Mail; using System.Threading.Tasks; using System.Web; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; @@ -28,7 +29,7 @@ namespace Umbraco.Core _enableEvents = enableEvents; } - private static readonly Lazy SmtpConfigured = new Lazy(() => GlobalSettings.HasSmtpServerConfigured(HttpRuntime.AppDomainAppVirtualPath)); + private static readonly Lazy SmtpConfigured = new Lazy(() => Current.Configs.Global().IsSmtpServerConfigured); /// /// Sends the message non-async diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Core/IO/MediaFileSystem.cs index edcbfadf0d..e776c1b2b2 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Core/IO/MediaFileSystem.cs @@ -1,15 +1,12 @@ using System; using System.Collections.Generic; -using System.Configuration; using System.IO; using System.Linq; using System.Threading.Tasks; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; -using Umbraco.Core.Media; using Umbraco.Core.Models; namespace Umbraco.Core.IO diff --git a/src/Umbraco.Core/IO/SystemFiles.cs b/src/Umbraco.Core/IO/SystemFiles.cs index 132945d130..5025a5b01f 100644 --- a/src/Umbraco.Core/IO/SystemFiles.cs +++ b/src/Umbraco.Core/IO/SystemFiles.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.IO // TODO: Kill this off we don't have umbraco.config XML cache we now have NuCache public static string GetContentCacheXml(IGlobalSettings globalSettings) { - return Path.Combine(globalSettings.LocalTempPath, "umbraco.config"); + return Path.Combine(globalSettings.LocalTempPath(Current.IOHelper), "umbraco.config"); } } } diff --git a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs index a0421a27c1..100aaf6478 100644 --- a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs @@ -1,5 +1,4 @@ using System; -using System.Configuration; using System.Data.SqlServerCe; using System.IO; using System.Linq; @@ -7,7 +6,6 @@ using System.Xml.Linq; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Exceptions; -using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Upgrade; using Umbraco.Core.Persistence; @@ -338,35 +336,6 @@ namespace Umbraco.Core.Migrations.Install attribute.Value = value; } - internal bool IsConnectionStringConfigured(ConnectionStringSettings databaseSettings) - { - var dbIsSqlCe = false; - if (databaseSettings?.ProviderName != null) - dbIsSqlCe = databaseSettings.ProviderName == Constants.DbProviderNames.SqlCe; - var sqlCeDatabaseExists = false; - if (dbIsSqlCe) - { - var parts = databaseSettings.ConnectionString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); - var dataSourcePart = parts.FirstOrDefault(x => x.InvariantStartsWith("Data Source=")); - if (dataSourcePart != null) - { - var datasource = dataSourcePart.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory").ToString()); - var filePath = datasource.Replace("Data Source=", string.Empty); - sqlCeDatabaseExists = File.Exists(filePath); - } - } - - // Either the connection details are not fully specified or it's a SQL CE database that doesn't exist yet - if (databaseSettings == null - || string.IsNullOrWhiteSpace(databaseSettings.ConnectionString) || string.IsNullOrWhiteSpace(databaseSettings.ProviderName) - || (dbIsSqlCe && sqlCeDatabaseExists == false)) - { - return false; - } - - return true; - } - #endregion #region Database Schema diff --git a/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs index d61397155a..070f4bdf6a 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs @@ -1,5 +1,4 @@ using System; -using System.Configuration; using Semver; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -63,7 +62,7 @@ namespace Umbraco.Core.Migrations.Upgrade get { // no state in database yet - assume we have something in web.config that makes some sense - if (!SemVersion.TryParse(ConfigurationManager.AppSettings[Constants.AppSettings.ConfigurationStatus], out var currentVersion)) + if (!SemVersion.TryParse(Current.Configs.Global().ConfigurationStatus, out var currentVersion)) throw new InvalidOperationException($"Could not get current version from web.config {Constants.AppSettings.ConfigurationStatus} appSetting."); // cannot go back in time diff --git a/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs index 13422f43b1..6a1a3ee3f1 100644 --- a/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs @@ -1,9 +1,10 @@ using System; -using System.Configuration; using System.Data.Common; using System.Threading; using NPoco; using NPoco.FluentMappings; +using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; using Umbraco.Core.Persistence.FaultHandling; @@ -51,15 +52,15 @@ namespace Umbraco.Core.Persistence /// Initializes a new instance of the . /// /// Used by core runtime. - public UmbracoDatabaseFactory(ILogger logger, Lazy mappers) - : this(Constants.System.UmbracoConnectionName, logger, mappers) + public UmbracoDatabaseFactory(ILogger logger, Lazy mappers, Configs configs) + : this(Constants.System.UmbracoConnectionName, logger, mappers, configs) { } /// /// Initializes a new instance of the . /// /// Used by the other ctor and in tests. - public UmbracoDatabaseFactory(string connectionStringName, ILogger logger, Lazy mappers) + public UmbracoDatabaseFactory(string connectionStringName, ILogger logger, Lazy mappers, Configs configs) { if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentNullOrEmptyException(nameof(connectionStringName)); @@ -67,7 +68,8 @@ namespace Umbraco.Core.Persistence _mappers = mappers ?? throw new ArgumentNullException(nameof(mappers)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - var settings = ConfigurationManager.ConnectionStrings[connectionStringName]; + var settings = configs.ConnectionStrings()[connectionStringName]; + if (settings == null) { logger.Debug("Missing connection string, defer configuration."); @@ -135,7 +137,7 @@ namespace Umbraco.Core.Persistence { // replace NPoco database type by a more efficient one - var setting = ConfigurationManager.AppSettings[Constants.AppSettings.Debug.DatabaseFactoryServerVersion]; + var setting = Current.Configs.Global().DatabaseFactoryServerVersion; var fromSettings = false; if (setting.IsNullOrWhiteSpace() || !setting.StartsWith("SqlServer.") diff --git a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs index 445747f299..61a9f472fe 100644 --- a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs @@ -1,5 +1,4 @@ using System; -using System.Configuration; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Composing.CompositionExtensions; @@ -81,10 +80,11 @@ namespace Umbraco.Core.Runtime // register a server registrar, by default it's the db registrar composition.RegisterUnique(f => { - // TODO: this is a hack, use proper configuration! - // also: we still register the full IServerMessenger because + var globalSettings = f.GetInstance(); + + // TODO: we still register the full IServerMessenger because // even on 1 single server we can have 2 concurrent app domains - var singleServer = "true".InvariantEquals(ConfigurationManager.AppSettings[Constants.AppSettings.DisableElectionForSingleServer]); + var singleServer = globalSettings.DisableElectionForSingleServer; return singleServer ? (IServerRegistrar) new SingleServerRegistrar(f.GetInstance()) : new DatabaseServerRegistrar( diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 99b8997ce5..dc6963109c 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.Configuration; using System.Diagnostics; using System.IO; using System.Web; using System.Web.Hosting; -using Semver; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -30,10 +28,31 @@ namespace Umbraco.Core.Runtime private IFactory _factory; private RuntimeState _state; + + public CoreRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger) + { + IOHelper = ioHelper; + Configs = configs; + UmbracoVersion = umbracoVersion ; + + Logger = logger; + // runtime state + // beware! must use '() => _factory.GetInstance()' and NOT '_factory.GetInstance' + // as the second one captures the current value (null) and therefore fails + _state = new RuntimeState(Logger, + Configs.Settings(), Configs.Global(), + new Lazy(() => _factory.GetInstance()), + new Lazy(() => _factory.GetInstance()), + UmbracoVersion) + { + Level = RuntimeLevel.Boot + }; + } + /// /// Gets the logger. /// - protected ILogger Logger { get; private set; } + protected ILogger Logger { get; set; } /// /// Gets the profiler. @@ -53,7 +72,10 @@ namespace Umbraco.Core.Runtime /// /// Gets the /// - protected IIOHelper IOHelper { get; private set; } + protected IIOHelper IOHelper { get; } + protected Configs Configs { get; set; } + protected IUmbracoVersion UmbracoVersion { get; } + /// public IRuntimeState State => _state; @@ -64,18 +86,11 @@ namespace Umbraco.Core.Runtime // ie the bare minimum required to boot // loggers - var logger = Logger = GetLogger(); - if (logger == null) - throw new InvalidOperationException($"The object returned from {nameof(GetLogger)} cannot be null"); var profiler = Profiler = GetProfiler(); if (profiler == null) throw new InvalidOperationException($"The object returned from {nameof(GetProfiler)} cannot be null"); - var profilingLogger = ProfilingLogger = new ProfilingLogger(logger, profiler); - - IOHelper = GetIOHelper(); - if (IOHelper == null) - throw new InvalidOperationException($"The object returned from {nameof(GetIOHelper)} cannot be null"); + var profilingLogger = ProfilingLogger = new ProfilingLogger(Logger, profiler); TypeFinder = GetTypeFinder(); if (TypeFinder == null) @@ -96,12 +111,12 @@ namespace Umbraco.Core.Runtime "Booted.", "Boot failed.")) { - logger.Info("Booting site '{HostingSiteName}', app '{HostingApplicationID}', path '{HostingPhysicalPath}', server '{MachineName}'.", + Logger.Info("Booting site '{HostingSiteName}', app '{HostingApplicationID}', path '{HostingPhysicalPath}', server '{MachineName}'.", HostingEnvironment.SiteName, HostingEnvironment.ApplicationID, HostingEnvironment.ApplicationPhysicalPath, NetworkHelper.MachineName); - logger.Debug("Runtime: {Runtime}", GetType().FullName); + Logger.Debug("Runtime: {Runtime}", GetType().FullName); // application environment ConfigureUnhandledException(); @@ -134,31 +149,15 @@ namespace Umbraco.Core.Runtime // database factory var databaseFactory = GetDatabaseFactory(); - // configs - var configs = GetConfigs(); - - var umbracoVersion = GetUmbracoVersion(configs.Global()); // type finder/loader - var typeLoader = new TypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(configs.Global().LocalTempPath), ProfilingLogger); - - // runtime state - // beware! must use '() => _factory.GetInstance()' and NOT '_factory.GetInstance' - // as the second one captures the current value (null) and therefore fails - _state = new RuntimeState(Logger, - configs.Settings(), configs.Global(), - new Lazy(() => _factory.GetInstance()), - new Lazy(() => _factory.GetInstance()), - umbracoVersion) - { - Level = RuntimeLevel.Boot - }; + var typeLoader = new TypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, new DirectoryInfo(Configs.Global().LocalTempPath(IOHelper)), ProfilingLogger); // main dom var mainDom = new MainDom(Logger); // create the composition - composition = new Composition(register, typeLoader, ProfilingLogger, _state, configs); - composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, mainDom, appCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper, umbracoVersion); + composition = new Composition(register, typeLoader, ProfilingLogger, _state, Configs); + composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, mainDom, appCaches, databaseFactory, typeLoader, _state, TypeFinder, IOHelper, UmbracoVersion); // run handlers RuntimeOptions.DoRuntimeEssentials(composition, appCaches, typeLoader, databaseFactory); @@ -333,12 +332,6 @@ namespace Umbraco.Core.Runtime protected virtual IEnumerable GetComposerTypes(TypeLoader typeLoader) => typeLoader.GetTypes(); - /// - /// Gets a logger. - /// - protected virtual ILogger GetLogger() - => SerilogLogger.CreateWithDefaultConfiguration(); - /// /// Gets a profiler. /// @@ -352,12 +345,6 @@ namespace Umbraco.Core.Runtime protected virtual ITypeFinder GetTypeFinder() => new TypeFinder(Logger); - /// - /// Gets a - /// - /// - protected virtual IIOHelper GetIOHelper() - => Umbraco.Core.IO.IOHelper.Default; /// /// Gets the application caches. @@ -384,17 +371,8 @@ namespace Umbraco.Core.Runtime /// /// This is strictly internal, for tests only. protected internal virtual IUmbracoDatabaseFactory GetDatabaseFactory() - => new UmbracoDatabaseFactory(Logger, new Lazy(() => _factory.GetInstance())); + => new UmbracoDatabaseFactory(Logger, new Lazy(() => _factory.GetInstance()), Configs); - /// - /// Gets the configurations. - /// - protected virtual Configs GetConfigs() - { - var configs = new ConfigsFactory(IOHelper).Create(); - - return configs; - } #endregion } diff --git a/src/Umbraco.Core/RuntimeOptions.cs b/src/Umbraco.Core/RuntimeOptions.cs index c0bae23446..23abd474a4 100644 --- a/src/Umbraco.Core/RuntimeOptions.cs +++ b/src/Umbraco.Core/RuntimeOptions.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using System.Configuration; -using System.Runtime.CompilerServices; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Logging; @@ -19,43 +17,6 @@ namespace Umbraco.Core { private static List> _onBoot; private static List> _onEssentials; - private static bool? _installMissingDatabase; - private static bool? _installEmptyDatabase; - - // reads a boolean appSetting - private static bool BoolSetting(string key, bool missing) => ConfigurationManager.AppSettings[key]?.InvariantEquals("true") ?? missing; - - /// - /// Gets a value indicating whether the runtime should enter Install level when the database is missing. - /// - /// - /// By default, when a database connection string is configured but it is not possible to - /// connect to the database, the runtime enters the BootFailed level. If this options is set to true, - /// it enters the Install level instead. - /// It is then up to the implementor, that is setting this value, to take over the installation - /// sequence. - /// - public static bool InstallMissingDatabase - { - get => _installEmptyDatabase ?? BoolSetting("Umbraco.Core.RuntimeState.InstallMissingDatabase", false); - set => _installEmptyDatabase = value; - } - - /// - /// Gets a value indicating whether the runtime should enter Install level when the database is empty. - /// - /// - /// By default, when a database connection string is configured and it is possible to connect to - /// the database, but the database is empty, the runtime enters the BootFailed level. If this options - /// is set to true, it enters the Install level instead. - /// It is then up to the implementor, that is setting this value, to take over the installation - /// sequence. - /// - public static bool InstallEmptyDatabase - { - get => _installMissingDatabase ?? BoolSetting("Umbraco.Core.RuntimeState.InstallEmptyDatabase", false); - set => _installMissingDatabase = value; - } /// /// Executes the RuntimeBoot handlers. diff --git a/src/Umbraco.Core/RuntimeState.cs b/src/Umbraco.Core/RuntimeState.cs index a73c1d9170..e0ce17f769 100644 --- a/src/Umbraco.Core/RuntimeState.cs +++ b/src/Umbraco.Core/RuntimeState.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading; using System.Web; using Semver; -using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Exceptions; @@ -68,7 +67,7 @@ namespace Umbraco.Core public SemVersion SemanticVersion => _umbracoVersion.SemanticVersion; /// - public bool Debug { get; } = GlobalSettings.DebugMode; + public bool Debug => HttpContext.Current != null ? HttpContext.Current.IsDebuggingEnabled : _globalSettings.DebugMode; /// public bool IsMainDom => MainDom.IsMainDom; @@ -170,7 +169,7 @@ namespace Umbraco.Core // else, keep going, // anything other than install wants a database - see if we can connect // (since this is an already existing database, assume localdb is ready) - var tries = RuntimeOptions.InstallMissingDatabase ? 2 : 5; + var tries = _globalSettings.InstallMissingDatabase ? 2 : 5; for (var i = 0;;) { connect = databaseFactory.CanConnect; @@ -184,7 +183,7 @@ namespace Umbraco.Core // cannot connect to configured database, this is bad, fail logger.Debug("Could not connect to database."); - if (RuntimeOptions.InstallMissingDatabase) + if (_globalSettings.InstallMissingDatabase) { // ok to install on a configured but missing database Level = RuntimeLevel.Install; @@ -213,7 +212,7 @@ namespace Umbraco.Core // can connect to the database but cannot check the upgrade state... oops logger.Warn(e, "Could not check the upgrade state."); - if (RuntimeOptions.InstallEmptyDatabase) + if (_globalSettings.InstallEmptyDatabase) { // ok to install on an empty database Level = RuntimeLevel.Install; diff --git a/src/Umbraco.Core/Security/MembershipProviderBase.cs b/src/Umbraco.Core/Security/MembershipProviderBase.cs index 633e12bcc1..aa0ef43b5c 100644 --- a/src/Umbraco.Core/Security/MembershipProviderBase.cs +++ b/src/Umbraco.Core/Security/MembershipProviderBase.cs @@ -10,9 +10,7 @@ using System.Web.Configuration; using System.Web.Hosting; using System.Web.Security; using Umbraco.Core.Composing; -using Umbraco.Core.Configuration; using Umbraco.Core.Logging; -using Umbraco.Core.Models; namespace Umbraco.Core.Security { diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index 7442169b44..118080feb6 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -534,7 +534,7 @@ namespace Umbraco.Core.Sync { var fileName = HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty) + "-lastsynced.txt"; - var distCacheFilePath = Path.Combine(globalSettings.LocalTempPath, "DistCache", fileName); + var distCacheFilePath = Path.Combine(globalSettings.LocalTempPath(Current.IOHelper), "DistCache", fileName); //ensure the folder exists var folder = Path.GetDirectoryName(distCacheFilePath); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 59e9c40d00..f3486aa1f7 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -149,9 +149,7 @@ - - - + @@ -561,7 +559,6 @@ - diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs index 46b936c1ae..ee78360716 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs @@ -24,7 +24,7 @@ namespace Umbraco.Tests.Cache.DistributedCache [SetUp] public void Setup() { - var register = RegisterFactory.Create(); + var register = TestHelper.GetRegister(); var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 9904be67cb..89bcd48d05 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Components var logger = Mock.Of(); var typeFinder = new TypeFinder(logger); - var f = new UmbracoDatabaseFactory(logger, new Lazy(() => new MapperCollection(Enumerable.Empty()))); + var f = new UmbracoDatabaseFactory(logger, new Lazy(() => new MapperCollection(Enumerable.Empty())), TestHelper.GetConfigs()); var fs = new FileSystems(mock.Object, logger, IOHelper.Default, SettingsForTests.GenerateMockGlobalSettings()); var p = new ScopeProvider(f, fs, logger, typeFinder); diff --git a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs index 91f1b42b8c..53b4a9c380 100644 --- a/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests/Composing/CollectionBuildersTests.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Composing { Current.Reset(); - var register = RegisterFactory.Create(); + var register = TestHelper.GetRegister(); _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); } diff --git a/src/Umbraco.Tests/Composing/ContainerConformingTests.cs b/src/Umbraco.Tests/Composing/ContainerConformingTests.cs index f5c1ff9bc7..4ec6dfc0d5 100644 --- a/src/Umbraco.Tests/Composing/ContainerConformingTests.cs +++ b/src/Umbraco.Tests/Composing/ContainerConformingTests.cs @@ -4,6 +4,7 @@ using System.Linq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Composing { @@ -12,7 +13,7 @@ namespace Umbraco.Tests.Composing { // tests that a container conforms - private IRegister GetRegister() => RegisterFactory.Create(); + private IRegister GetRegister() => TestHelper.GetRegister(); [Test] public void CanRegisterAndGet() diff --git a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs index 7143db6c70..6ba6a4c9b0 100644 --- a/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests/Composing/LazyCollectionBuilderTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Composing private IRegister CreateRegister() { - return RegisterFactory.Create(); + return TestHelper.GetRegister(); } // note diff --git a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs index bbe65c39aa..d4709ae03a 100644 --- a/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests/Composing/PackageActionCollectionTests.cs @@ -19,7 +19,7 @@ namespace Umbraco.Tests.Composing [Test] public void PackageActionCollectionBuilderWorks() { - var container = RegisterFactory.Create(); + var container = TestHelper.GetRegister(); var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index b836dda1e5..52ace63240 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -26,12 +26,6 @@ namespace Umbraco.Tests.Configurations Current.IOHelper.Root = _root; } - [Test] - public void Is_Debug_Mode() - { - Assert.That(GlobalSettings.DebugMode, Is.EqualTo(true)); - } - [Ignore("fixme - ignored test")] [Test] public void Is_Version_From_Assembly_Correct() diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 17d8c1421c..48ed9adbb1 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.IO [SetUp] public void Setup() { - _register = RegisterFactory.Create(); + _register = TestHelper.GetRegister(); var composition = new Composition(_register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); diff --git a/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs b/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs index fb451b1d5c..7ab9d2e28a 100644 --- a/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs +++ b/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Persistence _sqlCeSyntaxProvider = new SqlCeSyntaxProvider(); _sqlSyntaxProviders = new[] { (ISqlSyntaxProvider) _sqlCeSyntaxProvider }; _logger = Mock.Of(); - _databaseFactory = new UmbracoDatabaseFactory(_logger, new Lazy(() => Mock.Of())); + _databaseFactory = new UmbracoDatabaseFactory(_logger, new Lazy(() => Mock.Of()), TestHelper.GetConfigs()); } [TearDown] diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index 6b6e6f7841..e492e881c0 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -69,7 +69,7 @@ namespace Umbraco.Tests.PropertyEditors { try { - var container = RegisterFactory.Create(); + var container = TestHelper.GetRegister(); var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); composition.WithCollectionBuilder(); diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs index a282496a13..b3ec8dd08b 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueEditorTests.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.PropertyEditors //normalize culture Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; - var register = RegisterFactory.Create(); + var register = TestHelper.GetRegister(); var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); register.Register(_ diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index ad9da0cf65..f1042519f5 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -176,7 +176,7 @@ namespace Umbraco.Tests.Published public void SimpleConverter3Test() { Current.Reset(); - var register = RegisterFactory.Create(); + var register = TestHelper.GetRegister(); var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs index d0e780a92b..882db8112c 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs @@ -48,7 +48,7 @@ namespace Umbraco.Tests.PublishedContent { var baseLoader = base.CreateTypeLoader(ioHelper, typeFinder, runtimeCache, globalSettings, logger); - return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath), logger, false, + return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath(ioHelper)), logger, false, // this is so the model factory looks into the test assembly baseLoader.AssembliesToScan .Union(new[] {typeof(PublishedContentMoreTests).Assembly}) diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index 7c70e82047..de4dd45f64 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -91,7 +91,7 @@ namespace Umbraco.Tests.PublishedContent { var baseLoader = base.CreateTypeLoader(ioHelper, typeFinder, runtimeCache, globalSettings, logger); - return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath), logger, false, + return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath(ioHelper)), logger, false, // this is so the model factory looks into the test assembly baseLoader.AssembliesToScan .Union(new[] { typeof(PublishedContentTests).Assembly }) diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index ac402ad77d..be3892dd89 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -19,6 +19,7 @@ using Umbraco.Core.Strings; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Dictionary; +using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence; using Umbraco.Core.Services; @@ -49,11 +50,12 @@ namespace Umbraco.Tests.Routing public class TestRuntime : WebRuntime { - public TestRuntime(UmbracoApplicationBase umbracoApplication) - : base(umbracoApplication) - { } + public TestRuntime(UmbracoApplicationBase umbracoApplication, Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger) + : base(umbracoApplication, configs, umbracoVersion, ioHelper, logger) + { + Logger = Mock.Of(); + } - protected override ILogger GetLogger() => Mock.Of(); protected override IProfiler GetProfiler() => Mock.Of(); } diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index de8322d737..87e8322708 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -80,18 +80,34 @@ namespace Umbraco.Tests.Runtimes // test application public class TestUmbracoApplication : UmbracoApplicationBase { + public TestUmbracoApplication() : base(new DebugDiagnosticsLogger(new MessageTemplates()), GetConfigs()) + { + } + + private static Configs GetConfigs() + { + var configs = new ConfigsFactory(Umbraco.Core.IO.IOHelper.Default).Create(); + configs.Add(SettingsForTests.GetDefaultGlobalSettings); + configs.Add(SettingsForTests.GetDefaultUmbracoSettings); + return configs; + } + public IRuntime Runtime { get; private set; } - protected override IRuntime GetRuntime() + protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger) { - return Runtime = new TestRuntime(); + return Runtime = new TestRuntime(configs, umbracoVersion, ioHelper, logger); } } // test runtime public class TestRuntime : CoreRuntime { - protected override ILogger GetLogger() => new DebugDiagnosticsLogger(new MessageTemplates()); + public TestRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger) + :base(configs, umbracoVersion, ioHelper, logger) + { + + } protected override IProfiler GetProfiler() => new TestProfiler(); // must override the database factory @@ -104,14 +120,6 @@ namespace Umbraco.Tests.Runtimes return mock.Object; } - protected override Configs GetConfigs() - { - var configs = new ConfigsFactory(Umbraco.Core.IO.IOHelper.Default).Create(); - configs.Add(SettingsForTests.GetDefaultGlobalSettings); - configs.Add(SettingsForTests.GetDefaultUmbracoSettings); - return configs; - } - // FIXME: so how the f* should we do it now? /* // pretend we have the proper migration diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index e799c4e638..119211225a 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -60,22 +60,22 @@ namespace Umbraco.Tests.Runtimes var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = AppCaches.Disabled; - var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy(() => factory.GetInstance())); + var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy(() => factory.GetInstance()), TestHelper.GetConfigs()); var typeFinder = new TypeFinder(logger); var ioHelper = IOHelper.Default; var typeLoader = new TypeLoader(ioHelper, typeFinder, appCaches.RuntimeCache, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), profilingLogger); var mainDom = new SimpleMainDom(); var umbracoVersion = TestHelper.GetUmbracoVersion(); var runtimeState = new RuntimeState(logger, null, null, new Lazy(() => mainDom), new Lazy(() => factory.GetInstance()), umbracoVersion); + var configs = TestHelper.GetConfigs(); // create the register and the composition - var register = RegisterFactory.Create(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, TestHelper.GetConfigs()); + var register = TestHelper.GetRegister(); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion); // create the core runtime and have it compose itself - var coreRuntime = new CoreRuntime(); - coreRuntime.Compose(composition); + var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger);coreRuntime.Compose(composition); // determine actual runtime level runtimeState.DetermineRuntimeLevel(databaseFactory, logger); @@ -259,15 +259,16 @@ namespace Umbraco.Tests.Runtimes Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run); var mainDom = Mock.Of(); Mock.Get(mainDom).Setup(x => x.IsMainDom).Returns(true); + var configs = TestHelper.GetConfigs(); // create the register and the composition - var register = RegisterFactory.Create(); - var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, TestHelper.GetConfigs()); + var register = TestHelper.GetRegister(); + var composition = new Composition(register, typeLoader, profilingLogger, runtimeState, configs); var umbracoVersion = TestHelper.GetUmbracoVersion(); composition.RegisterEssentials(logger, profiler, profilingLogger, mainDom, appCaches, databaseFactory, typeLoader, runtimeState, typeFinder, ioHelper, umbracoVersion); // create the core runtime and have it compose itself - var coreRuntime = new CoreRuntime(); + var coreRuntime = new CoreRuntime(configs, umbracoVersion, ioHelper, logger); coreRuntime.Compose(composition); // get the components diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index d8af1af09d..708f0d29db 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Scoping DoThing2 = null; DoThing3 = null; - var register = RegisterFactory.Create(); + var register = TestHelper.GetRegister(); var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index 305143ec0f..140759c3bd 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -35,7 +35,7 @@ namespace Umbraco.Tests.TestHelpers { Current.Reset(); - var container = RegisterFactory.Create(); + var container = TestHelper.GetRegister(); var ioHelper = IOHelper.Default; var logger = new ProfilingLogger(Mock.Of(), Mock.Of()); diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index 7dc2aec8ea..a81a1062fc 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.TestHelpers settings.TimeOutInMinutes == 20 && settings.DefaultUILanguage == "en" && settings.LocalTempStorageLocation == LocalTempStorage.Default && - settings.LocalTempPath == Current.IOHelper.MapPath("~/App_Data/TEMP") && + //settings.LocalTempPath == Current.IOHelper.MapPath("~/App_Data/TEMP") && settings.ReservedPaths == (GlobalSettings.StaticReservedPaths + "~/umbraco") && settings.ReservedUrls == GlobalSettings.StaticReservedUrls && settings.UmbracoPath == "~/umbraco" && diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index 9dc24e4989..85c4ad345a 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -280,5 +280,10 @@ namespace Umbraco.Tests.TestHelpers { return new UmbracoVersion(GetConfigs().Global()); } + + public static IRegister GetRegister() + { + return RegisterFactory.Create(GetConfigs().Global()); + } } } diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 41395b465a..51a06ad564 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -238,7 +238,7 @@ namespace Umbraco.Tests.TestHelpers // mappersBuilder.AddCore(); // var mappers = mappersBuilder.CreateCollection(); var mappers = Current.Factory.GetInstance(); - databaseFactory = new UmbracoDatabaseFactory(Constants.System.UmbracoConnectionName, logger, new Lazy(() => mappers)); + databaseFactory = new UmbracoDatabaseFactory(Constants.System.UmbracoConnectionName, logger, new Lazy(() => mappers), TestHelper.GetConfigs()); } typeFinder = typeFinder ?? new TypeFinder(logger); @@ -246,6 +246,6 @@ namespace Umbraco.Tests.TestHelpers var scopeProvider = new ScopeProvider(databaseFactory, fileSystems, logger, typeFinder); return scopeProvider; } - + } } diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index f7804f33f0..b41b894283 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -142,7 +142,7 @@ namespace Umbraco.Tests.Testing UmbracoVersion = new UmbracoVersion(globalSettings); var typeLoader = GetTypeLoader(IOHelper, TypeFinder, appCaches.RuntimeCache, globalSettings, proflogger, Options.TypeLoader); - var register = RegisterFactory.Create(); + var register = TestHelper.GetRegister(); Composition = new Composition(register, typeLoader, proflogger, ComponentTests.MockRuntimeState(RuntimeLevel.Run), TestHelper.GetConfigs()); @@ -302,7 +302,7 @@ namespace Umbraco.Tests.Testing // common to all tests = cannot be overriden private static TypeLoader CreateCommonTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, IGlobalSettings globalSettings, IProfilingLogger logger) { - return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath), logger, false, new[] + return new TypeLoader(ioHelper, typeFinder, runtimeCache, new DirectoryInfo(globalSettings.LocalTempPath(ioHelper)), logger, false, new[] { Assembly.Load("Umbraco.Core"), Assembly.Load("Umbraco.Web"), @@ -362,7 +362,8 @@ namespace Umbraco.Tests.Testing Composition.RegisterUnique(f => new UmbracoDatabaseFactory( Constants.System.UmbracoConnectionName, Logger, - new Lazy(f.GetInstance))); + new Lazy(f.GetInstance), + TestHelper.GetConfigs())); Composition.RegisterUnique(f => f.TryGetInstance().SqlContext); Composition.WithCollectionBuilder(); // empty diff --git a/src/Umbraco.Web/Install/InstallHelper.cs b/src/Umbraco.Web/Install/InstallHelper.cs index 2cfd4b8c4d..093f3b944b 100644 --- a/src/Umbraco.Web/Install/InstallHelper.cs +++ b/src/Umbraco.Web/Install/InstallHelper.cs @@ -1,13 +1,10 @@ using System; using System.Collections.Generic; -using System.Configuration; -using System.IO; using System.Linq; using System.Net.Http; using System.Web; using Umbraco.Core; using Umbraco.Core.Configuration; -using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Persistence; @@ -113,9 +110,9 @@ namespace Umbraco.Web.Install { get { - var databaseSettings = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName]; + var databaseSettings = Current.Configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; if (_globalSettings.ConfigurationStatus.IsNullOrWhiteSpace() - && _databaseBuilder.IsConnectionStringConfigured(databaseSettings) == false) + && DatabaseHelper.IsConnectionStringConfigured(databaseSettings) == false) { //no version or conn string configured, must be a brand new install return true; @@ -123,7 +120,7 @@ namespace Umbraco.Web.Install //now we have to check if this is really a new install, the db might be configured and might contain data - if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings) == false + if (DatabaseHelper.IsConnectionStringConfigured(databaseSettings) == false || _databaseBuilder.IsDatabaseConfigured == false) { return true; diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs index d119759488..c96e11feae 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs @@ -1,7 +1,7 @@ using System; -using System.Configuration; using System.Threading.Tasks; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Web.Install.Models; @@ -72,9 +72,9 @@ namespace Umbraco.Web.Install.InstallSteps private bool ShouldDisplayView() { //If the connection string is already present in web.config we don't need to show the settings page and we jump to installing/upgrading. - var databaseSettings = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName]; + var databaseSettings = Current.Configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; - if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings)) + if (DatabaseHelper.IsConnectionStringConfigured(databaseSettings)) { try { diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs index 4e8068c4c5..8c6d727fef 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs @@ -1,13 +1,11 @@ -using System; -using System.Configuration; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Migrations.Upgrade; +using Umbraco.Web.Composing; using Umbraco.Web.Install.Models; -using Umbraco.Web.Migrations; using Umbraco.Web.Migrations.PostMigrations; namespace Umbraco.Web.Install.InstallSteps @@ -66,9 +64,9 @@ namespace Umbraco.Web.Install.InstallSteps return false; } - var databaseSettings = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName]; + var databaseSettings = Current.Configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; - if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings)) + if (DatabaseHelper.IsConnectionStringConfigured(databaseSettings)) { // a connection string was present, determine whether this is an install/upgrade // return true (upgrade) if there is an installed version, else false (install) diff --git a/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs index 151265f394..e0a5f29ace 100644 --- a/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Specialized; -using System.Configuration; -using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -135,13 +133,13 @@ namespace Umbraco.Web.Install.InstallSteps public override bool RequiresExecution(UserModel model) { //now we have to check if this is really a new install, the db might be configured and might contain data - var databaseSettings = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName]; + var databaseSettings = Current.Configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; //if there's already a version then there should def be a user but in some cases someone may have // left a version number in there but cleared out their db conn string, in that case, it's really a new install. if (_globalSettings.ConfigurationStatus.IsNullOrWhiteSpace() == false && databaseSettings != null) return false; - if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings) && _databaseBuilder.IsDatabaseConfigured) + if (DatabaseHelper.IsConnectionStringConfigured(databaseSettings) && _databaseBuilder.IsDatabaseConfigured) return _databaseBuilder.HasSomeNonDefaultUser() == false; // In this one case when it's a brand new install and nothing has been configured, make sure the diff --git a/src/Umbraco.Web/Profiling/WebProfilingController.cs b/src/Umbraco.Web/Profiling/WebProfilingController.cs index b3d580bc38..a8935da033 100644 --- a/src/Umbraco.Web/Profiling/WebProfilingController.cs +++ b/src/Umbraco.Web/Profiling/WebProfilingController.cs @@ -1,4 +1,10 @@ -using Umbraco.Web.Editors; +using Umbraco.Core; +using Umbraco.Core.Cache; +using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; +using Umbraco.Core.Persistence; +using Umbraco.Core.Services; +using Umbraco.Web.Editors; using Umbraco.Web.WebApi.Filters; namespace Umbraco.Web.Profiling @@ -9,11 +15,19 @@ namespace Umbraco.Web.Profiling [UmbracoApplicationAuthorize(Core.Constants.Applications.Settings)] public class WebProfilingController : UmbracoAuthorizedJsonController { + private readonly IRuntimeState _runtimeState; + + public WebProfilingController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper) + : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper) + { + _runtimeState = runtimeState; + } + public object GetStatus() { return new { - Enabled = Core.Configuration.GlobalSettings.DebugMode + Enabled = _runtimeState.Debug }; } }} diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 554e76c665..974731b9bd 100755 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -299,7 +299,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private string GetLocalFilesPath() { - var path = Path.Combine(_globalSettings.LocalTempPath, "NuCache"); + var path = Path.Combine(_globalSettings.LocalTempPath(Current.IOHelper), "NuCache"); if (!Directory.Exists(path)) Directory.CreateDirectory(path); diff --git a/src/Umbraco.Web/Runtime/WebInitialComponent.cs b/src/Umbraco.Web/Runtime/WebInitialComponent.cs index 6edb1f0039..380c3915b7 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComponent.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComponent.cs @@ -119,7 +119,7 @@ namespace Umbraco.Web.Runtime // location to be there if (globalSettings.LocalTempStorageLocation == LocalTempStorage.EnvironmentTemp) { - var cachePath = globalSettings.LocalTempPath; + var cachePath = globalSettings.LocalTempPath(Current.IOHelper); //set the file map and composite file default location to the %temp% location BaseCompositeFileProcessingProvider.CompositeFilePathDefaultFolder diff --git a/src/Umbraco.Web/Runtime/WebRuntime.cs b/src/Umbraco.Web/Runtime/WebRuntime.cs index 2f1ef43e4c..bd17907cc9 100644 --- a/src/Umbraco.Web/Runtime/WebRuntime.cs +++ b/src/Umbraco.Web/Runtime/WebRuntime.cs @@ -2,6 +2,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Runtime; using Umbraco.Web.Cache; @@ -24,7 +25,8 @@ namespace Umbraco.Web.Runtime /// Initializes a new instance of the class. /// /// - public WebRuntime(UmbracoApplicationBase umbracoApplication) + public WebRuntime(UmbracoApplicationBase umbracoApplication, Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger): + base(configs, umbracoVersion, ioHelper, logger) { _umbracoApplication = umbracoApplication; } @@ -33,8 +35,7 @@ namespace Umbraco.Web.Runtime public override IFactory Boot(IRegister register) { // create and start asap to profile boot - var debug = GlobalSettings.DebugMode; - if (debug) + if (State.Debug) { _webProfiler = new WebProfiler(); _webProfiler.Start(); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 048d8aacf2..503194e52a 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -1287,4 +1287,4 @@ - + \ No newline at end of file diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 191fb9dcd6..ec620cdb8d 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -1,6 +1,9 @@ using System.Threading; using System.Web; using Umbraco.Core; +using Umbraco.Core.Configuration; +using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Web.Runtime; namespace Umbraco.Web @@ -10,9 +13,9 @@ namespace Umbraco.Web /// public class UmbracoApplication : UmbracoApplicationBase { - protected override IRuntime GetRuntime() + protected override IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger) { - return new WebRuntime(this); + return new WebRuntime(this, configs, umbracoVersion, ioHelper, logger); } /// diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index dba7798559..c0e56579b6 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -6,6 +6,7 @@ using System.Web.Hosting; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Logging.Serilog; @@ -18,17 +19,36 @@ namespace Umbraco.Web { private IRuntime _runtime; + public readonly ILogger _logger; + private readonly Configs _configs; + private readonly IIOHelper _ioHelper; + + protected UmbracoApplicationBase() + { + _logger = SerilogLogger.CreateWithDefaultConfiguration(); + _ioHelper = IOHelper.Default; + _configs = new ConfigsFactory(_ioHelper).Create(); + } + + protected UmbracoApplicationBase(ILogger logger, Configs configs) + { + _logger = logger; + _configs = configs; + _ioHelper = IOHelper.Default; + } + + /// /// Gets a runtime. /// - protected abstract IRuntime GetRuntime(); + protected abstract IRuntime GetRuntime(Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger); /// /// Gets the application register. /// - protected virtual IRegister GetRegister() + protected virtual IRegister GetRegister(IGlobalSettings globalSettings) { - return RegisterFactory.Create(); + return RegisterFactory.Create(globalSettings); } // events - in the order they trigger @@ -59,10 +79,14 @@ namespace Umbraco.Web { // ******** THIS IS WHERE EVERYTHING BEGINS ******** + + var globalSettings = _configs.Global(); + var umbracoVersion = new UmbracoVersion(globalSettings); + // create the register for the application, and boot // the boot manager is responsible for registrations - var register = GetRegister(); - _runtime = GetRuntime(); + var register = GetRegister(globalSettings); + _runtime = GetRuntime(_configs, umbracoVersion, _ioHelper, _logger); _runtime.Boot(register); } diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 347f79e51b..547bd517d8 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -4,6 +4,7 @@ using System.IO; using System.Web; using System.Web.Routing; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; @@ -173,7 +174,7 @@ namespace Umbraco.Web { var request = GetRequestFromContext(); //NOTE: the request can be null during app startup! - return GlobalSettings.DebugMode + return Current.RuntimeState.Debug && request != null && (string.IsNullOrEmpty(request["umbdebugshowtrace"]) == false || string.IsNullOrEmpty(request["umbdebug"]) == false @@ -290,7 +291,7 @@ namespace Umbraco.Web _previewing = _previewToken.IsNullOrWhiteSpace() == false; } - + // say we render a macro or RTE in a give 'preview' mode that might not be the 'current' one, // then due to the way it all works at the moment, the 'current' published snapshot need to be in the proper // default 'preview' mode - somehow we have to force it. and that could be recursive. diff --git a/src/Umbraco.Web/UrlHelperExtensions.cs b/src/Umbraco.Web/UrlHelperExtensions.cs index 249ce76193..243f327c9a 100644 --- a/src/Umbraco.Web/UrlHelperExtensions.cs +++ b/src/Umbraco.Web/UrlHelperExtensions.cs @@ -143,7 +143,7 @@ namespace Umbraco.Web //in case the user bypasses the installer and just bumps the web.config or client dependency config //if in debug mode, always burst the cache - if (GlobalSettings.DebugMode) + if (Current.RuntimeState.Debug) { return DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture).GenerateHash(); } From ac2e8f63ef210e21b41ba51631681f83078f7a34 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 15 Nov 2019 12:25:09 +0100 Subject: [PATCH 41/61] AB3594 - Post Merge fixes :S --- src/Umbraco.Core/Umbraco.Core.csproj | 932 +++++++++++++-------------- 1 file changed, 453 insertions(+), 479 deletions(-) diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 813d25d42c..1335319a9a 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -127,283 +127,40 @@ --> - + + + + + + + - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -415,6 +172,7 @@ + @@ -428,45 +186,282 @@ + + + + + + + + - + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + @@ -475,76 +470,48 @@ + + + - - - + + + + - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - + + + + + + + + + + + @@ -573,14 +540,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -593,6 +619,7 @@ + @@ -609,7 +636,10 @@ + + + @@ -635,121 +665,13 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -766,33 +688,38 @@ + + + + + + + + + + + + + - - + + + + + - - - - - - - - - - - - + @@ -810,8 +737,8 @@ - + @@ -822,8 +749,10 @@ - + + + @@ -838,21 +767,48 @@ + - - + + Properties\SolutionInfo.cs + + + + + - + + + + + + + + + + + + + + + + + + + + + + @@ -867,9 +823,17 @@ + + + + + + + + @@ -900,42 +864,48 @@ + + - + + + + + + + + + + + + + + + + - + - - - - - - - - - - - @@ -949,41 +919,39 @@ - - - + + + + + + + + + - - - + + + + + + + - - Component - - - Properties\SolutionInfo.cs - - - - - - - @@ -991,5 +959,11 @@ Umbraco.Abstractions + + + + + + \ No newline at end of file From 36e030a2af65fede48aa9d3de3ef8efce36da3fb Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 18 Nov 2019 09:21:47 +0100 Subject: [PATCH 42/61] Moved IContentService, IDataType and PublishResult --- src/{Umbraco.Core => Umbraco.Abstractions}/Models/IDataType.cs | 0 .../Services/IContentService.cs | 1 - .../Services/PublishResult.cs | 0 src/Umbraco.Core/Umbraco.Core.csproj | 3 --- 4 files changed, 4 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/IDataType.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IContentService.cs (99%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/PublishResult.cs (100%) diff --git a/src/Umbraco.Core/Models/IDataType.cs b/src/Umbraco.Abstractions/Models/IDataType.cs similarity index 100% rename from src/Umbraco.Core/Models/IDataType.cs rename to src/Umbraco.Abstractions/Models/IDataType.cs diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Abstractions/Services/IContentService.cs similarity index 99% rename from src/Umbraco.Core/Services/IContentService.cs rename to src/Umbraco.Abstractions/Services/IContentService.cs index c7f71d33fc..2a34fcb898 100644 --- a/src/Umbraco.Core/Services/IContentService.cs +++ b/src/Umbraco.Abstractions/Services/IContentService.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.ComponentModel; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; -using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Querying; namespace Umbraco.Core.Services diff --git a/src/Umbraco.Core/Services/PublishResult.cs b/src/Umbraco.Abstractions/Services/PublishResult.cs similarity index 100% rename from src/Umbraco.Core/Services/PublishResult.cs rename to src/Umbraco.Abstractions/Services/PublishResult.cs diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index eae73c28bc..67313999a5 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -217,7 +217,6 @@ - @@ -976,7 +975,6 @@ - @@ -1000,7 +998,6 @@ - From c62088aa85849444e9641be4274db47f0d030c92 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 18 Nov 2019 09:27:06 +0100 Subject: [PATCH 43/61] Moved IMember, IPublicAccessService --- src/{Umbraco.Core => Umbraco.Abstractions}/Models/IMember.cs | 0 .../Services/IPublicAccessService.cs | 5 +---- src/Umbraco.Core/Umbraco.Core.csproj | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/IMember.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IPublicAccessService.cs (95%) diff --git a/src/Umbraco.Core/Models/IMember.cs b/src/Umbraco.Abstractions/Models/IMember.cs similarity index 100% rename from src/Umbraco.Core/Models/IMember.cs rename to src/Umbraco.Abstractions/Models/IMember.cs diff --git a/src/Umbraco.Core/Services/IPublicAccessService.cs b/src/Umbraco.Abstractions/Services/IPublicAccessService.cs similarity index 95% rename from src/Umbraco.Core/Services/IPublicAccessService.cs rename to src/Umbraco.Abstractions/Services/IPublicAccessService.cs index 6878e3f62d..a3efb07028 100644 --- a/src/Umbraco.Core/Services/IPublicAccessService.cs +++ b/src/Umbraco.Abstractions/Services/IPublicAccessService.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; +using System.Collections.Generic; using Umbraco.Core.Models; -using Umbraco.Core.Security; namespace Umbraco.Core.Services { diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 67313999a5..2c42ca2895 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -221,7 +221,6 @@ - @@ -983,7 +982,6 @@ - From 50e61e9227959c14e8bcfd8860bb931d59c1a762 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 18 Nov 2019 13:03:24 +0100 Subject: [PATCH 44/61] More usage of IPropertyType, and moved more classes --- .../Models/Entities/ICanBeDirty.cs | 1 + .../Models/Entities/IRememberBeingDirty.cs | 2 ++ .../Models/IContentType.cs | 0 .../Models/IContentTypeBase.cs | 14 ++++---- .../Models/IContentTypeComposition.cs | 2 +- .../Models/IMediaType.cs | 4 +-- .../Models/IMemberType.cs | 0 src/Umbraco.Abstractions/Models/IProperty.cs | 1 + .../Models/IPropertyType.cs | 31 ++++++++++------- .../Models/PropertyGroup.cs | 0 .../Models/PropertyGroupCollection.cs | 2 +- .../Models/PropertyTypeCollection.cs | 34 ++++++++++--------- .../Models/UmbracoObjectTypes.cs | 0 .../Services/IEntityService.cs | 9 +++-- .../Services/INotificationService.cs | 4 --- src/Umbraco.Core/Models/ContentBase.cs | 4 +-- src/Umbraco.Core/Models/ContentTypeBase.cs | 16 ++++----- .../Models/ContentTypeCompositionBase.cs | 18 +++++----- src/Umbraco.Core/Models/Property.cs | 2 +- src/Umbraco.Core/Models/PropertyCollection.cs | 4 +-- src/Umbraco.Core/Models/PropertyType.cs | 4 +-- .../IPublishedContentTypeFactory.cs | 2 +- .../PublishedContentTypeFactory.cs | 2 +- .../PublishedContent/PublishedPropertyType.cs | 2 +- .../Persistence/Factories/PropertyFactory.cs | 4 +-- .../Factories/PropertyGroupFactory.cs | 4 +-- .../Persistence/Mappers/PropertyTypeMapper.cs | 2 +- .../Repositories/IContentTypeRepository.cs | 2 +- .../Implement/ContentRepositoryBase.cs | 2 +- .../Implement/ContentTypeRepositoryBase.cs | 10 +++--- src/Umbraco.Core/Services/IDataTypeService.cs | 2 +- .../Services/Implement/DataTypeService.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 11 ------ .../Mapping/ContentTypeModelMappingTests.cs | 4 +-- src/Umbraco.Web/Editors/EntityController.cs | 2 +- .../Mapping/ContentTypeMapDefinition.cs | 12 +++---- .../Models/Mapping/PropertyTypeGroupMapper.cs | 2 +- 37 files changed, 105 insertions(+), 112 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/IContentType.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/IContentTypeBase.cs (93%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/IContentTypeComposition.cs (97%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/IMediaType.cs (86%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/IMemberType.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/PropertyGroup.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/PropertyGroupCollection.cs (99%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/PropertyTypeCollection.cs (84%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Models/UmbracoObjectTypes.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IEntityService.cs (99%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/INotificationService.cs (97%) diff --git a/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs b/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs index 57a8a581f0..f9844bf65b 100644 --- a/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs +++ b/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel; namespace Umbraco.Core.Models.Entities { diff --git a/src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs b/src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs index e679b98b93..05197a7d2d 100644 --- a/src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs +++ b/src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs @@ -36,5 +36,7 @@ namespace Umbraco.Core.Models.Entities /// Gets properties that were dirty. /// IEnumerable GetWereDirtyProperties(); + + } } diff --git a/src/Umbraco.Core/Models/IContentType.cs b/src/Umbraco.Abstractions/Models/IContentType.cs similarity index 100% rename from src/Umbraco.Core/Models/IContentType.cs rename to src/Umbraco.Abstractions/Models/IContentType.cs diff --git a/src/Umbraco.Core/Models/IContentTypeBase.cs b/src/Umbraco.Abstractions/Models/IContentTypeBase.cs similarity index 93% rename from src/Umbraco.Core/Models/IContentTypeBase.cs rename to src/Umbraco.Abstractions/Models/IContentTypeBase.cs index ed87c5f320..03ea0b5427 100644 --- a/src/Umbraco.Core/Models/IContentTypeBase.cs +++ b/src/Umbraco.Abstractions/Models/IContentTypeBase.cs @@ -103,17 +103,17 @@ namespace Umbraco.Core.Models /// /// Gets all local property types all local property groups or ungrouped. /// - IEnumerable PropertyTypes { get; } + IEnumerable PropertyTypes { get; } /// /// Gets or sets the local property types that do not belong to a group. /// - IEnumerable NoGroupPropertyTypes { get; set; } + IEnumerable NoGroupPropertyTypes { get; set; } /// /// Removes a PropertyType from the current ContentType /// - /// Alias of the to remove + /// Alias of the to remove void RemovePropertyType(string propertyTypeAlias); /// @@ -132,17 +132,17 @@ namespace Umbraco.Core.Models /// /// Adds a PropertyType to a specific PropertyGroup /// - /// to add + /// to add /// Name of the PropertyGroup to add the PropertyType to /// Returns True if PropertyType was added, otherwise False - bool AddPropertyType(PropertyType propertyType, string propertyGroupName); + bool AddPropertyType(IPropertyType propertyType, string propertyGroupName); /// /// Adds a PropertyType, which does not belong to a PropertyGroup. /// - /// to add + /// to add /// Returns True if PropertyType was added, otherwise False - bool AddPropertyType(PropertyType propertyType); + bool AddPropertyType(IPropertyType propertyType); /// /// Adds a PropertyGroup. diff --git a/src/Umbraco.Core/Models/IContentTypeComposition.cs b/src/Umbraco.Abstractions/Models/IContentTypeComposition.cs similarity index 97% rename from src/Umbraco.Core/Models/IContentTypeComposition.cs rename to src/Umbraco.Abstractions/Models/IContentTypeComposition.cs index 675d3cd268..17b6881487 100644 --- a/src/Umbraco.Core/Models/IContentTypeComposition.cs +++ b/src/Umbraco.Abstractions/Models/IContentTypeComposition.cs @@ -21,7 +21,7 @@ namespace Umbraco.Core.Models /// /// Gets the property types for the entire composition. /// - IEnumerable CompositionPropertyTypes { get; } + IEnumerable CompositionPropertyTypes { get; } /// /// Adds a new ContentType to the list of composite ContentTypes diff --git a/src/Umbraco.Core/Models/IMediaType.cs b/src/Umbraco.Abstractions/Models/IMediaType.cs similarity index 86% rename from src/Umbraco.Core/Models/IMediaType.cs rename to src/Umbraco.Abstractions/Models/IMediaType.cs index 25a5d0fa35..90fdc97ad7 100644 --- a/src/Umbraco.Core/Models/IMediaType.cs +++ b/src/Umbraco.Abstractions/Models/IMediaType.cs @@ -1,6 +1,4 @@ -using Umbraco.Core.Persistence.Mappers; - -namespace Umbraco.Core.Models +namespace Umbraco.Core.Models { /// /// Defines a ContentType, which Media is based on diff --git a/src/Umbraco.Core/Models/IMemberType.cs b/src/Umbraco.Abstractions/Models/IMemberType.cs similarity index 100% rename from src/Umbraco.Core/Models/IMemberType.cs rename to src/Umbraco.Abstractions/Models/IMemberType.cs diff --git a/src/Umbraco.Abstractions/Models/IProperty.cs b/src/Umbraco.Abstractions/Models/IProperty.cs index 35a151af10..3a0d984e55 100644 --- a/src/Umbraco.Abstractions/Models/IProperty.cs +++ b/src/Umbraco.Abstractions/Models/IProperty.cs @@ -41,5 +41,6 @@ namespace Umbraco.Core.Models int PropertyTypeId { get; } void PublishValues(string culture = "*", string segment = "*"); void UnpublishValues(string culture = "*", string segment = "*"); + void FactorySetValue(string culture, string segment, bool published, object value); } } diff --git a/src/Umbraco.Abstractions/Models/IPropertyType.cs b/src/Umbraco.Abstractions/Models/IPropertyType.cs index e70ee39933..c331590065 100644 --- a/src/Umbraco.Abstractions/Models/IPropertyType.cs +++ b/src/Umbraco.Abstractions/Models/IPropertyType.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Runtime.Serialization; using Umbraco.Core.Models.Entities; @@ -9,62 +10,62 @@ namespace Umbraco.Core.Models /// /// Gets of sets the name of the property type. /// - string Name { get; } + string Name { get; set; } /// /// Gets of sets the alias of the property type. /// - string Alias { get; } + string Alias { get; set; } /// /// Gets of sets the description of the property type. /// - string Description { get; } + string Description { get; set; } /// /// Gets or sets the identifier of the datatype for this property type. /// - int DataTypeId { get; } + int DataTypeId { get; set; } - Guid DataTypeKey { get; } + Guid DataTypeKey { get; set; } /// /// Gets or sets the alias of the property editor for this property type. /// - string PropertyEditorAlias { get; } + string PropertyEditorAlias { get; set; } /// /// Gets or sets the database type for storing value for this property type. /// - ValueStorageType ValueStorageType { get; } + ValueStorageType ValueStorageType { get; set; } /// /// Gets or sets the identifier of the property group this property type belongs to. /// /// For generic properties, the value is null. - Lazy PropertyGroupId { get; } + Lazy PropertyGroupId { get; set; } /// /// Gets of sets a value indicating whether a value for this property type is required. /// - bool Mandatory { get; } + bool Mandatory { get; set; } /// /// Gets of sets the sort order of the property type. /// - int SortOrder { get; } + int SortOrder { get; set; } /// /// Gets or sets the regular expression validating the property values. /// - string ValidationRegExp { get; } + string ValidationRegExp { get; set; } - bool SupportsPublishing { get; } + bool SupportsPublishing { get; set; } /// /// Gets or sets the content variation of the property type. /// - ContentVariation Variations { get; } + ContentVariation Variations { get; set; } /// /// Determines whether the property type supports a combination of culture and segment. @@ -83,5 +84,9 @@ namespace Umbraco.Core.Models /// Throws if the value cannot be converted. /// object ConvertAssignedValue(object value); + + event PropertyChangedEventHandler PropertyChanged; + void ResetIdentity(); + IProperty CreateProperty(); } } diff --git a/src/Umbraco.Core/Models/PropertyGroup.cs b/src/Umbraco.Abstractions/Models/PropertyGroup.cs similarity index 100% rename from src/Umbraco.Core/Models/PropertyGroup.cs rename to src/Umbraco.Abstractions/Models/PropertyGroup.cs diff --git a/src/Umbraco.Core/Models/PropertyGroupCollection.cs b/src/Umbraco.Abstractions/Models/PropertyGroupCollection.cs similarity index 99% rename from src/Umbraco.Core/Models/PropertyGroupCollection.cs rename to src/Umbraco.Abstractions/Models/PropertyGroupCollection.cs index 5422dfb792..c3c1d4b2b4 100644 --- a/src/Umbraco.Core/Models/PropertyGroupCollection.cs +++ b/src/Umbraco.Abstractions/Models/PropertyGroupCollection.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Models { private readonly ReaderWriterLockSlim _addLocker = new ReaderWriterLockSlim(); - internal PropertyGroupCollection() + public PropertyGroupCollection() { } public PropertyGroupCollection(IEnumerable groups) diff --git a/src/Umbraco.Core/Models/PropertyTypeCollection.cs b/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs similarity index 84% rename from src/Umbraco.Core/Models/PropertyTypeCollection.cs rename to src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs index 6e41f0d12b..3052bdfd23 100644 --- a/src/Umbraco.Core/Models/PropertyTypeCollection.cs +++ b/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs @@ -8,24 +8,26 @@ using System.Threading; namespace Umbraco.Core.Models { + + //public interface IPropertyTypeCollection: IEnumerable /// - /// Represents a collection of objects. + /// Represents a collection of objects. /// [Serializable] [DataContract] // TODO: Change this to ObservableDictionary so we can reduce the INotifyCollectionChanged implementation details - public class PropertyTypeCollection : KeyedCollection, INotifyCollectionChanged, IDeepCloneable + public class PropertyTypeCollection : KeyedCollection, INotifyCollectionChanged, IDeepCloneable { [IgnoreDataMember] private readonly ReaderWriterLockSlim _addLocker = new ReaderWriterLockSlim(); - internal PropertyTypeCollection(bool supportsPublishing) + public PropertyTypeCollection(bool supportsPublishing) { SupportsPublishing = supportsPublishing; } - public PropertyTypeCollection(bool supportsPublishing, IEnumerable properties) + public PropertyTypeCollection(bool supportsPublishing, IEnumerable properties) : this(supportsPublishing) { Reset(properties); @@ -34,25 +36,25 @@ namespace Umbraco.Core.Models public bool SupportsPublishing { get; } /// - /// Resets the collection to only contain the instances referenced in the parameter. + /// Resets the collection to only contain the instances referenced in the parameter. /// /// The properties. /// - internal void Reset(IEnumerable properties) + internal void Reset(IEnumerable properties) { //collection events will be raised in each of these calls Clear(); //collection events will be raised in each of these calls foreach (var property in properties) - Add(property); + Add(property); } - protected override void SetItem(int index, PropertyType item) + protected override void SetItem(int index, IPropertyType item) { item.SupportsPublishing = SupportsPublishing; var oldItem = index >= 0 ? this[index] : item; - base.SetItem(index, item); + base.SetItem(index, item); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, item, oldItem)); item.PropertyChanged += Item_PropertyChanged; } @@ -65,10 +67,10 @@ namespace Umbraco.Core.Models OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removed)); } - protected override void InsertItem(int index, PropertyType item) + protected override void InsertItem(int index, IPropertyType item) { item.SupportsPublishing = SupportsPublishing; - base.InsertItem(index, item); + base.InsertItem(index, item); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item)); item.PropertyChanged += Item_PropertyChanged; } @@ -82,7 +84,7 @@ namespace Umbraco.Core.Models } // TODO: Instead of 'new' this should explicitly implement one of the collection interfaces members - internal new void Add(PropertyType item) + internal new void Add(IPropertyType item) { item.SupportsPublishing = SupportsPublishing; @@ -120,13 +122,13 @@ namespace Umbraco.Core.Models } /// - /// Occurs when a property changes on a PropertyType that exists in this collection + /// Occurs when a property changes on a IPropertyType that exists in this collection /// /// /// private void Item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { - var propType = (PropertyType)sender; + var propType = (IPropertyType)sender; OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, propType, propType)); } @@ -156,7 +158,7 @@ namespace Umbraco.Core.Models return -1; } - protected override string GetKeyForItem(PropertyType item) + protected override string GetKeyForItem(IPropertyType item) { return item.Alias; } @@ -172,7 +174,7 @@ namespace Umbraco.Core.Models { var clone = new PropertyTypeCollection(SupportsPublishing); foreach (var propertyType in this) - clone.Add((PropertyType) propertyType.DeepClone()); + clone.Add((IPropertyType) propertyType.DeepClone()); return clone; } } diff --git a/src/Umbraco.Core/Models/UmbracoObjectTypes.cs b/src/Umbraco.Abstractions/Models/UmbracoObjectTypes.cs similarity index 100% rename from src/Umbraco.Core/Models/UmbracoObjectTypes.cs rename to src/Umbraco.Abstractions/Models/UmbracoObjectTypes.cs diff --git a/src/Umbraco.Core/Services/IEntityService.cs b/src/Umbraco.Abstractions/Services/IEntityService.cs similarity index 99% rename from src/Umbraco.Core/Services/IEntityService.cs rename to src/Umbraco.Abstractions/Services/IEntityService.cs index f03bc640ec..2b2fad277a 100644 --- a/src/Umbraco.Core/Services/IEntityService.cs +++ b/src/Umbraco.Abstractions/Services/IEntityService.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; -using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Querying; namespace Umbraco.Core.Services @@ -27,28 +26,28 @@ namespace Umbraco.Core.Services /// The identifier of the entity. /// The object type of the entity. IEntitySlim Get(int id, UmbracoObjectTypes objectType); - + /// /// Gets an entity. /// /// The unique key of the entity. /// The object type of the entity. IEntitySlim Get(Guid key, UmbracoObjectTypes objectType); - + /// /// Gets an entity. /// /// The type used to determine the object type of the entity. /// The identifier of the entity. IEntitySlim Get(int id) where T : IUmbracoEntity; - + /// /// Gets an entity. /// /// The type used to determine the object type of the entity. /// The unique key of the entity. IEntitySlim Get(Guid key) where T : IUmbracoEntity; - + /// /// Determines whether an entity exists. /// diff --git a/src/Umbraco.Core/Services/INotificationService.cs b/src/Umbraco.Abstractions/Services/INotificationService.cs similarity index 97% rename from src/Umbraco.Core/Services/INotificationService.cs rename to src/Umbraco.Abstractions/Services/INotificationService.cs index 1a48d73297..6ef639594d 100644 --- a/src/Umbraco.Core/Services/INotificationService.cs +++ b/src/Umbraco.Abstractions/Services/INotificationService.cs @@ -1,12 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; -using Umbraco.Core.Persistence; namespace Umbraco.Core.Services { diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs index c87cb0a370..e5adddad72 100644 --- a/src/Umbraco.Core/Models/ContentBase.cs +++ b/src/Umbraco.Core/Models/ContentBase.cs @@ -22,7 +22,7 @@ namespace Umbraco.Core.Models private int _writerId; private IPropertyCollection _properties; private ContentCultureInfosCollection _cultureInfos; - internal IReadOnlyList AllPropertyTypes { get; } + internal IReadOnlyList AllPropertyTypes { get; } #region Used for change tracking @@ -78,7 +78,7 @@ namespace Umbraco.Core.Models //track all property types on this content type, these can never change during the lifetime of this single instance //there is no real extra memory overhead of doing this since these property types are already cached on this object via the //properties already. - AllPropertyTypes = new List(contentType.CompositionPropertyTypes); + AllPropertyTypes = new List(contentType.CompositionPropertyTypes); } [IgnoreDataMember] diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index 04bcb7424a..a42419c66a 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -107,7 +107,7 @@ namespace Umbraco.Core.Models // { // var newAliases = string.Join(", ", e.NewItems.Cast().Select(x => x.Alias)); // throw new InvalidOperationException($"Other property types already exist with the aliases: {newAliases}"); - // } + // } //} OnPropertyChanged(nameof(PropertyTypes)); @@ -246,7 +246,7 @@ namespace Umbraco.Core.Models /// [IgnoreDataMember] [DoNotClone] - public IEnumerable PropertyTypes + public IEnumerable PropertyTypes { get { @@ -256,7 +256,7 @@ namespace Umbraco.Core.Models /// [DoNotClone] - public IEnumerable NoGroupPropertyTypes + public IEnumerable NoGroupPropertyTypes { get => _noGroupPropertyTypes; set @@ -305,17 +305,17 @@ namespace Umbraco.Core.Models /// /// Adds a PropertyType to a specific PropertyGroup /// - /// to add + /// to add /// Name of the PropertyGroup to add the PropertyType to /// Returns True if PropertyType was added, otherwise False - public abstract bool AddPropertyType(PropertyType propertyType, string propertyGroupName); + public abstract bool AddPropertyType(IPropertyType propertyType, string propertyGroupName); /// /// Adds a PropertyType, which does not belong to a PropertyGroup. /// - /// to add + /// to add /// Returns True if PropertyType was added, otherwise False - public bool AddPropertyType(PropertyType propertyType) + public bool AddPropertyType(IPropertyType propertyType) { if (PropertyTypeExists(propertyType.Alias) == false) { @@ -365,7 +365,7 @@ namespace Umbraco.Core.Models /// /// Removes a PropertyType from the current ContentType /// - /// Alias of the to remove + /// Alias of the to remove public void RemovePropertyType(string propertyTypeAlias) { //check through each property group to see if we can remove the property type by alias from it diff --git a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index ff61a15979..9db0eb9b41 100644 --- a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -56,7 +56,7 @@ namespace Umbraco.Core.Models // any change to compositions are ignored and that breaks many things - and tracking // changes to refresh the cache would be expensive. - void AcquireProperty(PropertyType propertyType) + void AcquireProperty(IPropertyType propertyType) { propertyType.Variations = propertyType.Variations & Variations; propertyType.ResetDirtyProperties(false); @@ -76,7 +76,7 @@ namespace Umbraco.Core.Models /// [IgnoreDataMember] - public IEnumerable CompositionPropertyTypes + public IEnumerable CompositionPropertyTypes { get { @@ -85,9 +85,9 @@ namespace Umbraco.Core.Models // // see note in CompositionPropertyGroups for comments on caching the resulting enumerable - PropertyType AcquireProperty(PropertyType propertyType) + IPropertyType AcquireProperty(IPropertyType propertyType) { - propertyType = (PropertyType) propertyType.DeepClone(); + propertyType = (IPropertyType) propertyType.DeepClone(); propertyType.Variations = propertyType.Variations & Variations; propertyType.ResetDirtyProperties(false); return propertyType; @@ -107,9 +107,9 @@ namespace Umbraco.Core.Models /// Gets them raw, ie with their original variation. /// [IgnoreDataMember] - internal IEnumerable RawComposedPropertyTypes => GetRawComposedPropertyTypes(); + internal IEnumerable RawComposedPropertyTypes => GetRawComposedPropertyTypes(); - private IEnumerable GetRawComposedPropertyTypes(bool start = true) + private IEnumerable GetRawComposedPropertyTypes(bool start = true) { var propertyTypes = ContentTypeComposition .Cast() @@ -250,10 +250,10 @@ namespace Umbraco.Core.Models /// /// Adds a PropertyType to a specific PropertyGroup /// - /// to add + /// to add /// Name of the PropertyGroup to add the PropertyType to /// Returns True if PropertyType was added, otherwise False - public override bool AddPropertyType(PropertyType propertyType, string propertyGroupName) + public override bool AddPropertyType(IPropertyType propertyType, string propertyGroupName) { // ensure no duplicate alias - over all composition properties if (PropertyTypeExists(propertyType.Alias)) @@ -302,7 +302,7 @@ namespace Umbraco.Core.Models base.PerformDeepClone(clone); var clonedEntity = (ContentTypeCompositionBase)clone; - + //need to manually assign since this is an internal field and will not be automatically mapped clonedEntity.RemovedContentTypeKeyTracker = new List(); clonedEntity._contentTypeComposition = ContentTypeComposition.Select(x => (IContentTypeComposition)x.DeepClone()).ToList(); diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index 9aa9ab4d74..e75a7420a8 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -284,7 +284,7 @@ namespace Umbraco.Core.Models } // bypasses all changes detection and is the *only* way to set the published value - internal void FactorySetValue(string culture, string segment, bool published, object value) + public void FactorySetValue(string culture, string segment, bool published, object value) { var (pvalue, _) = GetPValue(culture, segment, true); diff --git a/src/Umbraco.Core/Models/PropertyCollection.cs b/src/Umbraco.Core/Models/PropertyCollection.cs index b82fd71eaf..2800b92d75 100644 --- a/src/Umbraco.Core/Models/PropertyCollection.cs +++ b/src/Umbraco.Core/Models/PropertyCollection.cs @@ -26,7 +26,7 @@ namespace Umbraco.Core.Models /// /// Initializes a new instance of the class. /// - public PropertyCollection(IEnumerable properties) + public PropertyCollection(IEnumerable properties) : this() { Reset(properties); @@ -35,7 +35,7 @@ namespace Umbraco.Core.Models /// /// Replaces all properties, whilst maintaining validation delegates. /// - private void Reset(IEnumerable properties) + private void Reset(IEnumerable properties) { //collection events will be raised in each of these calls Clear(); diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index 3cbe1ab70b..e8c6b088c5 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -99,7 +99,7 @@ namespace Umbraco.Core.Models /// When false, getting the property value always return the edited value, /// regardless of the 'published' method parameter. /// - public bool SupportsPublishing { get; internal set; } + public bool SupportsPublishing { get; set; } /// [DataMember] @@ -213,7 +213,7 @@ namespace Umbraco.Core.Models /// /// Creates a new property of this property type. /// - public Property CreateProperty() + public IProperty CreateProperty() { return new Property(this); } diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs index 89009ac7b8..ca78573999 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs @@ -18,7 +18,7 @@ /// The published content type owning the property. /// A property type. /// Is used by constructor to create property types. - IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType); + IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, IPropertyType propertyType); /// /// Creates a published property type. diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs index 34094508c3..341d10b6b4 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs @@ -50,7 +50,7 @@ namespace Umbraco.Core.Models.PublishedContent } /// - public IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, PropertyType propertyType) + public IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, IPropertyType propertyType) { return new PublishedPropertyType(contentType, propertyType, _propertyValueConverters, _publishedModelFactory, this); } diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs index 0c2e62770e..b5e87ad6ff 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs @@ -30,7 +30,7 @@ namespace Umbraco.Core.Models.PublishedContent /// /// The new published property type belongs to the published content type. /// - public PublishedPropertyType(IPublishedContentType contentType, PropertyType propertyType, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory) + public PublishedPropertyType(IPublishedContentType contentType, IPropertyType propertyType, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory) : this(propertyType.Alias, propertyType.DataTypeId, true, propertyType.Variations, propertyValueConverters, publishedModelFactory, factory) { ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs index fc31f61763..527c4e59bf 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs @@ -9,9 +9,9 @@ namespace Umbraco.Core.Persistence.Factories { internal static class PropertyFactory { - public static IEnumerable BuildEntities(PropertyType[] propertyTypes, IReadOnlyCollection dtos, int publishedVersionId, ILanguageRepository languageRepository) + public static IEnumerable BuildEntities(IPropertyType[] propertyTypes, IReadOnlyCollection dtos, int publishedVersionId, ILanguageRepository languageRepository) { - var properties = new List(); + var properties = new List(); var xdtos = dtos.GroupBy(x => x.PropertyTypeId).ToDictionary(x => x.Key, x => (IEnumerable)x); foreach (var propertyType in propertyTypes) diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs index db8e2b20d9..a3014000b6 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyGroupFactory.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Persistence.Factories { internal static class PropertyGroupFactory { - + #region Implementation of IEntityFactory,IEnumerable> public static IEnumerable BuildEntity(IEnumerable groupDtos, @@ -115,7 +115,7 @@ namespace Umbraco.Core.Persistence.Factories return dto; } - internal static PropertyTypeDto BuildPropertyTypeDto(int tabId, PropertyType propertyType, int contentTypeId) + internal static PropertyTypeDto BuildPropertyTypeDto(int tabId, IPropertyType propertyType, int contentTypeId) { var propertyTypeDto = new PropertyTypeDto { diff --git a/src/Umbraco.Core/Persistence/Mappers/PropertyTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/PropertyTypeMapper.cs index ab1869a7f5..a9cabf1852 100644 --- a/src/Umbraco.Core/Persistence/Mappers/PropertyTypeMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/PropertyTypeMapper.cs @@ -6,7 +6,7 @@ using Umbraco.Core.Persistence.Dtos; namespace Umbraco.Core.Persistence.Mappers { /// - /// Represents a to DTO mapper used to translate the properties of the public api + /// Represents a to DTO mapper used to translate the properties of the public api /// implementation to that of the database's DTO as sql: [tableName].[columnName]. /// [MapperFor(typeof(PropertyType))] diff --git a/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepository.cs index d0fec639fe..203db8df93 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepository.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Persistence.Repositories public interface IContentTypeRepository : IContentTypeRepositoryBase { /// - /// Gets all entities of the specified query + /// Gets all entities of the specified query /// /// /// An enumerable list of objects diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs index 5e7c7a9b85..5803bc7b1d 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentRepositoryBase.cs @@ -524,7 +524,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement where T : class, IContentBase { var result = new Dictionary(); - var compositionPropertiesIndex = new Dictionary(); + var compositionPropertiesIndex = new Dictionary(); // index PropertyDataDto per versionId for perfs // merge edited and published dtos diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index c22d1f1200..7ec052a14c 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -405,7 +405,7 @@ AND umbracoNode.id <> @id", } // collect property types that have a dirty variation - List propertyTypeVariationDirty = null; + List propertyTypeVariationDirty = null; // note: this only deals with *local* property types, we're dealing w/compositions later below foreach (var propertyType in entity.PropertyTypes) @@ -415,7 +415,7 @@ AND umbracoNode.id <> @id", { // allocate the list only when needed if (propertyTypeVariationDirty == null) - propertyTypeVariationDirty = new List(); + propertyTypeVariationDirty = new List(); propertyTypeVariationDirty.Add(propertyType); } @@ -571,7 +571,7 @@ AND umbracoNode.id <> @id", // gets property types that have actually changed, and the corresponding changes // returns null if no property type has actually changed - private Dictionary GetPropertyVariationChanges(IEnumerable propertyTypes) + private Dictionary GetPropertyVariationChanges(IEnumerable propertyTypes) { var propertyTypesL = propertyTypes.ToList(); @@ -1190,7 +1190,7 @@ AND umbracoNode.id <> @id", new { Id = contentTypeId, PropertyTypeId = propertyTypeId }); } - protected void ValidateAlias(PropertyType pt) + protected void ValidateAlias(IPropertyType pt) { if (string.IsNullOrWhiteSpace(pt.Alias)) { @@ -1221,7 +1221,7 @@ AND umbracoNode.id <> @id", /// Try to set the data type id based on its ControlId /// /// - private void AssignDataTypeFromPropertyEditor(PropertyType propertyType) + private void AssignDataTypeFromPropertyEditor(IPropertyType propertyType) { //we cannot try to assign a data type of it's empty if (propertyType.PropertyEditorAlias.IsNullOrWhiteSpace() == false) diff --git a/src/Umbraco.Core/Services/IDataTypeService.cs b/src/Umbraco.Core/Services/IDataTypeService.cs index bedf6fdfad..b78607462c 100644 --- a/src/Umbraco.Core/Services/IDataTypeService.cs +++ b/src/Umbraco.Core/Services/IDataTypeService.cs @@ -82,7 +82,7 @@ namespace Umbraco.Core.Services /// /// /// Please note that deleting a will remove - /// all the data that references this . + /// all the data that references this . /// /// to delete /// Id of the user issuing the deletion diff --git a/src/Umbraco.Core/Services/Implement/DataTypeService.cs b/src/Umbraco.Core/Services/Implement/DataTypeService.cs index 5a93fb91b1..f9d0256568 100644 --- a/src/Umbraco.Core/Services/Implement/DataTypeService.cs +++ b/src/Umbraco.Core/Services/Implement/DataTypeService.cs @@ -414,7 +414,7 @@ namespace Umbraco.Core.Services.Implement /// /// /// Please note that deleting a will remove - /// all the data that references this . + /// all the data that references this . /// /// to delete /// Optional Id of the user issuing the deletion diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 2c42ca2895..d1fba11570 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -214,14 +214,9 @@ - - - - - @@ -258,9 +253,7 @@ - - @@ -531,10 +524,7 @@ - - - @@ -587,7 +577,6 @@ - diff --git a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs index 968e51ab97..7274ebcc98 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs @@ -626,7 +626,7 @@ namespace Umbraco.Tests.Models.Mapping } }; - var result = Mapper.Map(basic); + var result = Mapper.Map(basic); Assert.AreEqual(basic.Id, result.Id); Assert.AreEqual(basic.SortOrder, result.SortOrder); @@ -660,7 +660,7 @@ namespace Umbraco.Tests.Models.Mapping } }; - var result = Mapper.Map(basic); + var result = Mapper.Map(basic); Assert.AreEqual(basic.Id, result.Id); Assert.AreEqual(basic.SortOrder, result.SortOrder); diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 2381867616..2768af3782 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -1031,7 +1031,7 @@ namespace Umbraco.Web.Editors .SelectMany(x => x.PropertyTypes) .DistinctBy(composition => composition.Alias); var filteredPropertyTypes = ExecutePostFilter(propertyTypes, postFilter); - return Mapper.MapEnumerable(filteredPropertyTypes); + return Mapper.MapEnumerable(filteredPropertyTypes); case UmbracoEntityTypes.PropertyGroup: diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs index 528d5f6de5..05a8ecc97e 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web.Models.Mapping mapper.Define((source, context) => new MediaTypeDisplay(), Map); mapper.Define((source, context) => new MemberTypeDisplay(), Map); - mapper.Define( + mapper.Define( (source, context) => { var dataType = _dataTypeService.GetDataType(source.DataTypeId); @@ -216,7 +216,7 @@ namespace Umbraco.Web.Models.Mapping // Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate // Umbraco.Code.MapAll -SupportsPublishing -Key -PropertyEditorAlias -ValueStorageType - private static void Map(PropertyTypeBasic source, PropertyType target, MapperContext context) + private static void Map(PropertyTypeBasic source, IPropertyType target, MapperContext context) { target.Name = source.Label; target.DataTypeId = source.DataTypeId; @@ -610,9 +610,9 @@ namespace Umbraco.Web.Models.Mapping return destGroup; } - private static PropertyType MapSaveProperty(PropertyTypeBasic sourceProperty, IEnumerable destOrigProperties, MapperContext context) + private static IPropertyType MapSaveProperty(PropertyTypeBasic sourceProperty, IEnumerable destOrigProperties, MapperContext context) { - PropertyType destProperty; + IPropertyType destProperty; if (sourceProperty.Id > 0) { // updating an existing property @@ -631,11 +631,11 @@ namespace Umbraco.Web.Models.Mapping // insert a new property, or update an existing property that has // been deleted in the meantime and we need to re-create // map/create - destProperty = context.Map(sourceProperty); + destProperty = context.Map(sourceProperty); return destProperty; } - private static void EnsureUniqueAliases(IEnumerable properties) + private static void EnsureUniqueAliases(IEnumerable properties) { var propertiesA = properties.ToArray(); var distinctProperties = propertiesA diff --git a/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupMapper.cs b/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupMapper.cs index 540b080dbc..b7ebd49ac5 100644 --- a/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/PropertyTypeGroupMapper.cs @@ -194,7 +194,7 @@ namespace Umbraco.Web.Models.Mapping return groups.OrderBy(x => x.SortOrder); } - private IEnumerable MapProperties(IEnumerable properties, IContentTypeBase contentType, int groupId, bool inherited) + private IEnumerable MapProperties(IEnumerable properties, IContentTypeBase contentType, int groupId, bool inherited) { var mappedProperties = new List(); From 4c05af7b9d75f64d7f2e88034ed3f4153ab5434f Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 18 Nov 2019 14:11:50 +0100 Subject: [PATCH 45/61] AB3594 - Post review fixes.. Also removed the Current class from abstractions, and injected the factory into config --- .../Composing/Composition.cs | 2 + src/Umbraco.Abstractions/Composing/Current.cs | 76 ------------------- ...cs => ConfigConnectionStringExtensions.cs} | 5 +- .../Configuration/Configs.cs | 19 +++-- .../Logging/IMessageTemplates.cs | 5 +- .../OptionalInnerTextConfigurationElement.cs | 2 +- .../Umbraco.Configuration.csproj | 1 + .../UmbracoSettings/BackOfficeElement.cs | 2 +- .../UmbracoSettings/CharCollection.cs | 2 +- .../UmbracoSettings/CharElement.cs | 2 +- .../UmbracoSettings/ContentElement.cs | 2 +- .../ContentError404Collection.cs | 2 +- .../ContentErrorPageElement.cs | 2 +- .../UmbracoSettings/ContentErrorsElement.cs | 2 +- .../UmbracoSettings/ContentImagingElement.cs | 2 +- .../ImagingAutoFillPropertiesCollection.cs | 2 +- .../ImagingAutoFillUploadFieldElement.cs | 2 +- .../UmbracoSettings/LoggingElement.cs | 2 +- .../UmbracoSettings/NotificationsElement.cs | 2 +- .../UmbracoSettings/RequestHandlerElement.cs | 2 +- .../UmbracoSettings/SecurityElement.cs | 2 +- .../UmbracoSettings/TourConfigElement.cs | 2 +- .../UmbracoConfigurationElement.cs | 2 +- .../UmbracoSettings/UmbracoSettingsSection.cs | 2 +- .../UmbracoSettings/UrlReplacingElement.cs | 2 +- .../UmbracoSettings/WebRoutingElement.cs | 2 +- src/Umbraco.Core/Composing/Current.cs | 2 +- src/Umbraco.Core/Logging/MessageTemplates.cs | 3 - .../Implement/MemberTypeRepository.cs | 3 +- src/Umbraco.Core/Runtime/CoreRuntime.cs | 5 +- .../Services/Implement/KeyValueService.cs | 6 +- .../Configurations/GlobalSettingsTests.cs | 2 +- .../UmbracoServiceMembershipProviderTests.cs | 14 ++-- .../Routing/RenderRouteHandlerTests.cs | 3 +- .../Runtimes/CoreRuntimeTests.cs | 2 +- src/Umbraco.Web/Install/InstallHelper.cs | 18 +++-- .../InstallSteps/DatabaseConfigureStep.cs | 2 +- .../InstallSteps/DatabaseUpgradeStep.cs | 2 +- .../Install/InstallSteps/NewInstallStep.cs | 2 +- .../InstallSteps/SetUmbracoVersionStep.cs | 8 +- .../InstallSteps/StarterKitDownloadStep.cs | 6 +- .../Providers/MembersMembershipProvider.cs | 7 +- .../Providers/UmbracoMembershipProvider.cs | 8 +- .../Providers/UsersMembershipProvider.cs | 6 +- 44 files changed, 93 insertions(+), 154 deletions(-) delete mode 100644 src/Umbraco.Abstractions/Composing/Current.cs rename src/Umbraco.Abstractions/{DatabaseHelper.cs => ConfigConnectionStringExtensions.cs} (90%) diff --git a/src/Umbraco.Abstractions/Composing/Composition.cs b/src/Umbraco.Abstractions/Composing/Composition.cs index 7ff8901fc1..03c8777e89 100644 --- a/src/Umbraco.Abstractions/Composing/Composition.cs +++ b/src/Umbraco.Abstractions/Composing/Composition.cs @@ -130,6 +130,8 @@ namespace Umbraco.Core.Composing // ReSharper disable once AccessToModifiedClosure -- on purpose _register.Register(_ => factory, Lifetime.Singleton); factory = _register.CreateFactory(); + + Configs.Factory = factory; return factory; } diff --git a/src/Umbraco.Abstractions/Composing/Current.cs b/src/Umbraco.Abstractions/Composing/Current.cs deleted file mode 100644 index a01302f3e3..0000000000 --- a/src/Umbraco.Abstractions/Composing/Current.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using Umbraco.Core.Logging; -using Umbraco.Core.Strings; - -namespace Umbraco.Core.Composing -{ - /// - /// Provides a static service locator for most singletons. - /// - /// - /// This class is initialized with the container in UmbracoApplicationBase, - /// right after the container is created in UmbracoApplicationBase.HandleApplicationStart. - /// Obviously, this is a service locator, which some may consider an anti-pattern. And yet, - /// practically, it works. - /// - public static class CurrentCore - { - private static IFactory _factory; - - private static ILogger _logger; - private static IProfiler _profiler; - private static IProfilingLogger _profilingLogger; - - /// - /// Gets or sets the factory. - /// - public static IFactory Factory - { - get - { - if (_factory == null) throw new InvalidOperationException("No factory has been set."); - return _factory; - } - set - { - if (_factory != null) throw new InvalidOperationException("A factory has already been set."); - // if (_configs != null) throw new InvalidOperationException("Configs are unlocked."); - _factory = value; - } - } - - /// - /// Resets . Indented for testing only, and not supported in production code. - /// - /// - /// For UNIT TESTS exclusively. - /// Resets everything that is 'current'. - /// - public static void Reset() - { - _factory.DisposeIfDisposable(); - _factory = null; - - _logger = null; - _profiler = null; - _profilingLogger = null; - } - public static bool HasFactory => _factory != null; - - #region Getters - - - public static ILogger Logger - => _logger ?? (_logger = _factory?.TryGetInstance() ?? throw new Exception("TODO Fix")); //?? new DebugDiagnosticsLogger(new MessageTemplates())); - - public static IProfiler Profiler - => _profiler ?? (_profiler = _factory?.TryGetInstance() - ?? new LogProfiler(Logger)); - - public static IProfilingLogger ProfilingLogger - => _profilingLogger ?? (_profilingLogger = _factory?.TryGetInstance()) - ?? new ProfilingLogger(Logger, Profiler); - - #endregion - } -} diff --git a/src/Umbraco.Abstractions/DatabaseHelper.cs b/src/Umbraco.Abstractions/ConfigConnectionStringExtensions.cs similarity index 90% rename from src/Umbraco.Abstractions/DatabaseHelper.cs rename to src/Umbraco.Abstractions/ConfigConnectionStringExtensions.cs index 70c2d64774..693b8a433e 100644 --- a/src/Umbraco.Abstractions/DatabaseHelper.cs +++ b/src/Umbraco.Abstractions/ConfigConnectionStringExtensions.cs @@ -1,15 +1,14 @@ using System; using System.IO; using System.Linq; -using Umbraco.Core; using Umbraco.Core.Configuration; namespace Umbraco.Core { - public static class DatabaseHelper + public static class ConfigConnectionStringExtensions { - public static bool IsConnectionStringConfigured(ConfigConnectionString databaseSettings) + public static bool IsConnectionStringConfigured(this ConfigConnectionString databaseSettings) { var dbIsSqlCe = false; if (databaseSettings?.ProviderName != null) diff --git a/src/Umbraco.Abstractions/Configuration/Configs.cs b/src/Umbraco.Abstractions/Configuration/Configs.cs index b2dde785b2..ef6a086af5 100644 --- a/src/Umbraco.Abstractions/Configuration/Configs.cs +++ b/src/Umbraco.Abstractions/Configuration/Configs.cs @@ -15,6 +15,16 @@ namespace Umbraco.Core.Configuration { private readonly Func _configGetter; + public IFactory Factory + { + get => _factory; + set + { + if(!(_factory is null)) throw new InvalidOperationException("Factory cannot be set multiple times"); + _factory = value; + } + } + public Configs(Func configGetter) { _configGetter = configGetter; @@ -22,6 +32,7 @@ namespace Umbraco.Core.Configuration private readonly Dictionary> _configs = new Dictionary>(); private Dictionary> _registerings = new Dictionary>(); + private IFactory _factory; /// /// Gets a configuration. @@ -65,7 +76,7 @@ namespace Umbraco.Core.Configuration _configs[typeOfConfig] = new Lazy(() => { - if (CurrentCore.HasFactory) return CurrentCore.Factory.GetInstance(); + if (!(Factory is null)) return Factory.GetInstance(); throw new InvalidOperationException($"Cannot get configuration of type {typeOfConfig} during composition."); }); _registerings[typeOfConfig] = register => register.Register(configFactory, Lifetime.Singleton); @@ -90,9 +101,7 @@ namespace Umbraco.Core.Configuration { if ((_configGetter(sectionName) is TConfig config)) return config; -// var ex = new ConfigurationErrorsException($"Could not get configuration section \"{sectionName}\" from config files."); - var ex = new Exception($"Could not get configuration section \"{sectionName}\" from config files."); -// Current.Logger.Error(ex, "Config error"); + var ex = new InvalidOperationException($"Could not get configuration section \"{sectionName}\" from config files."); throw ex; } } @@ -114,7 +123,5 @@ namespace Umbraco.Core.Configuration // no need to keep them around _registerings = null; } - - } } diff --git a/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs b/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs index 60aa1035ad..b455e4af21 100644 --- a/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs +++ b/src/Umbraco.Abstractions/Logging/IMessageTemplates.cs @@ -1,7 +1,10 @@ namespace Umbraco.Core.Logging { + /// + /// Provides tools to support message templates. + /// public interface IMessageTemplates { string Render(string messageTemplate, params object[] args); } -} \ No newline at end of file +} diff --git a/src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs b/src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs index 08dffd5975..b15e33019d 100644 --- a/src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs +++ b/src/Umbraco.Configuration/OptionalInnerTextConfigurationElement.cs @@ -4,7 +4,7 @@ /// This is used to supply optional/default values when using InnerTextConfigurationElement /// /// - public class OptionalInnerTextConfigurationElement : InnerTextConfigurationElement + internal class OptionalInnerTextConfigurationElement : InnerTextConfigurationElement { private readonly InnerTextConfigurationElement _wrapped; private readonly T _defaultValue; diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj index 04f8eb14d3..44904fc3f3 100644 --- a/src/Umbraco.Configuration/Umbraco.Configuration.csproj +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -28,6 +28,7 @@ + diff --git a/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs b/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs index 1a939d4c9e..79bff51d05 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/BackOfficeElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class BackOfficeElement : UmbracoConfigurationElement, IBackOfficeSection + internal class BackOfficeElement : UmbracoConfigurationElement, IBackOfficeSection { [ConfigurationProperty("tours")] internal TourConfigElement Tours => (TourConfigElement)this["tours"]; diff --git a/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs b/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs index 3926e700c1..7b62fcc123 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/CharCollection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class CharCollection : ConfigurationElementCollection, IEnumerable + internal class CharCollection : ConfigurationElementCollection, IEnumerable { internal void Add(CharElement c) { diff --git a/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs b/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs index 2971228d9e..1ff63ac017 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/CharElement.cs @@ -1,6 +1,6 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class CharElement : InnerTextConfigurationElement, IChar + internal class CharElement : InnerTextConfigurationElement, IChar { private string _char; private string _replacement; diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs index 1e1ecb4d0c..8e4f0edd8f 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentElement.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Macros; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class ContentElement : UmbracoConfigurationElement, IContentSection + internal class ContentElement : UmbracoConfigurationElement, IContentSection { private const string DefaultPreviewBadge = @"
Preview modeClick to end
"; diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs index da146b14ec..bdbcb27b4c 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentError404Collection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class ContentError404Collection : ConfigurationElementCollection, IEnumerable + internal class ContentError404Collection : ConfigurationElementCollection, IEnumerable { internal void Add(ContentErrorPageElement element) { diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs index 8f5a5b3259..96cea71a8e 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorPageElement.cs @@ -3,7 +3,7 @@ using System.Xml.Linq; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class ContentErrorPageElement : InnerTextConfigurationElement, IContentErrorPage + internal class ContentErrorPageElement : InnerTextConfigurationElement, IContentErrorPage { public ContentErrorPageElement(XElement rawXml) : base(rawXml) diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs index a393267b9d..5b5b54380d 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentErrorsElement.cs @@ -3,7 +3,7 @@ using System.Linq; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class ContentErrorsElement : RawXmlConfigurationElement + internal class ContentErrorsElement : RawXmlConfigurationElement { public IEnumerable Error404Collection diff --git a/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs index 91eb180d08..9a5a9b2a59 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ContentImagingElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class ContentImagingElement : ConfigurationElement + internal class ContentImagingElement : ConfigurationElement { [ConfigurationProperty("imageFileTypes")] diff --git a/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs index 69680251af..0bac9721a3 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillPropertiesCollection.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class ImagingAutoFillPropertiesCollection : ConfigurationElementCollection, IEnumerable + internal class ImagingAutoFillPropertiesCollection : ConfigurationElementCollection, IEnumerable { protected override ConfigurationElement CreateNewElement() diff --git a/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs index ec3dc43caf..9b4c45b5c6 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/ImagingAutoFillUploadFieldElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class ImagingAutoFillUploadFieldElement : UmbracoConfigurationElement, IImagingAutoFillUploadField + internal class ImagingAutoFillUploadFieldElement : UmbracoConfigurationElement, IImagingAutoFillUploadField { /// /// Allow setting internally so we can create a default diff --git a/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs index daa45cf114..106b6cc134 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/LoggingElement.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class LoggingElement : UmbracoConfigurationElement, ILoggingSection + internal class LoggingElement : UmbracoConfigurationElement, ILoggingSection { [ConfigurationProperty("maxLogAge")] diff --git a/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs b/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs index cc76b2cb00..afadff5654 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/NotificationsElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class NotificationsElement : UmbracoConfigurationElement + internal class NotificationsElement : UmbracoConfigurationElement { [ConfigurationProperty("email")] internal InnerTextConfigurationElement NotificationEmailAddress => (InnerTextConfigurationElement)this["email"]; diff --git a/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs b/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs index e5350bf596..80fcb6ca1a 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/RequestHandlerElement.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class RequestHandlerElement : UmbracoConfigurationElement, IRequestHandlerSection + internal class RequestHandlerElement : UmbracoConfigurationElement, IRequestHandlerSection { [ConfigurationProperty("addTrailingSlash")] public InnerTextConfigurationElement AddTrailingSlash => GetOptionalTextElement("addTrailingSlash", true); diff --git a/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs b/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs index 42bafe4bd1..d45a3e7d85 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/SecurityElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class SecurityElement : UmbracoConfigurationElement, ISecuritySection + internal class SecurityElement : UmbracoConfigurationElement, ISecuritySection { [ConfigurationProperty("keepUserLoggedIn")] internal InnerTextConfigurationElement KeepUserLoggedIn => GetOptionalTextElement("keepUserLoggedIn", true); diff --git a/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs b/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs index f62d766d76..dab69f3da0 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/TourConfigElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class TourConfigElement : UmbracoConfigurationElement, ITourSection + internal class TourConfigElement : UmbracoConfigurationElement, ITourSection { //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 ? diff --git a/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs index 30cc33a260..670f620b15 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoConfigurationElement.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings /// /// Base class with shared helper methods /// - public class UmbracoConfigurationElement : ConfigurationElement + internal class UmbracoConfigurationElement : ConfigurationElement { /// /// Used so the RawElement types are not re-created every time they are accessed diff --git a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs index bc91dfd48a..98fdcaff93 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UmbracoSettingsSection.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class UmbracoSettingsSection : ConfigurationSection, IUmbracoSettingsSection + internal class UmbracoSettingsSection : ConfigurationSection, IUmbracoSettingsSection { [ConfigurationProperty("backOffice")] public BackOfficeElement BackOffice => (BackOfficeElement)this["backOffice"]; diff --git a/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs index 45fe2c4294..3e12d106ff 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/UrlReplacingElement.cs @@ -3,7 +3,7 @@ using System.Configuration; namespace Umbraco.Core.Configuration.UmbracoSettings { - public class UrlReplacingElement : ConfigurationElement + internal class UrlReplacingElement : ConfigurationElement { [ConfigurationProperty("removeDoubleDashes", DefaultValue = true)] internal bool RemoveDoubleDashes => (bool) base["removeDoubleDashes"]; diff --git a/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs b/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs index 4c74398e25..7b7102f2e7 100644 --- a/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs +++ b/src/Umbraco.Configuration/UmbracoSettings/WebRoutingElement.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Configuration.UmbracoSettings { - public class WebRoutingElement : ConfigurationElement, IWebRoutingSection + internal class WebRoutingElement : ConfigurationElement, IWebRoutingSection { [ConfigurationProperty("trySkipIisCustomErrors", DefaultValue = "false")] public bool TrySkipIisCustomErrors => (bool) base["trySkipIisCustomErrors"]; diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index e70763d0cc..3661695c54 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -61,7 +61,7 @@ namespace Umbraco.Core.Composing } } - internal static bool HasFactory => _factory != null; + public static bool HasFactory => _factory != null; /// /// Resets . Indented for testing only, and not supported in production code. diff --git a/src/Umbraco.Core/Logging/MessageTemplates.cs b/src/Umbraco.Core/Logging/MessageTemplates.cs index 887aa1402d..4640007e1a 100644 --- a/src/Umbraco.Core/Logging/MessageTemplates.cs +++ b/src/Umbraco.Core/Logging/MessageTemplates.cs @@ -8,9 +8,6 @@ using Serilog.Parsing; namespace Umbraco.Core.Logging { - /// - /// Provides tools to support message templates. - /// public class MessageTemplates : IMessageTemplates { // Umbraco now uses Message Templates (https://messagetemplates.org/) for logging, which means diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/MemberTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/MemberTypeRepository.cs index 741c5922ea..a204ab53d4 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/MemberTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/MemberTypeRepository.cs @@ -225,8 +225,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement if (builtinProperties.ContainsKey(propertyType.Alias)) { //this reset's its current data type reference which will be re-assigned based on the property editor assigned on the next line - var propDefinition = builtinProperties[propertyType.Alias]; - if (propDefinition != null) + if (builtinProperties.TryGetValue(propertyType.Alias, out var propDefinition) && propDefinition != null) { propertyType.DataTypeId = propDefinition.DataTypeId; propertyType.DataTypeKey = propDefinition.DataTypeKey; diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index dc6963109c..6e99cffc60 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -10,7 +10,6 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Exceptions; using Umbraco.Core.IO; using Umbraco.Core.Logging; -using Umbraco.Core.Logging.Serilog; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Sync; @@ -52,7 +51,7 @@ namespace Umbraco.Core.Runtime /// /// Gets the logger. /// - protected ILogger Logger { get; set; } + protected ILogger Logger { get; } /// /// Gets the profiler. @@ -73,7 +72,7 @@ namespace Umbraco.Core.Runtime /// Gets the /// protected IIOHelper IOHelper { get; } - protected Configs Configs { get; set; } + protected Configs Configs { get; } protected IUmbracoVersion UmbracoVersion { get; } /// diff --git a/src/Umbraco.Core/Services/Implement/KeyValueService.cs b/src/Umbraco.Core/Services/Implement/KeyValueService.cs index 57e7c9ba74..d5d8e66525 100644 --- a/src/Umbraco.Core/Services/Implement/KeyValueService.cs +++ b/src/Umbraco.Core/Services/Implement/KeyValueService.cs @@ -15,12 +15,14 @@ namespace Umbraco.Core.Services.Implement private readonly object _initialock = new object(); private readonly IScopeProvider _scopeProvider; private readonly ILogger _logger; + private readonly IUmbracoVersion _umbracoVersion; private bool _initialized; - public KeyValueService(IScopeProvider scopeProvider, ILogger logger) + public KeyValueService(IScopeProvider scopeProvider, ILogger logger, IUmbracoVersion umbracoVersion) { _scopeProvider = scopeProvider; _logger = logger; + _umbracoVersion = umbracoVersion; } private void EnsureInitialized() @@ -40,7 +42,7 @@ namespace Umbraco.Core.Services.Implement // if already running 8, either following an upgrade or an install, // then everything should be ok (the table should exist, etc) - if (Current.UmbracoVersion.LocalVersion != null && Current.UmbracoVersion.LocalVersion.Major >= 8) + if (_umbracoVersion.LocalVersion != null && _umbracoVersion.LocalVersion.Major >= 8) { _initialized = true; return; diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index 52ace63240..65027edc73 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Configurations globalSettingsMock.Setup(x => x.Path).Returns(() => Current.IOHelper.ResolveUrl(path)); Current.IOHelper.Root = rootPath; - Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(Core.IO.IOHelper.Default)); + Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(IOHelper)); } diff --git a/src/Umbraco.Tests/Membership/UmbracoServiceMembershipProviderTests.cs b/src/Umbraco.Tests/Membership/UmbracoServiceMembershipProviderTests.cs index 1c91d8a920..c70f304d66 100644 --- a/src/Umbraco.Tests/Membership/UmbracoServiceMembershipProviderTests.cs +++ b/src/Umbraco.Tests/Membership/UmbracoServiceMembershipProviderTests.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.Membership { var memberTypeServiceMock = new Mock(); memberTypeServiceMock.Setup(x => x.GetDefault()).Returns("Blah"); - var provider = new MembersMembershipProvider(Mock.Of(), memberTypeServiceMock.Object); + var provider = new MembersMembershipProvider(Mock.Of(), memberTypeServiceMock.Object, TestHelper.GetUmbracoVersion()); provider.Initialize("test", new NameValueCollection()); Assert.AreEqual("Blah", provider.DefaultMemberTypeAlias); @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Membership { var memberTypeServiceMock = new Mock(); memberTypeServiceMock.Setup(x => x.GetDefault()).Returns("Blah"); - var provider = new MembersMembershipProvider(Mock.Of(), memberTypeServiceMock.Object); + var provider = new MembersMembershipProvider(Mock.Of(), memberTypeServiceMock.Object, TestHelper.GetUmbracoVersion()); provider.Initialize("test", new NameValueCollection { { "defaultMemberTypeAlias", "Hello" } }); Assert.AreEqual("Hello", provider.DefaultMemberTypeAlias); @@ -48,7 +48,7 @@ namespace Umbraco.Tests.Membership var membershipServiceMock = new Mock(); membershipServiceMock.Setup(service => service.Exists("test")).Returns(true); - var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object); + var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object, TestHelper.GetUmbracoVersion()); provider.Initialize("test", new NameValueCollection()); MembershipCreateStatus status; @@ -65,7 +65,7 @@ namespace Umbraco.Tests.Membership var membershipServiceMock = new Mock(); membershipServiceMock.Setup(service => service.GetByEmail("test@test.com")).Returns(() => new Member("test", MockedContentTypes.CreateSimpleMemberType())); - var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object); + var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object, TestHelper.GetUmbracoVersion()); provider.Initialize("test", new NameValueCollection { { "requiresUniqueEmail", "true" } }); MembershipCreateStatus status; @@ -95,7 +95,7 @@ namespace Umbraco.Tests.Membership createdMember = new Member("test", e, u, p, memberType, isApproved); }) .Returns(() => createdMember); - var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object); + var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object, TestHelper.GetUmbracoVersion()); provider.Initialize("test", new NameValueCollection()); @@ -128,7 +128,7 @@ namespace Umbraco.Tests.Membership }) .Returns(() => createdMember); - var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object); + var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object, TestHelper.GetUmbracoVersion()); provider.Initialize("test", new NameValueCollection { { "passwordFormat", "Encrypted" } }); @@ -162,7 +162,7 @@ namespace Umbraco.Tests.Membership }) .Returns(() => createdMember); - var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object); + var provider = new MembersMembershipProvider(membershipServiceMock.Object, memberTypeServiceMock.Object, TestHelper.GetUmbracoVersion()); provider.Initialize("test", new NameValueCollection { { "passwordFormat", "Hashed" }, { "hashAlgorithmType", "HMACSHA256" } }); diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index be3892dd89..cfc42d3670 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -51,9 +51,8 @@ namespace Umbraco.Tests.Routing public class TestRuntime : WebRuntime { public TestRuntime(UmbracoApplicationBase umbracoApplication, Configs configs, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILogger logger) - : base(umbracoApplication, configs, umbracoVersion, ioHelper, logger) + : base(umbracoApplication, configs, umbracoVersion, ioHelper, Mock.Of()) { - Logger = Mock.Of(); } protected override IProfiler GetProfiler() => Mock.Of(); diff --git a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs index 87e8322708..93c931c93d 100644 --- a/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs +++ b/src/Umbraco.Tests/Runtimes/CoreRuntimeTests.cs @@ -86,7 +86,7 @@ namespace Umbraco.Tests.Runtimes private static Configs GetConfigs() { - var configs = new ConfigsFactory(Umbraco.Core.IO.IOHelper.Default).Create(); + var configs = new ConfigsFactory(IOHelper.Default).Create(); configs.Add(SettingsForTests.GetDefaultGlobalSettings); configs.Add(SettingsForTests.GetDefaultUmbracoSettings); return configs; diff --git a/src/Umbraco.Web/Install/InstallHelper.cs b/src/Umbraco.Web/Install/InstallHelper.cs index 093f3b944b..46efb69124 100644 --- a/src/Umbraco.Web/Install/InstallHelper.cs +++ b/src/Umbraco.Web/Install/InstallHelper.cs @@ -21,15 +21,17 @@ namespace Umbraco.Web.Install private readonly HttpContextBase _httpContext; private readonly ILogger _logger; private readonly IGlobalSettings _globalSettings; + private readonly IUmbracoVersion _umbracoVersion; private InstallationType? _installationType; public InstallHelper(IUmbracoContextAccessor umbracoContextAccessor, DatabaseBuilder databaseBuilder, - ILogger logger, IGlobalSettings globalSettings) + ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion) { _httpContext = umbracoContextAccessor.UmbracoContext.HttpContext; _logger = logger; _globalSettings = globalSettings; + _umbracoVersion = umbracoVersion; _databaseBuilder = databaseBuilder; } @@ -72,10 +74,10 @@ namespace Umbraco.Web.Install IsBrandNewInstall == false, isCompleted, DateTime.Now, - Current.UmbracoVersion.Current.Major, - Current.UmbracoVersion.Current.Minor, - Current.UmbracoVersion.Current.Build, - Current.UmbracoVersion.Comment, + _umbracoVersion.Current.Major, + _umbracoVersion.Current.Minor, + _umbracoVersion.Current.Build, + _umbracoVersion.Comment, errorMsg, userAgent, dbProvider); @@ -112,7 +114,7 @@ namespace Umbraco.Web.Install { var databaseSettings = Current.Configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; if (_globalSettings.ConfigurationStatus.IsNullOrWhiteSpace() - && DatabaseHelper.IsConnectionStringConfigured(databaseSettings) == false) + && databaseSettings.IsConnectionStringConfigured() == false) { //no version or conn string configured, must be a brand new install return true; @@ -120,7 +122,7 @@ namespace Umbraco.Web.Install //now we have to check if this is really a new install, the db might be configured and might contain data - if (DatabaseHelper.IsConnectionStringConfigured(databaseSettings) == false + if (databaseSettings.IsConnectionStringConfigured() == false || _databaseBuilder.IsDatabaseConfigured == false) { return true; @@ -138,7 +140,7 @@ namespace Umbraco.Web.Install var packages = new List(); try { - var requestUri = $"https://our.umbraco.com/webapi/StarterKit/Get/?umbracoVersion={Current.UmbracoVersion.Current}"; + var requestUri = $"https://our.umbraco.com/webapi/StarterKit/Get/?umbracoVersion={_umbracoVersion.Current}"; using (var request = new HttpRequestMessage(HttpMethod.Get, requestUri)) { diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs index c96e11feae..8d1e161811 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseConfigureStep.cs @@ -74,7 +74,7 @@ namespace Umbraco.Web.Install.InstallSteps //If the connection string is already present in web.config we don't need to show the settings page and we jump to installing/upgrading. var databaseSettings = Current.Configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; - if (DatabaseHelper.IsConnectionStringConfigured(databaseSettings)) + if (databaseSettings.IsConnectionStringConfigured()) { try { diff --git a/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs b/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs index 8c6d727fef..4a61ce3a70 100644 --- a/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/DatabaseUpgradeStep.cs @@ -66,7 +66,7 @@ namespace Umbraco.Web.Install.InstallSteps var databaseSettings = Current.Configs.ConnectionStrings()[Constants.System.UmbracoConnectionName]; - if (DatabaseHelper.IsConnectionStringConfigured(databaseSettings)) + if (databaseSettings.IsConnectionStringConfigured()) { // a connection string was present, determine whether this is an install/upgrade // return true (upgrade) if there is an installed version, else false (install) diff --git a/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs index e0a5f29ace..15d14574ed 100644 --- a/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs @@ -139,7 +139,7 @@ namespace Umbraco.Web.Install.InstallSteps // left a version number in there but cleared out their db conn string, in that case, it's really a new install. if (_globalSettings.ConfigurationStatus.IsNullOrWhiteSpace() == false && databaseSettings != null) return false; - if (DatabaseHelper.IsConnectionStringConfigured(databaseSettings) && _databaseBuilder.IsDatabaseConfigured) + if (databaseSettings.IsConnectionStringConfigured() && _databaseBuilder.IsDatabaseConfigured) return _databaseBuilder.HasSomeNonDefaultUser() == false; // In this one case when it's a brand new install and nothing has been configured, make sure the diff --git a/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs b/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs index a5b36d8033..3187953989 100644 --- a/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/SetUmbracoVersionStep.cs @@ -21,15 +21,15 @@ namespace Umbraco.Web.Install.InstallSteps private readonly InstallHelper _installHelper; private readonly IGlobalSettings _globalSettings; private readonly IUserService _userService; - private readonly DistributedCache _distributedCache; + private readonly IUmbracoVersion _umbracoVersion; - public SetUmbracoVersionStep(HttpContextBase httpContext, InstallHelper installHelper, IGlobalSettings globalSettings, IUserService userService, DistributedCache distributedCache) + public SetUmbracoVersionStep(HttpContextBase httpContext, InstallHelper installHelper, IGlobalSettings globalSettings, IUserService userService, IUmbracoVersion umbracoVersion) { _httpContext = httpContext; _installHelper = installHelper; _globalSettings = globalSettings; _userService = userService; - _distributedCache = distributedCache; + _umbracoVersion = umbracoVersion; } public override Task ExecuteAsync(object model) @@ -61,7 +61,7 @@ namespace Umbraco.Web.Install.InstallSteps } // Update configurationStatus - _globalSettings.ConfigurationStatus = Current.UmbracoVersion.SemanticVersion.ToSemanticString(); + _globalSettings.ConfigurationStatus = _umbracoVersion.SemanticVersion.ToSemanticString(); //reports the ended install _installHelper.InstallStatus(true, ""); diff --git a/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs b/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs index 20503316cf..624f5897c7 100644 --- a/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/StarterKitDownloadStep.cs @@ -19,13 +19,15 @@ namespace Umbraco.Web.Install.InstallSteps { private readonly InstallHelper _installHelper; private readonly IUmbracoContextAccessor _umbracoContextAccessor; + private readonly IUmbracoVersion _umbracoVersion; private readonly IContentService _contentService; private readonly IPackagingService _packageService; - public StarterKitDownloadStep(IContentService contentService, IPackagingService packageService, InstallHelper installHelper, IUmbracoContextAccessor umbracoContextAccessor) + public StarterKitDownloadStep(IContentService contentService, IPackagingService packageService, InstallHelper installHelper, IUmbracoContextAccessor umbracoContextAccessor, IUmbracoVersion umbracoVersion) { _installHelper = installHelper; _umbracoContextAccessor = umbracoContextAccessor; + _umbracoVersion = umbracoVersion; _contentService = contentService; _packageService = packageService; } @@ -64,7 +66,7 @@ namespace Umbraco.Web.Install.InstallSteps private async Task<(string packageFile, int packageId)> DownloadPackageFilesAsync(Guid kitGuid) { //Go get the package file from the package repo - var packageFile = await _packageService.FetchPackageFileAsync(kitGuid, Current.UmbracoVersion.Current, _umbracoContextAccessor.UmbracoContext.Security.GetUserId().ResultOr(0)); + var packageFile = await _packageService.FetchPackageFileAsync(kitGuid, _umbracoVersion.Current, _umbracoContextAccessor.UmbracoContext.Security.GetUserId().ResultOr(0)); if (packageFile == null) throw new InvalidOperationException("Could not fetch package file " + kitGuid); //add an entry to the installedPackages.config diff --git a/src/Umbraco.Web/Security/Providers/MembersMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/MembersMembershipProvider.cs index fff16cf314..656b4a4c66 100644 --- a/src/Umbraco.Web/Security/Providers/MembersMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/MembersMembershipProvider.cs @@ -2,6 +2,7 @@ using System.Configuration.Provider; using System.Web.Security; using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Core.Security; using Umbraco.Core.Services; @@ -16,11 +17,11 @@ namespace Umbraco.Web.Security.Providers public class MembersMembershipProvider : UmbracoMembershipProvider, IUmbracoMemberTypeMembershipProvider { public MembersMembershipProvider() - : this(Current.Services.MemberService, Current.Services.MemberTypeService) + : this(Current.Services.MemberService, Current.Services.MemberTypeService, Current.UmbracoVersion) { } - public MembersMembershipProvider(IMembershipMemberService memberService, IMemberTypeService memberTypeService) - : base(memberService) + public MembersMembershipProvider(IMembershipMemberService memberService, IMemberTypeService memberTypeService, IUmbracoVersion umbracoVersion) + : base(memberService, umbracoVersion) { LockPropertyTypeAlias = Constants.Conventions.Member.IsLockedOut; LastLockedOutPropertyTypeAlias = Constants.Conventions.Member.LastLockoutDate; diff --git a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs index 92289f8174..06b221288c 100644 --- a/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs @@ -27,11 +27,13 @@ namespace Umbraco.Web.Security.Providers where T : IMembershipMemberService where TEntity : class, IMembershipUser { + private readonly IUmbracoVersion _umbracoVersion; protected IMembershipMemberService MemberService { get; private set; } - protected UmbracoMembershipProvider(IMembershipMemberService memberService) + protected UmbracoMembershipProvider(IMembershipMemberService memberService, IUmbracoVersion umbracoVersion) { + _umbracoVersion = umbracoVersion; MemberService = memberService; } @@ -355,7 +357,7 @@ namespace Umbraco.Web.Security.Providers // http://issues.umbraco.org/issue/U4-3451 // when upgrading from 7.2 to 7.3 trying to save will throw - if (Current.UmbracoVersion.Current >= new Version(7, 3, 0, 0)) + if (_umbracoVersion.Current >= new Version(7, 3, 0, 0)) MemberService.Save(member, false); } @@ -595,7 +597,7 @@ namespace Umbraco.Web.Security.Providers // for this type of thing (i.e. UpdateLastLogin or similar). // when upgrading from 7.2 to 7.3 trying to save will throw - if (Current.UmbracoVersion.Current >= new Version(7, 3, 0, 0)) + if (_umbracoVersion.Current >= new Version(7, 3, 0, 0)) MemberService.Save(member, false); return new ValidateUserResult diff --git a/src/Umbraco.Web/Security/Providers/UsersMembershipProvider.cs b/src/Umbraco.Web/Security/Providers/UsersMembershipProvider.cs index f3aa5dd838..9d169414bb 100644 --- a/src/Umbraco.Web/Security/Providers/UsersMembershipProvider.cs +++ b/src/Umbraco.Web/Security/Providers/UsersMembershipProvider.cs @@ -21,12 +21,12 @@ namespace Umbraco.Web.Security.Providers { public UsersMembershipProvider() - : this(Current.Services.UserService, Current.Services.MemberTypeService) + : this(Current.Services.UserService, Current.Services.MemberTypeService, Current.UmbracoVersion) { } - public UsersMembershipProvider(IMembershipMemberService memberService, IMemberTypeService memberTypeService) - : base(memberService) + public UsersMembershipProvider(IMembershipMemberService memberService, IMemberTypeService memberTypeService, IUmbracoVersion umbracoVersion) + : base(memberService, umbracoVersion) { _memberTypeService = memberTypeService; } From 6af645db956291fbf02cdf09405edac73515a384 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 18 Nov 2019 14:22:11 +0100 Subject: [PATCH 46/61] AB3594 - removed reference to core from configuration --- src/Umbraco.Configuration/Umbraco.Configuration.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Umbraco.Configuration/Umbraco.Configuration.csproj b/src/Umbraco.Configuration/Umbraco.Configuration.csproj index 44904fc3f3..04f8eb14d3 100644 --- a/src/Umbraco.Configuration/Umbraco.Configuration.csproj +++ b/src/Umbraco.Configuration/Umbraco.Configuration.csproj @@ -28,7 +28,6 @@ - From 21e9d09ff0f6de1af8e1b6c7aa65dc8c3a72826b Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 18 Nov 2019 14:54:16 +0100 Subject: [PATCH 47/61] AB3594 - Fixed tests --- src/Umbraco.Tests/Services/MemberServiceTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/Services/MemberServiceTests.cs b/src/Umbraco.Tests/Services/MemberServiceTests.cs index 57d6b67af8..7bcd3790d4 100644 --- a/src/Umbraco.Tests/Services/MemberServiceTests.cs +++ b/src/Umbraco.Tests/Services/MemberServiceTests.cs @@ -20,6 +20,7 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Tests.LegacyXmlPublishedCache; +using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; using Umbraco.Tests.Testing.Objects.Accessors; @@ -40,7 +41,7 @@ namespace Umbraco.Tests.Services base.SetUp(); // HACK: but we have no choice until we remove the SavePassword method from IMemberService - var providerMock = new Mock(ServiceContext.MemberService, ServiceContext.MemberTypeService) { CallBase = true }; + var providerMock = new Mock(ServiceContext.MemberService, ServiceContext.MemberTypeService, TestHelper.GetUmbracoVersion()) { CallBase = true }; providerMock.Setup(@base => @base.AllowManuallyChangingPassword).Returns(false); providerMock.Setup(@base => @base.PasswordFormat).Returns(MembershipPasswordFormat.Hashed); var provider = providerMock.Object; From 03cb9c0104aeac56493f6c91b6cd632d3ab27090 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 18 Nov 2019 15:17:18 +0100 Subject: [PATCH 48/61] Fixed tests --- src/Umbraco.Abstractions/Models/PropertyGroupCollection.cs | 2 +- src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Abstractions/Models/PropertyGroupCollection.cs b/src/Umbraco.Abstractions/Models/PropertyGroupCollection.cs index c3c1d4b2b4..f5b3012b1a 100644 --- a/src/Umbraco.Abstractions/Models/PropertyGroupCollection.cs +++ b/src/Umbraco.Abstractions/Models/PropertyGroupCollection.cs @@ -68,7 +68,7 @@ namespace Umbraco.Core.Models OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } - internal new void Add(PropertyGroup item) + public new void Add(PropertyGroup item) { try { diff --git a/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs b/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs index 3052bdfd23..5d60241a9c 100644 --- a/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs +++ b/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs @@ -84,7 +84,7 @@ namespace Umbraco.Core.Models } // TODO: Instead of 'new' this should explicitly implement one of the collection interfaces members - internal new void Add(IPropertyType item) + public new void Add(IPropertyType item) { item.SupportsPublishing = SupportsPublishing; From 2c18dbffebbabad5a5a80fc2ccb24de0441899ea Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 18 Nov 2019 15:29:04 +0100 Subject: [PATCH 49/61] Clean up --- src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs | 1 - src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs b/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs index f9844bf65b..57a8a581f0 100644 --- a/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs +++ b/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.ComponentModel; namespace Umbraco.Core.Models.Entities { diff --git a/src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs b/src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs index 05197a7d2d..e679b98b93 100644 --- a/src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs +++ b/src/Umbraco.Abstractions/Models/Entities/IRememberBeingDirty.cs @@ -36,7 +36,5 @@ namespace Umbraco.Core.Models.Entities /// Gets properties that were dirty. /// IEnumerable GetWereDirtyProperties(); - - } } From 8f48df66d5a371aaa49576b13a32e2c10974510f Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 11:16:07 +1100 Subject: [PATCH 50/61] Refactors Configs and how it acquires a factory, re-internalizes Umbraco.Configuration classes --- .../Composing/Composition.cs | 6 +++--- .../Configuration/Configs.cs | 18 +++++------------- .../CommaDelimitedConfigurationElement.cs | 2 +- .../InnerTextConfigurationElement.cs | 2 +- ...tionalCommaDelimitedConfigurationElement.cs | 2 +- .../RawXmlConfigurationElement.cs | 2 +- 6 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Abstractions/Composing/Composition.cs b/src/Umbraco.Abstractions/Composing/Composition.cs index 03c8777e89..8cf02151e8 100644 --- a/src/Umbraco.Abstractions/Composing/Composition.cs +++ b/src/Umbraco.Abstractions/Composing/Composition.cs @@ -124,14 +124,14 @@ namespace Umbraco.Core.Composing builder.RegisterWith(_register); _builders.Clear(); // no point keep them around - Configs.RegisterWith(_register); - IFactory factory = null; + + Configs.RegisterWith(_register, () => factory); + // ReSharper disable once AccessToModifiedClosure -- on purpose _register.Register(_ => factory, Lifetime.Singleton); factory = _register.CreateFactory(); - Configs.Factory = factory; return factory; } diff --git a/src/Umbraco.Abstractions/Configuration/Configs.cs b/src/Umbraco.Abstractions/Configuration/Configs.cs index ef6a086af5..66980d83a6 100644 --- a/src/Umbraco.Abstractions/Configuration/Configs.cs +++ b/src/Umbraco.Abstractions/Configuration/Configs.cs @@ -15,16 +15,6 @@ namespace Umbraco.Core.Configuration { private readonly Func _configGetter; - public IFactory Factory - { - get => _factory; - set - { - if(!(_factory is null)) throw new InvalidOperationException("Factory cannot be set multiple times"); - _factory = value; - } - } - public Configs(Func configGetter) { _configGetter = configGetter; @@ -32,7 +22,7 @@ namespace Umbraco.Core.Configuration private readonly Dictionary> _configs = new Dictionary>(); private Dictionary> _registerings = new Dictionary>(); - private IFactory _factory; + private Lazy _factory; /// /// Gets a configuration. @@ -76,7 +66,7 @@ namespace Umbraco.Core.Configuration _configs[typeOfConfig] = new Lazy(() => { - if (!(Factory is null)) return Factory.GetInstance(); + if (!(_factory is null)) return _factory.Value.GetInstance(); throw new InvalidOperationException($"Cannot get configuration of type {typeOfConfig} during composition."); }); _registerings[typeOfConfig] = register => register.Register(configFactory, Lifetime.Singleton); @@ -109,12 +99,14 @@ namespace Umbraco.Core.Configuration /// /// Registers configurations in a register. /// - public void RegisterWith(IRegister register) + public void RegisterWith(IRegister register, Func factory) { // do it only once if (_registerings == null) throw new InvalidOperationException("Configurations have already been registered."); + _factory = new Lazy(factory); + register.Register(this); foreach (var registering in _registerings.Values) diff --git a/src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs b/src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs index 00dde5f206..3ced2fab46 100644 --- a/src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs +++ b/src/Umbraco.Configuration/CommaDelimitedConfigurationElement.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Configuration /// /// Defines a configuration section that contains inner text that is comma delimited /// - public class CommaDelimitedConfigurationElement : InnerTextConfigurationElement, IEnumerable + internal class CommaDelimitedConfigurationElement : InnerTextConfigurationElement, IEnumerable { public override CommaDelimitedStringCollection Value { diff --git a/src/Umbraco.Configuration/InnerTextConfigurationElement.cs b/src/Umbraco.Configuration/InnerTextConfigurationElement.cs index 3ff0c4d735..6a125f2c1b 100644 --- a/src/Umbraco.Configuration/InnerTextConfigurationElement.cs +++ b/src/Umbraco.Configuration/InnerTextConfigurationElement.cs @@ -9,7 +9,7 @@ namespace Umbraco.Core.Configuration /// {element}MyValue{/element} instead of as attribute values. /// /// - public class InnerTextConfigurationElement : RawXmlConfigurationElement + internal class InnerTextConfigurationElement : RawXmlConfigurationElement { public InnerTextConfigurationElement() { diff --git a/src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs b/src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs index b6771f98b0..610067d2db 100644 --- a/src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs +++ b/src/Umbraco.Configuration/OptionalCommaDelimitedConfigurationElement.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration /// /// Used for specifying default values for comma delimited config /// - public class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement + internal class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement { private readonly CommaDelimitedConfigurationElement _wrapped; private readonly string[] _defaultValue; diff --git a/src/Umbraco.Configuration/RawXmlConfigurationElement.cs b/src/Umbraco.Configuration/RawXmlConfigurationElement.cs index d7f0ed0332..5bc6ad3d32 100644 --- a/src/Umbraco.Configuration/RawXmlConfigurationElement.cs +++ b/src/Umbraco.Configuration/RawXmlConfigurationElement.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Configuration /// A configuration section that simply exposes the entire raw xml of the section itself which inheritors can use /// to do with as they please. /// - public abstract class RawXmlConfigurationElement : ConfigurationElement + internal abstract class RawXmlConfigurationElement : ConfigurationElement { protected RawXmlConfigurationElement() { From f71a54ec8f80a1a6be14a9d64da78033adc33b63 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 11:45:21 +1100 Subject: [PATCH 51/61] Adds some comments and fixme --- src/Umbraco.Abstractions/Configuration/Configs.cs | 8 ++++---- src/Umbraco.Abstractions/Configuration/ICoreDebug.cs | 11 ++++++++++- .../Configuration/IGlobalSettings.cs | 3 +++ src/Umbraco.Configuration/CoreDebug.cs | 6 ++---- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Abstractions/Configuration/Configs.cs b/src/Umbraco.Abstractions/Configuration/Configs.cs index 66980d83a6..abb06d525f 100644 --- a/src/Umbraco.Abstractions/Configuration/Configs.cs +++ b/src/Umbraco.Abstractions/Configuration/Configs.cs @@ -13,11 +13,11 @@ namespace Umbraco.Core.Configuration /// public class Configs { - private readonly Func _configGetter; + private readonly Func _configSectionResolver; - public Configs(Func configGetter) + public Configs(Func configSectionResolver) { - _configGetter = configGetter; + _configSectionResolver = configSectionResolver ?? throw new ArgumentNullException(nameof(configSectionResolver)); } private readonly Dictionary> _configs = new Dictionary>(); @@ -89,7 +89,7 @@ namespace Umbraco.Core.Configuration using (new SafeCallContext()) { - if ((_configGetter(sectionName) is TConfig config)) + if ((_configSectionResolver(sectionName) is TConfig config)) return config; var ex = new InvalidOperationException($"Could not get configuration section \"{sectionName}\" from config files."); throw ex; diff --git a/src/Umbraco.Abstractions/Configuration/ICoreDebug.cs b/src/Umbraco.Abstractions/Configuration/ICoreDebug.cs index 41476f4920..4ff2a1a300 100644 --- a/src/Umbraco.Abstractions/Configuration/ICoreDebug.cs +++ b/src/Umbraco.Abstractions/Configuration/ICoreDebug.cs @@ -2,7 +2,16 @@ namespace Umbraco.Core.Configuration { public interface ICoreDebug { + /// + /// When set to true, Scope logs the stack trace for any scope that gets disposed without being completed. + /// this helps troubleshooting rogue scopes that we forget to complete + /// bool LogUncompletedScopes { get; } + + /// + /// When set to true, the Logger creates a mini dump of w3wp in ~/App_Data/MiniDump whenever it logs + /// an error due to a ThreadAbortException that is due to a timeout. + /// bool DumpOnTimeoutThreadAbort { get; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Abstractions/Configuration/IGlobalSettings.cs b/src/Umbraco.Abstractions/Configuration/IGlobalSettings.cs index 077f853a97..da8b8cd373 100644 --- a/src/Umbraco.Abstractions/Configuration/IGlobalSettings.cs +++ b/src/Umbraco.Abstractions/Configuration/IGlobalSettings.cs @@ -5,6 +5,9 @@ /// public interface IGlobalSettings { + // fixme: Review this class, it is now just a dumping ground for config options (based basically on whatever might be in appSettings), + // our config classes should be named according to what they are configuring. + /// /// Gets the reserved urls from web.config. /// diff --git a/src/Umbraco.Configuration/CoreDebug.cs b/src/Umbraco.Configuration/CoreDebug.cs index 43238b2980..0ff3274565 100644 --- a/src/Umbraco.Configuration/CoreDebug.cs +++ b/src/Umbraco.Configuration/CoreDebug.cs @@ -12,12 +12,10 @@ namespace Umbraco.Core.Configuration DumpOnTimeoutThreadAbort = string.Equals("true", appSettings[Constants.AppSettings.Debug.DumpOnTimeoutThreadAbort], StringComparison.OrdinalIgnoreCase); } - // when true, Scope logs the stack trace for any scope that gets disposed without being completed. - // this helps troubleshooting rogue scopes that we forget to complete + /// public bool LogUncompletedScopes { get; } - // when true, the Logger creates a mini dump of w3wp in ~/App_Data/MiniDump whenever it logs - // an error due to a ThreadAbortException that is due to a timeout. + /// public bool DumpOnTimeoutThreadAbort { get; } } } From 31f51516d2e750095065f76b87cd6d4a7ad09d4f Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 11:53:05 +1100 Subject: [PATCH 52/61] removes old config transforms for v7 -> v8 no longer needed --- src/Umbraco.Web.UI/web.Template.Debug.config | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Umbraco.Web.UI/web.Template.Debug.config b/src/Umbraco.Web.UI/web.Template.Debug.config index ad76664924..c7c662a184 100644 --- a/src/Umbraco.Web.UI/web.Template.Debug.config +++ b/src/Umbraco.Web.UI/web.Template.Debug.config @@ -13,14 +13,6 @@ file everytime Umbraco builds. --> - -
-
- - - - - From ba35afa49415b221df026ef9aa97f086e1c01741 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 12:17:42 +1100 Subject: [PATCH 53/61] re, re, re-fixes the merge issues with this stupid csproj file, hopefully it now merges upwards properly. --- src/Umbraco.Core/Umbraco.Core.csproj | 807 ++++++++++----------------- 1 file changed, 306 insertions(+), 501 deletions(-) diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 0ac579b2cd..49011993e3 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -127,65 +127,30 @@ --> + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -193,21 +158,17 @@ - - - - - - - - - + + + + + @@ -237,26 +198,25 @@ - - + + + + - - - @@ -289,356 +249,76 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -649,53 +329,145 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - @@ -708,14 +480,11 @@ - - - @@ -733,10 +502,8 @@ - - @@ -769,16 +536,13 @@ - - - - + @@ -791,7 +555,6 @@ - @@ -808,10 +571,7 @@ - - - @@ -837,13 +597,121 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -860,38 +728,33 @@ - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + + + - @@ -909,8 +772,8 @@ - + @@ -921,10 +784,8 @@ - + - - @@ -939,48 +800,21 @@ - - - Properties\SolutionInfo.cs - - - - + + - - - - - - - - - - - - - - - - - - - - - + - - @@ -995,17 +829,9 @@ - - - - - - - - @@ -1036,41 +862,26 @@ - - + - - - - - - - - - - - - - - - - - + + + @@ -1104,34 +915,34 @@ + - - - - - - - - - - - - - + + + - - - + + Component + + + Properties\SolutionInfo.cs + + + + + + + @@ -1139,11 +950,5 @@ Umbraco.Abstractions - - - - - - \ No newline at end of file From 9f5479d6861d2a2bfe63b386c669d828b435ad08 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 12:28:41 +1100 Subject: [PATCH 54/61] Cleans up interface inheritance a bit --- src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs | 6 ++++++ src/Umbraco.Abstractions/Models/Entities/IEntity.cs | 2 ++ src/Umbraco.Abstractions/Models/IPropertyType.cs | 4 +--- .../Models/Membership/ContentPermissionSet.cs | 4 +++- src/Umbraco.Core/Models/PropertyType.cs | 8 -------- src/Umbraco.Core/Models/SimpleContentType.cs | 1 + src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs | 2 +- src/Umbraco.Tests/Models/Collections/Item.cs | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs index 77611ebc3d..c25f6b533e 100644 --- a/src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs +++ b/src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs @@ -181,6 +181,12 @@ namespace Umbraco.Core.Models.Entities throw new WontImplementException(); } + public void ResetIdentity() + { + Id = default; + Key = Guid.Empty; + } + #endregion } } diff --git a/src/Umbraco.Abstractions/Models/Entities/IEntity.cs b/src/Umbraco.Abstractions/Models/Entities/IEntity.cs index 0b060e4dbd..7aafcbeccb 100644 --- a/src/Umbraco.Abstractions/Models/Entities/IEntity.cs +++ b/src/Umbraco.Abstractions/Models/Entities/IEntity.cs @@ -41,5 +41,7 @@ namespace Umbraco.Core.Models.Entities /// Gets a value indicating whether the entity has an identity. /// bool HasIdentity { get; } + + void ResetIdentity(); } } diff --git a/src/Umbraco.Abstractions/Models/IPropertyType.cs b/src/Umbraco.Abstractions/Models/IPropertyType.cs index c331590065..ca288ad0b2 100644 --- a/src/Umbraco.Abstractions/Models/IPropertyType.cs +++ b/src/Umbraco.Abstractions/Models/IPropertyType.cs @@ -85,8 +85,6 @@ namespace Umbraco.Core.Models /// object ConvertAssignedValue(object value); - event PropertyChangedEventHandler PropertyChanged; - void ResetIdentity(); - IProperty CreateProperty(); + event PropertyChangedEventHandler PropertyChanged; } } diff --git a/src/Umbraco.Abstractions/Models/Membership/ContentPermissionSet.cs b/src/Umbraco.Abstractions/Models/Membership/ContentPermissionSet.cs index f683db2830..fcf1228e69 100644 --- a/src/Umbraco.Abstractions/Models/Membership/ContentPermissionSet.cs +++ b/src/Umbraco.Abstractions/Models/Membership/ContentPermissionSet.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Models.Membership /// Represents an -> user group & permission key value pair collection /// /// - /// This implements purely so it can be used with the repository layer which is why it's explicitly implemented. + /// This implements purely so it can be used with the repository layer which is why it's explicitly implemented. /// public class ContentPermissionSet : EntityPermissionSet, IEntity { @@ -37,6 +37,8 @@ namespace Umbraco.Core.Models.Membership get { return EntityId > 0; } } + void IEntity.ResetIdentity() => throw new InvalidOperationException($"Resetting identity on {nameof(ContentPermissionSet)} is invalid"); + Guid IEntity.Key { get; set; } DateTime IEntity.CreateDate { get; set; } diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index e8c6b088c5..2848caf791 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -210,14 +210,6 @@ namespace Umbraco.Core.Models return Variations.ValidateVariation(culture, segment, true, wildcards, false); } - /// - /// Creates a new property of this property type. - /// - public IProperty CreateProperty() - { - return new Property(this); - } - /// /// Determines whether a value is of the expected type for this property type. /// diff --git a/src/Umbraco.Core/Models/SimpleContentType.cs b/src/Umbraco.Core/Models/SimpleContentType.cs index fc84d15529..e3fde764cb 100644 --- a/src/Umbraco.Core/Models/SimpleContentType.cs +++ b/src/Umbraco.Core/Models/SimpleContentType.cs @@ -110,6 +110,7 @@ namespace Umbraco.Core.Models string ITreeEntity.Name { get => this.Name; set => throw new NotImplementedException(); } int IEntity.Id { get => this.Id; set => throw new NotImplementedException(); } bool IEntity.HasIdentity => this.Id != default; + void IEntity.ResetIdentity() => throw new NotImplementedException(); int ITreeEntity.CreatorId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } int ITreeEntity.ParentId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } int ITreeEntity.Level { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs index 527c4e59bf..e92c379f07 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs @@ -16,7 +16,7 @@ namespace Umbraco.Core.Persistence.Factories foreach (var propertyType in propertyTypes) { - var property = propertyType.CreateProperty(); + var property = new Property(propertyType); try { diff --git a/src/Umbraco.Tests/Models/Collections/Item.cs b/src/Umbraco.Tests/Models/Collections/Item.cs index 7c7f207aa2..38cf8ecb4b 100644 --- a/src/Umbraco.Tests/Models/Collections/Item.cs +++ b/src/Umbraco.Tests/Models/Collections/Item.cs @@ -93,7 +93,7 @@ namespace Umbraco.Tests.Models.Collections PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyInfo.Name)); } - internal virtual void ResetIdentity() + public virtual void ResetIdentity() { _hasIdentity = false; _id = default(int); From 645cfcab424e490dfd3abeecb2b3eb43c8012889 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 14:10:08 +1100 Subject: [PATCH 55/61] Simplifies the interface inheritance removes SimpleContentTypeMapper (can't be used), improves how mappers are looked up, simplifies other models --- .../Collections/DeepCloneableList.cs | 5 ++ .../Models/Entities/EntitySlim.cs | 65 +------------------ .../Models/Entities/ICanBeDirty.cs | 3 + .../Models/Entities/IUmbracoEntity.cs | 3 +- .../Models/IContentBase.cs | 2 +- .../Models/IContentTypeBase.cs | 2 +- src/Umbraco.Abstractions/Models/IDataType.cs | 2 +- .../Models/IDictionaryTranslation.cs | 2 +- src/Umbraco.Abstractions/Models/IFile.cs | 2 +- .../Models/IPropertyType.cs | 2 - .../Models/ISimpleContentType.cs | 9 +-- .../Models/IStylesheet.cs | 2 +- .../Models/MacroProperty.cs | 2 +- .../Models/ContentTypeBaseExtensions.cs | 7 +- .../Models/Identity/BackOfficeIdentityUser.cs | 14 ++++ src/Umbraco.Core/Models/SimpleContentType.cs | 47 +------------- .../Persistence/Mappers/IMapperCollection.cs | 1 + .../Persistence/Mappers/MapperCollection.cs | 41 ++++++++---- .../Mappers/SimpleContentTypeMapper.cs | 37 ----------- .../Querying/ModelToSqlExpressionVisitor.cs | 5 +- ...peServiceBaseOfTRepositoryTItemTService.cs | 7 +- src/Umbraco.Core/Umbraco.Core.csproj | 1 - 22 files changed, 75 insertions(+), 186 deletions(-) delete mode 100644 src/Umbraco.Core/Persistence/Mappers/SimpleContentTypeMapper.cs diff --git a/src/Umbraco.Abstractions/Collections/DeepCloneableList.cs b/src/Umbraco.Abstractions/Collections/DeepCloneableList.cs index cc57b96f1b..b682e20358 100644 --- a/src/Umbraco.Abstractions/Collections/DeepCloneableList.cs +++ b/src/Umbraco.Abstractions/Collections/DeepCloneableList.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -80,6 +81,7 @@ namespace Umbraco.Core.Collections } } + #region IRememberBeingDirty public bool IsDirty() { return this.OfType().Any(x => x.IsDirty()); @@ -150,5 +152,8 @@ namespace Umbraco.Core.Collections { return Enumerable.Empty(); } + + public event PropertyChangedEventHandler PropertyChanged; // noop + #endregion } } diff --git a/src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs b/src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs index c25f6b533e..b6983773b1 100644 --- a/src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs +++ b/src/Umbraco.Abstractions/Models/Entities/EntitySlim.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Runtime.Serialization; using Umbraco.Core.Exceptions; @@ -23,7 +24,7 @@ namespace Umbraco.Core.Models.Entities /// Gets an entity representing "root". /// public static readonly IEntitySlim Root = new EntitySlim { Path = "-1", Name = "root", HasChildren = true }; - + // implement IEntity /// @@ -121,72 +122,10 @@ namespace Umbraco.Core.Models.Entities #endregion - #region IRememberBeingDirty - - // IEntitySlim does *not* track changes, but since it indirectly implements IUmbracoEntity, - // and therefore IRememberBeingDirty, we have to have those methods - which all throw. - - public bool IsDirty() - { - throw new WontImplementException(); - } - - public bool IsPropertyDirty(string propName) - { - throw new WontImplementException(); - } - - public IEnumerable GetDirtyProperties() - { - throw new WontImplementException(); - } - - public void ResetDirtyProperties() - { - throw new WontImplementException(); - } - - public void DisableChangeTracking() - { - // noop - } - - public void EnableChangeTracking() - { - // noop - } - - public bool WasDirty() - { - throw new WontImplementException(); - } - - public bool WasPropertyDirty(string propertyName) - { - throw new WontImplementException(); - } - - public void ResetWereDirtyProperties() - { - throw new WontImplementException(); - } - - public void ResetDirtyProperties(bool rememberDirty) - { - throw new WontImplementException(); - } - - public IEnumerable GetWereDirtyProperties() - { - throw new WontImplementException(); - } - public void ResetIdentity() { Id = default; Key = Guid.Empty; } - - #endregion } } diff --git a/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs b/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs index 57a8a581f0..03e2f19c70 100644 --- a/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs +++ b/src/Umbraco.Abstractions/Models/Entities/ICanBeDirty.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel; namespace Umbraco.Core.Models.Entities { @@ -36,5 +37,7 @@ namespace Umbraco.Core.Models.Entities /// Enables change tracking. /// void EnableChangeTracking(); + + event PropertyChangedEventHandler PropertyChanged; } } diff --git a/src/Umbraco.Abstractions/Models/Entities/IUmbracoEntity.cs b/src/Umbraco.Abstractions/Models/Entities/IUmbracoEntity.cs index e5f628b098..f76ec2438a 100644 --- a/src/Umbraco.Abstractions/Models/Entities/IUmbracoEntity.cs +++ b/src/Umbraco.Abstractions/Models/Entities/IUmbracoEntity.cs @@ -2,6 +2,7 @@ namespace Umbraco.Core.Models.Entities { + /// /// Represents an entity that can be managed by the entity service. /// @@ -10,6 +11,6 @@ namespace Umbraco.Core.Models.Entities /// IUmbracoEntities can be retrieved with the IEntityService. /// An IUmbracoEntity can participate in notifications. /// - public interface IUmbracoEntity : ITreeEntity, IRememberBeingDirty + public interface IUmbracoEntity : ITreeEntity { } } diff --git a/src/Umbraco.Abstractions/Models/IContentBase.cs b/src/Umbraco.Abstractions/Models/IContentBase.cs index 1864996379..1aade803b8 100644 --- a/src/Umbraco.Abstractions/Models/IContentBase.cs +++ b/src/Umbraco.Abstractions/Models/IContentBase.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models /// Content items are documents, medias and members. /// Content items have a content type, and properties. /// - public interface IContentBase : IUmbracoEntity + public interface IContentBase : IUmbracoEntity, IRememberBeingDirty { /// /// Integer Id of the default ContentType diff --git a/src/Umbraco.Abstractions/Models/IContentTypeBase.cs b/src/Umbraco.Abstractions/Models/IContentTypeBase.cs index 03ea0b5427..d65e2dcdfb 100644 --- a/src/Umbraco.Abstractions/Models/IContentTypeBase.cs +++ b/src/Umbraco.Abstractions/Models/IContentTypeBase.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Models /// Defines the base for a ContentType with properties that /// are shared between ContentTypes and MediaTypes. /// - public interface IContentTypeBase : IUmbracoEntity + public interface IContentTypeBase : IUmbracoEntity, IRememberBeingDirty { /// /// Gets or Sets the Alias of the ContentType diff --git a/src/Umbraco.Abstractions/Models/IDataType.cs b/src/Umbraco.Abstractions/Models/IDataType.cs index c7e682e4a2..39278abdc1 100644 --- a/src/Umbraco.Abstractions/Models/IDataType.cs +++ b/src/Umbraco.Abstractions/Models/IDataType.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Models /// /// Represents a data type. /// - public interface IDataType : IUmbracoEntity + public interface IDataType : IUmbracoEntity, IRememberBeingDirty { /// /// Gets or sets the property editor. diff --git a/src/Umbraco.Abstractions/Models/IDictionaryTranslation.cs b/src/Umbraco.Abstractions/Models/IDictionaryTranslation.cs index 5cbec40b81..8510e5c520 100644 --- a/src/Umbraco.Abstractions/Models/IDictionaryTranslation.cs +++ b/src/Umbraco.Abstractions/Models/IDictionaryTranslation.cs @@ -3,7 +3,7 @@ using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models { - public interface IDictionaryTranslation : IEntity + public interface IDictionaryTranslation : IEntity, IRememberBeingDirty { /// /// Gets or sets the for the translation diff --git a/src/Umbraco.Abstractions/Models/IFile.cs b/src/Umbraco.Abstractions/Models/IFile.cs index 0d98c90ffb..835c9bf434 100644 --- a/src/Umbraco.Abstractions/Models/IFile.cs +++ b/src/Umbraco.Abstractions/Models/IFile.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Models /// Defines a File /// /// Used for Scripts, Stylesheets and Templates - public interface IFile : IEntity + public interface IFile : IEntity, IRememberBeingDirty { /// /// Gets the Name of the File including extension diff --git a/src/Umbraco.Abstractions/Models/IPropertyType.cs b/src/Umbraco.Abstractions/Models/IPropertyType.cs index ca288ad0b2..7c455d3ba5 100644 --- a/src/Umbraco.Abstractions/Models/IPropertyType.cs +++ b/src/Umbraco.Abstractions/Models/IPropertyType.cs @@ -84,7 +84,5 @@ namespace Umbraco.Core.Models /// Throws if the value cannot be converted. /// object ConvertAssignedValue(object value); - - event PropertyChangedEventHandler PropertyChanged; } } diff --git a/src/Umbraco.Abstractions/Models/ISimpleContentType.cs b/src/Umbraco.Abstractions/Models/ISimpleContentType.cs index 740db8e73f..52364cfa1e 100644 --- a/src/Umbraco.Abstractions/Models/ISimpleContentType.cs +++ b/src/Umbraco.Abstractions/Models/ISimpleContentType.cs @@ -1,14 +1,15 @@ -using Umbraco.Core.Models.Entities; +using System; namespace Umbraco.Core.Models { /// /// Represents a simplified view of a content type. /// - public interface ISimpleContentType : IUmbracoEntity + public interface ISimpleContentType { - new int Id { get; } - new string Name { get; } + int Id { get; } + Guid Key { get; } + string Name { get; } /// /// Gets the alias of the content type. diff --git a/src/Umbraco.Abstractions/Models/IStylesheet.cs b/src/Umbraco.Abstractions/Models/IStylesheet.cs index 737118d646..bc2d870ea4 100644 --- a/src/Umbraco.Abstractions/Models/IStylesheet.cs +++ b/src/Umbraco.Abstractions/Models/IStylesheet.cs @@ -3,7 +3,7 @@ using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models { - public interface IStylesheet : IFile, IRememberBeingDirty + public interface IStylesheet : IFile { /// /// Returns a list of umbraco back office enabled stylesheet properties diff --git a/src/Umbraco.Abstractions/Models/MacroProperty.cs b/src/Umbraco.Abstractions/Models/MacroProperty.cs index 9dfb81cf71..6714baf17b 100644 --- a/src/Umbraco.Abstractions/Models/MacroProperty.cs +++ b/src/Umbraco.Abstractions/Models/MacroProperty.cs @@ -9,7 +9,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class MacroProperty : BeingDirtyBase, IMacroProperty, IRememberBeingDirty, IDeepCloneable + public class MacroProperty : BeingDirtyBase, IMacroProperty { public MacroProperty() { diff --git a/src/Umbraco.Core/Models/ContentTypeBaseExtensions.cs b/src/Umbraco.Core/Models/ContentTypeBaseExtensions.cs index 51c642c20d..121fb7a5d1 100644 --- a/src/Umbraco.Core/Models/ContentTypeBaseExtensions.cs +++ b/src/Umbraco.Core/Models/ContentTypeBaseExtensions.cs @@ -44,16 +44,13 @@ namespace Umbraco.Core.Models // property variation change? var hasAnyPropertyVariationChanged = contentType.PropertyTypes.Any(propertyType => { - if (!(propertyType is IRememberBeingDirty dirtyProperty)) - throw new Exception("oops"); - // skip new properties // TODO: This used to be WasPropertyDirty("HasIdentity") but i don't think that actually worked for detecting new entities this does seem to work properly - var isNewProperty = dirtyProperty.WasPropertyDirty("Id"); + var isNewProperty = propertyType.WasPropertyDirty("Id"); if (isNewProperty) return false; // variation change? - var dirty = dirtyProperty.WasPropertyDirty("Variations"); + var dirty = propertyType.WasPropertyDirty("Variations"); if (dirty) a.Add(propertyType.Alias); diff --git a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs index 8dc056d555..7e42a526b0 100644 --- a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs +++ b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; +using System.ComponentModel; using System.Linq; using Umbraco.Core.Composing; using Umbraco.Core.Models.Entities; @@ -403,6 +404,18 @@ namespace Umbraco.Core.Models.Identity _beingDirty.EnableChangeTracking(); } + public event PropertyChangedEventHandler PropertyChanged + { + add + { + _beingDirty.PropertyChanged += value; + } + remove + { + _beingDirty.PropertyChanged -= value; + } + } + #endregion //Custom comparer for enumerables @@ -413,5 +426,6 @@ namespace Umbraco.Core.Models.Identity private static readonly DelegateEqualityComparer StartIdsComparer = new DelegateEqualityComparer( (groups, enumerable) => groups.UnsortedSequenceEqual(enumerable), groups => groups.GetHashCode()); + } } diff --git a/src/Umbraco.Core/Models/SimpleContentType.cs b/src/Umbraco.Core/Models/SimpleContentType.cs index e3fde764cb..dde8450d90 100644 --- a/src/Umbraco.Core/Models/SimpleContentType.cs +++ b/src/Umbraco.Core/Models/SimpleContentType.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using Umbraco.Core.Models.Entities; namespace Umbraco.Core.Models { @@ -37,6 +35,7 @@ namespace Umbraco.Core.Models if (contentType == null) throw new ArgumentNullException(nameof(contentType)); Id = contentType.Id; + Key = contentType.Key; Alias = contentType.Alias; Variations = contentType.Variations; Icon = contentType.Icon; @@ -46,32 +45,26 @@ namespace Umbraco.Core.Models IsElement = contentType.IsElement; } - /// public string Alias { get; } public int Id { get; } - /// + public Guid Key { get; } + public ITemplate DefaultTemplate { get; } - /// public ContentVariation Variations { get; } - /// public string Icon { get; } - /// public bool IsContainer { get; } public string Name { get; } - /// public bool AllowedAsRoot { get; } - /// public bool IsElement { get; } - /// public bool SupportsPropertyVariation(string culture, string segment, bool wildcards = false) { // non-exact validation: can accept a 'null' culture if the property type varies @@ -85,7 +78,6 @@ namespace Umbraco.Core.Models return string.Equals(Alias, other.Alias) && Id == other.Id; } - /// public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; @@ -94,7 +86,6 @@ namespace Umbraco.Core.Models return Equals((SimpleContentType) obj); } - /// public override int GetHashCode() { unchecked @@ -102,37 +93,5 @@ namespace Umbraco.Core.Models return ((Alias != null ? Alias.GetHashCode() : 0) * 397) ^ Id; } } - - // we have to have all this, because we're an IUmbracoEntity, because that is - // required by the query expression visitor / SimpleContentTypeMapper - // TODO: Make the query expression visitor use a different common interface, or investigate removing IRememberBeingDirty from being a requirement on that interface and expliclty checking for that throughout the code? - - string ITreeEntity.Name { get => this.Name; set => throw new NotImplementedException(); } - int IEntity.Id { get => this.Id; set => throw new NotImplementedException(); } - bool IEntity.HasIdentity => this.Id != default; - void IEntity.ResetIdentity() => throw new NotImplementedException(); - int ITreeEntity.CreatorId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - int ITreeEntity.ParentId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - int ITreeEntity.Level { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - string ITreeEntity.Path { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - int ITreeEntity.SortOrder { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - bool ITreeEntity.Trashed => throw new NotImplementedException(); - Guid IEntity.Key { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - DateTime IEntity.CreateDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - DateTime IEntity.UpdateDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - DateTime? IEntity.DeleteDate { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - void ITreeEntity.SetParent(ITreeEntity parent) => throw new NotImplementedException(); - object IDeepCloneable.DeepClone() => throw new NotImplementedException(); - bool IRememberBeingDirty.WasDirty() => throw new NotImplementedException(); - bool IRememberBeingDirty.WasPropertyDirty(string propertyName) => throw new NotImplementedException(); - void IRememberBeingDirty.ResetWereDirtyProperties() => throw new NotImplementedException(); - void IRememberBeingDirty.ResetDirtyProperties(bool rememberDirty) => throw new NotImplementedException(); - IEnumerable IRememberBeingDirty.GetWereDirtyProperties() => throw new NotImplementedException(); - bool ICanBeDirty.IsDirty() => throw new NotImplementedException(); - bool ICanBeDirty.IsPropertyDirty(string propName) => throw new NotImplementedException(); - IEnumerable ICanBeDirty.GetDirtyProperties() => throw new NotImplementedException(); - void ICanBeDirty.ResetDirtyProperties() => throw new NotImplementedException(); - public void DisableChangeTracking() => throw new NotImplementedException(); - public void EnableChangeTracking() => throw new NotImplementedException(); } } diff --git a/src/Umbraco.Core/Persistence/Mappers/IMapperCollection.cs b/src/Umbraco.Core/Persistence/Mappers/IMapperCollection.cs index dfa6a7ca5b..62d35c3eb8 100644 --- a/src/Umbraco.Core/Persistence/Mappers/IMapperCollection.cs +++ b/src/Umbraco.Core/Persistence/Mappers/IMapperCollection.cs @@ -5,6 +5,7 @@ namespace Umbraco.Core.Persistence.Mappers { public interface IMapperCollection : IBuilderCollection { + bool TryGetMapper(Type type, out BaseMapper mapper); BaseMapper this[Type type] { get; } } } diff --git a/src/Umbraco.Core/Persistence/Mappers/MapperCollection.cs b/src/Umbraco.Core/Persistence/Mappers/MapperCollection.cs index 343406378a..20929dd188 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MapperCollection.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MapperCollection.cs @@ -10,27 +10,40 @@ namespace Umbraco.Core.Persistence.Mappers { public MapperCollection(IEnumerable items) : base(items) - { } + { - // maintain our own index for faster lookup - private readonly ConcurrentDictionary _index = new ConcurrentDictionary(); + _index = new Lazy>(() => + { + var d = new ConcurrentDictionary(); + foreach(var mapper in this) + { + var attributes = mapper.GetType().GetCustomAttributes(false); + foreach(var a in attributes) + { + d.TryAdd(a.EntityType, mapper); + } + } + return d; + }); + } + private readonly Lazy> _index; + + /// + /// Returns a mapper for this type, throw an exception if not found + /// + /// + /// public BaseMapper this[Type type] { get { - return _index.GetOrAdd(type, t => - { - // check if any of the mappers are assigned to this type - var mapper = this.FirstOrDefault(x => x.GetType() - .GetCustomAttributes(false) - .Any(m => m.EntityType == type)); - - if (mapper != null) return mapper; - - throw new Exception($"Could not find a mapper matching type {type.FullName}."); - }); + if (_index.Value.TryGetValue(type, out var mapper)) + return mapper; + throw new Exception($"Could not find a mapper matching type {type.FullName}."); } } + + public bool TryGetMapper(Type type, out BaseMapper mapper) => _index.Value.TryGetValue(type, out mapper); } } diff --git a/src/Umbraco.Core/Persistence/Mappers/SimpleContentTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/SimpleContentTypeMapper.cs deleted file mode 100644 index f98ff3b694..0000000000 --- a/src/Umbraco.Core/Persistence/Mappers/SimpleContentTypeMapper.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Concurrent; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Mappers -{ - [MapperFor(typeof(ISimpleContentType))] - [MapperFor(typeof(SimpleContentType))] - public sealed class SimpleContentTypeMapper : BaseMapper - { - public SimpleContentTypeMapper(Lazy sqlContext, ConcurrentDictionary> maps) - : base(sqlContext, maps) - { } - - protected override void DefineMaps() - { - DefineMap(nameof(ContentType.Id), nameof(NodeDto.NodeId)); - DefineMap(nameof(ContentType.CreateDate), nameof(NodeDto.CreateDate)); - DefineMap(nameof(ContentType.Level), nameof(NodeDto.Level)); - DefineMap(nameof(ContentType.ParentId), nameof(NodeDto.ParentId)); - DefineMap(nameof(ContentType.Path), nameof(NodeDto.Path)); - DefineMap(nameof(ContentType.SortOrder), nameof(NodeDto.SortOrder)); - DefineMap(nameof(ContentType.Name), nameof(NodeDto.Text)); - DefineMap(nameof(ContentType.Trashed), nameof(NodeDto.Trashed)); - DefineMap(nameof(ContentType.Key), nameof(NodeDto.UniqueId)); - DefineMap(nameof(ContentType.CreatorId), nameof(NodeDto.UserId)); - DefineMap(nameof(ContentType.Alias), nameof(ContentTypeDto.Alias)); - DefineMap(nameof(ContentType.AllowedAsRoot), nameof(ContentTypeDto.AllowAtRoot)); - DefineMap(nameof(ContentType.Description), nameof(ContentTypeDto.Description)); - DefineMap(nameof(ContentType.Icon), nameof(ContentTypeDto.Icon)); - DefineMap(nameof(ContentType.IsContainer), nameof(ContentTypeDto.IsContainer)); - DefineMap(nameof(ContentType.IsElement), nameof(ContentTypeDto.IsElement)); - DefineMap(nameof(ContentType.Thumbnail), nameof(ContentTypeDto.Thumbnail)); - } - } -} diff --git a/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionVisitor.cs b/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionVisitor.cs index c87937e41e..7ff536caba 100644 --- a/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionVisitor.cs +++ b/src/Umbraco.Core/Persistence/Querying/ModelToSqlExpressionVisitor.cs @@ -60,8 +60,8 @@ namespace Umbraco.Core.Persistence.Querying if (m.Expression != null && m.Expression.Type != typeof(T) - && TypeHelper.IsTypeAssignableFrom(m.Expression.Type) //TODO: Could this just be `IEntity` ? why does it need to be IUmbracoEntity, we aren't even using the reference to that below - && EndsWithConstant(m) == false) + && EndsWithConstant(m) == false + && _mappers.TryGetMapper(m.Expression.Type, out var subMapper)) { //if this is the case, it means we have a sub expression / nested property access, such as: x.ContentType.Alias == "Test"; //and since the sub type (x.ContentType) is not the same as x, we need to resolve a mapper for x.ContentType to get it's mapped SQL column @@ -69,7 +69,6 @@ namespace Umbraco.Core.Persistence.Querying //don't execute if compiled if (Visited == false) { - var subMapper = _mappers[m.Expression.Type]; // throws if not found var field = subMapper.Map(m.Member.Name); if (field.IsNullOrWhiteSpace()) throw new InvalidOperationException($"The mapper returned an empty field for the member name: {m.Member.Name} for type: {m.Expression.Type}"); diff --git a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs index 705a876d83..ad10a1371b 100644 --- a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs @@ -148,16 +148,13 @@ namespace Umbraco.Core.Services.Implement // existing property alias change? var hasAnyPropertyChangedAlias = contentType.PropertyTypes.Any(propertyType => { - if (!(propertyType is IRememberBeingDirty dirtyProperty)) - throw new Exception("oops"); - // skip new properties // TODO: This used to be WasPropertyDirty("HasIdentity") but i don't think that actually worked for detecting new entities this does seem to work properly - var isNewProperty = dirtyProperty.WasPropertyDirty("Id"); + var isNewProperty = propertyType.WasPropertyDirty("Id"); if (isNewProperty) return false; // alias change? - return dirtyProperty.WasPropertyDirty("Alias"); + return propertyType.WasPropertyDirty("Alias"); }); // removed properties? diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 49011993e3..18dd60fd40 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -343,7 +343,6 @@ - From 1ef5106529083bd5fb79e9bc74e4af2172f8b553 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 14:54:03 +1100 Subject: [PATCH 56/61] oops fix build --- src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs b/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs index 951b0cdf93..2937d969c7 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs @@ -35,7 +35,6 @@ namespace Umbraco.Core.Persistence.Mappers Add(); Add(); Add(); - Add(); Add(); Add(); Add(); From dbd76a903a3de546ed219fb0aa99558d9bdab6e8 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 15:25:04 +1100 Subject: [PATCH 57/61] Cleans up the IPropertyType interface, cleans up how it is constructed --- src/Umbraco.Abstractions/Models/IProperty.cs | 7 +-- .../Models/PropertyTypeCollection.cs | 5 +- src/Umbraco.Core/Models/Property.cs | 50 ++++++++++++++++++- .../Persistence/Factories/PropertyFactory.cs | 30 ++++------- 4 files changed, 62 insertions(+), 30 deletions(-) diff --git a/src/Umbraco.Abstractions/Models/IProperty.cs b/src/Umbraco.Abstractions/Models/IProperty.cs index 3a0d984e55..44e84d9b68 100644 --- a/src/Umbraco.Abstractions/Models/IProperty.cs +++ b/src/Umbraco.Abstractions/Models/IProperty.cs @@ -33,14 +33,9 @@ namespace Umbraco.Core.Models /// void SetValue(object value, string culture = null, string segment = null); - /// - /// Resets the entity identity. - /// - void ResetIdentity(); - int PropertyTypeId { get; } void PublishValues(string culture = "*", string segment = "*"); void UnpublishValues(string culture = "*", string segment = "*"); - void FactorySetValue(string culture, string segment, bool published, object value); + } } diff --git a/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs b/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs index 5d60241a9c..d26a092c64 100644 --- a/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs +++ b/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs @@ -16,7 +16,7 @@ namespace Umbraco.Core.Models [Serializable] [DataContract] // TODO: Change this to ObservableDictionary so we can reduce the INotifyCollectionChanged implementation details - public class PropertyTypeCollection : KeyedCollection, INotifyCollectionChanged, IDeepCloneable + public class PropertyTypeCollection : KeyedCollection, INotifyCollectionChanged, IDeepCloneable, ICollection { [IgnoreDataMember] private readonly ReaderWriterLockSlim _addLocker = new ReaderWriterLockSlim(); @@ -83,8 +83,7 @@ namespace Umbraco.Core.Models OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } - // TODO: Instead of 'new' this should explicitly implement one of the collection interfaces members - public new void Add(IPropertyType item) + void ICollection.Add(IPropertyType item) { item.SupportsPublishing = SupportsPublishing; diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index e75a7420a8..caf3bcc167 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -47,6 +47,54 @@ namespace Umbraco.Core.Models PropertyType = propertyType; } + /// + /// Creates a new instance for existing + /// + /// + /// + /// + /// Generally will contain a published and an unpublished property values + /// + /// + public static Property CreateWithValues(int id, IPropertyType propertyType, params InitialPropertyValue[] values) + { + var property = new Property(propertyType); + try + { + property.DisableChangeTracking(); + property.Id = id; + foreach(var value in values) + { + property.FactorySetValue(value.Culture, value.Segment, value.Published, value.Value); + } + property.ResetDirtyProperties(false); + return property; + } + finally + { + property.EnableChangeTracking(); + } + } + + /// + /// Used for constructing a new instance + /// + public class InitialPropertyValue + { + public InitialPropertyValue(string culture, string segment, bool published, object value) + { + Culture = culture ?? throw new ArgumentNullException(nameof(culture)); + Segment = segment ?? throw new ArgumentNullException(nameof(segment)); + Published = published; + Value = value ?? throw new ArgumentNullException(nameof(value)); + } + + public string Culture { get; } + public string Segment { get; } + public bool Published { get; } + public object Value { get; } + } + /// /// Represents a property value. /// @@ -284,7 +332,7 @@ namespace Umbraco.Core.Models } // bypasses all changes detection and is the *only* way to set the published value - public void FactorySetValue(string culture, string segment, bool published, object value) + private void FactorySetValue(string culture, string segment, bool published, object value) { var (pvalue, _) = GetPValue(culture, segment, true); diff --git a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs index e92c379f07..f844d14022 100644 --- a/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs @@ -16,31 +16,21 @@ namespace Umbraco.Core.Persistence.Factories foreach (var propertyType in propertyTypes) { - var property = new Property(propertyType); + var values = new List(); + int propertyId = default; - try + // see notes in BuildDtos - we always have edit+published dtos + if (xdtos.TryGetValue(propertyType.Id, out var propDtos)) { - property.DisableChangeTracking(); - - // see notes in BuildDtos - we always have edit+published dtos - - if (xdtos.TryGetValue(propertyType.Id, out var propDtos)) + foreach (var propDto in propDtos) { - foreach (var propDto in propDtos) - { - property.Id = propDto.Id; - property.FactorySetValue(languageRepository.GetIsoCodeById(propDto.LanguageId), propDto.Segment, propDto.VersionId == publishedVersionId, propDto.Value); - } - + propertyId = propDto.Id; + values.Add(new Property.InitialPropertyValue(languageRepository.GetIsoCodeById(propDto.LanguageId), propDto.Segment, propDto.VersionId == publishedVersionId, propDto.Value)); } + } - property.ResetDirtyProperties(false); - properties.Add(property); - } - finally - { - property.EnableChangeTracking(); - } + var property = Property.CreateWithValues(propertyId, propertyType, values.ToArray()); + properties.Add(property); } return properties; From 01379968158ffd562c60033b070c2d0b83bd783b Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 15:38:06 +1100 Subject: [PATCH 58/61] Fixes tests, adds notes --- .../Persistence/Mappers/BaseMapper.cs | 1 + .../Mappers/MapperCollectionBuilder.cs | 1 + .../Mappers/SimpleContentTypeMapper.cs | 37 +++++++++++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 1 + 4 files changed, 40 insertions(+) create mode 100644 src/Umbraco.Core/Persistence/Mappers/SimpleContentTypeMapper.cs diff --git a/src/Umbraco.Core/Persistence/Mappers/BaseMapper.cs b/src/Umbraco.Core/Persistence/Mappers/BaseMapper.cs index bfdd60e897..a569fa4912 100644 --- a/src/Umbraco.Core/Persistence/Mappers/BaseMapper.cs +++ b/src/Umbraco.Core/Persistence/Mappers/BaseMapper.cs @@ -52,6 +52,7 @@ namespace Umbraco.Core.Persistence.Mappers return mappedName; } + // fixme: TSource is used for nothing protected void DefineMap(string sourceName, string targetName) { if (_sqlSyntax == null) diff --git a/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs b/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs index 2937d969c7..951b0cdf93 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs @@ -35,6 +35,7 @@ namespace Umbraco.Core.Persistence.Mappers Add(); Add(); Add(); + Add(); Add(); Add(); Add(); diff --git a/src/Umbraco.Core/Persistence/Mappers/SimpleContentTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/SimpleContentTypeMapper.cs new file mode 100644 index 0000000000..68df1550e5 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Mappers/SimpleContentTypeMapper.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Concurrent; +using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Mappers +{ + // TODO: This mapper is actually very useless because the only time it would ever be used is when trying to generate a strongly typed query + // on an IContentBase object which is what exposes ISimpleContentType, however the queries that we execute in the content repositories don't actually + // join on the content type table. The content type data is resolved outside of the query so the end result of the query that is generated by using + // this mapper will either fail or the syntax will target umbracoNode which will be filtering on the actual content NOT the content type. + // I'm leaving this here purely because the ExpressionTests rely on this which is fine for testing that the expressions work, but note that this + // resulting query will not. + + [MapperFor(typeof(ISimpleContentType))] + [MapperFor(typeof(SimpleContentType))] + public sealed class SimpleContentTypeMapper : BaseMapper + { + public SimpleContentTypeMapper(Lazy sqlContext, ConcurrentDictionary> maps) + : base(sqlContext, maps) + { } + + protected override void DefineMaps() + { + // There is no reason for using ContentType here instead of SimpleContentType, in fact the underlying DefineMap call does nothing with the first type parameter + + DefineMap(nameof(ContentType.Id), nameof(NodeDto.NodeId)); + DefineMap(nameof(ContentType.Key), nameof(NodeDto.UniqueId)); + DefineMap(nameof(ContentType.Name), nameof(NodeDto.Text)); + DefineMap(nameof(ContentType.Alias), nameof(ContentTypeDto.Alias)); + DefineMap(nameof(ContentType.Icon), nameof(ContentTypeDto.Icon)); + DefineMap(nameof(ContentType.IsContainer), nameof(ContentTypeDto.IsContainer)); + DefineMap(nameof(ContentType.AllowedAsRoot), nameof(ContentTypeDto.AllowAtRoot)); + DefineMap(nameof(ContentType.IsElement), nameof(ContentTypeDto.IsElement)); + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 18dd60fd40..b02a7df78c 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -217,6 +217,7 @@ + From e537a551814d3b43cddf5662411a0c439986cb16 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 15:42:18 +1100 Subject: [PATCH 59/61] fix incorrect validation --- src/Umbraco.Core/Models/Property.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index caf3bcc167..50a4b9416a 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -83,10 +83,10 @@ namespace Umbraco.Core.Models { public InitialPropertyValue(string culture, string segment, bool published, object value) { - Culture = culture ?? throw new ArgumentNullException(nameof(culture)); - Segment = segment ?? throw new ArgumentNullException(nameof(segment)); + Culture = culture; + Segment = segment; Published = published; - Value = value ?? throw new ArgumentNullException(nameof(value)); + Value = value; } public string Culture { get; } From e366f99105621b63dbc8eddfbb511cc11a225faf Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 15:52:56 +1100 Subject: [PATCH 60/61] Cleans up IPropertyType since we don't need the method ConvertAssignedValue as an abstraction --- .../Models/IPropertyType.cs | 9 -- src/Umbraco.Core/Models/Property.cs | 128 +++++++++++++++++- src/Umbraco.Core/Models/PropertyType.cs | 122 ----------------- 3 files changed, 125 insertions(+), 134 deletions(-) diff --git a/src/Umbraco.Abstractions/Models/IPropertyType.cs b/src/Umbraco.Abstractions/Models/IPropertyType.cs index 7c455d3ba5..6ed5dbd1cb 100644 --- a/src/Umbraco.Abstractions/Models/IPropertyType.cs +++ b/src/Umbraco.Abstractions/Models/IPropertyType.cs @@ -75,14 +75,5 @@ namespace Umbraco.Core.Models /// A value indicating whether wildcards are valid. bool SupportsVariation(string culture, string segment, bool wildcards = false); - /// - /// Converts a value assigned to a property. - /// - /// - /// The input value can be pretty much anything, and is converted to the actual CLR type - /// expected by the property (eg an integer if the property values are integers). - /// Throws if the value cannot be converted. - /// - object ConvertAssignedValue(object value); } } diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index 50a4b9416a..36efbad404 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -295,7 +295,7 @@ namespace Umbraco.Core.Models if (!PropertyType.SupportsPublishing) throw new NotSupportedException("Property type does not support publishing."); var origValue = pvalue.PublishedValue; - pvalue.PublishedValue = PropertyType.ConvertAssignedValue(pvalue.EditedValue); + pvalue.PublishedValue = ConvertAssignedValue(pvalue.EditedValue); DetectChanges(pvalue.EditedValue, origValue, nameof(Values), PropertyValueComparer, false); } @@ -306,7 +306,7 @@ namespace Umbraco.Core.Models if (!PropertyType.SupportsPublishing) throw new NotSupportedException("Property type does not support publishing."); var origValue = pvalue.PublishedValue; - pvalue.PublishedValue = PropertyType.ConvertAssignedValue(null); + pvalue.PublishedValue = ConvertAssignedValue(null); DetectChanges(pvalue.EditedValue, origValue, nameof(Values), PropertyValueComparer, false); } @@ -324,7 +324,7 @@ namespace Umbraco.Core.Models var (pvalue, change) = GetPValue(culture, segment, true); var origValue = pvalue.EditedValue; - var setValue = PropertyType.ConvertAssignedValue(value); + var setValue = ConvertAssignedValue(value); pvalue.EditedValue = setValue; @@ -380,6 +380,128 @@ namespace Umbraco.Core.Models return (pvalue, change); } + /// + public object ConvertAssignedValue(object value) => TryConvertAssignedValue(value, true, out var converted) ? converted : null; + + /// + /// Tries to convert a value assigned to a property. + /// + /// + /// + /// + private bool TryConvertAssignedValue(object value, bool throwOnError, out object converted) + { + var isOfExpectedType = IsOfExpectedPropertyType(value); + if (isOfExpectedType) + { + converted = value; + return true; + } + + // isOfExpectedType is true if value is null - so if false, value is *not* null + // "garbage-in", accept what we can & convert + // throw only if conversion is not possible + + var s = value.ToString(); + converted = null; + + switch (ValueStorageType) + { + case ValueStorageType.Nvarchar: + case ValueStorageType.Ntext: + { + converted = s; + return true; + } + + case ValueStorageType.Integer: + if (s.IsNullOrWhiteSpace()) + return true; // assume empty means null + var convInt = value.TryConvertTo(); + if (convInt) + { + converted = convInt.Result; + return true; + } + + if (throwOnError) + ThrowTypeException(value, typeof(int), Alias); + return false; + + case ValueStorageType.Decimal: + if (s.IsNullOrWhiteSpace()) + return true; // assume empty means null + var convDecimal = value.TryConvertTo(); + if (convDecimal) + { + // need to normalize the value (change the scaling factor and remove trailing zeros) + // because the underlying database is going to mess with the scaling factor anyways. + converted = convDecimal.Result.Normalize(); + return true; + } + + if (throwOnError) + ThrowTypeException(value, typeof(decimal), Alias); + return false; + + case ValueStorageType.Date: + if (s.IsNullOrWhiteSpace()) + return true; // assume empty means null + var convDateTime = value.TryConvertTo(); + if (convDateTime) + { + converted = convDateTime.Result; + return true; + } + + if (throwOnError) + ThrowTypeException(value, typeof(DateTime), Alias); + return false; + + default: + throw new NotSupportedException($"Not supported storage type \"{ValueStorageType}\"."); + } + } + + private static void ThrowTypeException(object value, Type expected, string alias) + { + throw new InvalidOperationException($"Cannot assign value \"{value}\" of type \"{value.GetType()}\" to property \"{alias}\" expecting type \"{expected}\"."); + } + + /// + /// Determines whether a value is of the expected type for this property type. + /// + /// + /// If the value is of the expected type, it can be directly assigned to the property. + /// Otherwise, some conversion is required. + /// + private bool IsOfExpectedPropertyType(object value) + { + // null values are assumed to be ok + if (value == null) + return true; + + // check if the type of the value matches the type from the DataType/PropertyEditor + // then it can be directly assigned, anything else requires conversion + var valueType = value.GetType(); + switch (ValueStorageType) + { + case ValueStorageType.Integer: + return valueType == typeof(int); + case ValueStorageType.Decimal: + return valueType == typeof(decimal); + case ValueStorageType.Date: + return valueType == typeof(DateTime); + case ValueStorageType.Nvarchar: + return valueType == typeof(string); + case ValueStorageType.Ntext: + return valueType == typeof(string); + default: + throw new NotSupportedException($"Not supported storage type \"{ValueStorageType}\"."); + } + } + + protected override void PerformDeepClone(object clone) { base.PerformDeepClone(clone); diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index 2848caf791..65c0ffeade 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -210,128 +210,6 @@ namespace Umbraco.Core.Models return Variations.ValidateVariation(culture, segment, true, wildcards, false); } - /// - /// Determines whether a value is of the expected type for this property type. - /// - /// - /// If the value is of the expected type, it can be directly assigned to the property. - /// Otherwise, some conversion is required. - /// - private bool IsOfExpectedPropertyType(object value) - { - // null values are assumed to be ok - if (value == null) - return true; - - // check if the type of the value matches the type from the DataType/PropertyEditor - // then it can be directly assigned, anything else requires conversion - var valueType = value.GetType(); - switch (ValueStorageType) - { - case ValueStorageType.Integer: - return valueType == typeof(int); - case ValueStorageType.Decimal: - return valueType == typeof(decimal); - case ValueStorageType.Date: - return valueType == typeof(DateTime); - case ValueStorageType.Nvarchar: - return valueType == typeof(string); - case ValueStorageType.Ntext: - return valueType == typeof(string); - default: - throw new NotSupportedException($"Not supported storage type \"{ValueStorageType}\"."); - } - } - - /// - public object ConvertAssignedValue(object value) => TryConvertAssignedValue(value, true, out var converted) ? converted : null; - - /// - /// Tries to convert a value assigned to a property. - /// - /// - /// - /// - private bool TryConvertAssignedValue(object value, bool throwOnError, out object converted) - { - var isOfExpectedType = IsOfExpectedPropertyType(value); - if (isOfExpectedType) - { - converted = value; - return true; - } - - // isOfExpectedType is true if value is null - so if false, value is *not* null - // "garbage-in", accept what we can & convert - // throw only if conversion is not possible - - var s = value.ToString(); - converted = null; - - switch (ValueStorageType) - { - case ValueStorageType.Nvarchar: - case ValueStorageType.Ntext: - { - converted = s; - return true; - } - - case ValueStorageType.Integer: - if (s.IsNullOrWhiteSpace()) - return true; // assume empty means null - var convInt = value.TryConvertTo(); - if (convInt) - { - converted = convInt.Result; - return true; - } - - if (throwOnError) - ThrowTypeException(value, typeof(int), Alias); - return false; - - case ValueStorageType.Decimal: - if (s.IsNullOrWhiteSpace()) - return true; // assume empty means null - var convDecimal = value.TryConvertTo(); - if (convDecimal) - { - // need to normalize the value (change the scaling factor and remove trailing zeros) - // because the underlying database is going to mess with the scaling factor anyways. - converted = convDecimal.Result.Normalize(); - return true; - } - - if (throwOnError) - ThrowTypeException(value, typeof(decimal), Alias); - return false; - - case ValueStorageType.Date: - if (s.IsNullOrWhiteSpace()) - return true; // assume empty means null - var convDateTime = value.TryConvertTo(); - if (convDateTime) - { - converted = convDateTime.Result; - return true; - } - - if (throwOnError) - ThrowTypeException(value, typeof(DateTime), Alias); - return false; - - default: - throw new NotSupportedException($"Not supported storage type \"{ValueStorageType}\"."); - } - } - - private static void ThrowTypeException(object value, Type expected, string alias) - { - throw new InvalidOperationException($"Cannot assign value \"{value}\" of type \"{value.GetType()}\" to property \"{alias}\" expecting type \"{expected}\"."); - } - - /// /// Sanitizes a property type alias. /// From e45ea6560d24dbd7245b5afc9085a05a2ac08f17 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2019 17:00:58 +1100 Subject: [PATCH 61/61] fixes test, adds note --- src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs b/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs index d26a092c64..bca7e88e03 100644 --- a/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs +++ b/src/Umbraco.Abstractions/Models/PropertyTypeCollection.cs @@ -83,7 +83,9 @@ namespace Umbraco.Core.Models OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } - void ICollection.Add(IPropertyType item) + // 'new' keyword is required! we can explicitly implement ICollection.Add BUT since normally a concrete PropertyType type + // is passed in, the explicit implementation doesn't get called, this ensures it does get called. + public new void Add(IPropertyType item) { item.SupportsPublishing = SupportsPublishing;