<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Development</title>
        <link>http://www.darkside.co.za/category/2.aspx</link>
        <description>Mostly R&amp;D stuff</description>
        <language>en-ZA</language>
        <copyright>Ryan Schreiber</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>A relook at my Windows service template project</title>
            <link>http://www.darkside.co.za/archive/2011/06/07/another-windows-service-template.aspx</link>
            <description>&lt;p&gt;A while ago I &lt;a title="A Simple Windows Service Template" href="http://www.darkside.co.za/archive/2009/02/11/simple-windows-service-template.aspx" target="_blank"&gt;blogged about a template project&lt;/a&gt; that I often use as my starting point for Windows services. I’ve recently been introduced to a component called &lt;a title="Topshelf" href="http://topshelf-project.com/" target="_blank"&gt;TopShelf&lt;/a&gt; that makes writing a service even simpler as well as taking just about all the plumbing code needed for installing/uninstalling and running in debug mode.&lt;/p&gt;  &lt;p&gt;Here’s an example of the code that goes into the Main method. It sets up the service, name, description, and you tell it what to call on the Start and Stop service control events. &lt;/p&gt;  &lt;div class="CodeCollapse"&gt;   &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;const&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; name = &lt;span style="color: #a31515"&gt;"My Service Host"&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;const&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; description = &lt;span style="color: #a31515"&gt;"My Service Host Description"&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; host = &lt;span style="color: #2b91af"&gt;HostFactory&lt;/span&gt;.New(configuration =&amp;gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                configuration.Service&amp;lt;&lt;span style="color: #2b91af"&gt;ServiceHostControl&lt;/span&gt;&amp;gt;(&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    callback =&amp;gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                        callback.SetServiceName(name);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                        callback.ConstructUsing(s =&amp;gt; &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ServiceHostControl&lt;/span&gt;());&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                        callback.WhenStarted(service =&amp;gt; service.Start());&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                        callback.WhenStopped(service =&amp;gt; service.Stop());&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    });&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                configuration.SetDisplayName(name);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                configuration.SetServiceName(name);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                configuration.SetDescription(description);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                configuration.DependsOnMsSql(); &lt;span style="color: green"&gt;//Just here as an example of some of the features&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                configuration.RunAsLocalService();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            });&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            host.Run();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I make reference in the code above to a class called ServiceHostControl. This class is the only other code I have in my template project as of now – it provides the stub methods for starting and stopping the service.&lt;/p&gt;

&lt;div class="CodeCollapse"&gt;
  &lt;pre style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;internal&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ServiceHostControl&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Start()&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"starting..."&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: green"&gt;//Do everything here to start up the service...&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"started."&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Stop()&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"stopping..."&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: green"&gt;//Do everything here to shut the service down...&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"stopped."&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    }&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;There is no longer a need to have a service installer class anymore either in the project – all this functionality is brought to the party by the Topshelf component. To install your service, you simply drop to a command prompt and type in:&lt;/p&gt;

&lt;div class="Code"&gt;
  &lt;p&gt;&lt;strong&gt;{serviceassembly.exe} install&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;and (as you can most likely guess) to uninstall, you type in:&lt;/p&gt;

