public string MapPathPhysicalToVirtual(string?physicalPath) { if (physicalPath._IsEmpty()) { return(""); } physicalPath = UnderlayPathParser.NormalizeDirectorySeparatorAndCheckIfAbsolutePath(physicalPath); // Remove the last directory letter physicalPath = UnderlayPathParser.RemoveLastSeparatorChar(physicalPath); // the examples of physicalPath: // c:\view_root // c:\view_root\readme.txt // c:\view_root\abc\def\ // c:\view_root\abc\def\readme.txt // delegating to the derive class string virtualPath = MapPathPhysicalToVirtualImpl(physicalPath); // the contents of virtualPath: // '' (empty) - representing the root directory // readme.txt // abc\def // abc\def\readme.txt // converting the naming convention virtualPath = UnderlayPathParser.ConvertDirectorySeparatorToOtherSystem(virtualPath, PathParser); // the contents of virtualPath: // / -- Prohibited // /abc -- Prohibited // '' (empty) - representing the root directory // readme.txt // abc/def // abc/def/readme.txt if (PathParser.IsAbsolutePath(virtualPath, false)) { throw new MapPathException($"The path \"{virtualPath}\" returned by MapPathPhysicalToVirtualImpl() is an absolute path."); } virtualPath = "/" + virtualPath; // Add "/" prefix on the virtual path // the examples of virtualPath: // / // /readme.txt // /abc/def // /abc/def/readme.txt // Check if the virtual path returned by MapPathPhysicalToVirtualImpl() is absolute path again virtualPath = PathParser.NormalizeDirectorySeparatorAndCheckIfAbsolutePath(virtualPath); virtualPath = PathParser.NormalizeUnixStylePathWithRemovingRelativeDirectoryElements(virtualPath); return(virtualPath); }
protected override string MapPathPhysicalToVirtualImpl(string relativeSafeUnderlayFsStyleVirtualPath) { // From: // the examples of physicalPath: // c:\view_root // c:\view_root\readme.txt // c:\view_root\abc\def\ // c:\view_root\abc\def\readme.txt // // To: // the contents of virtualPath: // '' (empty) - representing the root directory // readme.txt // abc\def // abc\def\readme.txt return(UnderlayPathParser.GetRelativeFileName(relativeSafeUnderlayFsStyleVirtualPath, this.PhysicalRootDirectory)); }