Huge IIOHelper cleanup, removes some overlap with IHostingEnvironment, much less usages of IIOHelper and instead just use what is already available on IHostingEnvironment

This commit is contained in:
Shannon
2020-04-03 11:03:06 +11:00
parent 1224c97f07
commit 7e2d0902af
70 changed files with 436 additions and 415 deletions

View File

@@ -5,8 +5,6 @@ namespace Umbraco.Core.IO
{
public static class IOHelperExtensions
{
private static string _mvcArea;
/// <summary>
/// Tries to create a directory.
/// </summary>
@@ -38,37 +36,6 @@ namespace Umbraco.Core.IO
return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8);
}
/// <summary>
/// This returns the string of the MVC Area route.
/// </summary>
/// <remarks>
/// This will return the MVC area that we will route all custom routes through like surface controllers, etc...
/// We will use the 'Path' (default ~/umbraco) to create it but since it cannot contain '/' and people may specify a path of ~/asdf/asdf/admin
/// we will convert the '/' to '-' and use that as the path. its a bit lame but will work.
///
/// We also make sure that the virtual directory (SystemDirectories.Root) is stripped off first, otherwise we'd end up with something
/// like "MyVirtualDirectory-Umbraco" instead of just "Umbraco".
/// </remarks>
public static string GetUmbracoMvcArea(this IIOHelper ioHelper)
{
if (_mvcArea != null) return _mvcArea;
_mvcArea = GetUmbracoMvcAreaNoCache(ioHelper);
return _mvcArea;
}
internal static string GetUmbracoMvcAreaNoCache(this IIOHelper ioHelper)
{
if (ioHelper.BackOfficePath.IsNullOrWhiteSpace())
{
throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified");
}
var path = ioHelper.BackOfficePath;
if (path.StartsWith(ioHelper.Root)) // beware of TrimStart, see U4-2518
path = path.Substring(ioHelper.Root.Length);
return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower();
}
}
}