예제 #1
0
        public static MongodbDatabase UsePool(params string[] keys)
        {
            int count = pool.Count;

            if (count != poolkey.Count || count == 0)
            {
                pool.Clear(); poolkey.Clear(); count = 0;
                ConnectionStringSettingsCollection conns = WebConfig.GetConn();
                foreach (ConnectionStringSettings info in conns)
                {
                    string key = info.Name;
                    if (key != "MongoDB" || keys.IndexOf(key) == -1)
                    {
                        continue;
                    }

                    MongodbDatabase db = new MongodbDatabase(key);
                    db.Pool             = key;
                    pool[key.ToLower()] = db;
                    poolkey.Add(key.ToLower());
                    count++;
                }
            }
            return(pool[poolkey[count == 1 ? 0 : Rand.RndInt(0, count)]]);
        }
예제 #2
0
 public static void AddPool(MongodbDatabase db)
 {
     if (db.IsNull())
     {
         return;
     }
     AddPool(db.Pool, db);
 }
예제 #3
0
 public static void AddPool(string key, MongodbDatabase db = null) {
     if (key.IsNullEmpty()) return;
     key = key.ToLower();
     if (pool.ContainsKey(key)) return;
     if (db.IsNull()) {
         MongodbDatabase newdb = new MongodbDatabase(key);
         newdb.Pool = key;
         pool[key] = newdb;
         poolkey.Add(key);
     } else {
         pool[key] = db;
         poolkey.Add(key);
     }
 }
예제 #4
0
        public static MongodbDatabase UsePool(params string[] keys) {
            int count = pool.Count;
            if (count != poolkey.Count || count == 0) {
                pool.Clear(); poolkey.Clear(); count = 0;
                ConnectionStringSettingsCollection conns = WebConfig.GetConn();
                foreach (ConnectionStringSettings info in conns) {
                    string key = info.Name;
                    if (key != "MongoDB" || keys.IndexOf(key) == -1) continue;

                    MongodbDatabase db = new MongodbDatabase(key);
                    db.Pool = key;
                    pool[key.ToLower()] = db;
                    poolkey.Add(key.ToLower());
                    count++;
                }
            }
            return pool[poolkey[count == 1 ? 0 : Rand.RndInt(0, count)]];
        }
예제 #5
0
 public static void AddPool(string key, MongodbDatabase db = null)
 {
     if (key.IsNullEmpty())
     {
         return;
     }
     key = key.ToLower();
     if (pool.ContainsKey(key))
     {
         return;
     }
     if (db.IsNull())
     {
         MongodbDatabase newdb = new MongodbDatabase(key);
         newdb.Pool = key;
         pool[key]  = newdb;
         poolkey.Add(key);
     }
     else
     {
         pool[key] = db;
         poolkey.Add(key);
     }
 }
예제 #6
0
 public static void AddPool(MongodbDatabase db) {
     if (db.IsNull()) return;
     AddPool(db.Pool, db);
 }