public IEnumerable <FileDescriptionEntity> LoadFileTree() { List <FileDescriptionEntity> fileList = new List <FileDescriptionEntity>(); if (!string.IsNullOrEmpty(metadataConfiguration.GetFilesDirectory())) { var currentPath = metadataConfiguration.GetFilesDirectory(); var inputDirectory = new DirectoryInfo(currentPath); var allFiles = inputDirectory.GetFiles(); const int newFileTimeFrameMin = -10; var newFileBorder = DateTime.Now.AddMinutes(newFileTimeFrameMin); Array.Sort(allFiles, (x, y) => { if (x.LastAccessTime >= newFileBorder && y.LastAccessTime >= newFileBorder) { return(DateTime.Compare(y.LastAccessTime, x.LastAccessTime)); } if (x.LastAccessTime < newFileBorder && y.LastAccessTime < newFileBorder) { return(string.Compare(x.Name, y.Name, CultureInfo.InvariantCulture, CompareOptions.None)); } return(x.LastAccessTime >= newFileBorder ? -1 : 1); }); foreach (var file in allFiles) { // check if current file/folder is hidden if (!file.Attributes.HasFlag(FileAttributes.Hidden) && !file.Name.StartsWith(".") && !file.Attributes.HasFlag(FileAttributes.Directory)) { // add object to array list fileList.Add(new FileDescriptionEntity { guid = file.Name, name = file.Name, size = file.Length, }); } } } return(fileList); }
public IEnumerable <FileDescriptionEntity> LoadFileTree() { List <FileDescriptionEntity> fileList = new List <FileDescriptionEntity>(); if (!string.IsNullOrEmpty(metadataConfiguration.GetFilesDirectory())) { var currentPath = metadataConfiguration.GetFilesDirectory(); List <string> allFiles = new List <string>(Directory.GetFiles(currentPath)); allFiles.AddRange(Directory.GetDirectories(currentPath)); // TODO: get temp directory name string tempDirectoryName = "temp"; allFiles.Sort(new FileNameComparator()); allFiles.Sort(new FileDateComparator()); foreach (string file in allFiles) { FileInfo fileInfo = new FileInfo(file); // check if current file/folder is hidden if (!(tempDirectoryName.Equals(Path.GetFileName(file)) || fileInfo.Attributes.HasFlag(FileAttributes.Hidden) || fileInfo.Name.StartsWith(".") || Path.GetFileName(file).Equals(Path.GetFileName(metadataConfiguration.GetFilesDirectory())))) { FileDescriptionEntity fileDescription = new FileDescriptionEntity(); fileDescription.guid = Path.GetFileName(file); fileDescription.name = Path.GetFileName(file); // set is directory true/false fileDescription.isDirectory = fileInfo.Attributes.HasFlag(FileAttributes.Directory); // set file size if (!fileDescription.isDirectory) { fileDescription.size = fileInfo.Length; } // add object to array list fileList.Add(fileDescription); } } } return(fileList); }