Example #1
0
 /// <summary>
 ///     获得JS名称列表
 /// </summary>
 /// <returns></returns>
 public static List <string> GetJsNameList()
 {
     return
         (GetCurrentJsCollection(RuntimeMongoDbContext.GetCurrentDataBase())
          .FindAllAs <BsonDocument>()
          .Select(item => item.GetValue(ConstMgr.KeyId).ToString())
          .OrderBy(item => item)
          .ToList());
 }
Example #2
0
 /// <summary>
 ///     设置DataFilter
 /// </summary>
 private void SetCurrDataFilter()
 {
     //清除以前的结果和内部变量,重要!
     _currentDataViewInfo.MDataFilter.Clear();
     _currentDataViewInfo.MDataFilter.DbName         = RuntimeMongoDbContext.GetCurrentDataBase().Name;
     _currentDataViewInfo.MDataFilter.CollectionName = RuntimeMongoDbContext.GetCurrentCollection().Name;
     _currentDataViewInfo.MDataFilter.QueryFieldList = QueryFieldPicker.GetQueryFieldList();
     ConditionPan.SetCurrDataFilter(_currentDataViewInfo);
 }
Example #3
0
        /// <summary>
        ///     Js数据集初始化
        /// </summary>
        public static void InitJavascript()
        {
            var mongDb = RuntimeMongoDbContext.GetCurrentDataBase();

            if (!mongDb.CollectionExists(ConstMgr.CollectionNameJavascript))
            {
                mongDb.CreateCollection(ConstMgr.CollectionNameJavascript);
            }
        }
Example #4
0
        /// <summary>
        ///     GFS初始化
        /// </summary>
        public static void InitGfs()
        {
            var mongoDb = RuntimeMongoDbContext.GetCurrentDataBase();

            if (!mongoDb.CollectionExists(ConstMgr.CollectionNameGfsFiles))
            {
                mongoDb.CreateCollection(ConstMgr.CollectionNameGfsFiles);
            }
        }
Example #5
0
        /// <summary>
        ///     Remove A User From Admin database
        /// </summary>
        /// <param name="strUser">UserName</param>
        public static void RemoveUserFromSystem(string strUser, bool isAdmin)
        {
            MongoCollection users;

            users = isAdmin
                ? RuntimeMongoDbContext.GetCurrentServer()
                    .GetDatabase(ConstMgr.DatabaseNameAdmin)
                    .GetCollection(ConstMgr.CollectionNameUsers)
                : RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(ConstMgr.CollectionNameUsers);
            users.Remove(Query.EQ("user", strUser));
        }
Example #6
0
        /// <summary>
        ///     Upload File
        /// </summary>
        private void UploadFileStripButton_Click(object sender, EventArgs e)
        {
            var upfile = new OpenFileDialog();

            if (upfile.ShowDialog() == DialogResult.OK)
            {
                var opt = GetUploadFileOption();
                Gfs.UpLoadFile(upfile.FileName, opt, RuntimeMongoDbContext.GetCurrentDataBase());
                RefreshGui();
            }
        }
Example #7
0
 /// <summary>
 ///     Open File
 /// </summary>
 private void OpenFileStripButton_Click(object sender, EventArgs e)
 {
     if (lstData.SelectedItems.Count == 1)
     {
         var strFileName = lstData.SelectedItems[0].Text;
         Gfs.OpenFile(strFileName, RuntimeMongoDbContext.GetCurrentDataBase());
     }
     else
     {
         MessageBox.Show("请选择一个文件");
     }
 }
Example #8
0
        /// <summary>
        ///     eval Javascript
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdEval_Click(object sender, EventArgs e)
        {
            var mongoDb = RuntimeMongoDbContext.GetCurrentDataBase();
            var js      = new BsonJavaScript(ctlEval.Context);
            var Params  = new List <BsonValue>();

            if (txtParm.Text != string.Empty)
            {
                foreach (var parm in txtParm.Text.Split(",".ToCharArray()))
                {
                    if (parm.StartsWith("'") & parm.EndsWith("'"))
                    {
                        Params.Add(parm.Trim("'".ToCharArray()));
                    }
                    else
                    {
                        try
                        {
                            var isNuberic = true;
                            for (var i = 0; i < parm.Length; i++)
                            {
                                if (!char.IsNumber(parm, i))
                                {
                                    isNuberic = false;
                                }
                            }
                            if (isNuberic)
                            {
                                Params.Add(Convert.ToInt16(parm));
                            }
                        }
                        catch (Exception ex)
                        {
                            Utility.ExceptionDeal(ex, "Exception", "Parameter Exception");
                        }
                    }
                }
            }
            try
            {
                var args = new EvalArgs {
                    Args = Params.ToArray(), Code = js
                };
                var result = mongoDb.Eval(args);
                MyMessageBox.ShowMessage("Result", "Result",
                                         result.ToJson(MongoHelper.JsonWriterSettings), true);
            }
            catch (Exception ex)
            {
                Utility.ExceptionDeal(ex, "Exception", "Result");
            }
        }
