當前位置: 首頁>>代碼示例>>C#>>正文


C# Bson.BsonDocumentWrapper類代碼示例

本文整理匯總了C#中MongoDB.Bson.BsonDocumentWrapper的典型用法代碼示例。如果您正苦於以下問題:C# BsonDocumentWrapper類的具體用法?C# BsonDocumentWrapper怎麽用?C# BsonDocumentWrapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BsonDocumentWrapper類屬於MongoDB.Bson命名空間,在下文中一共展示了BsonDocumentWrapper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SaveRequestData

        public static void SaveRequestData(HttpContextBase context)
        {
            var url = context.Request.Url.ToString();

            var data = new BsonDocumentWrapper(new
            {
                //_id = ObjectId.GenerateNewId(),
                at = DateTime.UtcNow,
                url,
                method = context.Request.HttpMethod,
                headers = From(context.Request.Headers),
                clientIp = context.Request.UserHostAddress
            }).ToBsonDocument();
            if (context.Request.Form.Count > 0)
            {
                data.Add("form", From(context.Request.Form));
            }
            var cookies = From(context.Response.Cookies);
            if (cookies.Length > 0)
                data.Add("cookies", BsonArray.Create((IEnumerable)cookies));
            var referrer = context.Request.UrlReferrer;
            if (referrer != null)
                data.Add("referrer", referrer.ToString());

            try
            {
                DB.Database.GetCollection("requestsLog").Insert(data);
            }
            catch
            {
            }
        }
開發者ID:lgadi,項目名稱:ZeeBi,代碼行數:32,代碼來源:RequestsLog.cs

示例2: TestAddNameValue

 public void TestAddNameValue()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument());
     Assert.AreEqual(false, wrapper.IsMaterialized);
     wrapper.Add("x", 1);
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreEqual(1, wrapper.ElementCount);
     Assert.AreEqual("x", wrapper.GetElement(0).Name);
     Assert.AreEqual(new BsonInt32(1), wrapper[0]);
 }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:10,代碼來源:BsonDocumentWrapperTests.cs

示例3: MongoQueryMessage

 internal MongoQueryMessage(
     string collectionFullName,
     QueryFlags flags,
     int numberToSkip,
     int numberToReturn,
     object query,
     BsonDocumentWrapper fields
 )
     : this(collectionFullName, flags, numberToSkip, numberToReturn, query, fields, null)
 {
 }
開發者ID:kenegozi,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:MongoQueryMessage.cs

示例4: CreateProtocol

 //  methods
 protected override IWireProtocol<BsonDocument> CreateProtocol(IConnectionHandle connection, WriteRequest request)
 {
     var insertRequest = (InsertRequest)request;
     var wrapper = new BsonDocumentWrapper(insertRequest.Document, insertRequest.Serializer);
     var documentSource = new BatchableSource<BsonDocument>(new[] { wrapper });
     return new InsertWireProtocol<BsonDocument>(
         DatabaseName,
         CollectionName,
         WriteConcern,
         BsonDocumentSerializer.Instance,
         documentSource,
         connection.Description.MaxBatchCount,
         connection.Description.MaxMessageSize,
         continueOnError: false);               
 }
開發者ID:Nakro,項目名稱:mongo-csharp-driver,代碼行數:16,代碼來源:BulkInsertOperationEmulator.cs

示例5: TestTryGetValue

 public void TestTryGetValue()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
     Assert.AreEqual(false, wrapper.IsMaterialized);
     BsonValue value;
     var result = wrapper.TryGetValue("x", out value);
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreEqual(true, result);
     Assert.AreEqual(new BsonInt32(1), value);
 }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:10,代碼來源:BsonDocumentWrapperTests.cs

示例6: TestTryGetElement

 public void TestTryGetElement()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
     Assert.AreEqual(false, wrapper.IsMaterialized);
     BsonElement element;
     var result = wrapper.TryGetElement("x", out element);
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreEqual(true, result);
     Assert.AreEqual("x", element.Name);
     Assert.AreEqual(new BsonInt32(1), element.Value);
 }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:BsonDocumentWrapperTests.cs

示例7: TestToString

 public void TestToString()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
     Assert.AreEqual(false, wrapper.IsMaterialized);
     var expected = "{ 'x' : 1 }".Replace("'", "\"");
     var s = wrapper.ToString();
     Assert.AreEqual(false, wrapper.IsMaterialized); // ToString just serializes, doesn't materialize
     Assert.AreEqual(expected, s);
 }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:9,代碼來源:BsonDocumentWrapperTests.cs

