Example #1
0
 /// <summary>
 ///     执行数据集命令
 /// </summary>
 /// <param name="commandString"></param>
 /// <param name="mongoCol"></param>
 /// <returns></returns>
 public static CommandResult ExecuteMongoColCommand(string commandString, MongoCollection mongoCol)
 {
     CommandResult mCommandResult;
     var baseCommand = new BsonDocument { { commandString, mongoCol.Name } };
     var mongoCmd = new CommandDocument();
     mongoCmd.AddRange(baseCommand);
     try
     {
         mCommandResult = mongoCol.Database.RunCommand(mongoCmd);
     }
     catch (MongoCommandException ex)
     {
         mCommandResult = new CommandResult(ex.Result);
     }
     var e = new RunCommandEventArgs
     {
         CommandString = commandString,
         RunLevel = EnumMgr.PathLevel.CollectionAndView,
         Result = mCommandResult
     };
     OnCommandRunComplete(e);
     return mCommandResult;
 }
Example #2
0
        //查看命令方法:http://localhost:29018/_commands
        //假设28018为端口号,同时使用 --rest 选项
        //http://www.mongodb.org/display/DOCS/Replica+Set+Commands

        /// <summary>
        ///     Command Complete
        /// </summary>
        /// <param name="e"></param>
        public static void OnCommandRunComplete(RunCommandEventArgs e)
        {
            e.Raise(null, ref RunCommandComplete);
        }
Example #3
0
 /// <summary>
 ///     执行MongoCommand
 /// </summary>
 /// <param name="mCommandDocument">命令Doc</param>
 /// <param name="mongoSvr">目标服务器</param>
 /// <returns></returns>
 public static CommandResult ExecuteMongoSvrCommand(CommandDocument mCommandDocument, MongoServer mongoSvr)
 {
     CommandResult mCommandResult;
     try
     {
         mCommandResult = mongoSvr.GetDatabase(ConstMgr.DatabaseNameAdmin).RunCommand(mCommandDocument);
     }
     catch (MongoCommandException ex)
     {
         mCommandResult = new CommandResult(ex.Result);
     }
     var e = new RunCommandEventArgs
     {
         CommandString = mCommandDocument.ToString(),
         RunLevel = EnumMgr.PathLevel.Instance,
         Result = mCommandResult
     };
     OnCommandRunComplete(e);
     return mCommandResult;
 }
Example #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="mongoCmd"></param>
 /// <param name="mongoDb"></param>
 /// <returns></returns>
 public static CommandResult ExecuteMongoDBCommand(CommandDocument mongoCmd, IMongoDatabase mongoDb)
 {
     CommandResult mCommandResult = null;
     try
     {
         var t = Task.Run(
             async () => { mCommandResult = await mongoDb.RunCommandAsync<CommandResult>(mongoCmd); }
             );
         t.Wait();
     }
     catch (MongoCommandException ex)
     {
         mCommandResult = new CommandResult(ex.Result);
     }
     var e = new RunCommandEventArgs
     {
         CommandString = mongoCmd.ToString(),
         RunLevel = EnumMgr.PathLevel.Database,
         Result = mCommandResult
     };
     OnCommandRunComplete(e);
     return mCommandResult;
 }
Example #5
0
 /// <summary>
 ///     执行数据库命令
 /// </summary>
 /// <param name="mongoCmd"></param>
 /// <param name="mongoDb"></param>
 /// <returns></returns>
 public static CommandResult ExecuteMongoDBCommand(CommandDocument mongoCmd, MongoDatabase mongoDb)
 {
     CommandResult mCommandResult;
     try
     {
         mCommandResult = mongoDb.RunCommand(mongoCmd);
     }
     catch (MongoCommandException ex)
     {
         mCommandResult = new CommandResult(ex.Result);
     }
     var e = new RunCommandEventArgs
     {
         CommandString = mongoCmd.ToString(),
         RunLevel = EnumMgr.PathLevel.Database,
         Result = mCommandResult
     };
     OnCommandRunComplete(e);
     return mCommandResult;
 }
Example #6
0
 /// <summary>
 ///     执行数据集命令
 /// </summary>
 /// <param name="cmdDoc"></param>
 /// <param name="mongoCol"></param>
 /// <returns></returns>
 public static CommandResult ExecuteMongoColCommand(CommandDocument cmdDoc, MongoCollection mongoCol)
 {
     CommandResult mCommandResult;
     try
     {
         mCommandResult = mongoCol.Database.RunCommand(cmdDoc);
     }
     catch (MongoCommandException ex)
     {
         mCommandResult = new CommandResult(ex.Result);
     }
     var e = new RunCommandEventArgs
     {
         CommandString = cmdDoc.GetElement(0).Value.ToString(),
         RunLevel = EnumMgr.PathLevel.Database,
         Result = mCommandResult
     };
     OnCommandRunComplete(e);
     return mCommandResult;
 }
Example #7
0
 /// <summary>
 ///     数据集命令
 /// </summary>
 /// <param name="command">命令关键字</param>
 /// <param name="mongoCol">数据集</param>
 /// <param name="extendInfo">命令参数</param>
 /// <returns></returns>
 public static CommandResult ExecuteMongoColCommand(string command, MongoCollection mongoCol,
     BsonDocument extendInfo)
 {
     var executeCommand = new CommandDocument
     {
         {command, mongoCol.Name}
     };
     foreach (var item in extendInfo.Elements)
     {
         executeCommand.Add(item);
     }
     var mCommandResult = mongoCol.Database.RunCommand(executeCommand);
     var e = new RunCommandEventArgs
     {
         CommandString = executeCommand.ToString(),
         RunLevel = EnumMgr.PathLevel.Collection,
         Result = mCommandResult
     };
     OnCommandRunComplete(e);
     return mCommandResult;
 }
Example #8
0
 /// <summary>
 ///     执行MongoCommand
 /// </summary>
 /// <param name="mCommandDocument">命令Doc</param>
 /// <param name="mongoSvr">目标服务器</param>
 /// <returns></returns>
 public static CommandResult ExecuteMongoSvrCommand(CommandDocument mCommandDocument, MongoServer mongoSvr)
 {
     CommandResult mCommandResult = null;
     try
     {
         if (mongoSvr.DatabaseExists(ConstMgr.DatabaseNameAdmin))
         {
             //Repl的时候,会发生超时问题
             mCommandResult = mongoSvr.GetDatabase(ConstMgr.DatabaseNameAdmin).RunCommand(mCommandDocument);
         }
         else
         {
             //Replset的时候,没有Admin数据库
             BsonDocument AdminDatabaseNotFound = new BsonDocument();
             AdminDatabaseNotFound.Add("errmsg", "Admin Database Not Found");
             mCommandResult = new CommandResult(AdminDatabaseNotFound);
         }
     }
     catch (MongoCommandException ex)
     {
         mCommandResult = new CommandResult(ex.Result);
     }
     catch (TimeoutException)
     {
         BsonDocument TimeOutDocument = new BsonDocument();
         TimeOutDocument.Add("errmsg", "TimeoutException");
         mCommandResult = new CommandResult(TimeOutDocument);
     }
     var e = new RunCommandEventArgs
     {
         CommandString = mCommandDocument.ToString(),
         RunLevel = EnumMgr.PathLevel.Instance,
         Result = mCommandResult
     };
     OnCommandRunComplete(e);
     return mCommandResult;
 }