Example #9
0
 private void frmUser_Load(object sender, EventArgs e)
 {
     if (_modifyName != string.Empty)
     {
         Text = "Change User Config";
         txtUserName.Enabled = false;
         txtUserName.Text    = _modifyName;
         var userInfo = RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(ConstMgr.CollectionNameUser)
                        .FindOneAs <BsonDocument>(Query.EQ("user", _modifyName));
         userRoles.SetRoles(userInfo["roles"].AsBsonArray);
         _otherDbRolesDict.Clear();
         foreach (var item in userInfo["otherDBRoles"].AsBsonDocument)
         {
             _otherDbRolesDict.Add(item.Name, item);
         }
         RefreshOtherDbRoles();
     }
     if (!GuiConfig.IsUseDefaultLanguage)
     {
         if (_modifyName == string.Empty)
         {
             Text = GuiConfig.GetText(_isAdmin
                 ? TextType.MainMenuOperationServerAddUserToAdmin
                 : TextType.MainMenuOperationDatabaseAddUser);
             if (!GuiConfig.IsMono)
             {
                 Icon = GetSystemIcon.ConvertImgToIcon(Resources.AddUserToDB);
             }
         }
         else
         {
             if (!GuiConfig.IsMono)
             {
                 Icon = GetSystemIcon.ConvertImgToIcon(Resources.DBkey);
             }
             Text = GuiConfig.GetText(TextType.CommonChangePassword);
         }
         lblUserName.Text =
             GuiConfig.GetText(TextType.CommonUsername);
         lblPassword.Text =
             GuiConfig.GetText(TextType.CommonPassword);
         lblConfirmPsw.Text =
             GuiConfig.GetText(TextType.CommonConfirmPassword);
         //chkReadOnly.Text = GUIConfig.GetText(MongoCola.Module.ResourceLib.MongoHelper.TextType.Common_ReadOnly);
         colRoles.Text    = GuiConfig.GetText(TextType.CommonRoles);
         colDataBase.Text =
             GuiConfig.GetText(TextType.CommonDataBase);
         cmdOK.Text     = GuiConfig.GetText(TextType.CommonOk);
         cmdCancel.Text = GuiConfig.GetText(TextType.CommonCancel);
     }
 }
Example #10
0
        /// <summary>
        ///     当前对象的MONGO命令
        /// </summary>
        /// <param name="mMongoCommand">命令对象</param>
        /// <param name="Obj"></param>
        /// <returns></returns>
        public static CommandResult ExecuteMongoCommand(MongoCommand mMongoCommand)
        {
            var resultCommandList = new List <CommandResult>();

            var mCommandResult = new CommandResult(new BsonDocument());

            try
            {
                switch (mMongoCommand.RunLevel)
                {
                case EnumMgr.PathLevel.Collection:
                    if (string.IsNullOrEmpty(mMongoCommand.CommandString))
                    {
                        mCommandResult = ExecuteMongoColCommand(mMongoCommand.CmdDocument,
                                                                RuntimeMongoDbContext.GetCurrentCollection());
                    }
                    else
                    {
                        mCommandResult = ExecuteMongoColCommand(mMongoCommand.CommandString,
                                                                RuntimeMongoDbContext.GetCurrentCollection());
                    }
                    break;

                case EnumMgr.PathLevel.Database:
                    mCommandResult = ExecuteMongoDBCommand(mMongoCommand.CmdDocument,
                                                           RuntimeMongoDbContext.GetCurrentDataBase());
                    break;

                case EnumMgr.PathLevel.Instance:
                    mCommandResult = ExecuteMongoSvrCommand(mMongoCommand.CmdDocument,
                                                            RuntimeMongoDbContext.GetCurrentServer());
                    break;

                default:
                    break;
                }
                resultCommandList.Add(mCommandResult);
            }
            catch (IOException ex)
            {
                Utility.ExceptionDeal(ex, mMongoCommand.CommandString,
                                      "IOException,Try to set Socket TimeOut more long at connection config");
            }
            catch (Exception ex)
            {
                Utility.ExceptionDeal(ex, mMongoCommand.CommandString);
            }

            return(mCommandResult);
        }
Example #11
0
        /// <summary>
        ///     Delete File
        /// </summary>
        public void DeleteFileStripButton_Click(object sender, EventArgs e)
        {
            var strTitle   = GuiConfig.GetText("Delete Files", "DropData");
            var strMessage = GuiConfig.GetText("Are you sure to delete selected File(s)?", "DropDataConfirm");

            if (MyMessageBox.ShowConfirm(strTitle, strMessage))
            {
                foreach (ListViewItem item in lstData.SelectedItems)
                {
                    Gfs.DelFile(item.Text, RuntimeMongoDbContext.GetCurrentDataBase());
                }
                RefreshGui();
            }
        }
