private DirectoryModel createDirectoryModel(ElfinderFile di, string directoryHash, string parentHash) { // check if path is root path - if yes then we need to change name string dirName = di.Name; if (di.Id == 1 /*_config.LocalFSRootDirectoryPath*/) { dirName = _config.RootDirectoryName; parentHash = null; } return new DirectoryModel(dirName, directoryHash, parentHash, DB.GetChildDir(di.Id).Any(), di.Mtime, Id, di.Read, di.Write, di.Locked); }
private FileModel createFileModel(ElfinderFile fi, string parentHash) { string hash = EncodePathToHash(fi.Content); string thumbnail = null; // supports thumbnails? //if (_imageEditorService.CanGenerateThumbnail(fi.Id.ToString())) //{ // if (!_config.LocalFSThumbsDirectoryPath.Contains(fi.DirectoryName)) // { // // check if thumbnail exists - cache it maybe? // string thumbnailPath = _config.LocalFSThumbsDirectoryPath + Path.DirectorySeparatorChar + hash + // fi.Extension; // if (File.Exists(thumbnailPath)) // thumbnail = hash + fi.Extension; // else // thumbnail = FileModel.ThumbnailIsSupported; // can create thumbnail // } //} return new FileModel(fi.Name, thumbnail, hash, fi.Size, parentHash, fi.Mtime, Id, fi.Read, fi.Write, fi.Locked); }
public FileModel CreateFile(DirectoryModel inDir, string name) { if (inDir == null) return null; string path = DecodeHashToPath(inDir.Hash, false); var model = DB.GetModelByHash(path); using (var context = new FileManagerContext()) { bool exist = context.ElfinderFiles.Count(x => x.Name == name && x.Parent_id == model.Id) > 0; if (exist) return null; } try { var filekey = this._key.CreateFileKey(name); this._uploadFile.SaveFile(new byte[0], filekey); var createdFile = new ElfinderFile { Name = name, Parent_id = model.Id, Mime = name.Substring(name.LastIndexOf('.') + 1), Read = true, Write = true, Width = 0, Content = filekey, Locked = false, Height = 0, Hidden = false, Mtime = DateTime.Now, Size = 0 }; using (var context = new FileManagerContext()) { context.ElfinderFiles.Add(createdFile); context.SaveChanges(); } return createFileModel(createdFile, inDir.Hash); } catch { throw new Exception(); return null; } }
public FileModel[] SaveFiles(string targetDirHash, IList<HttpPostedFile> files) { if (files == null) return new FileModel[0]; string targetPath = DecodeHashToPath(targetDirHash, false); //if (!Directory.Exists(targetPath)) // return new FileModel[0]; var entity = DB.GetModelByHash(targetPath); if (entity == null) return new FileModel[0]; IList<FileModel> added = new List<FileModel>(); for (int i = 0; i < files.Count; ++i) { HttpPostedFile file = files[i]; // handle special upload case, when "Include local directory path when uploading files" in IE is enabled (this might be when in intranet site): // http://blogs.msdn.com/b/webtopics/archive/2009/07/27/uploading-a-file-using-fileupload-control-fails-in-ie8.aspx string fName = Path.GetFileName(file.FileName); var key = this._key.CreateFileKey(fName); this._uploadFile.SaveFile(file.InputStream, key); var isImgFile = Dev.Comm.Utils.FileUtil.IsImageFile(fName); var Height = 0; var Width = 0; if (isImgFile) { var size = Dev.Comm.ImageHelper.GetImageSize(file.InputStream); Height = size.Height; Width = size.Width; } var createdFile = new ElfinderFile { Name = fName, Parent_id = entity.Id, Mime = Path.GetExtension(fName), Read = true, Write = true, Width = Width, Content = key, Locked = false, Height = Height, Hidden = false, Mtime = DateTime.Now, Size = file.ContentLength }; DB.AddModel(createdFile); added.Add(createFileModel(createdFile, targetDirHash)); } return added.ToArray(); }
public DirectoryModel CreateDirectory(DirectoryModel inDir, string name) { if (inDir == null) return null; string path = DecodeHashToPath(inDir.Hash, false); var model = DB.GetModelByHash(path); using (var context = new FileManagerContext()) { bool exist = context.ElfinderFiles.Count(x => x.Name == name && x.Parent_id == model.Id) > 0; if (exist) return null; } try { var createdDirectory = new ElfinderFile { Name = name, Parent_id = model.Id,// int.Parse(DecodeHashToPath(inDir.Hash, false)), Mime = "directory", Read = true, Write = true, Width = 0, Content = this._key.CreateFileKey("noname"), Locked = false, Height = 0, Hidden = false, Mtime = DateTime.Now, Size = 0 }; using (var context = new FileManagerContext()) { context.ElfinderFiles.Add(createdDirectory); context.SaveChanges(); } return createDirectoryModel(createdDirectory, EncodePathToHash(createdDirectory.Content), inDir.Hash); } catch { throw; } }