public static DTOBase Create(FileInfo info, Root root) { if (info == null) throw new ArgumentNullException("info"); if (root == null) throw new ArgumentNullException("root"); string ext = info.Extension.ToLower(); string parentPath = info.Directory.FullName.Substring(root.Directory.FullName.Length); FileDTO response; string hash = root.VolumeId + Helper.EncodePath(info.FullName.Substring(root.Directory.FullName.Length)); if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || info.Extension == ".gif") { response = new ImageDTO(); //((ImageDTO)response).Thumbnail = } else { response = new FileDTO(); } response.Read = 1; response.Write = root.IsReadOnly ? (byte)0 : (byte)1; response.Locked = root.IsReadOnly ? (byte)1 : (byte)0; response.Name = info.Name; response.Size = info.Length; response.UnixTimeStamp = (long)(info.LastWriteTimeUtc - _unixOrigin).TotalSeconds; response.Mime = Helper.GetMimeType(info); response.Hash = hash; response.ParentHash = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : info.Directory.Name); return response; }
public static DTOBase Create(FileInfo info, Root root) { if (info == null) throw new ArgumentNullException("info"); if (root == null) throw new ArgumentNullException("root"); string parentPath = info.Directory.FullName.Substring(root.Directory.FullName.Length); string relativePath = info.FullName.Substring(root.Directory.FullName.Length); FileDTO response; if (root.CanCreateThumbnail(info)) { ImageDTO imageResponse = new ImageDTO(); imageResponse.Thumbnail = root.GetExistingThumbHash(info) ?? (object)1; var dim = root.GetImageDimension(info); imageResponse.Dimension = string.Format("{0}x{1}", dim.Width, dim.Height); response = imageResponse; } else { response = new FileDTO(); } response.Read = 1; response.Write = root.IsReadOnly ? (byte)0 : (byte)1; response.Locked = (root.LockedFolders.Any(f => f == info.Directory.Name) || root.IsLocked) ? (byte)1 : (byte)0; response.Name = info.Name; response.Size = info.Length; response.UnixTimeStamp = (long)(info.LastWriteTimeUtc - _unixOrigin).TotalSeconds; response.Mime = Helper.GetMimeType(info); response.Hash = root.VolumeId + Helper.EncodePath(relativePath); response.ParentHash = root.VolumeId + Helper.EncodePath(parentPath.Length > 0 ? parentPath : info.Directory.Name); return response; }