Example #12
0
        /// <summary>
        ///     DownLoad File
        /// </summary>
        public void DownloadFileStripButton_Click(object sender, EventArgs e)
        {
            var downfile    = new SaveFileDialog();
            var strFileName = lstData.SelectedItems[0].Text;

            //For Winodws,Linux user DirectorySeparatorChar Replace with @"\"
            downfile.FileName =
                strFileName.Split(Path.DirectorySeparatorChar)[strFileName.Split(Path.DirectorySeparatorChar).Length - 1
                ];
            if (downfile.ShowDialog() == DialogResult.OK)
            {
                Gfs.DownloadFile(downfile.FileName, strFileName, RuntimeMongoDbContext.GetCurrentDataBase());
            }
            RefreshGui();
        }
Example #13
0
        /// <summary>
        ///     Upload File
        /// </summary>
        private void UploadFileStripButton_Click(object sender, EventArgs e)
        {
            var upfile = new OpenFileDialog();

            if (upfile.ShowDialog() == DialogResult.OK)
            {
                var opt = new Gfs.UpLoadFileOption();
                var frm = new FrmGfsOption();
                frm.ShowDialog();
                opt.AlreadyOpt             = frm.Option;
                opt.DirectorySeparatorChar = frm.DirectorySeparatorChar;
                opt.FileNameOpt            = frm.Filename;
                opt.IgnoreSubFolder        = frm.IgnoreSubFolder;
                Gfs.UpLoadFile(upfile.FileName, opt, RuntimeMongoDbContext.GetCurrentDataBase());
                RefreshGui();
            }
        }
Example #14
0
 /// <summary>
 ///     设置DataFilter
 /// </summary>
 private void SetCurrentDataFilter()
 {
     //清除以前的结果和内部变量,重要!
     //FieldList 和 FieldPicker 是引用关系,所以这里Clear掉之后FieldPicker也会被清除掉。GetQueryFieldList就会始终为空!
     _currentDataViewInfo.MDataFilter.QueryConditionList.Clear();
     _currentDataViewInfo.MDataFilter.DbName         = RuntimeMongoDbContext.GetCurrentDataBase().Name;
     _currentDataViewInfo.MDataFilter.CollectionName = RuntimeMongoDbContext.GetCurrentCollection().Name;
     _currentDataViewInfo.MDataFilter.QueryFieldList = QueryFieldPicker.GetQueryFieldList();
     ConditionPan.SetCurrDataFilter(_currentDataViewInfo);
     if (RuntimeMongoDbContext.CollectionFilter.ContainsKey(RuntimeMongoDbContext.GetCurrentCollectionName()))
     {
         RuntimeMongoDbContext.CollectionFilter[RuntimeMongoDbContext.GetCurrentCollectionName()] = _currentDataViewInfo.MDataFilter;
     }
     else
     {
         RuntimeMongoDbContext.CollectionFilter.Add(RuntimeMongoDbContext.GetCurrentCollectionName(), _currentDataViewInfo.MDataFilter);
     }
 }
Example #15
0
        /// <summary>
        ///     AddUserToSystem
        /// </summary>
        /// <param name="newUserEx">用户信息</param>
        /// <param name="isAdmin">是否是Admin</param>
        public static void AddUserToSystem(User newUserEx, bool isAdmin)
        {
            //必须使用MongoCredentials来添加用户,不然的话,Password将使用明文登入到数据库中!
            //这样的话,在使用MongoCredentials登入的时候,会发生密码错误引发的认证失败
            MongoCollection users;

            users = isAdmin
                ? RuntimeMongoDbContext.GetCurrentServer()
                    .GetDatabase(ConstMgr.DatabaseNameAdmin)
                    .GetCollection(ConstMgr.CollectionNameUser)
                : RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(ConstMgr.CollectionNameUser);
            //以下代码 1.Ver2.4以前的有ReadOnly,FindUser需要寻找ReadOnly字段
            //        2.这个其实不用检查,有的话修改,没有的话,新建
            //if (users.Database.FindUser(newUserEx.Username) == null)
            //{
            AddUserEx(users, newUserEx);
            //}
        }
Example #16
0
        /// <summary>
        ///     执行js
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void butEval_Click(object sender, EventArgs e)
        {
            var mongoDb = RuntimeMongoDbContext.GetCurrentDataBase();
            var js      = new BsonJavaScript(txtParameter.Text);

            try
            {
                var args = new EvalArgs {
                    Code = js
                };
                var result = mongoDb.Eval(args);
                txtEvalJavaScript.Text = ToJson(result);
            }
            catch (Exception ex)
            {
                txtEvalJavaScript.Text = ex.Message;
            }
        }
