umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
Other
4.49k stars 2.69k forks source link

.Net Core transition: Inject IIOHelper wherever possible #7138

Closed bergmania closed 4 years ago

bergmania commented 5 years ago

This task is up for grabs, for contributing to the .Net Core transition project

On the development branch of the .net core transition project netcore/dev, we have already abstracted the static IOHelper, into an interface (IIOHelper) and an instance class (IOHelper).

This was required to not block some other tasks. To finish that task as fast as possible, we just added a new static property on the static helper Current (Current.IOHelper). This new static property is used all over the system, instead of the original static IOHelper.

This task is about eliminating the usage of Current.IOHelper, by replacing it with a constructor injection of IIOHelper.

Expected Procedure:

If any questions, feel free to ask :)


Related: AB#3667

soreng commented 4 years ago

Currently i can find only one ref : https://github.com/umbraco/Umbraco-CMS/blob/netcore/dev/src/Umbraco.Core/PropertyEditors/GridEditor.cs

Do you know of others?

bergmania commented 4 years ago

Hi @soreng..

Be aware that both Umbraco.Web and Umbraco.Core has a Current.

My IDE found the following usages:

Search target
    Umbraco.Web.Composing.Current.IOHelper:IIOHelper
Found usages  (23 usages found)
    Read access  (23 usages found)
        <Tests>  (5 usages found)
            <Umbraco.Tests>  (5 usages found)
                LegacyXmlPublishedCache  (5 usages found)
                    PreviewContent.cs  (2 usages found)
                        (111: 49)  var dir = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Preview));
                        (125: 28)  return Current.IOHelper.MapPath(Path.Combine(SystemDirectories.Preview, userId + "_" + previewSet + ".config"));
                    XmlStore.cs  (3 usages found)
                        (89: 36)  _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(_globalSettings));
                        (113: 36)  _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global()));
                        (127: 36)  _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global()));
        <Umbraco.Web>  (18 usages found)
            Editors  (7 usages found)
                CodeFileController.cs  (1 usage found)
                    (638: 32)  var path = Current.IOHelper.MapPath(systemDirectory + "/" + virtualPath);
                MacrosController.cs  (2 usages found)
                    (314: 39)  var partialsDir = Current.IOHelper.MapPath(SystemDirectories.MacroPartials);
                    (332: 62)  var appPluginsFolder = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.AppPlugins));
                TinyMceController.cs  (4 usages found)
                    (48: 41)  var imageTempPath = Current.IOHelper.MapPath(SystemDirectories.TempImageUploads + "/" + Guid.NewGuid().ToString());
                    (51: 38)  var folderPath = Current.IOHelper.MapPath(SystemDirectories.TempFileUploads);
                    (89: 56)  var newFilePath = imageTempPath +  Current.IOHelper.DirSepChar + safeFileName;
                    (90: 47)  var relativeNewFilePath = Current.IOHelper.GetRelativePath(newFilePath);
            Install  (4 usages found)
                FilePermissionHelper.cs  (4 usages found)
                    (130: 36)  var path = Current.IOHelper.MapPath(dir + "/" + CreateRandomName());
                    (148: 39)  var dirPath = Current.IOHelper.MapPath(dir);
                    (176: 39)  var dirPath = Current.IOHelper.MapPath(dir);
                    (241: 36)  var path = Current.IOHelper.MapPath(file);
            Mvc  (1 usage found)
                UmbracoViewPageOfTModel.cs  (1 usage found)
                    (217: 45)  Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco),
            Runtime  (1 usage found)
                WebInitialComponent.cs  (1 usage found)
                    (49: 25)  if (Current.IOHelper.IsHosted)
            Security  (1 usage found)
                WebSecurity.cs  (1 usage found)
                    (212: 67)  return context.Request.Path.ToLower().IndexOf(Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco).ToLower(), StringComparison.Ordinal) > -1;
            Templates  (3 usages found)
                TemplateUtilities.cs  (3 usages found)
                    (132: 82)  var resolvedUrl = (url.Substring(0, 1) == "/") ? Current.IOHelper.ResolveUrl(url.Substring(1)) : Current.IOHelper.ResolveUrl(url);
                    (132: 130)  var resolvedUrl = (url.Substring(0, 1) == "/") ? Current.IOHelper.ResolveUrl(url.Substring(1)) : Current.IOHelper.ResolveUrl(url);
                    (218: 53)  var absoluteTempImagePath = Current.IOHelper.MapPath(tmpImgPath);
            HtmlHelperRenderExtensions.cs  (1 usage found)
                (70: 43)  Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco),

and


Search target
    Umbraco.Core.Composing.Current.IOHelper:IIOHelper
