本文整理汇总了C#中MongoDatabase.Eval方法的典型用法代码示例。如果您正苦于以下问题:C# MongoDatabase.Eval方法的具体用法?C# MongoDatabase.Eval怎么用?C# MongoDatabase.Eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDatabase
的用法示例。
在下文中一共展示了MongoDatabase.Eval方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Eval
public static void Eval(MongoDatabase database, string fileName)
{
using (var stream = new FileStream(fileName, FileMode.Open))
{
using (var reader = new StreamReader(stream))
{
var javaScript = new BsonJavaScript(reader.ReadToEnd());
database.Eval(javaScript);
}
}
}
示例2: AddRole
/// <summary>
/// 添加一个用户自定义角色
/// </summary>
public static BsonValue AddRole(MongoDatabase mongoDb, Role role)
{
var roleCommand = string.Empty;
var doc = new EvalArgs();
roleCommand = "db.createRole(" + Environment.NewLine;
roleCommand += "{" + Environment.NewLine;
roleCommand += " role: '" + role.Rolename + "'," + Environment.NewLine;
//Roles
roleCommand += " roles:" + Environment.NewLine;
roleCommand += " [";
for (var i = 0; i < role.Roles.Length; i++)
{
var singleroles = role.Roles[i];
roleCommand += "{ role: '" + singleroles.MRole + "', db: '" + singleroles.Db + "' }" +
((i == role.Roles.Length - 1) ? "" : ",") + Environment.NewLine;
}
roleCommand += " ],";
//privileges
roleCommand += " privileges:" + Environment.NewLine;
roleCommand += " [";
for (var i = 0; i < role.Privileges.Length; i++)
{
var singleprivileges = role.Privileges[i];
roleCommand += "{" + singleprivileges.Resource.GetJsCode() + "," +
MongoDbAction.GetActionListJs(singleprivileges.Actions) + "}" +
((i == role.Privileges.Length - 1) ? "" : ",") + Environment.NewLine;
}
roleCommand += " ],";
//
roleCommand += "}" + Environment.NewLine;
roleCommand += ")";
doc.Code = roleCommand;
BsonValue result;
try
{
result = mongoDb.Eval(doc);
}
catch (MongoCommandException ex)
{
result = ex.Result;
}
return result;
}
示例3: GetRole
/// <summary>
/// GetRole
/// </summary>
/// <param name="mongoDb"></param>
/// <param name="roleName"></param>
/// <returns></returns>
public static BsonDocument GetRole(MongoDatabase mongoDb, string roleName)
{
var doc = new EvalArgs();
doc.Code = "db.getRole('" + roleName + "',{showPrivileges:true})";
return mongoDb.Eval(doc).AsBsonDocument;
}
示例4: AddRole
/// <summary>
/// 添加一个用户自定义角色
/// </summary>
public static BsonValue AddRole(MongoDatabase mongoDb, Role role)
{
String RoleCommand = String.Empty;
EvalArgs doc = new EvalArgs();
RoleCommand = "db.createRole(" + System.Environment.NewLine;
RoleCommand += "{" + System.Environment.NewLine;
RoleCommand += " role: '" + role.rolename + "'," + System.Environment.NewLine;
//Roles
RoleCommand += " roles:" + System.Environment.NewLine;
RoleCommand += " [";
for (int i = 0; i < role.roles.Length; i++)
{
var singleroles = role.roles[i];
RoleCommand += "{ role: '" + singleroles.mRole + "', db: '" + singleroles.db + "' }" +
((i == role.roles.Length - 1) ? "" : ",") + System.Environment.NewLine;
}
RoleCommand += " ],";
//privileges
RoleCommand += " privileges:" + System.Environment.NewLine;
RoleCommand += " [";
for (int i = 0; i < role.privileges.Length; i++)
{
var singleprivileges = role.privileges[i];
RoleCommand += "{" + singleprivileges.resource.GetJsCode() + "," + Action.GetActionListJs(singleprivileges.actions) + "}" +
((i == role.privileges.Length - 1) ? "" : ",") + System.Environment.NewLine;
}
RoleCommand += " ],";
//
RoleCommand += "}" + System.Environment.NewLine;
RoleCommand += ")";
doc.Code = RoleCommand;
BsonValue result;
try
{
result = mongoDb.Eval(doc);
}
catch (MongoCommandException ex)
{
result = ex.CommandResult.Response;
}
return result;
}