本文整理汇总了C#中MongoDB.Driver.CommandResult类的典型用法代码示例。如果您正苦于以下问题:C# CommandResult类的具体用法?C# CommandResult怎么用?C# CommandResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandResult类属于MongoDB.Driver命名空间,在下文中一共展示了CommandResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestOkMissing
public void TestOkMissing() {
var command = new CommandDocument("invalid", true);
var document = new BsonDocument();
var result = new CommandResult(command, document);
try {
var dummy = result.Ok;
} catch (MongoCommandException ex) {
Assert.IsTrue(ex.Message.StartsWith("Command 'invalid' failed: response has no ok element (response: "));
}
}
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:10,代码来源:CommandResultTests.cs
示例17: IsShellOK
/// <summary>
/// Js Shell 的结果判定
/// </summary>
/// <param name="Result"></param>
/// <returns></returns>
public static Boolean IsShellOK(CommandResult Result)
{
if (!Result.Response.ToBsonDocument().GetElement("retval").Value.IsBsonDocument)
{
return true;
}
return
Result.Response.ToBsonDocument()
.GetElement("retval")
.Value.AsBsonDocument.GetElement("ok")
.Value.ToString() == "1";
}
开发者ID:EricBlack,项目名称:MagicMongoDBTool,代码行数:17,代码来源:MongoDBHelper_Command_Run.cs
示例18: RemoveFromReplsetServer
/// <summary>
/// 删除服务器
/// </summary>
/// <param name="mongoSvr">副本组主服务器</param>
/// <param name="hostPort">服务器信息</param>
/// <remarks>这个命令C#无法正确执行</remarks>
/// <returns></returns>
public static CommandResult RemoveFromReplsetServer(MongoServer mongoSvr, string hostPort)
{
var mCommandResult = new CommandResult(new BsonDocument());
try
{
CommandExecute.ExecuteJsShell("rs.remove('" + hostPort + "');", mongoSvr);
}
catch (EndOfStreamException)
{
}
return mCommandResult;
}
开发者ID:magicdict,项目名称:MongoCola,代码行数:20,代码来源:ShellMethod.cs
示例19: ReconfigReplsetServer
/// <summary>
/// 重新启动
/// </summary>
/// <param name="primarySvr">副本组主服务器</param>
/// <param name="config">服务器信息</param>
/// <remarks>这个命令C#无法正确执行</remarks>
/// <returns></returns>
public static CommandResult ReconfigReplsetServer(MongoServer primarySvr, BsonDocument config)
{
var cmdRtn = new CommandResult(new BsonDocument());
try
{
return CommandExecute.ExecuteJsShell("rs.reconfig(" + config + ",{force : true})", primarySvr);
}
catch (EndOfStreamException)
{
}
return cmdRtn;
}
开发者ID:magicdict,项目名称:MongoCola,代码行数:20,代码来源:ShellMethod.cs
示例20: TestOkMissing
public void TestOkMissing()
{
var command = new CommandDocument("invalid", 1);
var document = new BsonDocument();
var result = new CommandResult(document) { Command = command };
try
{
var dummy = result.Ok;
}
catch (MongoCommandException ex)
{
Assert.IsTrue(ex.Message.StartsWith("Command 'invalid' failed. Response has no ok element (response was ", StringComparison.Ordinal));
}
}
开发者ID:annikulin,项目名称:code-classifier,代码行数:14,代码来源:CommandResultTests.cs
注:本文中的MongoDB.Driver.CommandResult类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论