Move the config usage out of IOHelper
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
namespace Umbraco.Core.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains general settings information for the entire Umbraco instance based on information from web.config appsettings
|
||||
/// Contains general settings information for the entire Umbraco instance based on information from web.config appsettings
|
||||
/// </summary>
|
||||
public interface IGlobalSettings
|
||||
{
|
||||
@@ -21,7 +21,7 @@
|
||||
/// Gets the path to umbraco's root directory (/umbraco by default).
|
||||
/// </summary>
|
||||
string Path { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the configuration status. This will return the version number of the currently installed umbraco instance.
|
||||
/// </summary>
|
||||
@@ -67,5 +67,10 @@
|
||||
/// Gets the location of temporary files.
|
||||
/// </summary>
|
||||
string LocalTempPath { get; }
|
||||
|
||||
string UmbracoPath { get; }
|
||||
string UmbracoCssPath { get; }
|
||||
string UmbracoScriptsPath { get; }
|
||||
string UmbracoMediaPath { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,26 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
public const string ReservedUrls = "Umbraco.Core.ReservedUrls";
|
||||
|
||||
/// <summary>
|
||||
/// The path of backoffice.
|
||||
/// </summary>
|
||||
public const string UmbracoPath = "umbracoPath";
|
||||
|
||||
/// <summary>
|
||||
/// The path of the stylesheet folder.
|
||||
/// </summary>
|
||||
public const string UmbracoCssPath = "umbracoCssPath";
|
||||
|
||||
/// <summary>
|
||||
/// The path of script folder.
|
||||
/// </summary>
|
||||
public const string UmbracoScriptsPath = "umbracoScriptsPath";
|
||||
|
||||
/// <summary>
|
||||
/// The path of media folder.
|
||||
/// </summary>
|
||||
public const string UmbracoMediaPath = "umbracoMediaPath";
|
||||
|
||||
/// <summary>
|
||||
/// The reserved paths from web.config
|
||||
/// </summary>
|
||||
|
||||
@@ -378,5 +378,43 @@ namespace Umbraco.Core.Configuration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _umbracoMediaPath = null;
|
||||
public string UmbracoMediaPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoMediaPath, "~/umbraco", ref _umbracoMediaPath);
|
||||
|
||||
private string _umbracoScriptsPath = null;
|
||||
public string UmbracoScriptsPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoScriptsPath, "~/umbraco", ref _umbracoScriptsPath);
|
||||
|
||||
private string _umbracoCssPath = null;
|
||||
public string UmbracoCssPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoCssPath, "~/umbraco", ref _umbracoCssPath);
|
||||
|
||||
private string _umbracoPath = null;
|
||||
public string UmbracoPath => GetterWithDefaultValue(Constants.AppSettings.UmbracoPath, "~/umbraco", ref _umbracoPath);
|
||||
|
||||
private T GetterWithDefaultValue<T>(string appSettingKey, T defaultValue, ref T backingField)
|
||||
{
|
||||
if (backingField != null) return backingField;
|
||||
|
||||
if (ConfigurationManager.AppSettings.ContainsKey(appSettingKey))
|
||||
{
|
||||
try
|
||||
{
|
||||
var value = ConfigurationManager.AppSettings[appSettingKey];
|
||||
|
||||
backingField = (T)Convert.ChangeType(value, typeof(T));
|
||||
}
|
||||
catch
|
||||
{
|
||||
/* ignore and use default value */
|
||||
backingField = defaultValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
backingField = defaultValue;
|
||||
}
|
||||
|
||||
return backingField;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,22 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
public class IOHelper : IIOHelper
|
||||
{
|
||||
internal static IIOHelper Default { get; } = new IOHelper();
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
internal static IIOHelper Default { get; } = new IOHelper(new GlobalSettings());
|
||||
|
||||
public IOHelper(IGlobalSettings globalSettings)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value forcing Umbraco to consider it is non-hosted.
|
||||
@@ -289,25 +295,13 @@ namespace Umbraco.Core.IO
|
||||
}
|
||||
|
||||
|
||||
public string Media => ReturnPath("umbracoMediaPath", "~/media");
|
||||
public string Media => _globalSettings.UmbracoMediaPath;
|
||||
|
||||
public string Scripts => ReturnPath("umbracoScriptsPath", "~/scripts");
|
||||
public string Scripts => _globalSettings.UmbracoScriptsPath;
|
||||
|
||||
public string Css => ReturnPath("umbracoCssPath", "~/css");
|
||||
public string Css => _globalSettings.UmbracoCssPath;
|
||||
|
||||
public string Umbraco => ReturnPath("umbracoPath", "~/umbraco");
|
||||
|
||||
//use a tilde character instead of the complete path
|
||||
string ReturnPath(string settingsKey, string standardPath)
|
||||
{
|
||||
//TODO do not use ConfigurationManager directly
|
||||
var retval = ConfigurationManager.AppSettings[settingsKey];
|
||||
|
||||
if (string.IsNullOrEmpty(retval))
|
||||
retval = standardPath;
|
||||
|
||||
return retval.TrimEnd('/');
|
||||
}
|
||||
public string Umbraco => _globalSettings.UmbracoPath;
|
||||
|
||||
private string _root;
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
@inherits Umbraco.Web.Mvc.UmbracoViewPage
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
Reference in New Issue
Block a user