當前位置: 首頁>>代碼示例>>C#>>正文


C# Driver.CommandResult類代碼示例

本文整理匯總了C#中MongoDB.Driver.CommandResult的典型用法代碼示例。如果您正苦於以下問題:C# CommandResult類的具體用法?C# CommandResult怎麽用?C# CommandResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CommandResult類屬於MongoDB.Driver命名空間,在下文中一共展示了CommandResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: MongoSafeModeException

 public MongoSafeModeException(
     string message,
     CommandResult commandResult
 )
     : base(message, commandResult)
 {
 }
開發者ID:modesto,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:MongoSafeModeException.cs

示例2: TestErrorMessagePresent

 public void TestErrorMessagePresent()
 {
     var document = new BsonDocument("errmsg", "An error message");
     var result = new CommandResult();
     result.Initialize(document);
     Assert.AreEqual("An error message", result.ErrorMessage);
 }
開發者ID:swiggin1,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:CommandResultTests.cs

示例3: TestErrorMessageMissing

 public void TestErrorMessageMissing()
 {
     var document = new BsonDocument();
     var result = new CommandResult();
     result.Initialize(document);
     Assert.AreEqual("Unknown error", result.ErrorMessage);
 }
開發者ID:swiggin1,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:CommandResultTests.cs

示例4: TestErrorMessageNotString

 public void TestErrorMessageNotString()
 {
     var document = new BsonDocument("errmsg", 3.14159);
     var result = new CommandResult();
     result.Initialize(document);
     Assert.AreEqual("3.14159", result.ErrorMessage);
 }
開發者ID:swiggin1,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:CommandResultTests.cs

示例5: SaveEditorJavascript

 /// <summary>
 ///     Save Edited Javascript
 /// </summary>
 /// <param name="jsName"></param>
 /// <param name="jsCode"></param>
 /// <param name="jsCol"></param>
 /// <returns></returns>
 public static string SaveEditorJavascript(string jsName, string jsCode, MongoCollection jsCol)
 {
     //標準的JS庫格式未知
     if (QueryHelper.IsExistByKey(jsName))
     {
         var result = DropDocument(jsCol, (BsonString) jsName);
         if (string.IsNullOrEmpty(result))
         {
             CommandResult resultCommand;
             try
             {
                 resultCommand = new CommandResult(
                     jsCol.Insert(new BsonDocument().Add(ConstMgr.KeyId, jsName).Add("value", jsCode)).Response);
             }
             catch (MongoCommandException ex)
             {
                 resultCommand = new CommandResult(ex.Result);
             }
             if (resultCommand.Response["err"] == BsonNull.Value)
             {
                 return string.Empty;
             }
             return resultCommand.Response["err"].ToString();
         }
         return result;
     }
     return string.Empty;
 }
開發者ID:jango2015,項目名稱:MongoCola,代碼行數:35,代碼來源:Document.cs

示例6: DropDocument

 /// <summary>
 ///     刪除單條數據
 /// </summary>
 /// <param name="mongoCol">表對象</param>
 /// <param name="objectId">ObjectId</param>
 /// <returns></returns>
 public static string DropDocument(MongoCollection mongoCol, string objectId)
 {
     CommandResult result;
     try
     {
         //有時候在序列化的過程中,objectId是由某個字段帶上[id]特性客串的,所以無法轉換為ObjectId對象
         //這裏先嘗試轉換,如果可以轉換,則轉換
         ObjectId seekId;
         if (ObjectId.TryParse(objectId, out seekId))
         {
             //如果可以轉換,則轉換
             result =
                 new CommandResult(
                     mongoCol.Remove(Query.EQ(ConstMgr.KeyId, seekId), WriteConcern.Acknowledged)
                         .Response);
         }
         else
         {
             //不能轉換則保持原狀
             result =
                 new CommandResult(
                     mongoCol.Remove(Query.EQ(ConstMgr.KeyId, objectId), WriteConcern.Acknowledged)
                         .Response);
         }
     }
     catch (MongoCommandException ex)
     {
         result = new CommandResult(ex.Result);
     }
     BsonElement err;
     return !result.Response.TryGetElement("err", out err) ? string.Empty : err.ToString();
 }
開發者ID:magicdict,項目名稱:MongoCola,代碼行數:38,代碼來源:Document.cs

示例7: TestOkZero

 public void TestOkZero()
 {
     var document = new BsonDocument("ok", 0);
     var result = new CommandResult(document);
     Assert.False(result.Ok);
     Assert.NotNull(result.ErrorMessage);
 }
開發者ID:RavenZZ,項目名稱:MDRelation,代碼行數:7,代碼來源:CommandResultTests.cs

