From 603ec0ccfbab680ac413808857efc0fc22451b44 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 15 Nov 2019 11:07:37 +0100 Subject: [PATCH] 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(); }