예제 #1
0
        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);
        }
예제 #2
0
파일: TestBSON.cs 프로젝트: rayleyva/ejdb
 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);
 }
예제 #3
0
        private void reload()
        {
            // this.dkmEvalResult.InspectionContext;
            txtOutput.Text = "";
            ulong address = this.dkmEvalResult.Address.Value;

            DkmProcess process = this.dkmEvalResult.InspectionContext.Thread.Process;

            byte[] buffer = new byte[1024];
            process.ReadMemory(
                address,
                DkmReadMemoryFlags.None,
                buffer
                );

            using (BSONIterator it = new BSONIterator(buffer))
            {
                while (it.Next() != BSONType.EOO)
                {
                    BSONValue value = it.FetchCurrentValue();
                    String    s     = value.ToString();

                    txtOutput.Text += s;
                    txtOutput.Text += "\n";
                    continue;
                }
            }

            return;
        }
예제 #4
0
        public void TestIterate1()
        {
            var doc = new BSONDocument();

            doc["a"]  = "av";
            doc["bb"] = 24;
            //doc["ccc"] = BSONDocument.ValueOf(new{na1 = 1, nb = "2"});
            //doc["d"] = new BSONOid("51b9f3af98195c4600000000");

            //17-00-00-00                       +4
            //02-61-00-03-00-00-00-61-76-00		+10
            //10-62-62-00-18-00-00-00			+8
            //00								+1
            Assert.AreEqual("17-00-00-00-02-61-00-03-00-00-00-61-76-00-10-62-62-00-18-00-00-00-00",
                            doc.ToDebugDataString());
            BSONIterator it = new BSONIterator(doc);

            Assert.AreEqual(doc.ToByteArray().Length, it.DocumentLength);
            var c = "";

            while (it.Next() != BSONType.EOO)
            {
                c += it.CurrentKey;
            }
            Assert.AreEqual("abb", c);
            it.Dispose();

            it = new BSONIterator(doc);
            var cnt = 0;

            while (it.Next() != BSONType.EOO)
            {
                BSONValue bv = it.FetchCurrentValue();
                Assert.IsNotNull(bv);
                if (cnt == 0)
                {
                    Assert.IsTrue(bv.BSONType == BSONType.STRING);
                    Assert.IsTrue(bv.Key == "a");
                    Assert.AreEqual("av", bv.Value);
                }
                if (cnt == 1)
                {
                    Assert.IsTrue(bv.BSONType == BSONType.INT);
                    Assert.IsTrue(bv.Key == "bb");
                    Assert.AreEqual(24, bv.Value);
                }
                cnt++;
            }
        }
예제 #5
0
        /// <summary>
        /// Convert JSON string into BSONDocument.
        /// Returns `null` if conversion failed.
        /// </summary>
        /// <returns>The BSONDocument instance on success.</returns>
        /// <param name="json">JSON string</param>
        public BSONDocument Json2Bson(string json)
        {
            IntPtr bsonret = _json2bson(json);

            if (bsonret == IntPtr.Zero)
            {
                return(null);
            }
            byte[] bsdata = BsonPtrIntoByteArray(bsonret);
            if (bsdata.Length == 0)
            {
                return(null);
            }
            BSONIterator it = new BSONIterator(bsdata);

            return(it.ToBSONDocument());
        }
