public IDirectoryContents GetDirectoryContents(string subpath) { if (subpath == null) { return(NotFoundDirectoryContents.Singleton); } var folder = NormalizePath(subpath); var entries = new List <IFileInfo>(); // Under "Areas/{ApplicationName}". if (folder == Application.ModulePath) { // Always add a "Pages" folder. entries.Add(new EmbeddedDirectoryInfo("Pages")); } // Under "Areas/{ApplicationName}/Pages" or "Areas/{ApplicationName}/Pages/**". else if (folder.StartsWith(Application.ModuleRoot + "Pages", StringComparison.Ordinal)) { // Skip the "Areas/{ApplicationName}/" part from the given folder path. // So we get "Pages" or "Pages/**" paths relative to the application root. var subFolder = folder.Substring(Application.ModuleRoot.Length); // Resolve all files and folders directly under this subfolder by using the // compiled '_pages' paths which are also relative to the application root. NormalizedPaths.ResolveFolderContents(subFolder, _pages, out var files, out var folders); // And add them to the directory contents. entries.AddRange(files.Select(p => new EmptyPageFileInfo(Path.GetFileName(p)))); entries.AddRange(folders.Select(n => new EmbeddedDirectoryInfo(n))); } return(new EmbeddedDirectoryContents(entries)); }
public IDirectoryContents GetDirectoryContents(string subpath) { if (subpath == null) { return(NotFoundDirectoryContents.Singleton); } if (_modules == null) { _modules = _moduleManager.LoadModulesAsync() .GetAwaiter() .GetResult() .ToList(); } var folder = NormalizePath(subpath); var entries = new List <IFileInfo>(); // Under the root. if (folder == "") { // Add the virtual folder "Modules" containing all modules. entries.Add(new EmbeddedDirectoryInfo(_modulesFolder)); } // Under "Modules". else if (folder == _modulesFolder) { // Add virtual folders for all modules by using their assembly names (module ids). entries.AddRange( _modules.Select(m => new EmbeddedDirectoryInfo(m.Descriptor.Id))); } // Under "Modules/{ModuleId}" or "Modules/{ModuleId}/**". else if (folder.StartsWith(_modulesRoot, StringComparison.Ordinal)) { // Skip "Modules/" from the folder path. var path = folder.Substring(_modulesRoot.Length); var index = path.IndexOf('/'); // Resolve the module id and get all its asset paths. var name = index == -1 ? path : path.Substring(0, index); var ph = _root + _modulesFolder + "\\" + name; var paths = new List <string>(); foreach (var file in _fileProviderAccessor.GetDirectoryContents(path)) { paths.Add(path + name + file.Name); paths.Add(folder + file.Name); } // Resolve all files and folders directly under this given folder. NormalizedPaths.ResolveFolderContents(folder, paths, out var files, out var folders); // And add them to the directory contents. entries.AddRange(files.Select(p => GetFileInfo(p))); entries.AddRange(folders.Select(n => new EmbeddedDirectoryInfo(n))); } return(new EmbeddedDirectoryContents(entries)); }
public IDirectoryContents GetDirectoryContents(string subpath) { if (subpath == null) { return(NotFoundDirectoryContents.Singleton); } var folder = NormalizePath(subpath); var entries = new List <IFileInfo>(); // Under the root. if (folder == "") { // Add the virtual folder "Areas" containing all modules. entries.Add(new EmbeddedDirectoryInfo(Application.ModulesPath)); } // Under "Areas". else if (folder == Application.ModulesPath) { // Add virtual folders for all modules by using their assembly names (module ids). entries.AddRange(Application.Modules.Select(m => new EmbeddedDirectoryInfo(m.Name))); } // Under "Areas/{ModuleId}" or "Areas/{ModuleId}/**". else if (folder.StartsWith(Application.ModulesRoot, StringComparison.Ordinal)) { // Skip "Areas/" from the folder path. var path = folder.Substring(Application.ModulesRoot.Length); var index = path.IndexOf('/'); // Resolve the module id and get all its asset paths. var name = index == -1 ? path : path.Substring(0, index); var paths = Application.GetModule(name).AssetPaths; // Resolve all files and folders directly under this given folder. NormalizedPaths.ResolveFolderContents(folder, paths, out var files, out var folders); // And add them to the directory contents. entries.AddRange(files.Select(p => GetFileInfo(p))); entries.AddRange(folders.Select(n => new EmbeddedDirectoryInfo(n))); } return(new EmbeddedDirectoryContents(entries)); }