C# amo 完成角色 [英] C# amo get roles complete

查看:49
本文介绍了C# amo 完成角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个 SSAS 项目,除其他外,我需要在 C# 中获取表格立方体的完整用户列表.目前我让它以这样一种方式工作,我可以获得角色,但数据不完整.当我调用 Server.Database.Roles(为了可读性而简化)属性并通过它进行枚举时,我只得到 ID、Name 和 CreatedTimeStamp.我缺少的是成员、CellPermissions(DAX 过滤器)以及这些成员的权限,这一点至关重要.我目前在 Server.Database.Cube 中寻找的权限(读/写/管理员)但 CubePermissions 为空...

I'm working on a SSAS project in which I, amongst other things, need to get a complete list of users for a tabular cube, in C#. Currently I have it working in such a way that I can get the roles, but the data is incomplete. When I call the Server.Database.Roles (simplified for readability) property and enumerate through it I only get ID, Name and CreatedTimeStamp. What I am missing, which is crucial, is Members, CellPermissions (DAX Filters) and the permissions for those members. The permissions (read/write/administrator) I am currently looking for in Server.Database.Cube but the CubePermissions are empty...

在 SSMS 中,当我编写其中一个测试角色的脚本时,该角色包含:

In SSMS when I script one of my testroles the role contains:

<ID>Role</ID>
        <Name>TestRole</Name>
        <Description>role for testing</Description>
        <Members>
            <Member>
                <Name>THORVALDDATA\rj</Name>
                <Sid>OMITTED</Sid>
            </Member>
            <Member>
                <Name>THORVALDDATA\dp</Name>
                <Sid>OMITTED</Sid>
            </Member>
            <Member>
                <Name>THORVALDDATA\jtl</Name>
                <Sid>OMITTED</Sid>
            </Member>
        </Members>

但如前所述,当我在代码中枚举它时,我没有得到成员和描述.

But as said earlier, when I enumerate it in code, I don't get members and description.

你们有没有聪明人能帮我弄清楚这里出了什么问题?

Can any of you clever people help me figure out what is going wrong here?

我所有的代码:

        RoleCollection roleCollection = _analysisServer.Databases[dbID].Roles;

        Database database = _analysisServer.Databases[dbID];

        Dictionary<string, CubeRole> roles = new Dictionary<string, CubeRole>();
        foreach (Role role in roleCollection)
        {
            CubeRole cRole = new CubeRole();
            cRole.ID = role.ID;
            cRole.Name = role.Name;

            cRole.Members = role.Members;
            CubeCollection cubeCollection = _analysisServer.Databases[dbID].Cubes;

            foreach (Cube cube in cubeCollection)
            {
                foreach (CubePermission cubePermission in cube.CubePermissions)
                {
                    cRole.Filters = cubePermission.CellPermissions;
                    cRole.Permission.Add(cubePermission);
                }
            }
            roles.Add(cRole.Name, cRole);
        }
        return roles;

推荐答案

使用表格,您可以拥有服务器级别的管理员.而在数据库级别,您只有 3 个内置权限:1) 完全控制 2) 进程数据库 &3)阅读.您在数据库中创建的每个角色都可以选择这些权限.表格中没有多维数据集,因此您只有 2 个级别,服务器和数据库.MSDN 是理解权限的一个很好的起点表格中的角色 https://msdn.microsoft.com/en-us/library/hh213165.aspx

With tabular you can have administrators at the server level. And at the database level you have just 3 built-in permissions: 1) Full Control 2) Process Database & 3) Read. Each role you create in a database can have a selection of these permissions. There are no cubes in tabular so you just have the 2 levels, server & database. MSDN is a good starting point for understanding permissions & roles in tabular https://msdn.microsoft.com/en-us/library/hh213165.aspx

您可以遍历数据库的角色以提取每个角色中的角色成员以及与每个角色关联的权限:

You can loop through the roles of a database to pull out the role member in each and the permissions associated with each role:

   //loop through database permissions
   foreach (AMO.DatabasePermission dbp in Analysisdb.DatabasePermissions)
          {
           Console.Write(dbp.Role.Name); //role name
           Console.Write(dbp.Read); // Is read role?
           Console.Write(dbp.Process); // Is process role?
           Console.Write(dbp.Administer); // Is Full control role?
          //loop through database permissions role members
          foreach (AMO.RoleMember rolemember in dbp.Role.Members)
              { 
              Console.Write(rolemember.Name); 
               }
          }

可以通过循环遍历每个角色的每个维度来提取每个维度的 DAX 表达式.下面的示例将获取 codeplex AdventureWorks 示例模型中用户角色的货币维度的 DAX 表达式:

The DAX expressions for each dimension can be pulled out by looping through every dimension for every role. This example below will get the DAX expression for the Currency dimension for the Users role in the codeplex AdventureWorks sample model:

     using (AMO.DimensionPermission dimensionPermission = AnalysisDb.Dimensions.GetByName("Currency").DimensionPermissions[0]);
Console.Write(dimensionPermission.AllowedRowsExpression);

参见 http://tabularamo2012.codeplex.com/SourceControl/latest#AMO2TabularV2/AMO2Tabular.RlsFunctions.cs 了解更多关于表格 AMO 的信息.

See http://tabularamo2012.codeplex.com/SourceControl/latest#AMO2TabularV2/AMO2Tabular.RlsFunctions.cs for more on tabular AMO.

这篇关于C# amo 完成角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