• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IO.BsonBuffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: MongoQueryMessage

 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;
 }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:10,代码来源:MongoQueryMessage.cs


示例17: AddDocument

 // internal methods
 internal void AddDocument(BsonBuffer buffer, Type nominalType, object document)
 {
     _lastDocumentStartPosition = buffer.Position;
     using (var bsonWriter = new BsonBinaryWriter(buffer, false, WriterSettings))
     {
         bsonWriter.CheckElementNames = _checkElementNames;
         BsonSerializer.Serialize(bsonWriter, nominalType, document, DocumentSerializationOptions.SerializeIdFirstInstance);
     }
     BackpatchMessageLength(buffer);
 }
开发者ID:pwelter34,项目名称:mongo-csharp-driver,代码行数:11,代码来源:MongoInsertMessage.cs


示例18: ReadHeaderFrom

 // internal methods
 internal virtual void ReadHeaderFrom(BsonBuffer buffer)
 {
     _messageLength = buffer.ReadInt32();
     _requestId = buffer.ReadInt32();
     _responseTo = buffer.ReadInt32();
     if ((MessageOpcode)buffer.ReadInt32() != _opcode)
     {
         throw new FileFormatException("Message header opcode is not the expected one.");
     }
 }
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:11,代码来源:MongoMessage.cs


示例19: ReadMessageHeaderFrom

 // protected methods
 protected void ReadMessageHeaderFrom(BsonBuffer buffer)
 {
     messageLength = buffer.ReadInt32();
     requestId = buffer.ReadInt32();
     responseTo = buffer.ReadInt32();
     if ((MessageOpcode)buffer.ReadInt32() != opcode)
     {
         throw new FileFormatException("Message header opcode is not the expected one.");
     }
 }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:11,代码来源:MongoMessage.cs


示例20: TestBenchmarks

        public void TestBenchmarks()
        {
            int iterations;
            DateTime start;
            DateTime end;
            TimeSpan duration;

            iterations = 1;
            start = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++)
            {
                // about 2.06 on my machine
                //var doc = new BsonDocument {
                //    { "a", 1 },
                //    { "b", 2.0 },
                //    { "c", "hello" },
                //    { "d", DateTime.UtcNow },
                //    { "e", true }
                // };
                byte[] value = { 1, 2, 3, 4 };
                MemoryStream stream = new MemoryStream();
                for (int n = 0; n < 100000; n++)
                {
                    stream.Write(value, 0, 4);
                }
            }
            end = DateTime.UtcNow;
            duration = end - start;
            System.Diagnostics.Debug.WriteLine(duration);

            start = DateTime.UtcNow;
            for (int i = 0; i < iterations; i++)
            {
                // about 2.22 on my machine
                //var doc = new BsonDocument {
                //    { "a", BsonValue.Create((object) 1) },
                //    { "b", BsonValue.Create((object) 2.0) },
                //    { "c", BsonValue.Create((object) "hello") },
                //    { "d", BsonValue.Create((object) DateTime.UtcNow) },
                //    { "e", BsonValue.Create((object) true) }
                //};
                byte[] value = { 1, 2, 3, 4 };
                using (var buffer = new BsonBuffer())
                {
                    for (int n = 0; n < 100000; n++)
                    {
                        buffer.WriteBytes(value);
                    }
                }
            }
            end = DateTime.UtcNow;
            duration = end - start;
            System.Diagnostics.Debug.WriteLine(duration);
        }
开发者ID:purplecow,项目名称:mongo-csharp-driver,代码行数:54,代码来源:BsonDocumentTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.BsonDocumentWriter类代码示例发布时间:2022-05-26
下一篇:
C# IO.BsonBinaryWriterSettings类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap