August 29, 2009

Good Weekend

Hope everyone is having a great weekend!

August 28, 2009

AzMan Create/Remove Store with C#

I was looking through some old projects I did in AzMan as some are relevant to questions I received over the last few weeks. One person wanted to be able to create/remove a store through c#. This is 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 IAzAuthorizationStore CreateStore(string storeUrl)
{
if (storeUrl == null || storeUrl.Length == 0)
{
throw new ArgumentNullException("storeUrl", "Store URL can not be null or empty.");
}

IAzAuthorizationStore store = new AzAuthorizationStoreClass();
store.Initialize(1, storeUrl, null);

store.Submit(0, null);

return store;
}

Here is how to remove that store:

public static void RemoveStore(string storeUrl)
{
if (storeUrl == null || storeUrl.Length == 0)
{
throw new ArgumentNullException("storeUrl", "Store URL can not be null or empty.");
}

IAzAuthorizationStore store = GetStore(storeUrl);

store.Delete(null);
}

August 27, 2009

Powershell and XAML

Someone asked me if you can load up xaml in powershell. My response was "What can't powershell do!". The only thing is that you must start powershell using a single-threaded apartment like:
powershell -sta -file MyXAML.ps1
Here is one way of doing it with the xaml file not directly in the powershell script:
Add-Type -AssemblyName PresentationFramework
[System.Reflection.Assembly]::LoadFrom(".\lib\WPFToolkit.dll")
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

function LoadXaml
{
param($fileName)

[xml]$xaml = [IO.File]::ReadAllText($fileName)
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
[Windows.Markup.XamlReader]::Load( $reader )
}

# Load XAML
$app = new-object System.Windows.Application
$form = LoadXaml('.\dialog.xaml')
Your dialog.xaml file can look like:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
>
Title="Window1" Height="300" Width="408">
<Canvas>
<Button x:Name='button1'
Width='75'
Height='23'
Canvas.Left='118'
Canvas.Top='10'
Content='Click Here' />
</Canvas>
</Window>

August 26, 2009

Log4net ADO.NET Appender

Here is a simple way to make sure you don't have to put the connectionstring in the config file for Log4Net and instead just pull it from the connectionString setting:
using System;
using System.Collections.Generic;
using System.Configuration;
using log4net.Appender;
using System.Data.Common;

namespace Log4net.Appender
{
public class AppSettingsConnectionStringAdoNetAppender : AdoNetAppender
{
string _connectionStringName;

public string ConnectionStringName
{
get { return _connectionStringName; }

set
{
if (string.IsNullOrEmpty(value))
throw new ArgumentException("Null or empty connection string name.");

try
{
ConnectionStringSettings connectionString =
ConfigurationManager.ConnectionStrings[value];

DbProviderFactory factory = DbProviderFactories.GetFactory(
connectionString.ProviderName);

using (DbConnection connection = factory.CreateConnection())
{
this.ConnectionType = connection.GetType().ToString();
this.ConnectionString = connectionString.ConnectionString;
}

_connectionStringName = value;
}
catch(Exception ex)
{
throw new ArgumentException("We can't initialize connection string from the name passed. " + value, ex);
}
}
}
}
}
Take this code and add it to your appender library or create your own library and build the assembly. After that, in your log4net config file you can call the appender now like any other appender:
<appender name="My_AdoNetAppender" type="Log4Net.Appender.AppSettingsConnectionStringAdoNetAppender, JLFramework.Log4Net.Appender">
</appender>

August 25, 2009

Quiet Day

I don't know if it is a good thing or bad thing to have a really quiet day right after coming back from vacation. Anyway, I am working on my new projects and still trying to come up with a good domain name. I never thought it would be this hard!

August 24, 2009

Catching Up

On close to 450 emails..most seems to be shift delete ;)

August 23, 2009

BBQ Time

Time to grab a quick bbq over at a friend :) Hope everyone is having a nice weekend.