当前位置: 首页>>代码示例>>C#>>正文


C# MongoDatabase.Eval方法代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:namesecured,项目名称:MSBuildMongo,代码行数:11,代码来源:RunJavascript.cs

示例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;
 }
开发者ID:lizhi5753186,项目名称:MongoCola,代码行数:46,代码来源:Role.cs

示例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;
 }
开发者ID:jango2015,项目名称:MongoCola,代码行数:12,代码来源:Role.cs

示例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;
 }
开发者ID:EricBlack,项目名称:MagicMongoDBTool,代码行数:45,代码来源:Role.cs


注:本文中的MongoDatabase.Eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。