Example #17
0
        private void frmStatus_Load(object sender, EventArgs e)
        {
            var strType   = RuntimeMongoDbContext.SelectTagType;
            var docStatus = new BsonDocument();

            switch (strType)
            {
            case ConstMgr.ServerTag:
            case ConstMgr.SingleDbServerTag:
                if (RuntimeMongoDbContext.GetCurrentServerConfig().LoginAsAdmin)
                {
                    docStatus =
                        CommandExecute.ExecuteMongoSvrCommand(DataBaseCommand.ServerStatusCommand,
                                                              RuntimeMongoDbContext.GetCurrentServer()).Response;
                    trvStatus.Height = trvStatus.Height * 2;
                }
                break;

            case ConstMgr.DatabaseTag:
            case ConstMgr.SingleDatabaseTag:
                docStatus = RuntimeMongoDbContext.GetCurrentDataBase().GetStats().Response.ToBsonDocument();
                break;

            case ConstMgr.CollectionTag:
                //TODO:这里无法看到Collection的Document Validation信息。
                docStatus = RuntimeMongoDbContext.GetCurrentCollection().GetStats().Response.ToBsonDocument();

                break;

            default:
                if (RuntimeMongoDbContext.GetCurrentServerConfig().LoginAsAdmin)
                {
                    docStatus =
                        CommandExecute.ExecuteMongoSvrCommand(DataBaseCommand.ServerStatusCommand,
                                                              RuntimeMongoDbContext.GetCurrentServer()).Response;
                    trvStatus.Height = trvStatus.Height * 2;
                }
                break;
            }
            GuiConfig.Translateform(this);
            UiHelper.FillDataToTreeView(strType, trvStatus, docStatus);
            trvStatus.DatatreeView.Nodes[0].Expand();
        }
 /// <summary>
 ///     OK
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdOK_Click(object sender, EventArgs e)
 {
     //不支持中文 JIRA ticket is created : SERVER-4412
     //SERVER-4412已经在2013/03解决了
     //collection names are limited to 121 bytes after converting to UTF-8.
     if (txtCollectionName.Text == string.Empty)
     {
         return;
     }
     try
     {
         string errMessage;
         RuntimeMongoDbContext.GetCurrentDataBase().IsCollectionNameValid(txtCollectionName.Text, out errMessage);
         if (errMessage != null)
         {
             MyMessageBox.ShowMessage("Create MongoDatabase", "Argument Exception", errMessage, true);
             return;
         }
         if (chkAdvance.Checked)
         {
             var option = new CollectionOptionsBuilder();
             option.SetCapped(chkIsCapped.Checked);
             option.SetMaxSize((long)numMaxSize.Value);
             option.SetMaxDocuments((long)numMaxDocument.Value);
             //CappedCollection Default is AutoIndexId After MongoDB 2.2.2
             option.SetAutoIndexId(chkIsAutoIndexId.Checked);
             Result = Operater.CreateCollectionWithOptions(StrSvrPathWithTag, txtCollectionName.Text,
                                                           option, RuntimeMongoDbContext.GetCurrentDataBase());
         }
         else
         {
             Result = Operater.CreateCollection(StrSvrPathWithTag, txtCollectionName.Text,
                                                RuntimeMongoDbContext.GetCurrentDataBase());
         }
         Close();
     }
     catch (ArgumentException ex)
     {
         Utility.ExceptionDeal(ex, "Create MongoDatabase", "Argument Exception");
         Result = false;
     }
 }
        /// <summary>
        ///     ConvertToCapped
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConvertToCappedtoolStripMenuItem_Click(object sender, EventArgs e)
        {
            var maxSize = MyMessageBox.ShowInput("Please Input MaxSize(Byte)", "MaxSize", "4096");

            if (string.IsNullOrEmpty(maxSize))
            {
                return;
            }
            if (long.TryParse(maxSize, out long lngMaxSize))
            {
                var colName = RuntimeMongoDbContext.GetCurrentCollectionName();
                var db      = RuntimeMongoDbContext.GetCurrentDataBase();
                var result  = DataBaseCommand.convertToCapped(colName, lngMaxSize, db);
                MyMessageBox.ShowEasyMessage("ConvertToCapped", result.Response.ToString());
            }
            else
            {
                MessageBox.Show("Please Input a Number");
            }
        }