예제 #6
0
파일: EJDB.cs 프로젝트: sujeetpillai/ejdb
        /// <summary>
        /// Executes EJDB command.
        /// </summary>
        /// <remarks>
        /// Supported commands:
        ///
        /// 1) Exports database collections data. See ejdbexport() method.
        ///
        ///     "export" : {
        ///     "path" : string,                    //Exports database collections data
        ///     "cnames" : [string array]|null,     //List of collection names to export
        ///     "mode" : int|null                   //Values: null|`JBJSONEXPORT` See ejdb.h#ejdbexport() method
        /// }
        ///
        /// Command response:
        /// {
        ///     "log" : string,        //Diagnostic log about executing this command
        ///     "error" : string|null, //ejdb error message
        ///     "errorCode" : int|0,   //ejdb error code
        /// }
        ///
        /// 2) Imports previously exported collections data into ejdb.
        ///
        ///     "import" : {
        ///     "path" : string                     //The directory path in which data resides
        ///         "cnames" : [string array]|null,     //List of collection names to import
        ///         "mode" : int|null                //Values: null|`JBIMPORTUPDATE`|`JBIMPORTREPLACE` See ejdb.h#ejdbimport() method
        /// }
        ///
        /// Command response:
        /// {
        ///     "log" : string,        //Diagnostic log about executing this command
        ///     "error" : string|null, //ejdb error message
        ///     "errorCode" : int|0,   //ejdb error code
        /// }
        /// </remarks>
        /// <param name="cmd">Command object</param>
        /// <returns>Command response.</returns>
        public BSONDocument Command(BSONDocument cmd)
        {
            CheckDisposed();
            byte[] cmdata = cmd.ToByteArray();
            //internal static extern IntPtr _ejdbcommand([In] IntPtr db, [In] byte[] cmd);
            IntPtr cmdret = _ejdbcommand(_db, cmdata);

            if (cmdret == IntPtr.Zero)
            {
                return(null);
            }
            byte[] bsdata = BsonPtrIntoByteArray(cmdret);
            if (bsdata.Length == 0)
            {
                return(null);
            }
            BSONIterator it = new BSONIterator(bsdata);

            return(it.ToBSONDocument());
        }
예제 #7
0
        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();
        }
예제 #8
0
        public void TestIterate2()
        {
            var doc = new BSONDocument();

            doc["a"] = "av";
            doc["b"] = BSONDocument.ValueOf(new{ cc = 1 });
            doc["d"] = new BSONOid("51b9f3af98195c4600000000");
            Assert.AreEqual(3, doc.KeysCount);
            //Console.WriteLine(doc.KeysCount);
            //Console.WriteLine(doc.ToDebugDataString());
            //2E-00-00-00					    +4
            //02-61-00-03-00-00-00-61-76-00		+10 (14)
            //03-62-00							+3  (17) "d" =
            //0D-00-00-00						+4  (21) doc len = 13
            //10-63-63-00-01-00-00-00 -00		+9  (30)
            //07-64-00							+3  (33)
            //51-B9-F3-AF-98-19-5C-46-00-00-00-00	 +12 (45)
            //00									+1 (46)
            Assert.AreEqual("2E-00-00-00-" +
                            "02-61-00-03-00-00-00-61-76-00-" +
                            "03-62-00-" +
                            "0D-00-00-00-" +
                            "10-63-63-00-01-00-00-00-00-" +
                            "07-64-00-" +
                            "51-B9-F3-AF-98-19-5C-46-00-00-00-00-" +
                            "00", doc.ToDebugDataString());
            BSONIterator it = new BSONIterator(doc);
            int          c  = 0;

            foreach (var bt in it)
            {
                if (c == 0)
                {
                    Assert.IsTrue(bt == BSONType.STRING);
                }
                if (c == 1)
                {
                    Assert.IsTrue(bt == BSONType.OBJECT);
                }
                if (c == 2)
                {
                    Assert.IsTrue(bt == BSONType.OID);
                }
                ++c;
            }
            bool thrown = false;

            Assert.IsTrue(it.Disposed);
            try {
                it.Next();
            } catch (ObjectDisposedException) {
                thrown = true;
            }
            Assert.IsTrue(thrown);

            c  = 0;
            it = new BSONIterator(doc);
            foreach (var bv in it.Values())
            {
                if (c == 0)
                {
                    Assert.AreEqual("a", bv.Key);
                    Assert.AreEqual("av", bv.Value);
                }
                if (c == 1)
                {
                    Assert.AreEqual("b", bv.Key);
                    BSONDocument sdoc = bv.Value as BSONDocument;
                    Assert.IsNotNull(sdoc);
                    foreach (var bv2 in new BSONIterator(sdoc).Values())
                    {
                        Assert.AreEqual("cc", bv2.Key);
                        Assert.AreEqual(1, bv2.Value);
                        Assert.AreEqual(BSONType.INT, bv2.BSONType);
                    }
                }
                if (c == 2)
                {
                    Assert.AreEqual(BSONType.OID, bv.BSONType);
                    Assert.IsInstanceOf(typeof(BSONOid), bv.Value);
                    var oid = bv.Value as BSONOid;
                    Assert.AreEqual("51b9f3af98195c4600000000", oid.ToString());
                }
                c++;
            }
        }
