Disconnect() public method

public Disconnect ( ) : System.Boolean
return System.Boolean
        public void TestSetAndGetFunction()
        {
            string connstr = ConfigurationManager.AppSettings["mongoDBTest"];
            var mongo = new Mongo(connstr);
            mongo.Connect();

            var testDB = mongo.GetDatabase("myTest");

            AdminParameters.DB = testDB;

            AdminParameters.Set(AdminParameters.SuggesttedTagsForUserFavorite, "hello");
            Assert.AreEqual(AdminParameters.Get(AdminParameters.SuggesttedTagsForUserFavorite), "hello");

            mongo.Disconnect();
        }
Esempio n. 2
0
        public void FavoriteAdd()
        {
            string connstr = ConfigurationManager.AppSettings["mongoDBTest"];
            var mongo = new Mongo(connstr);
            mongo.Connect();

            var testDB = mongo.GetDatabase("myTest");
            UserFavorite fav = new UserFavorite(testDB, "testUserName" + DateTime.Now.ToShortTimeString());

            fav.Update("question", 101, "tag1,tag2");
            fav.Update("question", 102, "tag3,tag4");
            fav.Update("question", 104, "tag3,tag4,tag5");
            fav.Update("question", 103, "tag1,tag2");
            fav.Update("k", 101, "tag1,tag2");
            fav.Update("k", 102, "tag2,tag7");
            fav.Update("k", 103, "tag1,tag5");
            fav.Update("k", 104, "tag1,tag5");
            fav.Update("k", 105, "tag1,tag5");
            fav.Update("k", 106, "tag1,tag5");

            Assert.IsTrue(Compare(fav.GetTags("k"), "tag1,tag2,tag7,tag5"));
            Assert.IsTrue(Compare(fav.GetTags("question"), "tag1,tag2,tag3,tag4,tag5"));
            Assert.AreEqual("tag1,tag5", fav.GetTags("k", 103));
            Assert.AreEqual("tag1,tag2", fav.GetTags("question", 103));

            Assert.IsTrue(fav.GetIDs("question", "tag1").Contains(101));
            Assert.IsTrue(fav.GetIDs("question", "tag1").Contains(103));

            Assert.AreEqual(5, fav.GetIDs("k", "tag1").Count);
            Assert.AreEqual(6, fav.GetIDs("k").Count);
            Assert.AreEqual(0, fav.GetIDs("foofoo").Count);
            Assert.AreEqual(4, fav.GetIDs("question").Count);

            Assert.IsTrue(fav.HasFavorite("question", 103));
            Assert.IsFalse(fav.HasFavorite("k", 203));

            fav.Remove("question", 103);

            Assert.IsFalse(fav.HasFavorite("question", 103));

            mongo.Disconnect();
        }
        protected void CreateMongoDB(String dbName)
        {
            //mongod.exe must be running for this to work.
            var mongo = new Mongo();
            mongo.Connect();

            //if the database is not found in c:\data\db it will be created.
            var db = mongo.GetDatabase(dbName);

            //declare a new "table"
            var categories = db.GetCollection("categories");

            //create a new key value set
            var document = new Document();
            document["Name"] = "Product";
            document["Name"] = "Price";

            //create the "tabt"
            categories.Insert(document);
            mongo.Disconnect();
        }
        public static void GenerateMongoDB ()
        {
            var json = new MongoJson();
            var mongo = new Mongo();

            mongo.Connect();

            //Create clean database and collection for Notes
            var db = mongo["SupermarkertsDB"];
            db.SendCommand("dropDatabase");
            var products = db["Products"];

            List<int> ids;
            var jsonData = GenerateJSONReports.ExatractJsonData(out ids);
            foreach (var item in jsonData)
            {
                var jsonDocument = json.DocumentFrom(item);
                products.Insert(jsonDocument);
            }           
            
            mongo.Disconnect();
        }
        protected String GetMongoDBResults(String dbName)
        {
            //mongod.exe must be running for this to work.
            var mongo = new Mongo();
            mongo.Connect();

            //if the database is not found in c:\data\db it will be created.
            var db = mongo.GetDatabase(dbName);

            //declare a new "table"
            var categories = db.GetCollection("categories");

            //get the categories table
            var category = categories.FindOne(new Document() { { "Name","Price" } });
            //alternatively you can get all documents in the database
            var documents = categories.FindAll().Documents;
            String res = category["Name"].ToString();

            //diconnect
            mongo.Disconnect();

            //return results in a EF friendly shapre just because that's what I'm working with mostly nowadays
            return res;
        }
Esempio n. 6
0
 public void Dispose()
 {
     //cleanDB();
     db.Disconnect();
 }
