September 5, 2009
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)Now let's delete that task:
{
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;
}
public static void RemoveRoleDefinition(IAzApplication app, string roleDefinitionName)Get task by name:
{
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);
}
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);
}
September 3, 2009
AzMan Create/Remove/Get Operation with C#
Seems this is kind of shaping up into a bit of a series. As a background since someone asked me yesterday, all this code was used within a webservice for AzMan a few years ago. The idea was that the MMC console is really bad, and we wanted a better way to add things. Also, not everyone had access to the server and we wanted to make this web based for those users.
We have already seen how to add a store and create an application in AzMan using C#. Now, let's go on to creating an operation 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. This class was designed to work with XML and AD (sorry not sql server yet).
We have already seen how to add a store and create an application in AzMan using C#. Now, let's go on to creating an operation 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. This class was designed to work with XML and AD (sorry not sql server yet).
public static IAzOperation AddOperation(IAzApplication app, string operationName)Now let's delete that operation:
{
if (operationName == null || operationName.Length == 0)
{
throw new ArgumentNullException("operationName", "Operation name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}
IAzOperation operation = app.CreateOperation(operationName, null);
operation.Submit(0, null);
return operation;
}
public static void RemoveOperation(IAzApplication app, string operationName)Get operation by name:
{
if (operationName == null || operationName.Length == 0)
{
throw new ArgumentNullException("operationName", "Operation name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}
app.DeleteOperation(operationName , null);
app.Submit(0, null);
}
public static IAzOperation GetOperation(IAzApplication app, string operationName)
{
if (operationName == null || operationName.Length == 0)
{
throw new ArgumentNullException("operationName", "Operation name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}
return app.OpenOperation(operationName, null);
}
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:
Here is how to remove that application:
How about just getting the application:
What about getting application names from the store?
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));
}
September 1, 2009
Software Transactional Memory
I recently came across this on MSDN.
"Software Transactional Memory (STM.NET) is a mechanism for efficient isolation of shared state. The programmer demarcates a region of code as operating within a transaction that is “atomic” and “isolated” from other transacted code running concurrently."
This is an experimental release allowing c# coders to try this technology out. It requires VS 2008 and is only available now for c#. I will have to find a machine to test this out though since I am on 64 bit and it only supports 32.
Exciting though to see this...
"Software Transactional Memory (STM.NET) is a mechanism for efficient isolation of shared state. The programmer demarcates a region of code as operating within a transaction that is “atomic” and “isolated” from other transacted code running concurrently."
This is an experimental release allowing c# coders to try this technology out. It requires VS 2008 and is only available now for c#. I will have to find a machine to test this out though since I am on 64 bit and it only supports 32.
Exciting though to see this...
August 31, 2009
August 30, 2009
Compare Hotfixes on Server using Powershell
I came across this script on the Powershell Code Repository site. Props to the author as this is very helpful. I am showing the code below as sometimes hitting the community site is very slow:
Function Compare-InstalledHotfix {
param (
[parameter(Mandatory=$true,Position=0)]
$server1,
[parameter(Mandatory=$true,Position=1)]
$server2,
[parameter(Mandatory=$true,Position=3)]
[Management.Automation.PSCredential]
$credential
)
$server1HotFix = get-hotfix -computer $server1 -Credential $credential | select HotfixId
$server2HotFix = get-hotfix -computer $server2 -Credential $credential | select HotfixId
$comparedHotfixes = compare-object $server2HotFix $server1HotFix -IncludeEqual
$result = @();
foreach ($c in $comparedHotfixes) {
$kbinfo = "" | select KB,$server1,$server2
$kbinfo.KB = $c.InputObject.HotfixId
switch ($c.SideIndicator)
{
"==" {
write-host -ForegroundColor Green "Both servers have $($c.InputObject.HotfixId)"
$kbinfo.($server1) = $true
$kbinfo.($server2) = $true
$result += $kbinfo
}
"=>" {
write-host -ForegroundColor Yellow "$server1 has $($c.InputObject.HotfixId) but $server2 doesn't"
$kbinfo.($server1) = $true
$kbinfo.($server2) = $false
$result += $kbinfo
}
"<=" { write-host -ForegroundColor Magenta "$server2 has $($c.InputObject.HotfixId) but $server1 doesn't" $kbinfo.($server1) = $false $kbinfo.($server2) = $true $result += $kbinfo } } # End Switch } # End foreach $result } # End Function
Subscribe to:
Posts (Atom)