예제 #9
0
파일: EJDB.cs 프로젝트: kkk777kkk/ejdb
 /// <summary>
 /// Executes EJDB command.
 /// </summary>
 /// <remarks>
 /// Supported commands:
 ///
 /// 1) Exports database collections data. See ejdbexport() method.
 /// 
 /// 	"export" : {
 /// 	"path" : string,                    //Exports database collections data
 /// 	"cnames" : [string array]|null,     //List of collection names to export
 /// 	"mode" : int|null                   //Values: null|`JBJSONEXPORT` See ejdb.h#ejdbexport() method
 /// }
 /// 
 /// Command response:
 /// {
 /// 	"log" : string,        //Diagnostic log about executing this command
 /// 	"error" : string|null, //ejdb error message
 /// 	"errorCode" : int|0,   //ejdb error code
 /// }
 /// 
 /// 2) Imports previously exported collections data into ejdb.
 /// 
 /// 	"import" : {
 /// 	"path" : string                     //The directory path in which data resides
 /// 		"cnames" : [string array]|null,     //List of collection names to import
 /// 		"mode" : int|null                //Values: null|`JBIMPORTUPDATE`|`JBIMPORTREPLACE` See ejdb.h#ejdbimport() method
 /// }
 /// 
 /// Command response:
 /// {
 /// 	"log" : string,        //Diagnostic log about executing this command
 /// 	"error" : string|null, //ejdb error message
 /// 	"errorCode" : int|0,   //ejdb error code
 /// }
 /// </remarks>
 /// <param name="cmd">Command object</param>
 /// <returns>Command response.</returns>
 public BSONDocument Command(BSONDocument cmd)
 {
     CheckDisposed();
     byte[] cmdata = cmd.ToByteArray();
     //internal static extern IntPtr _ejdbcommand([In] IntPtr db, [In] byte[] cmd);
     IntPtr cmdret = _ejdbcommand(_db, cmdata);
     if (cmdret == IntPtr.Zero) {
         return null;
     }
     byte[] bsdata = BsonPtrIntoByteArray(cmdret);
     if (bsdata.Length == 0) {
         return null;
     }
     BSONIterator it = new BSONIterator(bsdata);
     return it.ToBSONDocument();
 }
예제 #10
0
파일: TestBSON.cs 프로젝트: rayleyva/ejdb
        public void TestIterate1()
        {
            var doc = new BSONDocument();
            doc["a"] = "av";
            doc["bb"] = 24;
            //doc["ccc"] = BSONDocument.ValueOf(new{na1 = 1, nb = "2"});
            //doc["d"] = new BSONOid("51b9f3af98195c4600000000");

            //17-00-00-00 						+4
            //02-61-00-03-00-00-00-61-76-00		+10
            //10-62-62-00-18-00-00-00			+8
            //00								+1
            Assert.AreEqual("17-00-00-00-02-61-00-03-00-00-00-61-76-00-10-62-62-00-18-00-00-00-00",
                            doc.ToDebugDataString());
            BSONIterator it = new BSONIterator(doc);
            Assert.AreEqual(doc.ToByteArray().Length, it.DocumentLength);
            var c = "";
            while (it.Next() != BSONType.EOO) {
                c += it.CurrentKey;
            }
            Assert.AreEqual("abb", c);
            it.Dispose();

            it = new BSONIterator(doc);
            var cnt = 0;
            while (it.Next() != BSONType.EOO) {
                BSONValue bv = it.FetchCurrentValue();
                Assert.IsNotNull(bv);
                if (cnt == 0) {
                    Assert.IsTrue(bv.BSONType == BSONType.STRING);
                    Assert.IsTrue(bv.Key == "a");
                    Assert.AreEqual("av", bv.Value);
                }
                if (cnt == 1) {
                    Assert.IsTrue(bv.BSONType == BSONType.INT);
                    Assert.IsTrue(bv.Key == "bb");
                    Assert.AreEqual(24, bv.Value);
                }
                cnt++;
            }
        }
