FindOne() public method

Finds the most recent version of a GridFS file.
public FindOne ( IMongoQuery query ) : MongoDB.Driver.GridFS.MongoGridFSFileInfo
query IMongoQuery The GridFS file.
return MongoDB.Driver.GridFS.MongoGridFSFileInfo
コード例 #1
0
        public void AttachFile(byte[] data, FileReference fileData, SCORMObject obj)
        {
            List<FileReference> files = new List<FileReference>();
            if (obj.Files != null)
            {
                files.AddRange(obj.Files);
            }

            var db = MongoDB.Driver.MongoDatabase.Create(_ConnectionString);
            var gfs = new MongoGridFS(db);
            var id = Guid.NewGuid().ToString();
            using (var file = gfs.OpenWrite(id))
            {
                file.Write(data, 0, data.Length);
                file.Flush();
            }
            var fileInfo = gfs.FindOne(id);
            gfs.SetContentType(fileInfo, fileData.ContentType);
            fileData.FileId = id;
            files.Add(fileData);
            obj.Files = files;
        }
コード例 #2
0
 private Stream GetImageStream(ImageData imageData, MongoGridFS mongoGridFS)
 {
     var file = mongoGridFS.FindOne(Query.EQ("_id", imageData.Id));
     return file.OpenRead();
 }
コード例 #3
0
        public ReturnFileStream GetFileStream(String objectId)
        {
            var db = MongoDB.Driver.MongoDatabase.Create(_ConnectionString);
            var gfs = new MongoGridFS(db);
            var value = gfs.FindOne(objectId);

            return new ReturnFileStream { Content = value.OpenRead(), ContentType = value.ContentType };
        }
コード例 #4
0
ファイル: MongoPolicy.cs プロジェクト: ideayapai/docviewer
        /// <summary>
        /// 获取元数据信息
        /// </summary>
        /// <param name="remoteFile"></param>
        /// <returns></returns>
        public MetaInfo GetMeta(string remoteFile)
        {
            _logger.DebugFormat("GetMeta By Id{0}.", remoteFile);

            MongoGridFS fs = new MongoGridFS(_context.DataBase);
            if (!fs.Exists(remoteFile))
            {
                return null;
            }

            var info = fs.FindOne(remoteFile);
            return new MetaInfo
            {
                fileName = remoteFile,
                MD5 = info.MD5,
                MimeType = info.ContentType,
            };
        }