示例8: TestOkFalse

 public void TestOkFalse()
 {
     var document = new BsonDocument("ok", false);
     var result = new CommandResult(null, document);
     Assert.IsFalse(result.Ok);
     Assert.IsNotNull(result.ErrorMessage);
 }
開發者ID:wireclub,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:CommandResultTests.cs

示例9: TestOkTrue

 public void TestOkTrue()
 {
     var document = new BsonDocument("ok", true);
     var result = new CommandResult(null, document);
     Assert.IsTrue(result.Ok);
     Assert.IsNull(result.ErrorMessage);
 }
開發者ID:wireclub,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:CommandResultTests.cs

示例10: AddToReplsetServer

        //Replica Set Commands
        //http://www.mongodb.org/display/DOCS/Replica+Set+Commands
        //rs.help()                       show help
        //rs.status()                     { replSetGetStatus : 1 }
        //rs.initiate()                   { replSetInitiate : null } initiate
        //                                    with default settings
        //rs.initiate(cfg)                { replSetInitiate : cfg }
        //rs.add(hostportstr)             add a new member to the set
        //rs.add(membercfgobj)            add a new member to the set
        //rs.addArb(hostportstr)          add a new member which is arbiterOnly:true
        //rs.remove(hostportstr)          remove a member (primary, secondary, or arbiter) from the set
        //rs.stepDown()                   { replSetStepDown : true }
        //rs.conf()                       return configuration from local.system.replset
        //db.isMaster()                   check who is primary
        /// <summary>
        /// 增加服務器
        /// </summary>
        /// <param name="mongoSvr">副本組主服務器</param>
        /// <param name="HostPort">服務器信息</param>
        /// <param name="IsArb">是否為仲裁服務器</param>
        /// <returns></returns>
        public static CommandResult AddToReplsetServer(MongoServer mongoSvr, String HostPort, int priority, Boolean IsArb)
        {
            CommandResult mCommandResult = new CommandResult(new BsonDocument());
            try
            {
                if (!IsArb)
                {
                    mCommandResult = ExecuteJsShell("rs.add({_id:" + mongoSvr.Instances.Length + 1 + ",host:'" + HostPort + "',priority:" + priority.ToString() + "});", mongoSvr);
                }
                else
                {
                    //其實addArb最後也隻是調用了add方法
                    mCommandResult = ExecuteJsShell("rs.addArb('" + HostPort + "');", mongoSvr);
                }
            }
            catch (EndOfStreamException)
            {

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return mCommandResult;
        }
開發者ID:qq33357486,項目名稱:MagicMongoDBTool,代碼行數:46,代碼來源:MongoDBHelper_RunCommand.cs

示例11: TestCodeMissing

        public void TestCodeMissing()
        {
            var document = new BsonDocument();
            var result = new CommandResult(document);

            Assert.False(result.Code.HasValue);
        }
開發者ID:RavenZZ,項目名稱:MDRelation,代碼行數:7,代碼來源:CommandResultTests.cs

示例12: MongoCommandException

 /// <summary>
 /// Initializes a new instance of the MongoCommandException class.
 /// </summary>
 /// <param name="message">The error message.</param>
 /// <param name="commandResult">The command result.</param>
 public MongoCommandException(
     string message,
     CommandResult commandResult
 )
     : this(message) {
         this.commandResult = commandResult;
 }
開發者ID:redforks,項目名稱:mongo-csharp-driver,代碼行數:12,代碼來源:MongoCommandException.cs

示例13: TestCode

        public void TestCode()
        {
            var document = new BsonDocument("code", 18);
            var result = new CommandResult(document);

            Assert.True(result.Code.HasValue);
            Assert.Equal(18, result.Code);
        }
開發者ID:RavenZZ,項目名稱:MDRelation,代碼行數:8,代碼來源:CommandResultTests.cs

示例14: TestCodeMissing

        public void TestCodeMissing()
        {
            var command = new CommandDocument("invalid", 1);
            var document = new BsonDocument();
            var result = new CommandResult(command, document);

            Assert.IsFalse(result.Code.HasValue);
        }
開發者ID:wireclub,項目名稱:mongo-csharp-driver,代碼行數:8,代碼來源:CommandResultTests.cs

示例15: TestCode

        public void TestCode()
        {
            var command = new CommandDocument("invalid", 1);
            var document = new BsonDocument("code", 18);
            var result = new CommandResult(command, document);

            Assert.IsTrue(result.Code.HasValue);
            Assert.AreEqual(18, result.Code);
        }
開發者ID:wireclub,項目名稱:mongo-csharp-driver,代碼行數:9,代碼來源:CommandResultTests.cs


注:本文中的MongoDB.Driver.CommandResult類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。