예제 #11
0
파일: TestBSON.cs 프로젝트: rayleyva/ejdb
        public void TestIterate2()
        {
            var doc = new BSONDocument();
            doc["a"] = "av";
            doc["b"] = BSONDocument.ValueOf(new{cc = 1});
            doc["d"] = new BSONOid("51b9f3af98195c4600000000");
            Assert.AreEqual(3, doc.KeysCount);
            //Console.WriteLine(doc.KeysCount);
            //Console.WriteLine(doc.ToDebugDataString());
            //2E-00-00-00					   	+4
            //02-61-00-03-00-00-00-61-76-00		+10 (14)
            //03-62-00							+3  (17) "d" =
            //0D-00-00-00						+4  (21) doc len = 13
            //10-63-63-00-01-00-00-00 -00		+9 	(30)
            //07-64-00							+3 	(33)
            //51-B9-F3-AF-98-19-5C-46-00-00-00-00	 +12 (45)
            //00									+1 (46)
            Assert.AreEqual("2E-00-00-00-" +
                "02-61-00-03-00-00-00-61-76-00-" +
                "03-62-00-" +
                "0D-00-00-00-" +
                "10-63-63-00-01-00-00-00-00-" +
                "07-64-00-" +
                "51-B9-F3-AF-98-19-5C-46-00-00-00-00-" +
                "00", doc.ToDebugDataString());
            BSONIterator it = new BSONIterator(doc);
            int c = 0;
            foreach (var bt in it) {
                if (c == 0) {
                    Assert.IsTrue(bt == BSONType.STRING);
                }
                if (c == 1) {
                    Assert.IsTrue(bt == BSONType.OBJECT);
                }
                if (c == 2) {
                    Assert.IsTrue(bt == BSONType.OID);
                }
                ++c;
            }
            bool thrown = false;
            Assert.IsTrue(it.Disposed);
            try {
                it.Next();
            } catch (ObjectDisposedException) {
                thrown = true;
            }
            Assert.IsTrue(thrown);

            c = 0;
            it = new BSONIterator(doc);
            foreach (var bv in it.Values()) {
                if (c == 0) {
                    Assert.AreEqual("a", bv.Key);
                    Assert.AreEqual("av", bv.Value);
                }
                if (c == 1) {
                    Assert.AreEqual("b", bv.Key);
                    BSONDocument sdoc = bv.Value as BSONDocument;
                    Assert.IsNotNull(sdoc);
                    foreach (var bv2 in new BSONIterator(sdoc).Values()) {
                        Assert.AreEqual("cc", bv2.Key);
                        Assert.AreEqual(1, bv2.Value);
                        Assert.AreEqual(BSONType.INT, bv2.BSONType);
                    }
                }
                if (c == 2) {
                    Assert.AreEqual(BSONType.OID, bv.BSONType);
                    Assert.IsInstanceOf(typeof(BSONOid), bv.Value);
                    var oid = bv.Value as BSONOid;
                    Assert.AreEqual("51b9f3af98195c4600000000", oid.ToString());
                }
                c++;
            }
        }
예제 #12
0
파일: EJDB.cs 프로젝트: JulianLiu/ejdb
 /// <summary>
 /// Convert JSON string into BSONDocument.
 /// Returns `null` if conversion failed.
 /// </summary>
 /// <returns>The BSONDocument instance on success.</returns>
 /// <param name="json">JSON string</param>
 public BSONDocument Json2Bson(string json)
 {
     IntPtr bsonret = _json2bson(json);
     if (bsonret == IntPtr.Zero) {
         return null;
     }
     byte[] bsdata = BsonPtrIntoByteArray(bsonret);
     if (bsdata.Length == 0) {
         return null;
     }
     BSONIterator it = new BSONIterator(bsdata);
     return it.ToBSONDocument();
 }