示例8: TestGetValueByName

 public void TestGetValueByName()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
     Assert.AreEqual(false, wrapper.IsMaterialized);
     var value = wrapper.GetValue("x");
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreEqual(new BsonInt32(1), value);
 }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:8,代碼來源:BsonDocumentWrapperTests.cs

示例9: TestConstructorWithNullNominalTypeAndObjectAndIsUpdateDocument

 public void TestConstructorWithNullNominalTypeAndObjectAndIsUpdateDocument()
 {
     Assert.Throws<ArgumentNullException>(() => { var wrapper = new BsonDocumentWrapper(null, _c, false); });
 }
開發者ID:CloudMetal,項目名稱:mongo-csharp-driver,代碼行數:4,代碼來源:BsonDocumentWrapperTests.cs

示例10: TestConstructorWithNominalTypeAndObject

 public void TestConstructorWithNominalTypeAndObject()
 {
     var wrapper = new BsonDocumentWrapper(typeof(C), _c);
     var expected = "{ \"X\" : 1 }";
     Assert.AreEqual(expected, wrapper.ToJson());
 }
開發者ID:CloudMetal,項目名稱:mongo-csharp-driver,代碼行數:6,代碼來源:BsonDocumentWrapperTests.cs

示例11: TestConstructorWithObject

 public void TestConstructorWithObject()
 {
     var wrapper = new BsonDocumentWrapper(_c);
     var expected = "{ \"X\" : 1 }";
     Assert.AreEqual(expected, wrapper.ToJson());
 }
開發者ID:CloudMetal,項目名稱:mongo-csharp-driver,代碼行數:6,代碼來源:BsonDocumentWrapperTests.cs

示例12: TestRawValues

        public void TestRawValues()
        {
#pragma warning disable 618
            var wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            var values = wrapper.RawValues.ToArray();
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(0, values.Length);

            wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
            Assert.AreEqual(false, wrapper.IsMaterialized);
            values = wrapper.RawValues.ToArray();
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, values.Length);
            Assert.AreEqual(1, values[0]);
#pragma warning restore
        }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:17,代碼來源:BsonDocumentWrapperTests.cs

示例13: TestNames

        public void TestNames()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            var names = wrapper.Names.ToArray();
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(0, names.Length);

            wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
            Assert.AreEqual(false, wrapper.IsMaterialized);
            names = wrapper.Names.ToArray();
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, names.Length);
            Assert.AreEqual("x", names[0]);
        }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:15,代碼來源:BsonDocumentWrapperTests.cs

示例14: TestMergeOverwrite

 public void TestMergeOverwrite()
 {
     var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
     Assert.AreEqual(false, wrapper.IsMaterialized);
     var result = wrapper.Merge(new BsonDocument("x", 2), true);
     Assert.AreEqual(true, wrapper.IsMaterialized);
     Assert.AreSame(wrapper, result);
     Assert.AreEqual(1, wrapper.ElementCount);
     Assert.AreEqual("x", wrapper.GetElement(0).Name);
     Assert.AreEqual(new BsonInt32(2), wrapper[0]);
 }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:BsonDocumentWrapperTests.cs

示例15: TestIndexerByName

        public void TestIndexerByName()
        {
            var wrapper = new BsonDocumentWrapper(new BsonDocument("x", 1));
            Assert.AreEqual(false, wrapper.IsMaterialized);
            var value = wrapper["x"];
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(new BsonInt32(1), value);

            wrapper = new BsonDocumentWrapper(new BsonDocument());
            Assert.AreEqual(false, wrapper.IsMaterialized);
            wrapper["x"] = 1;
            Assert.AreEqual(true, wrapper.IsMaterialized);
            Assert.AreEqual(1, wrapper.ElementCount);
            Assert.AreEqual("x", wrapper.GetElement(0).Name);
            Assert.AreEqual(new BsonInt32(1), wrapper[0]);
        }
開發者ID:rakesh-elevate,項目名稱:mongo-csharp-driver,代碼行數:16,代碼來源:BsonDocumentWrapperTests.cs


注:本文中的MongoDB.Bson.BsonDocumentWrapper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。