Found usages  (207 usages found)
    Read access  (206 usages found)
        <Tests>  (87 usages found)
            <Umbraco.Tests>  (87 usages found)
                Configurations  (1 usage found)
                    GlobalSettingsTests.cs  (1 usage found)
                        (52: 73)  globalSettingsMock.Setup(x => x.Path).Returns(() => Current.IOHelper.ResolveUrl(path));
                IO  (52 usages found)
                    FileSystemsTests.cs  (1 usage found)
                        (108: 36)  var physPath = Current.IOHelper.MapPath(Path.Combine("media", virtPath));
                    IoHelperTests.cs  (24 usages found)
                        (19: 68)  Assert.Throws(expectedExceptionType, () => Current.IOHelper.ResolveUrl(input));
                        (23: 38)  var result = Current.IOHelper.ResolveUrl(input);
                        (36: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Bin, true), Current.IOHelper.MapPath(SystemDirectories.Bin, false));
                        (36: 92)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Bin, true), Current.IOHelper.MapPath(SystemDirectories.Bin, false));
                        (37: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Config, true), Current.IOHelper.MapPath(SystemDirectories.Config, false));
                        (37: 95)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Config, true), Current.IOHelper.MapPath(SystemDirectories.Config, false));
                        (38: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Css, true), Current.IOHelper.MapPath(SystemDirectories.Css, false));
                        (38: 92)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Css, true), Current.IOHelper.MapPath(SystemDirectories.Css, false));
                        (39: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Data, true), Current.IOHelper.MapPath(SystemDirectories.Data, false));
                        (39: 93)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Data, true), Current.IOHelper.MapPath(SystemDirectories.Data, false));
                        (40: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Install, true), Current.IOHelper.MapPath(SystemDirectories.Install, false));
                        (40: 96)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Install, true), Current.IOHelper.MapPath(SystemDirectories.Install, false));
                        (41: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Media, true), Current.IOHelper.MapPath(SystemDirectories.Media, false));
                        (41: 94)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Media, true), Current.IOHelper.MapPath(SystemDirectories.Media, false));
                        (42: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Packages, true), Current.IOHelper.MapPath(SystemDirectories.Packages, false));
                        (42: 97)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Packages, true), Current.IOHelper.MapPath(SystemDirectories.Packages, false));
                        (43: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Preview, true), Current.IOHelper.MapPath(SystemDirectories.Preview, false));
                        (43: 96)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Preview, true), Current.IOHelper.MapPath(SystemDirectories.Preview, false));
                        (44: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Root, true), Current.IOHelper.MapPath(SystemDirectories.Root, false));
                        (44: 93)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Root, true), Current.IOHelper.MapPath(SystemDirectories.Root, false));
                        (45: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Scripts, true), Current.IOHelper.MapPath(SystemDirectories.Scripts, false));
                        (45: 96)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Scripts, true), Current.IOHelper.MapPath(SystemDirectories.Scripts, false));
                        (46: 37)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Umbraco, true), Current.IOHelper.MapPath(SystemDirectories.Umbraco, false));
                        (46: 96)  Assert.AreEqual(Current.IOHelper.MapPath(SystemDirectories.Umbraco, true), Current.IOHelper.MapPath(SystemDirectories.Umbraco, false));
                    ShadowFileSystemTests.cs  (27 usages found)
                        (43: 48)  TestHelper.DeleteDirectory(Current.IOHelper.MapPath("FileSysTests"));
                        (44: 48)  TestHelper.DeleteDirectory(Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"));
                        (55: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (89: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (138: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (177: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (232: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (251: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (290: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (330: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (352: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (390: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (391: 36)  var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
                        (485: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (486: 36)  var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
                        (538: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (539: 36)  var shadowfs = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs");
                        (606: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (628: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (649: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (681: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (716: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (748: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (783: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (830: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (864: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                        (903: 32)  var path = Current.IOHelper.MapPath("FileSysTests");
                Logging  (2 usages found)
                    LogviewerTests.cs  (2 usages found)
                        (46: 21)  Current.IOHelper.EnsurePathExists(_newLogfileDirPath);
                        (47: 21)  Current.IOHelper.EnsurePathExists(_newSearchfileDirPath);
                Packaging  (14 usages found)
                    CreatedPackagesRepositoryTests.cs  (4 usages found)
                        (37: 38)  Directory.Delete(Current.IOHelper.MapPath("~/" + _testBaseFolder), true);
                        (149: 39)  var mappedFile1 = Current.IOHelper.MapPath(file1);
                        (150: 39)  var mappedFile2 = Current.IOHelper.MapPath(file2);
                        (174: 59)  using (var archive = ZipFile.OpenRead(Current.IOHelper.MapPath(zip)))
                    PackageExtractionTests.cs  (1 usage found)
                        (19: 48)  string path = Path.Combine(Current.IOHelper.GetRootDirectorySafe(), testPackagesDirName, packageName);
                    PackageInstallationTest.cs  (9 usages found)
                        (38: 32)  var path = Current.IOHelper.MapPath("~/" + _testBaseFolder);
                        (56: 62)  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
                        (66: 51)  new FileInfo(Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage)));
                        (89: 51)  new FileInfo(Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), HelloPackage)));
                        (114: 32)  var path = Current.IOHelper.MapPath("~/" + _testBaseFolder);
                        (122: 52)  var packageFile = Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage);
                        (140: 51)  new FileInfo(Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage)));
                        (151: 60)  Assert.IsTrue(File.Exists(Path.Combine(Current.IOHelper.MapPath("~/" + _testBaseFolder), result[0])));
                        (162: 51)  new FileInfo(Path.Combine(Current.IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage)));
                Runtimes  (1 usage found)
                    StandaloneTests.cs  (1 usage found)
                        (50: 74)  foreach (var file in Directory.GetFiles(Path.Combine(Current.IOHelper.MapPath("~/App_Data")), "NuCache.*"))
                Scoping  (5 usages found)
                    ScopeFileSystemsTests.cs  (5 usages found)
                        (47: 48)  TestHelper.DeleteDirectory(Current.IOHelper.MapPath("media"));
                        (48: 48)  TestHelper.DeleteDirectory(Current.IOHelper.MapPath("FileSysTests"));
                        (49: 48)  TestHelper.DeleteDirectory(Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"));
                        (56: 70)  var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper.MapPath("media"), "ignore");
                        (89: 70)  var physMediaFileSystem = new PhysicalFileSystem(Current.IOHelper.MapPath("media"), "ignore");
                TestHelpers  (9 usages found)
                    SettingsForTests.cs  (2 usages found)
                        (21: 46)  settings.Path == Current.IOHelper.ResolveUrl("~/umbraco") &&
                        (25: 55)  settings.LocalTempPath == Current.IOHelper.MapPath("~/App_Data/TEMP") &&
                    TestHelper.cs  (3 usages found)
                        (77: 63)  var directoryInfo = new DirectoryInfo(Current.IOHelper.MapPath(directory));
                        (79: 55)  Directory.CreateDirectory(Current.IOHelper.MapPath(directory));
                        (91: 63)  var directoryInfo = new DirectoryInfo(Current.IOHelper.MapPath(directory));
                    TestObjects.cs  (4 usages found)
                        (121: 72)  var mainLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Umbraco + "/config/lang/"));
                        (122: 68)  var appPlugins = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.AppPlugins));
                        (123: 74)  var configLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Config + "/lang/"));
                        (184: 51)  new DirectoryInfo(Current.IOHelper.GetRootDirectorySafe())));
                Web  (3 usages found)
                    Controllers  (3 usages found)
                        AuthenticationControllerTests.cs  (3 usages found)
                            (73: 43)  var baseDir = Current.IOHelper.MapPath("", false).TrimEnd(Current.IOHelper.DirSepChar);
                            (73: 87)  var baseDir = Current.IOHelper.MapPath("", false).TrimEnd(Current.IOHelper.DirSepChar);
                            (76: 25)  Current.IOHelper.ForceNotHosted = true;
        <Umbraco.Core>  (71 usages found)
            Compose  (1 usage found)
                ManifestWatcherComponent.cs  (1 usage found)
                    (31: 38)  var appPlugins = Current.IOHelper.MapPath("~/App_Plugins/");
            Composing  (4 usages found)
                CompositionExtensions  (4 usages found)
                    Services.cs  (4 usages found)
                        (74: 47)  new DirectoryInfo(Current.IOHelper.GetRootDirectorySafe())));
                        (92: 60)  var mainLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Umbraco + "/config/lang/"));
                        (93: 56)  var appPlugins = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.AppPlugins));
                        (94: 62)  var configLangFolder = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Config + "/lang/"));
            Configuration  (4 usages found)
                GlobalSettings.cs  (4 usages found)
                    (144: 31)  ? Current.IOHelper.ResolveUrl(ConfigurationManager.AppSettings[Constants.AppSettings.Path])
                    (174: 36)  var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root));
                    (196: 36)  var fileName = Current.IOHelper.MapPath(string.Format("{0}/web.config", SystemDirectories.Root));
                    (323: 57)  return _localTempPath = Current.IOHelper.MapPath("~/App_Data/TEMP");
            Diagnostics  (2 usages found)
                MiniDump.cs  (2 usages found)
                    (113: 40)  var filepath = Current.IOHelper.MapPath("~/App_Data/MiniDump");
                    (129: 40)  var filepath = Current.IOHelper.MapPath("~/App_Data/MiniDump");
            IO  (16 usages found)
                MediaFileSystem.cs  (2 usages found)
                    (71: 32)  filename = Current.IOHelper.SafeFileName(filename.ToLowerInvariant());
                    (81: 32)  filename = Current.IOHelper.SafeFileName(filename.ToLowerInvariant());
                PhysicalFileSystem.cs  (7 usages found)
                    (35: 62)  _rootPath = EnsureDirectorySeparatorChar(Current.IOHelper.MapPath(virtualRoot)).TrimEnd(Path.DirectorySeparatorChar);
                    (37: 55)  _rootUrl = EnsureUrlSeparatorChar(Current.IOHelper.ResolveUrl(virtualRoot)).TrimEnd('/');
                    (50: 41)  var localRoot = Current.IOHelper.GetRootDirectorySafe();
                    (260: 25)  if (Current.IOHelper.PathStartsWith(path, _rootUrl, '/'))
                    (265: 25)  if (Current.IOHelper.PathStartsWith(path, _rootPathFwd, '/'))
                    (295: 25)  if (Current.IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar) == false)
                    (306: 25)  if (Current.IOHelper.PathStartsWith(path, _rootPath, Path.DirectorySeparatorChar))
                ShadowWrapper.cs  (3 usages found)
                    (41: 41)  var shadowDir = Current.IOHelper.MapPath(virt);
                    (59: 34)  _shadowDir = Current.IOHelper.MapPath(virt);
                    (86: 39)  var min = Current.IOHelper.MapPath(ShadowFsPath).Length;
                SystemDirectories.cs  (4 usages found)
                    (33: 47)  public static string Media => Current.IOHelper.ReturnPath("umbracoMediaPath", "~/media");
                    (35: 49)  public static string Scripts => Current.IOHelper.ReturnPath("umbracoScriptsPath", "~/scripts");
                    (37: 45)  public static string Css => Current.IOHelper.ReturnPath("umbracoCssPath", "~/css");
                    (39: 49)  public static string Umbraco => Current.IOHelper.ReturnPath("umbracoPath", "~/umbraco");
            Logging  (2 usages found)
                Viewer  (2 usages found)
                    LogViewerSourceBase.cs  (2 usages found)
                        (22: 42)  pathToSearches = Current.IOHelper.MapPath("~/Config/logviewer.searches.config.js");
                        (185: 40)  var absolutePath = Current.IOHelper.MapPath(path);
            Manifest  (5 usages found)
                ManifestContentAppDefinition.cs  (1 usage found)
                    (71: 36)  set => _view = Current.IOHelper.ResolveVirtualUrl(value);
                ManifestDashboard.cs  (1 usage found)
                    (25: 36)  set => _view = Current.IOHelper.ResolveVirtualUrl(value);
                ManifestParser.cs  (3 usages found)
                    (54: 61)  set => _path = value.StartsWith("~/") ? Current.IOHelper.MapPath(value) : value;
                    (169: 47)  manifest.Scripts[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Scripts[i]);
                    (171: 51)  manifest.Stylesheets[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Stylesheets[i]);
            Migrations  (3 usages found)
                Install  (3 usages found)
                    DatabaseBuilder.cs  (3 usages found)
                        (135: 45)  var path = Path.Combine(Current.IOHelper.GetRootDirectorySafe(), "App_Data", "Umbraco.sdf");
                        (286: 36)  var fileName = Current.IOHelper.MapPath(SystemDirectories.Root +"/" + fileSource);
                        (299: 36)  fileName = Current.IOHelper.MapPath(SystemDirectories.Root + "/" + fileSource);
            Packaging  (10 usages found)
                PackageFileInstallation.cs  (3 usages found)
                    (63: 42)  removedFiles.Add(Current.IOHelper.GetRelativePath(item));
                    (66: 36)  var file = Current.IOHelper.FindFile(item);
                    (71: 44)  var filePath = Current.IOHelper.MapPath(file);
                PackagesRepository.cs  (7 usages found)
                    (158: 41)  var temporaryPath = Current.IOHelper.MapPath(_tempFolderPath.EnsureEndsWith('/') + Guid.NewGuid());
                    (217: 46)  if (Directory.Exists(Current.IOHelper.MapPath(_mediaFolderPath)) == false)
                    (218: 55)  Directory.CreateDirectory(Current.IOHelper.MapPath(_mediaFolderPath));
                    (221: 51)  ZipPackage(temporaryPath, Current.IOHelper.MapPath(packPath));
                    (452: 38)  var serverPath = Current.IOHelper.MapPath(path);
                    (611: 42)  var packagesFolder = Current.IOHelper.MapPath(_packagesFolderPath);
                    (615: 36)  packagesFile = Current.IOHelper.MapPath(CreatedPackagesFile);
            Persistence  (4 usages found)
                Repositories  (4 usages found)
                    Implement  (4 usages found)
                        PartialViewRepository.cs  (2 usages found)
                            (107: 39)  var isValidPath = Current.IOHelper.VerifyEditPath(fullPath, validDir);
                            (108: 44)  var isValidExtension = Current.IOHelper.VerifyFileExtension(fullPath, ValidExtensions);
                        TemplateRepository.cs  (2 usages found)
                            (596: 37)  var validFile = Current.IOHelper.VerifyEditPath(path, validDirs);
                            (597: 42)  var validExtension = Current.IOHelper.VerifyFileExtension(path, validExts);
            PropertyEditors  (4 usages found)
                ConfigurationField.cs  (1 usage found)
                    (97: 36)  set => _view = Current.IOHelper.ResolveVirtualUrl(value);
                DataValueEditor.cs  (1 usage found)
                    (78: 36)  set => _view = Current.IOHelper.ResolveVirtualUrl(value);
                GridEditor.cs  (2 usages found)
                    (32: 36)  set => _view = Current.IOHelper.ResolveVirtualUrl(value);
                    (39: 38)  set => _render = Current.IOHelper.ResolveVirtualUrl(value);
            Runtime  (6 usages found)
                CoreInitialComponent.cs  (5 usages found)
                    (12: 21)  Current.IOHelper.EnsurePathExists("~/App_Data");
                    (13: 21)  Current.IOHelper.EnsurePathExists(SystemDirectories.Media);
                    (14: 21)  Current.IOHelper.EnsurePathExists(SystemDirectories.MvcViews);
                    (15: 21)  Current.IOHelper.EnsurePathExists(SystemDirectories.MvcViews + "/Partials");
                    (16: 21)  Current.IOHelper.EnsurePathExists(SystemDirectories.MvcViews + "/MacroPartials");
                CoreRuntime.cs  (1 usage found)
                    (242: 25)  Current.IOHelper.SetRootDirectory(path);
            Services  (5 usages found)
                Implement  (5 usages found)
                    FileService.cs  (2 usages found)
                        (667: 39)  var snippetPath = Current.IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/");
                        (901: 39)  var snippetPath = Current.IOHelper.MapPath($"{SystemDirectories.Umbraco}/PartialViewMacros/Templates/{fileName}");
                    NotificationService.cs  (2 usages found)
                        (387: 58)  string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco)),
                        (403: 58)  string.Concat(siteUri.Authority, Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco)),
                    PackagingService.cs  (1 usage found)
                        (67: 43)  var packagePath = Current.IOHelper.MapPath(SystemDirectories.Packages);
            Sync  (1 usage found)
                ApplicationUrlHelper.cs  (1 usage found)
                    (101: 102)  var url = "http" + ssl + "://" + request.ServerVariables["SERVER_NAME"] + port + Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco);
            ConfigsExtensions.cs  (1 usage found)
                (36: 55)  var configDir = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Config));
            ContentExtensions.cs  (1 usage found)
                (151: 32)  filename = Current.IOHelper.SafeFileName(filename);
            StringExtensions.cs  (1 usage found)
                (115: 53)  var resolvedUrlResult = Current.IOHelper.TryResolveUrl(input);
            UriExtensions.cs  (1 usage found)
                (118: 63)  return afterAuthority.InvariantStartsWith(Current.IOHelper.ResolveUrl("~/install").TrimStart("/"));
        <Umbraco.Examine>  (2 usages found)
            LuceneIndexCreator.cs  (1 usage found)
                (39: 66)  var dirInfo = new DirectoryInfo(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.TempData), "ExamineIndexes", folderName));
            LuceneIndexDiagnostics.cs  (1 usage found)
                (75: 136)  …y.ToString().ToLowerInvariant().TrimStart(Current.IOHelper.MapPath(SystemDirectories.Root).ToLowerInvariant()).Replace("\\", "/").EnsureStartsWith('/');
        <Umbraco.ModelsBuilder.Embedded>  (2 usages found)
            Configuration  (2 usages found)
                ModelsBuilderConfig.cs  (2 usages found)
                    (32: 39)  ModelsDirectory = Current.IOHelper.MapPath(DefaultModelsDirectory);
                    (78: 36)  var root = Current.IOHelper.MapPath("~/");
        <Umbraco.Web.UI>  (4 usages found)
            Config  (1 usage found)
                splashes  (1 usage found)
                    noNodes.aspx  (1 usage found)
                        (34: 26)  <a href="<%= Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco) %>" class="button">Open Umbraco</a>
            Umbraco  (3 usages found)
                Views  (3 usages found)
                    Preview  (1 usage found)
                        Index.cshtml  (1 usage found)
                            (25: 42)  new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco)))
                    AuthorizeUpgrade.cshtml  (1 usage found)
                        (36: 42)  new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco)))
                    Default.cshtml  (1 usage found)
                        (44: 42)  new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco)))
        <Umbraco.Web>  (40 usages found)
            Composing  (1 usage found)
                Current.cs  (1 usage found)
                    (229: 57)  public static IIOHelper IOHelper => CoreCurrent.IOHelper;
            Editors  (16 usages found)
                BackOfficeAssetsController.cs  (1 usage found)
                    (14: 116)  private readonly IFileSystem _jsLibFileSystem = new PhysicalFileSystem(SystemDirectories.Umbraco + Current.IOHelper.DirSepChar + "lib");
                BackOfficeServerVariables.cs  (3 usages found)
                    (323: 47)  {"mediaPath", Current.IOHelper.ResolveUrl(SystemDirectories.Media).TrimEnd('/')},
                    (324: 52)  {"appPluginsPath", Current.IOHelper.ResolveUrl(SystemDirectories.AppPlugins).TrimEnd('/')},
                    (343: 45)  {"cssPath", Current.IOHelper.ResolveUrl(SystemDirectories.Css).TrimEnd('/')},
                ContentTypeController.cs  (2 usages found)
                    (518: 49)  var filePath = Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Data), file);
                    (556: 32)  var root = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "FileUploads");
                MediaController.cs  (1 usage found)
                    (623: 32)  var root = Current.IOHelper.MapPath(SystemDirectories.TempFileUploads);
                PackageController.cs  (1 usage found)
                    (94: 36)  var fullPath = Current.IOHelper.MapPath(package.PackagePath);
                PackageInstallController.cs  (5 usages found)
                    (93: 61)  var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Packages), model.ZipFileName));
                    (135: 32)  var root = Current.IOHelper.MapPath(SystemDirectories.TempFileUploads);
                    (162: 50)  var packagesFolder = Current.IOHelper.MapPath(SystemDirectories.Packages);
                    (214: 50)  if (File.Exists(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Packages), fileName)) == false)
                    (254: 61)  var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Packages), model.ZipFileName));
                TourController.cs  (2 usages found)
                    (44: 54)  var coreToursPath = Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Config), "BackOfficeTours");
                    (54: 38)  var appPlugins = Current.IOHelper.MapPath(SystemDirectories.AppPlugins);
                UsersController.cs  (1 usage found)
                    (78: 32)  var root = Current.IOHelper.MapPath(SystemDirectories.TempFileUploads);
            HealthCheck  (5 usages found)
                Checks  (5 usages found)
                    Config  (1 usage found)
                        AbstractConfigCheck.cs  (1 usage found)
                            (69: 52)  private string AbsoluteFilePath => Current.IOHelper.MapPath(FilePath);
                    Permissions  (2 usages found)
                        FolderAndFilePermissionsCheck.cs  (2 usages found)
                            (128: 38)  .Select(x => Current.IOHelper.MapPath(x.Key))
                            (168: 38)  var rootFolder = Current.IOHelper.MapPath("/");
                    Security  (2 usages found)
                        BaseHttpHeaderCheck.cs  (1 usage found)
                            (172: 42)  var configFile = Current.IOHelper.MapPath("~/Web.config");
                        HttpsCheck.cs  (1 usage found)
                            (186: 38)  var configFile = Current.IOHelper.MapPath("~/Web.config");
            Install  (5 usages found)
                Controllers  (1 usage found)
                    InstallController.cs  (1 usage found)
                        (69: 51)  ViewData.SetUmbracoBaseFolder(Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco));
                InstallSteps  (2 usages found)
                    ConfigureMachineKey.cs  (1 usage found)
                        (40: 36)  var fileName = Current.IOHelper.MapPath($"{SystemDirectories.Root}/web.config");
                    StarterKitCleanupStep.cs  (1 usage found)
                        (30: 61)  var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Packages), HttpUtility.UrlDecode(packageFile)));
                InstallStatusTracker.cs  (2 usages found)
                    (28: 32)  var file = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "Install/" ↵ + "install_" ↵ + installId.ToString("N") ↵ + ".txt")
                    (43: 31)  var dir = Current.IOHelper.MapPath(SystemDirectories.TempData.EnsureEndsWith('/') + "Install/");
            JavaScript  (3 usages found)
                ClientDependencyConfiguration.cs  (1 usage found)
                    (30: 33)  _fileName = Current.IOHelper.MapPath(string.Format("{0}/ClientDependency.config", SystemDirectories.Config));
                JsInitialization.cs  (1 usage found)
                    (61: 59)  return WriteScript(jarray.ToString(), Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco), angularModule);
                UmbracoClientDependencyLoader.cs  (1 usage found)
                    (21: 49)  this.AddPath("UmbracoRoot", Current.IOHelper.ResolveUrl(SystemDirectories.Umbraco));
            Macros  (1 usage found)
                MacroRenderer.cs  (1 usage found)
                    (175: 34)  var mapped = Current.IOHelper.MapPath(filename);
            Models  (2 usages found)
                ContentEditing  (1 usage found)
                    ContentTypeBasic.cs  (1 usage found)
                        (112: 38)  : Current.IOHelper.ResolveUrl("~/umbraco/images/thumbnails/" + Thumbnail);
                Trees  (1 usage found)
                    TreeNode.cs  (1 usage found)
                        (113: 36)  return Current.IOHelper.ResolveUrl("~" + Icon.TrimStart('~'));
            Mvc  (2 usages found)
                PluginViewEngine.cs  (1 usage found)
                    (78: 56)  var folder = Path.GetDirectoryName(Current.IOHelper.MapPath(razorResult.ViewPath));
                RenderViewEngine.cs  (1 usage found)
                    (46: 38)  var viewFolder = Current.IOHelper.MapPath(Constants.ViewLocation);
            PropertyEditors  (1 usage found)
                RichTextPreValueController.cs  (1 usage found)
                    (54: 41)  xd.Load(Current.IOHelper.MapPath(SystemFiles.TinyMceConfig));
            Scheduling  (1 usage found)
                SchedulerComponent.cs  (1 usage found)
                    (173: 51)  new[] { new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.TempFileUploads)) },
            WebApi  (1 usage found)
                HttpActionContextExtensions.cs  (1 usage found)
                    (62: 32)  var root = Current.IOHelper.MapPath(rootVirtualPath);
            RoutableDocumentFilter.cs  (2 usages found)
                (108: 52)  .Select(reservedUrl => Current.IOHelper.ResolveUrl(reservedUrl).Trim().EnsureStartsWith("/"))
                (146: 49)  .Select(reservedPath => Current.IOHelper.ResolveUrl(reservedPath).Trim().EnsureStartsWith("/").EnsureEndsWith("/"))
    Write access  (1 usage found)
        <Umbraco.Core>  (1 usage found)
            Composing  (1 usage found)
                Current.cs  (1 usage found)
                    (208: 42)  public static readonly IIOHelper IOHelper = new IOHelper();
