/// <summary>
        /// 当前对象的MONGO命令
        /// </summary>
        /// <param name="mMongoCommand">命令对象</param>
        /// <param name="ShowMsgBox"></param>
        /// <returns></returns>
        public static CommandResult ExecuteMongoCommand(MongoCommand mMongoCommand, Boolean ShowMsgBox = true)
        {
            List <CommandResult> ResultCommandList = new List <CommandResult>();

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

            try
            {
                switch (mMongoCommand.RunLevel)
                {
                case PathLv.CollectionLV:
                    if (String.IsNullOrEmpty(mMongoCommand.CommandString))
                    {
                        mCommandResult = ExecuteMongoColCommand(mMongoCommand.cmdDocument, SystemManager.GetCurrentCollection());
                    }
                    else
                    {
                        mCommandResult = ExecuteMongoColCommand(mMongoCommand.CommandString, SystemManager.GetCurrentCollection());
                    }
                    break;

                case PathLv.DatabaseLV:
                    mCommandResult = ExecuteMongoDBCommand(mMongoCommand.cmdDocument, SystemManager.GetCurrentDataBase());
                    break;

                case PathLv.InstanceLV:
                    mCommandResult = ExecuteMongoSvrCommand(mMongoCommand.cmdDocument, SystemManager.GetCurrentServer());
                    break;

                default:
                    break;
                }
                ResultCommandList.Add(mCommandResult);
                if (ShowMsgBox)
                {
                    MyMessageBox.ShowMessage(mMongoCommand.CommandString, mMongoCommand.CommandString + " Result", MongoDBHelper.ConvertCommandResultlstToString(ResultCommandList), true);
                }
            }
            catch (System.IO.IOException ex)
            {
                SystemManager.ExceptionDeal(ex, mMongoCommand.CommandString, "IOException,Try to set Socket TimeOut more long at connection config");
            }
            catch (Exception ex)
            {
                SystemManager.ExceptionDeal(ex, mMongoCommand.CommandString);
            }

            return(mCommandResult);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 当前对象的MONGO命令
        /// </summary>
        /// <param name="cmd">命令对象</param>
        /// <returns></returns>
        public static void ExecuteMongoCommand(MongoCommand cmd)
        {
            var Command = new CommandDocument {
                { cmd.CommandString, 1 }
            };
            List <CommandResult> ResultCommandList = new List <CommandResult>();

            CommandResult rtn = new CommandResult();

            try
            {
                switch (cmd.RunLevel)
                {
                case PathLv.CollectionLV:
                    rtn = ExecuteMongoColCommand(cmd.CommandString, SystemManager.GetCurrentCollection());
                    break;

                case PathLv.DatabaseLV:
                    rtn = ExecuteMongoDBCommand(Command, SystemManager.GetCurrentDataBase());
                    break;

                case PathLv.ServerLV:
                    rtn = ExecuteMongoSvrCommand(Command, SystemManager.GetCurrentServer());
                    break;

                default:
                    break;
                }
                ResultCommandList.Add(rtn);
                MyMessageBox.ShowMessage(cmd.CommandString, cmd.CommandString + " Result", MongoDBHelper.ConvertCommandResultlstToString(ResultCommandList), true);
            }
            catch (System.IO.IOException ex)
            {
                MyMessageBox.ShowMessage(cmd.CommandString, "IOException,Try to set Socket TimeOut more long at connection config", ex.ToString(), true);
            }
            catch (Exception ex)
            {
                SystemManager.ExceptionDeal(ex, cmd.CommandString);
            }
        }