first round of refactoring

This commit is contained in:
Søren Gregersen
2019-11-13 21:00:54 +01:00
parent 149d128d03
commit 7b19ab005b
51 changed files with 388 additions and 242 deletions

View File

@@ -10,15 +10,17 @@ namespace Umbraco.Core.Compose
{
private readonly IRuntimeState _runtimeState;
private readonly ILogger _logger;
private readonly IIOHelper _ioHelper;
// if configured and in debug mode, a ManifestWatcher watches App_Plugins folders for
// package.manifest chances and restarts the application on any change
private ManifestWatcher _mw;
public ManifestWatcherComponent(IRuntimeState runtimeState, ILogger logger)
public ManifestWatcherComponent(IRuntimeState runtimeState, ILogger logger, IIOHelper ioHelper)
{
_runtimeState = runtimeState;
_logger = logger;
_ioHelper = ioHelper;
}
public void Initialize()
@@ -28,7 +30,7 @@ namespace Umbraco.Core.Compose
//if (ApplicationContext.Current.IsConfigured == false || GlobalSettings.DebugMode == false)
// return;
var appPlugins = Current.IOHelper.MapPath("~/App_Plugins/");
var appPlugins = _ioHelper.MapPath("~/App_Plugins/");
if (Directory.Exists(appPlugins) == false) return;
_mw = new ManifestWatcher(_logger);

View File

@@ -90,7 +90,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions
// register the IFileSystem supporting the IMediaFileSystem
// THIS IS THE ONLY THING THAT NEEDS TO CHANGE, IN ORDER TO REPLACE THE UNDERLYING FILESYSTEM
// and, SupportingFileSystem.For<IMediaFileSystem>() returns the underlying filesystem
composition.SetMediaFileSystem(() => new PhysicalFileSystem(SystemDirectories.Media));
composition.SetMediaFileSystem(factory => new PhysicalFileSystem(SystemDirectories.Media, factory.GetInstance<IIOHelper>()));
return composition;
}

View File

@@ -71,7 +71,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions
new PackageInstallation(
factory.GetInstance<PackageDataInstallation>(), factory.GetInstance<PackageFileInstallation>(),
factory.GetInstance<CompiledPackageXmlParser>(), factory.GetInstance<IPackageActionRunner>(),
new DirectoryInfo(Current.IOHelper.GetRootDirectorySafe())));
new DirectoryInfo( factory.GetInstance<IIOHelper>().GetRootDirectorySafe())));
return composition;
}
@@ -84,14 +84,16 @@ namespace Umbraco.Core.Composing.CompositionExtensions
/// <returns></returns>
private static PackagesRepository CreatePackageRepository(IFactory factory, string packageRepoFileName)
=> new PackagesRepository(
factory.GetInstance<IContentService>(), factory.GetInstance<IContentTypeService>(), factory.GetInstance<IDataTypeService>(), factory.GetInstance<IFileService>(), factory.GetInstance<IMacroService>(), factory.GetInstance<ILocalizationService>(), factory.GetInstance<IEntityXmlSerializer>(), factory.GetInstance<ILogger>(),
factory.GetInstance<IContentService>(), factory.GetInstance<IContentTypeService>(), factory.GetInstance<IDataTypeService>(), factory.GetInstance<IFileService>(), factory.GetInstance<IMacroService>(), factory.GetInstance<ILocalizationService>(), factory.GetInstance<IIOHelper>(), factory.GetInstance<IEntityXmlSerializer>(), factory.GetInstance<ILogger>(),
packageRepoFileName);
private static LocalizedTextServiceFileSources SourcesFactory(IFactory container)
{
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 ioHelper = container.GetInstance<IIOHelper>();
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 pluginLangFolders = appPlugins.Exists == false
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()

View File

@@ -205,6 +205,7 @@ namespace Umbraco.Core.Composing
public static IVariationContextAccessor VariationContextAccessor
=> Factory.GetInstance<IVariationContextAccessor>();
[Obsolete("being removed...", true)]
public static readonly IIOHelper IOHelper = new IOHelper();
#endregion

View File

@@ -33,9 +33,11 @@ namespace Umbraco.Core
public static void AddCoreConfigs(this Configs configs)
{
var configDir = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Config));
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
configs.Add<IGlobalSettings>(() => new GlobalSettings());
var configDir = new DirectoryInfo(ioHelper.MapPath(SystemDirectories.Config));
configs.Add<IGlobalSettings>(() => new GlobalSettings(ioHelper));
configs.Add<IUmbracoSettingsSection>("umbracoConfiguration/settings");
configs.Add<IHealthChecks>("umbracoConfiguration/HealthChecks");

View File

@@ -19,6 +19,7 @@ namespace Umbraco.Core.Configuration
/// </summary>
public class GlobalSettings : IGlobalSettings
{
private readonly IIOHelper _ioHelper;
private string _localTempPath;
// TODO these should not be static
@@ -29,6 +30,11 @@ namespace Umbraco.Core.Configuration
internal const string StaticReservedPaths = "~/app_plugins/,~/install/,~/mini-profiler-resources/,"; //must end with a comma!
internal const string StaticReservedUrls = "~/config/splashes/noNodes.aspx,~/.well-known,"; //must end with a comma!
public GlobalSettings(IIOHelper ioHelper)
{
_ioHelper = ioHelper;
}
/// <summary>
/// Used in unit testing to reset all config items that were set with property setters (i.e. did not come from config)
/// </summary>
@@ -141,7 +147,7 @@ namespace Umbraco.Core.Configuration
get
{
return ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.Path)
? Current.IOHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path])
? _ioHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path])
: string.Empty;
}
}
@@ -171,7 +177,9 @@ namespace Umbraco.Core.Configuration
/// <param name="value">Value of the setting to be saved.</param>
internal static void SaveSetting(string key, string value)
{
var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root));
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
var fileName = ioHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root));
var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace);
var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single();
@@ -191,9 +199,9 @@ namespace Umbraco.Core.Configuration
/// Removes a setting from the configuration file.
/// </summary>
/// <param name="key">Key of the setting to be removed.</param>
internal static void RemoveSetting(string key)
internal static void RemoveSetting(string key, IIOHelper ioHelper)
{
var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root));
var fileName = ioHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root));
var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace);
var appSettings = xml.Root.DescendantsAndSelf("appSettings").Single();
@@ -320,7 +328,7 @@ namespace Umbraco.Core.Configuration
//case LocalTempStorage.Default:
//case LocalTempStorage.Unknown:
default:
return _localTempPath = Current.IOHelper.MapPath("~/App_Data/TEMP");
return _localTempPath = _ioHelper.MapPath("~/App_Data/TEMP");
}
}
}

View File

@@ -148,7 +148,9 @@ namespace Umbraco.Core
if (filename == null || filestream == null) return;
// get a safe & clean filename
filename = Current.IOHelper.SafeFileName(filename);
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
filename = ioHelper.SafeFileName(filename);
if (string.IsNullOrWhiteSpace(filename)) return;
filename = filename.ToLower();

View File