soreng commented 4 years ago

thx @bergmania - I just did a quick search on github, but it's not yield the best result ;)

My IDE also gives alot -- all the tests are the worst so far

soreng commented 4 years ago

I'm having a wack at this ...

I found a Umbraco.Core.IO.IOHelper.Default -- should this also be removed @bergmania ?

Shazwazza commented 4 years ago

@soreng please leave Umbraco.Core.IO.IOHelper.Default as-is, this can also be used in unit tests if necessary. It shouldn't be used in the Core/Web projects though, only for registering IIOHelper in DI in the Core/Web Runtime.

bergmania commented 4 years ago

@soreng, if you think it make sense, feel free to split the task in multiple small PRs.

Some of the repleaces is very easy. E.g. in controllers. Others require more work :)

soreng commented 4 years ago

I sort of have done all the replaces, but about half of the unit tests are failing — not all of them are related to the files I’ve changed.

@bergmania haw many of the tests are currently passing?

bergmania commented 4 years ago

@soreng, All tests are passing on the netcore/dev branch.

soreng commented 4 years ago

Wow, then my work needs a bit more... work ;-)

soreng commented 4 years ago

@soreng please leave Umbraco.Core.IO.IOHelper.Default as-is, this can also be used in unit tests if necessary. It shouldn't be used in the Core/Web projects though, only for registering IIOHelper in DI in the Core/Web Runtime.

