当前位置: 首页>>代码示例>>C#>>正文


C# IO.BsonBuffer类代码示例

本文整理汇总了C#中MongoDB.Bson.IO.BsonBuffer的典型用法代码示例。如果您正苦于以下问题:C# BsonBuffer类的具体用法?C# BsonBuffer怎么用?C# BsonBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BsonBuffer类属于MongoDB.Bson.IO命名空间,在下文中一共展示了BsonBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteBodyTo

        // internal methods
        internal override void WriteBodyTo(BsonBuffer buffer)
        {
            var processedRequests = new List<InsertRequest>();

            var continuationBatch = _batch as ContinuationBatch<InsertRequest, byte[]>;
            if (continuationBatch != null)
            {
                AddOverflow(buffer, continuationBatch.PendingState);
                processedRequests.Add(continuationBatch.PendingItem);
                continuationBatch.ClearPending(); // so pending objects can be garbage collected sooner
            }

            // always go one document too far so that we can set IsDone as early as possible
            var enumerator = _batch.Enumerator;
            while (enumerator.MoveNext())
            {
                var request = enumerator.Current;
                AddRequest(buffer, request);

                if ((_batchCount > _maxBatchCount || _batchLength > _maxBatchLength) && _batchCount > 1)
                {
                    var serializedDocument = RemoveLastDocument(buffer);
                    var nextBatch = new ContinuationBatch<InsertRequest, byte[]>(enumerator, request, serializedDocument);
                    _batchProgress = new BatchProgress<InsertRequest>(_batchCount, _batchLength, processedRequests, nextBatch);
                    return;
                }

                processedRequests.Add(request);
            }

            _batchProgress = new BatchProgress<InsertRequest>(_batchCount, _batchLength, processedRequests, null);
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:33,代码来源:MongoInsertMessage.cs

示例2: Execute

        // public methods
        public WriteConcernResult Execute(MongoConnection connection)
        {
            var serverInstance = connection.ServerInstance;
            if (serverInstance.Supports(FeatureId.WriteCommands) && _args.WriteConcern.Enabled)
            {
                var emulator = new UpdateOpcodeOperationEmulator(_args);
                return emulator.Execute(connection);
            }

            SendMessageWithWriteConcernResult sendMessageResult;
            using (var buffer = new BsonBuffer(new MultiChunkBuffer(BsonChunkPool.Default), true))
            {
                var requests = _args.Requests.ToList();
                if (requests.Count != 1)
                {
                    throw new NotSupportedException("Update opcode only supports a single update request.");
                }
                var updateRequest = (UpdateRequest)requests[0];

                var flags = UpdateFlags.None;
                if (updateRequest.IsMultiUpdate ?? false) { flags |= UpdateFlags.Multi; }
                if (updateRequest.IsUpsert ?? false) { flags |= UpdateFlags.Upsert; }

                var maxDocumentSize = connection.ServerInstance.MaxDocumentSize;
                var query = updateRequest.Query ?? new QueryDocument();

                var message = new MongoUpdateMessage(WriterSettings, CollectionFullName, _args.CheckElementNames, flags, maxDocumentSize, query, updateRequest.Update);
                message.WriteTo(buffer);

                sendMessageResult =  SendMessageWithWriteConcern(connection, buffer, message.RequestId, ReaderSettings, WriterSettings, WriteConcern);
            }

            return WriteConcern.Enabled ? ReadWriteConcernResult(connection, sendMessageResult) : null;
        }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:35,代码来源:UpdateOpcodeOperation.cs

示例3: WriteHeaderTo

 internal virtual void WriteHeaderTo(BsonBuffer buffer)
 {
     buffer.WriteInt32(0); // messageLength will be backpatched later
     buffer.WriteInt32(_requestId);
     buffer.WriteInt32(0); // responseTo not used in requests sent by client
     buffer.WriteInt32((int)_opcode);
 }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:7,代码来源:MongoMessage.cs

示例4: Create

 public static BsonWriter Create(
     BsonBuffer buffer,
     BsonBinaryWriterSettings settings
 )
 {
     return new BsonBinaryWriter(null, buffer, settings);
 }
开发者ID:kenegozi,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonWriter.cs

示例5: WriteBody

 // protected methods
 protected override void WriteBody(BsonBuffer buffer)
 {
     buffer.WriteInt32(0); // reserved
     buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName);
     buffer.WriteInt32(_numberToReturn);
     buffer.WriteInt64(_cursorId);
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:8,代码来源:MongoGetMoreMessage.cs

示例6: WriteBody

 // protected methods
 protected override void WriteBody(BsonBuffer buffer)
 {
     buffer.WriteInt32((int)_flags);
     buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName);
     _firstDocumentStartPosition = buffer.Position;
     // documents to be added later by calling AddDocument
 }
