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


C# BsonDocument.InsertAt方法代码示例

本文整理汇总了C#中BsonDocument.InsertAt方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.InsertAt方法的具体用法?C# BsonDocument.InsertAt怎么用?C# BsonDocument.InsertAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BsonDocument的用法示例。


在下文中一共展示了BsonDocument.InsertAt方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AckSend

        public void AckSend()
        {
            var messageOne = new BsonDocument { { "key1", 0 }, { "key2", true } };
            var messageThree = new BsonDocument { { "hi", "there" }, { "rawr", 2 } };

            queue.Send(messageOne);
            queue.Send(new BsonDocument("key", "value"));

            var resultOne = queue.Get(new QueryDocument(messageOne), TimeSpan.MaxValue, TimeSpan.Zero);
            Assert.AreEqual(2, collection.Count());

            queue.AckSend(resultOne, messageThree);
            Assert.AreEqual(2, collection.Count());

            var actual = queue.Get(new QueryDocument("hi", "there"), TimeSpan.MaxValue, TimeSpan.Zero);
            messageThree.InsertAt(0, new BsonElement("id", resultOne["id"]));
            Assert.AreEqual(messageThree, actual);
        }
开发者ID:nubs,项目名称:mongo-queue-csharp,代码行数:18,代码来源:QueueTests.cs

示例2: ReplacePropertyPrefixes

        void ReplacePropertyPrefixes(BsonDocument doc, string prefixToReplace, string replacement)
        {
            foreach (var property in doc.ToList())
            {
                if (property.Name.StartsWith(prefixToReplace))
                {
                    doc.Remove(property.Name);

                    // since we know that it's most likely just about JSON.NET's $type property, we ensure that the replaced element gets to be first (which is required by JSON.NET)
                    doc.InsertAt(0, new BsonElement(replacement + property.Name.Substring(prefixToReplace.Length), property.Value));
                }

                if (property.Value.IsBsonDocument)
                {
                    ReplacePropertyPrefixes(property.Value.AsBsonDocument, prefixToReplace, replacement);
                    continue;
                }

                if (property.Value.IsBsonArray)
                {
                    foreach (var bsonValue in property.Value.AsBsonArray)
                    {
                        if (bsonValue.IsBsonDocument)
                        {
                            ReplacePropertyPrefixes(bsonValue.AsBsonDocument, prefixToReplace, replacement);
                        }
                    }
                }
            }
        }
开发者ID:linearregression,项目名称:Cirqus,代码行数:30,代码来源:MongoDbEventStore.cs

示例3: Send

        public void Send()
        {
            var now = DateTime.Now;

            var payload = new BsonDocument { { "key1", 0 }, { "key2", true } };
            queue.Send(payload, now, 0.8);

            var expected = new BsonDocument
            {
                //_id added below
                { "payload", payload },
                { "running", false },
                { "resetTimestamp", new BsonDateTime(DateTime.MaxValue) },
                { "earliestGet", new BsonDateTime(now) },
                { "priority", 0.8 },
                //created added below
            };

            var message = collection.FindOneAs<BsonDocument>();

            var actualCreated = message["created"];
            expected["created"] = actualCreated;
            actualCreated = actualCreated.AsDateTime;

            Assert.IsTrue(actualCreated <= DateTime.UtcNow);
            Assert.IsTrue(actualCreated > DateTime.UtcNow - TimeSpan.FromSeconds(10));

            expected.InsertAt(0, new BsonElement("_id", message["_id"]));
            Assert.AreEqual(expected, message);
        }
开发者ID:nubs,项目名称:mongo-queue-csharp,代码行数:30,代码来源:QueueTests.cs

示例4: GetWithTimeBasedPriority

        public void GetWithTimeBasedPriority()
        {
            var messageOne = new BsonDocument { { "key", 0 } };
            var messageTwo = new BsonDocument { { "key", 1 } };
            var messageThree = new BsonDocument { { "key", 2 } };

            queue.Send(messageOne);
            queue.Send(messageTwo);
            queue.Send(messageThree);

            var resultOne = queue.Get(new QueryDocument(), TimeSpan.MaxValue);
            var resultTwo = queue.Get(new QueryDocument(), TimeSpan.MaxValue);
            var resultThree = queue.Get(new QueryDocument(), TimeSpan.MaxValue);

            messageOne.InsertAt(0, new BsonElement("id", resultOne["id"]));
            messageTwo.InsertAt(0, new BsonElement("id", resultTwo["id"]));
            messageThree.InsertAt(0, new BsonElement("id", resultThree["id"]));

            Assert.AreEqual(messageOne, resultOne);
            Assert.AreEqual(messageTwo, resultTwo);
            Assert.AreEqual(messageThree, resultThree);
        }