There are some static (extension) methods (Umbraco.Core.ConfigsExtensions.AddCoreConfigs) that use the IO Helper. This gets called before the Current.Factory or any other IOC-helpers are in place. Would Umbraco.Core.IO.IOHelper.Default be used in a situation like that?

bergmania commented 4 years ago

For a first attempt, I think you should just leave these as Current.IOHelper. Otherwise we should inject IIOhelperinto these methods too.

bergmania commented 4 years ago

I merged the first PR. Thanks, @soreng!

The remaining usages is:

Most of these are found in tests, but there exists still some in the codebase.

Search target
    Umbraco.Core.Composing.Current.IOHelper:IIOHelper
Found usages  (97 usages found)
    Read access  (96 usages found)
        <Tests>  (41 usages found)
            <Umbraco.Tests>  (41 usages found)
                Configurations  (4 usages found)
                    GlobalSettingsTests.cs  (4 usages found)
                        (20: 29)  _root = Current.IOHelper.Root;
                        (26: 21)  Current.IOHelper.Root = _root;
                        (46: 73)  globalSettingsMock.Setup(x => x.Path).Returns(() => Current.IOHelper.ResolveUrl(path));
                        (48: 21)  Current.IOHelper.Root = rootPath;
                CoreThings  (3 usages found)
                    UriExtensionsTests.cs  (3 usages found)
                        (18: 29)  _root = Current.IOHelper.Root;
                        (24: 21)  Current.IOHelper.Root = _root;
                        (48: 21)  Current.IOHelper.Root = virtualPath;
                IO  (22 usages found)
                    IoHelperTests.cs  (22 usages found)
                        (43: 37)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Bin, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Bin, false));
                        (43: 102)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Bin, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Bin, false));
                        (44: 37)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Config, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Config, false));
                        (44: 105)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Config, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Config, false));
                        (45: 37)  Assert.AreEqual(Current.IOHelper.MapPath(globalSettings.UmbracoCssPath, true), Current.IOHelper.MapPath(globalSettings.UmbracoCssPath, false));
                        (45: 100)  Assert.AreEqual(Current.IOHelper.MapPath(globalSettings.UmbracoCssPath, true), Current.IOHelper.MapPath(globalSettings.UmbracoCssPath, false));
                        (46: 37)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Data, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Data, false));
                        (46: 103)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Data, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Data, false));
                        (47: 37)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Install, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Install, false));
                        (47: 106)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Install, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Install, false));
                        (48: 37)  Assert.AreEqual(Current.IOHelper.MapPath(globalSettings.UmbracoMediaPath, true), Current.IOHelper.MapPath(globalSettings.UmbracoMediaPath, false));
                        (48: 102)  Assert.AreEqual(Current.IOHelper.MapPath(globalSettings.UmbracoMediaPath, true), Current.IOHelper.MapPath(globalSettings.UmbracoMediaPath, false));
                        (49: 37)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Packages, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Packages, false));
                        (49: 107)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Packages, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Packages, false));
                        (50: 37)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Preview, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Preview, false));
                        (50: 106)  Assert.AreEqual(Current.IOHelper.MapPath(Constants.SystemDirectories.Preview, true), Current.IOHelper.MapPath(Constants.SystemDirectories.Preview, false));
                        (51: 37)  Assert.AreEqual(Current.IOHelper.MapPath(_ioHelper.Root, true), Current.IOHelper.MapPath(_ioHelper.Root, false));
                        (51: 85)  Assert.AreEqual(Current.IOHelper.MapPath(_ioHelper.Root, true), Current.IOHelper.MapPath(_ioHelper.Root, false));
                        (52: 37)  Assert.AreEqual(Current.IOHelper.MapPath(globalSettings.UmbracoScriptsPath, true), Current.IOHelper.MapPath(globalSettings.UmbracoScriptsPath, false));
                        (52: 104)  Assert.AreEqual(Current.IOHelper.MapPath(globalSettings.UmbracoScriptsPath, true), Current.IOHelper.MapPath(globalSettings.UmbracoScriptsPath, false));
                        (53: 37)  Assert.AreEqual(Current.IOHelper.MapPath(globalSettings.UmbracoPath, true), Current.IOHelper.MapPath(globalSettings.UmbracoPath, false));
                        (53: 97)  Assert.AreEqual(Current.IOHelper.MapPath(globalSettings.UmbracoPath, true), Current.IOHelper.MapPath(globalSettings.UmbracoPath, false));
                Packaging  (4 usages found)
                    CreatedPackagesRepositoryTests.cs  (3 usages found)
                        (150: 39)  var mappedFile1 = Current.IOHelper.MapPath(file1);
                        (151: 39)  var mappedFile2 = Current.IOHelper.MapPath(file2);
                        (175: 59)  using (var archive = ZipFile.OpenRead(Current.IOHelper.MapPath(zip)))
                    PackageExtractionTests.cs  (1 usage found)
                        (19: 48)  string path = Path.Combine(Current.IOHelper.GetRootDirectorySafe(), testPackagesDirName, packageName);
                Runtimes  (1 usage found)
                    StandaloneTests.cs  (1 usage found)
                        (50: 74)  foreach (var file in Directory.GetFiles(Path.Combine(Current.IOHelper.MapPath("~/App_Data")), "NuCache.*"))
                TestHelpers  (4 usages found)
                    SettingsForTests.cs  (1 usage found)
                        (21: 46)  settings.Path == Current.IOHelper.ResolveUrl("~/umbraco") &&
                    TestHelper.cs  (3 usages found)
                        (88: 63)  var directoryInfo = new DirectoryInfo(Current.IOHelper.MapPath(directory));
                        (90: 55)  Directory.CreateDirectory(Current.IOHelper.MapPath(directory));
                        (102: 63)  var directoryInfo = new DirectoryInfo(Current.IOHelper.MapPath(directory));
                Web  (3 usages found)
                    Controllers  (3 usages found)
                        AuthenticationControllerTests.cs  (3 usages found)
                            (73: 43)  var baseDir = Current.IOHelper.MapPath("", false).TrimEnd(Current.IOHelper.DirSepChar);
                            (73: 87)  var baseDir = Current.IOHelper.MapPath("", false).TrimEnd(Current.IOHelper.DirSepChar);
                            (76: 25)  Current.IOHelper.ForceNotHosted = true;
        <Umbraco.Core>  (5 usages found)
            IO  (1 usage found)
                SystemFiles.cs  (1 usage found)
                    (14: 70)  return Path.Combine(globalSettings.LocalTempPath(Current.IOHelper), "umbraco.config");
            PropertyEditors  (1 usage found)
                ConfigurationEditorOfTConfiguration.cs  (1 usage found)
                    (38: 45)  var attributeView = Current.IOHelper.ResolveVirtualUrl(attribute.View);
            Sync  (1 usage found)
                ApplicationUrlHelper.cs  (1 usage found)
                    (101: 102)  var url = "http" + ssl + "://" + request.ServerVariables["SERVER_NAME"] + port + Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath);
            UriExtensions.cs  (2 usages found)
                (55: 68)  var mvcArea = globalSettings.GetUmbracoMvcArea(Current.IOHelper);
                (119: 63)  return afterAuthority.InvariantStartsWith(Current.IOHelper.ResolveUrl("~/install").TrimStart("/"));
        <Umbraco.ModelsBuilder.Embedded>  (2 usages found)
            Configuration  (2 usages found)
                ModelsBuilderConfig.cs  (2 usages found)
                    (32: 39)  ModelsDirectory = Current.IOHelper.MapPath(DefaultModelsDirectory);
                    (78: 36)  var root = Current.IOHelper.MapPath("~/");
        <Umbraco.Web.UI>  (4 usages found)
            Config  (1 usage found)
                splashes  (1 usage found)
                    noNodes.aspx  (1 usage found)
                        (35: 26)  <a href="<%= Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath) %>" class="button">Open Umbraco</a>
            Umbraco  (3 usages found)
                Views  (3 usages found)
                    Preview  (1 usage found)
                        Index.cshtml  (1 usage found)
                            (25: 42)  new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath)))
                    AuthorizeUpgrade.cshtml  (1 usage found)
                        (36: 42)  new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath)))
                    Default.cshtml  (1 usage found)
                        (44: 42)  new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath)))
        <Umbraco.Web>  (44 usages found)
            Composing  (1 usage found)
                Current.cs  (1 usage found)
                    (229: 57)  public static IIOHelper IOHelper => CoreCurrent.IOHelper;
            ContentApps  (1 usage found)
                ContentAppFactoryCollectionBuilder.cs  (1 usage found)
                    (32: 142)  return base.CreateItems(factory).Concat(manifestParser.Manifest.ContentApps.Select(x => new ManifestContentAppFactory(x, Current.IOHelper)));
            Editors  (17 usages found)
                BackOfficeAssetsController.cs  (1 usage found)
                    (20: 87)  new PhysicalFileSystem(Current.Configs.Global().UmbracoPath + Current.IOHelper.DirSepChar + "lib", ↵ ioHelper)
                BackOfficeServerVariables.cs  (3 usages found)
                    (323: 47)  {"mediaPath", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoMediaPath).TrimEnd('/')},
                    (324: 52)  {"appPluginsPath", Current.IOHelper.ResolveUrl(Constants.SystemDirectories.AppPlugins).TrimEnd('/')},
                    (343: 45)  {"cssPath", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoCssPath).TrimEnd('/')},
                ContentTypeController.cs  (2 usages found)
                    (518: 49)  var filePath = Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Data), file);
                    (556: 32)  var root = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "FileUploads");
                MediaController.cs  (1 usage found)
                    (623: 32)  var root = Current.IOHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
                PackageController.cs  (1 usage found)
                    (94: 36)  var fullPath = Current.IOHelper.MapPath(package.PackagePath);
                PackageInstallController.cs  (5 usages found)
                    (93: 61)  var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages), model.ZipFileName));
                    (135: 32)  var root = Current.IOHelper.MapPath(Core.Constants.SystemDirectories.TempFileUploads);
                    (162: 50)  var packagesFolder = Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages);
                    (214: 50)  if (File.Exists(Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages), fileName)) == false)
                    (254: 61)  var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages), model.ZipFileName));
                TourController.cs  (2 usages found)
                    (44: 54)  var coreToursPath = Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Config), "BackOfficeTours");
                    (54: 38)  var appPlugins = Current.IOHelper.MapPath(Core.Constants.SystemDirectories.AppPlugins);
                UsersController.cs  (2 usages found)
                    (78: 32)  var root = Current.IOHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
                    (459: 69)  area = GlobalSettings.GetUmbracoMvcArea(Current.IOHelper),
            HealthCheck  (5 usages found)
                Checks  (5 usages found)
                    Config  (1 usage found)
                        AbstractConfigCheck.cs  (1 usage found)
                            (69: 52)  private string AbsoluteFilePath => Current.IOHelper.MapPath(FilePath);
                    Permissions  (2 usages found)
                        FolderAndFilePermissionsCheck.cs  (2 usages found)
                            (129: 38)  .Select(x => Current.IOHelper.MapPath(x.Key))
                            (169: 38)  var rootFolder = Current.IOHelper.MapPath("/");
                    Security  (2 usages found)
                        BaseHttpHeaderCheck.cs  (1 usage found)
                            (172: 42)  var configFile = Current.IOHelper.MapPath("~/Web.config");
                        HttpsCheck.cs  (1 usage found)
                            (186: 38)  var configFile = Current.IOHelper.MapPath("~/Web.config");
            Install  (6 usages found)
                Controllers  (1 usage found)
                    InstallController.cs  (1 usage found)
                        (69: 51)  ViewData.SetUmbracoBaseFolder(Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath));
                InstallSteps  (3 usages found)
                    ConfigureMachineKey.cs  (2 usages found)
                        (40: 36)  var fileName = Current.IOHelper.MapPath($"{Current.IOHelper.Root}/web.config");
                        (40: 64)  var fileName = Current.IOHelper.MapPath($"{Current.IOHelper.Root}/web.config");
                    StarterKitCleanupStep.cs  (1 usage found)
                        (30: 61)  var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(Core.Constants.SystemDirectories.Packages), HttpUtility.UrlDecode(packageFile)));
                InstallStatusTracker.cs  (2 usages found)
                    (28: 32)  var file = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "Install/" ↵ + "install_" ↵ + installId.ToString("N") ↵ + ".txt")
                    (43: 31)  var dir = Current.IOHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "Install/");
            JavaScript  (3 usages found)
                ClientDependencyConfiguration.cs  (1 usage found)
                    (30: 33)  _fileName = Current.IOHelper.MapPath(string.Format("{0}/ClientDependency.config", Core.Constants.SystemDirectories.Config));
                JsInitialization.cs  (1 usage found)
                    (62: 59)  return WriteScript(jarray.ToString(), Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath), angularModule);
                UmbracoClientDependencyLoader.cs  (1 usage found)
                    (22: 49)  this.AddPath("UmbracoRoot", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath));
            Macros  (1 usage found)
                MacroRenderer.cs  (1 usage found)
                    (175: 34)  var mapped = Current.IOHelper.MapPath(filename);
            Models  (2 usages found)
                ContentEditing  (1 usage found)
                    ContentTypeBasic.cs  (1 usage found)
                        (112: 38)  : Current.IOHelper.ResolveUrl("~/umbraco/images/thumbnails/" + Thumbnail);
                Trees  (1 usage found)
                    TreeNode.cs  (1 usage found)
                        (113: 36)  return Current.IOHelper.ResolveUrl("~" + Icon.TrimStart('~'));
            Mvc  (3 usages found)
                BackOfficeArea.cs  (1 usage found)
                    (51: 86)  public override string AreaName => _globalSettings.GetUmbracoMvcArea(Current.IOHelper);
                PluginViewEngine.cs  (1 usage found)
                    (78: 56)  var folder = Path.GetDirectoryName(Current.IOHelper.MapPath(razorResult.ViewPath));
                RenderViewEngine.cs  (1 usage found)
                    (46: 38)  var viewFolder = Current.IOHelper.MapPath(Constants.ViewLocation);
            PropertyEditors  (1 usage found)
                RichTextPreValueController.cs  (1 usage found)
                    (54: 41)  xd.Load(Current.IOHelper.MapPath(SystemFiles.TinyMceConfig));
            PublishedCache  (1 usage found)
                NuCache  (1 usage found)
                    PublishedSnapshotService.cs  (1 usage found)
                        (302: 75)  var path = Path.Combine(_globalSettings.LocalTempPath(Current.IOHelper), "NuCache");
            Scheduling  (1 usage found)
                SchedulerComponent.cs  (1 usage found)
                    (173: 51)  new[] { new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.TempFileUploads)) },
            RoutableDocumentFilter.cs  (2 usages found)
                (108: 52)  .Select(reservedUrl => Current.IOHelper.ResolveUrl(reservedUrl).Trim().EnsureStartsWith("/"))
                (146: 49)  .Select(reservedPath => Current.IOHelper.ResolveUrl(reservedPath).Trim().EnsureStartsWith("/").EnsureEndsWith("/"))
    Write access  (1 usage found)
        <Umbraco.Core>  (1 usage found)
            Composing  (1 usage found)
                Current.cs  (1 usage found)
                    (208: 42)  public static readonly IIOHelper IOHelper = Umbraco.Core.IO.IOHelper.Default;