Example #20
0
 /// <summary>
 ///     复制
 /// </summary>
 private void Copy(MongoDatabase toDb)
 {
     ChangeEnable(false);
     try
     {
         //获取选中的表
         for (var index = 0; index < _selectCollection.Count; index++)
         {
             var name = _selectCollection[index];
             Operater.CopyCollection(RuntimeMongoDbContext.GetCurrentDataBase(), toDb, name, false);
             ChangeProgress(index);
         }
         MessageBox.Show(@"OK");
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
     ChangeEnable(true);
 }
Example #21
0
        /// <summary>
        ///     加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmProfilling_Load(object sender, EventArgs e)
        {
            GuiConfig.Translateform(this);
            cmbProfillingLv.Items.Add("0-No Logging");
            cmbProfillingLv.Items.Add("1-Log Slow Operations");
            cmbProfillingLv.Items.Add("2-Log All Operations");
            cmbProfillingLv.SelectedIndex = (int)RuntimeMongoDbContext.GetCurrentDataBase().GetProfilingLevel().Level;
            switch (cmbProfillingLv.SelectedIndex)
            {
            case 1:
                NumTime.Enabled = true;
                NumTime.Value   =
                    (decimal)RuntimeMongoDbContext.GetCurrentDataBase().GetProfilingLevel().Slow.TotalSeconds *
                    1000;
                break;

            default:
                NumTime.Enabled = false;
                break;
            }
        }
Example #22
0
        /// <summary>
        /// </summary>
        /// <param name="uploadDir"></param>
        /// <param name="fileCount"></param>
        /// <param name="opt"></param>
        /// <returns>是否继续执行后续的所有操作</returns>
        private bool UploadFolder(DirectoryInfo uploadDir, ref int fileCount, Gfs.UpLoadFileOption opt)
        {
            foreach (var file in uploadDir.GetFiles())
            {
                var rtn = Gfs.UpLoadFile(file.FullName, opt, RuntimeMongoDbContext.GetCurrentDataBase());
                switch (rtn)
                {
                case Gfs.UploadResult.Complete:
                    fileCount++;
                    break;

                case Gfs.UploadResult.Skip:
                    if (opt.AlreadyOpt == Gfs.EnumGfsAlready.Stop)
                    {
                        //这个操作返回为False,停止包括父亲过程在内的所有操作
                        return(false);
                    }
                    break;

                case Gfs.UploadResult.Exception:
                    return(MyMessageBox.ShowConfirm("Upload Exception", "Is Continue?"));
                }
            }
            if (!opt.IgnoreSubFolder)
            {
                foreach (var dir in uploadDir.GetDirectories())
                {
                    //递归文件夹操作,如果下层有任何停止的意愿,则立刻停止,并且使上层也立刻停止
                    var isContinue = UploadFolder(dir, ref fileCount, opt);
                    if (!isContinue)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #23
0
        /// <summary>
        ///     拖曳终止
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstData_DragDrop(object sender, DragEventArgs e)
        {
            Array UploadfileList = (Array)e.Data.GetData(DataFormats.FileDrop);

            if (!MyMessageBox.ShowConfirm("UploadFile", "是否上传" + UploadfileList.Length + "个文件"))
            {
                return;
            }
            var opt = new Gfs.UpLoadFileOption();
            var frm = new FrmGfsOption();

            frm.ShowDialog();
            opt.AlreadyOpt             = frm.Option;
            opt.DirectorySeparatorChar = frm.DirectorySeparatorChar;
            opt.FileNameOpt            = frm.Filename;
            opt.IgnoreSubFolder        = frm.IgnoreSubFolder;
            var count = 0;

            foreach (string UploadFilename in UploadfileList)
            {
                if (File.Exists(UploadFilename))
                {
                    Gfs.UpLoadFile(UploadFilename, opt, RuntimeMongoDbContext.GetCurrentDataBase());
                    count++;
                }
                else
                {
                    if (Directory.Exists(UploadFilename))
                    {
                        var uploadDir = new DirectoryInfo(UploadFilename);
                        UploadFolder(uploadDir, ref count, opt);
                    }
                }
            }
            RefreshGui();
            MyMessageBox.ShowMessage("Upload", "Upload Completed! Upload Files Count: " + count);
        }
Example #24
0
        /// <summary>
        ///     数据绑定
        /// </summary>
        private void DataBind()
        {
            ChangeEnable(false);

            try
            {
                //数据来源绑定
                var db       = RuntimeMongoDbContext.GetCurrentDataBase();
                var treeNode = new TreeNode(db.Name);
                foreach (var name in db.GetCollectionNames())
                {
                    treeNode.Nodes.Add(name);
                }
                TreeNodeBind(treeNode);

                ComboxBind(comboBoxServer, RuntimeMongoDbContext.MongoConnSvrLst);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            ChangeEnable(true);
        }
Example #25
0
        private void RefreshDbStatusChart(string strField)
        {
            //图形化初始化
            chartResult.Series.Clear();
            chartResult.Titles.Clear();
            var seriesResult = new Series(strField);
            var viewlist     = RuntimeMongoDbContext.GetCurrentDBViewNameList();

            foreach (var colName in RuntimeMongoDbContext.GetCurrentDataBase().GetCollectionNames())
            {
                if (viewlist.Contains(colName))
                {
                    continue;
                }
                DataPoint colPoint = new DataPoint(0, 0);
                switch (strField)
                {
                case "AverageObjectSize":
                    if (RuntimeMongoDbContext.GetCurrentDataBase()
                        .GetCollection(colName).GetStats().ObjectCount > 0)
                    {
                        //如果没有任何对象的时候,平均值无法取得
                        colPoint = new DataPoint(0, RuntimeMongoDbContext.GetCurrentDataBase()
                                                 .GetCollection(colName)
                                                 .GetStats()
                                                 .AverageObjectSize);
                    }
                    else
                    {
                        colPoint = new DataPoint(0, 0);
                    }
                    break;

                case "DataSize":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().DataSize);
                    break;

                case "ExtentCount":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().ExtentCount);
                    break;

                case "IndexCount":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().IndexCount);
                    break;

                case "LastExtentSize":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().LastExtentSize);
                    break;

                case "MaxDocuments":
                    //    仅在CappedCollection时候有效
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().MaxDocuments);
                    break;

                case "ObjectCount":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().ObjectCount);
                    break;

                case "PaddingFactor":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().PaddingFactor);
                    break;

                case "StorageSize":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().StorageSize);
                    break;

                default:
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().StorageSize);
                    break;
                }

                colPoint.LegendText   = colName;
                colPoint.LabelToolTip = colName;
                colPoint.ToolTip      = colName;
                seriesResult.Points.Add(colPoint);
            }
            //图形化加载

            seriesResult.ChartType = SeriesChartType.Pie;
            chartResult.Series.Add(seriesResult);
            chartResult.Titles.Add(new Title(strField));
        }