开发者ID:nubs,项目名称:mongo-queue-csharp,代码行数:22,代码来源:QueueTests.cs

示例5: GetBySubDocQuery

        public void GetBySubDocQuery()
        {
            var messageTwo = new BsonDocument
            {
                {
                    "one",
                    new BsonDocument
                    {
                        { "two", new BsonDocument { { "three", 5 }, { "notused", "notused" } } },
                        { "notused", "notused" },
                    }
                },
                { "notused", "notused" },
            };

            queue.Send(new BsonDocument { { "key1", 0 }, { "key2", true } });
            queue.Send(messageTwo);

            var result = queue.Get(new QueryDocument("one.two.three", new BsonDocument("$gt", 4)), TimeSpan.MaxValue, TimeSpan.Zero);

            messageTwo.InsertAt(0, new BsonElement("id", result["id"]));
            Assert.AreEqual(messageTwo, result);
        }
开发者ID:nubs,项目名称:mongo-queue-csharp,代码行数:23,代码来源:QueueTests.cs

示例6: TestInsertAt

 public void TestInsertAt()
 {
     var document = new BsonDocument();
     document.InsertAt(0, new BsonElement("x", 1));
     Assert.AreEqual("x", document.GetElement(0).Name);
     Assert.AreEqual(1, document[0].AsInt32);
     document.InsertAt(0, new BsonElement("y", 2));
     Assert.AreEqual("y", document.GetElement(0).Name);
     Assert.AreEqual(2, document[0].AsInt32);
     Assert.AreEqual("x", document.GetElement(1).Name);
     Assert.AreEqual(1, document[1].AsInt32);
 }
开发者ID:jijamw,项目名称:mongo-csharp-driver,代码行数:12,代码来源:BsonDocumentTests.cs

示例7: TranslateMapping

        private BsonValue TranslateMapping(ProjectionMapping mapping)
        {
            BsonDocument doc = new BsonDocument();
            bool hasId = false;
            foreach (var memberMapping in mapping.Members)
            {
                var value = TranslateValue(memberMapping.Expression);
                string name = memberMapping.Member.Name;
                if (!hasId && memberMapping.Expression is GroupingKeyExpression)
                {
                    name = "_id";
                    hasId = true;
                    doc.InsertAt(0, new BsonElement(name, value));
                }
                else
                {
                    doc.Add(name, value);
                }
            }

            return doc;
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:22,代码来源:AggregateLanguageTranslator.cs

示例8: Send

        public void Send()
        {
            var now = DateTime.Now;

            var payload = new BsonDocument { { "key1", 0 }, { "key2", true } };

            using (var streamOne = new MemoryStream())
            using (var streamTwo = new MemoryStream())
            {
                gridfs.Upload(streamOne, "one");//making sure same file names are ok as long as their ids are diffrent

                streamOne.WriteByte(111);
                streamTwo.WriteByte(222);
                streamOne.Position = 0;
                streamTwo.Position = 0;
                queue.Send(payload, now, 0.8, new Dictionary<string, Stream>{ { "one", streamOne }, { "two", streamTwo } });
            }

            var expected = new BsonDocument
            {
                //_id added below
                { "payload", payload },
                { "running", false },
                { "resetTimestamp", new BsonDateTime(DateTime.MaxValue) },
                { "earliestGet", new BsonDateTime(now) },
                { "priority", 0.8 },
                //streams added below
                //created added below
            };

            var message = collection.FindOneAs<BsonDocument>();

            var actualCreated = message["created"];
            expected["created"] = actualCreated;
            actualCreated = actualCreated.ToUniversalTime();

            var actualStreamIds = message["streams"].AsBsonArray;
            expected["streams"] = actualStreamIds;

            Assert.IsTrue(actualCreated <= DateTime.UtcNow);
            Assert.IsTrue(actualCreated > DateTime.UtcNow - TimeSpan.FromSeconds(10));

            expected.InsertAt(0, new BsonElement("_id", message["_id"]));
            Assert.AreEqual(expected, message);

            var fileOne = gridfs.FindOneById(actualStreamIds[0]);
            Assert.AreEqual("one", fileOne.Name);
            using (var stream = fileOne.OpenRead())
                Assert.AreEqual(111, stream.ReadByte());

            var fileTwo = gridfs.FindOneById(actualStreamIds[1]);
            Assert.AreEqual("two", fileTwo.Name);
            using (var stream = fileTwo.OpenRead())
                Assert.AreEqual(222, stream.ReadByte());
        }
开发者ID:cihanozhan,项目名称:mongo-queue-csharp,代码行数:55,代码来源:QueueTests.cs


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