Search target
    Umbraco.Web.Composing.Current.IOHelper:IIOHelper
Found usages  (31 usages found)
    Read access  (31 usages found)
        <Tests>  (5 usages found)
            <Umbraco.Tests>  (5 usages found)
                LegacyXmlPublishedCache  (5 usages found)
                    PreviewContent.cs  (2 usages found)
                        (111: 49)  var dir = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.Preview));
                        (125: 28)  return Current.IOHelper.MapPath(Path.Combine(Constants.SystemDirectories.Preview, userId + "_" + previewSet + ".config"));
                    XmlStore.cs  (3 usages found)
                        (89: 36)  _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(_globalSettings));
                        (113: 36)  _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global()));
                        (127: 36)  _xmlFileName = Current.IOHelper.MapPath(SystemFiles.GetContentCacheXml(Current.Configs.Global()));
        <Umbraco.Web>  (26 usages found)
            Editors  (9 usages found)
                AuthenticationController.cs  (1 usage found)
                    (517: 69)  area = GlobalSettings.GetUmbracoMvcArea(Current.IOHelper),
                BackOfficeController.cs  (1 usage found)
                    (355: 78)  ViewData.SetUmbracoPath(GlobalSettings.GetUmbracoMvcArea(Current.IOHelper));
                CodeFileController.cs  (1 usage found)
                    (638: 32)  var path = Current.IOHelper.MapPath(systemDirectory + "/" + virtualPath);
                MacrosController.cs  (2 usages found)
                    (314: 39)  var partialsDir = Current.IOHelper.MapPath(Constants.SystemDirectories.MacroPartials);
                    (332: 62)  var appPluginsFolder = new DirectoryInfo(Current.IOHelper.MapPath(Constants.SystemDirectories.AppPlugins));
                TinyMceController.cs  (4 usages found)
                    (48: 41)  var imageTempPath = Current.IOHelper.MapPath(Constants.SystemDirectories.TempImageUploads + "/" + Guid.NewGuid().ToString());
                    (51: 38)  var folderPath = Current.IOHelper.MapPath(Constants.SystemDirectories.TempFileUploads);
                    (89: 56)  var newFilePath = imageTempPath +  Current.IOHelper.DirSepChar + safeFileName;
                    (90: 47)  var relativeNewFilePath = Current.IOHelper.GetRelativePath(newFilePath);
            Install  (5 usages found)
                InstallSteps  (1 usage found)
                    DatabaseInstallStep.cs  (1 usage found)
                        (59: 94)  GlobalSettings.RemoveSetting(Constants.System.UmbracoConnectionName, Current.IOHelper);
                FilePermissionHelper.cs  (4 usages found)
                    (131: 36)  var path = Current.IOHelper.MapPath(dir + "/" + CreateRandomName());
                    (149: 39)  var dirPath = Current.IOHelper.MapPath(dir);
                    (177: 39)  var dirPath = Current.IOHelper.MapPath(dir);
                    (242: 36)  var path = Current.IOHelper.MapPath(file);
            Mvc  (2 usages found)
                AreaRegistrationExtensions.cs  (1 usage found)
                    (59: 72)  var umbracoArea = globalSettings.GetUmbracoMvcArea(Current.IOHelper);
                UmbracoViewPageOfTModel.cs  (1 usage found)
                    (217: 45)  Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath),
            Runtime  (4 usages found)
                WebInitialComponent.cs  (4 usages found)
                    (49: 25)  if (Current.IOHelper.IsHosted)
                    (122: 70)  var cachePath = globalSettings.LocalTempPath(Current.IOHelper);
                    (153: 72)  var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.IOHelper);
                    (178: 72)  var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.IOHelper);
            Security  (1 usage found)
                WebSecurity.cs  (1 usage found)
                    (212: 67)  return context.Request.Path.ToLower().IndexOf(Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath).ToLower(), StringComparison.Ordinal) > -1;
            Templates  (3 usages found)
                TemplateUtilities.cs  (3 usages found)
                    (132: 82)  var resolvedUrl = (url.Substring(0, 1) == "/") ? Current.IOHelper.ResolveUrl(url.Substring(1)) : Current.IOHelper.ResolveUrl(url);
                    (132: 130)  var resolvedUrl = (url.Substring(0, 1) == "/") ? Current.IOHelper.ResolveUrl(url.Substring(1)) : Current.IOHelper.ResolveUrl(url);
                    (218: 53)  var absoluteTempImagePath = Current.IOHelper.MapPath(tmpImgPath);
            AppBuilderExtensions.cs  (1 usage found)
                (54: 72)  var umbracoPath = globalSettings.GetUmbracoMvcArea(Current.IOHelper);
            HtmlHelperRenderExtensions.cs  (1 usage found)
                (70: 43)  Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath),
