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

C# BSONDocument类代码示例

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

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



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

示例1: UpdateEntry

 public UpdateEntry(BSONDocument query, BSONDocument update, bool multi, bool upsert)
 {
   Query  = query;
   Update = update;
   Multi  = multi;
   Upsert = upsert;
 }
开发者ID:vlapchenko,项目名称:nfx,代码行数:7,代码来源:CRUDObjects.cs


示例2: btnCreateIndex_Click

        private void btnCreateIndex_Click(object sender, EventArgs e)
        {
            var db = MongoClient.Instance.DefaultLocalServer["db1"];

            var idx = new BSONDocument(@"
              {
               createIndexes: 't1',
            indexes: [
              {
                key: {name: 1},
                name: 'idxT1_Name',
                unique: false
              },
              {
                key: {age: -11},
                name: 'idxT1_Age',
                unique: false
              }
            ]
              }

            ",false);

            MessageBox.Show( db.RunCommand( idx ).ToString() );
        }
开发者ID:itadapter,项目名称:nfx,代码行数:25,代码来源:MongoConnectorForm.cs


示例3: InferSchema

        public void InferSchema()
        {
            var doc = new BSONDocument();
            doc.Set( new BSONStringElement("FullName", "Alex Bobby") );
            doc.Set( new BSONInt32Element("Age", 123) );
            doc.Set( new BSONBooleanElement("IsGood", true) );

            var c = new RowConverter();

            var schema = c.InferSchemaFromBSONDocument(doc);

            Assert.AreEqual(3, schema.FieldCount);

            Assert.AreEqual(0, schema["FullName"].Order);
            Assert.AreEqual(1, schema["Age"].Order);
            Assert.AreEqual(2, schema["IsGood"].Order);

            Assert.AreEqual(typeof(object), schema["FullName"].NonNullableType);
            Assert.AreEqual(typeof(object), schema["Age"].NonNullableType);
            Assert.AreEqual(typeof(object), schema["IsGood"].NonNullableType);

            var row = new DynamicRow(schema);
            c.BSONDocumentToRow(doc, row, null);

            Assert.AreEqual("Alex Bobby", row[0]);
            Assert.AreEqual(123,          row[1]);
            Assert.AreEqual(true,         row[2]);

            Assert.AreEqual("Alex Bobby", row["FullName"]);
            Assert.AreEqual(123,          row["Age"]);
            Assert.AreEqual(true,         row["IsGood"]);
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:32,代码来源:RowConverterTest.cs


示例4: TestFilteredDoc

 public void TestFilteredDoc()
 {
     var doc = new BSONDocument();
     doc["c"] = "d";
     doc["aaa"] = 11;
     doc["ndoc"] = BSONDocument.ValueOf(new {
         aaaa = "nv1",
         d = "nv2",
         nnd = BSONDocument.ValueOf(new {
             nnv = true,
             nns = "s"
         })
     });
     doc["ndoc2"] = BSONDocument.ValueOf(new {
         n = "v"
     });
     doc["f"] = "f";
     BSONIterator it = new BSONIterator(doc);
     BSONDocument doc2 = it.ToBSONDocument("c", "ndoc.d", "ndoc.nnd.nns", "f");
     Assert.AreEqual(3, doc2.KeysCount);
     Assert.AreEqual("d", doc2["c"]);
     Assert.AreEqual(2, ((BSONDocument) doc2["ndoc"]).KeysCount);
     Assert.AreEqual("nv2", ((BSONDocument) doc2["ndoc"])["d"]);
     Assert.AreEqual("s", ((BSONDocument) ((BSONDocument) doc2["ndoc"])["nnd"])["nns"]);
     Assert.AreEqual("s", doc2["ndoc.nnd.nns"]);
     Assert.AreEqual("f", "f");
     //Console.WriteLine("doc2=" + doc2);
 }
开发者ID:rayleyva,项目名称:ejdb,代码行数:28,代码来源:TestBSON.cs


示例5: Test3SaveLoad

        public void Test3SaveLoad()
        {
            EJDB jb = new EJDB("testdb1", EJDB.DEFAULT_OPEN_MODE | EJDB.JBOTRUNC);
            Assert.IsTrue(jb.IsOpen);
            BSONDocument doc = new BSONDocument().SetNumber("age", 33);
            Assert.IsNull(doc["_id"]);
            bool rv = jb.Save("mycoll", doc);
            Assert.IsTrue(rv);
            Assert.IsNotNull(doc["_id"]);
            Assert.IsInstanceOf(typeof(BSONOid), doc["_id"]);
            rv = jb.Save("mycoll", doc);
            Assert.IsTrue(rv);

            BSONIterator it = jb.Load("mycoll", doc["_id"] as BSONOid);
            Assert.IsNotNull(it);

            BSONDocument doc2 = it.ToBSONDocument();
            Assert.AreEqual(doc.ToDebugDataString(), doc2.ToDebugDataString());
            Assert.IsTrue(doc == doc2);

            Assert.AreEqual(1, jb.CreateQueryFor("mycoll").Count());
            Assert.IsTrue(jb.Remove("mycoll", doc["_id"] as BSONOid));
            Assert.AreEqual(0, jb.CreateQueryFor("mycoll").Count());

            jb.Save("mycoll", doc);
            Assert.AreEqual(1, jb.CreateQueryFor("mycoll").Count());
            Assert.IsTrue(jb.DropCollection("mycoll"));
            Assert.AreEqual(0, jb.CreateQueryFor("mycoll").Count());

            Assert.IsTrue(jb.Sync());
            jb.Dispose();
        }
开发者ID:JulianLiu,项目名称:ejdb,代码行数:32,代码来源:TestEJDB.cs


示例6: EJDBQuery

 internal EJDBQuery(EJDB jb, BSONDocument qdoc, string defaultcollection = null)
 {
     _qptr = _ejdbcreatequery(jb.DBPtr, qdoc.ToByteArray());
     if (_qptr == IntPtr.Zero) {
         throw new EJDBQueryException(jb);
     }
     _jb = jb;
     _defaultcollection = defaultcollection;
 }
开发者ID:JulianLiu,项目名称:ejdb,代码行数:9,代码来源:EJDBQuery.cs


示例7: WriteBigIntegers

 public void WriteBigIntegers(Stream stream)
 {
     stream.Position = 0;
       var root = new BSONDocument();
       root.Set(new BSONInt32Element("intMin", int.MinValue));
       root.Set(new BSONInt32Element("intMax", int.MaxValue));
       root.Set(new BSONInt64Element("longMin", long.MinValue));
       root.Set(new BSONInt64Element("longMax", long.MaxValue));
       root.WriteAsBSON(stream);
 }
开发者ID:vlapchenko,项目名称:nfx,代码行数:10,代码来源:BSONTestForm.cs


示例8: ReadEmptyDocument

        public void ReadEmptyDocument()
        {
            var src = Convert.FromBase64String(@"BQAAAAA=");

              using (var stream = new MemoryStream(src))
              {
            var root = new BSONDocument(stream);

            Assert.AreEqual(root.ByteSize, 5);
            Assert.AreEqual(root.Count, 0);
            Assert.AreEqual(stream.Position, 5); // ensure whole document readed
              }
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:13,代码来源:BSON.cs


示例9: FindOne

        /// <summary>
        /// Finds a document that satisfied query or null
        /// </summary>
        public BSONDocument FindOne(Query query, BSONDocument selector = null)
        {
          EnsureObjectNotDisposed();

          if (query==null)
           throw new MongoDBConnectorException(StringConsts.ARGUMENT_ERROR+"Collection.FindOne(query==null)");

          var connection = Server.AcquireConnection();
          try
          {
            var reqId = Database.NextRequestID;
            return connection.FindOne(reqId, this, query, selector);
          }
          finally
          {
            connection.Release();
          }
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:21,代码来源:Collection.cs


示例10: CollectionDrop

        public void CollectionDrop()
        {
            using(var client= new MongoClient("My Test"))
              {
            var collection = client.DefaultLocalServer["db1"]["ToDrop"];
            var doc1 = new BSONDocument();

            doc1.Set( new BSONStringElement("_id", "id1"))
            .Set( new BSONStringElement("val", "My value"))
            .Set( new BSONInt32Element("age", 125));

            var r = collection.Insert(doc1);
            Assert.AreEqual(1, r.TotalDocumentsAffected);

            collection.Drop();
            Assert.IsTrue( collection.Disposed );
              }
        }
开发者ID:vlapchenko,项目名称:nfx,代码行数:18,代码来源:BasicConnectorFunctionality.cs


示例11: ReadBigIntegers

        public void ReadBigIntegers()
        {
            var src = Convert.FromBase64String(@"PwAAABBpbnRNaW4AAAAAgBBpbnRNYXgA////fxJsb25nTWluAAAAAAAAAACAEmxvbmdNYXgA/////////38A");

              using (var stream = new MemoryStream(src))
              {
            var root = new BSONDocument(stream);

            Assert.AreEqual(root.ByteSize, 63);
            Assert.AreEqual(root.Count, 4);

            var element1 = root["intMin"] as BSONInt32Element;
            Assert.IsNotNull(element1);
            Assert.AreEqual(element1.ElementType, BSONElementType.Int32);
            Assert.AreEqual(element1.Name, "intMin");
            Assert.AreEqual(element1.Value, int.MinValue);

            var element2 = root["intMax"] as BSONInt32Element;
            Assert.IsNotNull(element2);
            Assert.AreEqual(element2.ElementType, BSONElementType.Int32);
            Assert.AreEqual(element2.Name, "intMax");
            Assert.AreEqual(element2.Value, int.MaxValue);

            var element3 = root["longMin"] as BSONInt64Element;
            Assert.IsNotNull(element3);
            Assert.AreEqual(element3.ElementType, BSONElementType.Int64);
            Assert.AreEqual(element3.Name, "longMin");
            Assert.AreEqual(element3.Value, long.MinValue);

            var element4 = root["longMax"] as BSONInt64Element;
            Assert.IsNotNull(element4);
            Assert.AreEqual(element4.ElementType, BSONElementType.Int64);
            Assert.AreEqual(element4.Name, "longMax");
            Assert.AreEqual(element4.Value, long.MaxValue);

            Assert.AreEqual(stream.Position, 63); // ensure whole document readed
              }
        }
开发者ID:itadapter,项目名称:nfx,代码行数:38,代码来源:BSON.cs


示例12: ReadUnicodeStrings

        public void ReadUnicodeStrings()
        {
            var src = Convert.FromBase64String(@"6AAAAAJlbmcABgAAAGhlbGxvAAJydXMADQAAANC/0YDQuNCy0LXRggACY2hpAAcAAADkvaDlpb0AAmphcAAQAAAA44GT44KT44Gr44Gh44GvAAJncmUAEAAAAM6zzrXOuc6xIM+DzrHPggACYWxiAA8AAABww6tyc2jDq25kZXRqZQACYXJtABIAAADVotWh1oDVpdaCINWB1aXVpgACdmllAAoAAAB4aW4gY2jDoG8AAnBvcgAFAAAAT2zDoQACdWtyAA0AAADQn9GA0LjQstGW0YIAAmdlcgAJAAAAd8O8bnNjaGUAAA==");

              using (var stream = new MemoryStream(src))
              {
            var root = new BSONDocument(stream);

            Assert.AreEqual(root.ByteSize, 232);
            Assert.AreEqual(root.Count, 11);

            var element = root["eng"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "eng");
            Assert.AreEqual(element.Value, "hello");

            element = root["rus"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "rus");
            Assert.AreEqual(element.Value, "привет");

            element = root["chi"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "chi");
            Assert.AreEqual(element.Value, "你好");

            element = root["jap"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "jap");
            Assert.AreEqual(element.Value, "こんにちは");

            element = root["gre"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "gre");
            Assert.AreEqual(element.Value, "γεια σας");

            element = root["alb"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "alb");
            Assert.AreEqual(element.Value, "përshëndetje");

            element = root["arm"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "arm");
            Assert.AreEqual(element.Value, "բարեւ Ձեզ");

            element = root["vie"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "vie");
            Assert.AreEqual(element.Value, "xin chào");

            element = root["por"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "por");
            Assert.AreEqual(element.Value, "Olá");

            element = root["ukr"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "ukr");
            Assert.AreEqual(element.Value, "Привіт");

            element = root["ger"] as BSONStringElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.ElementType, BSONElementType.String);
            Assert.AreEqual(element.Name, "ger");
            Assert.AreEqual(element.Value, "wünsche");

            Assert.AreEqual(stream.Position, 232); // ensure whole document readed
              }
        }
开发者ID:itadapter,项目名称:nfx,代码行数:80,代码来源:BSON.cs


示例13: Templatization_ArrayOfUnicodeStringNames

        public void Templatization_ArrayOfUnicodeStringNames()
        {
            var qry0 = new BSONDocument("{ '$$eng': 'eng', '$$rus': 'rus', '$$chi': 'chi', '$$jap': 'jap', '$$gre': 'gre', '$$alb': 'alb', '$$arm': 'arm', '$$vie': 'vie', '$$por': 'por', '$$ukr': 'ukr', '$$ger': 'ger' }", true,
                           new TemplateArg("eng", BSONElementType.String, "hello"),
                           new TemplateArg("rus", BSONElementType.String, "привет"),
                           new TemplateArg("chi", BSONElementType.String, "你好"),
                           new TemplateArg("jap", BSONElementType.String, "こんにちは"),
                           new TemplateArg("gre", BSONElementType.String, "γεια σας"),
                           new TemplateArg("alb", BSONElementType.String, "përshëndetje"),
                           new TemplateArg("arm", BSONElementType.String, "բարեւ Ձեզ"),
                           new TemplateArg("vie", BSONElementType.String, "xin chào"),
                           new TemplateArg("por", BSONElementType.String, "Olá"),
                           new TemplateArg("ukr", BSONElementType.String, "Привіт"),
                           new TemplateArg("ger", BSONElementType.String, "wünsche"));

              Assert.AreEqual(qry0.Count, 11);
              Assert.IsNotNull(qry0["hello"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["hello"]);
              Assert.AreEqual(((BSONStringElement)qry0["hello"]).Value, "eng");

              Assert.IsNotNull(qry0["привет"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["привет"]);
              Assert.AreEqual(((BSONStringElement)qry0["привет"]).Value, "rus");

              Assert.IsNotNull(qry0["你好"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["你好"]);
              Assert.AreEqual(((BSONStringElement)qry0["你好"]).Value, "chi");

              Assert.IsNotNull(qry0["こんにちは"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["こんにちは"]);
              Assert.AreEqual(((BSONStringElement)qry0["こんにちは"]).Value, "jap");

              Assert.IsNotNull(qry0["γεια σας"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["γεια σας"]);
              Assert.AreEqual(((BSONStringElement)qry0["γεια σας"]).Value, "gre");

              Assert.IsNotNull(qry0["përshëndetje"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["përshëndetje"]);
              Assert.AreEqual(((BSONStringElement)qry0["përshëndetje"]).Value, "alb");

              Assert.IsNotNull(qry0["բարեւ Ձեզ"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["բարեւ Ձեզ"]);
              Assert.AreEqual(((BSONStringElement)qry0["բարեւ Ձեզ"]).Value, "arm");

              Assert.IsNotNull(qry0["xin chào"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["xin chào"]);
              Assert.AreEqual(((BSONStringElement)qry0["xin chào"]).Value, "vie");

              Assert.IsNotNull(qry0["Olá"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["Olá"]);
              Assert.AreEqual(((BSONStringElement)qry0["Olá"]).Value, "por");

              Assert.IsNotNull(qry0["Привіт"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["Привіт"]);
              Assert.AreEqual(((BSONStringElement)qry0["Привіт"]).Value, "ukr");

              Assert.IsNotNull(qry0["wünsche"]);
              Assert.IsInstanceOf<BSONStringElement>(qry0["wünsche"]);
              Assert.AreEqual(((BSONStringElement)qry0["wünsche"]).Value, "ger");
        }
开发者ID:itadapter,项目名称:nfx,代码行数:60,代码来源:BSON.cs


示例14: Templatization_ArrayOfUnicodeStringValues

        public void Templatization_ArrayOfUnicodeStringValues()
        {
            var qry0 = new BSONDocument("{ '$$unicode': [ '$$eng', '$$rus', '$$chi', '$$jap', '$$gre', '$$alb', '$$arm', '$$vie', '$$por', '$$ukr', '$$ger' ] }", true,
                           new TemplateArg("unicode", BSONElementType.String, "strings"),
                           new TemplateArg("eng", BSONElementType.String, "hello"),
                           new TemplateArg("rus", BSONElementType.String, "привет"),
                           new TemplateArg("chi", BSONElementType.String, "你好"),
                           new TemplateArg("jap", BSONElementType.String, "こんにちは"),
                           new TemplateArg("gre", BSONElementType.String, "γεια σας"),
                           new TemplateArg("alb", BSONElementType.String, "përshëndetje"),
                           new TemplateArg("arm", BSONElementType.String, "բարեւ Ձեզ"),
                           new TemplateArg("vie", BSONElementType.String, "xin chào"),
                           new TemplateArg("por", BSONElementType.String, "Olá"),
                           new TemplateArg("ukr", BSONElementType.String, "Привіт"),
                           new TemplateArg("ger", BSONElementType.String, "wünsche"));

              Assert.AreEqual(qry0.Count, 1);
              Assert.IsNotNull(qry0["strings"]);
              Assert.IsInstanceOf<BSONArrayElement>(qry0["strings"]);
              var array = ((BSONArrayElement)qry0["strings"]).Value;
              Assert.IsNotNull(array);
              Assert.AreEqual(array.Length, 11);
              Assert.AreEqual(((BSONStringElement)array[0]).Value, "hello");
              Assert.AreEqual(((BSONStringElement)array[1]).Value, "привет");
              Assert.AreEqual(((BSONStringElement)array[2]).Value, "你好");
              Assert.AreEqual(((BSONStringElement)array[3]).Value, "こんにちは");
              Assert.AreEqual(((BSONStringElement)array[4]).Value, "γεια σας");
              Assert.AreEqual(((BSONStringElement)array[5]).Value, "përshëndetje");
              Assert.AreEqual(((BSONStringElement)array[6]).Value, "բարեւ Ձեզ");
              Assert.AreEqual(((BSONStringElement)array[7]).Value, "xin chào");
              Assert.AreEqual(((BSONStringElement)array[8]).Value, "Olá");
              Assert.AreEqual(((BSONStringElement)array[9]).Value, "Привіт");
              Assert.AreEqual(((BSONStringElement)array[10]).Value, "wünsche");
        }
开发者ID:itadapter,项目名称:nfx,代码行数:34,代码来源:BSON.cs


示例15: Templatization_QueryComplexObject

        public void Templatization_QueryComplexObject()
        {
            var qry0 = new BSONDocument(
            "{" +
              "'$$item1': 23," +
              "item2: [1, '$$item21', 123.456], " +
              "'$$item3': { item31: '$$false', item32: '$$array', item33: {} }," +
              "'$$item4': {" +
            "'$$item41': [1, 2, 3]," +
            "'$$item42': false," +
            "item43: '$$double'," +
            "item44: 'こんこんвапаъü'," +
            "item45: { item451: '$$array2', item452: true, item453: {} }" +
              "} "+
            "}", true,
            new TemplateArg("item1", BSONElementType.String, "item1"),
            new TemplateArg("item21", BSONElementType.String, "こん好արüвіт"),
            new TemplateArg("item3", BSONElementType.String, "item3"),
            new TemplateArg("false", BSONElementType.Boolean, false),
            new TemplateArg("array", BSONElementType.Array,
              new BSONElement[]
              {
            new BSONBooleanElement(true),
            new BSONBooleanElement(true),
            new BSONBooleanElement(false)
              }),
            new TemplateArg("item4", BSONElementType.String, "item4"),
            new TemplateArg("item41", BSONElementType.String, "item41"),
            new TemplateArg("item42", BSONElementType.String, "item42"),
            new TemplateArg("double", BSONElementType.Double, -123.4567),
            new TemplateArg("array2", BSONElementType.Array,
              new BSONElement[]
              {
            new BSONInt64Element(2),
              })
            );

              Assert.AreEqual(qry0.Count, 4);

              Assert.AreEqual(((BSONInt32Element)qry0["item1"]).Value, 23);

              var item2 = ((BSONArrayElement)qry0["item2"]).Value;
              Assert.AreEqual(item2.Length, 3);
              Assert.AreEqual(((BSONInt32Element)item2[0]).Value, 1);
              Assert.AreEqual(((BSONStringElement)item2[1]).Value, "こん好արüвіт");
              Assert.AreEqual(((BSONDoubleElement)item2[2]).Value, 123.456D);

              var item3 = ((BSONDocumentElement)qry0["item3"]).Value;
              Assert.AreEqual(item3.Count, 3);
              Assert.AreEqual(((BSONBooleanElement)item3["item31"]).Value, false);
              var arr = ((BSONArrayElement)item3["item32"]).Value;
              Assert.AreEqual(arr.Length, 3);
              Assert.AreEqual(((BSONBooleanElement)arr[0]).Value, true);
              Assert.AreEqual(((BSONBooleanElement)arr[1]).Value, true);
              Assert.AreEqual(((BSONBooleanElement)arr[2]).Value, false);
              var item33 =  ((BSONDocumentElement)item3["item33"]).Value;
              Assert.AreEqual(item33.Count, 0);

              var item4 = ((BSONDocumentElement)qry0["item4"]).Value;
              Assert.AreEqual(item4.Count, 5);
              var item41 = ((BSONArrayElement)item4["item41"]).Value;
              Assert.AreEqual(item41.Length, 3);
              Assert.AreEqual(((BSONInt32Element)item41[0]).Value, 1);
              Assert.AreEqual(((BSONInt32Element)item41[1]).Value, 2);
              Assert.AreEqual(((BSONInt32Element)item41[2]).Value, 3);
              Assert.AreEqual(((BSONBooleanElement)item4["item42"]).Value, false);
              Assert.AreEqual(((BSONDoubleElement)item4["item43"]).Value, -123.4567D);
              Assert.AreEqual(((BSONStringElement)item4["item44"]).Value, "こんこんвапаъü");

              var item45 = ((BSONDocumentElement)item4["item45"]).Value;
              Assert.AreEqual(item45.Count, 3);
              var item451 = ((BSONArrayElement)item45["item451"]).Value;
              Assert.AreEqual(item451.Length, 1);
              Assert.AreEqual(((BSONInt64Element)item451[0]).Value, 2);
              Assert.AreEqual(((BSONBooleanElement)item45["item452"]).Value, true);

              var item453 =  ((BSONDocumentElement)item45["item453"]).Value;
              Assert.AreEqual(item453.Count, 0);
        }
开发者ID:itadapter,项目名称:nfx,代码行数:79,代码来源:BSON.cs


示例16: Amount_CLRtoBSON

 public static BSONDocumentElement Amount_CLRtoBSON(string name, Amount amount)
 {
   var curEl = new BSONStringElement("c", amount.CurrencyISO);
   var valEl = Decimal_CLRtoBSON("v", amount.Value);
   var doc = new BSONDocument();
   doc.Set(curEl).Set(valEl);
  
   return name != null ? new BSONDocumentElement(name, doc) : new BSONDocumentElement(doc);
 }
开发者ID:huoxudong125,项目名称:nfx,代码行数:9,代码来源:RowConverter.cs


示例17: RowToBSONDocumentElement

      /// <summary>
      /// Converts row to BSON document suitable for storage in MONGO.DB.
      /// Pass target name (name of particular store/epoch/implementation) to get targeted field metadata.
      /// Note: the supplied row MAY NOT CONTAIN REFERENCE CYCLES - either direct or transitive
      /// </summary>
      public virtual BSONDocumentElement RowToBSONDocumentElement(Row row, string targetName, bool useAmorphousData = true, string name= null)
      {
        if (row==null) return null;

        var amrow = row as IAmorphousData;
        if (amrow!=null && useAmorphousData && amrow.AmorphousDataEnabled)
        {
            amrow.BeforeSave(targetName);
        }

        var result = new BSONDocument();
        foreach(var field in row.Schema)
        {
            var attr = field[targetName];
            if (attr!=null && attr.StoreFlag!=StoreFlag.OnlyStore && attr.StoreFlag!=StoreFlag.LoadAndStore) continue;
            var el = GetFieldAsBSON(row, field, targetName);
            result.Set( el ); 
        }

        if (amrow!=null && useAmorphousData && amrow.AmorphousDataEnabled)
          foreach(var kvp in amrow.AmorphousData)
          {
            result.Set( GetAmorphousFieldAsBSON(kvp, targetName) );
          }

        return name != null ? new BSONDocumentElement(name, result) : new BSONDocumentElement(result);
      } 
开发者ID:huoxudong125,项目名称:nfx,代码行数:32,代码来源:RowConverter.cs


示例18: BSONDocumentToRow

    /// <summary>
    /// Converts BSON document into Row by filling the supplied row instance making necessary type transforms to
    ///  suit Row.Schema field definitions per target name. If the passed row supports IAmorphousData, then
    /// the fields either not found in row, or the fields that could not be type-converted to CLR type will be 
    /// stowed in amorphous data dictionary
    /// </summary>
    public virtual void BSONDocumentToRow(BSONDocument doc, Row row, string targetName, bool useAmorphousData = true, Func<BSONDocument, BSONElement, bool> filter = null)
    {                
      if (doc==null || row==null) throw new BSONException(StringConsts.ARGUMENT_ERROR+"BSONDocumentToRow(doc|row=null)");
         
      var amrow = row as IAmorphousData;

      foreach(var elm in doc)
      {
        if (filter!=null)
          if (!filter(doc, elm)) continue;
           
        // 2015.03.01 Introduced caching
        var fld = MapBSONFieldNameToSchemaFieldDef(row.Schema, targetName, elm.Name);


        if (fld==null)
        {
            if (amrow!=null && useAmorphousData && amrow.AmorphousDataEnabled)
              SetAmorphousFieldAsCLR(amrow, elm, targetName, filter); 
            continue;
        }

        var wasSet = TrySetFieldAsCLR(row, fld, elm, targetName, filter);
        if (!wasSet)//again dump it in amorphous
        {
          if (amrow!=null && useAmorphousData && amrow.AmorphousDataEnabled)
              SetAmorphousFieldAsCLR(amrow, elm, targetName, filter);
        }
      }


      if (amrow!=null && useAmorphousData && amrow.AmorphousDataEnabled)
      {
          amrow.AfterLoad(targetName);
      }
    }
开发者ID:huoxudong125,项目名称:nfx,代码行数:42,代码来源:RowConverter.cs


示例19: Templatization_ComplexObjectNoTemplate

        public void Templatization_ComplexObjectNoTemplate()
        {
            var qry0 = new BSONDocument(
            "{" +
              "item1: 23," +
              "item2: [1, 'こん好արüвіт', 123.456], " +
              "item3: { item31: false, item32: [true, true, false], item33: {} }," +
              "item4: {" +
            "item41: [1, 2, 3]," +
            "item42: false," +
            "item43: -123.4567," +
            "item44: 'こんこんвапаъü'," +
            "item45: { item451: [2], item452: true, item453: {} }" +
              "} "+
            "}", true);

              Assert.AreEqual(qry0.Count, 4);

              Assert.AreEqual(((BSONInt32Element)qry0["item1"]).Value, 23);

              var item2 = ((BSONArrayElement)qry0["item2"]).Value;
              Assert.AreEqual(item2.Length, 3);
              Assert.AreEqual(((BSONInt32Element)item2[0]).Value, 1);
              Assert.AreEqual(((BSONStringElement)item2[1]).Value, "こん好արüвіт");
              Assert.AreEqual(((BSONDoubleElement)item2[2]).Value, 123.456D);

              var item3 = ((BSONDocumentElement)qry0["item3"]).Value;
              Assert.AreEqual(item3.Count, 3);
              Assert.AreEqual(((BSONBooleanElement)item3["item31"]).Value, false);
              var arr = ((BSONArrayElement)item3["item32"]).Value;
              Assert.AreEqual(arr.Length, 3);
              Assert.AreEqual(((BSONBooleanElement)arr[0]).Value, true);
              Assert.AreEqual(((BSONBooleanElement)arr[1]).Value, true);
              Assert.AreEqual(((BSONBooleanElement)arr[2]).Value, false);
              var item33 = ((BSONDocumentElement)item3["item33"]).Value;
              Assert.AreEqual(item33.Count, 0);

              var item4 = ((BSONDocumentElement)qry0["item4"]).Value;
              Assert.AreEqual(item4.Count, 5);
              var item41 = ((BSONArrayElement)item4["item41"]).Value;
              Assert.AreEqual(item41.Length, 3);
              Assert.AreEqual(((BSONInt32Element)item41[0]).Value, 1);
              Assert.AreEqual(((BSONInt32Element)item41[1]).Value, 2);
              Assert.AreEqual(((BSONInt32Element)item41[2]).Value, 3);
              Assert.AreEqual(((BSONBooleanElement)item4["item42"]).Value, false);
              Assert.AreEqual(((BSONDoubleElement)item4["item43"]).Value, -123.4567D);
              Assert.AreEqual(((BSONStringElement)item4["item44"]).Value, "こんこんвапаъü");

              var item45 = ((BSONDocumentElement)item4["item45"]).Value;
              Assert.AreEqual(item45.Count, 3);
              var item451 = ((BSONArrayElement)item45["item451"]).Value;
              Assert.AreEqual(item451.Length, 1);
              Assert.AreEqual(((BSONInt32Element)item451[0]).Value, 2);
              Assert.AreEqual(((BSONBooleanElement)item45["item452"]).Value, true);

              var item453 =  ((BSONDocumentElement)item45["item453"]).Value;
              Assert.AreEqual(item453.Count, 0);
        }
开发者ID:itadapter,项目名称:nfx,代码行数:58,代码来源:BSON.cs


示例20: ReadSingleRegularExpression

        public void ReadSingleRegularExpression()
        {
            var src = Convert.FromBase64String(@"NwAAAAtlbWFpbABeWy0uXHddK0AoPzpbYS16XGRdezIsfVwuKStbYS16XXsyLDZ9JABpbXUAAA==");

              using (var stream = new MemoryStream(src))
              {
            var root = new BSONDocument(stream);
            var pattern = @"^[-.\w][email protected](?:[a-z\d]{2,}\.)+[a-z]{2,6}$";
            var options = BSONRegularExpressionOptions.I | BSONRegularExpressionOptions.M |BSONRegularExpressionOptions.U;

            Assert.AreEqual(root.ByteSize, 55);
            Assert.AreEqual(root.Count, 1);

            var element = root["email"] as BSONRegularExpressionElement;
            Assert.IsNotNull(element);
            Assert.AreEqual(element.Name, "email");
            Assert.AreEqual(element.ElementType, BSONElementType.RegularExpression);
            Assert.AreEqual(element.Value.Pattern, pattern);
            Assert.AreEqual(element.Value.Options, options);

            Assert.AreEqual(stream.Position, 55); // ensure whole document readed
              }
        }
开发者ID:itadapter,项目名称:nfx,代码行数:23,代码来源:BSON.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# BSyncResult类代码示例发布时间:2022-05-24
下一篇:
C# BRemote类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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