当前位置: 首页>>代码示例>>C#>>正文


C# MongoServer.GetDatabaseNames方法代码示例

本文整理汇总了C#中MongoServer.GetDatabaseNames方法的典型用法代码示例。如果您正苦于以下问题:C# MongoServer.GetDatabaseNames方法的具体用法?C# MongoServer.GetDatabaseNames怎么用?C# MongoServer.GetDatabaseNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoServer的用法示例。


在下文中一共展示了MongoServer.GetDatabaseNames方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FillComboboxWithDatabaseNames

 /// <summary>
 /// Filling combobox with database names that server stores.
 /// </summary>
 /// <param name="server">MongoDB.Driver.MongoServer instance to connect to.</param>
 private void FillComboboxWithDatabaseNames(MongoServer server)
 {
     cbDatabases.Items.Clear();
     cbDatabases.Items.AddRange(server.GetDatabaseNames().ToArray());
     if(cbDatabases.Items.Count > 0)
     {
         cbDatabases.SelectedIndex = 0;
     }
 }
开发者ID:dr-dead,项目名称:diplomaWork,代码行数:13,代码来源:loginForm.cs

示例2: Main

 static void Main(string[] args)
 {
     var mongoServerAddress = new MongoServerAddress("127.0.0.1", 27017);
     var mongoServerSettings = new MongoServerSettings();
     mongoServerSettings.Server = mongoServerAddress;
     var mongoServer = new MongoServer(mongoServerSettings);
     mongoServer.Connect();
     IEnumerable<string> databases = mongoServer.GetDatabaseNames();
     var mongoDatabase = mongoServer.GetDatabase("classfrogdb");
     var classCollection = mongoDatabase.GetCollection("classes");
     classCollection.RemoveAll();
     var documents = classCollection.FindAll();
     ClassInstance instance = new ClassInstance();
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     classCollection.Insert(instance.NewDocument());
     mongoServer.Disconnect();
 }
开发者ID:nirmalclassfrog,项目名称:classfrog,代码行数:24,代码来源:Program.cs

