From 683c0da46825a3e292cf6579bb9f2b1550c787a2 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 13 Nov 2019 11:26:03 +0100 Subject: [PATCH] Moved stuff from SystemDirectories into constants and IOHelper to avoid a circular dependency --- .../Constants-SystemDirectories.cs | 36 ++++++++++++ src/Umbraco.Abstractions/IO/IIOHelper.cs | 17 +++++- .../IO/ISystemDirectories.cs | 33 ----------- .../CompositionExtensions/FileSystems.cs | 2 +- .../CompositionExtensions/Services.cs | 7 +-- src/Umbraco.Core/Composing/Current.cs | 1 - src/Umbraco.Core/ConfigsExtensions.cs | 2 +- .../Configuration/GlobalSettings.cs | 4 +- .../Configuration/GlobalSettingsExtensions.cs | 4 +- src/Umbraco.Core/IO/FileSystems.cs | 16 ++--- src/Umbraco.Core/IO/IOHelper.cs | 58 +++++++++++++------ src/Umbraco.Core/IO/ShadowWrapper.cs | 2 +- src/Umbraco.Core/IO/SystemDirectories.cs | 58 +------------------ src/Umbraco.Core/IO/SystemFiles.cs | 2 +- .../Migrations/Install/DatabaseBuilder.cs | 4 +- .../Packaging/CompiledPackageXmlParser.cs | 6 +- .../Packaging/PackageDataInstallation.cs | 2 +- .../Packaging/PackagesRepository.cs | 6 +- .../Implement/PartialViewRepository.cs | 2 +- .../Implement/ScriptRepository.cs | 4 +- .../Implement/StylesheetRepository.cs | 2 +- .../Implement/TemplateRepository.cs | 2 +- .../Runtime/CoreInitialComponent.cs | 10 ++-- .../Services/Implement/FileService.cs | 4 +- .../Services/Implement/NotificationService.cs | 4 +- .../Services/Implement/PackagingService.cs | 2 +- src/Umbraco.Core/Sync/ApplicationUrlHelper.cs | 2 +- src/Umbraco.Examine/LuceneIndexCreator.cs | 2 +- src/Umbraco.Examine/LuceneIndexDiagnostics.cs | 5 +- .../Components/ComponentTests.cs | 2 +- .../Configurations/GlobalSettingsTests.cs | 6 +- .../CoreThings/UriExtensionsTests.cs | 6 +- src/Umbraco.Tests/IO/FileSystemsTests.cs | 1 + src/Umbraco.Tests/IO/IoHelperTests.cs | 24 ++++---- src/Umbraco.Tests/IO/ShadowFileSystemTests.cs | 14 ++--- .../LegacyXmlPublishedCache/PreviewContent.cs | 4 +- .../PartialViewRepositoryTests.cs | 3 +- .../Repositories/ScriptRepositoryTest.cs | 2 +- .../Repositories/StylesheetRepositoryTest.cs | 2 +- .../Repositories/TemplateRepositoryTest.cs | 4 +- .../Scoping/ScopeEventDispatcherTests.cs | 2 +- .../Scoping/ScopeFileSystemsTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestHelper.cs | 6 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 8 +-- src/Umbraco.Tests/Views/textpage.cshtml | 4 ++ .../Umbraco/Views/AuthorizeUpgrade.cshtml | 2 +- .../Umbraco/Views/Default.cshtml | 2 +- .../Umbraco/Views/Preview/Index.cshtml | 2 +- .../config/splashes/noNodes.aspx | 2 +- src/Umbraco.Web/Composing/Current.cs | 1 - .../Editors/BackOfficeAssetsController.cs | 2 +- .../Editors/BackOfficeServerVariables.cs | 6 +- .../Binders/ContentModelBinderHelper.cs | 2 +- src/Umbraco.Web/Editors/CodeFileController.cs | 28 ++++----- .../Editors/ContentTypeController.cs | 4 +- src/Umbraco.Web/Editors/MacrosController.cs | 8 +-- src/Umbraco.Web/Editors/MediaController.cs | 2 +- .../Editors/PackageInstallController.cs | 10 ++-- src/Umbraco.Web/Editors/TinyMceController.cs | 4 +- src/Umbraco.Web/Editors/TourController.cs | 4 +- src/Umbraco.Web/Editors/UsersController.cs | 2 +- .../FolderAndFilePermissionsCheck.cs | 24 ++++---- src/Umbraco.Web/HtmlHelperRenderExtensions.cs | 2 +- .../Install/Controllers/InstallController.cs | 6 +- .../Install/FilePermissionHelper.cs | 7 ++- .../Install/InstallAuthorizeAttribute.cs | 2 +- .../Install/InstallStatusTracker.cs | 10 ++-- .../InstallSteps/ConfigureMachineKey.cs | 2 +- .../InstallSteps/StarterKitCleanupStep.cs | 2 +- .../ClientDependencyConfiguration.cs | 2 +- .../JavaScript/JsInitialization.cs | 2 +- .../UmbracoClientDependencyLoader.cs | 2 +- src/Umbraco.Web/Mvc/PluginViewEngine.cs | 24 ++++---- .../Mvc/UmbracoViewPageOfTModel.cs | 2 +- .../Runtime/WebInitialComponent.cs | 2 +- .../Scheduling/SchedulerComponent.cs | 2 +- src/Umbraco.Web/Security/WebSecurity.cs | 2 +- src/Umbraco.Web/UmbracoInjectedModule.cs | 2 +- 78 files changed, 278 insertions(+), 287 deletions(-) create mode 100644 src/Umbraco.Abstractions/Constants-SystemDirectories.cs delete mode 100644 src/Umbraco.Abstractions/IO/ISystemDirectories.cs create mode 100644 src/Umbraco.Tests/Views/textpage.cshtml diff --git a/src/Umbraco.Abstractions/Constants-SystemDirectories.cs b/src/Umbraco.Abstractions/Constants-SystemDirectories.cs new file mode 100644 index 0000000000..e33247be63 --- /dev/null +++ b/src/Umbraco.Abstractions/Constants-SystemDirectories.cs @@ -0,0 +1,36 @@ +namespace Umbraco.Core +{ + public static partial class Constants + { + public static class SystemDirectories + { + public const string Bin = "~/bin"; + + public const string Config = "~/config"; + + public const string Data = "~/App_Data"; + + public const string TempData = Data + "/TEMP"; + + public const string TempFileUploads = TempData + "/FileUploads"; + + public const string TempImageUploads = TempFileUploads + "/rte"; + + public const string Install = "~/install"; + + public const string AppCode = "~/App_Code"; + + public const string AppPlugins = "~/App_Plugins"; + + public const string MvcViews = "~/Views"; + + public const string PartialViews = MvcViews + "/Partials/"; + + public const string MacroPartials = MvcViews + "/MacroPartials/"; + + public const string Packages = Data + "/packages"; + + public const string Preview = Data + "/preview"; + } + } +} diff --git a/src/Umbraco.Abstractions/IO/IIOHelper.cs b/src/Umbraco.Abstractions/IO/IIOHelper.cs index c66e6137be..80e06b0062 100644 --- a/src/Umbraco.Abstractions/IO/IIOHelper.cs +++ b/src/Umbraco.Abstractions/IO/IIOHelper.cs @@ -5,7 +5,7 @@ namespace Umbraco.Core.IO public interface IIOHelper { bool ForceNotHosted { get; set; } - + /// /// Gets a value indicating whether Umbraco is hosted. /// @@ -80,5 +80,20 @@ namespace Umbraco.Core.IO /// /// string GetRelativePath(string path); + + string Media { get; } + string Scripts { get; } + string Css { get; } + string Umbraco { get; } + + + /// + /// Gets the root path of the application + /// + string Root + { + get; + set; //Only required for unit tests + } } } diff --git a/src/Umbraco.Abstractions/IO/ISystemDirectories.cs b/src/Umbraco.Abstractions/IO/ISystemDirectories.cs deleted file mode 100644 index 4c1499760e..0000000000 --- a/src/Umbraco.Abstractions/IO/ISystemDirectories.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace Umbraco.Core.IO -{ - public interface ISystemDirectories - { - string Bin { get; } - string Config { get; } - string Data { get; } - string TempData { get; } - string TempFileUploads { get; } - string TempImageUploads { get; } - string Install { get; } - string AppCode { get; } - string AppPlugins { get; } - string MvcViews { get; } - string PartialViews { get; } - string MacroPartials { get; } - string Media { get; } - string Scripts { get; } - string Css { get; } - string Umbraco { get; } - string Packages { get; } - string Preview { get; } - - /// - /// Gets the root path of the application - /// - string Root - { - get; - set; //Only required for unit tests - } - } -} diff --git a/src/Umbraco.Core/Composing/CompositionExtensions/FileSystems.cs b/src/Umbraco.Core/Composing/CompositionExtensions/FileSystems.cs index 27a8a03323..661c96a32f 100644 --- a/src/Umbraco.Core/Composing/CompositionExtensions/FileSystems.cs +++ b/src/Umbraco.Core/Composing/CompositionExtensions/FileSystems.cs @@ -90,7 +90,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions // register the IFileSystem supporting the IMediaFileSystem // THIS IS THE ONLY THING THAT NEEDS TO CHANGE, IN ORDER TO REPLACE THE UNDERLYING FILESYSTEM // and, SupportingFileSystem.For() returns the underlying filesystem - composition.SetMediaFileSystem(() => new PhysicalFileSystem(Current.SystemDirectories.Media)); + composition.SetMediaFileSystem(() => new PhysicalFileSystem(Current.IOHelper.Media)); return composition; } diff --git a/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs index bec5640860..b8fc37941a 100644 --- a/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs @@ -89,10 +89,9 @@ namespace Umbraco.Core.Composing.CompositionExtensions private static LocalizedTextServiceFileSources SourcesFactory(IFactory container) { - ISystemDirectories systemDirectories = new SystemDirectories(); - var mainLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(systemDirectories.Umbraco + "/config/lang/")); - var appPlugins = new DirectoryInfo(Current.IOHelper.MapPath(systemDirectories.AppPlugins)); - var configLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(systemDirectories.Config + "/lang/")); + var mainLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(IOHelper.Default.Umbraco + "/config/lang/")); + var appPlugins = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.AppPlugins)); + var configLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.Config + "/lang/")); var pluginLangFolders = appPlugins.Exists == false ? Enumerable.Empty() diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index 4604590a8f..afc2a93ea0 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -206,7 +206,6 @@ namespace Umbraco.Core.Composing => Factory.GetInstance(); public static readonly IIOHelper IOHelper = Umbraco.Core.IO.IOHelper.Default; - public static readonly ISystemDirectories SystemDirectories = new SystemDirectories(); #endregion } diff --git a/src/Umbraco.Core/ConfigsExtensions.cs b/src/Umbraco.Core/ConfigsExtensions.cs index a3e60457a2..59fcac6d1e 100644 --- a/src/Umbraco.Core/ConfigsExtensions.cs +++ b/src/Umbraco.Core/ConfigsExtensions.cs @@ -33,7 +33,7 @@ namespace Umbraco.Core public static void AddCoreConfigs(this Configs configs) { - var configDir = new DirectoryInfo(Current.IOHelper.MapPath(Current.SystemDirectories.Config)); + var configDir = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.Config)); configs.Add(() => new GlobalSettings()); configs.Add("umbracoConfiguration/settings"); diff --git a/src/Umbraco.Core/Configuration/GlobalSettings.cs b/src/Umbraco.Core/Configuration/GlobalSettings.cs index 0e024346af..4bd4f71447 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -171,7 +171,7 @@ namespace Umbraco.Core.Configuration /// Value of the setting to be saved. internal static void SaveSetting(string key, string value) { - var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", Current.SystemDirectories.Root)); + var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", Current.IOHelper.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -193,7 +193,7 @@ namespace Umbraco.Core.Configuration /// Key of the setting to be removed. internal static void RemoveSetting(string key) { - var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", Current.SystemDirectories.Root)); + var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", Current.IOHelper.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs index 2bc1e8d8c2..5c45b41f43 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs @@ -43,8 +43,8 @@ namespace Umbraco.Core.Configuration } var path = globalSettings.Path; - if (path.StartsWith(Current.SystemDirectories.Root)) // beware of TrimStart, see U4-2518 - path = path.Substring(Current.SystemDirectories.Root.Length); + if (path.StartsWith(Current.IOHelper.Root)) // beware of TrimStart, see U4-2518 + path = path.Substring(Current.IOHelper.Root.Length); return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower(); } diff --git a/src/Umbraco.Core/IO/FileSystems.cs b/src/Umbraco.Core/IO/FileSystems.cs index 88ed3b48ae..b50e53180c 100644 --- a/src/Umbraco.Core/IO/FileSystems.cs +++ b/src/Umbraco.Core/IO/FileSystems.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.IO { private readonly IFactory _container; private readonly ILogger _logger; - private readonly ISystemDirectories _systemDirectories; + private readonly IIOHelper _ioHelper; private readonly ConcurrentDictionary> _filesystems = new ConcurrentDictionary>(); @@ -34,11 +34,11 @@ namespace Umbraco.Core.IO #region Constructor // DI wants a public ctor - public FileSystems(IFactory container, ILogger logger) + public FileSystems(IFactory container, ILogger logger, IIOHelper ioHelper) { _container = container; _logger = logger; - _systemDirectories = Current.SystemDirectories; + _ioHelper = ioHelper; } // for tests only, totally unsafe @@ -122,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(Constants.SystemDirectories.MacroPartials); + var partialViewsFileSystem = new PhysicalFileSystem(Constants.SystemDirectories.PartialViews); + var stylesheetsFileSystem = new PhysicalFileSystem(_ioHelper.Css); + var scriptsFileSystem = new PhysicalFileSystem(_ioHelper.Scripts); + var mvcViewsFileSystem = new PhysicalFileSystem(Constants.SystemDirectories.MvcViews); _macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, "macro-partials", IsScoped); _partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, "partials", IsScoped); diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 3925e6d8d5..50fad1b6d5 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -7,19 +7,12 @@ using System.Configuration; using System.Linq; using System.Web; using System.Web.Hosting; -using System.IO.Compression; namespace Umbraco.Core.IO { public class IOHelper : IIOHelper { - private readonly ISystemDirectories _systemDirectories; - internal static IIOHelper Default { get; } = new IOHelper(new SystemDirectories()); - - public IOHelper(ISystemDirectories systemDirectories) - { - _systemDirectories = systemDirectories; - } + internal static IIOHelper Default { get; } = new IOHelper(); /// /// Gets or sets a value forcing Umbraco to consider it is non-hosted. @@ -45,10 +38,10 @@ namespace Umbraco.Core.IO string retval = virtualPath; if (virtualPath.StartsWith("~")) - retval = virtualPath.Replace("~", _systemDirectories.Root); + retval = virtualPath.Replace("~", Root); - if (virtualPath.StartsWith("/") && virtualPath.StartsWith(_systemDirectories.Root) == false) - retval = _systemDirectories.Root + "/" + virtualPath.TrimStart('/'); + if (virtualPath.StartsWith("/") && virtualPath.StartsWith(Root) == false) + retval = Root + "/" + virtualPath.TrimStart('/'); return retval; } @@ -63,11 +56,11 @@ namespace Umbraco.Core.IO public string ResolveUrl(string virtualPath) { if (virtualPath.StartsWith("~")) - return virtualPath.Replace("~", _systemDirectories.Root).Replace("//", "/"); + return virtualPath.Replace("~", Root).Replace("//", "/"); else if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute)) return virtualPath; else - return VirtualPathUtility.ToAbsolute(virtualPath, _systemDirectories.Root); + return VirtualPathUtility.ToAbsolute(virtualPath, Root); } public Attempt TryResolveUrl(string virtualPath) @@ -75,10 +68,10 @@ namespace Umbraco.Core.IO try { if (virtualPath.StartsWith("~")) - return Attempt.Succeed(virtualPath.Replace("~", _systemDirectories.Root).Replace("//", "/")); + return Attempt.Succeed(virtualPath.Replace("~", 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, Root)); } catch (Exception ex) { @@ -103,7 +96,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(Root))) return HostingEnvironment.MapPath(path); else return HostingEnvironment.MapPath("~/" + path.TrimStart('/')); @@ -166,7 +159,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(Root); if (filePath.StartsWith(mappedRoot) == false) filePath = MapPath(filePath); @@ -310,5 +303,36 @@ namespace Umbraco.Core.IO return path.EnsurePathIsApplicationRootPrefixed(); } + + public string Media => ReturnPath("umbracoMediaPath", "~/media"); + + public string Scripts => ReturnPath("umbracoScriptsPath", "~/scripts"); + + public string Css => ReturnPath("umbracoCssPath", "~/css"); + + public string Umbraco => ReturnPath("umbracoPath", "~/umbraco"); + + private string _root; + + /// + /// Gets the root path of the application + /// + public string Root + { + get + { + if (_root != null) return _root; + + var appPath = HttpRuntime.AppDomainAppVirtualPath; + // ReSharper disable once ConditionIsAlwaysTrueOrFalse + if (appPath == null || appPath == "/") appPath = string.Empty; + + _root = appPath; + + return _root; + } + //Only required for unit tests + set => _root = value; + } } } diff --git a/src/Umbraco.Core/IO/ShadowWrapper.cs b/src/Umbraco.Core/IO/ShadowWrapper.cs index aab65e0a25..379da60e10 100644 --- a/src/Umbraco.Core/IO/ShadowWrapper.cs +++ b/src/Umbraco.Core/IO/ShadowWrapper.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.IO { internal class ShadowWrapper : IFileSystem { - private static readonly string ShadowFsPath = Current.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"; + private static readonly string ShadowFsPath = Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"; private readonly Func _isScoped; private readonly IFileSystem _innerFileSystem; diff --git a/src/Umbraco.Core/IO/SystemDirectories.cs b/src/Umbraco.Core/IO/SystemDirectories.cs index 4a976f5675..bfdd3f33ed 100644 --- a/src/Umbraco.Core/IO/SystemDirectories.cs +++ b/src/Umbraco.Core/IO/SystemDirectories.cs @@ -4,65 +4,9 @@ using Umbraco.Core.Composing; namespace Umbraco.Core.IO { //all paths has a starting but no trailing / - public class SystemDirectories : ISystemDirectories + public class SystemDirectories { - public string Bin => "~/bin"; - public string Config => "~/config"; - public string Data => "~/App_Data"; - - public string TempData => Data + "/TEMP"; - - public string TempFileUploads => TempData + "/FileUploads"; - - public string TempImageUploads => TempFileUploads + "/rte"; - - public string Install => "~/install"; - - public string AppCode => "~/App_Code"; - - public string AppPlugins => "~/App_Plugins"; - - public string MvcViews => "~/Views"; - - public string PartialViews => MvcViews + "/Partials/"; - - public string MacroPartials => MvcViews + "/MacroPartials/"; - - public string Media => Current.IOHelper.ReturnPath("umbracoMediaPath", "~/media"); - - public string Scripts => Current.IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts"); - - public string Css => Current.IOHelper.ReturnPath("umbracoCssPath", "~/css"); - - public string Umbraco => Current.IOHelper.ReturnPath("umbracoPath", "~/umbraco"); - - public string Packages => Data + "/packages"; - - public string Preview => Data + "/preview"; - - private string _root; - - /// - /// Gets the root path of the application - /// - public string Root - { - get - { - if (_root != null) return _root; - - var appPath = HttpRuntime.AppDomainAppVirtualPath; - // ReSharper disable once ConditionIsAlwaysTrueOrFalse - if (appPath == null || appPath == "/") appPath = string.Empty; - - _root = appPath; - - return _root; - } - //Only required for unit tests - set => _root = value; - } } } diff --git a/src/Umbraco.Core/IO/SystemFiles.cs b/src/Umbraco.Core/IO/SystemFiles.cs index 7df39eac6c..132945d130 100644 --- a/src/Umbraco.Core/IO/SystemFiles.cs +++ b/src/Umbraco.Core/IO/SystemFiles.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.IO { public class SystemFiles { - public static string TinyMceConfig => Current.SystemDirectories.Config + "/tinyMceConfig.config"; + public static string TinyMceConfig => Constants.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) diff --git a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs index a7c6b38c1c..a0421a27c1 100644 --- a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs @@ -283,7 +283,7 @@ namespace Umbraco.Core.Migrations.Install if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullOrEmptyException(nameof(providerName)); var fileSource = "web.config"; - var fileName = Current.IOHelper.MapPath(Current.SystemDirectories.Root +"/" + fileSource); + var fileName = Current.IOHelper.MapPath(Current.IOHelper.Root +"/" + fileSource); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); if (xml.Root == null) throw new Exception($"Invalid {fileSource} file (no root)."); @@ -296,7 +296,7 @@ namespace Umbraco.Core.Migrations.Install if (configSourceAttribute != null) { fileSource = configSourceAttribute.Value; - fileName = Current.IOHelper.MapPath(Current.SystemDirectories.Root + "/" + fileSource); + fileName = Current.IOHelper.MapPath(Current.IOHelper.Root + "/" + fileSource); if (!File.Exists(fileName)) throw new Exception($"Invalid configSource \"{fileSource}\" (no such file)."); diff --git a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs index 80857ab5eb..f53fb872a0 100644 --- a/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs +++ b/src/Umbraco.Core/Packaging/CompiledPackageXmlParser.cs @@ -138,9 +138,9 @@ namespace Umbraco.Core.Packaging if (path.Contains("[$")) { //this is experimental and undocumented... - path = path.Replace("[$UMBRACO]", Current.SystemDirectories.Umbraco); - path = path.Replace("[$CONFIG]", Current.SystemDirectories.Config); - path = path.Replace("[$DATA]", Current.SystemDirectories.Data); + path = path.Replace("[$UMBRACO]", Current.IOHelper.Umbraco); + path = path.Replace("[$CONFIG]", Constants.SystemDirectories.Config); + path = path.Replace("[$DATA]", Constants.SystemDirectories.Data); } return path; } diff --git a/src/Umbraco.Core/Packaging/PackageDataInstallation.cs b/src/Umbraco.Core/Packaging/PackageDataInstallation.cs index 8cd0225327..3a87b28d0e 100644 --- a/src/Umbraco.Core/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Core/Packaging/PackageDataInstallation.cs @@ -1318,7 +1318,7 @@ namespace Umbraco.Core.Packaging private string ViewPath(string alias) { - return Current.SystemDirectories.MvcViews + "/" + alias.Replace(" ", "") + ".cshtml"; + return Constants.SystemDirectories.MvcViews + "/" + alias.Replace(" ", "") + ".cshtml"; } #endregion diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index 24455308c8..e4ff8dbf4b 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -70,9 +70,9 @@ namespace Umbraco.Core.Packaging _logger = logger; _packageRepositoryFileName = packageRepositoryFileName; - _tempFolderPath = tempFolderPath ?? Current.SystemDirectories.TempData.EnsureEndsWith('/') + "PackageFiles"; - _packagesFolderPath = packagesFolderPath ?? Current.SystemDirectories.Packages; - _mediaFolderPath = mediaFolderPath ?? Current.SystemDirectories.Media + "/created-packages"; + _tempFolderPath = tempFolderPath ?? Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "PackageFiles"; + _packagesFolderPath = packagesFolderPath ?? Constants.SystemDirectories.Packages; + _mediaFolderPath = mediaFolderPath ?? Current.IOHelper.Media + "/created-packages"; _parser = new PackageDefinitionXmlParser(logger); } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/PartialViewRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/PartialViewRepository.cs index bee7260b53..fc6f60eb1d 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/PartialViewRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/PartialViewRepository.cs @@ -103,7 +103,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement } // validate path & extension - var validDir = Current.SystemDirectories.MvcViews; + var validDir = Constants.SystemDirectories.MvcViews; var isValidPath = Current.IOHelper.VerifyEditPath(fullPath, validDir); var isValidExtension = Current.IOHelper.VerifyFileExtension(fullPath, ValidExtensions); return isValidPath && isValidExtension; diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ScriptRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ScriptRepository.cs index 3acdb331a1..6ae1dea5c6 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ScriptRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ScriptRepository.cs @@ -15,13 +15,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement internal class ScriptRepository : FileRepository, IScriptRepository { private readonly IIOHelper _ioHelper; - private readonly ISystemDirectories _systemDirectories; public ScriptRepository(IFileSystems fileSystems, IIOHelper ioHelper) : base(fileSystems.ScriptsFileSystem) { _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); - _systemDirectories = Current.SystemDirectories; } #region Implementation of IRepository @@ -106,7 +104,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement } // validate path & extension - var validDir = _systemDirectories.Scripts; + var validDir = _ioHelper.Scripts; var isValidPath = _ioHelper.VerifyEditPath(fullPath, validDir); var validExts = new[] {"js"}; var isValidExtension = _ioHelper.VerifyFileExtension(script.Path, validExts); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/StylesheetRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/StylesheetRepository.cs index de661d1f7e..b722434ad1 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/StylesheetRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/StylesheetRepository.cs @@ -121,7 +121,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement } // validate path and extension - var validDir = Current.SystemDirectories.Css; + var validDir = _ioHelper.Css; var isValidPath = _ioHelper.VerifyEditPath(fullPath, validDir); var isValidExtension = _ioHelper.VerifyFileExtension(stylesheet.Path, ValidExtensions); return isValidPath && isValidExtension; diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs index b45ec5048b..ac91134d2b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs @@ -585,7 +585,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var path = template.VirtualPath; // get valid paths - var validDirs = new[] { Current.SystemDirectories.MvcViews }; + var validDirs = new[] { Constants.SystemDirectories.MvcViews }; // get valid extensions var validExts = new List(); diff --git a/src/Umbraco.Core/Runtime/CoreInitialComponent.cs b/src/Umbraco.Core/Runtime/CoreInitialComponent.cs index 0cb7024e66..132deb8c8c 100644 --- a/src/Umbraco.Core/Runtime/CoreInitialComponent.cs +++ b/src/Umbraco.Core/Runtime/CoreInitialComponent.cs @@ -9,11 +9,11 @@ namespace Umbraco.Core.Runtime { // ensure we have some essential directories // every other component can then initialize safely - Current.IOHelper.EnsurePathExists("~/App_Data"); - Current.IOHelper.EnsurePathExists(Current.SystemDirectories.Media); - Current.IOHelper.EnsurePathExists(Current.SystemDirectories.MvcViews); - Current.IOHelper.EnsurePathExists(Current.SystemDirectories.MvcViews + "/Partials"); - Current.IOHelper.EnsurePathExists(Current.SystemDirectories.MvcViews + "/MacroPartials"); + Current.IOHelper.EnsurePathExists(Constants.SystemDirectories.Data); + Current.IOHelper.EnsurePathExists(Current.IOHelper.Media); + Current.IOHelper.EnsurePathExists(Constants.SystemDirectories.MvcViews); + Current.IOHelper.EnsurePathExists(Constants.SystemDirectories.PartialViews); + Current.IOHelper.EnsurePathExists(Constants.SystemDirectories.MacroPartials); } public void Terminate() diff --git a/src/Umbraco.Core/Services/Implement/FileService.cs b/src/Umbraco.Core/Services/Implement/FileService.cs index afc30e09ce..8c038d72d9 100644 --- a/src/Umbraco.Core/Services/Implement/FileService.cs +++ b/src/Umbraco.Core/Services/Implement/FileService.cs @@ -664,7 +664,7 @@ namespace Umbraco.Core.Services.Implement public IEnumerable GetPartialViewSnippetNames(params string[] filterNames) { - var snippetPath = Current.IOHelper.MapPath($"{Current.SystemDirectories.Umbraco}/PartialViewMacros/Templates/"); + var snippetPath = Current.IOHelper.MapPath($"{Current.IOHelper.Umbraco}/PartialViewMacros/Templates/"); var files = Directory.GetFiles(snippetPath, "*.cshtml") .Select(Path.GetFileNameWithoutExtension) .Except(filterNames, StringComparer.InvariantCultureIgnoreCase) @@ -898,7 +898,7 @@ namespace Umbraco.Core.Services.Implement fileName += ".cshtml"; } - var snippetPath = Current.IOHelper.MapPath($"{Current.SystemDirectories.Umbraco}/PartialViewMacros/Templates/{fileName}"); + var snippetPath = Current.IOHelper.MapPath($"{Current.IOHelper.Umbraco}/PartialViewMacros/Templates/{fileName}"); return System.IO.File.Exists(snippetPath) ? Attempt.Succeed(snippetPath) : Attempt.Fail(); diff --git a/src/Umbraco.Core/Services/Implement/NotificationService.cs b/src/Umbraco.Core/Services/Implement/NotificationService.cs index fa7b14abe4..874e92ef86 100644 --- a/src/Umbraco.Core/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Core/Services/Implement/NotificationService.cs @@ -384,7 +384,7 @@ namespace Umbraco.Core.Services.Implement var protocol = _globalSettings.UseHttps ? "https" : "http"; var subjectVars = new NotificationEmailSubjectParams( - string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(Current.SystemDirectories.Umbraco)), + string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(Current.IOHelper.Umbraco)), actionName, content.Name); @@ -400,7 +400,7 @@ namespace Umbraco.Core.Services.Implement string.Concat(content.Id, ".aspx"), protocol), performingUser.Name, - string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(Current.SystemDirectories.Umbraco)), + string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(Current.IOHelper.Umbraco)), summary.ToString()); // create the mail message diff --git a/src/Umbraco.Core/Services/Implement/PackagingService.cs b/src/Umbraco.Core/Services/Implement/PackagingService.cs index f68685ee57..6744b3234a 100644 --- a/src/Umbraco.Core/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Core/Services/Implement/PackagingService.cs @@ -64,7 +64,7 @@ namespace Umbraco.Core.Services.Implement //successful if (bytes.Length > 0) { - var packagePath = Current.IOHelper.MapPath(Current.SystemDirectories.Packages); + var packagePath = Current.IOHelper.MapPath(Constants.SystemDirectories.Packages); // Check for package directory if (Directory.Exists(packagePath) == false) diff --git a/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs b/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs index b58aefe5dd..1668476d96 100644 --- a/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs +++ b/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs @@ -98,7 +98,7 @@ namespace Umbraco.Core.Sync : ""; var ssl = globalSettings.UseHttps ? "s" : ""; // force, whatever the first request - var url = "http" + ssl + "://" + request.ServerVariables["SERVER_NAME"] + port + Current.IOHelper.ResolveUrl(Current.SystemDirectories.Umbraco); + var url = "http" + ssl + "://" + request.ServerVariables["SERVER_NAME"] + port + Current.IOHelper.ResolveUrl(Current.IOHelper.Umbraco); return url.TrimEnd('/'); } diff --git a/src/Umbraco.Examine/LuceneIndexCreator.cs b/src/Umbraco.Examine/LuceneIndexCreator.cs index f310ca9229..d6bf8c262c 100644 --- a/src/Umbraco.Examine/LuceneIndexCreator.cs +++ b/src/Umbraco.Examine/LuceneIndexCreator.cs @@ -36,7 +36,7 @@ namespace Umbraco.Examine public virtual Lucene.Net.Store.Directory CreateFileSystemLuceneDirectory(string folderName) { - var dirInfo = new DirectoryInfo(Path.Combine(Current.IOHelper.MapPath(Current.SystemDirectories.TempData), "ExamineIndexes", folderName)); + var dirInfo = new DirectoryInfo(Path.Combine(Current.IOHelper.MapPath(Constants.SystemDirectories.TempData), "ExamineIndexes", folderName)); if (!dirInfo.Exists) System.IO.Directory.CreateDirectory(dirInfo.FullName); diff --git a/src/Umbraco.Examine/LuceneIndexDiagnostics.cs b/src/Umbraco.Examine/LuceneIndexDiagnostics.cs index 0ed2d88085..3b23b57709 100644 --- a/src/Umbraco.Examine/LuceneIndexDiagnostics.cs +++ b/src/Umbraco.Examine/LuceneIndexDiagnostics.cs @@ -11,10 +11,13 @@ namespace Umbraco.Examine { public class LuceneIndexDiagnostics : IIndexDiagnostics { + private IIOHelper _ioHelper; + public LuceneIndexDiagnostics(LuceneIndex index, ILogger logger) { Index = index; Logger = logger; + _ioHelper = Current.IOHelper; } public LuceneIndex Index { get; } @@ -72,7 +75,7 @@ namespace Umbraco.Examine if (luceneDir is FSDirectory fsDir) { - d[nameof(UmbracoExamineIndex.LuceneIndexFolder)] = fsDir.Directory.ToString().ToLowerInvariant().TrimStart(Current.IOHelper.MapPath(Current.SystemDirectories.Root).ToLowerInvariant()).Replace("\\", "/").EnsureStartsWith('/'); + d[nameof(UmbracoExamineIndex.LuceneIndexFolder)] = fsDir.Directory.ToString().ToLowerInvariant().TrimStart(_ioHelper.MapPath(_ioHelper.Root).ToLowerInvariant()).Replace("\\", "/").EnsureStartsWith('/'); } return d; diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 5a437e402f..28d9e19cef 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -34,7 +34,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 fs = new FileSystems(mock.Object, logger); + var fs = new FileSystems(mock.Object, logger, IOHelper.Default); var p = new ScopeProvider(f, fs, logger, typeFinder); mock.Setup(x => x.GetInstance(typeof (ILogger))).Returns(logger); diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index bab6a13dad..2b5611deec 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -17,13 +17,13 @@ namespace Umbraco.Tests.Configurations public override void SetUp() { base.SetUp(); - _root = Current.SystemDirectories.Root; + _root = Current.IOHelper.Root; } public override void TearDown() { base.TearDown(); - Current.SystemDirectories.Root = _root; + Current.IOHelper.Root = _root; } [Test] @@ -51,7 +51,7 @@ namespace Umbraco.Tests.Configurations var globalSettingsMock = Mock.Get(globalSettings); globalSettingsMock.Setup(x => x.Path).Returns(() => Current.IOHelper.ResolveUrl(path)); - Current.SystemDirectories.Root = rootPath; + Current.IOHelper.Root = rootPath; Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache()); } diff --git a/src/Umbraco.Tests/CoreThings/UriExtensionsTests.cs b/src/Umbraco.Tests/CoreThings/UriExtensionsTests.cs index d3d5548a1d..780e204aad 100644 --- a/src/Umbraco.Tests/CoreThings/UriExtensionsTests.cs +++ b/src/Umbraco.Tests/CoreThings/UriExtensionsTests.cs @@ -15,13 +15,13 @@ namespace Umbraco.Tests.CoreThings [SetUp] public void SetUp() { - _root = Current.SystemDirectories.Root; + _root = Current.IOHelper.Root; } [TearDown] public void TearDown() { - Current.SystemDirectories.Root = _root; + Current.IOHelper.Root = _root; } [TestCase("http://www.domain.com/umbraco", "", true)] @@ -45,7 +45,7 @@ namespace Umbraco.Tests.CoreThings [TestCase("http://www.domain.com/umbraco/test/legacyAjaxCalls.ashx?some=query&blah=js", "", true)] public void Is_Back_Office_Request(string input, string virtualPath, bool expected) { - Current.SystemDirectories.Root = virtualPath; + Current.IOHelper.Root = virtualPath; var globalConfig = SettingsForTests.GenerateMockGlobalSettings(); var source = new Uri(input); Assert.AreEqual(expected, source.IsBackOfficeRequest(virtualPath, globalConfig)); diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 254371ae32..a7d4bd7c3b 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -34,6 +34,7 @@ namespace Umbraco.Tests.IO composition.Register(_ => Mock.Of()); composition.Register(_ => Mock.Of()); composition.RegisterUnique(); + composition.RegisterUnique(IOHelper.Default); composition.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); diff --git a/src/Umbraco.Tests/IO/IoHelperTests.cs b/src/Umbraco.Tests/IO/IoHelperTests.cs index 5ca335db25..3b3af2d4ce 100644 --- a/src/Umbraco.Tests/IO/IoHelperTests.cs +++ b/src/Umbraco.Tests/IO/IoHelperTests.cs @@ -9,7 +9,7 @@ namespace Umbraco.Tests.IO [TestFixture] public class IoHelperTests { - private ISystemDirectories SystemDirectories => Current.SystemDirectories; + private IIOHelper _ioHelper => IOHelper.Default; [TestCase("~/Scripts", "/Scripts", null)] [TestCase("/Scripts", "/Scripts", null)] @@ -35,17 +35,17 @@ namespace Umbraco.Tests.IO { //System.Diagnostics.Debugger.Break(); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Bin, true), Current.IOHelper.MapPath(SystemDirectories.Bin, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Config, true), Current.IOHelper.MapPath(SystemDirectories.Config, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Css, true), Current.IOHelper.MapPath(SystemDirectories.Css, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Data, true), Current.IOHelper.MapPath(SystemDirectories.Data, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Install, true), Current.IOHelper.MapPath(SystemDirectories.Install, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Media, true), Current.IOHelper.MapPath(SystemDirectories.Media, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Packages, true), Current.IOHelper.MapPath(SystemDirectories.Packages, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Preview, true), Current.IOHelper.MapPath(SystemDirectories.Preview, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Root, true), Current.IOHelper.MapPath(SystemDirectories.Root, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Scripts, true), Current.IOHelper.MapPath(SystemDirectories.Scripts, false)); - Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Umbraco, true), Current.IOHelper.MapPath(SystemDirectories.Umbraco, false)); + Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Bin, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Bin, false)); + Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Config, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Config, false)); + Assert.AreEqual(Current.IOHelper.MapPath(_ioHelper.Css, true), Current.IOHelper.MapPath(_ioHelper.Css, false)); + Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Data, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Data, false)); + Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Install, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Install, false)); + Assert.AreEqual(Current.IOHelper.MapPath(_ioHelper.Media, true), Current.IOHelper.MapPath(_ioHelper.Media, false)); + Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Packages, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Packages, false)); + Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Preview, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Preview, false)); + Assert.AreEqual(Current.IOHelper.MapPath(_ioHelper.Root, true), Current.IOHelper.MapPath(_ioHelper.Root, false)); + Assert.AreEqual(Current.IOHelper.MapPath(_ioHelper.Scripts, true), Current.IOHelper.MapPath(_ioHelper.Scripts, false)); + Assert.AreEqual(Current.IOHelper.MapPath(_ioHelper.Umbraco, true), Current.IOHelper.MapPath(_ioHelper.Umbraco, false)); } [Test] diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 2e8c6c110f..af7cfca41f 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -41,7 +41,7 @@ namespace Umbraco.Tests.IO private static void ClearFiles() { TestHelper.DeleteDirectory(Current.IOHelper.MapPath("FileSysTests")); - TestHelper.DeleteDirectory(Current.IOHelper.MapPath(Current.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); + TestHelper.DeleteDirectory(Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); } private static string NormPath(string path) @@ -388,7 +388,7 @@ namespace Umbraco.Tests.IO var logger = Mock.Of(); var path = Current.IOHelper.MapPath("FileSysTests"); - var shadowfs = Current.IOHelper.MapPath(Current.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var shadowfs = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); Directory.CreateDirectory(shadowfs); @@ -397,7 +397,7 @@ namespace Umbraco.Tests.IO var phy = new PhysicalFileSystem(path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, logger, IOHelper.Default) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem(phy); var sw = (ShadowWrapper) fs.InnerFileSystem; @@ -483,7 +483,7 @@ namespace Umbraco.Tests.IO var logger = Mock.Of(); var path = Current.IOHelper.MapPath("FileSysTests"); - var shadowfs = Current.IOHelper.MapPath(Current.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var shadowfs = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; @@ -491,7 +491,7 @@ namespace Umbraco.Tests.IO var phy = new PhysicalFileSystem(path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, logger, IOHelper.Default) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem( phy); var sw = (ShadowWrapper) fs.InnerFileSystem; @@ -536,7 +536,7 @@ namespace Umbraco.Tests.IO var logger = Mock.Of(); var path = Current.IOHelper.MapPath("FileSysTests"); - var shadowfs = Current.IOHelper.MapPath(Current.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var shadowfs = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; @@ -544,7 +544,7 @@ namespace Umbraco.Tests.IO var phy = new PhysicalFileSystem(path, "ignore"); var container = Mock.Of(); - var fileSystems = new FileSystems(container, logger) { IsScoped = () => scopedFileSystems }; + var fileSystems = new FileSystems(container, logger, IOHelper.Default) { IsScoped = () => scopedFileSystems }; var fs = fileSystems.GetFileSystem( phy); var sw = (ShadowWrapper)fs.InnerFileSystem; diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs index f023eb9446..5812fde11c 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs @@ -108,7 +108,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache _previewXml = _xmlStore.GetPreviewXml(contentId, includeSubs); // make sure the preview folder exists - var dir = new DirectoryInfo(Current.IOHelper.MapPath(Current.SystemDirectories.Preview)); + var dir = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.Preview)); if (dir.Exists == false) dir.Create(); @@ -122,7 +122,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache // get the full path to the preview set private static string GetPreviewSetPath(int userId, Guid previewSet) { - return Current.IOHelper.MapPath(Path.Combine(Current.SystemDirectories.Preview, userId + "_" + previewSet + ".config")); + return Current.IOHelper.MapPath(Path.Combine(Constants.SystemDirectories.Preview, userId + "_" + previewSet + ".config")); } // deletes files for the user, and files accessed more than one hour ago diff --git a/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs b/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs index 8c47d709f2..123e4c33ca 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/PartialViewRepositoryTests.cs @@ -1,6 +1,7 @@ using System.Linq; using Moq; using NUnit.Framework; +using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Models; @@ -21,7 +22,7 @@ namespace Umbraco.Tests.Persistence.Repositories { base.SetUp(); - _fileSystem = new PhysicalFileSystem(Current.SystemDirectories.MvcViews + "/Partials/"); + _fileSystem = new PhysicalFileSystem(Constants.SystemDirectories.MvcViews + "/Partials/"); } protected override void Compose() diff --git a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs index cd3a2dae2b..41a3e9cb03 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ScriptRepositoryTest.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(Current.SystemDirectories.Scripts); + _fileSystem = new PhysicalFileSystem(Current.IOHelper.Scripts); Mock.Get(_fileSystems).Setup(x => x.ScriptsFileSystem).Returns(_fileSystem); using (var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");")) { diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index a21222e4d2..97b411806d 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - _fileSystem = new PhysicalFileSystem(Current.SystemDirectories.Css); + _fileSystem = new PhysicalFileSystem(Current.IOHelper.Css); Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); diff --git a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs index c7eb9ed4f6..b86719e7e1 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Persistence.Repositories base.SetUp(); _fileSystems = Mock.Of(); - var viewsFileSystem = new PhysicalFileSystem(Current.SystemDirectories.MvcViews); + var viewsFileSystem = new PhysicalFileSystem(Constants.SystemDirectories.MvcViews); Mock.Get(_fileSystems).Setup(x => x.MvcViewsFileSystem).Returns(viewsFileSystem); } @@ -527,7 +527,7 @@ namespace Umbraco.Tests.Persistence.Repositories _fileSystems = null; //Delete all files - var fsViews = new PhysicalFileSystem(Current.SystemDirectories.MvcViews); + var fsViews = new PhysicalFileSystem(Constants.SystemDirectories.MvcViews); var views = fsViews.GetFiles("", "*.cshtml"); foreach (var file in views) fsViews.DeleteFile(file); diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index 74e79c4ce3..5c6ae779be 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Scoping _testObjects = new TestObjects(register); - composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance())); + composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance(), IOHelper.Default)); composition.WithCollectionBuilder(); composition.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); diff --git a/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs b/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs index 1f49e83202..ece78c0852 100644 --- a/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Scoping { TestHelper.DeleteDirectory(Current.IOHelper.MapPath("media")); TestHelper.DeleteDirectory(Current.IOHelper.MapPath("FileSysTests")); - TestHelper.DeleteDirectory(Current.IOHelper.MapPath(Current.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); + TestHelper.DeleteDirectory(Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); } [TestCase(true)] diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index abd4e0f91b..785315063e 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -62,12 +62,12 @@ namespace Umbraco.Tests.TestHelpers public static void InitializeContentDirectories() { - CreateDirectories(new[] { Current.SystemDirectories.MvcViews, Current.SystemDirectories.Media, Current.SystemDirectories.AppPlugins }); + CreateDirectories(new[] { Constants.SystemDirectories.MvcViews, Current.IOHelper.Media, Constants.SystemDirectories.AppPlugins }); } public static void CleanContentDirectories() { - CleanDirectories(new[] { Current.SystemDirectories.MvcViews, Current.SystemDirectories.Media }); + CleanDirectories(new[] { Constants.SystemDirectories.MvcViews, Current.IOHelper.Media }); } public static void CreateDirectories(string[] directories) @@ -84,7 +84,7 @@ namespace Umbraco.Tests.TestHelpers { var preserves = new Dictionary { - { Current.SystemDirectories.MvcViews, new[] {"dummy.txt"} } + { Constants.SystemDirectories.MvcViews, new[] {"dummy.txt"} } }; foreach (var directory in directories) { diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 0e838bbf24..d030d7e22c 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -118,9 +118,9 @@ namespace Umbraco.Tests.TestHelpers var localizedTextService = GetLazyService(factory, c => new LocalizedTextService( new Lazy(() => { - var mainLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(Current.SystemDirectories.Umbraco + "/config/lang/")); - var appPlugins = new DirectoryInfo(Current.IOHelper.MapPath(Current.SystemDirectories.AppPlugins)); - var configLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(Current.SystemDirectories.Config + "/lang/")); + var mainLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(Current.IOHelper.Umbraco + "/config/lang/")); + var appPlugins = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.AppPlugins)); + var configLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.Config + "/lang/")); var pluginLangFolders = appPlugins.Exists == false ? Enumerable.Empty() @@ -242,7 +242,7 @@ namespace Umbraco.Tests.TestHelpers } typeFinder = typeFinder ?? new TypeFinder(logger); - fileSystems = fileSystems ?? new FileSystems(Current.Factory, logger); + fileSystems = fileSystems ?? new FileSystems(Current.Factory, logger, IOHelper.Default); var scopeProvider = new ScopeProvider(databaseFactory, fileSystems, logger, typeFinder); return scopeProvider; } diff --git a/src/Umbraco.Tests/Views/textpage.cshtml b/src/Umbraco.Tests/Views/textpage.cshtml new file mode 100644 index 0000000000..d7b4dce307 --- /dev/null +++ b/src/Umbraco.Tests/Views/textpage.cshtml @@ -0,0 +1,4 @@ +@inherits Umbraco.Web.Mvc.UmbracoViewPage +@{ + Layout = null; +} \ No newline at end of file diff --git a/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml b/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml index 9f7a532fe0..8f0a31850e 100644 --- a/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml @@ -33,7 +33,7 @@ Umbraco @Html.RenderCssHere( - new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(Current.SystemDirectories.Umbraco))) + new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(Current.IOHelper.Umbraco))) @*Because we're lazy loading angular js, the embedded cloak style will not be loaded initially, but we need it*@