コード例 #1
0
ファイル: UnsafeStream.cs プロジェクト: solyutor/ejdb-csharp
 public UnsafeStream(BsonHandle bson) : this(bson.GetBsonBuffer())
 {
     if (bson.IsInvalid)
     {
         throw new InvalidOperationException();
     }
     _bson = bson;
 }
コード例 #2
0
ファイル: Collection.cs プロジェクト: solyutor/ejdb-csharp
        /// <summary>
        /// Loads JSON object identified by OID from the collection.
        /// </summary>
        /// <remarks>
        /// Returns <c>null</c> if object is not found.
        /// </remarks>
        /// <param name="id">Id of an object</param>
        public BsonDocument Load(ObjectId id)
        {
            using (var bson = new BsonHandle(() => _functions.LoadBson(CollectionHandle, ref id), Database.Library))
            {
                //document does not exists
                if (bson.IsInvalid)
                {
                    return(null);
                }

                using (var stream = Database.Library.ConvertToStream(bson))
                {
                    return(new BsonDocument(stream));
                }
            }
        }
コード例 #3
0
ファイル: Collection.cs プロジェクト: solyutor/ejdb-csharp
        /// <summary>
        /// Loads JSON object identified by OID from the collection.
        /// </summary>
        /// <remarks>
        /// Returns <c>null</c> if object is not found.
        /// </remarks>
        /// <param name="id">Id of an object</param>
        public TDocument Load <TDocument>(ObjectId id)
        {
            using (var bson = new BsonHandle(() => _functions.LoadBson(CollectionHandle, ref id), Database.Library))
            {
                //document does not exists
                if (bson.IsInvalid)
                {
                    return(default(TDocument));
                }

                using (var stream = Database.Library.ConvertToStream(bson))
                    using (var reader = new BsonReader(stream))
                    {
                        var document = Serializer.Deserialize <TDocument>(reader);
                        IdHelper <TDocument> .SetId(document, ref id);

                        return(document);
                    }
            }
        }
コード例 #4
0
        internal Stream ConvertToStream(BsonHandle bson)
        {
            var stream = new UnsafeStream(bson);

            return(stream);
        }