Umm, welcome to the confusion that is AzMan :-) There are currently 3 different versions/interfaces, with 2 different methods of doing what you ask.
From the stanard COM interface (IAzApplication), app.Roles refers to Role Assignments (Member assigned to roles), whereas I think what you want are Role Definitions, which weren't introduced as their own type until later in version 3.
For IAzApplication: to access Role Definitions you need to iterate over all the app.Tasks and check the task.IsRoleDefinition flag to get the role definitions.
NOTE: You should also bear in mind that what you're attempting to do is not quite as simple in AzMan as your original code solution. Roles can consist of sub-Roles, Tasks and Operations, Tasks can consist of sub-Tasks and Operations .. so you really need to recurse over the roles to build up a complete list of operations, tasks and roles in each given role.
The following code will output a full hierarchy of an apps Role Definitions for all versions of AzMan (just to be fancy it's got a .NET 3.5 callback lambda and a generic in it, but this could be re-written for .NET 1.0 easy enough). The callback returns the type (Role, Task, Operation), name and the hierarchy depth (for indenting):
private static void ProcessAzManRoleDefinitions(IAzApplication app, IAzTask task, int level, Action<string, string, int> callbackAction)
{
bool isRole = (task.IsRoleDefinition == 1);
callbackAction((isRole ? "Role" : "Task"), task.Name, level);
level++;
// Iterate over any subtasks defined for this task (or role)
Array tasks = (Array)task.Tasks;
foreach (string taskName in tasks)
{
IAzTask currentTask = app.OpenTask(taskName, null);
// Need to recursively process child roles and tasks
ProcessAzManRoleDefinitions(app, currentTask, level, callbackAction);
}
// Iterate over any opeations defined for this task (or role)
Array taskOperations = (Array)task.Operations;
foreach (string operationName in taskOperations)
callbackAction("Operation", operationName, level);
}
private static string GetRoleDefinitionHierarchy()
{
AzAuthorizationStore azManStore = new AzAuthorizationStoreClass();
azManStore.Initialize(0, "connectionstring", null);
IAzApplication azApp = azManStore.OpenApplication("TestApp", null);
StringBuilder output = new StringBuilder();
foreach (IAzTask task in azApp.Tasks)
{
if (task.IsRoleDefinition == 1)
ProcessAzManRoleDefinitions(azApp, task, 0, (type, name, level) => output.Append("".PadLeft(level * 2) + type + ": " + name + "\n"));
}
return output.ToString();
}
If you know your target platform is going to be Windows 7, Vista or Windows Server 2008 then you should be using the IAzManApplication3 interface, and this is a lot better defined (RoleDefinition has it's own collection/type). If you're developing on Windows XP, you will need to install the Windows Server 2008 Administration Pack and this will come with the updated AzMan DLL.
For AzMan v3, the following code will iterate over the hierarchy of Role Definitions, Tasks and Operations (it's the v3 equivalent of what you were asking originally):
private string GetAllRoleDefinitionHierarchies()
{
AzAuthorizationStore azManStore = new AzAuthorizationStoreClass();
azManStore.Initialize(0, "connectionstring", null);
IAzApplication3 azApp = azManStore.OpenApplication("TestApp", null) as IAzApplication3;
if (azApp == null)
throw new NotSupportedException("Getting Role Definitions is not supported by older versions of AzMan COM interface");
StringBuilder output = new StringBuilder();
foreach (IAzRoleDefinition currentRoleDefinition in azApp.RoleDefinitions)
{
output.Append(currentRoleDefinition.Name + "<br />");
Array roleTasks = (Array) currentRoleDefinition.Tasks;
foreach (string taskId in roleTasks)
{
IAzTask currentTask = azApp.OpenTask(taskId, null);
output.Append(" - Task: " + currentTask.Name + "<br />");
Array taskOperations = (Array)currentTask.Operations;
foreach (string operationId in taskOperations)
{
IAzOperation currentOperation = azApp.OpenOperation(operationId, null);
output.Append(" - Operation: " + currentOperation.Name + "<br />");
}
}
}
return output.ToString();
}
There are no enumerators on the tasks or operations, just an array of names, so if you want anything other than the name you need to call App.OpenXXX() to get more information.
Hope this helps ...