public static async Task <BaseModel> CreateAsync(IDriver driver, IDirectory directory, RootVolume volume) { if (directory == null) { throw new ArgumentNullException("directory"); } if (volume == null) { throw new ArgumentNullException("volume"); } if (volume.RootDirectory == directory.FullName) { bool hasSubdirs = false; var subdirs = await directory.GetDirectoriesAsync(); foreach (var item in subdirs) { if (!item.Attributes.HasFlag(FileAttributes.Hidden)) { hasSubdirs = true; break; } } var response = new RootModel { Mime = "directory", Dirs = hasSubdirs ? (byte)1 : (byte)0, Hash = volume.VolumeId + HttpEncoder.EncodePath(directory.Name), Read = 1, Write = volume.IsReadOnly ? (byte)0 : (byte)1, Locked = volume.IsLocked ? (byte)1 : (byte)0, Name = volume.Alias, Size = 0, UnixTimeStamp = (long)(DateTime.UtcNow - unixOrigin).TotalSeconds, VolumeId = volume.VolumeId }; return(response); } else { string parentPath = directory.Parent.FullName.Substring(volume.RootDirectory.Length); string relativePath = directory.FullName.Substring(volume.RootDirectory.Length).TrimEnd(Path.DirectorySeparatorChar); var response = new DirectoryModel { Mime = "directory", ContainsChildDirs = (await directory.GetDirectoriesAsync()).Count() > 0 ? (byte)1 : (byte)0, Hash = volume.VolumeId + HttpEncoder.EncodePath(relativePath), Read = 1, Write = volume.IsReadOnly ? (byte)0 : (byte)1, Locked = ((volume.LockedFolders != null && volume.LockedFolders.Any(f => f == directory.Name)) || volume.IsLocked) ? (byte)1 : (byte)0, Size = 0, Name = directory.Name, UnixTimeStamp = (long)(await directory.LastWriteTimeUtcAsync - unixOrigin).TotalSeconds, ParentHash = volume.VolumeId + HttpEncoder.EncodePath(parentPath.Length > 0 ? parentPath : directory.Parent.Name) }; return(response); } }