// 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
 }
 public BsonDocumentReader(
     BsonDocument document
 )
 {
     context = new BsonDocumentReaderContext(null, ContextType.TopLevel, document);
     currentValue = document;
 }
Пример #3
0
        /// <summary>
        /// Reads the end of a BSON array from the reader.
        /// </summary>
        public override void ReadEndArray()
        {
            if (Disposed)
            {
                ThrowObjectDisposedException();
            }
            if (_context.ContextType != ContextType.Array)
            {
                ThrowInvalidContextType("ReadEndArray", _context.ContextType, ContextType.Array);
            }
            if (State == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfArray if at end of array
            }
            if (State != BsonReaderState.EndOfArray)
            {
                ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray);
            }

            _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.");
            }
        }
Пример #4
0
 // 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;
     this.settings = settings; // already frozen by base class
 }
Пример #5
0
        /// <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.");
            }
        }
Пример #6
0
        /// <summary>
        /// Reads the end of a BSON array from the reader.
        /// </summary>
        public override void ReadEndArray()
        {
            if (disposed)
            {
                ThrowObjectDisposedException();
            }
            if (context.ContextType != ContextType.Array)
            {
                var message = string.Format("ReadEndArray cannot be called when ContextType is: {0}", context.ContextType);
                throw new InvalidOperationException(message);
            }
            if (state == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfArray if at end of array
            }
            if (state != BsonReaderState.EndOfArray)
            {
                var message = string.Format("ReadEndArray cannot be called when State is: {0}", state);
                throw new InvalidOperationException(message);
            }

            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");
            }
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the BsonDocumentReader class.
 /// </summary>
 /// <param name="document">A BsonDocument.</param>
 public BsonDocumentReader(
     BsonDocument document
     )
 {
     context      = new BsonDocumentReaderContext(null, ContextType.TopLevel, document);
     currentValue = document;
 }
 /// <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
 ) {
     context = new BsonDocumentReaderContext(null, ContextType.TopLevel, document);
     currentValue = document;
     this.settings = settings.Freeze();
 }
 // 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)
 {
     this.parentContext = parentContext;
     this.contextType   = contextType;
     this.document      = document;
     this.array         = array;
     this.index         = index;
 }
 // used by Clone
 private BsonDocumentReaderContext(BsonDocumentReaderContext parentContext, ContextType contextType, BsonDocument document, BsonArray array, int index)
 {
     this.parentContext = parentContext;
     this.contextType = contextType;
     this.document = document;
     this.array = array;
     this.index = index;
 }
Пример #12
0
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonDocument document)
 {
     _parentContext = parentContext;
     _contextType = contextType;
     _document = document;
 }
Пример #13
0
 // constructors
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonArray array)
 {
     _parentContext = parentContext;
     _contextType = contextType;
     _array = array;
 }
Пример #14
0
 /// <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
     )
 {
     context       = new BsonDocumentReaderContext(null, ContextType.TopLevel, document);
     currentValue  = document;
     this.settings = settings.Freeze();
 }
Пример #15
0
        /// <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;
        }
Пример #16
0
 /// <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;
 }
Пример #17
0
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonDocument document)
 {
     _parentContext = parentContext;
     _contextType   = contextType;
     _document      = document;
 }
Пример #18
0
 // constructors
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonArray array)
 {
     _parentContext = parentContext;
     _contextType   = contextType;
     _array         = array;
 }
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonDocument document
     )
 {
     this.parentContext = parentContext;
     this.contextType   = contextType;
     this.document      = document;
 }
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonArray array
     )
 {
     this.parentContext = parentContext;
     this.contextType   = contextType;
     this.array         = array;
 }
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonDocument document
 )
 {
     this.parentContext = parentContext;
     this.contextType = contextType;
     this.document = document;
 }
 internal BsonDocumentReaderContext(
     BsonDocumentReaderContext parentContext,
     ContextType contextType,
     BsonArray array
 )
 {
     this.parentContext = parentContext;
     this.contextType = contextType;
     this.array = array;
 }
 internal BsonDocumentReaderBookmark(
     BsonDocumentReaderContext context,
     BsonReadState state,
     BsonType currentBsonType
 )
 {
     this.context = context.Clone();
     this.state = state;
     this.currentBsonType = currentBsonType;
 }
 // constructors
 internal BsonDocumentReaderBookmark(
     BsonReaderState state,
     BsonType currentBsonType,
     string currentName,
     BsonDocumentReaderContext context,
     BsonValue currentValue)
     : base(state, currentBsonType, currentName)
 {
     _context      = context.Clone();
     _currentValue = currentValue;
 }
        /// <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;
        }
