public UnifiedGridFsDeleteOperation Build(string targetBucketId, BsonDocument arguments) { var bucket = _entityMap.GetBucket(targetBucketId); ObjectId?id = null; foreach (var argument in arguments) { switch (argument.Name) { case "id": id = argument.Value.AsObjectId; break; default: throw new FormatException($"Invalid GridFsDeleteOperation argument name: '{argument.Name}'."); } } return(new UnifiedGridFsDeleteOperation(bucket, id.Value)); }
public UnifiedGridFsUploadOperation Build(string targetBucketId, BsonDocument arguments) { var bucket = _entityMap.GetBucket(targetBucketId); string filename = null; GridFSUploadOptions options = null; byte[] source = null; foreach (var argument in arguments) { switch (argument.Name) { case "chunkSizeBytes": options = options ?? new GridFSUploadOptions(); options.ChunkSizeBytes = argument.Value.AsInt32; break; case "filename": filename = argument.Value.AsString; break; case "source": var sourceDocument = argument.Value.AsBsonDocument; JsonDrivenHelper.EnsureAllFieldsAreValid(sourceDocument, "$$hexBytes"); var sourceString = sourceDocument["$$hexBytes"].AsString; if (sourceString.Length % 2 != 0) { throw new FormatException("$$hexBytes must have an even number of bytes."); } source = BsonUtils.ParseHexString(sourceString); break; default: throw new FormatException($"Invalid GridFsUploadOperation argument name: '{argument.Name}'."); } } return(new UnifiedGridFsUploadOperation(bucket, filename, source, options)); }