Exemplo n.º 1
0
        /// <summary>
        ///     Fill Database status to ListView
        /// </summary>
        /// <param name="lstSvr"></param>
        public static void FillDataBaseStatusToList(CtlTreeViewColumns lstSvr,
                                                    Dictionary <string, MongoServer> mongoConnSvrLst)
        {
            var dbStatusList = new List <BsonDocument>();

            foreach (var mongoSvrKey in mongoConnSvrLst.Keys)
            {
                var mongoSvr         = mongoConnSvrLst[mongoSvrKey];
                var databaseNameList = mongoSvr.GetDatabaseNames().ToList();
                foreach (var strDbName in databaseNameList)
                {
                    var mongoDb  = mongoSvr.GetDatabase(strDbName);
                    var dbStatus = mongoDb.GetStats();
                    dbStatusList.Add(dbStatus.Response);
                }
            }
            UiHelper.FillDataToTreeView("DataBase Status", lstSvr, dbStatusList, 0);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Fill Client status to ListView
        /// </summary>
        /// <param name="trvSvrStatus"></param>
        /// <param name="mongoConnClientLst"></param>
        public static void FillClientStatusToList(CtlTreeViewColumns trvSvrStatus,
                                                  Dictionary <string, MongoClient> mongoConnClientLst)
        {
            var srvDocList = new List <BsonDocument>();

            foreach (var mongoSvrKey in mongoConnClientLst.Keys)
            {
                if (!MongoConnectionConfig.MongoConfig.ConnectionList[mongoSvrKey].Health)
                {
                    continue;
                }
                try
                {
                    var mongoClient = mongoConnClientLst[mongoSvrKey];
                    //flydreamer提供的代码
                    // 感谢 魏琼东 的Bug信息,一些命令必须以Admin执行
                    if (RuntimeMongoDbContext.GetServerConfigBySvrPath(mongoSvrKey).LoginAsAdmin)
                    {
                        var adminDb = mongoClient.GetDatabase(ConstMgr.DatabaseNameAdmin);
                        //Can't Convert IMongoDB To MongoDB
                        var command = new CommandDocument {
                            { DataBaseCommand.ServerStatusCommand.CommandString, 1 }
                        };
                        var serverStatusDoc = CommandExecute.ExecuteMongoDBCommand(command, adminDb).Response;
                        srvDocList.Add(serverStatusDoc);
                    }
                }
                catch (Exception ex)
                {
                    Utility.ExceptionDeal(ex);
                }
            }
            UiHelper.FillDataToTreeView("Server Status", trvSvrStatus, srvDocList, 0);
            //打开第一层
            foreach (TreeNode item in trvSvrStatus.DatatreeView.Nodes)
            {
                item.Expand();
            }
        }