Implemented most of the configs for asp.net core
This commit is contained in:
@@ -3,6 +3,7 @@ using Umbraco.Configuration.Models;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using ConnectionStrings = Umbraco.Configuration.Models.ConnectionStrings;
|
||||
using CoreDebugSettings = Umbraco.Configuration.Models.CoreDebugSettings;
|
||||
|
||||
namespace Umbraco.Configuration
|
||||
@@ -38,14 +39,10 @@ namespace Umbraco.Configuration
|
||||
configs.Add<IWebRoutingSettings>(() => new WebRoutingSettings(_configuration));
|
||||
configs.Add<IIndexCreatorSettings>(() => new IndexCreatorSettings(_configuration));
|
||||
configs.Add<IModelsBuilderConfig>(() => new ModelsBuilderConfig(_configuration));
|
||||
|
||||
// configs.Add<IGlobalSettings>(() => GlobalSettings);
|
||||
// configs.Add<IConnectionStrings>(() => ConnectionStrings);
|
||||
// configs.Add<IHostingSettings>(() => HostingSettings);
|
||||
// configs.Add<IMachineKeyConfig>(() => MachineKeyConfig);
|
||||
|
||||
|
||||
|
||||
configs.Add<IHostingSettings>(() => new HostingSettings(_configuration));
|
||||
configs.Add<IGlobalSettings>(() => new GlobalSettings(_configuration));
|
||||
configs.Add<IConnectionStrings>(() => new ConnectionStrings(_configuration));
|
||||
configs.Add<IMachineKeyConfig>(() => new MachineKeyConfig(_configuration));
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// A case-insensitive configuration converter for enumerations.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the enumeration.</typeparam>
|
||||
public class CaseInsensitiveEnumConfigConverter<T> : ConfigurationConverterBase
|
||||
where T : struct
|
||||
{
|
||||
public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data)
|
||||
{
|
||||
if (data == null)
|
||||
throw new ArgumentNullException("data");
|
||||
|
||||
//return Enum.Parse(typeof(T), (string)data, true);
|
||||
|
||||
T value;
|
||||
if (Enum.TryParse((string)data, true, out value))
|
||||
return value;
|
||||
|
||||
throw new Exception(string.Format("\"{0}\" is not valid {1} value. Valid values are: {2}.",
|
||||
data, typeof(T).Name,
|
||||
string.Join(", ", Enum.GetValues(typeof(T)).Cast<T>())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using Umbraco.Configuration.Implementations;
|
||||
using Umbraco.Configuration.Legacy;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Core.Configuration.Implementations;
|
||||
using Umbraco.Core.Configuration.Legacy;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
|
||||
namespace Umbraco.Core.Configuration
|
||||
|
||||
+1
-49
@@ -7,56 +7,8 @@ using Umbraco.Composing;
|
||||
using Umbraco.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Core.Configuration
|
||||
namespace Umbraco.Core.Configuration.Legacy
|
||||
{
|
||||
public class HostingSettings : IHostingSettings
|
||||
{
|
||||
private bool? _debugMode;
|
||||
|
||||
/// <inheritdoc />
|
||||
public LocalTempStorage LocalTempStorageLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
var setting = ConfigurationManager.AppSettings[Constants.AppSettings.LocalTempStorage];
|
||||
if (!string.IsNullOrWhiteSpace(setting))
|
||||
return Enum<LocalTempStorage>.Parse(setting);
|
||||
|
||||
return LocalTempStorage.Default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco is running in [debug mode].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [debug mode]; otherwise, <c>false</c>.</value>
|
||||
public bool DebugMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_debugMode.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ConfigurationManager.GetSection("system.web/compilation") is ConfigurationSection compilation)
|
||||
{
|
||||
var debugElement = compilation.ElementInformation.Properties["debug"];
|
||||
|
||||
_debugMode = debugElement != null && (debugElement.Value is bool debug && debug);
|
||||
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_debugMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
return _debugMode.GetValueOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Replace checking for if the app settings exist and returning an empty string, instead return the defaults!
|
||||
// TODO: need to massively cleanup these configuration classes
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.Legacy
|
||||
{
|
||||
public class HostingSettings : IHostingSettings
|
||||
{
|
||||
private bool? _debugMode;
|
||||
|
||||
/// <inheritdoc />
|
||||
public LocalTempStorage LocalTempStorageLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
var setting = ConfigurationManager.AppSettings[Constants.AppSettings.LocalTempStorage];
|
||||
if (!string.IsNullOrWhiteSpace(setting))
|
||||
return Enum<LocalTempStorage>.Parse(setting);
|
||||
|
||||
return LocalTempStorage.Default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco is running in [debug mode].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [debug mode]; otherwise, <c>false</c>.</value>
|
||||
public bool DebugMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_debugMode.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ConfigurationManager.GetSection("system.web/compilation") is ConfigurationSection compilation)
|
||||
{
|
||||
var debugElement = compilation.ElementInformation.Properties["debug"];
|
||||
|
||||
_debugMode = debugElement != null && (debugElement.Value is bool debug && debug);
|
||||
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_debugMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
return _debugMode.GetValueOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
using System.Configuration;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Configuration
|
||||
namespace Umbraco.Configuration.Legacy
|
||||
{
|
||||
public class MachineKeyConfig : IMachineKeyConfig
|
||||
{
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
|
||||
namespace Umbraco.Configuration.Models
|
||||
{
|
||||
public class ConnectionStrings : IConnectionStrings
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public ConnectionStrings(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public ConfigConnectionString this[string key]
|
||||
{
|
||||
get => new ConfigConnectionString(_configuration.GetConnectionString(key), "sasd", key);
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RemoveConnectionString(string umbracoConnectionName, IIOHelper ioHelper)
|
||||
{
|
||||
//TODO We need to figure out what to do here.. We cond have another config setting, that tells with file(s) to update? or should we assume appsettings.json
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveConnectionString(string connectionString, string providerName, IIOHelper ioHelper)
|
||||
{
|
||||
//TODO We need to figure out what to do here.. We cond have another config setting, that tells with file(s) to update? or should we assume appsettings.json
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Configuration;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Configuration.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// The GlobalSettings Class contains general settings information for the entire Umbraco instance based on information from web.config appsettings
|
||||
/// </summary>
|
||||
public class GlobalSettings : IGlobalSettings
|
||||
{
|
||||
private readonly IConfiguration _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(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public string ReservedUrls => _configuration.GetValue("Umbraco:CMS:Global:ReservedUrls", StaticReservedUrls);
|
||||
public string ReservedPaths => _configuration.GetValue("Umbraco:CMS:Global:ReservedPaths", StaticReservedPaths);
|
||||
public string Path => _configuration.GetValue<string>("Umbraco:CMS:Global:Path");
|
||||
// TODO: https://github.com/umbraco/Umbraco-CMS/issues/4238 - stop having version in web.config appSettings
|
||||
public string ConfigurationStatus
|
||||
{
|
||||
get => _configuration.GetValue<string>("Umbraco:CMS:Global:ConfigurationStatus");
|
||||
set => throw new NotImplementedException("We should remove this and only use the value from database");
|
||||
}
|
||||
|
||||
public int TimeOutInMinutes => _configuration.GetValue("Umbraco:CMS:Global:TimeOutInMinutes", 20);
|
||||
public string DefaultUILanguage => _configuration.GetValue("Umbraco:CMS:Global:TimeOutInMinutes", "en-US");
|
||||
public bool HideTopLevelNodeFromPath => _configuration.GetValue("Umbraco:CMS:Global:HideTopLevelNodeFromPath", false);
|
||||
public bool UseHttps => _configuration.GetValue("Umbraco:CMS:Global:UseHttps", false);
|
||||
public int VersionCheckPeriod => _configuration.GetValue("Umbraco:CMS:Global:VersionCheckPeriod", 7);
|
||||
public string UmbracoPath => _configuration.GetValue("Umbraco:CMS:Global:UmbracoPath", "~/umbraco");
|
||||
public string UmbracoCssPath => _configuration.GetValue("Umbraco:CMS:Global:UmbracoCssPath", "~/css");
|
||||
public string UmbracoScriptsPath => _configuration.GetValue("Umbraco:CMS:Global:UmbracoScriptsPath", "~/scripts");
|
||||
public string UmbracoMediaPath => _configuration.GetValue("Umbraco:CMS:Global:UmbracoMediaPath", "~/media");
|
||||
public bool InstallMissingDatabase => _configuration.GetValue("Umbraco:CMS:Global:InstallMissingDatabase", false);
|
||||
public bool InstallEmptyDatabase => _configuration.GetValue("Umbraco:CMS:Global:InstallEmptyDatabase", false);
|
||||
public bool DisableElectionForSingleServer => _configuration.GetValue("Umbraco:CMS:Global:DisableElectionForSingleServer", false);
|
||||
public string RegisterType => _configuration.GetValue("Umbraco:CMS:Global:RegisterType", string.Empty);
|
||||
public string DatabaseFactoryServerVersion => _configuration.GetValue("Umbraco:CMS:Global:DatabaseFactoryServerVersion", string.Empty);
|
||||
public string MainDomLock => _configuration.GetValue("Umbraco:CMS:Global:MainDomLock", string.Empty);
|
||||
public string NoNodesViewPath => _configuration.GetValue("Umbraco:CMS:Global:NoNodesViewPath", "~/config/splashes/NoNodes.cshtml");
|
||||
|
||||
public bool IsSmtpServerConfigured =>
|
||||
_configuration.GetSection("Umbraco:CMS:Smtp")?.GetChildren().Any() ?? false;
|
||||
|
||||
public ISmtpSettings SmtpSettings => new SmtpSettingsImpl(_configuration.GetSection("Umbraco:CMS:Smtp"));
|
||||
|
||||
private class SmtpSettingsImpl : ISmtpSettings
|
||||
{
|
||||
private readonly IConfigurationSection _configurationSection;
|
||||
|
||||
public SmtpSettingsImpl(IConfigurationSection configurationSection)
|
||||
{
|
||||
_configurationSection = configurationSection;
|
||||
}
|
||||
|
||||
public string From => _configurationSection.GetValue<string>("From");
|
||||
public string Host => _configurationSection.GetValue<string>("Host");
|
||||
public int Port => _configurationSection.GetValue<int>("Port");
|
||||
public string PickupDirectoryLocation => _configurationSection.GetValue<string>("PickupDirectoryLocation");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using ConfigurationSection = System.Configuration.ConfigurationSection;
|
||||
|
||||
namespace Umbraco.Configuration.Models
|
||||
{
|
||||
public class HostingSettings : IHostingSettings
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public HostingSettings(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public LocalTempStorage LocalTempStorageLocation =>
|
||||
_configuration.GetValue("Umbraco:CMS:Hosting:LocalTempStorage", LocalTempStorage.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether umbraco is running in [debug mode].
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if [debug mode]; otherwise, <c>false</c>.</value>
|
||||
public bool DebugMode => _configuration.GetValue("Umbraco:CMS:Hosting:Debug", false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Configuration.Models
|
||||
{
|
||||
public class MachineKeyConfig : IMachineKeyConfig
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
public MachineKeyConfig(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
//TODO all the machineKey stuff should be replaced: https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/compatibility/replacing-machinekey?view=aspnetcore-3.1
|
||||
|
||||
public bool HasMachineKey => throw new NotImplementedException("TODO we need to figure out what to do here");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,36 +26,6 @@ namespace Umbraco.Configuration.Models
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
private static string GetModelsDirectory(string root, string config, bool acceptUnsafe)
|
||||
{
|
||||
// making sure it is safe, ie under the website root,
|
||||
// unless AcceptUnsafeModelsDirectory and then everything is OK.
|
||||
|
||||
if (!Path.IsPathRooted(root))
|
||||
throw new ConfigurationErrorsException($"Root is not rooted \"{root}\".");
|
||||
|
||||
if (config.StartsWith("~/"))
|
||||
{
|
||||
var dir = Path.Combine(root, config.TrimStart("~/"));
|
||||
|
||||
// sanitize - GetFullPath will take care of any relative
|
||||
// segments in path, eg '../../foo.tmp' - it may throw a SecurityException
|
||||
// if the combined path reaches illegal parts of the filesystem
|
||||
dir = Path.GetFullPath(dir);
|
||||
root = Path.GetFullPath(root);
|
||||
|
||||
if (!dir.StartsWith(root) && !acceptUnsafe)
|
||||
throw new ConfigurationErrorsException($"Invalid models directory \"{config}\".");
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
if (acceptUnsafe)
|
||||
return Path.GetFullPath(config);
|
||||
|
||||
throw new ConfigurationErrorsException($"Invalid models directory \"{config}\".");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the whole models experience is enabled.
|
||||
/// </summary>
|
||||
@@ -94,7 +64,8 @@ namespace Umbraco.Configuration.Models
|
||||
/// Gets the models directory.
|
||||
/// </summary>
|
||||
/// <remarks>Default is ~/App_Data/Models but that can be changed.</remarks>
|
||||
public string ModelsDirectory => GetModelsDirectory("~/",_configuration.GetValue("Umbraco:CMS:ModelsBuilder:ModelsDirectory", "~/App_Data/Models"), AcceptUnsafeModelsDirectory);
|
||||
public string ModelsDirectory =>
|
||||
_configuration.GetValue("Umbraco:CMS:ModelsBuilder:ModelsDirectory", "~/App_Data/Models");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether to accept an unsafe value for ModelsDirectory.
|
||||
|
||||
@@ -31,8 +31,4 @@
|
||||
<ProjectReference Include="..\Umbraco.Core\Umbraco.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implementations" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
using System.Configuration;
|
||||
using Semver;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Configuration
|
||||
{
|
||||
public static class UmbracoVersionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the "local" version of the site.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>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.</para>
|
||||
/// </remarks>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Semver;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Legacy;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
@@ -7,6 +7,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Legacy;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Install;
|
||||
|
||||
@@ -7,6 +7,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Legacy;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Install;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
@@ -7,7 +7,6 @@ using Umbraco.Composing;
|
||||
using Umbraco.Configuration;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Logging.Serilog;
|
||||
@@ -32,9 +31,6 @@ namespace Umbraco.Web.BackOffice.AspNetCore
|
||||
|
||||
var settings = configs.GetConfig<IModelsBuilderConfig>();
|
||||
|
||||
var x =settings.ModelsDirectory;
|
||||
|
||||
|
||||
services.CreateCompositionRoot(
|
||||
httpContextAccessor,
|
||||
webHostEnvironment,
|
||||
|
||||
@@ -49,7 +49,6 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Request;
|
||||
using Umbraco.Core.Session;
|
||||
using Umbraco.Web.AspNet;
|
||||
using Umbraco.Web.AspNet;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
namespace Umbraco.Web.Runtime
|
||||
|
||||
Reference in New Issue
Block a user