// constructors
 /// <summary>
 /// Initializes a new instance of the BsonDocumentReader class.
 /// </summary>
 /// <param name="document">A BsonDocument.</param>
 /// <param name="settings">The reader settings.</param>
 public BsonDocumentReader(BsonDocument document, BsonDocumentReaderSettings settings)
     : base(settings)
 {
     _context                = new BsonDocumentReaderContext(null, ContextType.TopLevel, document);
     _currentValue           = document;
     _documentReaderSettings = settings; // already frozen by base class
 }
        /// <summary>
        /// Reads the end of a BSON document from the reader.
        /// </summary>
        public override void ReadEndDocument()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            if (_context.ContextType != ContextType.Document && _context.ContextType != ContextType.ScopeDocument)
            {
                ThrowInvalidContextType("ReadEndDocument", _context.ContextType, ContextType.Document, ContextType.ScopeDocument);
            }
            if (State == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfDocument if at end of document
            }
            if (State != BsonReaderState.EndOfDocument)
            {
                ThrowInvalidState("ReadEndDocument", BsonReaderState.EndOfDocument);
            }

            _context = _context.PopContext();
            switch (_context.ContextType)
            {
            case ContextType.Array: State = BsonReaderState.Type; break;

            case ContextType.Document: State = BsonReaderState.Type; break;

            case ContextType.TopLevel: State = BsonReaderState.Done; break;

            default: throw new BsonInternalException("Unexpected ContextType.");
            }
        }
Esempio n. 3
0
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonDocument document)
 {
     _parentContext = parentContext;
     _contextType   = contextType;
     _document      = document;
 }
Esempio n. 4
0
 // constructors
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonArray array)
 {
     _parentContext = parentContext;
     _contextType   = contextType;
     _array         = array;
 }
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonDocument document)
 {
     _parentContext = parentContext;
     _contextType = contextType;
     _document = document;
 }
 // constructors
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonArray array)
 {
     _parentContext = parentContext;
     _contextType = contextType;
     _array = array;
 }
        /// <summary>
        /// Returns the reader to previously bookmarked position and state.
        /// </summary>
        /// <param name="bookmark">The bookmark.</param>
        public override void ReturnToBookmark(BsonReaderBookmark bookmark)
        {
            var documentReaderBookmark = (BsonDocumentReaderBookmark)bookmark;

            State           = documentReaderBookmark.State;
            CurrentBsonType = documentReaderBookmark.CurrentBsonType;
            CurrentName     = documentReaderBookmark.CurrentName;
            _context        = documentReaderBookmark.CloneContext();
            _currentValue   = documentReaderBookmark.CurrentValue;
        }
 // constructors
 internal BsonDocumentReaderBookmark(
     BsonReaderState state,
     BsonType currentBsonType,
     string currentName,
     BsonDocumentReaderContext context,
     BsonValue currentValue)
     : base(state, currentBsonType, currentName)
 {
     _context = context.Clone();
     _currentValue = currentValue;
 }
Esempio n. 9
0
 // constructors
 internal BsonDocumentReaderBookmark(
     BsonReaderState state,
     BsonType currentBsonType,
     string currentName,
     BsonDocumentReaderContext context,
     BsonValue currentValue)
     : base(state, currentBsonType, currentName)
 {
     _context      = context.Clone();
     _currentValue = currentValue;
 }
        // constructors
        /// <summary>
        /// Initializes a new instance of the BsonDocumentReader class.
        /// </summary>
        /// <param name="document">A BsonDocument.</param>
        /// <param name="settings">The reader settings.</param>
        public BsonDocumentReader(BsonDocument document, BsonDocumentReaderSettings settings)
            : base(settings)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            _context                = new BsonDocumentReaderContext(null, ContextType.TopLevel, document);
            _currentValue           = document;
            _documentReaderSettings = settings; // already frozen by base class
        }
        /// <summary>
        /// Reads the start of a BSON array.
        /// </summary>
        public override void ReadStartArray()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            VerifyBsonType("ReadStartArray", BsonType.Array);

            var array = _currentValue.AsBsonArray;

            _context = new BsonDocumentReaderContext(_context, ContextType.Array, array);
            State    = BsonReaderState.Type;
        }
Esempio n. 12
0
 // used by Clone
 private BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonDocument document,
     BsonArray array,
     int index)
 {
     _parentContext = parentContext;
     _contextType   = contextType;
     _document      = document;
     _array         = array;
     _index         = index;
 }
 // used by Clone
 private BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonDocument document,
     BsonArray array,
     int index)
 {
     _parentContext = parentContext;
     _contextType = contextType;
     _document = document;
     _array = array;
     _index = index;
 }
        /// <summary>
        /// Reads the start of a BSON document.
        /// </summary>
        public override void ReadStartDocument()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            VerifyBsonType("ReadStartDocument", BsonType.Document);

            BsonDocument document;
            var          script = _currentValue as BsonJavaScriptWithScope;

            if (script != null)
            {
                document = script.Scope;
            }
            else
            {
                document = _currentValue.AsBsonDocument;
            }
            _context = new BsonDocumentReaderContext(_context, ContextType.Document, document);
            State    = BsonReaderState.Type;
        }