public static Archive[] GetFiles(string virtualPath, string resourceType) { Check.Arguments.ThrowIfStringNotSafe(virtualPath, "virtualPath"); Check.Arguments.ThrowIfStringNotSafe(resourceType, "resourceType"); var result = new List <Archive>(); var mappedPath = PathHelper.ToMappedPath(virtualPath); var dir = new DirectoryInfo(mappedPath); var resource = FileBrowser.Config.Settings.GetResources().FirstOrDefault(item => item.ResourceType.Equals(resourceType, StringComparison.InvariantCultureIgnoreCase)); if (resource != null) { var extensions = resource.GetAllowedExtensions(); foreach (var file in dir.GetFiles()) { if (!extensions.Any(extension => extension.Equals(file.Extension, StringComparison.InvariantCultureIgnoreCase))) { continue; } result.Add(new Archive() { DateCreated = file.CreationTime, Name = file.Name, Path = PathHelper.ToRelativePath(file.FullName), Size = (file.Length / 1024d) }); } } return(result.ToArray()); }
public static Folder GetTreeview() { if (!DirectoryHelper.Exists(FileBrowser.Config.Settings.Directory.GetUserVirtualDirectory())) { throw new DirectoryNotFoundException("User directory not found."); } var rootVirtualPath = FileBrowser.Config.Settings.Directory.GetUserVirtualDirectory().EnsureEndsWith("/").ToLower(); var rootMappedPath = PathHelper.ToMappedPath(rootVirtualPath); var rootDir = new DirectoryInfo(rootMappedPath); var rootNode = FolderViewHelper.GetRootTreeviewNode(rootDir); foreach (var resource in FileBrowser.Config.Settings.GetResources().OrderBy(x => x.ResourceType)) { if (DirectoryHelper.Exists(string.Concat(rootVirtualPath, resource.ResourceType))) { var childVirtualPath = string.Concat(rootVirtualPath, resource.ResourceType).EnsureEndsWith("/").ToLower(); var childMappethPath = PathHelper.ToMappedPath(childVirtualPath); var childDir = new DirectoryInfo(childMappethPath); rootNode.Children.Add(FolderViewHelper.GetChildTreeviewNode(childDir, rootNode, resource, 1)); } } return(rootNode); }
private void EnsureDirectoryExistence(string path) { Check.Arguments.ThrowIfStringNotSafe(path, "path"); if (path.StartsWith("~")) { path = PathHelper.ToMappedPath(path); } if (!this.MappedPathExists(path)) { Directory.CreateDirectory(path); } }
private bool VirtualPathExists(string virtualPath) { Check.Arguments.ThrowIfStringNotSafe(virtualPath, "virtualPath"); return(this.MappedPathExists(PathHelper.ToMappedPath(virtualPath))); }