/// <summary> /// Deletes one filed form Workstation or Black List collection /// </summary> /// <param name="filteredField">spcifies which field in database is going to be filtered</param> /// <param name="value">value of the field we wish to delete</param> /// <param name="collection">collection from where value is going to be deleted</param> public void DeleteOne(string filteredField, string value, int collection) { //in case of 0(Workstations) then... if (collection == 0) { RefreshWorkstations(); var filter = Builders <Workstations> .Filter.Eq(filteredField, ObjectId.Parse(value)); var list = workstationsCollection.Find(filter).ToList(); IGridFSBucket bucket = new GridFSBucket(db);; foreach (var l in list) { foreach (var a in l.Alerts) { bucket.Delete(a.Link1); bucket.Delete(a.Link2); bucket.Delete(a.Link3); } } workstationsCollection.DeleteOne(filter); } //in case of 1(Black List) then... else if (collection == 1) { var filter = Builders <BlackList> .Filter.Eq(filteredField, value); blackListCollection.DeleteOne(filter); } }
/// <summary> /// Acknowledge a handle was processed and remove from queue. /// </summary> /// <param name="handle">handle received from Get()</param> /// <exception cref="ArgumentNullException">handle is null</exception> public void Ack(Handle handle) { if (handle == null) { throw new ArgumentNullException("handle"); } collection.DeleteOne(new QueryDocument("_id", handle.Id)); foreach (var stream in handle.Streams) { stream.Value.Dispose(); gridfs.Delete(stream.Key); } }
public bool Delete(string fileId) { GridFSBucket gridFS = new GridFSBucket(this.GetDB()); gridFS.Delete(new ObjectId(fileId)); return(true); }
/// <summary> /// 删除文件 /// </summary> /// <param name="objectID"></param> public void FileDelete(string objectID) { GridFSBucket fs = new GridFSBucket(_db); ObjectId obj = new ObjectId(objectID); fs.Delete(obj); }
public void UploadImage(Image imageToUpload, string imageName) { var cardHashName = imageName.Substring(0, 4) + imageName.Substring(imageName.Length - 8, 4) + imageName.Substring(imageName.Length - 4, 4); MongoClient client = connection(); var db = client.GetDatabase("CreditCardIMG"); var bucket = new GridFSBucket(db); Image img = imageToUpload; byte[] source = ImageToByteArray(img); if (IsImageExist(cardHashName)) { var filter = Builders <GridFSFileInfo> .Filter.And( Builders <GridFSFileInfo> .Filter.Eq(x => x.Filename, cardHashName)); var options = new GridFSFindOptions { Limit = 1 }; using (var cursor = bucket.Find(filter, options)) { var fileInfo = cursor.ToList().FirstOrDefault(); bucket.Delete(fileInfo.Id); bucket.UploadFromBytes(cardHashName, source); } } else { bucket.UploadFromBytes(cardHashName, source); } }
private void DeleteImage(Rental rental) { IGridFSBucket bucket = new GridFSBucket(context.Database); bucket.Delete(new ObjectId(rental.ImageId)); context.Rentals.UpdateOne <Rental>(f => f.Id == rental.Id, Builders <Rental> .Update.Set(d => d.ImageId, null)); }
private void DeleteImage(Rental rental) { var gridFs = new GridFSBucket(Context.MongoDatabase); gridFs.Delete(new ObjectId(rental.ImageId)); rental.ImageId = null; Context.Rentals.ReplaceOne(x => x.Id == rental.Id, rental); }
public void DeleteSingleFile(ObjectId id) { MongoClient client = GetClient(m_connectionStr); var db = client.GetDatabase(DatabaseName); var bucket = new GridFSBucket(db, BucksOptions); bucket.Delete(id); }
public void DeleteDocument(string documentKey) { metadataCollection.DeleteOne($"{{{IdKey}: '{documentKey}'}}"); var file = fileBucket.Find(Builders <GridFSFileInfo> .Filter.Eq(e => e.Filename, documentKey)).FirstOrDefault(); if (file != null) { fileBucket.Delete(file.Id); } }
public bool DelFuncionario(string CPF) { try { // Remove imagem caso exista Funcionario func = _context.Funcionarios.Find(x => x.CPF == CPF).FirstOrDefault(); if (func != null && func.Photo != null) { _gridFS.Delete(func.Photo); } // Filtra funcionário pelo CPF e remove-o do BD FilterDefinition <Funcionario> filter = Builders <Funcionario> .Filter.Eq(x => x.CPF, CPF); DeleteResult deleteResult = _context.Funcionarios.DeleteOne(filter); return(deleteResult.IsAcknowledged && deleteResult.DeletedCount > 0); } catch (Exception ex) { throw new Exception("Falha ao deletar funcionário", ex); } }
public void Delete(string filePath) { string[] stringArray = filePath.Split('\\'); if (stringArray.Length < 2) { new FileUtilsException($"文件路径不正确:{filePath}"); } GridFSBucket fileSystem = new GridFSBucket(db, new GridFSBucketOptions { BucketName = stringArray[0] }); string fileName = filePath.Substring(stringArray[0].Length + 1, filePath.Length - stringArray[0].Length - 1); fileSystem.Delete(fileName); }
public bool Delete(string fileReference) { if (string.IsNullOrEmpty(fileReference)) { return(false); } try { var fs = new GridFSBucket(_context.Database); fs.Delete(new ObjectId(fileReference)); return(true); } catch { return(false); } }
public override void RemoveAttachment(string id, string attachmentName) { var bucket = new GridFSBucket(database, new GridFSBucketOptions() { BucketName = "attachments" }); var document = bucket.Find(Builders <GridFSFileInfo> .Filter.Eq(e => e.Metadata["attachment-id"], id + "-" + attachmentName)).FirstOrDefault(); if (document != null) { bucket.Delete(document.Id); } else { throw new AttachmentNotFoundNoSQLException(); } }
public CleanUpOperator(IMongoCollection <CleanUpTime> cleanUp, IMongoCollection <ToDeleteRevision> revisions, GridFSBucket bucket) { Receive <StartCleanUp>(_ => { try { var data = cleanUp.AsQueryable().First(); if (data.Last + data.Interval >= DateTime.Now) { return; } List <FilterDefinition <ToDeleteRevision> > deleted = new List <FilterDefinition <ToDeleteRevision> >(); foreach (var revision in revisions.AsQueryable()) { bucket.Delete(ObjectId.Parse(revision.BuckedId)); deleted.Add(Builders <ToDeleteRevision> .Filter.Eq(r => r.BuckedId == revision.BuckedId, true)); } if (deleted.Count != 0) { if (!revisions.DeleteMany(Builders <ToDeleteRevision> .Filter.And(deleted)).IsAcknowledged) { Log.Warning("Delete Revisions not Deleted"); } } if (!cleanUp.UpdateOne(Builders <CleanUpTime> .Filter.Empty, Builders <CleanUpTime> .Update.Set(c => c.Last, DateTime.Now)).IsAcknowledged) { Log.Warning("Cleanup Interval not updated"); } } catch (Exception e) { Log.Error(e, "Error on Clean up Database"); } finally { Context.Stop(Self); } }); }
private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { var items = GetSelectedItems(); if (items.Count == 0) { return; } try { var gridFsBucket = new GridFSBucket(GetDatabase()); foreach (var item in items) { gridFsBucket.Delete(item.Id); } SearchAsync(); } catch (Exception ex) { Logger.Log("***GridFS Error " + ex.Message); } }
/// <summary> /// 删除文件 /// </summary> /// <param name="filename"></param> public bool DeleteFile(string filename) { // 从FileInfo查找文件信息 var collection = fileInfoDB.GetCollection <BucketFileInfo>(fileInfoDbName); var results = collection.Find(fileInfo => fileInfo.FileName.Equals(filename)); if (results.Any()) { if (results.CountDocuments() > 1) { throw new GridFSException($"more than one file found with name {filename}"); } var id = results.First().Id; collection.DeleteOne(info => info.Id == id); fsBucket.Delete(id); return(true); } else { return(false); } }
public bool Delete(Guid id) { _fs.Delete(id); return(true); }
// protected methods protected void InvokeMethod(GridFSBucket bucket) { bucket.Delete(_id); }
/// <summary> /// 删除文件 /// </summary> /// <param name="id"></param> public void DeleteAndRename(ObjectId id) { bucket.Delete(id); }
public void DeleteFile(ObjectId objectId) { GridFSBucket gridFS = new GridFSBucket(_context.Database); gridFS.Delete(objectId); }
public bool DeleteFile(string fileId) { _gridFs.Delete(ObjectId.Parse(fileId)); return(true); }