@@ -110,11 +110,13 @@ namespace Umbraco.Core.Diagnostics
// filter everywhere in our code = not!
var stacktrace = withException ? Environment.StackTrace : string.Empty;
var filepath = Current.IOHelper.MapPath("~/App_Data/MiniDump");
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
var filepath = ioHelper.MapPath("~/App_Data/MiniDump");
if (Directory.Exists(filepath) == false)
Directory.CreateDirectory(filepath);
var filename = Path.Combine(filepath, string.Format("{0:yyyyMMddTHHmmss}.{1}.dmp", DateTime.UtcNow, Guid.NewGuid().ToString("N").Substring(0, 4)));
var filename = Path.Combine(filepath, $"{DateTime.UtcNow:yyyyMMddTHHmmss}.{Guid.NewGuid().ToString("N").Substring(0, 4)}.dmp");
using (var stream = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
{
return Write(stream.SafeFileHandle, options, withException);
@@ -126,7 +128,8 @@ namespace Umbraco.Core.Diagnostics
{
lock (LockO)
{
var filepath = Current.IOHelper.MapPath("~/App_Data/MiniDump");
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
var filepath = ioHelper.MapPath("~/App_Data/MiniDump");
if (Directory.Exists(filepath) == false) return true;
var count = Directory.GetFiles(filepath, "*.dmp").Length;
return count < 8;

View File

@@ -11,6 +11,7 @@ namespace Umbraco.Core.IO
{
private readonly IFactory _container;
private readonly ILogger _logger;
private readonly IIOHelper _ioHelper;
private readonly ConcurrentDictionary<Type, Lazy<IFileSystem>> _filesystems = new ConcurrentDictionary<Type, Lazy<IFileSystem>>();
@@ -33,10 +34,11 @@ namespace Umbraco.Core.IO
#region Constructor
// DI wants a public ctor
public FileSystems(IFactory container, ILogger logger)
public FileSystems(IFactory container, ILogger logger, IIOHelper ioHelper)
{
_container = container;
_logger = logger;
_ioHelper = ioHelper;
}
// for tests only, totally unsafe
@@ -120,17 +122,17 @@ namespace Umbraco.Core.IO
// but it does not really matter what we return - here, null
private object CreateWellKnownFileSystems()
{
var macroPartialFileSystem = new PhysicalFileSystem(SystemDirectories.MacroPartials);
var partialViewsFileSystem = new PhysicalFileSystem(SystemDirectories.PartialViews);
var stylesheetsFileSystem = new PhysicalFileSystem(SystemDirectories.Css);
var scriptsFileSystem = new PhysicalFileSystem(SystemDirectories.Scripts);
var mvcViewsFileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews);
var macroPartialFileSystem = new PhysicalFileSystem(SystemDirectories.MacroPartials, _ioHelper);
var partialViewsFileSystem = new PhysicalFileSystem(SystemDirectories.PartialViews, _ioHelper);
var stylesheetsFileSystem = new PhysicalFileSystem(SystemDirectories.Css, _ioHelper);
var scriptsFileSystem = new PhysicalFileSystem(SystemDirectories.Scripts, _ioHelper);
var mvcViewsFileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews, _ioHelper);
_macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, "macro-partials", IsScoped);
_partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, "partials", IsScoped);
_stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, "css", IsScoped);
_scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, "scripts", IsScoped);
_mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, "views", IsScoped);
_macroPartialFileSystem = new ShadowWrapper(macroPartialFileSystem, "macro-partials", _ioHelper, IsScoped);
_partialViewsFileSystem = new ShadowWrapper(partialViewsFileSystem, "partials", _ioHelper, IsScoped);
_stylesheetsFileSystem = new ShadowWrapper(stylesheetsFileSystem, "css", _ioHelper, IsScoped);
_scriptsFileSystem = new ShadowWrapper(scriptsFileSystem, "scripts", _ioHelper, IsScoped);
_mvcViewsFileSystem = new ShadowWrapper(mvcViewsFileSystem, "views", _ioHelper, IsScoped);
// TODO: do we need a lock here?
_shadowWrappers.Add(_macroPartialFileSystem);
@@ -269,7 +271,7 @@ namespace Umbraco.Core.IO
{
lock (_shadowLocker)
{
var wrapper = new ShadowWrapper(filesystem, shadowPath, IsScoped);
var wrapper = new ShadowWrapper(filesystem, shadowPath, _ioHelper, IsScoped);
if (_shadowCurrentId != null)
wrapper.Shadow(_shadowCurrentId);
_shadowWrappers.Add(wrapper);

View File

@@ -22,16 +22,18 @@ namespace Umbraco.Core.IO
private readonly IMediaPathScheme _mediaPathScheme;
private readonly IContentSection _contentConfig;
private readonly ILogger _logger;
private readonly IIOHelper _ioHelper;
/// <summary>
/// Initializes a new instance of the <see cref="MediaFileSystem"/> class.
/// </summary>
public MediaFileSystem(IFileSystem innerFileSystem, IContentSection contentConfig, IMediaPathScheme mediaPathScheme, ILogger logger)
public MediaFileSystem(IFileSystem innerFileSystem, IContentSection contentConfig, IMediaPathScheme mediaPathScheme, ILogger logger, IIOHelper ioHelper)
: base(innerFileSystem)
{
_contentConfig = contentConfig;
_mediaPathScheme = mediaPathScheme;
_logger = logger;
_ioHelper = ioHelper;
}
/// <inheritoc />
@@ -68,7 +70,7 @@ namespace Umbraco.Core.IO
{
filename = Path.GetFileName(filename);
if (filename == null) throw new ArgumentException("Cannot become a safe filename.", nameof(filename));
filename = Current.IOHelper.SafeFileName(filename.ToLowerInvariant());
filename = _ioHelper.SafeFileName(filename.ToLowerInvariant());
return _mediaPathScheme.GetFilePath(this, cuid, puid, filename);
}
@@ -78,7 +80,7 @@ namespace Umbraco.Core.IO
{
filename = Path.GetFileName(filename);
if (filename == null) throw new ArgumentException("Cannot become a safe filename.", nameof(filename));
filename = Current.IOHelper.SafeFileName(filename.ToLowerInvariant());
filename = _ioHelper.SafeFileName(filename.ToLowerInvariant());
return _mediaPathScheme.GetFilePath(this, cuid, puid, filename, prevpath);
}

View File

@@ -11,6 +11,8 @@ namespace Umbraco.Core.IO
{
public class PhysicalFileSystem : IFileSystem
{
private readonly IIOHelper _ioHelper;
// the rooted, filesystem path, using directory separator chars, NOT ending with a separator
// eg "c:" or "c:\path\to\site" or "\\server\path"
private readonly string _rootPath;
@@ -26,28 +28,32 @@ namespace Umbraco.Core.IO
// virtualRoot should be "~/path/to/root" eg "~/Views"
// the "~/" is mandatory.
public PhysicalFileSystem(string virtualRoot)
public PhysicalFileSystem(string virtualRoot, IIOHelper ioHelper)
{
if (virtualRoot == null) throw new ArgumentNullException("virtualRoot");
if (virtualRoot.StartsWith("~/") == false)
throw new ArgumentException("The virtualRoot argument must be a virtual path and start with '~/'");
_rootPath = EnsureDirectorySeparatorChar(Current.IOHelper.MapPath(virtualRoot)).TrimEnd(Path.DirectorySeparatorChar);
_ioHelper = ioHelper;
_rootPath = EnsureDirectorySeparatorChar(ioHelper.MapPath(virtualRoot)).TrimEnd(Path.DirectorySeparatorChar);
_rootPathFwd = EnsureUrlSeparatorChar(_rootPath);
_rootUrl = EnsureUrlSeparatorChar(Current.IOHelper.ResolveUrl(virtualRoot)).TrimEnd('/');
_rootUrl = EnsureUrlSeparatorChar(ioHelper.ResolveUrl(virtualRoot)).TrimEnd('/');
}
public PhysicalFileSystem(string rootPath, string rootUrl)
public PhysicalFileSystem(string rootPath, string rootUrl, IIOHelper ioHelper)
{
if (string.IsNullOrEmpty(rootPath)) throw new ArgumentNullOrEmptyException(nameof(rootPath));
if (string.IsNullOrEmpty(rootUrl)) throw new ArgumentNullOrEmptyException(nameof(rootUrl));
if (rootPath.StartsWith("~/")) throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'");
_ioHelper = ioHelper;
// rootPath should be... rooted, as in, it's a root path!
if (Path.IsPathRooted(rootPath) == false)
{
// but the test suite App.config cannot really "root" anything so we have to do it here
var localRoot = Current.IOHelper.GetRootDirectorySafe();
var localRoot = _ioHelper.GetRootDirectorySafe();
rootPath = Path.Combine(localRoot, rootPath);
}
@@ -257,12 +263,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 (Current.IOHelper.PathStartsWith(path, _rootUrl, '/'))
if (_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 (Current.IOHelper.PathStartsWith(path, _rootPathFwd, '/'))
if (_ioHelper.PathStartsWith(path, _rootPathFwd, '/'))
return path.Substring(_rootPathFwd.Length).TrimStart('/');
// unchanged - what else?
@@ -292,7 +298,7 @@ namespace Umbraco.Core.IO
path = GetRelativePath(path);
// if not already rooted, combine with the root path
if (Current.IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar) == false)
if (_ioHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar) == false)
path = Path.Combine(_rootPath, path);
// sanitize - GetFullPath will take care of any relative
@@ -303,7 +309,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 (Current.IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar))
if (_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

View File

@@ -12,14 +12,16 @@ namespace Umbraco.Core.IO
private readonly Func<bool> _isScoped;
private readonly IFileSystem _innerFileSystem;
private readonly IIOHelper _ioHelper;
private readonly string _shadowPath;
private ShadowFileSystem _shadowFileSystem;
private string _shadowDir;
public ShadowWrapper(IFileSystem innerFileSystem, string shadowPath, Func<bool> isScoped = null)
public ShadowWrapper(IFileSystem innerFileSystem, string shadowPath, IIOHelper ioHelper, Func<bool> isScoped = null)
{
_innerFileSystem = innerFileSystem;
_shadowPath = shadowPath;
_ioHelper = ioHelper;
_isScoped = isScoped;
}
@@ -33,12 +35,14 @@ namespace Umbraco.Core.IO
// we should end up with a unique identifier eventually - but just
// detect infinite loops (just in case)
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
for (var i = 0; i < retries; i++)
{
var id = GuidUtils.ToBase32String(Guid.NewGuid(), idLength);
var virt = ShadowFsPath + "/" + id;
var shadowDir = Current.IOHelper.MapPath(virt);
var shadowDir = ioHelper.MapPath(virt);
if (Directory.Exists(shadowDir))
continue;
@@ -56,9 +60,9 @@ namespace Umbraco.Core.IO
// in a single thread anyways
var virt = ShadowFsPath + "/" + id + "/" + _shadowPath;
_shadowDir = Current.IOHelper.MapPath(virt);
_shadowDir = _ioHelper.MapPath(virt);
Directory.CreateDirectory(_shadowDir);
var tempfs = new PhysicalFileSystem(virt);
var tempfs = new PhysicalFileSystem(virt, _ioHelper);
_shadowFileSystem = new ShadowFileSystem(_innerFileSystem, tempfs);
}
@@ -83,7 +87,7 @@ namespace Umbraco.Core.IO
// shadowPath make be path/to/dir, remove each
dir = dir.Replace("/", "\\");
var min = Current.IOHelper.MapPath(ShadowFsPath).Length;
var min = _ioHelper.MapPath(ShadowFsPath).Length;
var pos = dir.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase);
while (pos > min)
{

View File

@@ -6,6 +6,8 @@ namespace Umbraco.Core.IO
//all paths has a starting but no trailing /
public class SystemDirectories
{
private static IIOHelper IOHelper => Current.Factory.GetInstance<IIOHelper>();
public static string Bin => "~/bin";
public static string Config => "~/config";
@@ -30,13 +32,13 @@ namespace Umbraco.Core.IO
public static string MacroPartials => MvcViews + "/MacroPartials/";
public static string Media => Current.IOHelper.ReturnPath("umbracoMediaPath", "~/media");
public static string Media => IOHelper.ReturnPath("umbracoMediaPath", "~/media");
public static string Scripts => Current.IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts");
public static string Scripts => IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts");
public static string Css => Current.IOHelper.ReturnPath("umbracoCssPath", "~/css");
public static string Css => IOHelper.ReturnPath("umbracoCssPath", "~/css");
public static string Umbraco => Current.IOHelper.ReturnPath("umbracoPath", "~/umbraco");
public static string Umbraco => IOHelper.ReturnPath("umbracoPath", "~/umbraco");
public static string Packages => Data + "/packages";

View File

@@ -5,6 +5,7 @@ using System.Linq;
using Newtonsoft.Json;
using Serilog.Events;
using Serilog.Formatting.Compact.Reader;
using Umbraco.Core.IO;
namespace Umbraco.Core.Logging.Viewer
{
@@ -13,7 +14,7 @@ namespace Umbraco.Core.Logging.Viewer
private readonly string _logsPath;
private readonly ILogger _logger;
public JsonLogViewer(ILogger logger, string logsPath = "", string searchPath = "") : base(searchPath)
public JsonLogViewer(ILogger logger, IIOHelper ioHelper, string logsPath = "", string searchPath = "") : base(ioHelper, searchPath)
{
if (string.IsNullOrEmpty(logsPath))
logsPath = $@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\";

View File

@@ -1,5 +1,6 @@
using Umbraco.Core.Compose;
using Umbraco.Core.Composing;
using Umbraco.Core.IO;
namespace Umbraco.Core.Logging.Viewer
{
@@ -9,7 +10,7 @@ namespace Umbraco.Core.Logging.Viewer
{
public void Compose(Composition composition)
{
composition.SetLogViewer(_ => new JsonLogViewer(composition.Logger));
composition.SetLogViewer(factory => new JsonLogViewer(composition.Logger, factory.GetInstance<IIOHelper>()));
}
}
}

View File

@@ -15,17 +15,19 @@ namespace Umbraco.Core.Logging.Viewer
{
public abstract class LogViewerSourceBase : ILogViewer
{
protected LogViewerSourceBase(string pathToSearches = "")
private readonly string _searchesConfigPath;
private readonly IIOHelper _ioHelper;
protected LogViewerSourceBase(IIOHelper ioHelper, string pathToSearches = "")
{
if (string.IsNullOrEmpty(pathToSearches))
// ReSharper disable once StringLiteralTypo
pathToSearches = Current.IOHelper.MapPath("~/Config/logviewer.searches.config.js");
pathToSearches = ioHelper.MapPath("~/Config/logviewer.searches.config.js");
_searchesConfigPath = pathToSearches;
_ioHelper = ioHelper;
}
private readonly string _searchesConfigPath;
public abstract bool CanHandleLargeLogs { get; }
/// <summary>
@@ -40,7 +42,7 @@ namespace Umbraco.Core.Logging.Viewer
//Our default implementation
//If file does not exist - lets create it with an empty array
EnsureFileExists(_searchesConfigPath, "[]");
EnsureFileExists(_searchesConfigPath, "[]", _ioHelper);
var rawJson = System.IO.File.ReadAllText(_searchesConfigPath);
return JsonConvert.DeserializeObject<SavedLogSearch[]>(rawJson);
@@ -58,7 +60,7 @@ namespace Umbraco.Core.Logging.Viewer
var rawJson = JsonConvert.SerializeObject(searches, Formatting.Indented);
//If file does not exist - lets create it with an empty array
EnsureFileExists(_searchesConfigPath, "[]");
EnsureFileExists(_searchesConfigPath, "[]", _ioHelper);
//Write it back down to file
System.IO.File.WriteAllText(_searchesConfigPath, rawJson);
@@ -180,9 +182,9 @@ namespace Umbraco.Core.Logging.Viewer
};
}
private static void EnsureFileExists(string path, string contents)
private static void EnsureFileExists(string path, string contents, IIOHelper ioHelper)
{
var absolutePath = Current.IOHelper.MapPath(path);
var absolutePath = ioHelper.MapPath(path);
if (System.IO.File.Exists(absolutePath)) return;
using (var writer = System.IO.File.CreateText(absolutePath))

View File

@@ -22,6 +22,7 @@ namespace Umbraco.Core.Manifest
private readonly IAppPolicyCache _cache;
private readonly ILogger _logger;
private readonly IIOHelper _ioHelper;
private readonly ManifestValueValidatorCollection _validators;
private readonly ManifestFilterCollection _filters;
@@ -30,14 +31,14 @@ namespace Umbraco.Core.Manifest
/// <summary>
/// Initializes a new instance of the <see cref="ManifestParser"/> class.
/// </summary>
public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger)
: this(appCaches, validators, filters, "~/App_Plugins", logger)
public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger, IIOHelper ioHelper)
: this(appCaches, validators, filters, "~/App_Plugins", logger, ioHelper)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="ManifestParser"/> class.
/// </summary>
private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger)
private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger, IIOHelper ioHelper)
{
if (appCaches == null) throw new ArgumentNullException(nameof(appCaches));
_cache = appCaches.RuntimeCache;
@@ -46,12 +47,13 @@ namespace Umbraco.Core.Manifest
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullOrEmptyException(nameof(path));
Path = path;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_ioHelper = ioHelper;
}
public string Path
{
get => _path;
set => _path = value.StartsWith("~/") ? Current.IOHelper.MapPath(value) : value;
set => _path = value.StartsWith("~/") ? _ioHelper.MapPath(value) : value;
}
/// <summary>
@@ -166,9 +168,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] = Current.IOHelper.ResolveVirtualUrl(manifest.Scripts[i]);
manifest.Scripts[i] = _ioHelper.ResolveVirtualUrl(manifest.Scripts[i]);
for (var i = 0; i < manifest.Stylesheets.Length; i++)
manifest.Stylesheets[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Stylesheets[i]);
manifest.Stylesheets[i] = _ioHelper.ResolveVirtualUrl(manifest.Stylesheets[i]);
// add property editors that are also parameter editors, to the parameter editors list
// (the manifest format is kinda legacy)

View File

@@ -29,13 +29,14 @@ namespace Umbraco.Core.Migrations.Install
private readonly IMigrationBuilder _migrationBuilder;
private readonly IKeyValueService _keyValueService;
private readonly ILogger _logger;
private readonly IIOHelper _ioHelper;
private DatabaseSchemaResult _databaseSchemaValidationResult;
/// <summary>
/// Initializes a new instance of the <see cref="DatabaseBuilder"/> class.
/// </summary>
public DatabaseBuilder(IScopeProvider scopeProvider, IGlobalSettings globalSettings, IUmbracoDatabaseFactory databaseFactory, IRuntimeState runtime, ILogger logger, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService)
public DatabaseBuilder(IScopeProvider scopeProvider, IGlobalSettings globalSettings, IUmbracoDatabaseFactory databaseFactory, IRuntimeState runtime, ILogger logger, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, IIOHelper ioHelper)
{
_scopeProvider = scopeProvider;
_globalSettings = globalSettings;
@@ -44,6 +45,7 @@ namespace Umbraco.Core.Migrations.Install
_logger = logger;
_migrationBuilder = migrationBuilder;
_keyValueService = keyValueService;
_ioHelper = ioHelper;
}
#region Status
@@ -125,14 +127,14 @@ namespace Umbraco.Core.Migrations.Install
/// </summary>
public void ConfigureEmbeddedDatabaseConnection()
{
ConfigureEmbeddedDatabaseConnection(_databaseFactory, _logger);
ConfigureEmbeddedDatabaseConnection(_databaseFactory, _ioHelper, _logger);
}
private static void ConfigureEmbeddedDatabaseConnection(IUmbracoDatabaseFactory factory, ILogger logger)
private static void ConfigureEmbeddedDatabaseConnection(IUmbracoDatabaseFactory factory, IIOHelper ioHelper, ILogger logger)
{
SaveConnectionString(EmbeddedDatabaseConnectionString, Constants.DbProviderNames.SqlCe, logger);
SaveConnectionString(EmbeddedDatabaseConnectionString, Constants.DbProviderNames.SqlCe, ioHelper, logger);
var path = Path.Combine(Current.IOHelper.GetRootDirectorySafe(), "App_Data", "Umbraco.sdf");
var path = Path.Combine(ioHelper.GetRootDirectorySafe(), "App_Data", "Umbraco.sdf");
if (File.Exists(path) == false)
{
// this should probably be in a "using (new SqlCeEngine)" clause but not sure
@@ -154,7 +156,7 @@ namespace Umbraco.Core.Migrations.Install
{
const string providerName = Constants.DbProviderNames.SqlServer;
SaveConnectionString(connectionString, providerName, _logger);
SaveConnectionString(connectionString, providerName, _ioHelper, _logger);
_databaseFactory.Configure(connectionString, providerName);
}
@@ -170,7 +172,7 @@ namespace Umbraco.Core.Migrations.Install
{
var connectionString = GetDatabaseConnectionString(server, databaseName, user, password, databaseProvider, out var providerName);
SaveConnectionString(connectionString, providerName, _logger);
SaveConnectionString(connectionString, providerName, _ioHelper, _logger);
_databaseFactory.Configure(connectionString, providerName);
}
@@ -201,7 +203,7 @@ namespace Umbraco.Core.Migrations.Install
public void ConfigureIntegratedSecurityDatabaseConnection(string server, string databaseName)
{
var connectionString = GetIntegratedSecurityDatabaseConnectionString(server, databaseName);
SaveConnectionString(connectionString, Constants.DbProviderNames.SqlServer, _logger);
SaveConnectionString(connectionString, Constants.DbProviderNames.SqlServer, _ioHelper, _logger);
_databaseFactory.Configure(connectionString, Constants.DbProviderNames.SqlServer);
}
@@ -277,13 +279,13 @@ namespace Umbraco.Core.Migrations.Install
/// <param name="connectionString">The connection string.</param>
/// <param name="providerName">The provider name.</param>
/// <param name="logger">A logger.</param>
private static void SaveConnectionString(string connectionString, string providerName, ILogger logger)
private static void SaveConnectionString(string connectionString, string providerName, IIOHelper ioHelper, ILogger logger)
{
if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullOrEmptyException(nameof(connectionString));
if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullOrEmptyException(nameof(providerName));
var fileSource = "web.config";
var fileName = Current.IOHelper.MapPath(SystemDirectories.Root +"/" + fileSource);
var fileName = ioHelper.MapPath(SystemDirectories.Root +"/" + fileSource);
var xml = XDocument.Load(fileName, LoadOptions.PreserveWhitespace);
if (xml.Root == null) throw new Exception($"Invalid {fileSource} file (no root).");
@@ -296,7 +298,7 @@ namespace Umbraco.Core.Migrations.Install
if (configSourceAttribute != null)
{
fileSource = configSourceAttribute.Value;
fileName = Current.IOHelper.MapPath(SystemDirectories.Root + "/" + fileSource);
fileName = ioHelper.MapPath(SystemDirectories.Root + "/" + fileSource);
if (!File.Exists(fileName))
throw new Exception($"Invalid configSource \"{fileSource}\" (no such file).");

View File

@@ -20,12 +20,14 @@ namespace Umbraco.Core.Packaging
internal class PackageFileInstallation
{
private readonly CompiledPackageXmlParser _parser;
private readonly IIOHelper _ioHelper;
private readonly IProfilingLogger _logger;
private readonly PackageExtraction _packageExtraction;
public PackageFileInstallation(CompiledPackageXmlParser parser, IProfilingLogger logger)
public PackageFileInstallation(CompiledPackageXmlParser parser, IIOHelper ioHelper, IProfilingLogger logger)
{
_parser = parser;
_ioHelper = ioHelper;
_logger = logger;
_packageExtraction = new PackageExtraction();
}
@@ -60,15 +62,15 @@ namespace Umbraco.Core.Packaging
foreach (var item in package.Files.ToArray())
{
removedFiles.Add(Current.IOHelper.GetRelativePath(item));
removedFiles.Add(_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 = Current.IOHelper.FindFile(item);
var file = _ioHelper.FindFile(item);
if (file != null)
{
// TODO: Surely this should be ~/ ?
file = file.EnsureStartsWith("/");
var filePath = Current.IOHelper.MapPath(file);
var filePath = _ioHelper.MapPath(file);
if (File.Exists(filePath))
File.Delete(filePath);

View File

@@ -29,6 +29,7 @@ namespace Umbraco.Core.Packaging
private readonly ILocalizationService _languageService;
private readonly IEntityXmlSerializer _serializer;
private readonly ILogger _logger;
private readonly IIOHelper _ioHelper;
private readonly string _packageRepositoryFileName;
private readonly string _mediaFolderPath;
private readonly string _packagesFolderPath;
@@ -44,6 +45,7 @@ namespace Umbraco.Core.Packaging
/// <param name="fileService"></param>
/// <param name="macroService"></param>
/// <param name="languageService"></param>
/// <param name="ioHelper"></param>
/// <param name="serializer"></param>
/// <param name="logger"></param>
/// <param name="packageRepositoryFileName">
@@ -55,6 +57,7 @@ namespace Umbraco.Core.Packaging
public PackagesRepository(IContentService contentService, IContentTypeService contentTypeService,
IDataTypeService dataTypeService, IFileService fileService, IMacroService macroService,
ILocalizationService languageService,
IIOHelper ioHelper,
IEntityXmlSerializer serializer, ILogger logger,
string packageRepositoryFileName,
string tempFolderPath = null, string packagesFolderPath = null, string mediaFolderPath = null)
@@ -68,6 +71,7 @@ namespace Umbraco.Core.Packaging
_languageService = languageService;
_serializer = serializer;
_logger = logger;
_ioHelper = ioHelper;
_packageRepositoryFileName = packageRepositoryFileName;
_tempFolderPath = tempFolderPath ?? SystemDirectories.TempData.EnsureEndsWith('/') + "PackageFiles";
@@ -155,7 +159,7 @@ namespace Umbraco.Core.Packaging
ValidatePackage(definition);
//Create a folder for building this package
var temporaryPath = Current.IOHelper.MapPath(_tempFolderPath.EnsureEndsWith('/') + Guid.NewGuid());
var temporaryPath = _ioHelper.MapPath(_tempFolderPath.EnsureEndsWith('/') + Guid.NewGuid());
if (Directory.Exists(temporaryPath) == false)
Directory.CreateDirectory(temporaryPath);
@@ -178,13 +182,13 @@ namespace Umbraco.Core.Packaging
//Files
foreach (var fileName in definition.Files)
AppendFileToPackage(fileName, temporaryPath, filesXml);
AppendFileToPackage(fileName, temporaryPath, filesXml, _ioHelper);
//Load view on install...
if (!string.IsNullOrEmpty(definition.PackageView))
{
var control = new XElement("view", definition.PackageView);
AppendFileToPackage(definition.PackageView, temporaryPath, filesXml);
AppendFileToPackage(definition.PackageView, temporaryPath, filesXml, _ioHelper);
root.Add(control);
}
@@ -214,11 +218,11 @@ namespace Umbraco.Core.Packaging
// check if there's a packages directory below media
if (Directory.Exists(Current.IOHelper.MapPath(_mediaFolderPath)) == false)
Directory.CreateDirectory(Current.IOHelper.MapPath(_mediaFolderPath));
if (Directory.Exists(_ioHelper.MapPath(_mediaFolderPath)) == false)
Directory.CreateDirectory(_ioHelper.MapPath(_mediaFolderPath));
var packPath = _mediaFolderPath.EnsureEndsWith('/') + (definition.Name + "_" + definition.Version).Replace(' ', '_') + ".zip";
ZipPackage(temporaryPath, Current.IOHelper.MapPath(packPath));
ZipPackage(temporaryPath, _ioHelper.MapPath(packPath));
//we need to update the package path and save it
definition.PackagePath = packPath;
@@ -294,7 +298,7 @@ namespace Umbraco.Core.Packaging
macros.Add(macroXml);
//if the macro has a file copy it to the xml
if (!string.IsNullOrEmpty(macro.MacroSource))
AppendFileToPackage(macro.MacroSource, temporaryPath, filesXml);
AppendFileToPackage(macro.MacroSource, temporaryPath, filesXml,_ioHelper);
}
root.Add(macros);
}
@@ -444,12 +448,12 @@ namespace Umbraco.Core.Packaging
/// <param name="path">The path.</param>
/// <param name="packageDirectory">The package directory.</param>
/// <param name="filesXml">The files xml node</param>
private static void AppendFileToPackage(string path, string packageDirectory, XContainer filesXml)
private static void AppendFileToPackage(string path, string packageDirectory, XContainer filesXml, IIOHelper ioHelper)
{
if (!path.StartsWith("~/") && !path.StartsWith("/"))
path = "~/" + path;
var serverPath = Current.IOHelper.MapPath(path);
var serverPath = ioHelper.MapPath(path);
if (File.Exists(serverPath))
AppendFileXml(new FileInfo(serverPath), path, packageDirectory, filesXml);
@@ -608,11 +612,11 @@ namespace Umbraco.Core.Packaging
private XDocument EnsureStorage(out string packagesFile)
{
var packagesFolder = Current.IOHelper.MapPath(_packagesFolderPath);
var packagesFolder = _ioHelper.MapPath(_packagesFolderPath);
//ensure it exists
Directory.CreateDirectory(packagesFolder);
packagesFile = Current.IOHelper.MapPath(CreatedPackagesFile);
packagesFile = _ioHelper.MapPath(CreatedPackagesFile);
if (!File.Exists(packagesFile))
{
var xml = new XDocument(new XElement("packages"));

View File

@@ -5,8 +5,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
{
internal class PartialViewMacroRepository : PartialViewRepository, IPartialViewMacroRepository
{
public PartialViewMacroRepository(IFileSystems fileSystems)
: base(fileSystems.MacroPartialsFileSystem)
public PartialViewMacroRepository(IFileSystems fileSystems, IIOHelper ioHelper)
: base(fileSystems.MacroPartialsFileSystem, ioHelper)
{ }
protected override PartialViewType ViewType => PartialViewType.PartialViewMacro;

View File

@@ -10,13 +10,19 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
{
internal class PartialViewRepository : FileRepository<string, IPartialView>, IPartialViewRepository
{
public PartialViewRepository(IFileSystems fileSystems)
: base(fileSystems.PartialViewsFileSystem)
{ }
private readonly IIOHelper _ioHelper;
protected PartialViewRepository(IFileSystem fileSystem)
public PartialViewRepository(IFileSystems fileSystems, IIOHelper ioHelper)
: base(fileSystems.PartialViewsFileSystem)
{
_ioHelper = ioHelper;
}
protected PartialViewRepository(IFileSystem fileSystem, IIOHelper ioHelper)
: base(fileSystem)
{ }
{
_ioHelper = ioHelper;
}
protected virtual PartialViewType ViewType => PartialViewType.PartialView;
@@ -104,8 +110,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
// validate path & extension
var validDir = SystemDirectories.MvcViews;
var isValidPath = Current.IOHelper.VerifyEditPath(fullPath, validDir);
var isValidExtension = Current.IOHelper.VerifyFileExtension(fullPath, ValidExtensions);
var isValidPath = _ioHelper.VerifyEditPath(fullPath, validDir);
var isValidExtension = _ioHelper.VerifyFileExtension(fullPath, ValidExtensions);
return isValidPath && isValidExtension;
}

View File

@@ -23,12 +23,14 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
/// </summary>
internal class TemplateRepository : NPocoRepositoryBase<int, ITemplate>, ITemplateRepository
{
private readonly IIOHelper _ioHelper;
private readonly IFileSystem _viewsFileSystem;
private readonly ViewHelper _viewHelper;
public TemplateRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger logger, IFileSystems fileSystems)
public TemplateRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger logger, IFileSystems fileSystems, IIOHelper ioHelper)
: base(scopeAccessor, cache, logger)
{
_ioHelper = ioHelper;
_viewsFileSystem = fileSystems.MvcViewsFileSystem;
_viewHelper = new ViewHelper(_viewsFileSystem);
}
@@ -593,8 +595,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
validExts.Add("vbhtml");
// validate path and extension
var validFile = Current.IOHelper.VerifyEditPath(path, validDirs);
var validExtension = Current.IOHelper.VerifyFileExtension(path, validExts);
var validFile = _ioHelper.VerifyEditPath(path, validDirs);
var validExtension = _ioHelper.VerifyFileExtension(path, validExts);
return validFile && validExtension;
}

View File

@@ -94,7 +94,7 @@ namespace Umbraco.Core.PropertyEditors
public string View
{
get => _view;
set => _view = Current.IOHelper.ResolveVirtualUrl(value);
set => _view = Current.Factory.GetInstance<IIOHelper>().ResolveVirtualUrl(value);
}
/// <summary>

View File

@@ -8,11 +8,13 @@ namespace Umbraco.Core.PropertyEditors
{
public class GridEditor : IGridEditorConfig
{
private readonly IIOHelper _ioHelper;
private string _view;
private string _render;
public GridEditor()
public GridEditor(IIOHelper ioHelper)
{
_ioHelper = ioHelper;
Config = new Dictionary<string, object>();
}
@@ -29,14 +31,14 @@ namespace Umbraco.Core.PropertyEditors
public string View
{
get => _view;
set => _view = Current.IOHelper.ResolveVirtualUrl(value);
set => _view = _ioHelper.ResolveVirtualUrl(value);
}
[JsonProperty("render")]
public string Render
{
get => _render;
set => _render = Current.IOHelper.ResolveVirtualUrl(value);
set => _render = _ioHelper.ResolveVirtualUrl(value);
}
[JsonProperty("icon", Required = Required.Always)]

View File

@@ -5,15 +5,22 @@ namespace Umbraco.Core.Runtime
{
public class CoreInitialComponent : IComponent
{
private readonly IIOHelper _ioHelper;
public CoreInitialComponent(IIOHelper ioHelper)
{
_ioHelper = ioHelper;
}
public void Initialize()
{
// ensure we have some essential directories
// every other component can then initialize safely
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");
_ioHelper.EnsurePathExists("~/App_Data");
_ioHelper.EnsurePathExists(SystemDirectories.Media);
_ioHelper.EnsurePathExists(SystemDirectories.MvcViews);
_ioHelper.EnsurePathExists(SystemDirectories.MvcViews + "/Partials");
_ioHelper.EnsurePathExists(SystemDirectories.MvcViews + "/MacroPartials");
}
public void Terminate()

View File

@@ -239,7 +239,7 @@ namespace Umbraco.Core.Runtime
{
var path = GetApplicationRootPath();
if (string.IsNullOrWhiteSpace(path) == false)
Current.IOHelper.SetRootDirectory(path);
IOHelper.SetRootDirectory(path);
}
private bool AcquireMainDom(MainDom mainDom)

View File

@@ -19,6 +19,7 @@ namespace Umbraco.Core.Services.Implement
/// </summary>
public class FileService : ScopeRepositoryService, IFileService
{
private readonly IIOHelper _ioHelper;
private readonly IStylesheetRepository _stylesheetRepository;
private readonly IScriptRepository _scriptRepository;
private readonly ITemplateRepository _templateRepository;
@@ -29,12 +30,13 @@ namespace Umbraco.Core.Services.Implement
private const string PartialViewHeader = "@inherits Umbraco.Web.Mvc.UmbracoViewPage";
private const string PartialViewMacroHeader = "@inherits Umbraco.Web.Macros.PartialViewMacroPage";
public FileService(IScopeProvider uowProvider, ILogger logger, IEventMessagesFactory eventMessagesFactory,
public FileService(IScopeProvider uowProvider, IIOHelper ioHelper, ILogger logger, IEventMessagesFactory eventMessagesFactory,
IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, ITemplateRepository templateRepository,
IPartialViewRepository partialViewRepository, IPartialViewMacroRepository partialViewMacroRepository,
IAuditRepository auditRepository)
: base(uowProvider, logger, eventMessagesFactory)
{
_ioHelper = ioHelper;
_stylesheetRepository = stylesheetRepository;
_scriptRepository = scriptRepository;
_templateRepository = templateRepository;
@@ -664,7 +666,7 @@ namespace Umbraco.Core.Services.Implement
public IEnumerable<string> GetPartialViewSnippetNames(params string[] filterNames)
{
var snippetPath = Current.IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/");
var snippetPath = _ioHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/");
var files = Directory.GetFiles(snippetPath, "*.cshtml")
.Select(Path.GetFileNameWithoutExtension)
.Except(filterNames, StringComparer.InvariantCultureIgnoreCase)
@@ -898,7 +900,7 @@ namespace Umbraco.Core.Services.Implement
fileName += ".cshtml";
}
var snippetPath = Current.IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/{fileName}");
var snippetPath = _ioHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/{fileName}");
return System.IO.File.Exists(snippetPath)
? Attempt<string>.Succeed(snippetPath)
: Attempt<string>.Fail();

View File

@@ -30,9 +30,10 @@ namespace Umbraco.Core.Services.Implement
private readonly IGlobalSettings _globalSettings;
private readonly IContentSection _contentSection;
private readonly ILogger _logger;
private readonly IIOHelper _ioHelper;
public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService,
ILogger logger, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, IContentSection contentSection)
ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IGlobalSettings globalSettings, IContentSection contentSection)
{
_notificationsRepository = notificationsRepository;
_globalSettings = globalSettings;
@@ -42,6 +43,7 @@ namespace Umbraco.Core.Services.Implement
_contentService = contentService ?? throw new ArgumentNullException(nameof(contentService));
_localizationService = localizationService;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_ioHelper = ioHelper;
}
/// <summary>
@@ -384,7 +386,7 @@ namespace Umbraco.Core.Services.Implement
var protocol = _globalSettings.UseHttps ? "https" : "http";
var subjectVars = new NotificationEmailSubjectParams(
string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco)),
string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(SystemDirectories.Umbraco)),
actionName,
content.Name);
@@ -400,7 +402,7 @@ namespace Umbraco.Core.Services.Implement
string.Concat(content.Id, ".aspx"),
protocol),
performingUser.Name,
string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco)),
string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(SystemDirectories.Umbraco)),
summary.ToString());
// create the mail message

View File

@@ -23,6 +23,7 @@ namespace Umbraco.Core.Services.Implement
{
private readonly IPackageInstallation _packageInstallation;
private readonly IIOHelper _ioHelper;
private readonly IAuditService _auditService;
private readonly ICreatedPackagesRepository _createdPackages;
private readonly IInstalledPackagesRepository _installedPackages;
@@ -32,12 +33,14 @@ namespace Umbraco.Core.Services.Implement
IAuditService auditService,
ICreatedPackagesRepository createdPackages,
IInstalledPackagesRepository installedPackages,
IPackageInstallation packageInstallation)
IPackageInstallation packageInstallation,
IIOHelper ioHelper)
{
_auditService = auditService;
_createdPackages = createdPackages;
_installedPackages = installedPackages;
_packageInstallation = packageInstallation;
_ioHelper = ioHelper;
}
#region Package Files
@@ -64,7 +67,7 @@ namespace Umbraco.Core.Services.Implement
//successful
if (bytes.Length > 0)
{
var packagePath = Current.IOHelper.MapPath(SystemDirectories.Packages);
var packagePath = _ioHelper.MapPath(SystemDirectories.Packages);
// Check for package directory
if (Directory.Exists(packagePath) == false)

View File

@@ -112,7 +112,9 @@ namespace Umbraco.Core
if (isValid)
{
var resolvedUrlResult = Current.IOHelper.TryResolveUrl(input);
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
var resolvedUrlResult = 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.

View File

@@ -114,8 +114,10 @@ namespace Umbraco.Core
.TrimStart(authority)
.TrimStart("/");
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
//check if this is in the umbraco back office
return afterAuthority.InvariantStartsWith(Current.IOHelper.ResolveUrl("~/install").TrimStart("/"));
return afterAuthority.InvariantStartsWith(ioHelper.ResolveUrl("~/install").TrimStart("/"));
}
/// <summary>

View File

@@ -32,9 +32,10 @@ namespace Umbraco.Tests.Components
var mock = new Mock<IFactory>();
var logger = Mock.Of<ILogger>();
var ioHelper = Mock.Of<IIOHelper>();
var typeFinder = new TypeFinder(logger);
var f = new UmbracoDatabaseFactory(logger, new Lazy<IMapperCollection>(() => new MapperCollection(Enumerable.Empty<BaseMapper>())));
var fs = new FileSystems(mock.Object, logger);
var fs = new FileSystems(mock.Object, logger, ioHelper);
var p = new ScopeProvider(f, fs, logger, typeFinder);
mock.Setup(x => x.GetInstance(typeof (ILogger))).Returns(logger);

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Tests.IO
{
public PhysicalFileSystemTests()
: base(new PhysicalFileSystem(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests"),
"/Media/"))
"/Media/", new IOHelper()))
{ }
[SetUp]

View File

@@ -40,8 +40,9 @@ namespace Umbraco.Tests.IO
private static void ClearFiles()
{
TestHelper.DeleteDirectory(Current.IOHelper.MapPath("FileSysTests"));
TestHelper.DeleteDirectory(Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"));
var ioHelper = new IOHelper();
TestHelper.DeleteDirectory(ioHelper.MapPath("FileSysTests"));
TestHelper.DeleteDirectory(ioHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"));
}
private static string NormPath(string path)
@@ -52,13 +53,15 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowDeleteDirectory()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
Directory.CreateDirectory(path + "/ShadowTests/d1");
@@ -86,13 +89,15 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowDeleteDirectoryInDir()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
Directory.CreateDirectory(path + "/ShadowTests/sub");
@@ -135,13 +140,15 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowDeleteFile()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
File.WriteAllText(path + "/ShadowTests/f1.txt", "foo");
@@ -174,13 +181,16 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowDeleteFileInDir()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
Directory.CreateDirectory(path + "/ShadowTests/sub");
@@ -229,13 +239,15 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowCantCreateFile()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
Assert.Throws<FileSecurityException>(() =>
@@ -248,13 +260,15 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowCreateFile()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
File.WriteAllText(path + "/ShadowTests/f2.txt", "foo");
@@ -287,13 +301,15 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowCreateFileInDir()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
@@ -327,13 +343,15 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowAbort()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
@@ -349,13 +367,15 @@ namespace Umbraco.Tests.IO
[Test]
public void ShadowComplete()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
Directory.CreateDirectory(path + "/ShadowTests/sub/sub");
@@ -386,18 +406,19 @@ namespace Umbraco.Tests.IO
public void ShadowScopeComplete()
{
var logger = Mock.Of<ILogger>();
var ioHelper = new IOHelper();
var path = Current.IOHelper.MapPath("FileSysTests");
var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
var path = ioHelper.MapPath("FileSysTests");
var shadowfs = ioHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
Directory.CreateDirectory(path);
Directory.CreateDirectory(shadowfs);
var scopedFileSystems = false;
var phy = new PhysicalFileSystem(path, "ignore");
var phy = new PhysicalFileSystem(path, "ignore", ioHelper);
var container = Mock.Of<IFactory>();
var fileSystems = new FileSystems(container, logger) { IsScoped = () => scopedFileSystems };
var fileSystems = new FileSystems(container, logger, ioHelper) { IsScoped = () => scopedFileSystems };
var fs = fileSystems.GetFileSystem<FS>(phy);
var sw = (ShadowWrapper) fs.InnerFileSystem;
@@ -481,17 +502,18 @@ namespace Umbraco.Tests.IO
public void ShadowScopeCompleteWithFileConflict()
{
var logger = Mock.Of<ILogger>();
var ioHelper = new IOHelper();
var path = Current.IOHelper.MapPath("FileSysTests");
var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
var path = ioHelper.MapPath("FileSysTests");
var shadowfs = ioHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
Directory.CreateDirectory(path);
var scopedFileSystems = false;
var phy = new PhysicalFileSystem(path, "ignore");
var phy = new PhysicalFileSystem(path, "ignore", ioHelper);
var container = Mock.Of<IFactory>();
var fileSystems = new FileSystems(container, logger) { IsScoped = () => scopedFileSystems };
var fileSystems = new FileSystems(container, logger, ioHelper) { IsScoped = () => scopedFileSystems };
var fs = fileSystems.GetFileSystem<FS>( phy);
var sw = (ShadowWrapper) fs.InnerFileSystem;
@@ -534,17 +556,18 @@ namespace Umbraco.Tests.IO
public void ShadowScopeCompleteWithDirectoryConflict()
{
var logger = Mock.Of<ILogger>();
var ioHelper = new IOHelper();
var path = Current.IOHelper.MapPath("FileSysTests");
var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
var path = ioHelper.MapPath("FileSysTests");
var shadowfs = ioHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
Directory.CreateDirectory(path);
var scopedFileSystems = false;
var phy = new PhysicalFileSystem(path, "ignore");
var phy = new PhysicalFileSystem(path, "ignore", ioHelper);
var container = Mock.Of<IFactory>();
var fileSystems = new FileSystems(container, logger) { IsScoped = () => scopedFileSystems };
var fileSystems = new FileSystems(container, logger, ioHelper) { IsScoped = () => scopedFileSystems };
var fs = fileSystems.GetFileSystem<FS>( phy);
var sw = (ShadowWrapper)fs.InnerFileSystem;
@@ -603,7 +626,9 @@ namespace Umbraco.Tests.IO
[Test]
public void GetFilesReturnsChildrenOnly()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
File.WriteAllText(path + "/f1.txt", "foo");
Directory.CreateDirectory(path + "/test");
@@ -625,7 +650,9 @@ namespace Umbraco.Tests.IO
[Test]
public void DeleteDirectoryAndFiles()
{
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
File.WriteAllText(path + "/f1.txt", "foo");
Directory.CreateDirectory(path + "/test");
@@ -646,13 +673,15 @@ namespace Umbraco.Tests.IO
public void ShadowGetFiles()
{
// Arrange
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
// Act
@@ -678,13 +707,15 @@ namespace Umbraco.Tests.IO
public void ShadowGetFilesUsingEmptyFilter()
{
// Arrange
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
// Act
@@ -713,13 +744,15 @@ namespace Umbraco.Tests.IO
public void ShadowGetFilesUsingNullFilter()
{
// Arrange
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
// Act
@@ -745,13 +778,15 @@ namespace Umbraco.Tests.IO
public void ShadowGetFilesUsingWildcardFilter()
{
// Arrange
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
// Act
@@ -780,13 +815,15 @@ namespace Umbraco.Tests.IO
public void ShadowGetFilesUsingSingleCharacterFilter()
{
// Arrange
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
// Act
@@ -827,13 +864,15 @@ namespace Umbraco.Tests.IO
public void ShadowGetFullPath()
{
// Arrange
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
// Act
@@ -861,13 +900,15 @@ namespace Umbraco.Tests.IO
public void ShadowGetRelativePath()
{
// Arrange
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
// Act
@@ -900,13 +941,15 @@ namespace Umbraco.Tests.IO
public void ShadowGetUrl()
{
// Arrange
var path = Current.IOHelper.MapPath("FileSysTests");
var ioHelper = new IOHelper();
var path = ioHelper.MapPath("FileSysTests");
Directory.CreateDirectory(path);
Directory.CreateDirectory(path + "/ShadowTests");
Directory.CreateDirectory(path + "/ShadowSystem");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "rootUrl");
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "rootUrl");
var fs = new PhysicalFileSystem(path + "/ShadowTests/", "rootUrl", ioHelper);
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "rootUrl", ioHelper);
var ss = new ShadowFileSystem(fs, sfs);
// Act

View File

@@ -33,6 +33,7 @@ namespace Umbraco.Tests.Logging
{
//Create an example JSON log file to check results
//As a one time setup for all tets in this class/fixture
var ioHelper = new IOHelper();
var exampleLogfilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Logging\", _logfileName);
_newLogfileDirPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"App_Data\Logs\");
@@ -43,15 +44,15 @@ namespace Umbraco.Tests.Logging
_newSearchfilePath = Path.Combine(_newSearchfileDirPath, _searchfileName);
//Create/ensure Directory exists
Current.IOHelper.EnsurePathExists(_newLogfileDirPath);
Current.IOHelper.EnsurePathExists(_newSearchfileDirPath);
ioHelper.EnsurePathExists(_newLogfileDirPath);
ioHelper.EnsurePathExists(_newSearchfileDirPath);
//Copy the sample files
File.Copy(exampleLogfilePath, _newLogfilePath, true);
File.Copy(exampleSearchfilePath, _newSearchfilePath, true);
var logger = Mock.Of<Core.Logging.ILogger>();
_logViewer = new JsonLogViewer(logger, logsPath: _newLogfileDirPath, searchPath: _newSearchfilePath);
_logViewer = new JsonLogViewer(logger, ioHelper, logsPath: _newLogfileDirPath, searchPath: _newSearchfilePath);
}
[OneTimeTearDown]

View File

@@ -13,6 +13,7 @@ using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.Validators;
using Umbraco.Core.Services;
using Umbraco.Core.Dashboards;
using Umbraco.Core.IO;
namespace Umbraco.Tests.Manifest
{
@@ -44,7 +45,7 @@ namespace Umbraco.Tests.Manifest
new RequiredValidator(Mock.Of<ILocalizedTextService>()),
new RegexValidator(Mock.Of<ILocalizedTextService>(), null)
};
_parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty<IManifestFilter>()), Mock.Of<ILogger>());
_parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty<IManifestFilter>()), Mock.Of<ILogger>(), Mock.Of<IIOHelper>());
}
[Test]

View File

@@ -33,8 +33,9 @@ namespace Umbraco.Tests.Models
var logger = Mock.Of<ILogger>();
var scheme = Mock.Of<IMediaPathScheme>();
var config = Mock.Of<IContentSection>();
var ioHelper = Mock.Of<IIOHelper>();
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), config, scheme, logger);
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), config, scheme, logger, ioHelper);
var ignored = new FileUploadPropertyEditor(Mock.Of<ILogger>(), mediaFileSystem, config);
var media = MockedMedia.CreateMediaImage(mediaType, -1);

View File

@@ -35,7 +35,7 @@ namespace Umbraco.Tests.Packaging
base.TearDown();
//clear out files/folders
var path = Current.IOHelper.MapPath("~/" + _testBaseFolder);
var path = IOHelper.MapPath("~/" + _testBaseFolder);
if (Directory.Exists(path))
Directory.Delete(path, true);
}
@@ -51,9 +51,9 @@ namespace Umbraco.Tests.Packaging
private IPackageInstallation PackageInstallation => new PackageInstallation(
PackageDataInstallation,
new PackageFileInstallation(Parser, ProfilingLogger),
new PackageFileInstallation(Parser, IOHelper, ProfilingLogger),
Parser, Mock.Of<IPackageActionRunner>(),
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
applicationRootFolder: new DirectoryInfo(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(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage)));
new FileInfo(Path.Combine(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(Current.IOHelper.MapPath("~/Packaging/packages"), HelloPackage)));
new FileInfo(Path.Combine(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 = Current.IOHelper.MapPath("~/" + _testBaseFolder);
var path = 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(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage);
var packageFile = Path.Combine(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(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage)));
new FileInfo(Path.Combine(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(Current.IOHelper.MapPath("~/" + _testBaseFolder), result[0])));
Assert.IsTrue(File.Exists(Path.Combine(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(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage)));
new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage)));
var def = PackageDefinition.FromCompiledPackage(package);
def.Id = 1;
def.PackageId = Guid.NewGuid();

View File

@@ -20,7 +20,7 @@ namespace Umbraco.Tests.Persistence.Repositories
{
base.SetUp();
_fileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews + "/Partials/");
_fileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews + "/Partials/", new IOHelper());
}
protected override void Compose()
@@ -41,7 +41,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = TestObjects.GetScopeProvider(Logger);
using (var scope = provider.CreateScope())
{
var repository = new PartialViewRepository(fileSystems);
var repository = new PartialViewRepository(fileSystems, IOHelper);
var partialView = new PartialView(PartialViewType.PartialView, "test-path-1.cshtml") { Content = "// partialView" };
repository.Save(partialView);

View File

@@ -26,7 +26,7 @@ namespace Umbraco.Tests.Persistence.Repositories
base.SetUp();
_fileSystems = Mock.Of<IFileSystems>();
_fileSystem = new PhysicalFileSystem(SystemDirectories.Scripts);
_fileSystem = new PhysicalFileSystem(SystemDirectories.Scripts, new IOHelper());
Mock.Get(_fileSystems).Setup(x => x.ScriptsFileSystem).Returns(_fileSystem);
using (var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");"))
{

View File

@@ -25,7 +25,7 @@ namespace Umbraco.Tests.Persistence.Repositories
base.SetUp();
_fileSystems = Mock.Of<IFileSystems>();
_fileSystem = new PhysicalFileSystem(SystemDirectories.Css);
_fileSystem = new PhysicalFileSystem(SystemDirectories.Css, new IOHelper());
Mock.Get(_fileSystems).Setup(x => x.StylesheetsFileSystem).Returns(_fileSystem);
var stream = CreateStream("body {background:#EE7600; color:#FFF;}");
_fileSystem.AddFile("styles.css", stream);

View File

@@ -27,7 +27,7 @@ namespace Umbraco.Tests.Persistence.Repositories
private ITemplateRepository CreateRepository(IScopeProvider provider)
{
return new TemplateRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, _fileSystems);
return new TemplateRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, _fileSystems, IOHelper);
}
public override void SetUp()
@@ -35,7 +35,7 @@ namespace Umbraco.Tests.Persistence.Repositories
base.SetUp();
_fileSystems = Mock.Of<IFileSystems>();
var viewsFileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews);
var viewsFileSystem = new PhysicalFileSystem(SystemDirectories.MvcViews, IOHelper);
Mock.Get(_fileSystems).Setup(x => x.MvcViewsFileSystem).Returns(viewsFileSystem);
}
@@ -526,7 +526,7 @@ namespace Umbraco.Tests.Persistence.Repositories
_fileSystems = null;
//Delete all files
var fsViews = new PhysicalFileSystem(SystemDirectories.MvcViews);
var fsViews = new PhysicalFileSystem(SystemDirectories.MvcViews, new IOHelper());
var views = fsViews.GetFiles("", "*.cshtml");
foreach (var file in views)
fsViews.DeleteFile(file);

View File

@@ -79,8 +79,9 @@ namespace Umbraco.Tests.PropertyEditors
var logger = Mock.Of<ILogger>();
var scheme = Mock.Of<IMediaPathScheme>();
var config = Mock.Of<IContentSection>();
var ioHelper = Mock.Of<IIOHelper>();
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), config, scheme, logger);
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), config, scheme, logger, ioHelper);
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new ImageCropperPropertyEditor(Mock.Of<ILogger>(), mediaFileSystem, Mock.Of<IContentSection>(), Mock.Of<IDataTypeService>())) { Id = 1 });