Example #26
0
        /// <summary>
        ///     Is Exist by Key
        /// </summary>
        /// <param name="keyValue">KeyValue</param>
        /// <returns></returns>
        public static bool IsExistByKey(string keyValue)
        {
            var mongoCol = MongoHelper.GetCurrentJsCollection(RuntimeMongoDbContext.GetCurrentDataBase());

            return(mongoCol.FindAs <BsonDocument>(Query.EQ(ConstMgr.KeyId, keyValue)).Any());
        }
Example #27
0
        private void RefreshDbStatusChart(string strField)
        {
            //图形化初始化
            chartResult.Series.Clear();
            chartResult.Titles.Clear();
            var seriesResult = new Series(strField);

            foreach (var colName in RuntimeMongoDbContext.GetCurrentDataBase().GetCollectionNames())
            {
                DataPoint colPoint = null;
                switch (strField)
                {
                case "AverageObjectSize":
                    try
                    {
                        if (RuntimeMongoDbContext.GetCurrentDataBase()
                            .GetCollection(colName).GetStats().ObjectCount > 0)
                        {
                            //如果没有任何对象的时候,平均值无法取得
                            colPoint = new DataPoint(0,
                                                     RuntimeMongoDbContext.GetCurrentDataBase()
                                                     .GetCollection(colName)
                                                     .GetStats()
                                                     .AverageObjectSize);
                        }
                        else
                        {
                            colPoint = new DataPoint(0, 0);
                        }
                    }
                    catch (Exception ex)
                    {
                        Utility.ExceptionDeal(ex);
                    }
                    break;

                case "DataSize":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().DataSize);
                    break;

                case "ExtentCount":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().ExtentCount);
                    break;

                //case "Flags":
                //    ColPoint = new DataPoint(0, MongoHelper.Core.RuntimeMongoDBContext.GetCurrentDataBase().GetCollection(colName).GetStats().Flags);
                //    break;
                case "IndexCount":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().IndexCount);
                    break;

                case "LastExtentSize":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().LastExtentSize);
                    break;

                case "MaxDocuments":
                    //    仅在CappedCollection时候有效
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().MaxDocuments);
                    break;

                case "ObjectCount":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().ObjectCount);
                    break;

                case "PaddingFactor":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().PaddingFactor);
                    break;

                case "StorageSize":
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().StorageSize);
                    break;

                default:
                    colPoint = new DataPoint(0,
                                             RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(colName).GetStats().StorageSize);
                    break;
                }

                colPoint.LegendText   = colName;
                colPoint.LabelToolTip = colName;
                colPoint.ToolTip      = colName;
                seriesResult.Points.Add(colPoint);
            }
            //图形化加载

            seriesResult.ChartType = SeriesChartType.Pie;
            chartResult.Series.Add(seriesResult);
            chartResult.Titles.Add(new Title(strField));
        }
