diff --git a/src/Umbraco.Core/Compose/ManifestWatcherComponent.cs b/src/Umbraco.Core/Compose/ManifestWatcherComponent.cs index 4821a1dd94..97e27e9e23 100644 --- a/src/Umbraco.Core/Compose/ManifestWatcherComponent.cs +++ b/src/Umbraco.Core/Compose/ManifestWatcherComponent.cs @@ -22,13 +22,13 @@ namespace Umbraco.Core.Compose } public void Initialize() - { + { if (_runtimeState.Debug == false) return; //if (ApplicationContext.Current.IsConfigured == false || GlobalSettings.DebugMode == false) // return; - var appPlugins = IOHelper.MapPath("~/App_Plugins/"); + var appPlugins = Current.IOHelper.MapPath("~/App_Plugins/"); if (Directory.Exists(appPlugins) == false) return; _mw = new ManifestWatcher(_logger); diff --git a/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs index d252c58730..9d7d0a191d 100644 --- a/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs @@ -71,7 +71,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions new PackageInstallation( factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), - new DirectoryInfo(IOHelper.GetRootDirectorySafe()))); + new DirectoryInfo(Current.IOHelper.GetRootDirectorySafe()))); return composition; } @@ -89,9 +89,9 @@ namespace Umbraco.Core.Composing.CompositionExtensions private static LocalizedTextServiceFileSources SourcesFactory(IFactory container) { - var mainLangFolder = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Umbraco + "/config/lang/")); - var appPlugins = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins)); - var configLangFolder = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config + "/lang/")); + 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 pluginLangFolders = appPlugins.Exists == false ? Enumerable.Empty() diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index f12bf0dd63..b289e2aaf5 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -205,6 +205,9 @@ namespace Umbraco.Core.Composing public static IVariationContextAccessor VariationContextAccessor => Factory.GetInstance(); + public static IIOHelper IOHelper + => new IOHelper(); + #endregion } } diff --git a/src/Umbraco.Core/Composing/TypeFinder.cs b/src/Umbraco.Core/Composing/TypeFinder.cs index 5ad1e43580..c07f3ae0f4 100644 --- a/src/Umbraco.Core/Composing/TypeFinder.cs +++ b/src/Umbraco.Core/Composing/TypeFinder.cs @@ -78,7 +78,7 @@ namespace Umbraco.Core.Composing HashSet assemblies = null; try { - var isHosted = IOHelper.IsHosted; + var isHosted = Current.IOHelper.IsHosted; try { @@ -97,7 +97,7 @@ namespace Umbraco.Core.Composing { //NOTE: we cannot use AppDomain.CurrentDomain.GetAssemblies() because this only returns assemblies that have // already been loaded in to the app domain, instead we will look directly into the bin folder and load each one. - var binFolder = IOHelper.GetRootDirectoryBinFolder(); + var binFolder = Current.IOHelper.GetRootDirectoryBinFolder(); var binAssemblyFiles = Directory.GetFiles(binFolder, "*.dll", SearchOption.TopDirectoryOnly).ToList(); //var binFolder = Assembly.GetExecutingAssembly().GetAssemblyFile().Directory; //var binAssemblyFiles = Directory.GetFiles(binFolder.FullName, "*.dll", SearchOption.TopDirectoryOnly).ToList(); @@ -135,7 +135,7 @@ namespace Umbraco.Core.Composing //here we are trying to get the App_Code assembly var fileExtensions = new[] { ".cs", ".vb" }; //only vb and cs files are supported - var appCodeFolder = new DirectoryInfo(IOHelper.MapPath(IOHelper.ResolveUrl("~/App_code"))); + var appCodeFolder = new DirectoryInfo(Current.IOHelper.MapPath(Current.IOHelper.ResolveUrl("~/App_code"))); //check if the folder exists and if there are any files in it with the supported file extensions if (appCodeFolder.Exists && fileExtensions.Any(x => appCodeFolder.GetFiles("*" + x).Any())) { diff --git a/src/Umbraco.Core/Composing/TypeLoader.cs b/src/Umbraco.Core/Composing/TypeLoader.cs index fe7a561eca..d2dffb8ffc 100644 --- a/src/Umbraco.Core/Composing/TypeLoader.cs +++ b/src/Umbraco.Core/Composing/TypeLoader.cs @@ -181,11 +181,11 @@ namespace Umbraco.Core.Composing _currentAssembliesHash = GetFileHash(new List> { // the bin folder and everything in it - new Tuple(new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Bin)), false), + new Tuple(new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Bin)), false), // the app code folder and everything in it - new Tuple(new DirectoryInfo(IOHelper.MapPath("~/App_Code")), false), + new Tuple(new DirectoryInfo(Current.IOHelper.MapPath("~/App_Code")), false), // global.asax (the app domain also monitors this, if it changes will do a full restart) - new Tuple(new FileInfo(IOHelper.MapPath("~/global.asax")), false) + new Tuple(new FileInfo(Current.IOHelper.MapPath("~/global.asax")), false) }, _logger); return _currentAssembliesHash; diff --git a/src/Umbraco.Core/ConfigsExtensions.cs b/src/Umbraco.Core/ConfigsExtensions.cs index d1672c6c7f..10293d1171 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(IOHelper.MapPath(SystemDirectories.Config)); + var configDir = new DirectoryInfo(Current.IOHelper.MapPath(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 a888e3c42b..f2438065a4 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettings.cs @@ -6,6 +6,7 @@ using System.Web; using System.Web.Configuration; using System.Web.Hosting; using System.Xml.Linq; +using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Core.Configuration @@ -140,7 +141,7 @@ namespace Umbraco.Core.Configuration get { return ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.Path) - ? IOHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path]) + ? Current.IOHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path]) : string.Empty; } } @@ -170,7 +171,7 @@ namespace Umbraco.Core.Configuration /// Value of the setting to be saved. internal static void SaveSetting(string key, string value) { - var fileName = IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root)); + var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -192,7 +193,7 @@ namespace Umbraco.Core.Configuration /// Key of the setting to be removed. internal static void RemoveSetting(string key) { - var fileName = IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root)); + var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root)); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single(); @@ -319,7 +320,7 @@ namespace Umbraco.Core.Configuration //case LocalTempStorage.Default: //case LocalTempStorage.Unknown: default: - return _localTempPath = IOHelper.MapPath("~/App_Data/TEMP"); + return _localTempPath = Current.IOHelper.MapPath("~/App_Data/TEMP"); } } } diff --git a/src/Umbraco.Core/ContentExtensions.cs b/src/Umbraco.Core/ContentExtensions.cs index a7d40b0b7d..8e404402d0 100644 --- a/src/Umbraco.Core/ContentExtensions.cs +++ b/src/Umbraco.Core/ContentExtensions.cs @@ -148,7 +148,7 @@ namespace Umbraco.Core if (filename == null || filestream == null) return; // get a safe & clean filename - filename = IOHelper.SafeFileName(filename); + filename = Current.IOHelper.SafeFileName(filename); if (string.IsNullOrWhiteSpace(filename)) return; filename = filename.ToLower(); diff --git a/src/Umbraco.Core/Diagnostics/MiniDump.cs b/src/Umbraco.Core/Diagnostics/MiniDump.cs index e8c2e82f94..92b6e8cbda 100644 --- a/src/Umbraco.Core/Diagnostics/MiniDump.cs +++ b/src/Umbraco.Core/Diagnostics/MiniDump.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; +using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Core.Diagnostics @@ -109,7 +110,7 @@ namespace Umbraco.Core.Diagnostics // filter everywhere in our code = not! var stacktrace = withException ? Environment.StackTrace : string.Empty; - var filepath = IOHelper.MapPath("~/App_Data/MiniDump"); + var filepath = Current.IOHelper.MapPath("~/App_Data/MiniDump"); if (Directory.Exists(filepath) == false) Directory.CreateDirectory(filepath); @@ -125,7 +126,7 @@ namespace Umbraco.Core.Diagnostics { lock (LockO) { - var filepath = IOHelper.MapPath("~/App_Data/MiniDump"); + var filepath = Current.IOHelper.MapPath("~/App_Data/MiniDump"); if (Directory.Exists(filepath) == false) return true; var count = Directory.GetFiles(filepath, "*.dmp").Length; return count < 8; diff --git a/src/Umbraco.Core/IO/IIOHelper.cs b/src/Umbraco.Core/IO/IIOHelper.cs new file mode 100644 index 0000000000..c66e6137be --- /dev/null +++ b/src/Umbraco.Core/IO/IIOHelper.cs @@ -0,0 +1,84 @@ +using System.Collections.Generic; + +namespace Umbraco.Core.IO +{ + public interface IIOHelper + { + bool ForceNotHosted { get; set; } + + /// + /// Gets a value indicating whether Umbraco is hosted. + /// + bool IsHosted { get; } + + char DirSepChar { get; } + string FindFile(string virtualPath); + string ResolveVirtualUrl(string path); + string ResolveUrl(string virtualPath); + Attempt TryResolveUrl(string virtualPath); + string MapPath(string path, bool useHttpContext); + string MapPath(string path); + string ReturnPath(string settingsKey, string standardPath, bool useTilde); + string ReturnPath(string settingsKey, string standardPath); + + /// + /// Verifies that the current filepath matches a directory where the user is allowed to edit a file. + /// + /// The filepath to validate. + /// The valid directory. + /// A value indicating whether the filepath is valid. + bool VerifyEditPath(string filePath, string validDir); + + /// + /// Verifies that the current filepath matches one of several directories where the user is allowed to edit a file. + /// + /// The filepath to validate. + /// The valid directories. + /// A value indicating whether the filepath is valid. + bool VerifyEditPath(string filePath, IEnumerable validDirs); + + /// + /// Verifies that the current filepath has one of several authorized extensions. + /// + /// The filepath to validate. + /// The valid extensions. + /// A value indicating whether the filepath is valid. + bool VerifyFileExtension(string filePath, IEnumerable validFileExtensions); + + bool PathStartsWith(string path, string root, char separator); + + /// + /// Returns the path to the root of the application, by getting the path to where the assembly where this + /// method is included is present, then traversing until it's past the /bin directory. Ie. this makes it work + /// even if the assembly is in a /bin/debug or /bin/release folder + /// + /// + string GetRootDirectorySafe(); + + string GetRootDirectoryBinFolder(); + + /// + /// Allows you to overwrite RootDirectory, which would otherwise be resolved + /// automatically upon application start. + /// + /// The supplied path should be the absolute path to the root of the umbraco site. + /// + void SetRootDirectory(string rootPath); + + /// + /// Check to see if filename passed has any special chars in it and strips them to create a safe filename. Used to overcome an issue when Umbraco is used in IE in an intranet environment. + /// + /// The filename passed to the file handler from the upload field. + /// A safe filename without any path specific chars. + string SafeFileName(string filePath); + + void EnsurePathExists(string path); + + /// + /// Get properly formatted relative path from an existing absolute or relative path + /// + /// + /// + string GetRelativePath(string path); + } +} diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 53aa5a8179..a81c0ab559 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -11,13 +11,13 @@ using System.IO.Compression; namespace Umbraco.Core.IO { - public static class IOHelper + public class IOHelper : IIOHelper { /// /// Gets or sets a value forcing Umbraco to consider it is non-hosted. /// /// This should always be false, unless unit testing. - public static bool ForceNotHosted { get; set; } + public bool ForceNotHosted { get; set; } private static string _rootDir = ""; @@ -27,12 +27,12 @@ namespace Umbraco.Core.IO /// /// Gets a value indicating whether Umbraco is hosted. /// - public static bool IsHosted => !ForceNotHosted && (HttpContext.Current != null || HostingEnvironment.IsHosted); + public bool IsHosted => !ForceNotHosted && (HttpContext.Current != null || HostingEnvironment.IsHosted); - public static char DirSepChar => Path.DirectorySeparatorChar; + public char DirSepChar => Path.DirectorySeparatorChar; //helper to try and match the old path to a new virtual one - public static string FindFile(string virtualPath) + public string FindFile(string virtualPath) { string retval = virtualPath; @@ -45,14 +45,14 @@ namespace Umbraco.Core.IO return retval; } - public static string ResolveVirtualUrl(string path) + public string ResolveVirtualUrl(string path) { if (string.IsNullOrWhiteSpace(path)) return path; return path.StartsWith("~/") ? ResolveUrl(path) : path; } //Replaces tildes with the root dir - public static string ResolveUrl(string virtualPath) + public string ResolveUrl(string virtualPath) { if (virtualPath.StartsWith("~")) return virtualPath.Replace("~", SystemDirectories.Root).Replace("//", "/"); @@ -62,7 +62,7 @@ namespace Umbraco.Core.IO return VirtualPathUtility.ToAbsolute(virtualPath, SystemDirectories.Root); } - public static Attempt TryResolveUrl(string virtualPath) + public Attempt TryResolveUrl(string virtualPath) { try { @@ -78,7 +78,7 @@ namespace Umbraco.Core.IO } } - public static string MapPath(string path, bool useHttpContext) + public string MapPath(string path, bool useHttpContext) { if (path == null) throw new ArgumentNullException("path"); useHttpContext = useHttpContext && IsHosted; @@ -102,19 +102,19 @@ namespace Umbraco.Core.IO } var root = GetRootDirectorySafe(); - var newPath = path.TrimStart('~', '/').Replace('/', IOHelper.DirSepChar); - var retval = root + IOHelper.DirSepChar.ToString(CultureInfo.InvariantCulture) + newPath; + var newPath = path.TrimStart('~', '/').Replace('/', DirSepChar); + var retval = root + DirSepChar.ToString(CultureInfo.InvariantCulture) + newPath; return retval; } - public static string MapPath(string path) + public string MapPath(string path) { return MapPath(path, true); } //use a tilde character instead of the complete path - internal static string ReturnPath(string settingsKey, string standardPath, bool useTilde) + public string ReturnPath(string settingsKey, string standardPath, bool useTilde) { var retval = ConfigurationManager.AppSettings[settingsKey]; @@ -124,7 +124,7 @@ namespace Umbraco.Core.IO return retval.TrimEnd('/'); } - internal static string ReturnPath(string settingsKey, string standardPath) + public string ReturnPath(string settingsKey, string standardPath) { return ReturnPath(settingsKey, standardPath, false); @@ -136,7 +136,7 @@ namespace Umbraco.Core.IO /// The filepath to validate. /// The valid directory. /// A value indicating whether the filepath is valid. - internal static bool VerifyEditPath(string filePath, string validDir) + public bool VerifyEditPath(string filePath, string validDir) { return VerifyEditPath(filePath, new[] { validDir }); } @@ -147,7 +147,7 @@ namespace Umbraco.Core.IO /// The filepath to validate. /// The valid directories. /// A value indicating whether the filepath is valid. - internal static bool VerifyEditPath(string filePath, IEnumerable validDirs) + public bool VerifyEditPath(string filePath, IEnumerable validDirs) { // this is called from ScriptRepository, PartialViewRepository, etc. // filePath is the fullPath (rooted, filesystem path, can be trusted) @@ -185,13 +185,13 @@ namespace Umbraco.Core.IO /// The filepath to validate. /// The valid extensions. /// A value indicating whether the filepath is valid. - internal static bool VerifyFileExtension(string filePath, IEnumerable validFileExtensions) + public bool VerifyFileExtension(string filePath, IEnumerable validFileExtensions) { var ext = Path.GetExtension(filePath); return ext != null && validFileExtensions.Contains(ext.TrimStart('.')); } - public static bool PathStartsWith(string path, string root, char separator) + public bool PathStartsWith(string path, string root, char separator) { // either it is identical to root, // or it is root + separator + anything @@ -208,7 +208,7 @@ namespace Umbraco.Core.IO /// even if the assembly is in a /bin/debug or /bin/release folder /// /// - internal static string GetRootDirectorySafe() + public string GetRootDirectorySafe() { if (String.IsNullOrEmpty(_rootDir) == false) { @@ -229,7 +229,7 @@ namespace Umbraco.Core.IO return _rootDir; } - internal static string GetRootDirectoryBinFolder() + public string GetRootDirectoryBinFolder() { string binFolder = String.Empty; if (String.IsNullOrEmpty(_rootDir)) @@ -262,7 +262,7 @@ namespace Umbraco.Core.IO /// /// The supplied path should be the absolute path to the root of the umbraco site. /// - internal static void SetRootDirectory(string rootPath) + public void SetRootDirectory(string rootPath) { _rootDir = rootPath; } @@ -272,39 +272,25 @@ namespace Umbraco.Core.IO /// /// The filename passed to the file handler from the upload field. /// A safe filename without any path specific chars. - internal static string SafeFileName(string filePath) + public string SafeFileName(string filePath) { // use string extensions return filePath.ToSafeFileName(); } - public static void EnsurePathExists(string path) + public void EnsurePathExists(string path) { var absolutePath = MapPath(path); if (Directory.Exists(absolutePath) == false) Directory.CreateDirectory(absolutePath); } - /// - /// Checks if a given path is a full path including drive letter - /// - /// - /// - // From: http://stackoverflow.com/a/35046453/5018 - internal static bool IsFullPath(this string path) - { - return string.IsNullOrWhiteSpace(path) == false - && path.IndexOfAny(Path.GetInvalidPathChars().ToArray()) == -1 - && Path.IsPathRooted(path) - && Path.GetPathRoot(path).Equals(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) == false; - } - /// /// Get properly formatted relative path from an existing absolute or relative path /// /// /// - internal static string GetRelativePath(this string path) + public string GetRelativePath(string path) { if (path.IsFullPath()) { @@ -316,20 +302,5 @@ namespace Umbraco.Core.IO return path.EnsurePathIsApplicationRootPrefixed(); } - /// - /// Ensures that a path has `~/` as prefix - /// - /// - /// - internal static string EnsurePathIsApplicationRootPrefixed(this string path) - { - if (path.StartsWith("~/")) - return path; - if (path.StartsWith("/") == false && path.StartsWith("\\") == false) - path = string.Format("/{0}", path); - if (path.StartsWith("~") == false) - path = string.Format("~{0}", path); - return path; - } } } diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Core/IO/MediaFileSystem.cs index 2ce1230bcc..2de7bc2f81 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Core/IO/MediaFileSystem.cs @@ -68,7 +68,7 @@ namespace Umbraco.Core.IO { filename = Path.GetFileName(filename); if (filename == null) throw new ArgumentException("Cannot become a safe filename.", nameof(filename)); - filename = IOHelper.SafeFileName(filename.ToLowerInvariant()); + filename = Current.IOHelper.SafeFileName(filename.ToLowerInvariant()); return _mediaPathScheme.GetFilePath(this, cuid, puid, filename); } @@ -78,7 +78,7 @@ namespace Umbraco.Core.IO { filename = Path.GetFileName(filename); if (filename == null) throw new ArgumentException("Cannot become a safe filename.", nameof(filename)); - filename = IOHelper.SafeFileName(filename.ToLowerInvariant()); + filename = Current.IOHelper.SafeFileName(filename.ToLowerInvariant()); return _mediaPathScheme.GetFilePath(this, cuid, puid, filename, prevpath); } diff --git a/src/Umbraco.Core/IO/PhysicalFileSystem.cs b/src/Umbraco.Core/IO/PhysicalFileSystem.cs index e4edb2b86b..2e133a03c3 100644 --- a/src/Umbraco.Core/IO/PhysicalFileSystem.cs +++ b/src/Umbraco.Core/IO/PhysicalFileSystem.cs @@ -32,9 +32,9 @@ namespace Umbraco.Core.IO if (virtualRoot.StartsWith("~/") == false) throw new ArgumentException("The virtualRoot argument must be a virtual path and start with '~/'"); - _rootPath = EnsureDirectorySeparatorChar(IOHelper.MapPath(virtualRoot)).TrimEnd(Path.DirectorySeparatorChar); + _rootPath = EnsureDirectorySeparatorChar(Current.IOHelper.MapPath(virtualRoot)).TrimEnd(Path.DirectorySeparatorChar); _rootPathFwd = EnsureUrlSeparatorChar(_rootPath); - _rootUrl = EnsureUrlSeparatorChar(IOHelper.ResolveUrl(virtualRoot)).TrimEnd('/'); + _rootUrl = EnsureUrlSeparatorChar(Current.IOHelper.ResolveUrl(virtualRoot)).TrimEnd('/'); } public PhysicalFileSystem(string rootPath, string rootUrl) @@ -47,7 +47,7 @@ namespace Umbraco.Core.IO if (Path.IsPathRooted(rootPath) == false) { // but the test suite App.config cannot really "root" anything so we have to do it here - var localRoot = IOHelper.GetRootDirectorySafe(); + var localRoot = Current.IOHelper.GetRootDirectorySafe(); rootPath = Path.Combine(localRoot, rootPath); } @@ -257,12 +257,12 @@ namespace Umbraco.Core.IO // if it starts with the root url, strip it and trim the starting slash to make it relative // eg "/Media/1234/img.jpg" => "1234/img.jpg" - if (IOHelper.PathStartsWith(path, _rootUrl, '/')) + if (Current.IOHelper.PathStartsWith(path, _rootUrl, '/')) return path.Substring(_rootUrl.Length).TrimStart('/'); // if it starts with the root path, strip it and trim the starting slash to make it relative // eg "c:/websites/test/root/Media/1234/img.jpg" => "1234/img.jpg" - if (IOHelper.PathStartsWith(path, _rootPathFwd, '/')) + if (Current.IOHelper.PathStartsWith(path, _rootPathFwd, '/')) return path.Substring(_rootPathFwd.Length).TrimStart('/'); // unchanged - what else? @@ -292,7 +292,7 @@ namespace Umbraco.Core.IO path = GetRelativePath(path); // if not already rooted, combine with the root path - if (IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar) == false) + if (Current.IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar) == false) path = Path.Combine(_rootPath, path); // sanitize - GetFullPath will take care of any relative @@ -303,7 +303,7 @@ namespace Umbraco.Core.IO // at that point, path is within legal parts of the filesystem, ie we have // permissions to reach that path, but it may nevertheless be outside of // our root path, due to relative segments, so better check - if (IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar)) + if (Current.IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar)) { // this says that 4.7.2 supports long paths - but Windows does not // https://docs.microsoft.com/en-us/dotnet/api/system.io.pathtoolongexception?view=netframework-4.7.2 diff --git a/src/Umbraco.Core/IO/ShadowWrapper.cs b/src/Umbraco.Core/IO/ShadowWrapper.cs index dacef52a92..44152d7c1a 100644 --- a/src/Umbraco.Core/IO/ShadowWrapper.cs +++ b/src/Umbraco.Core/IO/ShadowWrapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Umbraco.Core.Composing; namespace Umbraco.Core.IO { @@ -37,7 +38,7 @@ namespace Umbraco.Core.IO var id = GuidUtils.ToBase32String(Guid.NewGuid(), idLength); var virt = ShadowFsPath + "/" + id; - var shadowDir = IOHelper.MapPath(virt); + var shadowDir = Current.IOHelper.MapPath(virt); if (Directory.Exists(shadowDir)) continue; @@ -55,7 +56,7 @@ namespace Umbraco.Core.IO // in a single thread anyways var virt = ShadowFsPath + "/" + id + "/" + _shadowPath; - _shadowDir = IOHelper.MapPath(virt); + _shadowDir = Current.IOHelper.MapPath(virt); Directory.CreateDirectory(_shadowDir); var tempfs = new PhysicalFileSystem(virt); _shadowFileSystem = new ShadowFileSystem(_innerFileSystem, tempfs); @@ -82,7 +83,7 @@ namespace Umbraco.Core.IO // shadowPath make be path/to/dir, remove each dir = dir.Replace("/", "\\"); - var min = IOHelper.MapPath(ShadowFsPath).Length; + var min = Current.IOHelper.MapPath(ShadowFsPath).Length; var pos = dir.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase); while (pos > min) { diff --git a/src/Umbraco.Core/IO/SystemDirectories.cs b/src/Umbraco.Core/IO/SystemDirectories.cs index d6fb63b0a1..c5c410ff3f 100644 --- a/src/Umbraco.Core/IO/SystemDirectories.cs +++ b/src/Umbraco.Core/IO/SystemDirectories.cs @@ -1,4 +1,5 @@ using System.Web; +using Umbraco.Core.Composing; namespace Umbraco.Core.IO { @@ -29,13 +30,13 @@ namespace Umbraco.Core.IO public static string MacroPartials => MvcViews + "/MacroPartials/"; - public static string Media => IOHelper.ReturnPath("umbracoMediaPath", "~/media"); + public static string Media => Current.IOHelper.ReturnPath("umbracoMediaPath", "~/media"); - public static string Scripts => IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts"); + public static string Scripts => Current.IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts"); - public static string Css => IOHelper.ReturnPath("umbracoCssPath", "~/css"); + public static string Css => Current.IOHelper.ReturnPath("umbracoCssPath", "~/css"); - public static string Umbraco => IOHelper.ReturnPath("umbracoPath", "~/umbraco"); + public static string Umbraco => Current.IOHelper.ReturnPath("umbracoPath", "~/umbraco"); public static string Packages => Data + "/packages"; diff --git a/src/Umbraco.Core/Logging/Viewer/LogViewerSourceBase.cs b/src/Umbraco.Core/Logging/Viewer/LogViewerSourceBase.cs index 607c20e601..c2d9dbb46c 100644 --- a/src/Umbraco.Core/Logging/Viewer/LogViewerSourceBase.cs +++ b/src/Umbraco.Core/Logging/Viewer/LogViewerSourceBase.cs @@ -5,6 +5,7 @@ using System.Xml; using Newtonsoft.Json; using Serilog; using Serilog.Events; +using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.Persistence.DatabaseModelDefinitions; @@ -18,7 +19,7 @@ namespace Umbraco.Core.Logging.Viewer { if (string.IsNullOrEmpty(pathToSearches)) // ReSharper disable once StringLiteralTypo - pathToSearches = IOHelper.MapPath("~/Config/logviewer.searches.config.js"); + pathToSearches = Current.IOHelper.MapPath("~/Config/logviewer.searches.config.js"); _searchesConfigPath = pathToSearches; } @@ -93,7 +94,7 @@ namespace Umbraco.Core.Logging.Viewer } /// - /// Get the Serilog minimum-level value from the config file. + /// Get the Serilog minimum-level value from the config file. /// /// public string GetLogLevel() @@ -181,7 +182,7 @@ namespace Umbraco.Core.Logging.Viewer private static void EnsureFileExists(string path, string contents) { - var absolutePath = IOHelper.MapPath(path); + var absolutePath = Current.IOHelper.MapPath(path); if (System.IO.File.Exists(absolutePath)) return; using (var writer = System.IO.File.CreateText(absolutePath)) diff --git a/src/Umbraco.Core/Manifest/ManifestContentAppDefinition.cs b/src/Umbraco.Core/Manifest/ManifestContentAppDefinition.cs index af66bfc544..2aafcd8b74 100644 --- a/src/Umbraco.Core/Manifest/ManifestContentAppDefinition.cs +++ b/src/Umbraco.Core/Manifest/ManifestContentAppDefinition.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Core.Manifest @@ -67,7 +68,7 @@ namespace Umbraco.Core.Manifest public string View { get => _view; - set => _view = IOHelper.ResolveVirtualUrl(value); + set => _view = Current.IOHelper.ResolveVirtualUrl(value); } /// diff --git a/src/Umbraco.Core/Manifest/ManifestDashboard.cs b/src/Umbraco.Core/Manifest/ManifestDashboard.cs index e790655221..33af12e3cd 100644 --- a/src/Umbraco.Core/Manifest/ManifestDashboard.cs +++ b/src/Umbraco.Core/Manifest/ManifestDashboard.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using Newtonsoft.Json; +using Umbraco.Core.Composing; using Umbraco.Core.Dashboards; using Umbraco.Core.IO; @@ -21,7 +22,7 @@ namespace Umbraco.Core.Manifest public string View { get => _view; - set => _view = IOHelper.ResolveVirtualUrl(value); + set => _view = Current.IOHelper.ResolveVirtualUrl(value); } [JsonProperty("sections")] diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index efd9e92b1f..cac904a520 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using Newtonsoft.Json; using Umbraco.Core.Cache; +using Umbraco.Core.Composing; using Umbraco.Core.Exceptions; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -50,7 +51,7 @@ namespace Umbraco.Core.Manifest public string Path { get => _path; - set => _path = value.StartsWith("~/") ? IOHelper.MapPath(value) : value; + set => _path = value.StartsWith("~/") ? Current.IOHelper.MapPath(value) : value; } /// @@ -165,9 +166,9 @@ namespace Umbraco.Core.Manifest // scripts and stylesheets are raw string, must process here for (var i = 0; i < manifest.Scripts.Length; i++) - manifest.Scripts[i] = IOHelper.ResolveVirtualUrl(manifest.Scripts[i]); + manifest.Scripts[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Scripts[i]); for (var i = 0; i < manifest.Stylesheets.Length; i++) - manifest.Stylesheets[i] = IOHelper.ResolveVirtualUrl(manifest.Stylesheets[i]); + manifest.Stylesheets[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Stylesheets[i]); // add property editors that are also parameter editors, to the parameter editors list // (the manifest format is kinda legacy) diff --git a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs index d86c682bd5..a0c87ce510 100644 --- a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs @@ -4,6 +4,7 @@ using System.Data.SqlServerCe; using System.IO; using System.Linq; using System.Xml.Linq; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Exceptions; using Umbraco.Core.IO; @@ -131,7 +132,7 @@ namespace Umbraco.Core.Migrations.Install { SaveConnectionString(EmbeddedDatabaseConnectionString, Constants.DbProviderNames.SqlCe, logger); - var path = Path.Combine(IOHelper.GetRootDirectorySafe(), "App_Data", "Umbraco.sdf"); + var path = Path.Combine(Current.IOHelper.GetRootDirectorySafe(), "App_Data", "Umbraco.sdf"); if (File.Exists(path) == false) { // this should probably be in a "using (new SqlCeEngine)" clause but not sure @@ -282,7 +283,7 @@ namespace Umbraco.Core.Migrations.Install if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullOrEmptyException(nameof(providerName)); var fileSource = "web.config"; - var fileName = IOHelper.MapPath(SystemDirectories.Root +"/" + fileSource); + var fileName = Current.IOHelper.MapPath(SystemDirectories.Root +"/" + fileSource); var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace); if (xml.Root == null) throw new Exception($"Invalid {fileSource} file (no root)."); @@ -295,7 +296,7 @@ namespace Umbraco.Core.Migrations.Install if (configSourceAttribute != null) { fileSource = configSourceAttribute.Value; - fileName = IOHelper.MapPath(SystemDirectories.Root + "/" + fileSource); + fileName = Current.IOHelper.MapPath(SystemDirectories.Root + "/" + fileSource); if (!File.Exists(fileName)) throw new Exception($"Invalid configSource \"{fileSource}\" (no such file)."); diff --git a/src/Umbraco.Core/Packaging/PackageFileInstallation.cs b/src/Umbraco.Core/Packaging/PackageFileInstallation.cs index 29afc11d83..45e40b8e5f 100644 --- a/src/Umbraco.Core/Packaging/PackageFileInstallation.cs +++ b/src/Umbraco.Core/Packaging/PackageFileInstallation.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Xml.Linq; +using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -28,7 +29,7 @@ namespace Umbraco.Core.Packaging _logger = logger; _packageExtraction = new PackageExtraction(); } - + /// /// Returns a list of all installed file paths /// @@ -59,15 +60,15 @@ namespace Umbraco.Core.Packaging foreach (var item in package.Files.ToArray()) { - removedFiles.Add(item.GetRelativePath()); + removedFiles.Add(Current.IOHelper.GetRelativePath(item)); //here we need to try to find the file in question as most packages does not support the tilde char - var file = IOHelper.FindFile(item); + var file = Current.IOHelper.FindFile(item); if (file != null) { // TODO: Surely this should be ~/ ? file = file.EnsureStartsWith("/"); - var filePath = IOHelper.MapPath(file); + var filePath = Current.IOHelper.MapPath(file); if (File.Exists(filePath)) File.Delete(filePath); diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index 72954b238d..458a239cc0 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -5,6 +5,7 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Xml.Linq; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -139,7 +140,7 @@ namespace Umbraco.Core.Packaging var updatedXml = _parser.ToXml(definition); packageXml.ReplaceWith(updatedXml); } - + packagesXml.Save(packagesFile); return true; @@ -154,7 +155,7 @@ namespace Umbraco.Core.Packaging ValidatePackage(definition); //Create a folder for building this package - var temporaryPath = IOHelper.MapPath(_tempFolderPath.EnsureEndsWith('/') + Guid.NewGuid()); + var temporaryPath = Current.IOHelper.MapPath(_tempFolderPath.EnsureEndsWith('/') + Guid.NewGuid()); if (Directory.Exists(temporaryPath) == false) Directory.CreateDirectory(temporaryPath); @@ -212,12 +213,12 @@ namespace Umbraco.Core.Packaging compiledPackageXml.Save(packageXmlFileName); // check if there's a packages directory below media - - if (Directory.Exists(IOHelper.MapPath(_mediaFolderPath)) == false) - Directory.CreateDirectory(IOHelper.MapPath(_mediaFolderPath)); + + if (Directory.Exists(Current.IOHelper.MapPath(_mediaFolderPath)) == false) + Directory.CreateDirectory(Current.IOHelper.MapPath(_mediaFolderPath)); var packPath = _mediaFolderPath.EnsureEndsWith('/') + (definition.Name + "_" + definition.Version).Replace(' ', '_') + ".zip"; - ZipPackage(temporaryPath, IOHelper.MapPath(packPath)); + ZipPackage(temporaryPath, Current.IOHelper.MapPath(packPath)); //we need to update the package path and save it definition.PackagePath = packPath; @@ -448,7 +449,7 @@ namespace Umbraco.Core.Packaging if (!path.StartsWith("~/") && !path.StartsWith("/")) path = "~/" + path; - var serverPath = IOHelper.MapPath(path); + var serverPath = Current.IOHelper.MapPath(path); if (File.Exists(serverPath)) AppendFileXml(new FileInfo(serverPath), path, packageDirectory, filesXml); @@ -562,7 +563,7 @@ namespace Umbraco.Core.Packaging package.Add(new XElement("url", definition.Url)); var requirements = new XElement("requirements"); - + requirements.Add(new XElement("major", definition.UmbracoVersion == null ? UmbracoVersion.SemanticVersion.Major.ToInvariantString() : definition.UmbracoVersion.Major.ToInvariantString())); requirements.Add(new XElement("minor", definition.UmbracoVersion == null ? UmbracoVersion.SemanticVersion.Minor.ToInvariantString() : definition.UmbracoVersion.Minor.ToInvariantString())); requirements.Add(new XElement("patch", definition.UmbracoVersion == null ? UmbracoVersion.SemanticVersion.Patch.ToInvariantString() : definition.UmbracoVersion.Build.ToInvariantString())); @@ -589,7 +590,7 @@ namespace Umbraco.Core.Packaging contributors.Add(new XElement("contributor", contributor)); } } - + info.Add(contributors); info.Add(new XElement("readme", new XCData(definition.Readme))); @@ -607,11 +608,11 @@ namespace Umbraco.Core.Packaging private XDocument EnsureStorage(out string packagesFile) { - var packagesFolder = IOHelper.MapPath(_packagesFolderPath); + var packagesFolder = Current.IOHelper.MapPath(_packagesFolderPath); //ensure it exists Directory.CreateDirectory(packagesFolder); - packagesFile = IOHelper.MapPath(CreatedPackagesFile); + packagesFile = Current.IOHelper.MapPath(CreatedPackagesFile); if (!File.Exists(packagesFile)) { var xml = new XDocument(new XElement("packages")); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/PartialViewRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/PartialViewRepository.cs index d04bc47cd8..d7d1be55c7 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/PartialViewRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/PartialViewRepository.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Text; +using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Models; @@ -103,8 +104,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement // validate path & extension var validDir = SystemDirectories.MvcViews; - var isValidPath = IOHelper.VerifyEditPath(fullPath, validDir); - var isValidExtension = IOHelper.VerifyFileExtension(fullPath, ValidExtensions); + 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 5806a17970..3196332a86 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ScriptRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ScriptRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; using Umbraco.Core.Models; @@ -101,9 +102,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement // validate path & extension var validDir = SystemDirectories.Scripts; - var isValidPath = IOHelper.VerifyEditPath(fullPath, validDir); + var isValidPath = Current.IOHelper.VerifyEditPath(fullPath, validDir); var validExts = new[] {"js"}; - var isValidExtension = IOHelper.VerifyFileExtension(script.Path, validExts); + var isValidExtension = Current.IOHelper.VerifyFileExtension(script.Path, validExts); return isValidPath && isValidExtension; } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/StylesheetRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/StylesheetRepository.cs index 6823a00f94..52ff14b0dc 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/StylesheetRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/StylesheetRepository.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Models; @@ -114,8 +115,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement // validate path and extension var validDir = SystemDirectories.Css; - var isValidPath = IOHelper.VerifyEditPath(fullPath, validDir); - var isValidExtension = IOHelper.VerifyFileExtension(stylesheet.Path, ValidExtensions); + var isValidPath = Current.IOHelper.VerifyEditPath(fullPath, validDir); + var isValidExtension = Current.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 b348317989..5fd319e4d4 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using NPoco; using Umbraco.Core.Cache; +using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -592,8 +593,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement validExts.Add("vbhtml"); // validate path and extension - var validFile = IOHelper.VerifyEditPath(path, validDirs); - var validExtension = IOHelper.VerifyFileExtension(path, validExts); + var validFile = Current.IOHelper.VerifyEditPath(path, validDirs); + var validExtension = Current.IOHelper.VerifyFileExtension(path, validExts); return validFile && validExtension; } diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs index ac74953230..ee07f8dcef 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Core.PropertyEditors @@ -93,7 +94,7 @@ namespace Umbraco.Core.PropertyEditors public string View { get => _view; - set => _view = IOHelper.ResolveVirtualUrl(value); + set => _view = Current.IOHelper.ResolveVirtualUrl(value); } /// diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index c4380f032c..a9ce27d964 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -75,7 +75,7 @@ namespace Umbraco.Core.PropertyEditors public string View { get => _view; - set => _view = IOHelper.ResolveVirtualUrl(value); + set => _view = Current.IOHelper.ResolveVirtualUrl(value); } /// @@ -204,7 +204,7 @@ namespace Umbraco.Core.PropertyEditors /// /// /// By default this will attempt to automatically convert the string value to the value type supplied by ValueType. - /// + /// /// If overridden then the object returned must match the type supplied in the ValueType, otherwise persisting the /// value to the DB will fail when it tries to validate the value type. /// diff --git a/src/Umbraco.Core/PropertyEditors/GridEditor.cs b/src/Umbraco.Core/PropertyEditors/GridEditor.cs index cc3561fbc2..388e79675c 100644 --- a/src/Umbraco.Core/PropertyEditors/GridEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/GridEditor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration.Grid; using Umbraco.Core.IO; @@ -28,14 +29,14 @@ namespace Umbraco.Core.PropertyEditors public string View { get => _view; - set => _view = IOHelper.ResolveVirtualUrl(value); + set => _view = Current.IOHelper.ResolveVirtualUrl(value); } [JsonProperty("render")] public string Render { get => _render; - set => _render = IOHelper.ResolveVirtualUrl(value); + set => _render = Current.IOHelper.ResolveVirtualUrl(value); } [JsonProperty("icon", Required = Required.Always)] diff --git a/src/Umbraco.Core/Runtime/CoreInitialComponent.cs b/src/Umbraco.Core/Runtime/CoreInitialComponent.cs index 2e40bf1339..f88417948b 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 - IOHelper.EnsurePathExists("~/App_Data"); - IOHelper.EnsurePathExists(SystemDirectories.Media); - IOHelper.EnsurePathExists(SystemDirectories.MvcViews); - IOHelper.EnsurePathExists(SystemDirectories.MvcViews + "/Partials"); - IOHelper.EnsurePathExists(SystemDirectories.MvcViews + "/MacroPartials"); + Current.IOHelper.EnsurePathExists("~/App_Data"); + Current.IOHelper.EnsurePathExists(SystemDirectories.Media); + Current.IOHelper.EnsurePathExists(SystemDirectories.MvcViews); + Current.IOHelper.EnsurePathExists(SystemDirectories.MvcViews + "/Partials"); + Current.IOHelper.EnsurePathExists(SystemDirectories.MvcViews + "/MacroPartials"); } public void Terminate() diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 5b069641c4..c1215553a2 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -215,7 +215,7 @@ namespace Umbraco.Core.Runtime { var path = GetApplicationRootPath(); if (string.IsNullOrWhiteSpace(path) == false) - IOHelper.SetRootDirectory(path); + Current.IOHelper.SetRootDirectory(path); } private bool AcquireMainDom(MainDom mainDom) diff --git a/src/Umbraco.Core/Services/Implement/FileService.cs b/src/Umbraco.Core/Services/Implement/FileService.cs index bd07892144..2cdff9a8e4 100644 --- a/src/Umbraco.Core/Services/Implement/FileService.cs +++ b/src/Umbraco.Core/Services/Implement/FileService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; +using Umbraco.Core.Composing; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -410,7 +411,7 @@ namespace Umbraco.Core.Services.Implement throw new ArgumentNullException(nameof(name)); } - if (string.IsNullOrWhiteSpace(name)) + if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Name cannot be empty or contain only white-space characters", nameof(name)); } @@ -558,7 +559,7 @@ namespace Umbraco.Core.Services.Implement { throw new ArgumentNullException(nameof(template)); } - + if (string.IsNullOrWhiteSpace(template.Name) || template.Name.Length > 255) { throw new InvalidOperationException("Name cannot be null, empty, contain only white-space characters or be more than 255 characters in length."); @@ -701,7 +702,7 @@ namespace Umbraco.Core.Services.Implement public IEnumerable GetPartialViewSnippetNames(params string[] filterNames) { - var snippetPath = IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/"); + var snippetPath = Current.IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/"); var files = Directory.GetFiles(snippetPath, "*.cshtml") .Select(Path.GetFileNameWithoutExtension) .Except(filterNames, StringComparer.InvariantCultureIgnoreCase) @@ -935,7 +936,7 @@ namespace Umbraco.Core.Services.Implement fileName += ".cshtml"; } - var snippetPath = IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/{fileName}"); + var snippetPath = Current.IOHelper.MapPath($"{SystemDirectories.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 5f81cf8c4a..65040f625a 100644 --- a/src/Umbraco.Core/Services/Implement/NotificationService.cs +++ b/src/Umbraco.Core/Services/Implement/NotificationService.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Net.Mail; using System.Text; using System.Threading; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; @@ -383,7 +384,7 @@ namespace Umbraco.Core.Services.Implement var protocol = _globalSettings.UseHttps ? "https" : "http"; var subjectVars = new NotificationEmailSubjectParams( - string.Concat(siteUri.Authority, IOHelper.ResolveUrl(SystemDirectories.Umbraco)), + string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco)), actionName, content.Name); @@ -399,7 +400,7 @@ namespace Umbraco.Core.Services.Implement string.Concat(content.Id, ".aspx"), protocol), performingUser.Name, - string.Concat(siteUri.Authority, IOHelper.ResolveUrl(SystemDirectories.Umbraco)), + string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(SystemDirectories.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 79fa2b42ed..c0946e4468 100644 --- a/src/Umbraco.Core/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Core/Services/Implement/PackagingService.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Semver; +using Umbraco.Core.Composing; using Umbraco.Core.Events; using Umbraco.Core.Exceptions; using Umbraco.Core.IO; @@ -63,7 +64,7 @@ namespace Umbraco.Core.Services.Implement //successful if (bytes.Length > 0) { - var packagePath = IOHelper.MapPath(SystemDirectories.Packages); + var packagePath = Current.IOHelper.MapPath(SystemDirectories.Packages); // Check for package directory if (Directory.Exists(packagePath) == false) diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index 025cb35904..027b5fc928 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -112,7 +112,7 @@ namespace Umbraco.Core if (isValid) { - var resolvedUrlResult = IOHelper.TryResolveUrl(input); + var resolvedUrlResult = Current.IOHelper.TryResolveUrl(input); //if the resolution was success, return it, otherwise just return the path, we've detected // it's a path but maybe it's relative and resolution has failed, etc... in which case we're just // returning what was given to us. @@ -1475,5 +1475,35 @@ namespace Umbraco.Core // /// // public static string NullOrWhiteSpaceAsNull(this string text) // => string.IsNullOrWhiteSpace(text) ? null : text; + + /// + /// Checks if a given path is a full path including drive letter + /// + /// + /// + // From: http://stackoverflow.com/a/35046453/5018 + internal static bool IsFullPath(this string path) + { + return string.IsNullOrWhiteSpace(path) == false + && path.IndexOfAny(Path.GetInvalidPathChars().ToArray()) == -1 + && Path.IsPathRooted(path) + && Path.GetPathRoot(path).Equals(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) == false; + } + + /// + /// Ensures that a path has `~/` as prefix + /// + /// + /// + internal static string EnsurePathIsApplicationRootPrefixed(this string path) + { + if (path.StartsWith("~/")) + return path; + if (path.StartsWith("/") == false && path.StartsWith("\\") == false) + path = string.Format("/{0}", path); + if (path.StartsWith("~") == false) + path = string.Format("~{0}", path); + return path; + } } } diff --git a/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs b/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs index 43d6d1194e..b7afc1048b 100644 --- a/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs +++ b/src/Umbraco.Core/Sync/ApplicationUrlHelper.cs @@ -1,5 +1,6 @@ using System; using System.Web; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; @@ -97,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 + IOHelper.ResolveUrl(SystemDirectories.Umbraco); + var url = "http" + ssl + "://" + request.ServerVariables["SERVER_NAME"] + port + Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco); return url.TrimEnd('/'); } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 5f18cb3d95..93631e5782 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -185,6 +185,7 @@ + diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 1198b26e0f..9fd1bf46dc 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -115,7 +115,7 @@ namespace Umbraco.Core .TrimStart("/"); //check if this is in the umbraco back office - return afterAuthority.InvariantStartsWith(IOHelper.ResolveUrl("~/install").TrimStart("/")); + return afterAuthority.InvariantStartsWith(Current.IOHelper.ResolveUrl("~/install").TrimStart("/")); } /// diff --git a/src/Umbraco.Core/Xml/XmlHelper.cs b/src/Umbraco.Core/Xml/XmlHelper.cs index 3fd8dcaea5..53d56c1aac 100644 --- a/src/Umbraco.Core/Xml/XmlHelper.cs +++ b/src/Umbraco.Core/Xml/XmlHelper.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using System.Xml; using System.Xml.Linq; using System.Xml.XPath; +using Umbraco.Core.Composing; using Umbraco.Core.Exceptions; using Umbraco.Core.IO; @@ -210,14 +211,14 @@ namespace Umbraco.Core.Xml /// Returns a XmlDocument class public static XmlDocument OpenAsXmlDocument(string filePath) { - using (var reader = new XmlTextReader(IOHelper.MapPath(filePath)) {WhitespaceHandling = WhitespaceHandling.All}) + using (var reader = new XmlTextReader(Current.IOHelper.MapPath(filePath)) {WhitespaceHandling = WhitespaceHandling.All}) { var xmlDoc = new XmlDocument(); //Load the file into the XmlDocument xmlDoc.Load(reader); - + return xmlDoc; - } + } } /// diff --git a/src/Umbraco.Examine/LuceneIndexCreator.cs b/src/Umbraco.Examine/LuceneIndexCreator.cs index 806d0edc7a..ca5aacfabc 100644 --- a/src/Umbraco.Examine/LuceneIndexCreator.cs +++ b/src/Umbraco.Examine/LuceneIndexCreator.cs @@ -28,8 +28,8 @@ namespace Umbraco.Examine /// public virtual Lucene.Net.Store.Directory CreateFileSystemLuceneDirectory(string folderName) { - - var dirInfo = new DirectoryInfo(Path.Combine(IOHelper.MapPath(SystemDirectories.TempData), "ExamineIndexes", folderName)); + + var dirInfo = new DirectoryInfo(Path.Combine(Current.IOHelper.MapPath(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 96363904b4..7a91552c81 100644 --- a/src/Umbraco.Examine/LuceneIndexDiagnostics.cs +++ b/src/Umbraco.Examine/LuceneIndexDiagnostics.cs @@ -5,6 +5,7 @@ using Umbraco.Core.Logging; using Lucene.Net.Store; using Umbraco.Core.IO; using System.Linq; +using Umbraco.Core.Composing; namespace Umbraco.Examine { @@ -66,18 +67,18 @@ namespace Umbraco.Examine { [nameof(UmbracoExamineIndex.CommitCount)] = Index.CommitCount, [nameof(UmbracoExamineIndex.DefaultAnalyzer)] = Index.DefaultAnalyzer.GetType().Name, - ["LuceneDirectory"] = luceneDir.GetType().Name + ["LuceneDirectory"] = luceneDir.GetType().Name }; if (luceneDir is FSDirectory fsDir) { - d[nameof(UmbracoExamineIndex.LuceneIndexFolder)] = fsDir.Directory.ToString().ToLowerInvariant().TrimStart(IOHelper.MapPath(SystemDirectories.Root).ToLowerInvariant()).Replace("\\", "/").EnsureStartsWith('/'); + d[nameof(UmbracoExamineIndex.LuceneIndexFolder)] = fsDir.Directory.ToString().ToLowerInvariant().TrimStart(Current.IOHelper.MapPath(SystemDirectories.Root).ToLowerInvariant()).Replace("\\", "/").EnsureStartsWith('/'); } return d; } } - + } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/Configuration/ModelsBuilderConfig.cs b/src/Umbraco.ModelsBuilder.Embedded/Configuration/ModelsBuilderConfig.cs index c6bccdcf87..d3335ac41b 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Configuration/ModelsBuilderConfig.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Configuration/ModelsBuilderConfig.cs @@ -3,6 +3,7 @@ using System.Configuration; using System.IO; using System.Web.Configuration; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.ModelsBuilder.Embedded.Configuration @@ -28,7 +29,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Configuration // ensure defaults are initialized for tests ModelsNamespace = DefaultModelsNamespace; - ModelsDirectory = IOHelper.MapPath(DefaultModelsDirectory); + ModelsDirectory = Current.IOHelper.MapPath(DefaultModelsDirectory); DebugLevel = 0; // stop here, everything is false @@ -74,7 +75,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Configuration value = ConfigurationManager.AppSettings[prefix + "ModelsDirectory"]; if (!string.IsNullOrWhiteSpace(value)) { - var root = IOHelper.MapPath("~/"); + var root = Current.IOHelper.MapPath("~/"); if (root == null) throw new ConfigurationErrorsException("Could not determine root directory."); diff --git a/src/Umbraco.Tests/Components/ComponentTests.cs b/src/Umbraco.Tests/Components/ComponentTests.cs index 2ba94d8c78..0e72d6d0fe 100644 --- a/src/Umbraco.Tests/Components/ComponentTests.cs +++ b/src/Umbraco.Tests/Components/ComponentTests.cs @@ -361,7 +361,7 @@ namespace Umbraco.Tests.Components [Test] public void AllComposers() { - var typeLoader = new TypeLoader(AppCaches.Disabled.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), Mock.Of()); + var typeLoader = new TypeLoader(AppCaches.Disabled.RuntimeCache, Current.IOHelper.MapPath("~/App_Data/TEMP"), Mock.Of()); var register = MockRegister(); var composition = new Composition(register, typeLoader, Mock.Of(), MockRuntimeState(RuntimeLevel.Run)); diff --git a/src/Umbraco.Tests/Composing/ComposingTestBase.cs b/src/Umbraco.Tests/Composing/ComposingTestBase.cs index ef364afd38..f7d2c869b4 100644 --- a/src/Umbraco.Tests/Composing/ComposingTestBase.cs +++ b/src/Umbraco.Tests/Composing/ComposingTestBase.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Composing { ProfilingLogger = new ProfilingLogger(Mock.Of(), Mock.Of()); - TypeLoader = new TypeLoader(NoAppCache.Instance, IOHelper.MapPath("~/App_Data/TEMP"), ProfilingLogger, detectChanges: false) + TypeLoader = new TypeLoader(NoAppCache.Instance, Current.IOHelper.MapPath("~/App_Data/TEMP"), ProfilingLogger, detectChanges: false) { AssembliesToScan = AssembliesToScan }; diff --git a/src/Umbraco.Tests/Composing/CompositionTests.cs b/src/Umbraco.Tests/Composing/CompositionTests.cs index 33855a8bfb..77453e86b4 100644 --- a/src/Umbraco.Tests/Composing/CompositionTests.cs +++ b/src/Umbraco.Tests/Composing/CompositionTests.cs @@ -36,7 +36,7 @@ namespace Umbraco.Tests.Composing .Returns(() => factoryFactory?.Invoke(mockedFactory)); var logger = new ProfilingLogger(Mock.Of(), Mock.Of()); - var typeLoader = new TypeLoader(Mock.Of(), IOHelper.MapPath("~/App_Data/TEMP"), logger); + var typeLoader = new TypeLoader(Mock.Of(), Current.IOHelper.MapPath("~/App_Data/TEMP"), logger); var composition = new Composition(mockedRegister, typeLoader, logger, Mock.Of()); // create the factory, ensure it is the mocked factory diff --git a/src/Umbraco.Tests/Composing/TypeFinderTests.cs b/src/Umbraco.Tests/Composing/TypeFinderTests.cs index ca622e9288..579ee081ed 100644 --- a/src/Umbraco.Tests/Composing/TypeFinderTests.cs +++ b/src/Umbraco.Tests/Composing/TypeFinderTests.cs @@ -207,7 +207,7 @@ namespace Umbraco.Tests.Composing //here we are trying to get the App_Code assembly var fileExtensions = new[] { ".cs", ".vb" }; //only vb and cs files are supported - var appCodeFolder = new DirectoryInfo(IOHelper.MapPath(IOHelper.ResolveUrl("~/App_code"))); + var appCodeFolder = new DirectoryInfo(Current.IOHelper.MapPath(Current.IOHelper.ResolveUrl("~/App_code"))); //check if the folder exists and if there are any files in it with the supported file extensions if (appCodeFolder.Exists && (fileExtensions.Any(x => appCodeFolder.GetFiles("*" + x).Any()))) { diff --git a/src/Umbraco.Tests/Composing/TypeLoaderTests.cs b/src/Umbraco.Tests/Composing/TypeLoaderTests.cs index 7459ae848b..d22b534d2b 100644 --- a/src/Umbraco.Tests/Composing/TypeLoaderTests.cs +++ b/src/Umbraco.Tests/Composing/TypeLoaderTests.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.Composing public void Initialize() { // this ensures it's reset - _typeLoader = new TypeLoader(NoAppCache.Instance, IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of(), Mock.Of()), false); + _typeLoader = new TypeLoader(NoAppCache.Instance, Current.IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of(), Mock.Of()), false); // for testing, we'll specify which assemblies are scanned for the PluginTypeResolver // TODO: Should probably update this so it only searches this assembly and add custom types to be found diff --git a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs index 50ead4b702..69a9613a38 100644 --- a/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs +++ b/src/Umbraco.Tests/Configurations/GlobalSettingsTests.cs @@ -49,15 +49,15 @@ namespace Umbraco.Tests.Configurations var globalSettings = SettingsForTests.GenerateMockGlobalSettings(); var globalSettingsMock = Mock.Get(globalSettings); - globalSettingsMock.Setup(x => x.Path).Returns(() => IOHelper.ResolveUrl(path)); + globalSettingsMock.Setup(x => x.Path).Returns(() => Current.IOHelper.ResolveUrl(path)); SystemDirectories.Root = rootPath; Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache()); } - - + + } } diff --git a/src/Umbraco.Tests/CoreThings/UdiTests.cs b/src/Umbraco.Tests/CoreThings/UdiTests.cs index 2770803bea..8c790c0784 100644 --- a/src/Umbraco.Tests/CoreThings/UdiTests.cs +++ b/src/Umbraco.Tests/CoreThings/UdiTests.cs @@ -27,7 +27,7 @@ namespace Umbraco.Tests.CoreThings var container = new Mock(); var globalSettings = SettingsForTests.GenerateMockGlobalSettings(); container.Setup(x => x.GetInstance(typeof(TypeLoader))).Returns( - new TypeLoader(NoAppCache.Instance, IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of(), Mock.Of()))); + new TypeLoader(NoAppCache.Instance, Current.IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of(), Mock.Of()))); Current.Factory = container.Object; Udi.ResetUdiTypes(); diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index b21faec586..872d7c2526 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -105,7 +105,7 @@ namespace Umbraco.Tests.IO fs.AddFile(virtPath, ms); // ~/media/1234/file.txt exists - var physPath = IOHelper.MapPath(Path.Combine("media", virtPath)); + var physPath = Current.IOHelper.MapPath(Path.Combine("media", virtPath)); Assert.IsTrue(File.Exists(physPath)); // ~/media/1234/file.txt is gone diff --git a/src/Umbraco.Tests/IO/IoHelperTests.cs b/src/Umbraco.Tests/IO/IoHelperTests.cs index 34b18ffc5e..2a7e633e4f 100644 --- a/src/Umbraco.Tests/IO/IoHelperTests.cs +++ b/src/Umbraco.Tests/IO/IoHelperTests.cs @@ -1,6 +1,8 @@ using System; using NUnit.Framework; using Umbraco.Core.IO; +using Umbraco.Core; +using Umbraco.Core.Composing; namespace Umbraco.Tests.IO { @@ -14,11 +16,11 @@ namespace Umbraco.Tests.IO { if (expectedExceptionType != null) { - Assert.Throws(expectedExceptionType, () => IOHelper.ResolveUrl(input)); + Assert.Throws(expectedExceptionType, () => Current.IOHelper.ResolveUrl(input)); } else { - var result = IOHelper.ResolveUrl(input); + var result = Current.IOHelper.ResolveUrl(input); Assert.AreEqual(expected, result); } } @@ -31,17 +33,17 @@ namespace Umbraco.Tests.IO { //System.Diagnostics.Debugger.Break(); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Bin, true), IOHelper.MapPath(SystemDirectories.Bin, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Config, true), IOHelper.MapPath(SystemDirectories.Config, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Css, true), IOHelper.MapPath(SystemDirectories.Css, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Data, true), IOHelper.MapPath(SystemDirectories.Data, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Install, true), IOHelper.MapPath(SystemDirectories.Install, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Media, true), IOHelper.MapPath(SystemDirectories.Media, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Packages, true), IOHelper.MapPath(SystemDirectories.Packages, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Preview, true), IOHelper.MapPath(SystemDirectories.Preview, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Root, true), IOHelper.MapPath(SystemDirectories.Root, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Scripts, true), IOHelper.MapPath(SystemDirectories.Scripts, false)); - Assert.AreEqual(IOHelper.MapPath(SystemDirectories.Umbraco, true), IOHelper.MapPath(SystemDirectories.Umbraco, false)); + 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)); } [Test] diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 31b00e5cf8..409fae6081 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -40,8 +40,8 @@ namespace Umbraco.Tests.IO private static void ClearFiles() { - TestHelper.DeleteDirectory(IOHelper.MapPath("FileSysTests")); - TestHelper.DeleteDirectory(IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); + TestHelper.DeleteDirectory(Current.IOHelper.MapPath("FileSysTests")); + TestHelper.DeleteDirectory(Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); } private static string NormPath(string path) @@ -52,7 +52,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteDirectory() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -86,7 +86,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteDirectoryInDir() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -135,7 +135,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteFile() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -174,7 +174,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowDeleteFileInDir() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -229,7 +229,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCantCreateFile() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -248,7 +248,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCreateFile() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -287,7 +287,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowCreateFileInDir() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -327,7 +327,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowAbort() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -349,7 +349,7 @@ namespace Umbraco.Tests.IO [Test] public void ShadowComplete() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -387,8 +387,8 @@ namespace Umbraco.Tests.IO { var logger = Mock.Of(); - var path = IOHelper.MapPath("FileSysTests"); - var shadowfs = IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = Current.IOHelper.MapPath("FileSysTests"); + var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); Directory.CreateDirectory(shadowfs); @@ -482,8 +482,8 @@ namespace Umbraco.Tests.IO { var logger = Mock.Of(); - var path = IOHelper.MapPath("FileSysTests"); - var shadowfs = IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = Current.IOHelper.MapPath("FileSysTests"); + var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; @@ -535,8 +535,8 @@ namespace Umbraco.Tests.IO { var logger = Mock.Of(); - var path = IOHelper.MapPath("FileSysTests"); - var shadowfs = IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); + var path = Current.IOHelper.MapPath("FileSysTests"); + var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"); Directory.CreateDirectory(path); var scopedFileSystems = false; @@ -603,7 +603,7 @@ namespace Umbraco.Tests.IO [Test] public void GetFilesReturnsChildrenOnly() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); File.WriteAllText(path + "/f1.txt", "foo"); Directory.CreateDirectory(path + "/test"); @@ -625,7 +625,7 @@ namespace Umbraco.Tests.IO [Test] public void DeleteDirectoryAndFiles() { - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); File.WriteAllText(path + "/f1.txt", "foo"); Directory.CreateDirectory(path + "/test"); @@ -646,7 +646,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFiles() { // Arrange - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -678,7 +678,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingEmptyFilter() { // Arrange - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -713,7 +713,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingNullFilter() { // Arrange - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -745,7 +745,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingWildcardFilter() { // Arrange - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -780,7 +780,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFilesUsingSingleCharacterFilter() { // Arrange - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -827,7 +827,7 @@ namespace Umbraco.Tests.IO public void ShadowGetFullPath() { // Arrange - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -861,7 +861,7 @@ namespace Umbraco.Tests.IO public void ShadowGetRelativePath() { // Arrange - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); @@ -900,7 +900,7 @@ namespace Umbraco.Tests.IO public void ShadowGetUrl() { // Arrange - var path = IOHelper.MapPath("FileSysTests"); + var path = Current.IOHelper.MapPath("FileSysTests"); Directory.CreateDirectory(path); Directory.CreateDirectory(path + "/ShadowTests"); Directory.CreateDirectory(path + "/ShadowSystem"); diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PreviewContent.cs index 84b6f2b91c..adbd15b16a 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(IOHelper.MapPath(SystemDirectories.Preview)); + var dir = new DirectoryInfo(Current.IOHelper.MapPath(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 IOHelper.MapPath(Path.Combine(SystemDirectories.Preview, userId + "_" + previewSet + ".config")); + return Current.IOHelper.MapPath(Path.Combine(SystemDirectories.Preview, userId + "_" + previewSet + ".config")); } // deletes files for the user, and files accessed more than one hour ago diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs index 447104b7cd..a9ae5a1955 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/XmlStore.cs @@ -86,7 +86,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache _memberRepository = memberRepository; _globalSettings = globalSettings; _entitySerializer = entitySerializer; - _xmlFileName = IOHelper.MapPath(SystemFiles.GetContentCacheXml(_globalSettings)); + _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(_globalSettings)); if (testing) { @@ -110,7 +110,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache _mediaRepository = mediaRepository; _memberRepository = memberRepository; _xmlFileEnabled = false; - _xmlFileName = IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global())); + _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global())); // do not plug events, we may not have what it takes to handle them } @@ -124,7 +124,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache _memberRepository = memberRepository; GetXmlDocument = getXmlDocument ?? throw new ArgumentNullException(nameof(getXmlDocument)); _xmlFileEnabled = false; - _xmlFileName = IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global())); + _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global())); // do not plug events, we may not have what it takes to handle them } diff --git a/src/Umbraco.Tests/Logging/LogviewerTests.cs b/src/Umbraco.Tests/Logging/LogviewerTests.cs index 28c8d02dc3..96a68beccb 100644 --- a/src/Umbraco.Tests/Logging/LogviewerTests.cs +++ b/src/Umbraco.Tests/Logging/LogviewerTests.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Linq; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Logging.Viewer; @@ -42,8 +43,8 @@ namespace Umbraco.Tests.Logging _newSearchfilePath = Path.Combine(_newSearchfileDirPath, _searchfileName); //Create/ensure Directory exists - IOHelper.EnsurePathExists(_newLogfileDirPath); - IOHelper.EnsurePathExists(_newSearchfileDirPath); + Current.IOHelper.EnsurePathExists(_newLogfileDirPath); + Current.IOHelper.EnsurePathExists(_newSearchfileDirPath); //Copy the sample files File.Copy(exampleLogfilePath, _newLogfilePath, true); diff --git a/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs index df4071281c..ffa90e57da 100644 --- a/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Packaging base.TearDown(); //clear out files/folders - Directory.Delete(IOHelper.MapPath("~/" + _testBaseFolder), true); + Directory.Delete(Current.IOHelper.MapPath("~/" + _testBaseFolder), true); } public ICreatedPackagesRepository PackageBuilder => new PackagesRepository( @@ -146,8 +146,8 @@ namespace Umbraco.Tests.Packaging { var file1 = $"~/{_testBaseFolder}/App_Plugins/MyPlugin/package.manifest"; var file2 = $"~/{_testBaseFolder}/App_Plugins/MyPlugin/styles.css"; - var mappedFile1 = IOHelper.MapPath(file1); - var mappedFile2 = IOHelper.MapPath(file2); + var mappedFile1 = Current.IOHelper.MapPath(file1); + var mappedFile2 = Current.IOHelper.MapPath(file2); Directory.CreateDirectory(Path.GetDirectoryName(mappedFile1)); Directory.CreateDirectory(Path.GetDirectoryName(mappedFile2)); File.WriteAllText(mappedFile1, "hello world"); @@ -171,7 +171,7 @@ namespace Umbraco.Tests.Packaging def = PackageBuilder.GetById(def.Id); //re-get Assert.IsNotNull(def.PackagePath); - using (var archive = ZipFile.OpenRead(IOHelper.MapPath(zip))) + using (var archive = ZipFile.OpenRead(Current.IOHelper.MapPath(zip))) { Assert.AreEqual(3, archive.Entries.Count); diff --git a/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs b/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs index 61494166ff..909b910feb 100644 --- a/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs +++ b/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using NUnit.Framework; +using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Packaging; @@ -15,7 +16,7 @@ namespace Umbraco.Tests.Packaging private static FileInfo GetTestPackagePath(string packageName) { const string testPackagesDirName = "Packaging\\Packages"; - string path = Path.Combine(IOHelper.GetRootDirectorySafe(), testPackagesDirName, packageName); + string path = Path.Combine(Current.IOHelper.GetRootDirectorySafe(), testPackagesDirName, packageName); return new FileInfo(path); } diff --git a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs index 6dd3f2aacb..14a7049195 100644 --- a/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs +++ b/src/Umbraco.Tests/Packaging/PackageInstallationTest.cs @@ -35,7 +35,7 @@ namespace Umbraco.Tests.Packaging base.TearDown(); //clear out files/folders - var path = IOHelper.MapPath("~/" + _testBaseFolder); + var path = Current.IOHelper.MapPath("~/" + _testBaseFolder); if (Directory.Exists(path)) Directory.Delete(path, true); } @@ -53,7 +53,7 @@ namespace Umbraco.Tests.Packaging PackageDataInstallation, new PackageFileInstallation(Parser, ProfilingLogger), Parser, Mock.Of(), - applicationRootFolder: new DirectoryInfo(IOHelper.MapPath("~/" + _testBaseFolder))); //we don't want to extract package files to the real root, so extract to a test folder + applicationRootFolder: new DirectoryInfo(Current.IOHelper.MapPath("~/" + _testBaseFolder))); //we don't want to extract package files to the real root, so extract to a test folder private const string DocumentTypePickerPackage = "Document_Type_Picker_1.1.umb"; private const string HelloPackage = "Hello_1.0.0.zip"; @@ -63,7 +63,7 @@ namespace Umbraco.Tests.Packaging { var package = PackageInstallation.ReadPackage( //this is where our test zip file is - new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); + new FileInfo(Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); Assert.IsNotNull(package); Assert.AreEqual(1, package.Files.Count); Assert.AreEqual("095e064b-ba4d-442d-9006-3050983c13d8.dll", package.Files[0].UniqueFileName); @@ -86,7 +86,7 @@ namespace Umbraco.Tests.Packaging { var package = PackageInstallation.ReadPackage( //this is where our test zip file is - new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), HelloPackage))); + new FileInfo(Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), HelloPackage))); Assert.IsNotNull(package); Assert.AreEqual(0, package.Files.Count); Assert.AreEqual("Hello", package.Name); @@ -111,7 +111,7 @@ namespace Umbraco.Tests.Packaging public void Can_Read_Compiled_Package_Warnings() { //copy a file to the same path that the package will install so we can detect file conflicts - var path = IOHelper.MapPath("~/" + _testBaseFolder); + var path = Current.IOHelper.MapPath("~/" + _testBaseFolder); Console.WriteLine(path); var filePath = Path.Combine(path, "bin", "Auros.DocumentTypePicker.dll"); @@ -119,7 +119,7 @@ namespace Umbraco.Tests.Packaging File.WriteAllText(filePath, "test"); //this is where our test zip file is - var packageFile = Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage); + var packageFile = Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage); Console.WriteLine(packageFile); var package = PackageInstallation.ReadPackage(new FileInfo(packageFile)); @@ -137,7 +137,7 @@ namespace Umbraco.Tests.Packaging { var package = PackageInstallation.ReadPackage( //this is where our test zip file is - new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); + new FileInfo(Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); var def = PackageDefinition.FromCompiledPackage(package); def.Id = 1; @@ -148,7 +148,7 @@ namespace Umbraco.Tests.Packaging Assert.AreEqual(1, result.Count); Assert.AreEqual("bin\\Auros.DocumentTypePicker.dll", result[0]); - Assert.IsTrue(File.Exists(Path.Combine(IOHelper.MapPath("~/" + _testBaseFolder), result[0]))); + Assert.IsTrue(File.Exists(Path.Combine(Current.IOHelper.MapPath("~/" + _testBaseFolder), result[0]))); //make sure the def is updated too Assert.AreEqual(result.Count, def.Files.Count); @@ -159,7 +159,7 @@ namespace Umbraco.Tests.Packaging { var package = PackageInstallation.ReadPackage( //this is where our test zip file is - new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); + new FileInfo(Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); var def = PackageDefinition.FromCompiledPackage(package); def.Id = 1; def.PackageId = Guid.NewGuid(); diff --git a/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs b/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs index 0b98ec64b6..00ab29bfea 100644 --- a/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs +++ b/src/Umbraco.Tests/Publishing/PublishingStrategyTests.cs @@ -19,7 +19,7 @@ namespace Umbraco.Tests.Publishing { base.SetUp(); - //LegacyUmbracoSettings.SettingsFilePath = IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false); + //LegacyUmbracoSettings.SettingsFilePath = Current.IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false); } private IContent _homePage; diff --git a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs index 1f1500137f..440c279755 100644 --- a/src/Umbraco.Tests/Runtimes/StandaloneTests.cs +++ b/src/Umbraco.Tests/Runtimes/StandaloneTests.cs @@ -47,7 +47,7 @@ namespace Umbraco.Tests.Runtimes IFactory factory = null; // clear - foreach (var file in Directory.GetFiles(Path.Combine(IOHelper.MapPath("~/App_Data")), "NuCache.*")) + foreach (var file in Directory.GetFiles(Path.Combine(Current.IOHelper.MapPath("~/App_Data")), "NuCache.*")) File.Delete(file); // settings @@ -59,9 +59,9 @@ namespace Umbraco.Tests.Runtimes var logger = new ConsoleLogger(); var profiler = new LogProfiler(logger); var profilingLogger = new ProfilingLogger(logger, profiler); - var appCaches = AppCaches.Disabled; + var appCaches = AppCaches.Disabled; var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy(() => factory.GetInstance())); - var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); + var typeLoader = new TypeLoader(appCaches.RuntimeCache, Current.IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var mainDom = new SimpleMainDom(); var runtimeState = new RuntimeState(logger, null, null, new Lazy(() => mainDom), new Lazy(() => factory.GetInstance())); @@ -249,7 +249,7 @@ namespace Umbraco.Tests.Runtimes var profilingLogger = new ProfilingLogger(logger, profiler); var appCaches = AppCaches.Disabled; var databaseFactory = Mock.Of(); - var typeLoader = new TypeLoader(appCaches.RuntimeCache, IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); + var typeLoader = new TypeLoader(appCaches.RuntimeCache, Current.IOHelper.MapPath("~/App_Data/TEMP"), profilingLogger); var runtimeState = Mock.Of(); Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run); var mainDom = Mock.Of(); diff --git a/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs b/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs index b9d680780e..305ae70be9 100644 --- a/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeFileSystemsTests.cs @@ -44,16 +44,16 @@ namespace Umbraco.Tests.Scoping private static void ClearFiles() { - TestHelper.DeleteDirectory(IOHelper.MapPath("media")); - TestHelper.DeleteDirectory(IOHelper.MapPath("FileSysTests")); - TestHelper.DeleteDirectory(IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); + TestHelper.DeleteDirectory(Current.IOHelper.MapPath("media")); + TestHelper.DeleteDirectory(Current.IOHelper.MapPath("FileSysTests")); + TestHelper.DeleteDirectory(Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs")); } [TestCase(true)] [TestCase(false)] public void CreateMediaTest(bool complete) { - var physMediaFileSystem = new PhysicalFileSystem(IOHelper.MapPath("media"), "ignore"); + var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper.MapPath("media"), "ignore"); var mediaFileSystem = Current.MediaFileSystem; Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt")); @@ -86,7 +86,7 @@ namespace Umbraco.Tests.Scoping [Test] public void MultiThread() { - var physMediaFileSystem = new PhysicalFileSystem(IOHelper.MapPath("media"), "ignore"); + var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper.MapPath("media"), "ignore"); var mediaFileSystem = Current.MediaFileSystem; var scopeProvider = ScopeProvider; diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index f62effcb62..eb3eb8c483 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -38,7 +38,7 @@ namespace Umbraco.Tests.TestHelpers var logger = new ProfilingLogger(Mock.Of(), Mock.Of()); var typeLoader = new TypeLoader(NoAppCache.Instance, - IOHelper.MapPath("~/App_Data/TEMP"), + Current.IOHelper.MapPath("~/App_Data/TEMP"), logger, false); diff --git a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs index 572d572ab7..98ae816317 100644 --- a/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs +++ b/src/Umbraco.Tests/TestHelpers/SettingsForTests.cs @@ -2,6 +2,7 @@ using System.Configuration; using Moq; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.IO; @@ -17,11 +18,11 @@ namespace Umbraco.Tests.TestHelpers settings.ConfigurationStatus == UmbracoVersion.SemanticVersion.ToSemanticString() && settings.UseHttps == false && settings.HideTopLevelNodeFromPath == false && - settings.Path == IOHelper.ResolveUrl("~/umbraco") && + settings.Path == Current.IOHelper.ResolveUrl("~/umbraco") && settings.TimeOutInMinutes == 20 && settings.DefaultUILanguage == "en" && settings.LocalTempStorageLocation == LocalTempStorage.Default && - settings.LocalTempPath == IOHelper.MapPath("~/App_Data/TEMP") && + settings.LocalTempPath == Current.IOHelper.MapPath("~/App_Data/TEMP") && settings.ReservedPaths == (GlobalSettings.StaticReservedPaths + "~/umbraco") && settings.ReservedUrls == GlobalSettings.StaticReservedUrls); return config; diff --git a/src/Umbraco.Tests/TestHelpers/TestHelper.cs b/src/Umbraco.Tests/TestHelpers/TestHelper.cs index dc692af36a..647797a500 100644 --- a/src/Umbraco.Tests/TestHelpers/TestHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/TestHelper.cs @@ -9,6 +9,7 @@ using System.Reflection; using System.Threading; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -67,9 +68,9 @@ namespace Umbraco.Tests.TestHelpers { foreach (var directory in directories) { - var directoryInfo = new DirectoryInfo(IOHelper.MapPath(directory)); + var directoryInfo = new DirectoryInfo(Current.IOHelper.MapPath(directory)); if (directoryInfo.Exists == false) - Directory.CreateDirectory(IOHelper.MapPath(directory)); + Directory.CreateDirectory(Current.IOHelper.MapPath(directory)); } } @@ -81,7 +82,7 @@ namespace Umbraco.Tests.TestHelpers }; foreach (var directory in directories) { - var directoryInfo = new DirectoryInfo(IOHelper.MapPath(directory)); + var directoryInfo = new DirectoryInfo(Current.IOHelper.MapPath(directory)); var preserve = preserves.ContainsKey(directory) ? preserves[directory] : null; if (directoryInfo.Exists) foreach (var x in directoryInfo.GetFiles().Where(x => preserve == null || preserve.Contains(x.Name) == false)) diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 56ad22d414..22858c2aed 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(IOHelper.MapPath(SystemDirectories.Umbraco + "/config/lang/")); - var appPlugins = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins)); - var configLangFolder = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config + "/lang/")); + 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 pluginLangFolders = appPlugins.Exists == false ? Enumerable.Empty() @@ -181,7 +181,7 @@ namespace Umbraco.Tests.TestHelpers new PackageDataInstallation(logger, fileService.Value, macroService.Value, localizationService.Value, dataTypeService.Value, entityService.Value, contentTypeService.Value, contentService.Value, propertyEditorCollection, scopeProvider), new PackageFileInstallation(compiledPackageXmlParser, new ProfilingLogger(logger, new TestProfiler())), compiledPackageXmlParser, Mock.Of(), - new DirectoryInfo(IOHelper.GetRootDirectorySafe()))); + new DirectoryInfo(Current.IOHelper.GetRootDirectorySafe()))); }); var relationService = GetLazyService(factory, c => new RelationService(scopeProvider, logger, eventMessagesFactory, entityService.Value, GetRepo(c), GetRepo(c))); var tagService = GetLazyService(factory, c => new TagService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); diff --git a/src/Umbraco.Tests/Web/Controllers/AuthenticationControllerTests.cs b/src/Umbraco.Tests/Web/Controllers/AuthenticationControllerTests.cs index 3d264663b5..ef28a7fc9d 100644 --- a/src/Umbraco.Tests/Web/Controllers/AuthenticationControllerTests.cs +++ b/src/Umbraco.Tests/Web/Controllers/AuthenticationControllerTests.cs @@ -70,10 +70,10 @@ namespace Umbraco.Tests.Web.Controllers } else { - var baseDir = IOHelper.MapPath("", false).TrimEnd(IOHelper.DirSepChar); + var baseDir = Current.IOHelper.MapPath("", false).TrimEnd(Current.IOHelper.DirSepChar); HttpContext.Current = new HttpContext(new SimpleWorkerRequest("/", baseDir, "", "", new StringWriter())); } - IOHelper.ForceNotHosted = true; + Current.IOHelper.ForceNotHosted = true; var usersController = new AuthenticationController( Factory.GetInstance(), umbracoContextAccessor, diff --git a/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs b/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs index 3a5405548b..b1c49b511d 100644 --- a/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs +++ b/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs @@ -40,7 +40,7 @@ namespace Umbraco.Tests.Web // FIXME: bad in a unit test - but Udi has a static ctor that wants it?! var factory = new Mock(); factory.Setup(x => x.GetInstance(typeof(TypeLoader))).Returns( - new TypeLoader(NoAppCache.Instance, IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of(), Mock.Of()))); + new TypeLoader(NoAppCache.Instance, Current.IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of(), Mock.Of()))); factory.Setup(x => x.GetInstance(typeof (ServiceContext))).Returns(serviceContext); var settings = SettingsForTests.GetDefaultUmbracoSettings(); diff --git a/src/Umbraco.Tests/Web/UmbracoHelperTests.cs b/src/Umbraco.Tests/Web/UmbracoHelperTests.cs index 26d85f60cf..ead2f850fd 100644 --- a/src/Umbraco.Tests/Web/UmbracoHelperTests.cs +++ b/src/Umbraco.Tests/Web/UmbracoHelperTests.cs @@ -265,7 +265,7 @@ namespace Umbraco.Tests.Web .Setup(x => x.GetInstance(typeof(TypeLoader))) .Returns(new TypeLoader( NoAppCache.Instance, - IOHelper.MapPath("~/App_Data/TEMP"), + Current.IOHelper.MapPath("~/App_Data/TEMP"), new ProfilingLogger(Mock.Of(), Mock.Of()) ) ); diff --git a/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml b/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml index b7c1e6540c..59568b508e 100644 --- a/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml @@ -7,6 +7,7 @@ @using Microsoft.Owin.Security @using Newtonsoft.Json @using Newtonsoft.Json.Linq +@using Umbraco.Core.Composing @using Umbraco.Core.IO @using Umbraco.Web @using Umbraco.Web.Editors @@ -32,7 +33,7 @@ Umbraco @Html.RenderCssHere( - new BasicPath("Umbraco", IOHelper.ResolveUrl(SystemDirectories.Umbraco))) + new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco))) @*Because we're lazy loading angular js, the embedded cloak style will not be loaded initially, but we need it*@