示例3: GetInstanceNode

 /// <summary>
 /// 获取实例节点
 /// </summary>
 /// <param name="mongoConnKey"></param>
 /// <param name="config">由于是结构体,必须ref</param>
 /// <param name="mongoConn"></param>
 /// <param name="mMasterServerInstace"></param>
 /// <param name="mServer"></param>
 /// <param name="UserList"></param>
 /// <returns></returns>
 private static TreeNode GetInstanceNode(String mongoConnKey,
                                         ref ConfigHelper.MongoConnectionConfig config,
                                         MongoServer mongoConn,
                                         MongoServerInstance mMasterServerInstace,
                                         MongoServer mServer,
                                         EachDatabaseUser UserList)
 {
     Boolean isReplsetMasterServer = false;
     //无论如何,都改为主要服务器读优先
     if (mMasterServerInstace == null)
     {
         isReplsetMasterServer = true;
     }
     TreeNode SvrInstanceNode = new TreeNode();
     String ConnSvrKey;
     if (isReplsetMasterServer)
     {
         ConnSvrKey = mongoConnKey + "/" + mongoConnKey;
     }
     else
     {
         ConnSvrKey = mongoConnKey + "/" + mMasterServerInstace.Address.ToString().Replace(":", "@");
     }
     SvrInstanceNode.SelectedImageIndex = (int)GetSystemIcon.MainTreeImageType.WebServer;
     SvrInstanceNode.ImageIndex = (int)GetSystemIcon.MainTreeImageType.WebServer;
     if (isReplsetMasterServer)
     {
         SvrInstanceNode.Text = "Connection";
     }
     else
     {
         SvrInstanceNode.Text = "Server[" + mMasterServerInstace.Address.ToString() + "]";
     }
     if ((!String.IsNullOrEmpty(config.UserName)) & (!String.IsNullOrEmpty(config.Password)))
     {
         //是否是认证模式,应该取决于服务器!
         config.AuthMode = true;
     }
     //获取ReadOnly
     config.IsReadOnly = false;
     List<String> databaseNameList = new List<String>();
     if (!String.IsNullOrEmpty(config.DataBaseName))
     {
         //单数据库模式
         TreeNode mongoSingleDBNode;
         if (isReplsetMasterServer)
         {
             mongoSingleDBNode = FillDataBaseInfoToTreeNode(config.DataBaseName, mServer, mongoConnKey + "/" + mongoConnKey);
         }
         else
         {
             mongoSingleDBNode = FillDataBaseInfoToTreeNode(config.DataBaseName, mServer, mongoConnKey + "/" + mMasterServerInstace.Address.ToString());
         }
         mongoSingleDBNode.Tag = SINGLE_DATABASE_TAG + ":" + ConnSvrKey + "/" + config.DataBaseName;
         mongoSingleDBNode.SelectedImageIndex = (int)GetSystemIcon.MainTreeImageType.Database;
         mongoSingleDBNode.ImageIndex = (int)GetSystemIcon.MainTreeImageType.Database;
         SvrInstanceNode.Nodes.Add(mongoSingleDBNode);
         SvrInstanceNode.Tag = SINGLE_DB_SERVER_TAG + ":" + ConnSvrKey;
         ///获取User信息
         if (config.AuthMode)
         {
             try
             {
                 ///尝试添加用户信息
                 UserList.AddUser(mongoConn.GetDatabase(config.DataBaseName), config.UserName);
             }
             catch (Exception)
             {
                 //可能出现没有权限的问题,这里就认为无法取得权限
             }
         }
     }
     else
     {
         MongoServer InstantSrv;
         if (isReplsetMasterServer)
         {
             InstantSrv = mServer;
             databaseNameList = mServer.GetDatabaseNames().ToList<String>();
         }
         else
         {
             MongoClientSettings setting = CreateMongoClientSettingsByConfig(ref config);
             setting.ConnectionMode = ConnectionMode.Direct;
             //When Replset Case,Application need to read admin DB information
             //if Primary,there will be exception
             setting.ReadPreference = ReadPreference.PrimaryPreferred;
             setting.Server = mMasterServerInstace.Address;
             InstantSrv = new MongoClient(setting).GetServer();
             databaseNameList = InstantSrv.GetDatabaseNames().ToList<String>();
//.........这里部分代码省略.........
开发者ID:ZhenghaiYe,项目名称:MagicMongoDBTool,代码行数:101,代码来源:MongoDBHelper_Connection_Present.cs

示例4: GetInstanceNode

 /// <summary>
 /// 
 /// </summary>
 /// <param name="mongoConnKey"></param>
 /// <param name="config"></param>
 /// <param name="mongoConn"></param>
 /// <param name="mServerInstace"></param>
 /// <param name="mServer"></param>
 /// <returns></returns>
 private static TreeNode GetInstanceNode(String mongoConnKey, ConfigHelper.MongoConnectionConfig config,
                                         MongoServer mongoConn, MongoServerInstance mServerInstace, MongoServer mServer)
 {
     Boolean isServer = false;
     if (mServerInstace == null)
     {
         isServer = true;
     }
     TreeNode SvrInstanceNode = new TreeNode();
     String ConnSvrKey;
     if (isServer)
     {
         ConnSvrKey = mongoConnKey + "/" + mongoConnKey;
     }
     else
     {
         ConnSvrKey = mongoConnKey + "/" + mServerInstace.Address.ToString().Replace(":", "@");
     }
     SvrInstanceNode.SelectedImageIndex = (int)GetSystemIcon.MainTreeImageType.WebServer;
     SvrInstanceNode.ImageIndex = (int)GetSystemIcon.MainTreeImageType.WebServer;
     if (isServer)
     {
         SvrInstanceNode.Text = "Connection";
     }
     else
     {
         SvrInstanceNode.Text = "Server[" + mServerInstace.Address.ToString() + "]";
     }
     if ((!String.IsNullOrEmpty(config.UserName)) & (!String.IsNullOrEmpty(config.Password)))
     {
         config.AuthMode = true;
     }
     //获取ReadOnly
     config.IsReadOnly = false;
     List<String> databaseNameList = new List<String>();
     if (!String.IsNullOrEmpty(config.DataBaseName))
     {
         //单数据库模式
         TreeNode mongoSingleDBNode;
         if (isServer)
         {
             mongoSingleDBNode = FillDataBaseInfoToTreeNode(config.DataBaseName, mServer, mongoConnKey + "/" + mongoConnKey);
         }
         else
         {
             mongoSingleDBNode = FillDataBaseInfoToTreeNode(config.DataBaseName, mServerInstace.Server, mongoConnKey + "/" + mServerInstace.Address.ToString());
         }
         mongoSingleDBNode.Tag = SINGLE_DATABASE_TAG + ":" + ConnSvrKey + "/" + config.DataBaseName;
         mongoSingleDBNode.SelectedImageIndex = (int)GetSystemIcon.MainTreeImageType.Database;
         mongoSingleDBNode.ImageIndex = (int)GetSystemIcon.MainTreeImageType.Database;
         SvrInstanceNode.Nodes.Add(mongoSingleDBNode);
         SvrInstanceNode.Tag = SINGLE_DB_SERVER_TAG + ":" + ConnSvrKey;
         if (config.AuthMode)
         {
             config.IsReadOnly = mongoConn.GetDatabase(config.DataBaseName).FindUser(config.UserName).IsReadOnly;
         }
     }
     else
     {
         MongoServer InstantSrv;
         if (isServer)
         {
             InstantSrv = mServer;
             databaseNameList = mServer.GetDatabaseNames().ToList<String>();
         }
         else
         {
             MongoServerSettings setting = mongoConn.Settings.Clone();
             setting.ConnectionMode = ConnectionMode.Direct;
             //When Replset Case,Application need to read admin DB information
             //if Primary,there will be exception
             setting.ReadPreference = ReadPreference.PrimaryPreferred;
             setting.Server = mServerInstace.Address;
             InstantSrv = new MongoServer(setting);
             databaseNameList = InstantSrv.GetDatabaseNames().ToList<String>();
         }
         foreach (String strDBName in databaseNameList)
         {
             TreeNode mongoDBNode;
             try
             {
                 mongoDBNode = FillDataBaseInfoToTreeNode(strDBName, InstantSrv, ConnSvrKey);
                 mongoDBNode.ImageIndex = (int)GetSystemIcon.MainTreeImageType.Database;
                 mongoDBNode.SelectedImageIndex = (int)GetSystemIcon.MainTreeImageType.Database;
                 SvrInstanceNode.Nodes.Add(mongoDBNode);
                 if (strDBName == MongoDBHelper.DATABASE_NAME_ADMIN)
                 {
                     if (config.AuthMode)
                     {
                         config.IsReadOnly = mongoConn.GetDatabase(strDBName).FindUser(config.UserName).IsReadOnly;
                     }
//.........这里部分代码省略.........
开发者ID:peidachang,项目名称:MagicMongoDBTool,代码行数:101,代码来源:MongoDBHelper_Connection_Present.cs

示例5: Connected

        public bool Connected()
        {
            string msString = sPreMs + Server;
            ms = MongoServer.Create(msString);

            ms.Connect();
            //while (true)
            //{
            //    if (ms.State!= MongoServerState.Connecting)
            //    {
            //        break;
            //    }
            //    System.Threading.Thread.Sleep(1000);
            //}
            if (ms.State == MongoServerState.Connected)
            {
                 foreach(string s in ms.GetDatabaseNames())
                 {
                     Dbs.Add(ms.GetDatabase(s));
                 }

                return true;
            }
            return false;
        }
开发者ID:dingxinbei,项目名称:BMongoDB,代码行数:25,代码来源:DBData.cs


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