Example #28
0
        /// <summary>
        ///     Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmUser_Load(object sender, EventArgs e)
        {
            if (_modifyName != string.Empty)
            {
                Text = "Change User Config";
                txtUserName.Enabled = false;
                txtUserName.Text    = _modifyName;
                var userInfo = RuntimeMongoDbContext.GetCurrentDataBase().GetCollection(ConstMgr.CollectionNameUsers)
                               .FindOneAs <BsonDocument>(Query.EQ("user", _modifyName));

                BsonElement role;
                if (userInfo.TryGetElement("roles", out role))
                {
                    var roles = role.Value.AsBsonArray;
                    foreach (var _role in roles)
                    {
                        if (_role.IsBsonDocument)
                        {
                            _roleList.Add(new Role.GrantRole()
                            {
                                Role = _role.AsBsonDocument.GetElement("role").Value.ToString(),
                                Db   = _role.AsBsonDocument.GetElement("db").Value.ToString()
                            });
                        }
                        else
                        {
                            _roleList.Add(new Role.GrantRole()
                            {
                                Role = _role.ToString(),
                            });
                        }
                    }
                }
                RefreshRoles();

                BsonElement custom;
                if (userInfo.TryGetElement("customData", out custom))
                {
                    customData             = custom.Value.AsBsonDocument;
                    lblcustomDocument.Text = "Custom Document:" + customData.ToString();
                }
            }

            GuiConfig.Translateform(this);

            if (!GuiConfig.IsUseDefaultLanguage)
            {
                if (_modifyName == string.Empty)
                {
                    if (!GuiConfig.IsMono)
                    {
                        Icon = GetSystemIcon.ConvertImgToIcon(Resources.AddUserToDB);
                    }
                    Text = GuiConfig.GetText(_isAdmin ? "MainMenu.OperationServerAddUserToAdmin" : "MainMenu.OperationDatabaseAddUser");
                }
                else
                {
                    if (!GuiConfig.IsMono)
                    {
                        Icon = GetSystemIcon.ConvertImgToIcon(Resources.DBkey);
                    }
                    Text = GuiConfig.GetText("CommonChangePassword");
                }
            }
        }
Example #29
0
        /// <summary>
        ///     窗体初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmStatus_Load(object sender, EventArgs e)
        {
            if (!GuiConfig.IsMono)
            {
                Icon = GetSystemIcon.ConvertImgToIcon(Resources.KeyInfo);
            }
            GuiConfig.Translateform(this);
            var strType   = RuntimeMongoDbContext.SelectTagType;
            var docStatus = new BsonDocument();

            cmbChartField.Visible          = false;
            chartResult.Visible            = false;
            tempIsDisplayNumberWithKSystem = CtlTreeViewColumns.IsDisplayNumberWithKSystem;
            CtlTreeViewColumns.IsDisplayNumberWithKSystem = true;

            switch (strType)
            {
            case ConstMgr.ServerTag:
            case ConstMgr.SingleDbServerTag:
                if (RuntimeMongoDbContext.GetCurrentServerConfig().LoginAsAdmin)
                {
                    var StatusList = new List <BsonDocument>();
                    var Status     = CommandExecute.ExecuteMongoSvrCommand(DataBaseCommand.ServerStatusCommand,
                                                                           RuntimeMongoDbContext.GetCurrentServer()).Response;
                    StatusList.Add(Status);
                    try
                    {
                        var ServerDesripter = MongoUtility.ToolKit.MongoHelper.GetCurrentServerDescription();
                        StatusList.Add(ServerDesripter);
                    }
                    catch (Exception)
                    {
                        //Repl的时候,无法获得
                    }
                    UiHelper.FillDataToTreeView(strType, trvStatus, StatusList, 0);
                    trvStatus.Height = trvStatus.Height * 2;
                    trvStatus.DatatreeView.Nodes[0].Expand();
                    trvStatus.DatatreeView.Nodes[1].Expand();
                    return;
                }
                break;

            case ConstMgr.DatabaseTag:
            case ConstMgr.SingleDatabaseTag:
                docStatus             = RuntimeMongoDbContext.GetCurrentDataBase().GetStats().Response.ToBsonDocument();
                cmbChartField.Visible = true;
                chartResult.Visible   = true;
                //{{ "db" : "aaaa",
                //   "collections" : 8,
                //   "objects" : 0,
                //   "avgObjSize" : 0.0,
                //   "dataSize" : 0.0,
                //   "storageSize" : 32768.0,
                //   "numExtents" : 0,
                //   "indexes" : 8,
                //   "indexSize" : 32768.0,
                //   "ok" : 1.0 }}
                var statuspoint = docStatus.AsBsonDocument;
                //这里其实应该看Collection的Status,不同的引擎所拥有的状态不一样
                if (statuspoint.Contains("avgObjSize"))
                {
                    cmbChartField.Items.Add("AverageObjectSize");
                }
                if (statuspoint.Contains("dataSize"))
                {
                    cmbChartField.Items.Add("DataSize");
                }
                if (statuspoint.Contains("extentCount"))
                {
                    cmbChartField.Items.Add("ExtentCount");
                }
                if (statuspoint.Contains("indexes"))
                {
                    cmbChartField.Items.Add("IndexCount");
                }
                if (statuspoint.Contains("lastExtentSize"))
                {
                    cmbChartField.Items.Add("LastExtentSize");
                }
                //MaxDocuments仅在CapedCollection时候有效
                if (statuspoint.Contains("MaxDocuments"))
                {
                    cmbChartField.Items.Add("MaxDocuments");
                }
                if (statuspoint.Contains("ObjectCount"))
                {
                    cmbChartField.Items.Add("ObjectCount");
                }
                if (statuspoint.Contains("PaddingFactor"))
                {
                    cmbChartField.Items.Add("PaddingFactor");
                }
                if (statuspoint.Contains("storageSize"))
                {
                    cmbChartField.Items.Add("StorageSize");
                }
                cmbChartField.SelectedIndex = 0;
                try
                {
                    RefreshDbStatusChart("StorageSize");
                }
                catch (Exception ex)
                {
                    Utility.ExceptionDeal(ex);
                }
                break;

            case ConstMgr.CollectionTag:
                //TODO:这里无法看到Collection的Document Validation信息。
                docStatus = RuntimeMongoDbContext.GetCurrentCollection().GetStats().Response.ToBsonDocument();
                //图形化初始化
                chartResult.Visible = true;

                chartResult.Series.Clear();
                chartResult.Titles.Clear();
                var seriesResult = new Series("Usage");
                var dpDataSize   = new DataPoint(0, RuntimeMongoDbContext.GetCurrentCollection().GetStats().DataSize)
                {
                    LegendText    = "DataSize",
                    LegendToolTip = "DataSize",
                    ToolTip       = "DataSize"
                };
                seriesResult.Points.Add(dpDataSize);

                var dpTotalIndexSize = new DataPoint(0,
                                                     RuntimeMongoDbContext.GetCurrentCollection().GetStats().TotalIndexSize)
                {
                    LegendText    = "TotalIndexSize",
                    LegendToolTip = "TotalIndexSize",
                    ToolTip       = "TotalIndexSize"
                };
                seriesResult.Points.Add(dpTotalIndexSize);

                var dpFreeSize = new DataPoint(0,
                                               RuntimeMongoDbContext.GetCurrentCollection().GetStats().StorageSize -
                                               RuntimeMongoDbContext.GetCurrentCollection().GetStats().TotalIndexSize -
                                               RuntimeMongoDbContext.GetCurrentCollection().GetStats().DataSize)
                {
                    LegendText    = "FreeSize",
                    LegendToolTip = "FreeSize",
                    ToolTip       = "FreeSize"
                };
                seriesResult.Points.Add(dpFreeSize);

                seriesResult.ChartType = SeriesChartType.Pie;
                chartResult.Series.Add(seriesResult);
                chartResult.Titles.Add(new Title("Usage"));

                break;

            default:
                if (RuntimeMongoDbContext.GetCurrentServerConfig().LoginAsAdmin)
                {
                    docStatus =
                        CommandExecute.ExecuteMongoSvrCommand(DataBaseCommand.ServerStatusCommand,
                                                              RuntimeMongoDbContext.GetCurrentServer()).Response;
                    trvStatus.Height = trvStatus.Height * 2;
                }
                break;
            }
            UiHelper.FillDataToTreeView(strType, trvStatus, docStatus);
            trvStatus.DatatreeView.Nodes[0].Expand();
        }
