/// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="fileInfo">File info</param>
        /// <param name="rootVolume">Root volume</param>
        /// <returns>Result instance</returns>
        public static ImageEntryObjectModel Create(FileInfo fileInfo, FileSystemRootVolume rootVolume)
        {
            // Get paths
            var parentPath   = fileInfo.Directory?.FullName.Substring(rootVolume.Directory.FullName.Length);
            var relativePath = fileInfo.FullName.Substring(rootVolume.Directory.FullName.Length);

            // Get image size
            var imageSize = ImagingUtils.GetImageSize(fileInfo.FullName);

            // Create new instance
            var objectModel = new ImageEntryObjectModel
            {
                Read          = true,
                Write         = !rootVolume.IsReadOnly,
                Locked        = rootVolume.IsLocked,
                Name          = fileInfo.Name,
                Size          = fileInfo.Length,
                UnixTimeStamp = (long)(fileInfo.LastWriteTimeUtc - UnixOrigin).TotalSeconds,
                Mime          = UrlPathUtils.GetMimeType(fileInfo),
                Hash          = rootVolume.VolumeId + UrlPathUtils.EncodePath(relativePath),
                ParentHash    =
                    rootVolume.VolumeId +
                    UrlPathUtils.EncodePath(!string.IsNullOrEmpty(parentPath) ? parentPath : fileInfo.Directory?.Name),
                Tmb       = rootVolume.GetExistingThumbHash(fileInfo) ?? "",
                Dimension = $"{imageSize.Width}x{imageSize.Height}"
            };

            // Return it
            return(objectModel);
        }
예제 #2
0
        /// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="fileInfo">File info</param>
        /// <param name="rootVolume">Root volume</param>
        /// <returns>Result instance</returns>
        public static FileEntryObjectModel Create(FileInfo fileInfo, FileSystemRootVolume rootVolume)
        {
            // Get paths
            var parentPath   = fileInfo.Directory?.FullName.Substring(rootVolume.Directory.FullName.Length);
            var relativePath = fileInfo.FullName.Substring(rootVolume.Directory.FullName.Length);

            // Create new instance
            var objectModel = new FileEntryObjectModel
            {
                Read          = true,
                Write         = !rootVolume.IsReadOnly,
                Locked        = rootVolume.IsLocked,
                Name          = fileInfo.Name,
                Size          = fileInfo.Length,
                UnixTimeStamp = (long)(fileInfo.LastWriteTimeUtc - UnixOrigin).TotalSeconds,
                Mime          = UrlPathUtils.GetMimeType(fileInfo),
                Hash          = rootVolume.VolumeId + UrlPathUtils.EncodePath(relativePath),
                ParentHash    =
                    rootVolume.VolumeId +
                    UrlPathUtils.EncodePath(!string.IsNullOrEmpty(parentPath) ? parentPath : fileInfo.Directory?.Name)
            };

            // Return it
            return(objectModel);
        }
예제 #3
0
 /// <summary>
 /// Generate thumbnail hash
 /// </summary>
 /// <param name="fileInfo">File info</param>
 /// <returns>Result</returns>
 public string GenerateThumbHash(FileInfo fileInfo)
 {
     if (ThumbnailsDirectory == null)
     {
         var thumbName    = Path.GetFileNameWithoutExtension(fileInfo.Name) + "_" + FileSystemUtils.GetFileMd5(fileInfo) + fileInfo.Extension;
         var relativePath = fileInfo.DirectoryName?.Substring(Directory.FullName.Length);
         return(VolumeId + UrlPathUtils.EncodePath(relativePath + "\\" + thumbName));
     }
     else
     {
         var thumbPath    = GenerateThumbPath(fileInfo);
         var relativePath = thumbPath.Substring(ThumbnailsDirectory.FullName.Length);
         return(VolumeId + UrlPathUtils.EncodePath(relativePath));
     }
 }
예제 #4
0
        /// <summary>
        /// Get existing thumbnails hash for file
        /// </summary>
        /// <param name="fileInfo">File info</param>
        /// <returns>Result</returns>
        public string GetExistingThumbHash(FileInfo fileInfo)
        {
            // Get thumbnails path
            var thumbPath = GetExistingThumbPath(fileInfo);

            if (thumbPath == null)
            {
                return(null);
            }

            // Get result paths
            var relativePath = thumbPath.Substring(this.GetThumbnailStoragePath().Length);

            return(VolumeId + UrlPathUtils.EncodePath(relativePath));
        }
예제 #5
0
        /// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="directoryInfo">Directory path info</param>
        /// <param name="rootVolume">Root volume</param>
        /// <returns>Result instance</returns>
        public static DirectoryEntryObjectModel Create(DirectoryInfo directoryInfo, FileSystemRootVolume rootVolume)
        {
            // Get visible subdirectories
            var subDirectories = directoryInfo.GetVisibleDirectories();

            // Validate parent directory
            if (directoryInfo.Parent == null)
            {
                throw new ELFinderParentDirectoryNotFoundException(directoryInfo.FullName);
            }

            // Get parent path
            var parentPath = directoryInfo.Parent.FullName.Substring(rootVolume.Directory.FullName.Length);

            // Create new instance
            var objectModel = new DirectoryEntryObjectModel
            {
                Mime = "directory",
                ContainsChildDirs = subDirectories.Any(),
                Hash =
                    rootVolume.VolumeId +
                    UrlPathUtils.EncodePath(
                        directoryInfo.FullName.Substring(rootVolume.Directory.FullName.Length)),
                Read          = true,
                Write         = !rootVolume.IsReadOnly,
                Locked        = rootVolume.IsLocked,
                Size          = 0,
                Name          = directoryInfo.Name,
                UnixTimeStamp = (long)(directoryInfo.LastWriteTimeUtc - UnixOrigin).TotalSeconds,
                ParentHash    =
                    rootVolume.VolumeId +
                    UrlPathUtils.EncodePath(!string.IsNullOrEmpty(parentPath)
                        ? parentPath
                        : directoryInfo.Parent?.Name)
            };

            // Return it
            return(objectModel);
        }
        /// <summary>
        /// Create a new instance
        /// </summary>
        /// <param name="directoryInfo">Directory path info</param>
        /// <param name="rootVolume">Root volume</param>
        /// <returns>Result instance</returns>
        public static RootDirectoryEntryObjectModel Create(DirectoryInfo directoryInfo, FileSystemRootVolume rootVolume)
        {
            // Get visible subdirectories
            var subDirectories = directoryInfo.GetVisibleDirectories();

            // Create new instance
            var objectModel = new RootDirectoryEntryObjectModel
            {
                Mime          = "directory",
                Dirs          = subDirectories.Any(),
                Hash          = rootVolume.VolumeId + UrlPathUtils.EncodePath(directoryInfo.Name),
                Read          = true,
                Write         = !rootVolume.IsReadOnly,
                Locked        = rootVolume.IsLocked,
                Name          = rootVolume.Alias,
                Size          = 0,
                UnixTimeStamp = (long)(directoryInfo.LastWriteTimeUtc - UnixOrigin).TotalSeconds,
                VolumeId      = rootVolume.VolumeId
            };

            // Return it
            return(objectModel);
        }