September 4, 2009

AzMan Create/Remove/Get Task with C#

We have already seen how to add a store,create an application, and add an operation in AzMan using C#. Now, let's go on to creating a task using c#. I have uploaded a helper class here which has some comments not included in the short snippets below as well as some other methods (check if exists etc.). This class was designed to work with XML and AD (sorry not sql server yet).
public static IAzTask AddRoleDefinition(IAzApplication app, string roleDefinitionName)
{
if (roleDefinitionName == null || roleDefinitionName.Length == 0)
{
throw new ArgumentNullException("roleDefinitionName", "RoleDefinition name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}

IAzTask roleDefinition = app.CreateTask(roleDefinitionName, null);
roleDefinition.IsRoleDefinition = 1;
roleDefinition.Submit(0, null);

return roleDefinition;
}
Now let's delete that task:
public static void RemoveRoleDefinition(IAzApplication app, string roleDefinitionName)
{
if (roleDefinitionName == null || roleDefinitionName.Length == 0)
{
throw new ArgumentNullException("roleDefinitionName", "RoleDefinition name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}

app.DeleteTask(roleDefinitionName , null);

app.Submit(0, null);
}
Get task by name:
public static IAzTask GetRoleDefinition(IAzApplication app, string roleDefinitionName)
{
if (roleDefinitionName == null || roleDefinitionName.Length == 0)
{
throw new ArgumentNullException("roleDefinitionName", "RoleDefinition name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}

return app.OpenTask(roleDefinitionName, null);
}

No comments:

Post a Comment