Exemple #1
0
 /// <summary>
 /// Creates a BsonWriter to a BsonBuffer.
 /// </summary>
 /// <param name="buffer">A BsonBuffer.</param>
 /// <param name="settings">Optional BsonBinaryWriterSettings.</param>
 /// <returns>A BsonWriter.</returns>
 public static BsonWriter Create(
     BsonBuffer buffer,
     BsonBinaryWriterSettings settings
     )
 {
     return(new BsonBinaryWriter(null, buffer, settings));
 }
Exemple #2
0
 /// <summary>
 /// Creates a BsonWriter to a BSON Stream.
 /// </summary>
 /// <param name="stream">A Stream.</param>
 /// <param name="settings">Optional BsonBinaryWriterSettings.</param>
 /// <returns>A BsonWriter.</returns>
 public static BsonWriter Create(
     Stream stream,
     BsonBinaryWriterSettings settings
     )
 {
     return(new BsonBinaryWriter(stream, null, BsonBinaryWriterSettings.Defaults));
 }
 public static BsonWriter Create(
     BsonBuffer buffer,
     BsonBinaryWriterSettings settings
 )
 {
     return new BsonBinaryWriter(null, buffer, settings);
 }
 internal MongoInsertMessage(
     BsonBinaryWriterSettings writerSettings,
     string collectionFullName
 )
     : base(MessageOpcode.Insert, null, writerSettings) {
     this.collectionFullName = collectionFullName;
 }
 public static BsonWriter Create(
     Stream stream,
     BsonBinaryWriterSettings settings
 )
 {
     return new BsonBinaryWriter(stream, null, BsonBinaryWriterSettings.Defaults);
 }
 // constructors
 protected BulkWriteOperationArgs(
     string collectionName,
     string databaseName,
     int maxBatchCount,
     int maxBatchLength,
     int maxDocumentSize,
     int maxWireDocumentSize,
     bool isOrdered,
     BsonBinaryReaderSettings readerSettings,
     IEnumerable<WriteRequest> requests,
     WriteConcern writeConcern,
     BsonBinaryWriterSettings writerSettings)
 {
     _collectionName = collectionName;
     _databaseName = databaseName;
     _maxBatchCount = maxBatchCount;
     _maxBatchLength = maxBatchLength;
     _maxDocumentSize = maxDocumentSize;
     _maxWireDocumentSize = maxWireDocumentSize;
     _isOrdered = isOrdered;
     _readerSettings = readerSettings;
     _requests = requests;
     _writeConcern = writeConcern;
     _writerSettings = writerSettings;
 }
 // constructors
 public BulkInsertOperationArgs(
     Action<InsertRequest> assignId,
     bool checkElementNames,
     string collectionName,
     string databaseName,
     int maxBatchCount,
     int maxBatchLength,
     int maxDocumentSize,
     int maxWireDocumentSize,
     bool isOrdered,
     BsonBinaryReaderSettings readerSettings,
     IEnumerable<InsertRequest> requests,
     WriteConcern writeConcern,
     BsonBinaryWriterSettings writerSettings)
     : base(
         collectionName,
         databaseName,
         maxBatchCount,
         maxBatchLength,
         maxDocumentSize,
         maxWireDocumentSize,
         isOrdered,
         readerSettings,
         requests.Cast<WriteRequest>(),
         writeConcern,
         writerSettings)
 {
     _assignId = assignId;
     _checkElementNames = checkElementNames;
 }
 // constructors
 internal MongoInsertMessage(BsonBinaryWriterSettings writerSettings, string collectionFullName, bool checkElementNames, InsertFlags flags)
     : base(MessageOpcode.Insert, null, writerSettings)
 {
     this.collectionFullName = collectionFullName;
     this.checkElementNames = checkElementNames;
     this.flags = flags;
 }
 // constructors
 public BulkDeleteOperationArgs(
     string collectionName,
     string databaseName,
     int maxBatchCount,
     int maxBatchLength,
     int maxDocumentSize,
     int maxWireDocumentSize,
     bool isOrdered,
     BsonBinaryReaderSettings readerSettings,
     IEnumerable<DeleteRequest> requests,
     WriteConcern writeConcern,
     BsonBinaryWriterSettings writerSettings)
     : base(
         collectionName,
         databaseName,
         maxBatchCount,
         maxBatchLength,
         maxDocumentSize,
         maxWireDocumentSize,
         isOrdered,
         readerSettings,
         requests.Cast<WriteRequest>(),
         writeConcern,
         writerSettings)
 {
 }
 // constructors
 internal MongoDeleteMessage(BsonBinaryWriterSettings writerSettings, string collectionFullName, RemoveFlags flags, IMongoQuery query)
     : base(MessageOpcode.Delete, null, writerSettings)
 {
     _collectionFullName = collectionFullName;
     _flags = flags;
     _query = query;
 }
 // constructors
 public BulkMixedWriteOperation(
     Action<InsertRequest> assignId,
     bool checkElementNames,
     string collectionName,
     string databaseName,
     int maxBatchCount,
     int maxBatchLength,
     int maxDocumentSize,
     int maxWireDocumentSize,
     bool isOrdered,
     BsonBinaryReaderSettings readerSettings,
     IEnumerable<WriteRequest> requests,
     WriteConcern writeConcern,
     BsonBinaryWriterSettings writerSettings)
 {
     _assignId = assignId;
     _checkElementNames = checkElementNames;
     _collectionName = collectionName;
     _databaseName = databaseName;
     _maxBatchCount = maxBatchCount;
     _maxBatchLength = maxBatchLength;
     _maxDocumentSize = maxDocumentSize;
     _maxWireDocumentSize = maxWireDocumentSize;
     _isOrdered = isOrdered;
     _readerSettings = readerSettings;
     _requests = requests;
     _writeConcern = writeConcern;
     _writerSettings = writerSettings;
 }
        private int _messageStartPosition = -1; // start position in buffer for backpatching messageLength

        // constructors
        protected MongoRequestMessage(
            MessageOpcode opcode,
            BsonBinaryWriterSettings writerSettings)
            : base(opcode)
        {
            _writerSettings = writerSettings;
            RequestId = Interlocked.Increment(ref __lastRequestId);
        }
 protected ReadOperationBase(
     string databaseName,
     string collectionName,
     BsonBinaryReaderSettings readerSettings,
     BsonBinaryWriterSettings writerSettings)
     : base(databaseName, collectionName, readerSettings, writerSettings)
 {
 }
 // constructors
 internal MongoUpdateMessage(BsonBinaryWriterSettings writerSettings, string collectionFullName, bool checkUpdateDocument, UpdateFlags flags, IMongoQuery query, IMongoUpdate update)
     : base(MessageOpcode.Update, null, writerSettings)
 {
     this.collectionFullName = collectionFullName;
     this.checkUpdateDocument = checkUpdateDocument;
     this.flags = flags;
     this.query = query;
     this.update = update;
 }
 internal MongoQueryMessage(BsonBuffer buffer, BsonBinaryWriterSettings writerSettings, string collectionFullName, QueryFlags flags, int numberToSkip, int numberToReturn, IMongoQuery query, IMongoFields fields)
     : base(MessageOpcode.Query, buffer, writerSettings)
 {
     this.collectionFullName = collectionFullName;
     this.flags = flags;
     this.numberToSkip = numberToSkip;
     this.numberToReturn = numberToReturn;
     this.query = query;
     this.fields = fields;
 }
 protected WriteOpcodeOperationBase(
     string databaseName,
     string collectionName,
     BsonBinaryReaderSettings readerSettings,
     BsonBinaryWriterSettings writerSettings,
     WriteConcern writeConcern)
     : base(databaseName, collectionName, readerSettings, writerSettings)
 {
     _writeConcern = writeConcern;
 }
 protected DatabaseOperation(
     string databaseName,
     string collectionName,
     BsonBinaryReaderSettings readerSettings,
     BsonBinaryWriterSettings writerSettings)
 {
     _databaseName = databaseName;
     _collectionName = collectionName;
     _readerSettings = (BsonBinaryReaderSettings)readerSettings.FrozenCopy();
     _writerSettings = (BsonBinaryWriterSettings)writerSettings.FrozenCopy();
 }
 // constructors
 internal MongoQueryMessage(
     BsonBinaryWriterSettings writerSettings,
     string collectionFullName,
     QueryFlags flags,
     int numberToSkip,
     int numberToReturn,
     IMongoQuery query,
     IMongoFields fields)
     : this(null, writerSettings, collectionFullName, flags, numberToSkip, numberToReturn, query, fields)
 {
 }
        protected WriteConcernResult SendMessageWithWriteConcern(
            MongoConnection connection,
            BsonBuffer buffer,
            int requestId,
            BsonBinaryReaderSettings readerSettings,
            BsonBinaryWriterSettings writerSettings,
            WriteConcern writeConcern)
        {
            CommandDocument getLastErrorCommand = null;
            if (writeConcern.Enabled)
            {
                var fsync = (writeConcern.FSync == null) ? null : (BsonValue)writeConcern.FSync;
                var journal = (writeConcern.Journal == null) ? null : (BsonValue)writeConcern.Journal;
                var w = (writeConcern.W == null) ? null : writeConcern.W.ToGetLastErrorWValue();
                var wTimeout = (writeConcern.WTimeout == null) ? null : (BsonValue)(int)writeConcern.WTimeout.Value.TotalMilliseconds;

                getLastErrorCommand = new CommandDocument
                {
                    { "getlasterror", 1 }, // use all lowercase for backward compatibility
                    { "fsync", fsync, fsync != null },
                    { "j", journal, journal != null },
                    { "w", w, w != null },
                    { "wtimeout", wTimeout, wTimeout != null }
                };

                // piggy back on network transmission for message
                var getLastErrorMessage = new MongoQueryMessage(writerSettings, DatabaseName + ".$cmd", QueryFlags.None, 0, 1, getLastErrorCommand, null);
                getLastErrorMessage.WriteToBuffer(buffer);
            }

            connection.SendMessage(buffer, requestId);

            WriteConcernResult writeConcernResult = null;
            if (writeConcern.Enabled)
            {
                var writeConcernResultSerializer = BsonSerializer.LookupSerializer(typeof(WriteConcernResult));
                var replyMessage = connection.ReceiveMessage<WriteConcernResult>(readerSettings, writeConcernResultSerializer, null);
                if (replyMessage.NumberReturned == 0)
                {
                    throw new MongoCommandException("Command 'getLastError' failed. No response returned");
                }
                writeConcernResult = replyMessage.Documents[0];
                writeConcernResult.Command = getLastErrorCommand;

                var mappedException = ExceptionMapper.Map(writeConcernResult);
                if (mappedException != null)
                {
                    throw mappedException;
                }
            }

            return writeConcernResult;
        }
 public RemoveOperation(
     string databaseName,
     string collectionName,
     BsonBinaryReaderSettings readerSettings,
     BsonBinaryWriterSettings writerSettings,
     WriteConcern writeConcern,
     IMongoQuery query,
     RemoveFlags flags)
     : base(databaseName, collectionName, readerSettings, writerSettings, writeConcern)
 {
     _query = query;
     _flags = flags;
 }