&lt;div class="Code"&gt;
  &lt;p&gt;&lt;strong&gt;{serviceassembly.exe} uninstall&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;It’s as simple as that.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/122.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2011/06/07/another-windows-service-template.aspx</guid>
            <pubDate>Tue, 07 Jun 2011 09:00:15 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2011/06/07/another-windows-service-template.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/122.aspx</wfw:commentRss>
        </item>
        <item>
            <title>What&amp;rsquo;s new in Castle ActiveRecord 3 RC?</title>
            <link>http://www.darkside.co.za/archive/2011/03/30/whats-new-castle-activerecord-3.aspx</link>
            <description>&lt;h1&gt;Configuration&lt;/h1&gt;  &lt;p&gt;Version 3 now supports the short-hand configuration options supplied by NHibernate. You choose the DB type, supply a connection string name, and the rest of the defaults are chosen for you.&lt;/p&gt;  &lt;div class="Code"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;configSections&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;section&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;activerecord&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;configSections&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;ARTest&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;connectionString&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Server=(local); Database=ComplexDBTest; Integrated Security=SSPI&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;activerecord&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;config&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;db&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;MsSqlServer2005&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;csn&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;ARTest&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;activerecord&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;h1&gt;SessionScope-less Lazy Loading&lt;/h1&gt;  &lt;p&gt;This is a great change that’s been implemented. The code example below (very contrived, I know, but demonstrates the point) used to throw an exception, but doesn’t anymore. &lt;/p&gt;  &lt;div class="Code"&gt;   &lt;p style="margin: 0px"&gt;    [&lt;span style="color: #2b91af"&gt;ActiveRecord&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"Person"&lt;/span&gt;, Lazy = &lt;span style="color: blue"&gt;true&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;partial&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Person&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;ActiveRecordBase&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Person&lt;/span&gt;&amp;gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        [&lt;span style="color: #2b91af"&gt;PrimaryKey&lt;/span&gt;(Generator = &lt;span style="color: #2b91af"&gt;PrimaryKeyType&lt;/span&gt;.GuidComb, Column = &lt;span style="color: #a31515"&gt;"PersonId"&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;virtual&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt; Id { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        [&lt;span style="color: #2b91af"&gt;HasMany&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ContactNumber&lt;/span&gt;), Table = &lt;span style="color: #a31515"&gt;"ContactNumbers"&lt;/span&gt;, ColumnKey = &lt;span style="color: #a31515"&gt;"PersonId"&lt;/span&gt;, Lazy = &lt;span style="color: blue"&gt;true&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;virtual&lt;/span&gt; &lt;span style="color: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;ContactNumber&lt;/span&gt;&amp;gt; PersonIdContactNumbersList { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    [&lt;span style="color: #2b91af"&gt;ActiveRecord&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"ContactNumber"&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;partial&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ContactNumber&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;ActiveRecordBase&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;ContactNumber&lt;/span&gt;&amp;gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        [&lt;span style="color: #2b91af"&gt;PrimaryKey&lt;/span&gt;(Generator = &lt;span style="color: #2b91af"&gt;PrimaryKeyType&lt;/span&gt;.GuidComb, Column = &lt;span style="color: #a31515"&gt;"ContactNumberId"&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;virtual&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt; Id { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        [&lt;span style="color: #2b91af"&gt;BelongsTo&lt;/span&gt;(Type = &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Person&lt;/span&gt;), Column = &lt;span style="color: #a31515"&gt;"PersonId"&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;virtual&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Person&lt;/span&gt; Person { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    } &lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Program&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;ActiveRecordStarter&lt;/span&gt;.Initialize(&lt;span style="color: #2b91af"&gt;Assembly&lt;/span&gt;.GetExecutingAssembly(), &lt;span style="color: #2b91af"&gt;ActiveRecordSectionHandler&lt;/span&gt;.Instance);&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;ContactNumber&lt;/span&gt; contactNumber;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SessionScope&lt;/span&gt;())&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                contactNumber = &lt;span style="color: #2b91af"&gt;ContactNumber&lt;/span&gt;.FindFirst(&lt;span style="color: #2b91af"&gt;Order&lt;/span&gt;.Asc(&lt;span style="color: #a31515"&gt;"Id"&lt;/span&gt;));&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(contactNumber.Person.Id); &lt;span style="color: green"&gt;//Used to throw an exception&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    }&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;Make sure that in your configuration, (if you’re still specifying the entire config) you’re using the Castle.ActiveRecord.ByteCode.ProxyFactoryFactory proxy factory.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h1&gt;Lazy Loading of Blob Properties&lt;/h1&gt;  &lt;p&gt;You can now use the “Lazy” keyword on blob properties which tells NHibernate not to include this column in the select statement, but only call it when it’s explicitly used. Some notes on this, though: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;If you have more than one column marked as lazy, they are ALL fetched when you access the first one. &lt;/li&gt;    &lt;li&gt;The property should be an auto-prop &lt;/li&gt;    &lt;li&gt;This results in and extra select being fired off when you used this column – it may end up being a problem in large sets of data.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The syntax is straight forward:&lt;/p&gt;  &lt;div class="Code"&gt;   &lt;p style="margin: 0px"&gt;        [&lt;span style="color: #2b91af"&gt;Property&lt;/span&gt; (Column =&lt;span style="color: #a31515"&gt;"Data"&lt;/span&gt;, ColumnType = &lt;span style="color: #a31515"&gt;"BinaryBlob"&lt;/span&gt; , Lazy = &lt;span style="color: blue"&gt;true&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;virtual&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] Data { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }&lt;/p&gt; &lt;/div&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h1&gt;LINQ&lt;/h1&gt;  &lt;p&gt;LINQ support is now rolled into the Castle ActiveRecord assembly, and doesn’t require a reference to another file.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h1&gt;SessionScopeWebModule (Breaking Change)&lt;/h1&gt;  &lt;p&gt;This has been removed from the main Castle ActiveRecord assembly and is now in the assembly Castle.ActiveRecord.Web.dll. You’ll need to update your configuration for the HttpModule as follows:&lt;/p&gt;  &lt;div class="Code"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;httpModules&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;ARScope&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Castle.ActiveRecord.Framework.SessionScopeWebModule, Castle.ActiveRecord.Web&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;httpModules&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;&lt;img src="http://www.darkside.co.za/aggbug/119.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2011/03/30/whats-new-castle-activerecord-3.aspx</guid>
            <pubDate>Wed, 30 Mar 2011 10:37:46 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2011/03/30/whats-new-castle-activerecord-3.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/119.aspx</wfw:commentRss>
        </item>
        <item>
            <title>SqlDependency Helper Class</title>
            <link>http://www.darkside.co.za/archive/2011/02/11/sqldependency-helper-class.aspx</link>
            <description>&lt;p&gt;It’s been a while since I used the SqlDependency class and the features it provides, and was then quite disappointed that I hadn’t a copy of the plumbing code anywhere on my web clipboard (a.k.a darkside.co.za). I’ve put together a static helper class that you can attach an event to, and then call the Start(…) method. &lt;/p&gt;  &lt;p&gt;Here is the code for the class (&lt;strong&gt;UPDATE: &lt;/strong&gt;or you can &lt;a href="http://www.darkside.co.za/files/SqlNotificationHelper.zip" target="_blank"&gt;download it here&lt;/a&gt;):&lt;/p&gt;  &lt;div class="CodeCollapse"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    1&lt;/span&gt; &lt;span style="color: blue"&gt;using&lt;/span&gt; System.Data;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    2&lt;/span&gt; &lt;span style="color: blue"&gt;using&lt;/span&gt; System.Data.SqlClient;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    3&lt;/span&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    4&lt;/span&gt; &lt;span style="color: blue"&gt;namespace&lt;/span&gt; Darkside&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    5&lt;/span&gt; {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    6&lt;/span&gt;     &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlNotificationHelper&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    7&lt;/span&gt;     {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    8&lt;/span&gt;         &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlConnection&lt;/span&gt; m_SqlConnection;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;    9&lt;/span&gt;         &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt; m_SqlCommand;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   10&lt;/span&gt;         &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DataSet&lt;/span&gt; m_DataSet;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   11&lt;/span&gt;         &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; m_ConnectionString;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   12&lt;/span&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   13&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;delegate&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DataChanged&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;DataSet&lt;/span&gt; dataSet);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   14&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;event&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DataChanged&lt;/span&gt; DataChangedEvent;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   15&lt;/span&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   16&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Start(&lt;span style="color: blue"&gt;string&lt;/span&gt; connectionString, &lt;span style="color: blue"&gt;string&lt;/span&gt; sql, &lt;span style="color: #2b91af"&gt;CommandType&lt;/span&gt; commandType)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   17&lt;/span&gt;         {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   18&lt;/span&gt;             m_ConnectionString = connectionString;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   19&lt;/span&gt;             &lt;span style="color: #2b91af"&gt;SqlDependency&lt;/span&gt;.Stop(m_ConnectionString);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   20&lt;/span&gt;             &lt;span style="color: #2b91af"&gt;SqlDependency&lt;/span&gt;.Start(m_ConnectionString);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   21&lt;/span&gt;             &lt;span style="color: blue"&gt;if&lt;/span&gt; (m_SqlConnection == &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   22&lt;/span&gt;                 m_SqlConnection = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlConnection&lt;/span&gt;(m_ConnectionString);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   23&lt;/span&gt;             &lt;span style="color: blue"&gt;if&lt;/span&gt; (m_SqlCommand == &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   24&lt;/span&gt;                 m_SqlCommand = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt;(sql, m_SqlConnection) { CommandType = commandType };&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   25&lt;/span&gt;             &lt;span style="color: blue"&gt;if&lt;/span&gt; (m_DataSet == &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   26&lt;/span&gt;                 m_DataSet = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DataSet&lt;/span&gt;();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   27&lt;/span&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   28&lt;/span&gt;             SetupNotification();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   29&lt;/span&gt;         }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   30&lt;/span&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   31&lt;/span&gt;         &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Stop()&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   32&lt;/span&gt;         {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   33&lt;/span&gt;             &lt;span style="color: #2b91af"&gt;SqlDependency&lt;/span&gt;.Stop(m_ConnectionString);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   34&lt;/span&gt;             &lt;span style="color: blue"&gt;if&lt;/span&gt; (m_SqlConnection != &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   35&lt;/span&gt;                 m_SqlConnection.Close();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   36&lt;/span&gt;         }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   37&lt;/span&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   38&lt;/span&gt;         &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; SqlDependencyOnChange(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;SqlNotificationEventArgs&lt;/span&gt; e)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   39&lt;/span&gt;         {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   40&lt;/span&gt;             &lt;span style="color: blue"&gt;var&lt;/span&gt; sqlDependency = sender &lt;span style="color: blue"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlDependency&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   41&lt;/span&gt;             &lt;span style="color: blue"&gt;if&lt;/span&gt; (sqlDependency != &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   42&lt;/span&gt;                 sqlDependency.OnChange -= SqlDependencyOnChange;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   43&lt;/span&gt;             SetupNotification();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   44&lt;/span&gt;             &lt;span style="color: blue"&gt;if&lt;/span&gt; (DataChangedEvent != &lt;span style="color: blue"&gt;null&lt;/span&gt;)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   45&lt;/span&gt;                 DataChangedEvent(m_DataSet);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   46&lt;/span&gt;         }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   47&lt;/span&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   48&lt;/span&gt;         &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; SetupNotification()&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   49&lt;/span&gt;         {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   50&lt;/span&gt;             m_DataSet.Clear();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   51&lt;/span&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   52&lt;/span&gt;             m_SqlCommand.Notification = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   53&lt;/span&gt;             &lt;span style="color: blue"&gt;var&lt;/span&gt; sqlDependency = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlDependency&lt;/span&gt;(m_SqlCommand);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   54&lt;/span&gt;             sqlDependency.OnChange += SqlDependencyOnChange;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   55&lt;/span&gt;             &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: blue"&gt;var&lt;/span&gt; adapter = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlDataAdapter&lt;/span&gt;(m_SqlCommand))&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   56&lt;/span&gt;             {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   57&lt;/span&gt;                 adapter.Fill(m_DataSet, &lt;span style="color: #a31515"&gt;"DataSet"&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   58&lt;/span&gt;             }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   59&lt;/span&gt;         }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   60&lt;/span&gt;     }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   61&lt;/span&gt; }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: #2b91af"&gt;   62&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And you can use it as follows:&lt;/p&gt;

&lt;div class="Code"&gt;
  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;protected&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; Main()&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;{&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    &lt;span style="color: #2b91af"&gt;SqlNotificationHelper&lt;/span&gt;.DataChangedEvent += &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlNotificationHelper&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;DataChanged&lt;/span&gt;(SqlNotificationHelper_DataChangedEvent);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    &lt;span style="color: #2b91af"&gt;SqlNotificationHelper&lt;/span&gt;.Start(&lt;span style="color: #a31515"&gt;"Server=(local); Database=Test; Integrated Security=SSPI"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"SELECT Id, FirstName, Surname FROM dbo.People"&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;CommandType&lt;/span&gt;.Text);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;}&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; SqlNotificationHelper_DataChangedEvent(System.Data.&lt;span style="color: #2b91af"&gt;DataSet&lt;/span&gt; dataSet)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;{&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;"Event – Data Updated."&lt;/span&gt; + dataSet.Tables[0].Rows.Count);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I should point out that you need to be quite specific in the type of query that you use. The list contained &lt;a title="Creating a Query for Notification" href="http://msdn.microsoft.com/en-us/library/ms181122(SQL.100).aspx" target="_blank"&gt;here on MSDN&lt;/a&gt; is quite comprehensive. The most common pitfalls I can imagine will befall people is using a * in the SELECT statement, and not specifying the table name in two-part format. The change event still fires even if the query isn’t correct, however, it fires repeatedly and can be quite a pain to debug.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/118.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2011/02/11/sqldependency-helper-class.aspx</guid>
            <pubDate>Fri, 11 Feb 2011 09:52:45 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2011/02/11/sqldependency-helper-class.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/118.aspx</wfw:commentRss>
        </item>
        <item>
            <title>A C# Regular Expression for a GUID</title>
            <link>http://www.darkside.co.za/archive/2010/09/03/regex-guid.aspx</link>
            <description>&lt;p&gt;I’ve been searching for a good regular expression to validate a string representation of a GUID, and even though there are 17 results on &lt;a title="GUID search on RegExLib.com" href="http://www.regexlib.com/Search.aspx?k=guid" target="_blank"&gt;RegExLib.com&lt;/a&gt; and 73000+ on Google, I’ve not found one that matches the start and end braces correctly. Every single one I’ve found (without exaggerating, I read over 60 posts while looking)either matches a GUID without the braces, or those that match on a string including the braces allow for either only the first or last to be present.&lt;/p&gt;  &lt;div class="Code"&gt;^(?&amp;lt;-BRACE&amp;gt;\{)?[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}(?&amp;lt;-BRACE&amp;gt;\})?(?(BRACE)^.)$ &lt;/div&gt;  &lt;p&gt;On a side note: The project I’m doing maintenance on is VS2008/.Net 3.5. If you’re using .Net Framework 4, you can use the Guid.Parse and Guid.TryParse methods to validate a Guid.&lt;/p&gt;  &lt;p&gt;UPDATE: I’ve submitted it to &lt;a title="My Guid Regex" href="http://www.regexlib.com/REDetails.aspx?regexp_id=3112" target="_blank"&gt;RegExLib.com&lt;/a&gt;. &lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/117.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2010/09/03/regex-guid.aspx</guid>
            <pubDate>Fri, 03 Sep 2010 09:53:17 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2010/09/03/regex-guid.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/117.aspx</wfw:commentRss>
        </item>
        <item>
            <title>T4 Text Template for Castle ActiveRecord</title>
            <link>http://www.darkside.co.za/archive/2010/08/18/t4-text-template-castle-activerecord.aspx</link>
            <description>&lt;p&gt;I was busy with a(nother) comparison of Castle ActiveRecord and the Microsoft offerings that have shipped with VS2010 just to make sure that I wasn’t missing out on anything. I ended up fiddling with EDMX files, and then custom generation, which then led me to downloading the ADO.Net POCO T4 generation templates and checking out what was in the files. &lt;/p&gt;
&lt;p&gt;I have to admit: when I saw what was in it, I got quite giddy with excitement, followed shortly by feeling like a tool. I can’t believe I’ve missed out on this excellent piece of functionality that has been around for ages. &lt;/p&gt;
&lt;p&gt;I decided to tackle making a template that generated output that matched what is generated by &lt;a target="_blank" href="http://generatorstudio.codeplex.com/"&gt;Generator Studio&lt;/a&gt;, which is an open source project I started with &lt;a target="_blank" href="http://www.fryhard.com/"&gt;FryHard&lt;/a&gt; a few years back, primarily to generate my ActiveRecord classes from my database model. I based my template on the ADO.Net POCO template from Microsoft and used it as my guideline.&lt;/p&gt;
&lt;p&gt;Explaining the code in the TT file is a little out of the scope of this article, but it is &lt;a title="Darkside Castle ActiveRecord CodeGen Template" target="_blank" href="http://www.darkside.co.za/files/DarksideCastleActiveRecordTemplate.zip"&gt;available here for download&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can paste the zip file in&lt;/p&gt;
&lt;div class="Code"&gt;%userprofile%\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#\ &lt;/div&gt;
&lt;p&gt;and then open the Visual Studio Command Prompt (as Administrator) and run:&lt;/p&gt;
&lt;div class="Code"&gt;devenv /installvstemplates &lt;/div&gt;
&lt;p&gt;The command above installs the new templates for Visual Studio.&lt;/p&gt;
&lt;p&gt;The quickest way to use it in much the same way as a generator is as follows:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Create a new class library or windows app project. &lt;/li&gt;
    &lt;li&gt;Add a reference to Castle.ActiveRecord.&lt;/li&gt;
    &lt;li&gt;Add an ADO.NET Entity Data Model to your project. &lt;/li&gt;
    &lt;li&gt;Choose the “Generate from Database” option in the wizard&lt;/li&gt;
    &lt;li&gt;Run through the rest of the wizard adding the tables you’d like to generate ActiveRecord classes from.&lt;/li&gt;
    &lt;li&gt;Open the entity model in the IDE, and change the “Code Generation Strategy” property in the properties tab to “None”. This remove all code from the designer class attached to the EDMX file.&lt;/li&gt;
    &lt;li&gt;Add a new “Castle ActiveRecord Basic Template” item to your project. This is the template contained in the download above. &lt;/li&gt;
    &lt;li&gt;Once the template has been added, you can look at the files generated by it, and there should be 1 each for each table in your database, as well as an additional file that has the same name as the template (except with a .CS extension), that has no functionality in it. This is created by the template (as it was in the original from MS), and I’ve left it there because I’ll most likely use for custom features/base classes as I build on the template.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You should now be able to use the ActiveRecord classes generated as you normally would. &lt;/p&gt;
&lt;p&gt;If you make changes to your model in the EDMX designer, you can simply right-click on the template file in the solution and select the “Run Custom Tool” to regenerate your classes.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/116.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2010/08/18/t4-text-template-castle-activerecord.aspx</guid>
            <pubDate>Wed, 18 Aug 2010 09:32:35 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2010/08/18/t4-text-template-castle-activerecord.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/116.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Initialising Castle ActiveRecord in a WAS-hosted WCF service</title>
            <link>http://www.darkside.co.za/archive/2010/07/16/initialise-castle-activerecord-was-wcf.aspx</link>
            <description>&lt;p&gt;I stumbled upon an interesting problem this morning where Castle ActiveRecord was being initialised correctly in the development environment, but as soon as everything was rolled out to the lab environment, the application would throw errors about AR not being initialised. The error message was along the lines of:&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000" face="Courier New"&gt;An ActiveRecord class (Darkside.Domain.Person) was used but the framework seems not properly initialized. Did you forget about ActiveRecordStarter.Initialize() ?&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;A bit of background info: As is custom in our web projects, we use an HttpModule to do the AR initialisation. In this case, the web project is actually a WAS host for our WCF services. After doing a bit of research, I found out that HttpModules are not executed when running WCF services. The reason we had the illusion it was working in dev is because of a default page that was started when the project was run. This caused the HttpModule to run, which in turn initialised AR for that session.&lt;/p&gt;  &lt;p&gt;Our solution to this problem was to make use of a custom service host factory. I’ve touched on the custom service host factory subject &lt;a href="http://www.darkside.co.za/archive/2008/02/21/custom-servicehostfactory-for-wcf-and-iis.aspx" target="_blank"&gt;here&lt;/a&gt; before, and this solution is just another use of it.&lt;/p&gt;  &lt;div class="Code"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CustomServiceHostFactory&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;ServiceHostFactory&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;{&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;readonly&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt; m_InitActiveRecordLock = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: blue"&gt;object&lt;/span&gt;();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; System.ServiceModel.&lt;span style="color: #2b91af"&gt;ServiceHostBase&lt;/span&gt; CreateServiceHost(&lt;span style="color: blue"&gt;string&lt;/span&gt; constructorString, &lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;[] baseAddresses)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: green"&gt;//Initialise ActiveRecord...&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: #2b91af"&gt;ActiveRecordStarter&lt;/span&gt;.IsInitialized)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;lock&lt;/span&gt; (m_InitActiveRecordLock)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (!&lt;span style="color: #2b91af"&gt;ActiveRecordStarter&lt;/span&gt;.IsInitialized)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;ActiveRecordStarter&lt;/span&gt;.Initialize(&lt;span style="color: #2b91af"&gt;Assembly&lt;/span&gt;.Load(&lt;span style="color: #a31515"&gt;"Darkside.Domain"&lt;/span&gt;), &lt;span style="color: #2b91af"&gt;ActiveRecordSectionHandler&lt;/span&gt;.Instance);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: green"&gt;//Hand off the real host creation to the base class..&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;return&lt;/span&gt; (&lt;span style="color: blue"&gt;base&lt;/span&gt;.CreateServiceHost(constructorString, baseAddresses));&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;You then need to add the Factory attribute into your .SVC file&lt;/p&gt;

&lt;div class="Code"&gt;
  &lt;pre style="margin: 0px"&gt;&lt;span style="background: yellow"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;@&lt;/span&gt; &lt;span style="color: maroon"&gt;ServiceHost&lt;/span&gt; &lt;span style="color: red"&gt;Language&lt;/span&gt;&lt;span style="color: blue"&gt;="C#"&lt;/span&gt; &lt;span style="color: red"&gt;Debug&lt;/span&gt;&lt;span style="color: blue"&gt;="false"&lt;/span&gt; &lt;span style="color: red"&gt;Service&lt;/span&gt;&lt;span style="color: blue"&gt;="Darkside.Services.CRUDService, Darkside.Services"&lt;/span&gt; &lt;span style="color: red"&gt;Factory&lt;/span&gt;&lt;span style="color: blue"&gt;="Darkside.WAS.CustomServiceHostFactory"&lt;/span&gt; &lt;span style="background: yellow"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Now, if a new service host is created in your app, AR will be initialised first, if needed.&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/115.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2010/07/16/initialise-castle-activerecord-was-wcf.aspx</guid>
            <pubDate>Fri, 16 Jul 2010 09:25:53 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2010/07/16/initialise-castle-activerecord-was-wcf.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/115.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Configuring and using the SQLite database in Castle ActiveRecord</title>
            <link>http://www.darkside.co.za/archive/2010/07/07/configuring-using-sqlite-castle-activerecord.aspx</link>
            <description>&lt;p&gt;There are a few solutions out on the web for this – here’s my implementation for you to use (and for me to safe-keep). I use this primarily for testing my ActiveRecord objects, as I haven’t really found any use for this mechanism in any production environment&lt;/p&gt;  &lt;p&gt;Firstly, the configuration. Notice that I specify my own connection provider (make sure you correctly swap out the relevant portions with your own namespaces). Also, there’s a slight twist in the connection string that you may want to take note of. The rest is straight forward.&lt;/p&gt;  &lt;div class="Code"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;activerecord&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;isDebug&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;true&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;isWeb&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;false&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;config&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;connection.provider&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;           &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Darkside.ARLibrary.SqLiteConnectionProvider, Darkside.ARLibrary&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;dialect&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;NHibernate.Dialect.SQLiteDialect&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;connection.driver_class&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;NHibernate.Driver.SQLite20Driver&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;connection.connection_string&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Data Source=:memory:;Version=3;New=True;&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;proxyfactory.factory_class&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;           &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle&lt;/span&gt;"&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;key&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;show_sql&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;true&lt;/span&gt;"&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;config&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;activerecord&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next, you’ll need to implement your own connection provider. The reason this needs to be done is because when you close a connection on a SQLite database which you’ve configured to be in-memory, the entire contents (tables and data) is lost.&lt;/p&gt;

&lt;p&gt;You simply inherit from NHibernate.Connection.DriverConnectionProvider and override the GetConnection() and CloseConnection() methods. In your implementation of GetConnection(), you cache an instance of the connection and always return the same one. In CloseConnection(), you do nothing – you don’t need or want to close the connection.&lt;/p&gt;

&lt;div class="Code"&gt;
  &lt;pre style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqLiteConnectionProvider&lt;/span&gt; : NHibernate.Connection.&lt;span style="color: #2b91af"&gt;DriverConnectionProvider&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; System.Data.&lt;span style="color: #2b91af"&gt;IDbConnection&lt;/span&gt; m_Connection;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; System.Data.&lt;span style="color: #2b91af"&gt;IDbConnection&lt;/span&gt; GetConnection()&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;if&lt;/span&gt; (m_Connection == &lt;span style="color: blue"&gt;null&lt;/span&gt;) &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                m_Connection = &lt;span style="color: blue"&gt;base&lt;/span&gt;.GetConnection();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; m_Connection;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;override&lt;/span&gt; &lt;span style="color: blue"&gt;void&lt;/span&gt; CloseConnection(System.Data.&lt;span style="color: #2b91af"&gt;IDbConnection&lt;/span&gt; conn)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: green"&gt;//Do nothing&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    }&lt;/pre&gt;
&lt;/div&gt;&lt;img src="http://www.darkside.co.za/aggbug/113.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2010/07/07/configuring-using-sqlite-castle-activerecord.aspx</guid>
            <pubDate>Wed, 07 Jul 2010 17:36:16 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2010/07/07/configuring-using-sqlite-castle-activerecord.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/113.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Compress and decompress a byte array</title>
            <link>http://www.darkside.co.za/archive/2010/05/11/compress-decompress-byte-array.aspx</link>
            <description>&lt;p&gt;A colleague asked me this morning if I already had a code snippet that compressed and decompressed byte arrays that he could make use of. He needed it to compress a variable before passing it as an argument to a WCF call, and decompress in the service itself. I’ve never made use of the System.IO.Compression namespace (I’d always used SharpZipLib), so I thought this would be a quick and useful experiment.&lt;/p&gt;  &lt;p&gt;After referencing the local MSDN and then the customary 30 second google, I decided I’d make my own, better, wheel :) I’m still convinced it’s less verbose than the first ten results I looked at, by the way. &lt;/p&gt;  &lt;p&gt;The compress part was easy enough (and follows the same logic as just about every example I found). What I couldn’t understand was why everyone implemented long-winded decompress routines. The answer to that question (found in MSDN) is that the Length property of the DeflateStream is not implemented and always throws an exception, meaning that you can’t determine the length of the byte array you’ll need.&lt;/p&gt;  &lt;p&gt;Here’s my quick-and-easy solution to the problem:  &lt;/p&gt;  &lt;div class="CodeCollapse"&gt;   &lt;pre style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CompressionUtils&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;const&lt;/span&gt; &lt;span style="color: blue"&gt;int&lt;/span&gt; BUFFERSIZE = 1024;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] Compress(&lt;span style="color: blue"&gt;byte&lt;/span&gt;[] data)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; memoryStream = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;MemoryStream&lt;/span&gt;();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; deflateStream = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DeflateStream&lt;/span&gt;(memoryStream, &lt;span style="color: #2b91af"&gt;CompressionMode&lt;/span&gt;.Compress);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            deflateStream.Write(data, 0, data.Length);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            deflateStream.Flush();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            deflateStream.Close();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; memoryStream.ToArray();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[] Decompress(&lt;span style="color: blue"&gt;byte&lt;/span&gt;[] data)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; buffer = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[BUFFERSIZE];&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; returnVal = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;byte&lt;/span&gt;&amp;gt;();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;var&lt;/span&gt; deflateStream = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DeflateStream&lt;/span&gt;(&lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;MemoryStream&lt;/span&gt;(data), &lt;span style="color: #2b91af"&gt;CompressionMode&lt;/span&gt;.Decompress);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;int&lt;/span&gt; count;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;while&lt;/span&gt; ((count = deflateStream.Read(buffer, 0, BUFFERSIZE)) &amp;gt; 0)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;if&lt;/span&gt; (count != BUFFERSIZE)&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                {&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    &lt;span style="color: blue"&gt;var&lt;/span&gt; tmpBuffer = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: blue"&gt;byte&lt;/span&gt;[count];&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    &lt;span style="color: #2b91af"&gt;Array&lt;/span&gt;.Copy(buffer, tmpBuffer, count);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    returnVal.AddRange(tmpBuffer);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                &lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;                    returnVal.AddRange(buffer);&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt; &lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; returnVal.ToArray();&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;        }&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;    }&lt;/pre&gt;
&lt;/div&gt;&lt;img src="http://www.darkside.co.za/aggbug/112.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2010/05/11/compress-decompress-byte-array.aspx</guid>
            <pubDate>Tue, 11 May 2010 18:23:43 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2010/05/11/compress-decompress-byte-array.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/112.aspx</wfw:commentRss>
        </item>
        <item>
            <title>An example of speculative execution</title>
            <link>http://www.darkside.co.za/archive/2009/11/19/example-speculative-execution.aspx</link>
            <description>&lt;p&gt;Speculative execution is a term applied to the execution of code that you may not need the results of. With the abundance of spare processing power on servers these days (and workstations for that matter), you can easily make an application be far more responsive to the user or make processing tasks on a server application quicker.&lt;/p&gt;
&lt;p&gt;A contrived example that I've come up: Consider a process that runs periodically on a server that:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Finds a list of all your customers from the SQL Server-based accounting system that have purchased an item from your online store in the past 24 hours (quick DB call) (1 sec in total) &lt;/li&gt;
    &lt;li&gt;For each customer, sum up the values of all their transactions for the past 6 months - it's a longer process because you have to fetch the data from data warehouse tables on a different SQL Server (2 sec per call) &lt;/li&gt;
    &lt;li&gt;For customers who have purchased more than ZAR100*, check if they have received a cheesy gift from the online loyalty app that you outsource to. (2 sec per call). &lt;/li&gt;
    &lt;li&gt;If they haven't received the gift yet, make another call to the online loyalty app to request that a gift be delivered (2 sec) &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Most likely you have these running sequentially; looking at the tasks that need to be performed, they all seem to be dependant on the previous step. A quick tally based on a made of set of results returned in each step:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;5 customers are returned. Total running time elapsed: &lt;em&gt;1 sec&lt;/em&gt; &lt;/li&gt;
    &lt;li&gt;Sum up the values of each customer @ 2 seconds/call. Total running time elapsed: &lt;em&gt;11 sec&lt;/em&gt; &lt;/li&gt;
    &lt;li&gt;Let's say only 2 make it to this step that need to be checked. Total running time elapsed: &lt;em&gt;15 sec&lt;/em&gt; &lt;/li&gt;
    &lt;li&gt;One has already received a gift, so it's only 1 call left. Total running time elapsed: &lt;em&gt;16 sec&lt;/em&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here's an example of what the code may look like: &lt;/p&gt;
&lt;div class="Code"&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Customer&lt;/span&gt;&amp;gt; customers = GetListOfCustomers();&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; customer &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; customers)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;{&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (GetPurchaseTotalForSixMonths(customer) &amp;gt; 100)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    {&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (!HasCustomerReceivedGift(customer))&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;            RequestGiftForCustomer(customer);&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;    }&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; Considering that in every step from the process your server application is waiting for a response from another server, it's most likely idling away. So let's run some of the tasks in parallel. We can run each call made in (2) at the same time as the call that may or may not have been made initially in (3). We can make the call to the online loyalty app, and if the result from the call in two requires the data from the call in (3), you use it. If not, too bad - you just discard the results. Your code may look something like this: &lt;/p&gt;
&lt;div class="Code"&gt;
&lt;pre style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Speculative()&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;        {&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Customer&lt;/span&gt;&amp;gt; customers = GetListOfCustomers();&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; customer &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; customers)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;            {&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; c = customer;   &lt;span style="COLOR: green"&gt;//**              &lt;/span&gt;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; meetsPurchaseLimit=&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; hasReceivedGift=&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="COLOR: #2b91af"&gt;Fork&lt;/span&gt;.Begin()&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                    .Call(() =&amp;gt; meetsPurchaseLimit = (GetPurchaseTotalForSixMonths(c) &amp;gt; 100))&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                    .Call(() =&amp;gt; hasReceivedGift = HasCustomerReceivedGift(c))&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                    .End();&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (meetsPurchaseLimit &amp;amp;&amp;amp; !hasReceivedGift)&lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;                    RequestGiftForCustomer(customer); &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;            } &lt;/pre&gt;
&lt;pre style="MARGIN: 0px"&gt;        }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; The Fork code that you see here is the same as what I've described in the article "&lt;a title="Asynchronous fork article" target="_blank" href="http://www.darkside.co.za/archive/2009/04/24/easy-to-use-asynchronous-fork.aspx"&gt;An easy to use asynchronous fork&lt;/a&gt;". &lt;/p&gt;
&lt;p&gt;Re-doing the calculation on the elapsed time, but now using speculative execution on the call made in (3), we get: &lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;5 customers are returned. Total running time elapsed: &lt;em&gt;1 sec&lt;/em&gt; &lt;/li&gt;
    &lt;li&gt;Sum up the values of each customer @ 2 seconds/call, but at the same time check if the customer received a gift. Total running time elapsed: &lt;em&gt;11 sec&lt;/em&gt; &lt;/li&gt;
    &lt;li&gt;Marrying up the results from the parallel calls, make the single call for the gift. Total running time elapsed: &lt;em&gt;12 sec&lt;/em&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Back to the example: As you can see, you have a 25% saving in time. Yes, this is a contrived example with naive timing, but the general idea is what matters most. Don't feel bad about using your CPU's idle time to get work done, even if you're going to throw it away later.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;*&lt;/strong&gt; ZAR100 is equivalent to about USD500 or GBP300. Ok, it isn't so. Check &lt;a title="South African Forex" target="_blank" href="http://www.southafrica.co.za/forex/"&gt;here&lt;/a&gt; if you really want to. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;**&lt;/strong&gt; You may or may not be wondering why I have the line:  &lt;/p&gt;
&lt;div class="Code"&gt;
&lt;pre style="MARGIN: 0px"&gt;                &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; c = customer;  &lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; It's to remove the warning I get from &lt;a title="Jetbrains ReSharper" target="_blank" href="http://www.jetbrains.com/resharper/index.html"&gt;ReSharper&lt;/a&gt; - it complains about a possible "access to a modified closure". Have a look at &lt;a title="Closing over the loop variable considered harmful" target="_blank" href="http://blogs.msdn.com/ericlippert/archive/2009/11/12/closing-over-the-loop-variable-considered-harmful.aspx"&gt;this article&lt;/a&gt; from &lt;a title="Eric Lippert's blog" target="_blank" href="http://blogs.msdn.com/ericlippert/about.aspx"&gt;Eric Lippert&lt;/a&gt; explaining it. &lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/110.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/11/19/example-speculative-execution.aspx</guid>
            <pubDate>Thu, 19 Nov 2009 17:53:39 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/11/19/example-speculative-execution.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/110.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C++ Compile Error - C2664</title>
            <link>http://www.darkside.co.za/archive/2009/11/16/compile-error-c2664.aspx</link>
            <description>&lt;p&gt;If you find you’re getting compile errors something along the lines of&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000" face="Courier New"&gt;error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char [261]' to 'LPCWSTR'&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;or&lt;/p&gt;  &lt;p&gt;&lt;font color="#ff0000" face="Courier New"&gt;error C2664: 'CreateProcessW' : cannot convert parameter 2 from 'char *' to 'LPWSTR'&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;I got plenty of these when compiling code which I C&amp;amp;P’d, which was working perfectly in one project, to a new project I had just created; All the errors were related to converting char/char arrays to LPWSTR. There are plenty of programmatic ways of converting this data, and keep in mind you may still want to check these out, rather than my “simple” fix, which is change the “Character Set” property in the project configuration settings to “Multi-Byte”&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="/files/images/CCompileErrorC2664.gif" width="587" height="395" /&gt;&lt;/p&gt;&lt;img src="http://www.darkside.co.za/aggbug/109.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ryan Schreiber</dc:creator>
            <guid>http://www.darkside.co.za/archive/2009/11/16/compile-error-c2664.aspx</guid>
            <pubDate>Mon, 16 Nov 2009 12:19:13 GMT</pubDate>
            <comments>http://www.darkside.co.za/archive/2009/11/16/compile-error-c2664.aspx#feedback</comments>
            <wfw:commentRss>http://www.darkside.co.za/comments/commentRss/109.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