开发者ID:pwelter34,项目名称:mongo-csharp-driver,代码行数:8,代码来源:MongoInsertMessage.cs

示例7: ResetBatch

 internal void ResetBatch(BsonBuffer buffer, byte[] lastDocument)
 {
     buffer.Position = _firstDocumentStartPosition;
     buffer.Length = _firstDocumentStartPosition;
     buffer.WriteBytes(lastDocument);
     BackpatchMessageLength(buffer);
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoInsertMessage.cs

示例8: Create

 public static BsonReader Create(
     BsonBuffer buffer,
     BsonBinaryReaderSettings settings
 )
 {
     return new BsonBinaryReader(buffer, settings);
 }
开发者ID:kolupaev,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonReader.cs

示例9: WriteHeaderTo

 internal override void WriteHeaderTo(BsonBuffer buffer)
 {
     base.WriteHeaderTo(buffer);
     buffer.WriteInt32(0); // reserved
     buffer.WriteCString(new UTF8Encoding(false, true), _collectionFullName);
     buffer.WriteInt32(_numberToReturn);
 }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:7,代码来源:MongoGetMoreMessage.cs

示例10: Test20KDocument

        public void Test20KDocument()
        {
            // manufacture an approximately 20K document using 200 strings each 100 characters long
            // it's enough to cause the document to straddle a chunk boundary
            var document = new BsonDocument();
            var value = new string('x', 100);
            for (int i = 0; i < 200; i++)
            {
                var name = i.ToString();
                document.Add(name, value);
            }

            // round trip tests
            var bson = document.ToBson();
            var rehydrated = BsonSerializer.Deserialize<BsonDocument>(bson);
            Assert.IsTrue(bson.SequenceEqual(rehydrated.ToBson()));

            // test failure mode when 20 bytes are truncated from the buffer
            using (var buffer = new BsonBuffer())
            {
                buffer.LoadFrom(new MemoryStream(bson));
                buffer.Length -= 20;
                using (var bsonReader = BsonReader.Create(buffer))
                {
                    Assert.Throws<EndOfStreamException>(() => BsonSerializer.Deserialize<BsonDocument>(bsonReader));
                }
            }
        }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:28,代码来源:CSharp71Tests.cs

示例11: WriteMessageHeaderTo

 protected void WriteMessageHeaderTo(
     BsonBuffer buffer
 ) {
     buffer.WriteInt32(0); // messageLength will be backpatched later
     buffer.WriteInt32(requestId);
     buffer.WriteInt32(0); // responseTo not used in requests sent by client
     buffer.WriteInt32((int) opcode);
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:8,代码来源:MongoMessage.cs

示例12: WriteBodyTo

 // internal methods
 internal override void WriteBodyTo(BsonBuffer buffer)
 {
     buffer.WriteInt32(_cursorIds.Length);
     foreach (long cursorId in _cursorIds)
     {
         buffer.WriteInt64(cursorId);
     }
 }
开发者ID:ExM,项目名称:mongo-csharp-driver,代码行数:9,代码来源:MongoKillCursorsMessage.cs

示例13: BsonBinaryReader

 public BsonBinaryReader(
     BsonBuffer buffer,
     BsonBinaryReaderSettings settings
 ) {
     this.buffer = buffer ?? new BsonBuffer();
     this.disposeBuffer = buffer == null; // only call Dispose if we allocated the buffer
     this.settings = settings;
     context = null;
 }
开发者ID:swiggin1,项目名称:mongo-csharp-driver,代码行数:9,代码来源:BsonBinaryReader.cs

示例14: WriteBody

 // protected methods
 protected override void WriteBody(BsonBuffer buffer)
 {
     buffer.WriteInt32(0); // reserved
     buffer.WriteInt32(_cursorIds.Length);
     foreach (long cursorId in _cursorIds)
     {
         buffer.WriteInt64(cursorId);
     }
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:10,代码来源:MongoKillCursorsMessage.cs

示例15: RemoveLastDocument

 internal byte[] RemoveLastDocument(BsonBuffer buffer)
 {
     var lastDocumentLength = buffer.Position - _lastDocumentStartPosition;
     buffer.Position = _lastDocumentStartPosition;
     var lastDocument = buffer.ReadBytes(lastDocumentLength);
     buffer.Length = _lastDocumentStartPosition;
     BackpatchMessageLength(buffer);
     return lastDocument;
 }
开发者ID:pwelter34,项目名称:mongo-csharp-driver,代码行数:9,代码来源:MongoInsertMessage.cs


注:本文中的MongoDB.Bson.IO.BsonBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。