View File

@@ -36,7 +36,7 @@ namespace Umbraco.Tests.Scoping
_testObjects = new TestObjects(register);
composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance<ILogger>()));
composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance<ILogger>(), factory.TryGetInstance<IIOHelper>()));
composition.WithCollectionBuilder<MapperCollectionBuilder>();
composition.Configs.Add(SettingsForTests.GetDefaultGlobalSettings);

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Tests.Scoping
base.SetUp();
SafeCallContext.Clear();
ClearFiles();
ClearFiles(this.IOHelper);
}
protected override void ComposeApplication(bool withApplication)
@@ -39,21 +39,21 @@ namespace Umbraco.Tests.Scoping
base.TearDown();
SafeCallContext.Clear();
FileSystems.ResetShadowId();
ClearFiles();
ClearFiles(this.IOHelper);
}
private static void ClearFiles()
private static void ClearFiles(IIOHelper ioHelper)
{
TestHelper.DeleteDirectory(Current.IOHelper.MapPath("media"));
TestHelper.DeleteDirectory(Current.IOHelper.MapPath("FileSysTests"));
TestHelper.DeleteDirectory(Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"));
TestHelper.DeleteDirectory(ioHelper.MapPath("media"));
TestHelper.DeleteDirectory(ioHelper.MapPath("FileSysTests"));
TestHelper.DeleteDirectory(ioHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"));
}
[TestCase(true)]
[TestCase(false)]
public void CreateMediaTest(bool complete)
{
var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper.MapPath("media"), "ignore");
var physMediaFileSystem = new PhysicalFileSystem(IOHelper.MapPath("media"), "ignore", IOHelper);
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(Current.IOHelper.MapPath("media"), "ignore");
var physMediaFileSystem = new PhysicalFileSystem(IOHelper.MapPath("media"), "ignore", new IOHelper());
var mediaFileSystem = Current.MediaFileSystem;
var scopeProvider = ScopeProvider;

View File

@@ -107,8 +107,9 @@ namespace Umbraco.Tests.TestHelpers
var scheme = Mock.Of<IMediaPathScheme>();
var config = Mock.Of<IContentSection>();
var ioHelper = Mock.Of<IIOHelper>();
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), config, scheme, logger);
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), config, scheme, logger, ioHelper);
var externalLoginService = GetLazyService<IExternalLoginService>(factory, c => new ExternalLoginService(scopeProvider, logger, eventMessagesFactory, GetRepo<IExternalLoginRepository>(c)));
var publicAccessService = GetLazyService<IPublicAccessService>(factory, c => new PublicAccessService(scopeProvider, logger, eventMessagesFactory, GetRepo<IPublicAccessRepository>(c)));
@@ -118,9 +119,9 @@ namespace Umbraco.Tests.TestHelpers
var localizedTextService = GetLazyService<ILocalizedTextService>(factory, c => new LocalizedTextService(
new Lazy<LocalizedTextServiceFileSources>(() =>
{
var mainLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Umbraco + "/config/lang/"));
var appPlugins = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.AppPlugins));
var configLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Config + "/lang/"));
var mainLangFolder = new DirectoryInfo(ioHelper.MapPath(SystemDirectories.Umbraco + "/config/lang/"));
var appPlugins = new DirectoryInfo(ioHelper.MapPath(SystemDirectories.AppPlugins));
var configLangFolder = new DirectoryInfo(ioHelper.MapPath(SystemDirectories.Config + "/lang/"));
var pluginLangFolders = appPlugins.Exists == false
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()
@@ -154,14 +155,14 @@ namespace Umbraco.Tests.TestHelpers
var userService = GetLazyService<IUserService>(factory, c => new UserService(scopeProvider, logger, eventMessagesFactory, runtimeState, GetRepo<IUserRepository>(c), GetRepo<IUserGroupRepository>(c),globalSettings));
var dataTypeService = GetLazyService<IDataTypeService>(factory, c => new DataTypeService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDataTypeRepository>(c), GetRepo<IDataTypeContainerRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IEntityRepository>(c), GetRepo<IContentTypeRepository>(c)));
var contentService = GetLazyService<IContentService>(factory, c => new ContentService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDocumentRepository>(c), GetRepo<IEntityRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IContentTypeRepository>(c), GetRepo<IDocumentBlueprintRepository>(c), GetRepo<ILanguageRepository>(c)));
var notificationService = GetLazyService<INotificationService>(factory, c => new NotificationService(scopeProvider, userService.Value, contentService.Value, localizationService.Value, logger, GetRepo<INotificationsRepository>(c), globalSettings, umbracoSettings.Content));
var notificationService = GetLazyService<INotificationService>(factory, c => new NotificationService(scopeProvider, userService.Value, contentService.Value, localizationService.Value, logger, ioHelper, GetRepo<INotificationsRepository>(c), globalSettings, umbracoSettings.Content));
var serverRegistrationService = GetLazyService<IServerRegistrationService>(factory, c => new ServerRegistrationService(scopeProvider, logger, eventMessagesFactory, GetRepo<IServerRegistrationRepository>(c)));
var memberGroupService = GetLazyService<IMemberGroupService>(factory, c => new MemberGroupService(scopeProvider, logger, eventMessagesFactory, GetRepo<IMemberGroupRepository>(c)));
var memberService = GetLazyService<IMemberService>(factory, c => new MemberService(scopeProvider, logger, eventMessagesFactory, memberGroupService.Value, GetRepo<IMemberRepository>(c), GetRepo<IMemberTypeRepository>(c), GetRepo<IMemberGroupRepository>(c), GetRepo<IAuditRepository>(c)));
var mediaService = GetLazyService<IMediaService>(factory, c => new MediaService(scopeProvider, mediaFileSystem, logger, eventMessagesFactory, GetRepo<IMediaRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IMediaTypeRepository>(c), GetRepo<IEntityRepository>(c)));
var contentTypeService = GetLazyService<IContentTypeService>(factory, c => new ContentTypeService(scopeProvider, logger, eventMessagesFactory, contentService.Value, GetRepo<IContentTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IDocumentTypeContainerRepository>(c), GetRepo<IEntityRepository>(c)));
var mediaTypeService = GetLazyService<IMediaTypeService>(factory, c => new MediaTypeService(scopeProvider, logger, eventMessagesFactory, mediaService.Value, GetRepo<IMediaTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IMediaTypeContainerRepository>(c), GetRepo<IEntityRepository>(c)));
var fileService = GetLazyService<IFileService>(factory, c => new FileService(scopeProvider, logger, eventMessagesFactory, GetRepo<IStylesheetRepository>(c), GetRepo<IScriptRepository>(c), GetRepo<ITemplateRepository>(c), GetRepo<IPartialViewRepository>(c), GetRepo<IPartialViewMacroRepository>(c), GetRepo<IAuditRepository>(c)));
var fileService = GetLazyService<IFileService>(factory, c => new FileService(scopeProvider, ioHelper, logger, eventMessagesFactory, GetRepo<IStylesheetRepository>(c), GetRepo<IScriptRepository>(c), GetRepo<ITemplateRepository>(c), GetRepo<IPartialViewRepository>(c), GetRepo<IPartialViewMacroRepository>(c), GetRepo<IAuditRepository>(c)));
var memberTypeService = GetLazyService<IMemberTypeService>(factory, c => new MemberTypeService(scopeProvider, logger, eventMessagesFactory, memberService.Value, GetRepo<IMemberTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IEntityRepository>(c)));
var entityService = GetLazyService<IEntityService>(factory, c => new EntityService(scopeProvider, logger, eventMessagesFactory, idkMap, GetRepo<IEntityRepository>(c)));
@@ -173,15 +174,15 @@ namespace Umbraco.Tests.TestHelpers
var compiledPackageXmlParser = new CompiledPackageXmlParser(new ConflictingPackageData(macroService.Value, fileService.Value));
return new PackagingService(
auditService.Value,
new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value,
new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, ioHelper,
new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders), logger, "createdPackages.config"),
new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value,
new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, ioHelper,
new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders), logger, "installedPackages.config"),
new PackageInstallation(
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())),
new PackageFileInstallation(compiledPackageXmlParser, ioHelper, new ProfilingLogger(logger, new TestProfiler())),
compiledPackageXmlParser, Mock.Of<IPackageActionRunner>(),
new DirectoryInfo(Current.IOHelper.GetRootDirectorySafe())));
new DirectoryInfo(ioHelper.GetRootDirectorySafe())), ioHelper);
});
var relationService = GetLazyService<IRelationService>(factory, c => new RelationService(scopeProvider, logger, eventMessagesFactory, entityService.Value, GetRepo<IRelationRepository>(c), GetRepo<IRelationTypeRepository>(c)));
var tagService = GetLazyService<ITagService>(factory, c => new TagService(scopeProvider, logger, eventMessagesFactory, GetRepo<ITagRepository>(c)));
@@ -242,7 +243,7 @@ namespace Umbraco.Tests.TestHelpers
}
typeFinder = typeFinder ?? new TypeFinder(logger);
fileSystems = fileSystems ?? new FileSystems(Current.Factory, logger);
fileSystems = fileSystems ?? new FileSystems(Current.Factory, logger, new IOHelper());
var scopeProvider = new ScopeProvider(databaseFactory, fileSystems, logger, typeFinder);
return scopeProvider;
}