Esempio n. 7
0
 public void Dispose()
 {
     db.Disconnect();
 }
        public virtual object DoCheck()
        {
            Document commandResults = null;
            Mongo mongo = null;

            try
            {
                mongo = new Mongo(_connectionString);
                mongo.Connect();

                // In the Linux agent, we get all database names and use the first
                // one found, but no such functionality exists with this .NET
                // MongoDB library.
                Database database = mongo.GetDatabase(DatabaseName);
                commandResults = database.SendCommand("serverStatus");
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return null;
            }
            finally
            {

                if (mongo != null)
                {
                    mongo.Disconnect();
                }

            }

            if (commandResults == null)
            {
                Log.Warn("MongoDB returned no results for serverStatus command.");
                Log.Warn("This is possible on older versions of MongoDB.");
                return null;
            }

            Document indexCounters = (Document)commandResults["indexCounters"];
            Document btree = null;

            // Index counters are currently not supported on Windows.
            if (indexCounters["note"] == null)
            {
                btree = (Document)indexCounters["btree"];
            }
            else
            {
                // We add a blank document, since the server is expecting
                // these btree index values to be present.
                btree = new Document();
                indexCounters.Add("btree", btree);
                btree.Add("accesses", 0);
                btree.Add("accessesPS", 0);
                btree.Add("hits", 0);
                btree.Add("hitsPS", 0);
                btree.Add("misses", 0);
                btree.Add("missesPS", 0);
                btree.Add("missRatio", 0D);
                btree.Add("missRatioPS", 0);
            }

            Document opCounters = (Document)commandResults["opcounters"];
            Document asserts = (Document)commandResults["asserts"];

            if (_mongoDBStore == null)
            {
                Log.Debug("No cached data, so storing for the first time.");

                btree["accessesPS"] = 0;
                btree["hitsPS"] = 0;
                btree["missesPS"] = 0;
                btree["missRatioPS"] = 0;

                opCounters.Add("insertPS", 0);
                opCounters.Add("queryPS", 0);
                opCounters.Add("updatePS", 0);
                opCounters.Add("deletePS", 0);
                opCounters.Add("getmorePS", 0);
                opCounters.Add("commandPS", 0);

                asserts.Add("regularPS", 0);
                asserts.Add("warningPS", 0);
                asserts.Add("msgPS", 0);
                asserts.Add("userPS", 0);
                asserts.Add("rolloversPS", 0);
            }
            else
            {
                Log.Debug("Cached data exists, so calculating per sec metrics.");

                Document cachedBtree = (Document)((Document)_mongoDBStore["indexCounters"])["btree"];
                Document cachedOpCounters = (Document)_mongoDBStore["opcounters"];
                Document cachedAsserts = (Document)commandResults["asserts"];

                btree["accessesPS"] = (float)(((int)btree["accesses"] - (int)cachedBtree["accesses"]) / 60);
                btree["hitsPS"] = (float)(((int)btree["hits"] - (int)cachedBtree["hits"]) / 60);
                btree["missesPS"] = (float)(((int)btree["misses"] - (int)cachedBtree["misses"]) / 60);
                btree["missRatioPS"] = (float)(((double)btree["missRatio"] - (double)cachedBtree["missRatio"]) / 60);

                opCounters.Add("insertPS", (float)(((int)opCounters["insert"] - (int)cachedOpCounters["insert"]) / 60));
                opCounters.Add("queryPS", (float)(((int)opCounters["query"] - (int)cachedOpCounters["query"]) / 60));
                opCounters.Add("updatePS", (float)(((int)opCounters["update"] - (int)cachedOpCounters["update"]) / 60));
                opCounters.Add("deletePS", (float)(((int)opCounters["delete"] - (int)cachedOpCounters["delete"]) / 60));
                opCounters.Add("getmorePS", (float)(((int)opCounters["getmore"] - (int)cachedOpCounters["getmore"]) / 60));
                opCounters.Add("commandPS", (float)(((int)opCounters["command"] - (int)cachedOpCounters["command"]) / 60));

                asserts.Add("regularPS", (float)(((int)asserts["regular"] - (int)cachedAsserts["regular"]) / 60));
                asserts.Add("warningPS", (float)(((int)asserts["warning"] - (int)cachedAsserts["warning"]) / 60));
                asserts.Add("msgPS", (float)(((int)asserts["msg"] - (int)cachedAsserts["msg"]) / 60));
                asserts.Add("userPS", (float)(((int)asserts["user"] - (int)cachedAsserts["user"]) / 60));
                asserts.Add("rolloversPS", (float)(((int)asserts["rollovers"] - (int)cachedAsserts["rollovers"]) / 60));
            }

            _mongoDBStore = commandResults;

            return _mongoDBStore;
        }
 public void Dispose()
 {
     mongo.Disconnect();
 }