Exemple #21
0
        // protected methods
        /// <summary>
        /// Creates a clone of the settings.
        /// </summary>
        /// <returns>A clone of the settings.</returns>
        protected override BsonWriterSettings CloneImplementation()
        {
            var clone = new BsonBinaryWriterSettings
            {
                Encoding = _encoding,
                FixOldBinarySubTypeOnOutput = _fixOldBinarySubTypeOnOutput,
                GuidRepresentation          = GuidRepresentation,
                MaxDocumentSize             = _maxDocumentSize,
                MaxSerializationDepth       = MaxSerializationDepth
            };

            return(clone);
        }
 public BsonBinaryWriter CreateBinaryWriter()
 {
     var writerSettings = new BsonBinaryWriterSettings();
     if (_encoderSettings != null)
     {
         writerSettings.Encoding = _encoderSettings.GetOrDefault(MessageEncoderSettingsName.WriteEncoding, writerSettings.Encoding);
         writerSettings.FixOldBinarySubTypeOnOutput = _encoderSettings.GetOrDefault(MessageEncoderSettingsName.FixOldBinarySubTypeOnOutput, writerSettings.FixOldBinarySubTypeOnOutput);
         writerSettings.GuidRepresentation = _encoderSettings.GetOrDefault(MessageEncoderSettingsName.GuidRepresentation, writerSettings.GuidRepresentation);
         writerSettings.MaxDocumentSize = _encoderSettings.GetOrDefault(MessageEncoderSettingsName.MaxDocumentSize, writerSettings.MaxDocumentSize);
         writerSettings.MaxSerializationDepth = _encoderSettings.GetOrDefault(MessageEncoderSettingsName.MaxSerializationDepth, writerSettings.MaxSerializationDepth);
     }
     return new BsonBinaryWriter(_stream, writerSettings);
 }
        /// <summary>
        /// Initializes a new instance of the BsonBinaryWriter class.
        /// </summary>
        /// <param name="buffer">A BsonBuffer.</param>
        /// <param name="disposeBuffer">if set to <c>true</c> this BsonBinaryReader will own the buffer and when Dispose is called the buffer will be Disposed also.</param>
        /// <param name="settings">Optional BsonBinaryWriter settings.</param>
        /// <exception cref="System.ArgumentNullException">
        /// encoder
        /// or
        /// settings
        /// </exception>
        public BsonBinaryWriter(BsonBuffer buffer, bool disposeBuffer, BsonBinaryWriterSettings settings)
            : base(settings)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("encoder");
            }

            _buffer = buffer;
            _disposeBuffer = disposeBuffer;
            _binaryWriterSettings = settings; // already frozen by base class

            _context = null;
            State = BsonWriterState.Initial;
        }
        /// <summary>
        /// Initializes a new instance of the BsonBinaryWriter class.
        /// </summary>
        /// <param name="buffer">A BsonBuffer.</param>
        /// <param name="disposeBuffer">if set to <c>true</c> this BsonBinaryReader will own the buffer and when Dispose is called the buffer will be Disposed also.</param>
        /// <param name="settings">Optional BsonBinaryWriter settings.</param>
        /// <exception cref="System.ArgumentNullException">
        /// encoder
        /// or
        /// settings
        /// </exception>
        public BsonBinaryWriter(BsonBuffer buffer, bool disposeBuffer, BsonBinaryWriterSettings settings)
            : base(settings)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("encoder");
            }

            _buffer               = buffer;
            _disposeBuffer        = disposeBuffer;
            _binaryWriterSettings = settings; // already frozen by base class

            _context = null;
            State    = BsonWriterState.Initial;
        }
        public void DeserializeBatch_should_return_expected_result_when_GuidRepresentation_is_Standard()
        {
            var document = BsonDocument.Parse("{ batch : [ { a : HexData(4, \"0102030405060708090a0b0c0d0e0f10\") } ] }");
            var writerSettings = new BsonBinaryWriterSettings { GuidRepresentation = GuidRepresentation.Standard };
            var bson = document.ToBson(writerSettings: writerSettings);
            var rawDocument = new RawBsonDocument(bson);
            var batch = (RawBsonArray)rawDocument["batch"];
            var documentSerializer = BsonDocumentSerializer.Instance;
            var messageEncoderSettings = new MessageEncoderSettings { { "GuidRepresentation", GuidRepresentation.Standard } };

            var result = CursorBatchDeserializationHelper.DeserializeBatch<BsonDocument>(batch, documentSerializer, messageEncoderSettings);

            result.Count.Should().Be(1);
            result[0].Should().BeOfType<BsonDocument>();
            result[0].Should().Be("{ a : HexData(4, \"0102030405060708090a0b0c0d0e0f10\") }");
        }
 // constructors
 internal MongoUpdateMessage(
     BsonBinaryWriterSettings writerSettings,
     string collectionFullName,
     bool checkUpdateDocument,
     UpdateFlags flags,
     int maxDocumentSize,
     IMongoQuery query,
     IMongoUpdate update)
     : base(MessageOpcode.Update, writerSettings)
 {
     _collectionFullName = collectionFullName;
     _checkUpdateDocument = checkUpdateDocument;
     _flags = flags;
     _maxDocumentSize = maxDocumentSize;
     _query = query;
     _update = update;
 }
 // constructors
 internal MongoQueryMessage(
     BsonBinaryWriterSettings writerSettings,
     string collectionFullName,
     QueryFlags flags,
     int numberToSkip,
     int numberToReturn,
     IMongoQuery query,
     IMongoFields fields)
     : base(MessageOpcode.Query, writerSettings)
 {
     _collectionFullName = collectionFullName;
     _flags = flags;
     _numberToSkip = numberToSkip;
     _numberToReturn = numberToReturn;
     _query = query;
     _fields = fields;
 }
 public UpdateOperation(
     string databaseName,
     string collectionName,
     BsonBinaryReaderSettings readerSettings,
     BsonBinaryWriterSettings writerSettings,
     WriteConcern writeConcern,
     IMongoQuery query,
     IMongoUpdate update,
     UpdateFlags flags,
     bool checkElementNames)
     : base(databaseName, collectionName, readerSettings, writerSettings, writeConcern)
 {
     _query = query;
     _update = update;
     _flags = flags;
     _checkElementNames = checkElementNames;
 }
 // constructors
 protected MongoRequestMessage(MessageOpcode opcode, BsonBuffer buffer, BsonBinaryWriterSettings writerSettings)
     : base(opcode)
 {
     // buffer is not null if piggybacking this message onto an existing buffer
     if (buffer == null)
     {
         this.buffer = new BsonBuffer();
         this.disposeBuffer = true; // only call Dispose if we allocated the buffer
     }
     else
     {
         this.buffer = buffer;
         this.disposeBuffer = false;
     }
     this.writerSettings = writerSettings;
     this.requestId = Interlocked.Increment(ref lastRequestId);
 }
        // private methods
        private CommandResult RunCommand(MongoConnection connection, string databaseName, IMongoCommand command)
        {
            var readerSettings = new BsonBinaryReaderSettings();
            var writerSettings = new BsonBinaryWriterSettings();
            var resultSerializer = BsonSerializer.LookupSerializer<CommandResult>();

            var commandOperation = new CommandOperation<CommandResult>(
                databaseName,
                readerSettings,
                writerSettings,
                command,
                QueryFlags.None,
                null, // options
                null, // readPreference
                resultSerializer);

            return commandOperation.Execute(connection);
        }