Пример #26
0
 // constructors
 internal BsonDocumentReaderBookmark(
     BsonReaderState state,
     BsonType currentBsonType,
     string currentName,
     BsonDocumentReaderContext context,
     BsonValue currentValue)
     : base(state, currentBsonType, currentName)
 {
     _context = context.Clone();
     _currentValue = currentValue;
 }
Пример #27
0
        /// <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;
        }
Пример #28
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;
 }
Пример #29
0
        /// <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;
        }
        /// <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;
        }
        /// <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;
        }
        /// <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.");
            }
        }
        public override void ReadEndDocument()
        {
            if (disposed) { ThrowObjectDisposedException(); }
            if (
                context.ContextType != ContextType.Document &&
                context.ContextType != ContextType.ScopeDocument
            ) {
                var message = string.Format("ReadEndDocument cannot be called when ContextType is: {0}", context.ContextType);
                throw new InvalidOperationException(message);
            }
            if (state == BsonReadState.Type && context.GetNextElement() == null) {
                // automatically advance to EndOfDocument state
                state = BsonReadState.EndOfDocument;
            }
            if (state != BsonReadState.EndOfDocument) {
                var message = string.Format("ReadEndDocument cannot be called when ReadState is: {0}", state);
                throw new InvalidOperationException(message);
            }

            context = context.PopContext();
            state = (context == null) ? BsonReadState.Done : BsonReadState.Type;
        }
        public override void ReadStartArray()
        {
            if (disposed) { ThrowObjectDisposedException(); }
            if (state != BsonReadState.Value || currentBsonType != BsonType.Array) {
                string message = string.Format("ReadStartArray cannot be called when ReadState is: {0} and BsonType is: {1}", state, currentBsonType);
                throw new InvalidOperationException(message);
            }

            var array = currentElement.Value.AsBsonArray;
            context = new BsonDocumentReaderContext(context, ContextType.Array, array);
            state = BsonReadState.Type;
        }
 public BsonDocumentReaderContext Clone()
 {
     var clone = new BsonDocumentReaderContext();
     clone.parentContext = this.parentContext;
     clone.contextType = this.contextType;
     clone.document = this.document;
     clone.array = this.array;
     clone.index = this.index;
     return clone;
 }
 public override void ReturnToBookmark(
     BsonReaderBookmark bookmark
 )
 {
     var documentReaderBookmark = (BsonDocumentReaderBookmark) bookmark;
     context = documentReaderBookmark.Context;
     state = documentReaderBookmark.State;
     currentBsonType = documentReaderBookmark.CurrentBsonType;
 }
 public BsonDocumentReader(
     BsonDocument document
 )
 {
     context = new BsonDocumentReaderContext(null, ContextType.Document, document);
 }
 /// <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;
 }
        public override void ReadStartDocument()
        {
            if (disposed) { ThrowObjectDisposedException(); }
            if (
                state != BsonReadState.Initial &&
                state != BsonReadState.ScopeDocument &&
                (state != BsonReadState.Value || currentBsonType != BsonType.Document)
            ) {
                string message = string.Format("ReadStartDocument cannot be called when ReadState is: {0} and BsonType is: {1}", state, currentBsonType);
                throw new InvalidOperationException(message);
            }

            if (state == BsonReadState.ScopeDocument) {
                var scope = currentElement.Value.AsBsonJavaScriptWithScope.Scope;
                context = new BsonDocumentReaderContext(context, ContextType.ScopeDocument, scope);
            } else if (state == BsonReadState.Value) {
                var document = currentElement.Value.AsBsonDocument;
                context = new BsonDocumentReaderContext(context, ContextType.Document, document);
            }
            state = BsonReadState.Type;
        }
        /// <summary>
        /// Reads the end of a BSON array from the reader.
        /// </summary>
        public override void ReadEndArray()
        {
            if (Disposed) { ThrowObjectDisposedException(); }
            if (_context.ContextType != ContextType.Array)
            {
                ThrowInvalidContextType("ReadEndArray", _context.ContextType, ContextType.Array);
            }
            if (State == BsonReaderState.Type)
            {
                ReadBsonType(); // will set state to EndOfArray if at end of array
            }
            if (State != BsonReaderState.EndOfArray)
            {
                ThrowInvalidState("ReadEndArray", BsonReaderState.EndOfArray);
            }

            _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.");
            }
        }
        /// <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
            ) {
                var message = string.Format("ReadEndDocument cannot be called when ContextType is: {0}", context.ContextType);
                throw new InvalidOperationException(message);
            }
            if (state == BsonReaderState.Type) {
                ReadBsonType(); // will set state to EndOfDocument if at end of document
            }
            if (state != BsonReaderState.EndOfDocument) {
                var message = string.Format("ReadEndDocument cannot be called when State is: {0}", state);
                throw new InvalidOperationException(message);
            }

            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");
            }
        }