當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。