Exemple #31
0
        // protected methods
        /// <summary>
        /// Creates a clone of the settings.
        /// </summary>
        /// <returns>A clone of the settings.</returns>
        protected override BsonWriterSettings CloneImplementation()
        {
            var clone = new BsonBinaryWriterSettings
            {
                Encoding = _encoding,
                FixOldBinarySubTypeOnOutput = _fixOldBinarySubTypeOnOutput,
                MaxDocumentSize             = _maxDocumentSize,
                MaxSerializationDepth       = MaxSerializationDepth
            };

#pragma warning disable 618
            if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
            {
                clone.GuidRepresentation = GuidRepresentation;
            }
#pragma warning restore 618
            return(clone);
        }
Exemple #32
0
        /// <summary>
        /// Initializes a new instance of the BsonBinaryWriter class.
        /// </summary>
        /// <param name="stream">A stream. The BsonBinaryWriter does not own the stream and will not Dispose it.</param>
        /// <param name="settings">The BsonBinaryWriter settings.</param>
        public BsonBinaryWriter(Stream stream, BsonBinaryWriterSettings settings)
            : base(settings)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must be capable of seeking.", "stream");
            }

            _baseStream = stream;
            _bsonStream = (stream as BsonStream) ?? new BsonStreamAdapter(stream);

            _context = null;
            State    = BsonWriterState.Initial;
        }
        /// <summary>
        /// Initializes a new instance of the BsonBinaryWriter class.
        /// </summary>
        /// <param name="stream">A stream.</param>
        /// <param name="buffer">A BsonBuffer.</param>
        /// <param name="settings">Optional BsonBinaryWriter settings.</param>
        public BsonBinaryWriter(
            Stream stream,
            BsonBuffer buffer,
            BsonBinaryWriterSettings settings
        ) {
            this.stream = stream;
            if (buffer == null) {
                this.buffer = new BsonBuffer();
                this.disposeBuffer = true; // only call Dispose if we allocated the buffer
            } else {
                this.buffer = buffer;
                this.disposeBuffer = false;
            }
            this.settings = settings.Freeze();

            context = null;
            state = BsonWriterState.Initial;
        }
        // constructors
        /// <summary>
        /// Initializes a new instance of the BsonBinaryWriter class.
        /// </summary>
        /// <param name="stream">A stream.</param>
        /// <param name="buffer">A BsonBuffer.</param>
        /// <param name="settings">Optional BsonBinaryWriter settings.</param>
        public BsonBinaryWriter(Stream stream, BsonBuffer buffer, BsonBinaryWriterSettings settings)
            : base(settings)
        {
            _stream = stream;
            if (buffer == null)
            {
                _buffer = new BsonBuffer();
                _disposeBuffer = true; // only call Dispose if we allocated the buffer
            }
            else
            {
                _buffer = buffer;
                _disposeBuffer = false;
            }
            _binaryWriterSettings = settings; // already frozen by base class

            _context = null;
            State = BsonWriterState.Initial;
        }
 // constructors
 internal MongoInsertMessage(
     BsonBinaryWriterSettings writerSettings,
     string collectionFullName,
     bool checkElementNames,
     InsertFlags flags,
     int maxBatchCount,
     int maxBatchLength,
     int maxDocumentSize,
     Batch<InsertRequest> batch)
     : base(MessageOpcode.Insert, writerSettings)
 {
     _collectionFullName = collectionFullName;
     _checkElementNames = checkElementNames;
     _flags = flags;
     _maxBatchCount = maxBatchCount;
     _maxBatchLength = maxBatchLength;
     _maxDocumentSize = maxDocumentSize;
     _batch = batch;
 }
        // constructors
        /// <summary>
        /// Initializes a new instance of the BsonBinaryWriter class.
        /// </summary>
        /// <param name="stream">A stream.</param>
        /// <param name="buffer">A BsonBuffer.</param>
        /// <param name="settings">Optional BsonBinaryWriter settings.</param>
        public BsonBinaryWriter(Stream stream, BsonBuffer buffer, BsonBinaryWriterSettings settings)
            : base(settings)
        {
            _stream = stream;
            if (buffer == null)
            {
                _buffer        = new BsonBuffer();
                _disposeBuffer = true; // only call Dispose if we allocated the buffer
            }
            else
            {
                _buffer        = buffer;
                _disposeBuffer = false;
            }
            _binaryWriterSettings = settings; // already frozen by base class

            _context = null;
            State    = BsonWriterState.Initial;
        }
 public InsertOperation(
     string databaseName,
     string collectionName,
     BsonBinaryReaderSettings readerSettings,
     BsonBinaryWriterSettings writerSettings,
     WriteConcern writeConcern,
     bool assignIdOnInsert,
     bool checkElementNames,
     Type documentType,
     IEnumerable documents,
     InsertFlags flags)
     : base(databaseName, collectionName, readerSettings, writerSettings, writeConcern)
 {
     _assignIdOnInsert = assignIdOnInsert;
     _checkElementNames = checkElementNames;
     _documentType = documentType;
     _documents = documents;
     _flags = flags;
 }