soreng commented 4 years ago

I’ll have a look at the usage in tests - it should be a bit easier than the parts you are refactoring.

For all the extension-methods, should the IOHelper be found via Current.Factory, or should it be injected as a parameter?

bergmania commented 4 years ago

👍 If it is easy, then please also inject in extension methods..

soreng commented 4 years ago

This construct Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath)) is used in a number of views (.cshtml). What would be a good solution for this?

Alot of the views use BackOfficeModel or BackOfficePreviewModel as the model, wich allows us to inject the IOHelper into those models. This would allow an UmbracoPath property to be defined on the model, and used instead of the above. I can't quite see what the benefit of the resolved umbracopath would be though, since this is used for ClientDependency. If the path does not need to be resolved, we could just use Current.Configs.Global().UmbracoPath or better Model.GlobalSettings.UmbracoPath

@bergmania other than above, I think this issue should / could be resolved.

bergmania commented 4 years ago

@soreng, I think we should leave these for know. When we are running ASP.NET core, we should be able to inject the IIOHelper into the views.

soreng commented 4 years ago

@bergmania is this issue ready for closing, as per above? :)

bergmania commented 4 years ago

@soreng, there still exists lots of usages in the codebase..

E.g. https://github.com/umbraco/Umbraco-CMS/blob/netcore/dev/src/Umbraco.Web/Macros/MacroRenderer.cs#L176 - These should still be easy to replace with injections..

elit0451 commented 4 years ago

Last bits are fixed in: https://github.com/umbraco/Umbraco-CMS/pull/7581