<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Musings and frustrations</title>
	<atom:link href="http://peteohanlon.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://peteohanlon.wordpress.com</link>
	<description>Rants, musings and disjointed thoughts from a confused world</description>
	<pubDate>Tue, 22 Apr 2008 20:15:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Still lovin&#8217; WPF</title>
		<link>http://peteohanlon.wordpress.com/2008/04/22/still-lovin-wpf/</link>
		<comments>http://peteohanlon.wordpress.com/2008/04/22/still-lovin-wpf/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 20:12:35 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/?p=22</guid>
		<description><![CDATA[In a previous  post I looked at why WPF was something to really take a look at. I posted a bare bones WPF page that just contained a status bar. In this post, I&#8217;d like to show how to spruce the WPF up with just a little bit of effort (and hopefully to demonstrate why [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In a <a title="Lovin' WPF" href="http://peteohanlon.wordpress.com/2008/04/20/lovin-wpf/">previous </a> post I looked at why WPF was something to really take a look at. I posted a bare bones WPF page that just contained a status bar. In this post, I&#8217;d like to show how to spruce the WPF up with just a little bit of effort (and hopefully to demonstrate why I really like it).</p>
<p>Anyway, without further ado, here is the updated class:</p>
<pre>&lt;Window x:Class="WorkforcePF.Window1"
    xmlns="<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>"
    xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>"
    Title="Main Window" Height="450" Width="600"&gt;
    &lt;Window.Resources&gt;
        &lt;LinearGradientBrush x:Key="MyBlueGradientBrush" EndPoint="0,1" StartPoint="0,0"&gt;
            &lt;GradientStop Color="#FFE3EFFF" Offset="0"/&gt;
            &lt;GradientStop Color="#FFD4E5FC" Offset="0.2"/&gt;
            &lt;GradientStop Color="#FFB3CFF5" Offset="0.6"/&gt;
            &lt;GradientStop Color="#FF89B3ED" Offset="1"/&gt;
        &lt;/LinearGradientBrush&gt;
    &lt;/Window.Resources&gt;
    &lt;DockPanel&gt;
        &lt;StatusBar Name="statusBar1" Background="{StaticResource MyBlueGradientBrush}" 
            Height="20" VerticalAlignment="Bottom" DockPanel.Dock="Bottom"&gt;
            &lt;StatusBar.ItemsPanel&gt;
                &lt;ItemsPanelTemplate&gt;
                    &lt;Grid&gt;
                        &lt;Grid.RowDefinitions&gt;
                            &lt;RowDefinition Height="*"/&gt;
                        &lt;/Grid.RowDefinitions&gt;
                        &lt;Grid.ColumnDefinitions&gt;
                            &lt;ColumnDefinition Width="4*" /&gt;
                            &lt;ColumnDefinition Width="*" /&gt;
                        &lt;/Grid.ColumnDefinitions&gt;
                    &lt;/Grid&gt;
                &lt;/ItemsPanelTemplate&gt;
            &lt;/StatusBar.ItemsPanel&gt;
            &lt;StatusBarItem&gt;Ready&lt;/StatusBarItem&gt;
            &lt;StatusBarItem Grid.Column="1"&gt;
                &lt;TextBlock TextAlignment="Right"&gt;Set&lt;/TextBlock&gt;
            &lt;/StatusBarItem&gt;
        &lt;/StatusBar&gt;
    &lt;/DockPanel&gt;
&lt;/Window&gt;</pre>
<p>As you can see, we have declared a style (similar to the way you think of styles in CSS). The background of the statusbar is set to this style and, lo-and-behold, the status bar now has a nice blue gradient. In the next post, we&#8217;ll look at adding extra elements and see how the styling can help it to stand out more. </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=22&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/04/22/still-lovin-wpf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Lovin&#8217; WPF</title>
		<link>http://peteohanlon.wordpress.com/2008/04/20/lovin-wpf/</link>
		<comments>http://peteohanlon.wordpress.com/2008/04/20/lovin-wpf/#comments</comments>
		<pubDate>Sun, 20 Apr 2008 20:49:42 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<category><![CDATA[ItemsPanelTemplate]]></category>

		<category><![CDATA[StatusBar]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/?p=21</guid>
		<description><![CDATA[Recently we&#8217;ve been moving more and more towards using WPF to deliver LOB applications (Line Of Business). It took me a while to persuade the team that WPF was something worth investing time and effort in, which is funny really because they normally jump at the chance to play with new technologies. So, how did [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently we&#8217;ve been moving more and more towards using WPF to deliver LOB applications (Line Of Business). It took me a while to persuade the team that WPF was something worth investing time and effort in, which is funny really because they normally jump at the chance to play with new technologies. So, how did I do it? Ironically - it was with a hugely trivial example; a status bar. Basically I showed them how the same code could be written in markup in two ways. The first one was:</p>
<pre>&lt;Window x:Class="WorkforcePF.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="300" Width="300"&gt;
  &lt;DockPanel&gt;
    &lt;StatusBar Name="statusBar1" Height="20" VerticalAlignment="Bottom"
      DockPanel.Dock="Bottom"&gt;
      &lt;StatusBar.ItemsPanel&gt;
        &lt;ItemsPanelTemplate&gt;
          &lt;Grid&gt;
            &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="*"/&gt;
            &lt;/Grid.RowDefinitions&gt;
            &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="4*" /&gt;
              &lt;ColumnDefinition Width="Auto" /&gt;
              &lt;ColumnDefinition/&gt;
            &lt;/Grid.ColumnDefinitions&gt;
          &lt;/Grid&gt;
        &lt;/ItemsPanelTemplate&gt;
      &lt;/StatusBar.ItemsPanel&gt;
      &lt;StatusBarItem&gt;Ready&lt;/StatusBarItem&gt;
      &lt;StatusBarItem Grid.Column="1" Content="StatusBarItem" /&gt;
    &lt;/StatusBar&gt;
  &lt;/DockPanel&gt;
&lt;/Window<span style="font-size:x-small;color:#0000ff;"><span style="font-size:x-small;color:#0000ff;">&gt;</span></span></pre>
<p>while the second one was:</p>
<pre>&lt;Window
 xmlns="<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation">http://schemas.microsoft.com/winfx/2006/xaml/presentation</a>"
 xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>"
 x:Class="StatusBarInWpf.Window1"
 x:Name="Window"
 Title="Window1"
 Width="640" Height="480"&gt;

 &lt;Window.Resources&gt;
  &lt;ItemsPanelTemplate x:Key="StatusBarItemTemplate"&gt;
   &lt;Grid&gt;
    &lt;Grid.ColumnDefinitions&gt;
     &lt;ColumnDefinition Width="4*"/&gt;
     &lt;ColumnDefinition Width="Auto"/&gt;
     &lt;ColumnDefinition/&gt;
    &lt;/Grid.ColumnDefinitions&gt;
    &lt;Grid.RowDefinitions&gt;
     &lt;RowDefinition/&gt;
    &lt;/Grid.RowDefinitions&gt;
   &lt;/Grid&gt;
  &lt;/ItemsPanelTemplate&gt;
 &lt;/Window.Resources&gt;

 &lt;DockPanel&gt;
  &lt;StatusBar Height="20" DockPanel.Dock="Bottom" ItemsPanel="{DynamicResource StatusBarItemTemplate}"&gt;
   &lt;StatusBarItem Content="Ready" Grid.Column="0"/&gt;
   &lt;StatusBarItem Content="StatusBarItem" Grid.Column="1"/&gt;
  &lt;/StatusBar&gt;
 &lt;/DockPanel&gt;
&lt;/Window&gt;</pre>
<p>The thing I love about the second version is the way that the StatusBar template is removed from the actual implementation of the StatusBar, so you can move them into one place (currently in the Window.Resources but this could be put into a named template or the Application.Resources) and manage them really easily.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=21&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/04/20/lovin-wpf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>I won an armageddon button.</title>
		<link>http://peteohanlon.wordpress.com/2008/04/03/i-won-an-armageddon-button/</link>
		<comments>http://peteohanlon.wordpress.com/2008/04/03/i-won-an-armageddon-button/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 12:03:44 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/?p=20</guid>
		<description><![CDATA[Woo hoo. At www.community-credit.com, I won a nuclear war USB hub. It&#8217;s really cool. Check it out at http://www.community-credit.com/CommunityCreditPrizePage.aspx. Just look under March 2008 prizes. If you haven&#8217;t joined Community Credit, then I suggest you do so pronto.
       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Woo hoo. At <a href="http://www.community-credit.com/">www.community-credit.com</a>, I won a nuclear war USB hub. It&#8217;s really cool. Check it out at <a href="http://www.community-credit.com/CommunityCreditPrizePage.aspx">http://www.community-credit.com/CommunityCreditPrizePage.aspx</a>. Just look under March 2008 prizes. If you haven&#8217;t joined Community Credit, then I suggest you do so pronto.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=20&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/04/03/i-won-an-armageddon-button/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Help me - I&#8217;m a user.</title>
		<link>http://peteohanlon.wordpress.com/2008/03/13/help-me-im-a-user/</link>
		<comments>http://peteohanlon.wordpress.com/2008/03/13/help-me-im-a-user/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 14:14:44 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/?p=19</guid>
		<description><![CDATA[I need help. I&#8217;m a user - I admit it. I love using the using statement in C# (I&#8217;m not talking about the one that&#8217;s equivalent to the #include statement). Imagine my surprise that some people haven&#8217;t heard of this wonderful, wonderful keyword.
So what does it actually do? Well, you can think of it as [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I need help. I&#8217;m a user - I admit it. I love using the using statement in C# (I&#8217;m not talking about the one that&#8217;s equivalent to the #include statement). Imagine my surprise that some people haven&#8217;t heard of this wonderful, wonderful keyword.</p>
<p>So what does it actually do? Well, you can think of it as automatically calling <strong>Dispose</strong> on a disposable object. Effectively, it translates into a try/finally block where Dispose is called automatically in the finally section. So:</p>
<pre>using (SqlConnection conn = new SqlConnection())
{
 // Do something...
}</pre>
<p>translates into</p>
<pre>SqlConnection conn = null;
try
{
  conn = new SqlConnection();
  // Do something..
}
finally
{
  if (conn != null &amp;&amp; conn is IDisposable)
    ((IDisposable)conn).Dispose();
 
}</pre>
<p>It&#8217;s perfectly possible to nest using blocks, and the compiler will ensure that Dispose is called in the correct fashion. So, if a class has a Dispose method, you should really consider wrapping it in a using(&#8230;) block.</p>
<p>Warning - If the class you are referencing in the using statement doesn&#8217;t implement IDisposable then you can&#8217;t do this.</p>
<p>Now, did you know that you can alias namespaces in a using statement? It&#8217;s true - if you don&#8217;t want to put in that StreamWriter is in the System.IO namespace all over your code and you are in the midst of classname conflicts, it&#8217;s a simple matter to put something like the following in your code:</p>
<p>using io = System.IO;</p>
<p>Then, elsewhere in your code you can use:</p>
<pre>using (io.StreamWriter sw = new io.StreamWriter(@"c:\dev.txt"))
{
}</pre>
<p>Note the &#8220;clever&#8221; use of the two different using types.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=19&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/03/13/help-me-im-a-user/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Returning status 500 from an HttpHandler</title>
		<link>http://peteohanlon.wordpress.com/2008/03/02/returning-status-500-from-an-httphandler/</link>
		<comments>http://peteohanlon.wordpress.com/2008/03/02/returning-status-500-from-an-httphandler/#comments</comments>
		<pubDate>Sun, 02 Mar 2008 20:28:19 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/?p=18</guid>
		<description><![CDATA[Recently, on The Code Project, a question was posted about returning the status 500 and it not actually working. I suggested that an HttpHandler would be the way to cope with this, and the original poster asked how to do this. Rather than posting the answer there, I decided to post it here. Without further ado, [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently, on <a target="_blank" href="http://www.codeproject.com/script/Forums/View.aspx?fid=12076&amp;msg=2447440" title="The Code Project">The Code Project</a>, a question was posted about returning the status 500 and it not actually working. I suggested that an HttpHandler would be the way to cope with this, and the original poster asked how to do this. Rather than posting the answer there, I decided to post it here. Without further ado, this is how it is done:</p>
<pre>/// &lt;summary&gt;
/// Base class for ensuring that the handler always returns
/// a status code.
/// &lt;/summary&gt;
public abstract class StatusHandlerBase : IHttpHandler
{
  private int _returnStatus = 400;
  /// &lt;summary&gt;
  /// Initializes a new instance of &lt;see cref="StatusHandlerBase" /&gt;.
  /// &lt;/summary&gt;
  public StatusHandlerBase() {}
  /// &lt;summary&gt;
  /// Initializes a new instance of &lt;see cref="StatusHandlerBase" /&gt;.
  /// &lt;/summary&gt;
  /// &lt;param ref="status"&gt;The Http status code&lt;/param&gt;
  public StatusHandlerBase(int status)
  {
    _returnStatus = status;
  }
  /// &lt;summary&gt;
  /// Don't let the response be cached by the browser. Set up the status code
  /// and return.
  /// &lt;/summary&gt;
  public virtual void ProcessRequest(HttpContext context)
  {
    context.Response.Cache.SetCacheablity(HttpCacheability.NoCache);
    context.Response.Cache.SetNoStore();
    context.Response.Cache.SetExpires(DateTime.MinValue);     ParseStatusCode(context, _returnStatus);
  }   /// &lt;summary&gt;
  /// Actually set up the status code at this point, and return.
  /// &lt;/summary&gt;
  protected virtual void ParseStatusCode(HttpContext context, int statusCode)
  {
    context.Response.StatusCode = statusCode;
    context.Response.End();
  }   public bool IsReusable
  {
    get { return true; }
  }
} /// &lt;summary&gt;
/// This concrete implementation of the &lt;see cref="StatusHandlerBase" /&gt; class
/// sets up the http handler to return a status code of 500.
/// &lt;/summary&gt;
public class Return500 : StatusHandlerBase
{
  public Return500() : base(500) {}
}</pre>
<p>Now, one of the things I always like to do is to look for ways to abstract so even in a relatively trivial example like this, there&#8217;s abstraction. I&#8217;m sorry, but there you go - personality quirk and all of that. There you go though, an HttpHandler that returns a 500 status.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=18&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/03/02/returning-status-500-from-an-httphandler/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Return to Regex.</title>
		<link>http://peteohanlon.wordpress.com/2008/02/19/return-to-regex/</link>
		<comments>http://peteohanlon.wordpress.com/2008/02/19/return-to-regex/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 15:57:15 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[Regular Expressions]]></category>

		<category><![CDATA[Date regex]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/2008/02/19/return-to-regex/</guid>
		<description><![CDATA[Continuing with our series on regular expressions, here&#8217;s a more complex example of regular expression testing. In this example, we&#8217;re going to see how to check a date that comes in different formats. The extra wrinkle that we are providing here is that we&#8217;re constraining the date so that it can only be in certain [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Continuing with our series on regular expressions, here&#8217;s a more complex example of regular expression testing. In this example, we&#8217;re going to see how to check a date that comes in different formats. The extra wrinkle that we are providing here is that we&#8217;re constraining the date so that it can only be in certain centuries.</p>
<p>First of all, we&#8217;re going to define how the date is separated out. For instance, if we use DateSeparator.Slash, then the date will be separated by the / character.</p>
<pre>/// &lt;summary&gt;
/// Describes how the date is separated.
/// &lt;/summary&gt;
public enum DateSeparator
{
    /// &lt;summary&gt;
    /// The parts of the date are separated by a space.
    /// &lt;/summary&gt;
    Space,
    /// &lt;summary&gt;
    /// The parts of the date are separated by a slash (/)
    /// &lt;/summary&gt;
    Slash,
    /// &lt;summary&gt;
    /// The parts of the date are separated by a dot (.)
    /// &lt;/summary&gt;
    Dot,
    /// &lt;summary&gt;
    /// The parts of the date are separated by a hyphen (-)
    /// &lt;/summary&gt;
    Hyphen
}</pre>
<p>Next we&#8217;re going to define the format of the date (without separator characters). This basically states the order of the different parts of the date so DateFormat.MonthYearDay corresponds to MMYYYYDD.</p>
<pre>/// &lt;summary&gt;
/// This enumeration tells you the date format that you want to use.
/// &lt;/summary&gt;
public enum DateFormat
{
    /// &lt;summary&gt;
    /// Formatted as YYYYMMDD
    /// &lt;/summary&gt;
    YearMonthDay,
    /// &lt;summary&gt;
    /// Formatted as MMYYYYDD
    /// &lt;/summary&gt;
    MonthYearDay,
    /// &lt;summary&gt;
    /// Formatted as DDMMYYYY
    /// &lt;/summary&gt;
    DayMonthYear,
    /// &lt;summary&gt;
    /// Formatted as YYMMDD
    /// &lt;/summary&gt;
    ShortYearMonthDay,
    /// &lt;summary&gt;
    /// Formatted as MMYYDD
    /// &lt;/summary&gt;
    ShortMonthYearDay,
    /// &lt;summary&gt;
    /// Formatted as DDMMYY
    /// &lt;/summary&gt;
    ShortDayMonthYear,
}</pre>
<p>Finally we&#8217;re going to provide the methods to actually parse the date. Here there are 3 versions of the IsValidDate, with suitable overrides.</p>
<pre>/// &lt;summary&gt;
/// Checks to see if this is a valid date.
/// &lt;/summary&gt;
/// &lt;param name="date"&gt;The date to check.&lt;/param&gt;
/// &lt;param name="separator"&gt;The &lt;see cref="DateSeparator"/&gt; for this date.&lt;/param&gt;
/// &lt;returns&gt;True if the date is valid, false otherwise.&lt;/returns&gt;
public static bool IsValidDate(string date, DateSeparator separator)
{
    return IsValidDate(date, separator, DateFormat.YearMonthDay);
} /// &lt;summary&gt;
/// Checks to see if this is a valid date.
/// &lt;/summary&gt;
/// &lt;param name="date"&gt;The date to check.&lt;/param&gt;
/// &lt;param name="separator"&gt;The &lt;see cref="DateSeparator"/&gt; for this date.&lt;/param&gt;
/// &lt;param name="format"&gt;The &lt;see cref="DateFormat"/&gt; for this date.&lt;/param&gt;
/// &lt;returns&gt;True if the date is valid, false otherwise.&lt;/returns&gt;
public static bool IsValidDate(string date,
    DateSeparator separator,
    DateFormat format)
{
    List&lt;int&gt; yearConstrain = new List&lt;int&gt;();
    yearConstrain.Add(19);
    yearConstrain.Add(20);
    return IsValidDate(date, separator, format, yearConstrain);
} /// &lt;summary&gt;
/// Checks to see if this is a valid date.
/// &lt;/summary&gt;
/// &lt;param name="date"&gt;The date to check.&lt;/param&gt;
/// &lt;param name="separator"&gt;The &lt;see cref="DateSeparator"/&gt; for this date.&lt;/param&gt;
/// &lt;param name="format"&gt;The &lt;see cref="DateFormat"/&gt; for this date.&lt;/param&gt;
/// &lt;param name="yearConstrain"&gt;Any century periods that the
/// date needs constraining to.&lt;/param&gt;
/// &lt;returns&gt;True if the date is valid, false otherwise.&lt;/returns&gt;
public static bool IsValidDate(string date,
    DateSeparator separator,
    DateFormat format,
    List&lt;int&gt; yearConstrain)
{
    if (string.IsNullOrEmpty(date))
        throw new ArgumentNullException("date");
    // Ensure that we have some base periods to check for "long" date formats.
    if (format == DateFormat.DayMonthYear ||
        format == DateFormat.MonthYearDay ||
        format == DateFormat.YearMonthDay)
    {
        if (yearConstrain == null)
            yearConstrain = new List&lt;int&gt;();
        if (yearConstrain.Count == 0)
        {
            yearConstrain.Add(19);
            yearConstrain.Add(20);
        }
    }     string dayFormat = "(0[1-9]|[12][0-9]|3[01])";
    string monthFormat = "(0[1-9]|1[012])";
    StringBuilder years = new StringBuilder();
    if (yearConstrain != null &amp;&amp; yearConstrain.Count &gt; 0)
    {
        foreach (int i in yearConstrain)
        {
            years.AppendFormat("{0}|", i);
        }
    }
    string yearFormatLong = string.Format(@"({0})\d\d",
        years.ToString().Substring(0, years.ToString().Length -1));
    string yearFormatShort = @"\d\d";
    string baseFormat = "{0}[{3}]{1}[{3}]{2}";
    int yearPos = 0;
    int yearLength = 4;
    int monthPos = 0;
    int dayPos = 0;
    string sep = string.Empty;
    switch (separator)
    {
        case DateSeparator.Dot:
            sep = ".";
            break;
        case DateSeparator.Hyphen:
            sep = "-";
            break;
        case DateSeparator.Slash:
            sep = "/";
            break;
        case DateSeparator.Space:
            sep = " ";
            break;
    }
    switch (format)
    {
        case DateFormat.DayMonthYear:
            dayPos = 0;
            monthPos = 1;
            yearPos = 2;
            baseFormat = string.Format(baseFormat,
                dayFormat,
                monthFormat,
                yearFormatLong,
                sep);
            break;
        case DateFormat.MonthYearDay:
            monthPos = 0;
            yearPos = 1;
            dayPos = 2;
            baseFormat = string.Format(baseFormat,
                monthFormat,
                yearFormatLong,
                dayFormat,
                sep);
            break;
        case DateFormat.ShortDayMonthYear:
            dayPos = 0;
            monthPos = 1;
            yearPos = 2;
            baseFormat = string.Format(baseFormat,
                dayFormat,
                monthFormat,
                yearFormatShort,
                sep);
            break;
        case DateFormat.ShortMonthYearDay:
            monthPos = 0;
            yearPos = 1;
            dayPos = 2;
            baseFormat = string.Format(baseFormat,
                monthFormat,
                yearFormatShort,
                dayFormat,
                sep);
            break;
        case DateFormat.ShortYearMonthDay:
            yearPos = 0;
            monthPos = 1;
            dayPos = 2;
            baseFormat = string.Format(baseFormat,
                yearFormatShort,
                monthFormat,
                dayFormat,
                sep);
            break;
        case DateFormat.YearMonthDay:
            yearPos = 0;
            monthPos = 1;
            dayPos = 2;
            baseFormat = string.Format(baseFormat,
                yearFormatLong,
                monthFormat,
                dayFormat,
                sep);
            break;
    }
    Regex regex = new Regex(baseFormat, RegexOptions.IgnoreCase
        | RegexOptions.Multiline
        | RegexOptions.IgnorePatternWhitespace);
    Match m = regex.Match(date);
    bool success = (m.Success);
    // Now, we need to do a little bit more processing
    // (taking care of invalid dates).
    if (success)
    {
        char sepChar = char.Parse(sep);
        string[] splitDate = date.Split(sepChar) ;
        int day = int.Parse(splitDate[dayPos]);
        int month = int.Parse(splitDate[monthPos]);
        int year = int.Parse(splitDate[yearPos]);
        if (yearLength == 2)
            year = 2000 + year;         if (month == 2)
        {
            if (day &gt; 29)
                success = false;
            else
            {
                if (day == 29 &amp;&amp; !(year % 4 == 0 &amp;&amp;
                    (year % 100 != 0 || year % 400 == 0)))
                    success = false;
            }
        }
        else
        {
            if (day &gt; 30)
            {
                // The following months can only have 30 days.
                if (month == 9 || month == 4 || month == 6 || month == 11)
                    success = false;
            }
        }
    }
    return success;
}</pre>
<p>The first thing that we do is check the input values to make sure they look valid. If no year constraints are applied then we default to the 20th and 21st century (Gregorian Calendar based).</p>
<pre>    if (string.IsNullOrEmpty(date))
        throw new ArgumentNullException("date");
    // Ensure that we have some base periods to check for "long" date formats.
    if (format == DateFormat.DayMonthYear ||
        format == DateFormat.MonthYearDay ||
        format == DateFormat.YearMonthDay)
    {
        if (yearConstrain == null)
            yearConstrain = new List&lt;int&gt;();
        if (yearConstrain.Count == 0)
        {
            yearConstrain.Add(19);
            yearConstrain.Add(20);
        }
    }</pre>
<p>The next section is where we start to flesh out what we are actually going to use as the regular expression. We constrain the day format to be from 01 through to 31.</p>
<pre>    string dayFormat = "(0[1-9]|[12][0-9]|3[01])";</pre>
<p>The month format is constrained to 01 through to 12.</p>
<pre>    string monthFormat = "(0[1-9]|1[012])";</pre>
<p>Next we loop through the year constraints. This is where things become a little bit more complicated. Because we can cater for both long and short date formats, we need to put together constraints that suit both.</p>
<pre>    StringBuilder years = new StringBuilder();
    if (yearConstrain != null &amp;&amp; yearConstrain.Count &gt; 0)
    {
        foreach (int i in yearConstrain)
        {
            years.AppendFormat("{0}|", i);
        }
    }
    string yearFormatLong = string.Format(@"({0})\d\d",
        years.ToString().Substring(0, years.ToString().Length -1));
    string yearFormatShort = @"\d\d";</pre>
<p>Then we build up the format of the search that we will use. The base format consists of a number of placeholders that will be replaced in the regular expression. The {3} is the separator characters, and the other parts are the day, month and year values that will be put in in the order specified in the DateFormat.</p>
<pre>    string baseFormat = "{0}[{3}]{1}[{3}]{2}";</pre>
<p>You may notice that we do a little bit more checking once we get a match back. This final check ensures that nonsense dates such as 30th February and invalid leap years don&#8217;t pass through uncaught. Finally, to call it you can use it like this:</p>
<pre>    string testdate = "2100/02/29";
    List&lt;int&gt; list = new List&lt;int&gt;();
    list.Add(21);
    if (!IsValidDate(testdate, DateSeparator.Slash, DateFormat.YearMonthDay, list))
    {
      Console.WriteLine("This is an invalid date.");
    }</pre>
<p>I hope that this whets your appetite for delving into Regular Expressions and shows you how powerful they can be when combined with other coding techniques to build up a more flexible system. I know you can use DateTime.Parse to do a lot of what I have just shown, but this was intended to demonstrate composition of regular expressions.</p>
<p>Finally, I promised that we&#8217;d revisit the grab tags regex. Basically it allows you to grab tags regardless of whether or not it has nested &lt; characters.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=17&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/02/19/return-to-regex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Regular Expressions revisited.</title>
		<link>http://peteohanlon.wordpress.com/2008/02/12/regular-expressions-revisited/</link>
		<comments>http://peteohanlon.wordpress.com/2008/02/12/regular-expressions-revisited/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 13:58:21 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/2008/02/12/regular-expressions-revisited/</guid>
		<description><![CDATA[Well - it&#8217;s time to visit Regex land again. Thanks to Mustafa for giving me the push I needed to continue with our journey into Regular Expressions. The following regular expression is a one that I find handy from time to time to identify text that occur near to each other. For instance, suppose I [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Well - it&#8217;s time to visit Regex land again. Thanks to Mustafa for giving me the push I needed to continue with our journey into Regular Expressions. The following regular expression is a one that I find handy from time to time to identify text that occur near to each other. For instance, suppose I want to find all of the instances of time in this paragraph where there is another mention of time inside 10 words. This expression allows me to do this easily, and would be called as MatchCollection coll = FindNear(&lt;&lt;paragraph text&gt;&gt;, &#8220;Time&#8221;, &#8220;Time&#8221;, 1, 10).</p>
<p>One little feature of this, is that you can set the minimum number of words that the text must be apart as well.</p>
<p>Anyway - without further ado, here&#8217;s the FindNear function.</p>
<pre>/// &lt;summary&gt;
/// Using this method, you can find instances of a particular word near other text.
/// For instance, you can find Dr near Who when the words occur near each other.
/// This is achieved by constraining the distance of the words that must be between the
/// instances.
/// &lt;/summary&gt;
/// &lt;param name="text"&gt;The text to search.&lt;/param&gt;
/// &lt;param name="findText"&gt;The text to find.&lt;/param&gt;
/// &lt;param name="nearText"&gt;The text to find the text near.&lt;/param&gt;
/// &lt;param name="minWords"&gt;The minimum number of words the two words can be apart.&lt;/param&gt;
/// &lt;param name="maxWords"&gt;The maximum number of words the two words can be apart.&lt;/param&gt;
/// &lt;returns&gt;A match collection containing the find results.&lt;/returns&gt;
public static MatchCollection FindNear(string text,
    string findText,
    string nearText,
    int minWords,
    int maxWords)
{
    if (string.IsNullOrEmpty(text))
        throw new ArgumentNullException("text");
    if (string.IsNullOrEmpty(findText))
        throw new ArgumentNullException("findText");
    if (string.IsNullOrEmpty(nearText))
        throw new ArgumentNullException("nearText");
    if (minWords &gt; maxWords)
        throw new ArgumentOutOfRangeException("minWords");
    if (maxWords == 0)
        throw new ArgumentOutOfRangeException("maxWords");
    string reg = @"\b" + findText +
                    @"\W+(?:\w+\W+){" +
                    minWords +
                    "," +
                    maxWords +"}?" +
                    nearText + @"\b";
    Regex regex = new Regex(reg,
        RegexOptions.IgnoreCase
        | RegexOptions.Multiline
        | RegexOptions.IgnorePatternWhitespace
        );
    return regex.Matches(text);
}</pre>
<p>So, how does it work? Well, it builds up the following regular expression (in the case of the above example):</p>
<pre>\bTime\W+(?:\w+\W+){1,10}?Time\b</pre>
<p>The &#8220;magic&#8221; part is the bit {1,10} which tells the expression how many words can exist between the words you are searching for. In this case it&#8217;s from 1 to 10 words.</p>
<p>I haven&#8217;t forgotten the first part of the series on regular expressions - we&#8217;ll come back to that one in the next installment when I cover a different way to handle dates. In the meantime, have fun playing around with this regular expression.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=16&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/02/12/regular-expressions-revisited/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Config Files and Dlls.</title>
		<link>http://peteohanlon.wordpress.com/2008/01/23/config-files-and-dlls/</link>
		<comments>http://peteohanlon.wordpress.com/2008/01/23/config-files-and-dlls/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 15:50:15 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/2008/01/23/config-files-and-dlls/</guid>
		<description><![CDATA[Well - A request recently came up on CodeProject asking how to associate a config file with a DLL and then use that configuration file. Like me you would think that this would be an easy thing to do, and that it would be taken care of for you automatically. Unfortunately, it would seem that [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Well - A request recently came up on <a href="http://www.codeproject.com" title="CodeProject">CodeProject</a> asking how to associate a config file with a DLL and then use that configuration file. Like me you would think that this would be an easy thing to do, and that it would be taken care of for you automatically. Unfortunately, it would seem that this isn&#8217;t the case - it&#8217;s easy enough to do, but you have to do it yourself. One way to do it would be to use XML to read the configuration file directly and then deal with it from there, but it turns out that there is another way that allows you to use the ConfigurationManager directly. To do this, you need to load the application into a separate application domain and then use remoting to access it. This does give you the ability to load plugins with their own config file and isolate them from the main process just in case they are a bit naughty.</p>
<p>Here&#8217;s a quick overview of the process - suppose you have a config file for your plugin Dll that contains the following settings:</p>
<pre>&lt;appSettings&gt;
  &lt;add key="PluginName" value="My Funky Plugin" /&gt;
  &lt;add key="RequiredVersion" value="2.1" /&gt;
&lt;appSettings&gt;</pre>
<p>Your Dll class may implement the following interface:</p>
<pre>public interface IPluginConfiguration
{
  string PluginName { get ; }
  string RequiredVersion { get ; }
} public class MyPlugin : IPluginConfiguration
{
  public string PluginName
  {
    get
    {
      return ConfigurationManager.AppSettings["PluginName"];
    }
  }
  public string RequiredVersion
  {
    get
    {
      return ConfigurationManager.AppSettings["RequiredVersion"];
    }
  }
}</pre>
<p>Now, in your calling application you could do the following:</p>
<pre>private IPluginConfiguration _config;
public void ActivatePlugin(string configFile, string domainName)
{ 
  AppDomainSetup setup = new AppDomainSetup(); 
  setup.ConfigurationFile = configFile; 
  AppDomain domain = AppDomain.CreateDomain(domainName, null, setup); 
 
  _config = (IPluginConfiguration)domain.CreateInstanceAndUnwrap("MyDll", "MyDll.MyDllClass");
  Console.WriteLine("Name {0}", _config.PluginName);
}</pre>
<p>There you go - you can now refer to the localised config file. It&#8217;s that simple.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=15&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/01/23/config-files-and-dlls/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sql Server, GetDate and Linq to Sql.</title>
		<link>http://peteohanlon.wordpress.com/2008/01/11/sql-server-getdate-and-linq-to-sql/</link>
		<comments>http://peteohanlon.wordpress.com/2008/01/11/sql-server-getdate-and-linq-to-sql/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 09:44:04 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[Linq]]></category>

		<category><![CDATA[SQL]]></category>

		<category><![CDATA[GetDate]]></category>

		<category><![CDATA[SQL Functions]]></category>

		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/2008/01/11/sql-server-getdate-and-linq-to-sql/</guid>
		<description><![CDATA[OK, you&#8217;ve put a default value of GETDATE() on a column in your database and you&#8217;re inserting a record via InsertOnSubmit. Oh no, the current server date isn&#8217;t applied to your record. How can you get the server date and apply it?
Well, it turns out that there&#8217;s a really simple trick that just requires a [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>OK, you&#8217;ve put a default value of GETDATE() on a column in your database and you&#8217;re inserting a record via InsertOnSubmit. Oh no, the current server date isn&#8217;t applied to your record. How can you get the server date and apply it?</p>
<p>Well, it turns out that there&#8217;s a really simple trick that just requires a little bit of skullduggery on your part. (I like that word). Create a partial class that corresponds to your data context. In that class, put the following code:</p>
<pre>[Function(Name="GetDate", IsComposable=true)]
public DateTime GetSystemDate()
{
  MethodInfo mi = MethodBase.GetCurrentMethod() as MethodInfo;
  return (DateTime)this.ExecuteMethodCall(this, mi, new object[]{}).ReturnValue;
}</pre>
<p>Then, all your code needs to do is call GetSystemDate() whenever you need to the current date from SQL.</p>
<p>Note: You may wonder why I&#8217;ve gone to all of this trouble, rather than using DateTime.Now in the client code. By using this method, we get the date and time based on the database server, rather than on client connections which may be set to different times.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=14&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/01/11/sql-server-getdate-and-linq-to-sql/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Refining queries in Linq.</title>
		<link>http://peteohanlon.wordpress.com/2008/01/10/refining-queries-in-linq/</link>
		<comments>http://peteohanlon.wordpress.com/2008/01/10/refining-queries-in-linq/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 09:59:12 +0000</pubDate>
		<dc:creator>peteohanlon</dc:creator>
		
		<category><![CDATA[IQueryable]]></category>

		<category><![CDATA[Linq]]></category>

		<category><![CDATA[Refining Queries]]></category>

		<guid isPermaLink="false">http://peteohanlon.wordpress.com/2008/01/10/refining-queries-in-linq/</guid>
		<description><![CDATA[The more I play around with Linq, the more it really appeals to me. It really is amazing how powerful it is, and how flexible it can actually make your applications. &#8220;Examples&#8221; I hear you cry, &#8220;give me examples&#8221;. Who am I to deny you when you ask so nicely?
Quite often, when an record is [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The more I play around with Linq, the more it really appeals to me. It really is amazing how powerful it is, and how flexible it can actually make your applications. &#8220;Examples&#8221; I hear you cry, &#8220;give me examples&#8221;. Who am I to deny you when you ask so nicely?</p>
<p>Quite often, when an record is deleted in a database, the application design mandates that the record isn&#8217;t physically deleted. Instead, it is given a status of Deleted. This means that retrieval of live records needs to take this status into account. Now, in stored procedures you would add a check for the status in each query that you perform against one of these tables. As you can imagine, this quickly becomes very tedious.</p>
<p>So, how can Linq help to make this situation better? Well one of the tricks that you can employ with Linq is refining queries, so you start with a general query and then refine it until you get to a specific query. So, how does this work in practice? Well, take a look at the following query to get all of the records from a table (cunningly called MyTable in this example):</p>
<pre>protected virtual IQueryable&lt;MyTable&gt; GetAll()
{
  IQueryable&lt;MyTable&gt; query = from myTable in context.MyTable // The context is the DataContext.
     select myTable;
  return query;
}</pre>
<p>Now, as you can see, this query retrieves all of the records from MyTable regardless of status. However, we&#8217;ve already stated that we want a query that retrieves records that have been marked as Deleted (in MyTable, there&#8217;s a bit field called IsDeleted that states whether or not the record has been deleted). It turns out that it&#8217;s really easy to refine these queries. In the next example, we are going to provide methods that refine the original query further and further. We want a method that gets active products, and another method that gets active customers.</p>
<pre>protected virtual IQueryable&lt;MyTable&gt; GetAllLiveItems()
{
  IQueryable&lt;MyTable&gt; query = GetAll();
  query = from myTable in query
          where myTable.IsDeleted == false
          select myTable;
}  public List&lt;MyTable&gt; GetActiveProducts(string name)
{
  IQueryable&lt;MyTable&gt; query = GetAllLiveItems();
  query = from myTable in query
          where myTable.ProductName == name
          select myTable;
  return query.ToList&lt;MyTable&gt;();
}  public List&lt;MyTable&gt; GetActiveCustomers(string name)
{
  IQueryable&lt;MyTable&gt; query = GetAllLiveItems();
  query = from myTable in query
          where myTable.CustomerName == name
          select myTable;
  return query.ToList&lt;MyTable&gt;();
}</pre>
<p>I know, the table normalisation sucks big time, but this is intended to highlight how the queries have been refined. As you can see, the GetAllLiveItems method refines the original GetAll query so that it retrieves records that haven&#8217;t been deleted. The GetActiveCustomers and GetActiveProducts queries take the query from GetAllLiveItems and refine it further still to return the appropriate list. It&#8217;s this ability to refine and extend broad stroke queries that, in my mind, opens Linq up as a real rapid database application development tool.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/peteohanlon.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/peteohanlon.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/peteohanlon.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/peteohanlon.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/peteohanlon.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/peteohanlon.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/peteohanlon.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/peteohanlon.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/peteohanlon.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/peteohanlon.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/peteohanlon.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/peteohanlon.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=peteohanlon.wordpress.com&blog=1230283&post=13&subd=peteohanlon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://peteohanlon.wordpress.com/2008/01/10/refining-queries-in-linq/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>