September 2, 2009

AzMan Create/Remove Application with C#

As I continue to go through my old AzMan projects, I am going to show some more helper classes that I whipped up. I already showed how easy it is to create a store, but what about an application? Well, this is also easily done with the current API. I have uploaded a helper class here which has some comments not included in the short snippets below as well as simple checking for existing store. This class was designed to work with XML and AD (sorry not sql server yet).

Some examples:
public static IAzApplication AddApplication(IAzAuthorizationStore store, string applicationName)
{
if (applicationName == null || applicationName.Length == 0)
{
throw new ArgumentNullException("applicationName", "Application name can not be null or empty.");
}
if (store == null)
{
throw new ArgumentNullException("store", "Store can not be null.");
}

IAzApplication app = store.CreateApplication(applicationName, null);

app.Submit(0, null);

return app;
}

Here is how to remove that application:
public static void RemoveApplication(IAzAuthorizationStore store, string applicationName)
{
if (applicationName == null || applicationName.Length == 0)
{
throw new ArgumentNullException("applicationName", "Application name can not be null or empty.");
}
if (store == null)
{
throw new ArgumentNullException("store", "Store can not be null.");
}

store.DeleteApplication(applicationName , null);

store.Submit(0, null);
}

How about just getting the application:
public static IAzApplication GetApplication(string storeUrl, string applicationName)
{
if (applicationName == null || applicationName.Length == 0)
{
throw new ArgumentNullException("applicationName", "Application name can not be null or empty.");
}
if (storeUrl == null || storeUrl.Length == 0)
{
throw new ArgumentNullException("storeUrl", "Store URL can not be null or empty.");
}

//http://www.box.net/shared/ubs0oebs0l to get storehelper
IAzAuthorizationStore store = StoreHelper.GetStore(storeUrl);
return store.OpenApplication(applicationName, null);
}

What about getting application names from the store?
public static string[] GetApplicationNames(IAzAuthorizationStore store)
{
if (store == null)
{
throw new ArgumentNullException("store", "Store can not be null.");
}

ArrayList applicationNames = new ArrayList();

foreach (IAzApplication app in store.Applications)
{
applicationNames.Add(app.Name);
}

return (string[])applicationNames.ToArray(typeof(string));
}

No comments:

Post a Comment