Example #30
0
        /// <summary>
        ///     当前对象的MONGO命令
        /// </summary>
        /// <param name="mMongoCommand">命令对象</param>
        /// <returns></returns>
        public static CommandResult ExecuteMongoCommand(MongoCommand mMongoCommand)
        {
            var resultCommandList = new List <CommandResult>();

            var mCommandResult = new CommandResult(new BsonDocument());

            switch (mMongoCommand.RunLevel)
            {
            case EnumMgr.PathLevel.CollectionAndView:
                if (string.IsNullOrEmpty(mMongoCommand.CommandString))
                {
                    mCommandResult = ExecuteMongoColCommand(mMongoCommand.CmdDocument,
                                                            RuntimeMongoDbContext.GetCurrentCollection());
                }
                else
                {
                    mCommandResult = ExecuteMongoColCommand(mMongoCommand.CommandString,
                                                            RuntimeMongoDbContext.GetCurrentCollection());
                }
                break;

            case EnumMgr.PathLevel.Database:
                if (string.IsNullOrEmpty(mMongoCommand.DatabaseName))
                {
                    mCommandResult = ExecuteMongoDBCommand(mMongoCommand.CmdDocument, RuntimeMongoDbContext.GetCurrentDataBase());
                }
                else
                {
                    var db = RuntimeMongoDbContext.GetCurrentClient().GetDatabase(mMongoCommand.DatabaseName);
                    mCommandResult = ExecuteMongoDBCommand(mMongoCommand.CmdDocument, db);
                }
                break;

            case EnumMgr.PathLevel.Instance:
                mCommandResult = ExecuteMongoSvrCommand(mMongoCommand.CmdDocument,
                                                        RuntimeMongoDbContext.GetCurrentServer());
                break;
            }
            resultCommandList.Add(mCommandResult);
            return(mCommandResult);
        }