View File

@@ -342,8 +342,9 @@ namespace Umbraco.Tests.Testing
var logger = Mock.Of<ILogger>();
var scheme = Mock.Of<IMediaPathScheme>();
var config = Mock.Of<IContentSection>();
var ioHelper = Mock.Of<IIOHelper>();
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), config, scheme, logger);
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), config, scheme, logger, ioHelper);
Composition.RegisterUnique<IMediaFileSystem>(factory => mediaFileSystem);
// no factory (noop)

View File

@@ -11,7 +11,14 @@ namespace Umbraco.Web.Editors
[PluginController("UmbracoApi")]
public class BackOfficeAssetsController : UmbracoAuthorizedJsonController
{
private readonly IFileSystem _jsLibFileSystem = new PhysicalFileSystem(SystemDirectories.Umbraco + Current.IOHelper.DirSepChar + "lib");
private readonly IIOHelper _ioHelper;
private readonly IFileSystem _jsLibFileSystem;
public BackOfficeAssetsController(IFileSystem jsLibFileSystem, IIOHelper ioHelper)
{
_ioHelper = ioHelper;
_jsLibFileSystem = new PhysicalFileSystem(SystemDirectories.Umbraco + _ioHelper.DirSepChar + "lib", _ioHelper);
}
[HttpGet]
public object GetSupportedLocales()

View File

@@ -8,10 +8,19 @@ namespace Umbraco.Web.Trees
[CoreTree]
public class FilesTreeController : FileSystemTreeController
{
protected override IFileSystem FileSystem => new PhysicalFileSystem("~/");
private readonly IIOHelper _ioHelper;
private readonly IFileSystem _fileSystem;
protected override IFileSystem FileSystem => _fileSystem;
private static readonly string[] ExtensionsStatic = { "*" };
public FilesTreeController(IIOHelper ioHelper)
{
_ioHelper = ioHelper;
_fileSystem = new PhysicalFileSystem("~/", _ioHelper);
}
protected override string[] Extensions => ExtensionsStatic;
protected override string FileIcon => Constants.Icons.MediaFile;

View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.IO;
@@ -59,7 +60,8 @@ namespace Umbraco.Web.WebApi
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var root = Current.IOHelper.MapPath(rootVirtualPath);
var ioHelper = Current.Factory.GetInstance<IIOHelper>();
var root = ioHelper.MapPath(rootVirtualPath);
//ensure it exists
Directory.CreateDirectory(root);
var provider = new MultipartFormDataStreamProvider(root);