Exemple #38
0
        /// <summary>
        /// Initializes a new instance of the BsonBinaryWriter class.
        /// </summary>
        /// <param name="stream">A stream. The BsonBinaryWriter does not own the stream and will not Dispose it.</param>
        /// <param name="settings">The BsonBinaryWriter settings.</param>
        public BsonBinaryWriter(Stream stream, BsonBinaryWriterSettings settings)
            : base(settings)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must be capable of seeking.", "stream");
            }

            _baseStream = stream;
            _bsonStream = (stream as BsonStream) ?? new BsonStreamAdapter(stream);
            _settings   = settings; // already frozen by base class
            _maxDocumentSizeStack.Push(_settings.MaxDocumentSize);

            _context = null;
            State    = BsonWriterState.Initial;
        }
Exemple #39
0
        /// <summary>
        /// Initializes a new instance of the BsonBinaryWriter class.
        /// </summary>
        /// <param name="stream">A stream.</param>
        /// <param name="buffer">A BsonBuffer.</param>
        /// <param name="settings">Optional BsonBinaryWriter settings.</param>
        public BsonBinaryWriter(
            Stream stream,
            BsonBuffer buffer,
            BsonBinaryWriterSettings settings
            )
        {
            this.stream = stream;
            if (buffer == null)
            {
                this.buffer        = new BsonBuffer();
                this.disposeBuffer = true; // only call Dispose if we allocated the buffer
            }
            else
            {
                this.buffer        = buffer;
                this.disposeBuffer = false;
            }
            this.settings = settings.Freeze();

            context = null;
            state   = BsonWriterState.Initial;
        }
Exemple #40
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the BsonBinaryWriter class.
 /// </summary>
 /// <param name="stream">A stream.</param>
 /// <param name="buffer">A BsonBuffer.</param>
 /// <param name="settings">Optional BsonBinaryWriter settings.</param>
 public BsonBinaryWriter(Stream stream, BsonBuffer buffer, BsonBinaryWriterSettings settings)
     : this(buffer ?? new BsonBuffer(), buffer == null, settings)
 {
     _stream = stream;
 }