public void TestSetMetadata() { var fileInfo = UploadHelloWorld(); Assert.IsNull(fileInfo.Metadata); var metadata = new BsonDocument { { "a", 1 }, { "b", 2 } }; _gridFS.SetMetadata(fileInfo, metadata); fileInfo.Refresh(); Assert.AreEqual(metadata, fileInfo.Metadata); _gridFS.SetMetadata(fileInfo, null); fileInfo.Refresh(); Assert.IsNull(fileInfo.Metadata); }
private void InternalMoveFile(string fromVirtualPath, string destinationVirtualPath) { MongoGridFS mongoGridFs = GetGridFS(); string fixedDestinationPath = FixPath(destinationVirtualPath); mongoGridFs.MoveTo(FixPath(fromVirtualPath), fixedDestinationPath); MongoGridFSFileInfo fileInfo = mongoGridFs.FindOne(fixedDestinationPath); mongoGridFs.SetMetadata(fileInfo, CreateMetadata(fixedDestinationPath, fileInfo.Metadata["is_directory"] == new BsonBoolean(true))); }
public void CopyFile(string fromVirtualPath, string destinationVirtualPath) { MongoGridFS mongoGridFs = GetGridFS(); string fixedDestinationPath = FixPath(destinationVirtualPath); mongoGridFs.CopyTo(FixPath(fromVirtualPath), fixedDestinationPath); MongoGridFSFileInfo fileInfo = mongoGridFs.FindOne(fixedDestinationPath); mongoGridFs.SetMetadata(fileInfo, CreateMetadata(fixedDestinationPath, false)); if (FileCopied != null) { FileCopied.Invoke(this, new FileEventArgs(destinationVirtualPath, fromVirtualPath)); } }
public Stream OpenFile(string virtualPath, bool readOnly = false) { string fixedPath = FixPath(virtualPath); if (!FileExists(fixedPath) && !readOnly) { InternalWriteFile(fixedPath, new MemoryStream(new byte[0])); } MongoGridFS gridFs = GetGridFS(); if (readOnly) { return(gridFs.OpenRead(fixedPath)); } MongoGridFSFileInfo fileInfo = gridFs.FindOne(fixedPath); gridFs.SetMetadata(fileInfo, CreateMetadata(fixedPath, false)); return(gridFs.OpenWrite(fixedPath)); }
/// <summary> /// update security attributes /// </summary> /// <param name="filepath"></param> /// <param name="ownerId"></param> /// <param name="roles"></param> /// <returns></returns> public IStorageFile UpdateSecurityInfo(string filepath, Guid?ownerId, List <Guid> roles) { if (string.IsNullOrWhiteSpace(filepath)) { throw new ArgumentException("filepath cannot be null or empty"); } //all filepaths are lowercase and all starts with folder separator filepath = filepath.ToLowerInvariant(); if (!filepath.StartsWith(FOLDER_SEPARATOR)) { filepath = FOLDER_SEPARATOR + filepath; } var file = gfs.FindOne(filepath); if (file == null) { throw new ArgumentException("file does not exist."); } BsonDocument metadata = new BsonDocument(); metadata.Add(new BsonElement("owner_id", ownerId)); BsonArray rolesArr = new BsonArray(); if (roles != null && roles.Count > 0) { foreach (var roleId in roles) { rolesArr.Add(BsonValue.Create(roleId)); } } metadata.Add(new BsonElement("available_to_roles", rolesArr)); gfs.SetMetadata(file, metadata); return(Find(filepath)); }