示例#1
0
        public static MongoDatabase Pool()
        {
            int count = pool.Count;

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

                    MongoClient client = new MongoClient(info.ConnectionString);
                    clients[key.ToLower()] = client;
                    MongoServer server = client.GetServer();
                    servers[key.ToLower()] = server;
                    pool[key.ToLower()]    = server.GetDatabase(key.IndexOf(".") == -1 ? key : key.Split('.')[1]);
                    poolkey.Add(key.ToLower());
                    count++;
                }
            }
            return(pool[poolkey[count == 1 ? 0 : Rand.RndInt(0, count)]]);
        }
示例#2
0
        public static MongodbDatabase Pool()
        {
            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;
                    string type = info.ProviderName;
                    if (type != "MongoDB")
                    {
                        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)]]);
        }
示例#3
0
 public static void ClosePool(string key = null)
 {
     if (key.IsNullEmpty())
     {
         foreach (string info in servers.Keys)
         {
             servers[info].Disconnect();
         }
         pool.Clear();
         poolkey.Clear();
         servers.Clear();
         clients.Clear();
     }
     else
     {
         key = key.ToLower();
         if (!pool.ContainsKey(key))
         {
             return;
         }
         servers[key].Disconnect();
         pool[key] = null;
         poolkey.Remove(key);
         pool.Remove(key);
         servers.Remove(key);
         clients.Remove(key);
     }
 }
示例#4
0
 /// <summary>
 /// Çå¿ÕËùÓлº´æÏîÄ¿
 /// </summary>
 public void Clear()
 {
     cacheList.Clear();
 }