Example #1
0
        /// <summary>
        ///     Datas the base handler.
        /// </summary>
        /// <param name="strNodeType">String node type.</param>
        /// <param name="e">E.</param>
        private void DataBaseHandler(string strNodeType, TreeNodeMouseClickEventArgs e)
        {
            RuntimeMongoDbContext.SelectObjectTag = e.Node.Tag.ToString();
            var roles = MongoUserEx.GetCurrentDbRoles(RuntimeMongoDbContext.CurrentMongoConnectionconfig.ConnectionName,
                                                      RuntimeMongoDbContext.GetCurrentDataBaseName());

            if (GuiConfig.IsUseDefaultLanguage)
            {
                statusStripMain.Items[0].Text = "Selected DataBase:" + RuntimeMongoDbContext.SelectTagData;
            }
            else
            {
                statusStripMain.Items[0].Text =
                    GuiConfig.GetText(TextType.SelectedDataBase) + ":" +
                    RuntimeMongoDbContext.SelectTagData;
            }
            //系统库不允许修改
            if (!Operater.IsSystemDataBase(RuntimeMongoDbContext.GetCurrentDataBaseName()))
            {
                if (RuntimeMongoDbContext.CurrentMongoConnectionconfig.AuthMode)
                {
                    //根据Roles确定删除数据库/创建数据集等的权限
                    DelMongoDBToolStripMenuItem.Enabled = MongoAction.JudgeRightByBuildInRole(roles,
                                                                                              MongoAction.ActionType.ServerAdministrationActionsDropDatabase);
                    CreateMongoCollectionToolStripMenuItem.Enabled = MongoAction.JudgeRightByBuildInRole(roles,
                                                                                                         MongoAction.ActionType.DatabaseManagementActionsCreateCollection);
                    CopyDatabasetoolStripMenuItem.Enabled = true;
                    InitGFSToolStripMenuItem.Enabled      = MongoAction.JudgeRightByBuildInRole(roles,
                                                                                                MongoAction.ActionType.MiscActionsInitGfs);
                    AddUserToolStripMenuItem.Enabled = MongoAction.JudgeRightByBuildInRole(roles,
                                                                                           MongoAction.ActionType.DatabaseManagementActionsCreateUser);
                    //If a Slave server can repair database @ Master-Slave is not sure ??
                    RepairDBToolStripMenuItem.Enabled = MongoAction.JudgeRightByBuildInRole(roles,
                                                                                            MongoAction.ActionType.ServerAdministrationActionsRepairDatabase);
                }
                else
                {
                    DelMongoDBToolStripMenuItem.Enabled            = true;
                    CreateMongoCollectionToolStripMenuItem.Enabled = true;
                    CreateViewtoolStripMenuItem.Enabled            = true;
                    CopyDatabasetoolStripMenuItem.Enabled          = true;
                    InitGFSToolStripMenuItem.Enabled  = true;
                    AddUserToolStripMenuItem.Enabled  = true;
                    RepairDBToolStripMenuItem.Enabled = true;
                }
            }

            AddDBCustomeRoleStripMenuItem.Enabled = true;

            //使用Shell:从实际情况来看,有一些Shell指令是不依赖与Admin数据库或者和数据库无关的
            //所以这里暂时开放所有的Shell指令。
            EvalJSToolStripMenuItem.Enabled = true;
            //备份数据库
            DumpDatabaseToolStripMenuItem.Enabled = true;
            //Profilling
            ProfillingLevelToolStripMenuItem.Enabled = true;
            if (strNodeType == ConstMgr.SingleDatabaseTag)
            {
                DelMongoDBToolStripMenuItem.Enabled = false;
            }
            DBStatusToolStripMenuItem.Enabled = true;
            if (e.Button == MouseButtons.Right)
            {
                contextMenuStripMain = new ContextMenuStrip();
                if (SystemManager.MonoMode)
                {
                    //悲催MONO不支持
                    var delMongoDb = DelMongoDBToolStripMenuItem.Clone();
                    delMongoDb.Click += DelMongoDBToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(delMongoDb);

                    var createMongoCollection = CreateMongoCollectionToolStripMenuItem.Clone();
                    createMongoCollection.Click += CreateMongoCollectionToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(createMongoCollection);

                    var createView = CreateViewtoolStripMenuItem.Clone();
                    createView.Click += CreateViewtoolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(createView);

                    var addUser = AddUserToolStripMenuItem.Clone();
                    addUser.Click += AddUserToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(addUser);

                    var evalJs = EvalJSToolStripMenuItem.Clone();
                    evalJs.Click += evalJSToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(evalJs);

                    var repairDb = RepairDBToolStripMenuItem.Clone();
                    repairDb.Click += RepairDBToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(repairDb);


                    var initGfs = InitGFSToolStripMenuItem.Clone();
                    initGfs.Click += InitGFSToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(initGfs);

                    var dumpDatabase = DumpDatabaseToolStripMenuItem.Clone();
                    dumpDatabase.Click += DumpDatabaseToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(dumpDatabase);

                    var restoreMongo = RestoreMongoToolStripMenuItem.Clone();
                    restoreMongo.Click += RestoreMongoToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(restoreMongo);


                    contextMenuStripMain.Items.Add(new ToolStripSeparator());

                    var profillingLevel = ProfillingLevelToolStripMenuItem.Clone();
                    profillingLevel.Click += profillingLevelToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(profillingLevel);

                    var dbStatus = DBStatusToolStripMenuItem.Clone();
                    dbStatus.Click += DBStatusToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(dbStatus);
                }
                else
                {
                    contextMenuStripMain.Items.Add(DelMongoDBToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(CreateMongoCollectionToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(CreateViewtoolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(CopyDatabasetoolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(AddUserToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(AddDBCustomeRoleStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(EvalJSToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(RepairDBToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(InitGFSToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(DumpDatabaseToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(RestoreMongoToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(new ToolStripSeparator());
                    contextMenuStripMain.Items.Add(ProfillingLevelToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(DBStatusToolStripMenuItem.Clone());
                }
                e.Node.ContextMenuStrip = contextMenuStripMain;
                contextMenuStripMain.Show(trvsrvlst.PointToScreen(e.Location));
            }
        }
        private void DataBaseHandler(string strNodeType, TreeNodeMouseClickEventArgs e)
        {
            RuntimeMongoDbContext.SelectObjectTag = e.Node.Tag.ToString();
            var roles = User.GetCurrentDbRoles(RuntimeMongoDbContext.CurrentMongoConnectionconfig.ConnectionName,
                                               RuntimeMongoDbContext.GetCurrentDataBaseName());

            if (GuiConfig.IsUseDefaultLanguage)
            {
                statusStripMain.Items[0].Text = "Selected DataBase:" + RuntimeMongoDbContext.SelectTagData;
            }
            else
            {
                statusStripMain.Items[0].Text =
                    GuiConfig.GetText(TextType.SelectedDataBase) + ":" +
                    RuntimeMongoDbContext.SelectTagData;
            }
            //系统库不允许修改
            if (!Operater.IsSystemDataBase(RuntimeMongoDbContext.GetCurrentDataBaseName()))
            {
                if (RuntimeMongoDbContext.CurrentMongoConnectionconfig.AuthMode)
                {
                    //根据Roles确定删除数据库/创建数据集等的权限
                    DelMongoDBToolStripMenuItem.Enabled = MongoDbAction.JudgeRightByBuildInRole(roles,
                                                                                                MongoDbAction.ActionType.ServerAdministrationActionsDropDatabase);
                    CreateMongoCollectionToolStripMenuItem.Enabled = MongoDbAction.JudgeRightByBuildInRole(roles,
                                                                                                           MongoDbAction.ActionType.DatabaseManagementActionsCreateCollection);
                    InitGFSToolStripMenuItem.Enabled = MongoDbAction.JudgeRightByBuildInRole(roles,
                                                                                             MongoDbAction.ActionType.MiscInitGfs);
                    AddUserToolStripMenuItem.Enabled = MongoDbAction.JudgeRightByBuildInRole(roles,
                                                                                             MongoDbAction.ActionType.DatabaseManagementActionsCreateUser);
                    //If a Slave server can repair database @ Master-Slave is not sure ??
                    RepairDBToolStripMenuItem.Enabled = MongoDbAction.JudgeRightByBuildInRole(roles,
                                                                                              MongoDbAction.ActionType.ServerAdministrationActionsRepairDatabase);
                }
                else
                {
                    DelMongoDBToolStripMenuItem.Enabled            = true;
                    CreateMongoCollectionToolStripMenuItem.Enabled = true;
                    InitGFSToolStripMenuItem.Enabled  = true;
                    AddUserToolStripMenuItem.Enabled  = true;
                    RepairDBToolStripMenuItem.Enabled = true;
                }
                EvalJSToolStripMenuItem.Enabled = MongoDbAction.JudgeRightByBuildInRole(roles,
                                                                                        MongoDbAction.ActionType.MiscEvalJs);
            }
            //备份数据库
            DumpDatabaseToolStripMenuItem.Enabled    = true;
            ProfillingLevelToolStripMenuItem.Enabled = true;
            if (strNodeType == ConstMgr.SingleDatabaseTag)
            {
                DelMongoDBToolStripMenuItem.Enabled = false;
            }
            DBStatusToolStripMenuItem.Enabled = true;
            if (e.Button == MouseButtons.Right)
            {
                contextMenuStripMain = new ContextMenuStrip();
                if (SystemManager.MonoMode)
                {
                    //悲催MONO不支持
                    var t1 = DelMongoDBToolStripMenuItem.Clone();
                    t1.Click += DelMongoDBToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t1);

                    var t2 = CreateMongoCollectionToolStripMenuItem.Clone();
                    t2.Click += CreateMongoCollectionToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t2);

                    var t3 = AddUserToolStripMenuItem.Clone();
                    t3.Click += AddUserToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t3);

                    var t4 = EvalJSToolStripMenuItem.Clone();
                    t4.Click += evalJSToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t4);

                    var t5 = RepairDBToolStripMenuItem.Clone();
                    t5.Click += RepairDBToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t5);


                    var t6 = InitGFSToolStripMenuItem.Clone();
                    t6.Click += InitGFSToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t6);

                    var t7 = DumpDatabaseToolStripMenuItem.Clone();
                    t7.Click += DumpDatabaseToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t7);

                    var t8 = RestoreMongoToolStripMenuItem.Clone();
                    t8.Click += RestoreMongoToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t8);


                    contextMenuStripMain.Items.Add(new ToolStripSeparator());

                    var t10 = ProfillingLevelToolStripMenuItem.Clone();
                    t10.Click += profillingLevelToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t10);

                    var t11 = DBStatusToolStripMenuItem.Clone();
                    t11.Click += DBStatusToolStripMenuItem_Click;
                    contextMenuStripMain.Items.Add(t11);
                }
                else
                {
                    contextMenuStripMain.Items.Add(DelMongoDBToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(CreateMongoCollectionToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(AddUserToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(AddDBCustomeRoleStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(EvalJSToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(RepairDBToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(InitGFSToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(DumpDatabaseToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(RestoreMongoToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(new ToolStripSeparator());
                    contextMenuStripMain.Items.Add(ProfillingLevelToolStripMenuItem.Clone());
                    contextMenuStripMain.Items.Add(DBStatusToolStripMenuItem.Clone());
                }
                e.Node.ContextMenuStrip = contextMenuStripMain;
                contextMenuStripMain.Show(trvsrvlst.PointToScreen(e.Location));
            }
        }