Changed SystemDirectories from static to instance, Added interface in abstractions and create a static property on current.
This commit is contained in:
@@ -11,6 +11,7 @@ namespace Umbraco.Core.IO
|
||||
{
|
||||
private readonly IFactory _container;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISystemDirectories _systemDirectories;
|
||||
|
||||
private readonly ConcurrentDictionary<Type, Lazy<IFileSystem>> _filesystems = new ConcurrentDictionary<Type, Lazy<IFileSystem>>();
|
||||
|
||||
@@ -37,6 +38,7 @@ namespace Umbraco.Core.IO
|
||||
{
|
||||
_container = container;
|
||||
_logger = logger;
|
||||
_systemDirectories = Current.SystemDirectories;
|
||||
}
|
||||
|
||||
// for tests only, totally unsafe
|
||||
@@ -120,11 +122,11 @@ namespace Umbraco.Core.IO
|
||||
// but it does not really matter what we return - here, null
|
||||
private object CreateWellKnownFileSystems()
|
||||
{
|
||||
var macroPartialFileSystem = new PhysicalFileSystem(SystemDirectories.MacroPartials);
|
||||
var partialViewsFileSystem = new PhysicalFileSystem(SystemDirectories.PartialViews);
|
||||
var stylesheetsFileSystem = new PhysicalFileSystem(SystemDirectories.Css);
|
||||
var scriptsFileSystem = new PhysicalFileSystem(SystemDirectories.Scripts);
|
||||
var mvcViewsFileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews);
|
||||
var macroPartialFileSystem = new PhysicalFileSystem(_systemDirectories.MacroPartials);
|
||||
var partialViewsFileSystem = new PhysicalFileSystem(_systemDirectories.PartialViews);
|
||||
var stylesheetsFileSystem = new PhysicalFileSystem(_systemDirectories.Css);
|
||||
var scriptsFileSystem = new PhysicalFileSystem(_systemDirectories.Scripts);
|
||||
var mvcViewsFileSystem = new PhysicalFileSystem(_systemDirectories.MvcViews);
|
||||
|
||||
_macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, "macro-partials", IsScoped);
|
||||
_partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, "partials", IsScoped);
|
||||
|
||||
@@ -13,7 +13,13 @@ namespace Umbraco.Core.IO
|
||||
{
|
||||
public class IOHelper : IIOHelper
|
||||
{
|
||||
internal static IIOHelper Default { get; } = new IOHelper();
|
||||
private readonly ISystemDirectories _systemDirectories;
|
||||
internal static IIOHelper Default { get; } = new IOHelper(new SystemDirectories());
|
||||
|
||||
public IOHelper(ISystemDirectories systemDirectories)
|
||||
{
|
||||
_systemDirectories = systemDirectories;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value forcing Umbraco to consider it is non-hosted.
|
||||
@@ -39,10 +45,10 @@ namespace Umbraco.Core.IO
|
||||
string retval = virtualPath;
|
||||
|
||||
if (virtualPath.StartsWith("~"))
|
||||
retval = virtualPath.Replace("~", SystemDirectories.Root);
|
||||
retval = virtualPath.Replace("~", _systemDirectories.Root);
|
||||
|
||||
if (virtualPath.StartsWith("/") && virtualPath.StartsWith(SystemDirectories.Root) == false)
|
||||
retval = SystemDirectories.Root + "/" + virtualPath.TrimStart('/');
|
||||
if (virtualPath.StartsWith("/") && virtualPath.StartsWith(_systemDirectories.Root) == false)
|
||||
retval = _systemDirectories.Root + "/" + virtualPath.TrimStart('/');
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -57,11 +63,11 @@ namespace Umbraco.Core.IO
|
||||
public string ResolveUrl(string virtualPath)
|
||||
{
|
||||
if (virtualPath.StartsWith("~"))
|
||||
return virtualPath.Replace("~", SystemDirectories.Root).Replace("//", "/");
|
||||
return virtualPath.Replace("~", _systemDirectories.Root).Replace("//", "/");
|
||||
else if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute))
|
||||
return virtualPath;
|
||||
else
|
||||
return VirtualPathUtility.ToAbsolute(virtualPath, SystemDirectories.Root);
|
||||
return VirtualPathUtility.ToAbsolute(virtualPath, _systemDirectories.Root);
|
||||
}
|
||||
|
||||
public Attempt<string> TryResolveUrl(string virtualPath)
|
||||
@@ -69,10 +75,10 @@ namespace Umbraco.Core.IO
|
||||
try
|
||||
{
|
||||
if (virtualPath.StartsWith("~"))
|
||||
return Attempt.Succeed(virtualPath.Replace("~", SystemDirectories.Root).Replace("//", "/"));
|
||||
return Attempt.Succeed(virtualPath.Replace("~", _systemDirectories.Root).Replace("//", "/"));
|
||||
if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute))
|
||||
return Attempt.Succeed(virtualPath);
|
||||
return Attempt.Succeed(VirtualPathUtility.ToAbsolute(virtualPath, SystemDirectories.Root));
|
||||
return Attempt.Succeed(VirtualPathUtility.ToAbsolute(virtualPath, _systemDirectories.Root));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -97,7 +103,7 @@ namespace Umbraco.Core.IO
|
||||
if (useHttpContext && HttpContext.Current != null)
|
||||
{
|
||||
//string retval;
|
||||
if (String.IsNullOrEmpty(path) == false && (path.StartsWith("~") || path.StartsWith(SystemDirectories.Root)))
|
||||
if (String.IsNullOrEmpty(path) == false && (path.StartsWith("~") || path.StartsWith(_systemDirectories.Root)))
|
||||
return HostingEnvironment.MapPath(path);
|
||||
else
|
||||
return HostingEnvironment.MapPath("~/" + path.TrimStart('/'));
|
||||
@@ -160,7 +166,7 @@ namespace Umbraco.Core.IO
|
||||
// TODO: what's below is dirty, there are too many ways to get the root dir, etc.
|
||||
// not going to fix everything today
|
||||
|
||||
var mappedRoot = MapPath(SystemDirectories.Root);
|
||||
var mappedRoot = MapPath(_systemDirectories.Root);
|
||||
if (filePath.StartsWith(mappedRoot) == false)
|
||||
filePath = MapPath(filePath);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Umbraco.Core.IO
|
||||
{
|
||||
internal class ShadowWrapper : IFileSystem
|
||||
{
|
||||
private static readonly string ShadowFsPath = SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs";
|
||||
private static readonly string ShadowFsPath = Current.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs";
|
||||
|
||||
private readonly Func<bool> _isScoped;
|
||||
private readonly IFileSystem _innerFileSystem;
|
||||
|
||||
@@ -4,50 +4,50 @@ using Umbraco.Core.Composing;
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
//all paths has a starting but no trailing /
|
||||
public class SystemDirectories
|
||||
public class SystemDirectories : ISystemDirectories
|
||||
{
|
||||
public static string Bin => "~/bin";
|
||||
public string Bin => "~/bin";
|
||||
|
||||
public static string Config => "~/config";
|
||||
public string Config => "~/config";
|
||||
|
||||
public static string Data => "~/App_Data";
|
||||
public string Data => "~/App_Data";
|
||||
|
||||
public static string TempData => Data + "/TEMP";
|
||||
public string TempData => Data + "/TEMP";
|
||||
|
||||
public static string TempFileUploads => TempData + "/FileUploads";
|
||||
public string TempFileUploads => TempData + "/FileUploads";
|
||||
|
||||
public static string TempImageUploads => TempFileUploads + "/rte";
|
||||
public string TempImageUploads => TempFileUploads + "/rte";
|
||||
|
||||
public static string Install => "~/install";
|
||||
public string Install => "~/install";
|
||||
|
||||
public static string AppCode => "~/App_Code";
|
||||
public string AppCode => "~/App_Code";
|
||||
|
||||
public static string AppPlugins => "~/App_Plugins";
|
||||
public string AppPlugins => "~/App_Plugins";
|
||||
|
||||
public static string MvcViews => "~/Views";
|
||||
public string MvcViews => "~/Views";
|
||||
|
||||
public static string PartialViews => MvcViews + "/Partials/";
|
||||
public string PartialViews => MvcViews + "/Partials/";
|
||||
|
||||
public static string MacroPartials => MvcViews + "/MacroPartials/";
|
||||
public string MacroPartials => MvcViews + "/MacroPartials/";
|
||||
|
||||
public static string Media => Current.IOHelper.ReturnPath("umbracoMediaPath", "~/media");
|
||||
public string Media => Current.IOHelper.ReturnPath("umbracoMediaPath", "~/media");
|
||||
|
||||
public static string Scripts => Current.IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts");
|
||||
public string Scripts => Current.IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts");
|
||||
|
||||
public static string Css => Current.IOHelper.ReturnPath("umbracoCssPath", "~/css");
|
||||
public string Css => Current.IOHelper.ReturnPath("umbracoCssPath", "~/css");
|
||||
|
||||
public static string Umbraco => Current.IOHelper.ReturnPath("umbracoPath", "~/umbraco");
|
||||
public string Umbraco => Current.IOHelper.ReturnPath("umbracoPath", "~/umbraco");
|
||||
|
||||
public static string Packages => Data + "/packages";
|
||||
public string Packages => Data + "/packages";
|
||||
|
||||
public static string Preview => Data + "/preview";
|
||||
public string Preview => Data + "/preview";
|
||||
|
||||
private static string _root;
|
||||
private string _root;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root path of the application
|
||||
/// </summary>
|
||||
public static string Root
|
||||
public string Root
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace Umbraco.Core.IO
|
||||
return _root;
|
||||
}
|
||||
//Only required for unit tests
|
||||
internal set => _root = value;
|
||||
set => _root = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using System.IO;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
{
|
||||
public class SystemFiles
|
||||
{
|
||||
public static string TinyMceConfig => SystemDirectories.Config + "/tinyMceConfig.config";
|
||||
public static string TinyMceConfig => Current.SystemDirectories.Config + "/tinyMceConfig.config";
|
||||
|
||||
// TODO: Kill this off we don't have umbraco.config XML cache we now have NuCache
|
||||
public static string GetContentCacheXml(IGlobalSettings globalSettings)
|
||||
|
||||
Reference in New Issue
Block a user