<?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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ivan Porto Carrero &#187; Base4</title>
	<atom:link href="http://flanders.co.nz/category/base4/feed/" rel="self" type="application/rss+xml" />
	<link>http://flanders.co.nz</link>
	<description>thoughts.each { &#38;:propagandise }</description>
	<lastBuildDate>Fri, 12 Mar 2010 12:24:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>NBlogr Presentation in Wellington</title>
		<link>http://flanders.co.nz/2007/05/01/nblogr-presentation-in-wellington/</link>
		<comments>http://flanders.co.nz/2007/05/01/nblogr-presentation-in-wellington/#comments</comments>
		<pubDate>Tue, 01 May 2007 23:17:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[Base4]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[NBlogr]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2007/05/01/nblogr-presentation-in-wellington/</guid>
		<description><![CDATA[

				Tonight I got the chance to present my nblogr application to a larger audience. Unfortunately I&#8217;m in the process of fixing bugs in NBlogr and one of those bugs required me to make a change to NBlogr.Web/views/default/shared/mainmenu.boo . I had made this change on sunday around midnight right before I went to bed. Of course [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>
				<br />Tonight I got the chance to present my nblogr application to a larger audience. Unfortunately I&#8217;m in the process of fixing bugs in NBlogr and one of those bugs required me to make a change to NBlogr.Web/views/default/shared/mainmenu.boo . I had made this change on sunday around midnight right before I went to bed. Of course I forgot to test the application because and it wouldn&#8217;t run on my presentation.  When I got home it took me about 3 minutes to fix. I had to import a reference to Base4.Storage in the mainmenu.boo file.</p>
<p>I&#8217;d like to thank everybody for coming, their patience and listening to my ramblings.</p>
<p>Anyway I&#8217;ve included my slide deck in this post and I think it might be a good idea to post a couple more links to some of the people I mentioned in my talk.<br /><a href="http://www.base4.net">http://www.base4.net</a>  &#8211; Alex James, Auckland<br /><a href="http://blog.bittercoder.com">http://blog.bittercoder.com</a> &#8211; Alex Henderson, Auckland<br /><a href="http://www.ayende.com/blog">http://www.ayende.com/blog</a><br /><a href="http://hammet.castleproject.org">http://hammet.castleproject.org</a></p>
<p><a href="http://www.castleproject.org">http://www.castleproject.org</a><br /><a href="http://www.nunit.org">http://www.nunit.org</a><br /><a href="http://www.nblogr.com">http://www.nblogr.com</a></p>
<p>svn repository:<br /><a href="https://svn.koolkraft.net/nblogr/trunk">https://svn.koolkraft.net/nblogr/trunk</a></p>
<p>
				<a href="http://www.flanders.co.nz/Blog/content/binary/NBlogr-Wellington%2002%20_05_2007.ppt">NBlogr-Wellington 02 _05_2007.ppt (440 KB)</a></p>
<p>To get nblogr running on your machine follow these steps :</p>
<p>Make sure you have a subversion client installed or subversion itself. </p>
<p>C:\Projects> svn co <a href="https://svn.koolkraft.net/nblogr/trunk">https://svn.koolkraft.net/nblogr/trunk</a><br />C:\Projects> osql -E<br />1> create database nblogr<br />2> go<br />1> quit</p>
<p>open the nblogr solution.</p>
<p>change the connection string in web.config</p>
<p>The different configuration options are explained in the web.config</p>
<p>If you want to use a different extension than aspx you have to change the httphandler configuration and set the extension in nblogr/routing</p>
<p>if you want urls to be rewritten without an extension you will have to enable wildcard handling.</p>
<p>hit ctrl-f5 and it should take you through the configuration. If ctrl-f5 doesn&#8217;t work try setting up the application in IIS.</p>
<p></p>
<p>
				<b>Update: <br /></b>James Hippolite from telecom was so kind to blog most of the bullet points of my slides. Which can be found here <a href="http://tvornz.spaces.live.com/blog/cns%21A93B6100E328706D%21388.entry?_c=BlogPart&#038;_c02_owner=1">http://tvornz.spaces.live.com/blog/cns!A93B6100E328706D!388.entry?_c=BlogPart&#038;_c02_owner=1</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2007/05/01/nblogr-presentation-in-wellington/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Base4 and Castle&#8230; the controller</title>
		<link>http://flanders.co.nz/2006/10/18/base4-and-castle-the-controller/</link>
		<comments>http://flanders.co.nz/2006/10/18/base4-and-castle-the-controller/#comments</comments>
		<pubDate>Wed, 18 Oct 2006 08:14:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Base4]]></category>
		<category><![CDATA[Castle]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/10/18/base4-and-castle-the-controller/</guid>
		<description><![CDATA[The next bit for pages in general is that often they represent a list. Often this list is a really long list that you&#8217;d like to page through.
I put this functionality into a generic base controller class. The whole idea of my set up is to provide a technique called progressive enhancement of forms.  In short [...]]]></description>
			<content:encoded><![CDATA[<p>The next bit for pages in general is that often they represent a list. Often this list is a really long list that you&#8217;d like to page through.</p>
<p>I put this functionality into a generic base controller class. The whole idea of my set up is to provide a technique called progressive enhancement of forms.  In short you create an application that works completely without javascript using hyperlinks for gets and submit buttons etc.  Then you attach some css selector classes to the different bits of functionality and you attach these behaviors to the html elements on your page. </p>
<p>I thought that that is a really nice way of enriching the experience of people that allow it to be enriched <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   And that is the explanation of the ajaxCall bool variable on some of the methods</p>
<p>The first thing is the interface for the class : </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Presenter</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: teal">INBlogrController</span><T></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: blue">bool</span> IsCompositeView{<span style="color: blue">get</span>;}</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Delete(T item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Delete(T item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Edit(<span style="color: teal">Guid</span> Id);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Edit(<span style="color: teal">Guid</span> Id, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> JumpToPage(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> JumpToPage(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> List();</p>
<p style="margin: 0px">        <span style="color: blue">void</span> List(<span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> NavigateBack(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> NavigateFirst(<span style="color: blue">int</span> pageSize);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> NavigateNext(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> NavigateBack(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> NavigateFirst(<span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> NavigateNext(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Show();</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Show(<span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Save(T item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Save(T item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> CreateNew();</p>
<p style="margin: 0px">        <span style="color: blue">void</span> CreateNew(<span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p>And the next thing is the base class again : </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Collections.Generic;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Text;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Base4.Storage;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Presenter.Abstract</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">abstract</span> <span style="color: blue">class</span> <span style="color: teal">AbstractAdminController</span><T> : <span style="color: teal">AbstractController</span>, <span style="color: teal">INBlogrController</span><T> <span style="color: blue">where</span> T: <span style="color: blue">class</span>, <span style="color: teal">IItem</span>, <span style="color: blue">new</span>()</p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: blue">bool</span> compositeView;</p>
<p style="margin: 0px">        <span style="color: blue">int</span> _pageSize;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> AbstractAdminController()</p>
<p style="margin: 0px">            : <span style="color: blue">base</span>()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">this</span>.compositeView = <span style="color: blue">false</span>;</p>
<p style="margin: 0px">            _pageSize = 10;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> AbstractAdminController(<span style="color: blue">bool</span> compositeView) : <span style="color: blue">base</span>()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">this</span>.compositeView = compositeView;</p>
<p style="margin: 0px">            _pageSize = 10;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">internal</span> <span style="color: blue">abstract</span> <span style="color: blue">void</span> getList(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> skipLayout);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">internal</span> <span style="color: blue">void</span> getList(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(pageNumber, pageSize, <span style="color: blue">false</span>);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"><span style="color: blue">        #region</span> INBlogrController<T> Members</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">bool</span> IsCompositeView</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">get</span></p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                <span style="color: blue">return</span> compositeView;</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">int</span> PageSize</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">get</span></p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                <span style="color: blue">return</span> _pageSize;</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px">            <span style="color: blue">set</span></p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                _pageSize = <span style="color: blue">value</span>;</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> Delete(T item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            Delete(item,pageNumber,pageSize,<span style="color: blue">false</span>);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">abstract</span> <span style="color: blue">void</span> Delete(T item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> CreateNew()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            CreateNew(<span style="color: blue">false</span>);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> CreateNew(<span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            Edit(<span style="color: teal">Guid</span>.NewGuid(), ajaxCall);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> Edit(<span style="color: teal">Guid</span> Id)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            Edit(Id, <span style="color: blue">false</span>);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">abstract</span> <span style="color: blue">void</span> Edit(<span style="color: teal">Guid</span> Id, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> JumpToPage(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(pageNumber, pageSize);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> JumpToPage(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(pageNumber, pageSize, ajaxCall);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> List()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(1, _pageSize);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> List(<span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(1, _pageSize, ajaxCall);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> NavigateBack(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(&#8211;pageNumber, pageSize);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> NavigateFirst(<span style="color: blue">int</span> pageSize)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(1, pageSize);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> NavigateNext(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(++pageNumber, pageSize);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> NavigateBack(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(&#8211;pageNumber, pageSize, ajaxCall);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> NavigateFirst(<span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(1, pageSize, ajaxCall);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> NavigateNext(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(++pageNumber, pageSize, ajaxCall);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> Show()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(1, _pageSize);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> Show(<span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            getList(1, _pageSize, ajaxCall);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">void</span> Save(T item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            Save(item, pageNumber, pageSize, <span style="color: blue">false</span>);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">abstract</span> <span style="color: blue">void</span> Save(T item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">        #endregion</span></p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p>Now onto the concrete implementation of my controller class</p>
<p> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Collections.Generic;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Text;</p>
<p style="margin: 0px"><span style="color: blue">using</span> NBlogr.Core;</p>
<p style="margin: 0px"><span style="color: blue">using</span> NBlogr.Service;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Base4.Storage;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Castle.MonoRail.Framework;</p>
<p style="margin: 0px"><span style="color: blue">using</span> NBlogr.Common.Base4Integration;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Castle.Services.Transaction;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Presenter</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">BlogController</span> : Abstract.<span style="color: teal">AbstractAdminController</span><<span style="color: teal">Blog</span>></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: teal">BlogService</span> blogService;</p>
<p style="margin: 0px">        </p>
<p style="margin: 0px">        <span style="color: blue">public</span> BlogController(<span style="color: teal">IService</span><<span style="color: teal">Blog</span>> blogService)</p>
<p style="margin: 0px">            : <span style="color: blue">base</span>(<span style="color: blue">true</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">this</span>.blogService = blogService <span style="color: blue">as</span> <span style="color: teal">BlogService</span>;</p>
<p style="margin: 0px">             </p>
<p style="margin: 0px">             </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">private</span> <span style="color: blue">void</span> internalGetList(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">int</span> pageCount;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: teal">IItemList</span><<span style="color: teal">Blog</span>> blog = blogService.GetAll(<span style="color: maroon">&#8220;Name&#8221;</span>, pageNumber, pageSize, <span style="color: blue">out</span> pageCount);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            internalMapProperties(blog , pageNumber,pageSize, pageCount);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">private</span> <span style="color: blue">void</span> internalMapProperties(<span style="color: teal">IItemList</span><<span style="color: teal">Blog</span>> blogs, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">int</span> pageCount)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">int</span> totalCount = blogs.Count;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span> (PropertyBag[<span style="color: maroon">"blog"</span>] == <span style="color: blue">null</span>)</p>
<p style="margin: 0px">                PropertyBag.Add(<span style="color: maroon">&#8220;blog&#8221;</span>, <span style="color: blue">new</span> <span style="color: teal">Blog</span>());</p>
<p style="margin: 0px">            </p>
<p style="margin: 0px">            PropertyBag.Add(<span style="color: maroon">&#8220;blogs&#8221;</span>, pageNumber);</p>
<p style="margin: 0px">            PropertyBag.Add(<span style="color: maroon">&#8220;index&#8221;</span>, pageNumber);</p>
<p style="margin: 0px">            PropertyBag.Add(<span style="color: maroon">&#8220;count&#8221;</span>, totalCount);</p>
<p style="margin: 0px">            PropertyBag.Add(<span style="color: maroon">&#8220;pageCount&#8221;</span>, pageCount);</p>
<p style="margin: 0px">            PropertyBag.Add(<span style="color: maroon">&#8220;pageSize&#8221;</span>, pageSize);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">internal</span> <span style="color: blue">override</span> <span style="color: blue">void</span> getList(<span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> skipLayout)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            internalGetList(pageNumber, pageSize);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span> (!skipLayout)</p>
<p style="margin: 0px">                RenderView(<span style="color: maroon">&#8220;Show&#8221;</span>, <span style="color: blue">false</span>);</p>
<p style="margin: 0px">            <span style="color: blue">else</span></p>
<p style="margin: 0px">                RenderView(<span style="color: maroon">&#8220;List&#8221;</span>, <span style="color: blue">true</span>);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Edit(<span style="color: teal">Guid</span> Id, <span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: teal">Blog </span>blog = blogService.GetById(Id);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            PropertyBag.Add(<span style="color: maroon">&#8220;blog&#8221;</span>, blog);</p>
<p style="margin: 0px">             </p>
<p style="margin: 0px">            <span style="color: blue">if</span> (!ajaxCall)</p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                getList(1, 0);</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px">            <span style="color: blue">else</span></p>
<p style="margin: 0px">                RenderView(<span style="color: maroon">&#8220;Save&#8221;</span>, ajaxCall);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Delete([<span style="color: teal">DataBind</span>(<span style="color: maroon">"blog"</span>)] <span style="color: teal">Blog </span>item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            blogService.Delete(item);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span> (!ajaxCall)</p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                getList(1, 0);</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px">            <span style="color: blue">else</span></p>
<p style="margin: 0px">                RenderText(getJsonResponse(<span style="color: maroon">&#8220;Contract deleted successfully&#8221;</span>));</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Save([<span style="color: teal">DataBind</span>(<span style="color: maroon">"blog"</span>)] <span style="color: teal">Blog </span>item, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">bool</span> ajaxCall)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            PropertyBag.Add(<span style="color: maroon">&#8220;blog&#8221;</span>, blogService.Save(item));</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span> (!ajaxCall)</p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                getList(1, 0);</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px">            <span style="color: blue">else</span></p>
<p style="margin: 0px">                RenderText(getJsonResponse(<span style="color: maroon">&#8220;Contract saved successfully&#8221;</span>));</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">private</span> <span style="color: blue">string</span> getJsonResponse(<span style="color: blue">string</span> message)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">return</span> <span style="color: maroon">&#8220;{result: true, content: &#8216;&#8221;</span> + message + <span style="color: maroon">&#8220;&#8216;}&#8221;</span>;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/10/18/base4-and-castle-the-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Base4 and Castle &#8230; The service</title>
		<link>http://flanders.co.nz/2006/10/17/base4-and-castle-the-service/</link>
		<comments>http://flanders.co.nz/2006/10/17/base4-and-castle-the-service/#comments</comments>
		<pubDate>Tue, 17 Oct 2006 06:38:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Base4]]></category>
		<category><![CDATA[Castle]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/10/17/base4-and-castle-the-service/</guid>
		<description><![CDATA[UPDATE: THE SERVICE CLASS HAS CHANGED AGAIN.Scratch the update.. it assumes that the object is already in the database which isn&#8217;t always the case. For this type of synchronisation to work I need some more time. So I reverted this back to the old version
This post continues my previous posts on using base4 and castle [...]]]></description>
			<content:encoded><![CDATA[<p><em>UPDATE: THE SERVICE CLASS HAS CHANGED AGAIN</em><strong>.<br /></strong><em>Scratch the update.. it assumes that the object is already in the database which isn&#8217;t always the case. For this type of synchronisation to work I need some more time. So I reverted this back to the old version</em></p>
<p>This post continues my previous posts on using base4 and castle together.</p>
<p>I&#8217;m sorry but there is no Active record in the base4 way of doing things.</p>
<p>The previous posts you would be intrested in can be found here : </p>
<p><a href="http://www.flanders.co.nz/Blog/2006/10/12/HostingBase4InsideYourWebApplication.aspx">Hosting base4 inside your web application<br /></a><a href="http://www.flanders.co.nz/Blog/2006/10/16/Base4OnCastleContinuedTheFacility.aspx">Base4 and Castle continued&#8230; The facility</a></p>
<p>Today I want to show you the abstract service class that I use so the controller only talks to the service and never to the dataobject directly.  </p>
<p>It is not a very big class but i found it pretty useful.  As it turns out almost all my service classes in a previous project started to look very much alike so I grouped that functionality in an abstract class. There is one thing you have to look out for and that is if you have something like audit fields (Created, LastModified,&#8230;..) you need to first get the object from the datastore and then set just the changed properties on the retrieved object.</p>
<p>The first thing you need is the contract/interface for the service. I expect this interface to grow over time so keep checking NBlogr for updates but this where I am at now <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Service</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: teal">IService</span><T></p>
<p style="margin: 0px">    <span style="color: blue">where</span> T : <span style="color: blue">class</span>, Base4.Storage.<span style="color: teal">IItem</span>, <span style="color: blue">new</span>()</p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Delete(T item);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> GetAll(<span style="color: blue">string</span> sortExpression, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">out</span> <span style="color: blue">int</span> pageCount);</p>
<p style="margin: 0px">        T GetById(<span style="color: teal">Guid</span> Id);</p>
<p style="margin: 0px">        T Save(T item);</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p>And here&#8217;s the abstract class :</p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> Base4.Storage;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Castle.Core.Logging;</p>
<p style="margin: 0px"><span style="color: blue">using</span> NBlogr.Common.Base4Integration;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">using</span> <span style="color: teal">User</span> = NBlogr.Core.<span style="color: teal">User</span>;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Castle.Services.Transaction;</p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> Base4.Storage.Utils;</p>
</div>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Service.Abstract</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"></p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px">    [<span style="color: teal">Transactional</span>]</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">abstract</span> <span style="color: blue">class</span> <span style="color: teal">AbstractService</span><T> : <span style="color: teal">IService</span><T> <span style="color: blue">where</span> T : <span style="color: blue">class</span>,<span style="color: teal">IItem</span>,<span style="color: blue">new</span>()</p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: blue">internal</span> <span style="color: blue">readonly</span> <span style="color: teal">ILogger</span> logger;</p>
<p style="margin: 0px">        <span style="color: blue">internal</span> <span style="color: teal">IDataObject</span><T> dao;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> AbstractService(<span style="color: teal">ILogger</span> logger, <span style="color: teal">IDataObject</span><T> dao)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">this</span>.logger = logger;</p>
<p style="margin: 0px">            <span style="color: blue">this</span>.dao = dao;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        [<span style="color: teal">Transaction</span>(<span style="color: teal">TransactionMode</span>.Requires)]</p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> T Save(T item)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">return</span> dao.Save(internalPrepareSave(item));</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">internal</span> <span style="color: blue">abstract</span> T internalPrepareSave(T item);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        [<span style="color: teal">Transaction</span>(<span style="color: teal">TransactionMode</span>.Requires)]</p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> Delete(T item)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            dao.Delete(item);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: teal">IItemList</span><T> GetAll(<span style="color: blue">string</span> sortExpression, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">out</span> <span style="color: blue">int</span> pageCount)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">return</span> dao.FindAll(sortExpression, pageNumber, pageSize, <span style="color: blue">out</span> pageCount);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> T GetById(<span style="color: teal">Guid</span> Id)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">return</span> dao.GetById(Id);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">    }</p>
</div>
</div>
<p style="margin: 0px">}</p>
</div>
<p>And the last bit could be an implementation of this service.  I don&#8217;t have companies in NBlogr. I took this class from another project : </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"></p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"></p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue"></span></p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue"></span></p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Castle.Services.Transaction;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Castle.Core.Logging;</p>
<p style="margin: 0px"><span style="color: blue">using</span> NBlogr.Common.Base4Integration;</p>
<p style="margin: 0px"><span style="color: blue">using</span> NBlogr.Core;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Service</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    [<span style="color: teal">Transactional</span>]</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">BlogService</span> : Abstract.<span style="color: teal">AbstractService</span><<span style="color: teal">Blog</span>></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> BlogService(<span style="color: teal">ILogger</span> logger, <span style="color: teal">IDataObject</span><<span style="color: teal">Blog</span>> dao)</p>
<p style="margin: 0px">            : <span style="color: blue">base</span>(logger, dao)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">internal</span> <span style="color: blue">override</span> <span style="color: teal">Blog</span> internalPrepareSave(<span style="color: teal">Blog</span> item)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: teal">Blog</span> itemToSave = GetById(item.Id);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span> (!itemToSave.Internals.InDatabase)</p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                itemToSave.Created = <span style="color: teal">DateTime</span>.Now;</p>
<p style="margin: 0px">                itemToSave.Creator = CurrentUser;</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            itemToSave.AkismetKey = item.AkismetKey;</p>
<p style="margin: 0px">            <span style="color: green">//TODO: finish mapping properties</span></p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">return</span> itemToSave;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
</div>
</div>
</div>
</div>
<p>This concludes the service for use with base4.  I hope you find it as useful as I do.<br />If somebody knows improvements etc. Please let me know I am always keen to learn.</p>
<p>I also realise that I can just call save on an IItem object but i like every tier to have it&#8217;s specific task so the dataobject doesn&#8217;t do much else than call IItem.Save() for now</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/10/17/base4-and-castle-the-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Base4 on Castle continued&#8230; The facility</title>
		<link>http://flanders.co.nz/2006/10/16/base4-on-castle-continued-the-facility/</link>
		<comments>http://flanders.co.nz/2006/10/16/base4-on-castle-continued-the-facility/#comments</comments>
		<pubDate>Mon, 16 Oct 2006 07:00:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Base4]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[NBlogr]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/10/16/base4-on-castle-continued-the-facility/</guid>
		<description><![CDATA[Much of what I&#8217;m going to show today has been borrowed from Alex Henderson on the storage facility.
This post continues the hosting base4 inside your web application post
To integrate base4 in castle you can register either components or create a facility which allows it to hook into some bits of the castle life-cycle.
It doesn&#8217;t make [...]]]></description>
			<content:encoded><![CDATA[<p>Much of what I&#8217;m going to show today has been borrowed from <a href="http://blog.bittercoder.com/PermaLink,guid,d996b96f-13f3-4d0f-9c5b-e770dabd77ce.aspx">Alex Henderson</a> on the storage facility.</p>
<p>This post continues the <a href="http://www.flanders.co.nz/Blog/2006/10/12/HostingBase4InsideYourWebApplication.aspx">hosting base4 inside your web application</a> post</p>
<p>To integrate <a href="http://www.base4.net">base4</a> in <a href="http://www.castleproject.org/">castle</a> you can register either components or create a facility which allows it to hook into some bits of the castle life-cycle.</p>
<p>It doesn&#8217;t make such a big difference when actually writing code except for the fact that you have transactions managed by castle, caching etc practically for free.</p>
<p>The ObjectTransaction that is available in base4 is built on the transaction scope and uses TransactionOptions.Required. Translated freely this means it will attach itself to an existing transaction if one exists if not it will create one.</p>
<p>So below I&#8217;ll first put the code for the storage facility and the base4TransactionManager and the configuration in the config files.  The full version of these files and the classes can be found in the source control repository of <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=Nblogr">NBlogr</a></p>
<p><strong>The storage facility</strong></p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Common.Base4Integration</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">Base4StorageFacility</span> : <span style="color: teal">AbstractFacility</span></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: blue">protected</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Init()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: green">// If no context has been set yet (but should be done in application_start) set the default context.</span></p>
<p style="margin: 0px">            <span style="color: blue">if</span> (<span style="color: teal">StorageContext</span>.Default == <span style="color: blue">null</span>)</p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                <span style="color: blue">string</span> base4Context = FacilityConfig.Attributes[<span style="color: maroon">"base4Context"</span>];</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">                <span style="color: blue">if</span> (<span style="color: blue">string</span>.IsNullOrEmpty(base4Context))</p>
<p style="margin: 0px">                {</p>
<p style="margin: 0px">                    <span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: teal">StorageException</span>(<span style="color: maroon">&#8220;The Base4StorageFacility requires a \&#8221;base4Context\&#8221; attribute to be set&#8221;</span>);</p>
<p style="margin: 0px">                }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">                <span style="color: teal">StorageContext</span>.SetDefault(base4Context);</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">// Add the transactionmanager to the registered components</span></p>
<p style="margin: 0px">            Kernel.AddComponent(<span style="color: maroon">&#8220;base4.transactionManager&#8221;</span>, <span style="color: blue">typeof</span>(<span style="color: teal">ITransactionManager</span>), <span style="color: blue">typeof</span>(<span style="color: teal">Base4TransactionManager</span>));</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">// Add the IItemcontext to the registered components</span></p>
<p style="margin: 0px">            Kernel.AddComponentInstance(<span style="color: maroon">&#8220;base4.defaultContext&#8221;</span>, <span style="color: blue">typeof</span>(<span style="color: teal">IItemContext</span>), <span style="color: teal">StorageContext</span>.Default);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">// Add the base4Dataobject</span></p>
<p style="margin: 0px">            Kernel.AddComponent(<span style="color: maroon">&#8220;base4.dataObject&#8221;</span>, <span style="color: blue">typeof</span>(<span style="color: teal">IDataObject</span><>), <span style="color: blue">typeof</span>(<span style="color: teal">BaseDataObject</span><>));</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><strong>The transaction manager</strong></p>
<p style="margin: 0px"><strong></strong> </p>
<p style="margin: 0px"><strong></strong> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Common.Base4Integration</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    [<span style="color: teal">PerThread</span>]</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">Base4TransactionManager</span> : <span style="color: teal">DefaultTransactionManager</span></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p style="margin: 0px"><strong></strong> </p>
<p style="margin: 0px"><strong>The IDataObject interface</strong></p>
<p style="margin: 0px"><strong></strong> </p>
<p style="margin: 0px"><strong></strong> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: teal">IDataObject</span><T> : <span style="color: teal">IBaseDataObject</span></p>
<p style="margin: 0px">    <span style="color: blue">where</span> T : <span style="color: blue">class</span>, <span style="color: teal">IItem</span>, <span style="color: blue">new</span>()</p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Delete(T item);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> Find(<span style="color: teal">ObjectPath</span> oPath, <span style="color: blue">string</span> sortExpression);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> Find(<span style="color: blue">string</span> oPath, <span style="color: blue">string</span> sortExpression, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">out</span> <span style="color: blue">int</span> pageCount);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> Find(<span style="color: teal">ObjectPath</span> oPath, <span style="color: blue">string</span> sortExpression, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">out</span> <span style="color: blue">int</span> pageCount);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> Find(<span style="color: blue">string</span> oPath);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> Find(<span style="color: teal">ObjectPath</span> oPath);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> Find(<span style="color: blue">string</span> oPath, <span style="color: blue">string</span> sortExpression);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> FindAll(<span style="color: blue">string</span> sortExpression, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">out</span> <span style="color: blue">int</span> pageCount);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> FindAll(<span style="color: blue">string</span> sortExpression);</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> FindAll();</p>
<p style="margin: 0px">        Base4.Storage.<span style="color: teal">IItemList</span><T> FindById(<span style="color: teal">Guid</span> Id);</p>
<p style="margin: 0px">        T GetById(<span style="color: teal">Guid</span> Id);</p>
<p style="margin: 0px">        T GetOne(<span style="color: blue">string</span> oPath, <span style="color: blue">params</span> <span style="color: blue">object</span>[] parameters);</p>
<p style="margin: 0px">        T GetOne(<span style="color: blue">string</span> oPath);</p>
<p style="margin: 0px">        T GetOne(<span style="color: teal">ObjectPath</span> oPath);</p>
<p style="margin: 0px">        T GetOneUsingSQL(<span style="color: blue">string</span> SQL);</p>
<p style="margin: 0px">        T GetOneUsingSQL(<span style="color: blue">string</span> SQL, <span style="color: teal">ObjectScope</span> scope);</p>
<p style="margin: 0px">        T GetOne(<span style="color: blue">string</span> opath, <span style="color: teal">ObjectScope</span> scope);</p>
<p style="margin: 0px">        T GetOne(<span style="color: teal">ObjectPath</span> path, <span style="color: teal">ObjectScope</span> scope);</p>
<p style="margin: 0px">        T Save(T item);</p>
<p style="margin: 0px">        <span style="color: blue">string</span> SortExpression { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</p>
<p style="margin: 0px">        <span style="color: blue">void</span> DeleteAll();</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Delete(<span style="color: teal">ObjectPath</span> path);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Delete(<span style="color: blue">string</span> path);</p>
<p style="margin: 0px">        <span style="color: blue">void</span> Delete(<span style="color: blue">string</span> path, <span style="color: blue">params</span> <span style="color: blue">string</span>[] replaces);</p>
<p style="margin: 0px">        <span style="color: teal">IItemList</span><T> Find(<span style="color: teal">ObjectPath</span> path, <span style="color: teal">ObjectScope</span> scope);</p>
<p style="margin: 0px">        <span style="color: teal">IItemList</span><T> FindUsingSQL(<span style="color: blue">string</span> SQL);</p>
<p style="margin: 0px">        <span style="color: teal">IItemList</span><T> FindUsingSQL(<span style="color: blue">string</span> SQL, <span style="color: teal">ObjectScope</span> scope);</p>
<p style="margin: 0px">        <span style="color: teal">IItemList</span><T> Find(<span style="color: teal">ObjectPath</span> path, <span style="color: teal">ObjectScope</span> scope, <span style="color: blue">string</span> sortExpression, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">out</span> <span style="color: blue">int</span> pageCount);</p>
<p style="margin: 0px">        <span style="color: teal">IItemList</span><T> FindAll(<span style="color: teal">ObjectScope</span> scope, <span style="color: blue">string</span> sortExpression, <span style="color: blue">int</span> pageNumber, <span style="color: blue">int</span> pageSize, <span style="color: blue">out</span> <span style="color: blue">int</span> pageCount);</p>
<p style="margin: 0px">    }</p>
</div>
<p style="margin: 0px"><strong></strong> </p>
<p style="margin: 0px"><strong>The facilities.config file</strong></p>
<p style="margin: 0px"><strong></strong> </p>
<p style="margin: 0px"> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue"><</span><span style="color: maroon">configuration</span><span style="color: blue">></span></p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">  <</span><span style="color: maroon">facilities</span><span style="color: blue">></span></p>
<p style="margin: 0px"><span style="color: blue">    <!--</span><span style="color: green"> This is required for windsor integration </span><span style="color: blue">&#8211;></span></p>
<p style="margin: 0px"><span style="color: blue">    <</span><span style="color: maroon">facility</span><span style="color: blue"> </span><span style="color: red">id</span><span style="color: blue">=</span>&#8220;<span style="color: blue">rails.facility</span>&#8220;</p>
<p style="margin: 0px"><span style="color: blue">      </span><span style="color: red">type</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Castle.MonoRail.WindsorExtension.RailsFacility, Castle.MonoRail.WindsorExtension</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">    <!--</span><span style="color: green"> Automatic transaction management for our services. Whooa! </span><span style="color: blue">&#8211;></span></p>
<p style="margin: 0px"><span style="color: blue">    <</span><span style="color: maroon">facility</span><span style="color: blue"> </span><span style="color: red">id</span><span style="color: blue">=</span>&#8220;<span style="color: blue">transaction</span>&#8220;</p>
<p style="margin: 0px"><span style="color: blue">      </span><span style="color: red">type</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Castle.Facilities.AutomaticTransactionManagement.TransactionFacility, Castle.Facilities.AutomaticTransactionManagement</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">    <!--</span><span style="color: green"> The facility that takes care of storing things with base4 </span><span style="color: blue">&#8211;></span></p>
<p style="margin: 0px"><span style="color: blue">    <</span><span style="color: maroon">facility</span><span style="color: blue"> </span></p>
<p style="margin: 0px"><span style="color: blue">      </span><span style="color: red">id</span><span style="color: blue">=</span>&#8220;<span style="color: blue">base4.storageFacility</span>&#8220;<span style="color: blue"> </span></p>
<p style="margin: 0px"><span style="color: blue">      </span><span style="color: red">type</span><span style="color: blue">=</span>&#8220;<span style="color: blue">NBlogr.Common.Base4Integration.Base4StorageFacility, NBlogr.Common</span>&#8220;<span style="color: blue"> </span></p>
<p style="margin: 0px"><span style="color: blue">      </span><span style="color: red">base4Context</span><span style="color: blue">=</span>&#8220;<span style="color: blue">tcp://Server:@localhost:8819/NBlogr</span>&#8220;<span style="color: blue">/></span></p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">    <!--</span><span style="color: green"> Enable logging for our application </span><span style="color: blue">&#8211;></span></p>
<p style="margin: 0px"><span style="color: blue">    <</span><span style="color: maroon">facility</span><span style="color: blue"> </span><span style="color: red">id</span><span style="color: blue">=</span>&#8220;<span style="color: blue">logging</span>&#8220;<span style="color: blue">  </span></p>
<p style="margin: 0px"><span style="color: blue">              </span><span style="color: red">type</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging</span>&#8220;<span style="color: blue"> </span></p>
<p style="margin: 0px"><span style="color: blue">              </span><span style="color: red">loggingApi</span><span style="color: blue">=</span>&#8220;<span style="color: blue">nlog</span>&#8220;<span style="color: blue">  /></span></p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">    <!--</span><span style="color: green"> enable caching for our application </span><span style="color: blue">&#8211;></span></p>
<p style="margin: 0px"><span style="color: blue">    <</span><span style="color: maroon">facility</span><span style="color: blue"> </span><span style="color: red">id</span><span style="color: blue">=</span>&#8220;<span style="color: blue">CacheFacility</span>&#8220;<span style="color: blue"> </span><span style="color: red">type</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Castle.Facilities.Cache.CacheFacility, Castle.Facilities.Cache</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">  </</span><span style="color: maroon">facilities</span><span style="color: blue">></span></p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue"></</span><span style="color: maroon">configuration</span><span style="color: blue">></span></p>
</div>
<p style="margin: 0px"><strong></strong> </p>
<p style="margin: 0px"><strong></strong> </p>
<p style="margin: 0px">That is it for today. Tomorrow I&#8217;ll show you the service class I use to manage my base4 and UI interaction</p>
<p style="margin: 0px">The day after is for the controller. And friday will be for the javascript object used in nblogr to manage interaction.</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/10/16/base4-on-castle-continued-the-facility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some news on nblogr</title>
		<link>http://flanders.co.nz/2006/10/14/some-news-on-nblogr/</link>
		<comments>http://flanders.co.nz/2006/10/14/some-news-on-nblogr/#comments</comments>
		<pubDate>Sat, 14 Oct 2006 08:12:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Base4]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[NBlogr]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/10/14/some-news-on-nblogr/</guid>
		<description><![CDATA[NBlogr isn&#8217;t dead.. It just underwent a transformation for the better.
I also changed the title of the application from NBlogr &#8211; An atlas blogging engine to NBlogr &#8211; a blogging engine built on simplicityThe reason for this change is the fact that it is currently built using jquery as javascript library.  I will look at [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=Nblogr">NBlogr</a> isn&#8217;t dead.. It just underwent a transformation for the better.</p>
<p>I also changed the title of the application from <strong>NBlogr &#8211; An atlas blogging engine</strong> to <strong>NBlogr &#8211; a blogging engine built on simplicity<br /></strong>The reason for this change is the fact that it is currently built using jquery as javascript library.  I will look at atlas again when it releases. </p>
<p>I moved <a href="http://www.nblogr.com">NBlogr</a> to run on <a href="http://www.castleproject.org/">castle</a>.  During the course of the next week I&#8217;ll complete my posts on how to do Castle development with <a href="http://www.base4.net/">base4</a></p>
<p>If you&#8217;re interested in how it looks or you want a preview the <a href="http://www.codeplex.com/SourceControl/ListDownloadableCommits.aspx?ProjectName=Nblogr">last source in the repository builds</a> and you should be able to run it in the development server of visual studio</p>
<p>I had a chat with <a href="http://blog.bluecog.co.nz/">JD</a> a while ago and he asked me about plugins. At that time I knew already I wanted to provide something for users to be able to add plugin&#8217;s to the database.  But I hadn&#8217;t really given it much thought on how I would do that.</p>
<p>My reasoning on this subject is : <br />I want users to be able to add a plug in at runtime. Plugin&#8217;s for a blog are lately both server related client side. So I will create a plugin factory with a couple of providers like a google video provider, grouper video, flickr, bookmark services.  And you can write a plugin using javascript and ironpython code. The engine will evaluate that code at runtime and there has been no application restarting etc. If somebody has a better plan for doing a plugin infrastructure please let me know I haven&#8217;t done any of the ground work for this yet but create a schema in base4 so now would be the best time to stop me from making big mistakes.</p>
<p>Another improvement is the fact that when nblogr reaches release it will come with a couple of templates for you to chose from. I&#8217;ll try to include one that is built on the css scheme of csszengarden that way you&#8217;ll have an infinite repository of css to make your blog look differently instantaneously.</p>
<p>The next improvement is that a user is now able to mimic wildcard requests and nblogr will handle those. So there is no need for appending aspx to pages for rewriting (routing it is called in monorail)  You get the choice in the config file to have your webserver handle the wild card mapping or nblogr. When you choose for nblogr nblogr will need write access to 2 folders in your website and create a shadow folder structure to represent the rewrite tree structure. There is weaker point here and that is that the <strong>first</strong> default document in IIS must be set to Default.aspx If you can map an extension to aspnet_isapi.dll at your webserver then you can also have the urls rewritten using a branded extension.</p>
<p>I think that this are the 3 major changes for the moment to the engine.  This did set me back for the next release with a couple of weeks but in the end the final release can be done much more quickly than it would have been possible using the code I had before.</p>
<p>I also promise that this time things mostly stay as they are. There will be no more experimenting but just getting Nblogr to a proper release state and shipped.</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/10/14/some-news-on-nblogr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hosting Base4 inside your web application</title>
		<link>http://flanders.co.nz/2006/10/12/hosting-base4-inside-your-web-application/</link>
		<comments>http://flanders.co.nz/2006/10/12/hosting-base4-inside-your-web-application/#comments</comments>
		<pubDate>Thu, 12 Oct 2006 05:42:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Base4]]></category>
		<category><![CDATA[Castle]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/10/12/hosting-base4-inside-your-web-application/</guid>
		<description><![CDATA[
Following up on the post of yesterday.  To use base4 with asp.net often you do not have the possibility to host base4 as a windows service. But to host base4 in the same appdomain as you website isn&#8217;t all that hard.
I&#8217;ll just share my code and how to use it. The way to go is [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css"><!--
	.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }
--></style>
<p>Following up on the post of yesterday.  To use base4 with asp.net often you do not have the possibility to host <a href="http://wwww.base4.net">base4</a> as a windows service. But to host base4 in the same appdomain as you website isn&#8217;t all that hard.</p>
<p>I&#8217;ll just share my code and how to use it. The way to go is to create a class that extends the HttpApplicatin and handle the application start and end events.</p>
<p>I&#8217;ll also post the code i have to integrate this with castle.</p>
<p>This is my base HttpApplication, every web app inherits of this one.</p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> System;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Collections.Generic;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Text;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Web;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Base4.Storage.Server;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Text.RegularExpressions;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Reflection;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Data.SqlClient;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Configuration;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Base4.Storage;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Xml;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.IO;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">namespace</span> Flanders.Library.Base4Integration</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">Base4HttpApplication</span> : <span style="color: teal">HttpApplication</span></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: teal">ServerConfiguration</span> config;</p>
<p style="margin: 0px">        <span style="color: teal">IServerProxy</span> proxy;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> Base4HttpApplication()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> Application_Start(<span style="color: blue">object</span> sender, <span style="color: teal">EventArgs</span> e)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: green">//Build the base4 server configuration from the connection strings settings in the web.config</span></p>
<p style="margin: 0px">            config = <span style="color: blue">new</span> <span style="color: teal">ServerConfiguration</span>();</p>
<p style="margin: 0px">            config.Store.Root = Server.MapPath(<span style="color: maroon">&#8220;~/&#8221;</span>);</p>
<p style="margin: 0px">            config.Store.Root = config.Store.Root.EndsWith(<span style="color: maroon">&#8220;\\&#8221;</span>) ? config.Store.Root </p>
<p style="margin: 0px">                + <span style="color: maroon">&#8220;App_Data\\Base4&#8243;</span> : config.Store.Root + <span style="color: maroon">&#8220;\\App_Data\\Base4&#8243;</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Set the application name of the store. In my case I define a title for my application in a </span></p>
<p style="margin: 0px">            <span style="color: green">//solution info file and use that as my app name</span></p>
<p style="margin: 0px">            <span style="color: green">//For this to work you will need to name your database the same as your applicationname</span></p>
<p style="margin: 0px">            <span style="color: blue">if</span> (Application[<span style="color: maroon">"AppName"</span>] == <span style="color: blue">null</span>)</p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                <span style="color: teal">Assembly</span> assembly = <span style="color: teal">Assembly</span>.GetCallingAssembly();</p>
<p style="margin: 0px">                Application[<span style="color: maroon">"AppName"</span>] = </p>
<p style="margin: 0px">                    (<span style="color: teal">AssemblyTitleAttribute</span>.GetCustomAttribute(assembly, <span style="color: blue">typeof</span>(<span style="color: teal">AssemblyTitleAttribute</span>)) <span style="color: blue">as</span> <span style="color: teal">AssemblyTitleAttribute</span>).Title;</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            config.Store.Name = Application[<span style="color: maroon">"AppName"</span>].ToString();</p>
<p style="margin: 0px">            config.Store.Provider = <span style="color: maroon">&#8220;SQL2005&#8243;</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Set the port for base4 to listen on.  This is defined in the web.config app settings</span></p>
<p style="margin: 0px">            <span style="color: blue">if</span> (Application[<span style="color: maroon">"AppPort"</span>] == <span style="color: blue">null</span>)</p>
<p style="margin: 0px">                Application[<span style="color: maroon">"AppPort"</span>] = <span style="color: blue">string</span>.IsNullOrEmpty(<span style="color: teal">ConfigurationManager</span>.AppSettings[<span style="color: maroon">"Base4.Port"</span>]) ? 8809 : </p>
<p style="margin: 0px">                    <span style="color: blue">int</span>.Parse(<span style="color: teal">ConfigurationManager</span>.AppSettings[<span style="color: maroon">"Base4.Port"</span>]);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            config.Store.Port = (<span style="color: blue">int</span>)Application[<span style="color: maroon">"AppPort"</span>];</p>
<p style="margin: 0px">            <span style="color: green">//We are hosting base4 in the same process as the website. so localhost will do <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></p>
<p style="margin: 0px">            config.Store.MachineName = <span style="color: maroon">&#8220;localhost&#8221;</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Set the connection string for the base4 store</span></p>
<p style="margin: 0px">            <span style="color: blue">string</span> connectionStringName = <span style="color: teal">ConfigurationManager</span>.AppSettings[<span style="color: maroon">"DefaultConnection"</span>];</p>
<p style="margin: 0px">            <span style="color: blue">if</span> (<span style="color: blue">string</span>.IsNullOrEmpty(connectionStringName) &#038;&#038; <span style="color: teal">ConfigurationManager</span>.ConnectionStrings != <span style="color: blue">null</span> </p>
<p style="margin: 0px">                &#038;&#038; <span style="color: teal">ConfigurationManager</span>.ConnectionStrings.Count > 0)</p>
<p style="margin: 0px">                connectionStringName = <span style="color: teal">ConfigurationManager</span>.ConnectionStrings[0].Name;            </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            config.Store.ConnectionString = <span style="color: blue">string</span>.IsNullOrEmpty(connectionStringName) ?</p>
<p style="margin: 0px">                <span style="color: teal">ConfigurationManager</span>.AppSettings[<span style="color: maroon">"Store.ConnectionString"</span>] :</p>
<p style="margin: 0px">                <span style="color: teal">ConfigurationManager</span>.ConnectionStrings[connectionStringName].ConnectionString;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Set the master connection string</span></p>
<p style="margin: 0px">            <span style="color: teal">SqlConnectionStringBuilder</span> connStrBuilder = <span style="color: blue">new</span> <span style="color: teal">SqlConnectionStringBuilder</span>(config.Store.ConnectionString);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            connStrBuilder.InitialCatalog = <span style="color: maroon">&#8220;master&#8221;</span>;</p>
<p style="margin: 0px">            config.MasterConnectionString = connStrBuilder.ToString();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Check if we have a directory to store the files generated by base4</span></p>
<p style="margin: 0px">            <span style="color: blue">if</span>(!<span style="color: teal">Directory</span>.Exists(config.Store.Root))</p>
<p style="margin: 0px">                <span style="color: teal">Directory</span>.CreateDirectory(config.Store.Root);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Actually start the server</span></p>
<p style="margin: 0px">            proxy = <span style="color: teal">ServerFactory</span>.StartServer(config, <span style="color: blue">false</span>);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Set the context for base4</span></p>
<p style="margin: 0px">            <span style="color: blue">string</span> base4Context = <span style="color: blue">string</span>.Format(<span style="color: maroon">&#8220;tcp://Server:@localhost:{0}/{1}&#8221;</span>, Application[<span style="color: maroon">"AppPort"</span>], Application[<span style="color: maroon">"AppName"</span>]);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            Application[<span style="color: maroon">"Base4Context"</span>] = base4Context;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Set the default storage context for base4</span></p>
<p style="margin: 0px">            <span style="color: teal">StorageContext</span>.SetDefault(base4Context);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">virtual</span> <span style="color: blue">void</span> Application_End(<span style="color: blue">object</span> sender, <span style="color: teal">EventArgs</span> e)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            proxy.Stop();</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p>Now to integrate this with monorail then this is you application class in your website :</p>
<p> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">using</span> System.Web;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Castle.Windsor;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Base4.Storage;</p>
<p style="margin: 0px"><span style="color: blue">using</span> System.Configuration;</p>
<p style="margin: 0px"><span style="color: blue">using</span> Flanders.Library.Base4Integration;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Presentation</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">ASPGlobal</span> : <span style="color: teal">Base4HttpApplication</span>, <span style="color: teal">IContainerAccessor</span></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: teal">MonoRailContainer</span> container;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Application_Start(<span style="color: blue">object</span> sender, System.<span style="color: teal">EventArgs</span> e)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">base</span>.Application_Start(sender, e);</p>
<p style="margin: 0px">            container = <span style="color: blue">new</span> <span style="color: teal">MonoRailContainer</span>();</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Application_End(<span style="color: blue">object</span> sender, System.<span style="color: teal">EventArgs</span> e)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            container.Dispose();</p>
<p style="margin: 0px">            <span style="color: blue">base</span>.Application_End(sender, e);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">        #region</span> IContainerAccessor Members</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: teal">IWindsorContainer</span> Container</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">get</span> { <span style="color: blue">return</span> container; }</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: blue">        #endregion</span></p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p>The global.asax should only contain one line :</p>
<pre class="csharpcode"><span class="asp"><%@ Application Inherits="NBlogr.Presentation.ASPGlobal" Language="C#" %></span></pre>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/10/12/hosting-base4-inside-your-web-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Base4 and NLog</title>
		<link>http://flanders.co.nz/2006/10/11/base4-and-nlog/</link>
		<comments>http://flanders.co.nz/2006/10/11/base4-and-nlog/#comments</comments>
		<pubDate>Wed, 11 Oct 2006 06:07:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Base4]]></category>
		<category><![CDATA[Nlog]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/10/11/base4-and-nlog/</guid>
		<description><![CDATA[As you know already I like base4 a lot
Alex Henderson has got a nice post on integrating base4 much prettier than I did in castle.  Later on today I&#8217;ll post what I made of it
I tried to use log4net but didn&#8217;t succeed.  So I switched to nlog which I like a lot.
Now to integrate nlog [...]]]></description>
			<content:encoded><![CDATA[<p>As you know already I like <a href="http://www.base4.net/">base4</a> a lot</p>
<p><a href="http://blog.bittercoder.com/PermaLink,guid,d996b96f-13f3-4d0f-9c5b-e770dabd77ce.aspx">Alex Henderson</a> has got a nice post on integrating base4 much prettier than I did in castle.  Later on today I&#8217;ll post what I made of it</p>
<p>I tried to use log4net but didn&#8217;t succeed.  So I switched to <a href="http://www.nlog-project.org/">nlog</a> which I like a lot.</p>
<p>Now to integrate nlog with base4 wasn&#8217;t all that hard.</p>
<p>
<property typename="System.String" name="StackTrace" nullable="True" length="1025"></property>
<property typename="System.DateTime" name="EventTime"></property>
<property typename="Base4.Storage.ContentStream" name="ApplicationContext" nullable="True"></property>
<property typename="System.String" name="LoggerName" length="256"></property>
<property typename="System.String" name="Level" length="256"></property>
<property typename="System.String" name="Exception" nullable="True" length="1025"></property>
<property typename="System.String" name="UserStackFrame" nullable="True" length="1025"></property>
<property typename="System.Guid" name="Id" unique="True"></property>
<property typename="System.Int32" name="Sequence" nullable="true"></property>
<property typename="System.String" name="Message" length="1025">This is the type from my schema which just stores about anything i would want to know about a particular event. and probably more in my case <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </property></p>
<p> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">    <</span><span style="color: maroon">Type</span><span style="color: blue"> </span><span style="color: red">FullName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">NBlogr.Core.AppEvent</span>&#8220;<span style="color: blue"> </span><span style="color: red">baseName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Base4.Storage.ItemImpl</span>&#8220;<span style="color: blue"> </span><span style="color: red">keyProperty</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Id</span>&#8220;<span style="color: blue"> </span><span style="color: red">version</span><span style="color: blue">=</span>&#8220;<span style="color: blue">1</span>&#8220;<span style="color: blue"> </span><span style="color: red">mode</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Rich</span>&#8220;<span style="color: blue">></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">ApplicationContext</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Base4.Storage.ContentStream</span>&#8220;<span style="color: blue"> </span><span style="color: red">nullable</span><span style="color: blue">=</span>&#8220;<span style="color: blue">True</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">EventTime</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.DateTime</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Exception</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.String</span>&#8220;<span style="color: blue"> </span><span style="color: red">nullable</span><span style="color: blue">=</span>&#8220;<span style="color: blue">True</span>&#8220;<span style="color: blue"> </span><span style="color: red">length</span><span style="color: blue">=</span>&#8220;<span style="color: blue">1025</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Id</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.Guid</span>&#8220;<span style="color: blue"> </span><span style="color: red">unique</span><span style="color: blue">=</span>&#8220;<span style="color: blue">True</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Level</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.String</span>&#8220;<span style="color: blue"> </span><span style="color: red">length</span><span style="color: blue">=</span>&#8220;<span style="color: blue">256</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">LoggerName</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.String</span>&#8220;<span style="color: blue"> </span><span style="color: red">length</span><span style="color: blue">=</span>&#8220;<span style="color: blue">256</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Message</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.String</span>&#8220;<span style="color: blue"> </span><span style="color: red">length</span><span style="color: blue">=</span>&#8220;<span style="color: blue">1025</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">Sequence</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.Int32</span>&#8220;<span style="color: blue"> </span><span style="color: red">nullable</span><span style="color: blue">=</span>&#8220;<span style="color: blue">True</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">StackTrace</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.String</span>&#8220;<span style="color: blue"> </span><span style="color: red">nullable</span><span style="color: blue">=</span>&#8220;<span style="color: blue">True</span>&#8220;<span style="color: blue"> </span><span style="color: red">length</span><span style="color: blue">=</span>&#8220;<span style="color: blue">1025</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">      <</span><span style="color: maroon">Property</span><span style="color: blue"> </span><span style="color: red">name</span><span style="color: blue">=</span>&#8220;<span style="color: blue">UserStackFrame</span>&#8220;<span style="color: blue"> </span><span style="color: red">typeName</span><span style="color: blue">=</span>&#8220;<span style="color: blue">System.String</span>&#8220;<span style="color: blue"> </span><span style="color: red">nullable</span><span style="color: blue">=</span>&#8220;<span style="color: blue">True</span>&#8220;<span style="color: blue"> </span><span style="color: red">length</span><span style="color: blue">=</span>&#8220;<span style="color: blue">1025</span>&#8220;<span style="color: blue"> /></span></p>
<p style="margin: 0px"><span style="color: blue">    </</span><span style="color: maroon">Type</span><span style="color: blue">></span></p>
<p style="margin: 0px"><span style="color: blue"></span> </p>
<p style="margin: 0px"><span style="color: blue">The actual target :</span></p>
<p style="margin: 0px"><span style="color: blue"></span> </p>
<div style="font-size: 10pt; background: white; color: black; font-family: consolas">
<p style="margin: 0px"><span style="color: blue">namespace</span> NBlogr.Common.Base4Integration</p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">    <span style="color: gray">///</span><span style="color: green"> This is a target for the nlog logging library. </span></p>
<p style="margin: 0px">    <span style="color: gray">///</span><span style="color: green"> This is dependent on the NBlogr.Core.xml file and Base4.</span></p>
<p style="margin: 0px">    <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">    [<span style="color: teal">Target</span>(<span style="color: maroon">"Base4Target"</span>)]</p>
<p style="margin: 0px">    <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: teal">Base4Target</span> : <span style="color: teal">TargetWithLayout</span></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: blue">private</span> <span style="color: blue">string</span> _host = <span style="color: maroon">&#8220;tcp://server:@localhost:999/Base4_Default&#8221;</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">public</span> <span style="color: blue">string</span> Base4Context</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">get</span> { <span style="color: blue">return</span> _host; }</p>
<p style="margin: 0px">            <span style="color: blue">set</span> { _host = <span style="color: blue">value</span>; }</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">protected</span> <span style="color: blue">override</span> <span style="color: blue">void</span> Write(<span style="color: teal">LogEventInfo</span> logEvent)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: blue">string</span> logMessage = CompiledLayout.GetFormattedMessage(logEvent);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span>(<span style="color: teal">StorageContext</span>.Default == <span style="color: blue">null</span>)</p>
<p style="margin: 0px">                <span style="color: teal">StorageContext</span>.SetDefault(Base4Context);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: teal">AppEvent</span> appEvent = <span style="color: blue">new</span> <span style="color: teal">AppEvent</span>();</p>
<p style="margin: 0px">            appEvent.Sequence = logEvent.SequenceID;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span>(logEvent.Context != <span style="color: blue">null</span> &#038;&#038; logEvent.Context.Count > 0)</p>
<p style="margin: 0px">                appEvent.ApplicationContext.Content = GetZippedBytes(logEvent.Context);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            appEvent.EventTime = logEvent.TimeStamp;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span>(logEvent.Exception != <span style="color: blue">null</span>) appEvent.Exception = logEvent.Exception.ToString();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">if</span>(logEvent.StackTrace != <span style="color: blue">null</span>) appEvent.StackTrace = logEvent.StackTrace.ToString();</p>
<p style="margin: 0px">            <span style="color: blue">if</span> (logEvent.UserStackFrame != <span style="color: blue">null</span>) appEvent.UserStackFrame = logEvent.UserStackFrame.ToString();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            appEvent.Level = logEvent.Level.Name;</p>
<p style="margin: 0px">            appEvent.LoggerName = logEvent.LoggerName;</p>
<p style="margin: 0px">            appEvent.Message = logMessage;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            appEvent.Save();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: blue">private</span> <span style="color: blue">byte</span>[] GetZippedBytes(<span style="color: teal">IDictionary</span> evt)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: teal">MemoryStream</span> ms = <span style="color: blue">new</span> <span style="color: teal">MemoryStream</span>();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: teal">BinaryFormatter</span> formatter = <span style="color: blue">new</span> <span style="color: teal">BinaryFormatter</span>();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            formatter.Serialize(ms, evt);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: teal">GZipStream</span> zipStream = <span style="color: blue">new</span> <span style="color: teal">GZipStream</span>(ms, <span style="color: teal">CompressionMode</span>.Compress);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: teal">BinaryReader</span> bRdr = <span style="color: blue">new</span> <span style="color: teal">BinaryReader</span>(zipStream);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: blue">return</span> bRdr.ReadBytes((<span style="color: blue">int</span>)zipStream.Length);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/10/11/base4-and-nlog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Base4 and Castle</title>
		<link>http://flanders.co.nz/2006/09/23/base4-and-castle/</link>
		<comments>http://flanders.co.nz/2006/09/23/base4-and-castle/#comments</comments>
		<pubDate>Sat, 23 Sep 2006 10:08:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Base4]]></category>
		<category><![CDATA[Castle]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/09/23/base4-and-castle/</guid>
		<description><![CDATA[Something I found very useful to use in castle is Base4 
And as it so happens Nic Wise just asked me if you could use the 2 together. The answer is yes you can.
I know they support nhibernate but that is not really the same    Base4 just goes that extra mile.
Since data access is always [...]]]></description>
			<content:encoded><![CDATA[<p>Something I found very useful to use in <a href="http://www.castleproject.org/">castle</a> is <a href="http://www.base4.net/">Base4</a> </p>
<p>And as it so happens <a href="http://www.fastchicken.co.nz/blog/">Nic Wise</a> just asked me if you could use the 2 together. The answer is yes you can.</p>
<p>I know they support <a href="http://www.nhibernate.org/">nhibernate</a> but that is not really the same <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   <a href="http://www.base4.net/">Base4</a> just goes that extra mile.</p>
<p>Since data access is always the same. And the examples on the castle site use concrete implementations of data access objects. I thought I really don&#8217;t need a facility for the moment and can just use base4.</p>
<p>Anyway here is the class I use to do all my data access. it&#8217;s an abstract class that has concrete implementations so that I can extend the functionality if I need to.</p>
<p>The interface for the class (the colors look different on my screen I swear  the gray bits should be some type of blue and the yellow also isn&#8217;t quite right): </p>
<p> </p>
<div style="font-size: 9pt; background: black; color: white; font-family: consolas">
<p style="margin: 0px"><span style="color: gray">using</span> <span style="color: yellow">System</span>;</p>
<p style="margin: 0px"><span style="color: gray">namespace</span> <span style="color: yellow">TimeSheets</span>.<span style="color: yellow">Application</span>.<span style="color: yellow">Contract</span>.<span style="color: yellow">Data</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: gray">public</span> <span style="color: gray">interface</span> <span style="color: silver">IDataObject</span><<span style="color: yellow">T</span>></p>
<p style="margin: 0px">    <span style="color: gray">where</span> <span style="color: yellow">T</span> : <span style="color: gray">class</span>, <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>.<span style="color: silver">IItem</span>, <span style="color: gray">new</span>()</p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: gray">void</span> <span style="color: yellow">Delete</span>(<span style="color: yellow">T</span> <span style="color: yellow">item</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>.<span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">Find</span>(<span style="color: gray">string</span> <span style="color: yellow">oPath</span>, <span style="color: gray">string</span> <span style="color: yellow">sortExpression</span>, <span style="color: gray">int</span> <span style="color: yellow">pageNumber</span>, <span style="color: gray">int</span> <span style="color: yellow">pageSize</span>, <span style="color: gray">out</span> <span style="color: gray">int</span> <span style="color: yellow">pageCount</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>.<span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">Find</span>(<span style="color: gray">string</span> <span style="color: yellow">oPath</span>, <span style="color: gray">string</span> <span style="color: yellow">sortExpression</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>.<span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">Find</span>(<span style="color: gray">string</span> <span style="color: yellow">oPath</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>.<span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">FindAll</span>(<span style="color: gray">string</span> <span style="color: yellow">sortExpression</span>, <span style="color: gray">int</span> <span style="color: yellow">pageNumber</span>, <span style="color: gray">int</span> <span style="color: yellow">pageSize</span>, <span style="color: gray">out</span> <span style="color: gray">int</span> <span style="color: yellow">pageCount</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>.<span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">FindAll</span>(<span style="color: gray">string</span> <span style="color: yellow">sortExpression</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>.<span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">FindAll</span>();</p>
<p style="margin: 0px">        <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>.<span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">FindById</span>(<span style="color: silver">Guid</span> <span style="color: yellow">Id</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">T</span> <span style="color: yellow">GetById</span>(<span style="color: silver">Guid</span> <span style="color: yellow">Id</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">T</span> <span style="color: yellow">GetOne</span>(<span style="color: gray">string</span> <span style="color: yellow">oPath</span>);</p>
<p style="margin: 0px">        <span style="color: yellow">T</span> <span style="color: yellow">Insert</span>(<span style="color: yellow">T</span> <span style="color: yellow">item</span>);</p>
<p style="margin: 0px">        <span style="color: gray">string</span> <span style="color: yellow">SortExpression</span> { <span style="color: gray">get</span>; <span style="color: gray">set</span>; }</p>
<p style="margin: 0px">        <span style="color: yellow">T</span> <span style="color: yellow">Update</span>(<span style="color: yellow">T</span> <span style="color: yellow">item</span>);</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p> </p>
<p>And this is the abstract class :</p>
<p> </p>
<div style="font-size: 9pt; background: black; color: white; font-family: consolas">
<p style="margin: 0px"><span style="color: gray">using</span> <span style="color: yellow">System</span>;</p>
<p style="margin: 0px"><span style="color: gray">using</span> <span style="color: yellow">System</span>.<span style="color: yellow">Collections</span>.<span style="color: yellow">Generic</span>;</p>
<p style="margin: 0px"><span style="color: gray">using</span> <span style="color: yellow">System</span>.<span style="color: yellow">Text</span>;</p>
<p style="margin: 0px"><span style="color: gray">using</span> <span style="color: yellow">Base4</span>.<span style="color: yellow">Storage</span>;</p>
<p style="margin: 0px"><span style="color: gray">using</span> <span style="color: yellow">System</span>.<span style="color: yellow">ComponentModel</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: gray">namespace</span> <span style="color: yellow">TimeSheets</span>.<span style="color: yellow">Application</span>.<span style="color: yellow">Base</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">    <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">    <span style="color: gray">///</span><span style="color: green"> A generic class that handles data access through Base4</span></p>
<p style="margin: 0px">    <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">    <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><typeparam name="T"></typeparam></span></p>
<p style="margin: 0px">    <span style="color: gray">public</span> <span style="color: gray">abstract</span> <span style="color: gray">class</span> <span style="color: silver">BaseDataObject</span><<span style="color: yellow">T</span>> : <span style="color: yellow">Base</span>.<span style="color: silver">DataObject</span>, <span style="color: yellow">Contract</span>.<span style="color: yellow">Data</span>.<span style="color: silver">IDataObject</span><<span style="color: yellow">T</span>> <span style="color: gray">where</span> <span style="color: yellow">T</span> : <span style="color: gray">class</span>,<span style="color: silver">IItem</span>, <span style="color: gray">new</span>()</p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">        <span style="color: gray">private</span> <span style="color: gray">string</span> <span style="color: yellow">m_SortExpression</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Gets or sets the sort expression.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><value></span><span style="color: green">The sort expression.</span><span style="color: gray"></value></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: gray">string</span> <span style="color: yellow">SortExpression</span></p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: gray">get</span> { <span style="color: gray">return</span> <span style="color: yellow">m_SortExpression</span>; }</p>
<p style="margin: 0px">            <span style="color: gray">set</span> { <span style="color: yellow">m_SortExpression</span> = <span style="color: gray">value</span>; }</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Finds the specified in the object path.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="oPath"></span><span style="color: green">The Object path.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">Find</span>(<span style="color: gray">string</span> <span style="color: yellow">oPath</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: green">//set the default sort expression to none</span></p>
<p style="margin: 0px">            <span style="color: gray">this</span>.<span style="color: yellow">m_SortExpression</span> = <span style="color: gray">string</span>.<span style="color: yellow">Empty</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Get my stuff</span></p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: silver">StorageContext</span>.<span style="color: yellow">Find</span><<span style="color: yellow">T</span>>(<span style="color: yellow">initialiseObjectPath</span>(<span style="color: gray">new</span> <span style="color: silver">ObjectPath</span>(<span style="color: yellow">oPath</span>)));</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Finds the specified Object path sorted by the provided sort expression.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="oPath"></span><span style="color: green">The Object path.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="sortExpression"></span><span style="color: green">The sort expression.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">Find</span>(<span style="color: gray">string</span> <span style="color: yellow">oPath</span>, <span style="color: gray">string</span> <span style="color: yellow">sortExpression</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: green">//Set the default sort expression</span></p>
<p style="margin: 0px">            <span style="color: gray">this</span>.<span style="color: yellow">m_SortExpression</span> = <span style="color: yellow">sortExpression</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Get the data out</span></p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: silver">StorageContext</span>.<span style="color: yellow">Find</span><<span style="color: yellow">T</span>>(<span style="color: yellow">initialiseObjectPath</span>(<span style="color: gray">new</span> <span style="color: silver">ObjectPath</span>(<span style="color: yellow">oPath</span>)));</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Finds the specified Object path with server side paging.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="oPath"></span><span style="color: green">The Object path.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="sortExpression"></span><span style="color: green">The sort expression.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="pageNumber"></span><span style="color: green">The page number.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="pageSize"></span><span style="color: green">Size of the page.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="pageCount"></span><span style="color: green">The page count.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">Find</span>(<span style="color: gray">string</span> <span style="color: yellow">oPath</span>, <span style="color: gray">string</span> <span style="color: yellow">sortExpression</span>, <span style="color: gray">int</span> <span style="color: yellow">pageNumber</span>, <span style="color: gray">int</span> <span style="color: yellow">pageSize</span>, <span style="color: gray">out</span> <span style="color: gray">int</span> <span style="color: yellow">pageCount</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: green">//initialise the pagecount parameter</span></p>
<p style="margin: 0px">            <span style="color: yellow">pageCount</span> = <span style="color: aqua">0</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Set the pagecount parameter tot he actual value</span></p>
<p style="margin: 0px">            <span style="color: yellow">pageCount</span> = (<span style="color: gray">int</span>)<span style="color: silver">Math</span>.<span style="color: yellow">Ceiling</span>(<span style="color: silver">Convert</span>.<span style="color: yellow">ToDouble</span>(<span style="color: yellow">getCount</span>() / <span style="color: yellow">pageSize</span>));</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//if we got a sort expression do initialize with it please</span></p>
<p style="margin: 0px">            <span style="color: gray">if</span> (!<span style="color: gray">string</span>.<span style="color: yellow">IsNullOrEmpty</span>(<span style="color: yellow">sortExpression</span>))</p>
<p style="margin: 0px">                <span style="color: yellow">m_SortExpression</span> = <span style="color: yellow">sortExpression</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//initialise the object pathe with the provide oPath parameter and initialise the order by</span></p>
<p style="margin: 0px">            <span style="color: silver">ObjectPath</span> <span style="color: yellow">path</span> = <span style="color: yellow">initialiseObjectPath</span>(<span style="color: gray">new</span> <span style="color: silver">ObjectPath</span>(<span style="color: yellow">oPath</span>));</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Tell Base4 which page to retrieve</span></p>
<p style="margin: 0px">            <span style="color: yellow">path</span>.<span style="color: yellow">PageSize</span> = <span style="color: yellow">pageSize</span>;</p>
<p style="margin: 0px">            <span style="color: yellow">path</span>.<span style="color: yellow">PageNumber</span> = <span style="color: yellow">pageNumber</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Get the items</span></p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: silver">StorageContext</span>.<span style="color: yellow">Find</span><<span style="color: yellow">T</span>>(<span style="color: yellow">path</span>);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Finds all items.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">FindAll</span>()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: gray">this</span>.<span style="color: yellow">m_SortExpression</span> = <span style="color: gray">string</span>.<span style="color: yellow">Empty</span>;</p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: silver">StorageContext</span>.<span style="color: yellow">Find</span><<span style="color: yellow">T</span>>(<span style="color: yellow">initialiseObjectPath</span>());</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Finds all the items sorted.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="sortExpression"></span><span style="color: green">The sort expression.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">FindAll</span>(<span style="color: gray">string</span> <span style="color: yellow">sortExpression</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: gray">this</span>.<span style="color: yellow">m_SortExpression</span> = <span style="color: yellow">sortExpression</span>;</p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: silver">StorageContext</span>.<span style="color: yellow">Find</span><<span style="color: yellow">T</span>>(<span style="color: yellow">initialiseObjectPath</span>());</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Finds all.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="sortExpression"></span><span style="color: green">The sort expression.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="pageNumber"></span><span style="color: green">The page number.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="pageSize"></span><span style="color: green">Size of the page.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="pageCount"></span><span style="color: green">The page count.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">FindAll</span>(<span style="color: gray">string</span> <span style="color: yellow">sortExpression</span>, <span style="color: gray">int</span> <span style="color: yellow">pageNumber</span>, <span style="color: gray">int</span> <span style="color: yellow">pageSize</span>, <span style="color: gray">out</span> <span style="color: gray">int</span> <span style="color: yellow">pageCount</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: green">//initialise the pagecount parameter</span></p>
<p style="margin: 0px">            <span style="color: yellow">pageCount</span> = <span style="color: aqua">0</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Set the pagecount parameter tot he actual value</span></p>
<p style="margin: 0px">            <span style="color: yellow">pageCount</span> = (<span style="color: gray">int</span>)<span style="color: silver">Math</span>.<span style="color: yellow">Ceiling</span>(<span style="color: silver">Convert</span>.<span style="color: yellow">ToDouble</span>(<span style="color: yellow">getCount</span>() / <span style="color: yellow">pageSize</span>));</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//if we got a sort expression do initialize with it please</span></p>
<p style="margin: 0px">            <span style="color: gray">if</span> (!<span style="color: gray">string</span>.<span style="color: yellow">IsNullOrEmpty</span>(<span style="color: yellow">sortExpression</span>))</p>
<p style="margin: 0px">                <span style="color: yellow">m_SortExpression</span> = <span style="color: yellow">sortExpression</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//initialise the object pathe with the provide oPath parameter and initialise the order by</span></p>
<p style="margin: 0px">            <span style="color: silver">ObjectPath</span> <span style="color: yellow">path</span> = <span style="color: yellow">initialiseObjectPath</span>();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Tell Base4 which page to retrieve</span></p>
<p style="margin: 0px">            <span style="color: yellow">path</span>.<span style="color: yellow">PageSize</span> = <span style="color: yellow">pageSize</span>;</p>
<p style="margin: 0px">            <span style="color: yellow">path</span>.<span style="color: yellow">PageNumber</span> = <span style="color: yellow">pageNumber</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: green">//Get the items</span></p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: silver">StorageContext</span>.<span style="color: yellow">Find</span><<span style="color: yellow">T</span>>(<span style="color: yellow">path</span>);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: green">//internal method that gives the rowcount of all items. </span></p>
<p style="margin: 0px">        <span style="color: gray">protected</span> <span style="color: gray">int</span> <span style="color: yellow">getCount</span>()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: silver">StorageContext</span>.<span style="color: yellow">FindAll</span><<span style="color: yellow">T</span>>().<span style="color: yellow">Count</span>;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">protected</span> <span style="color: silver">ObjectPath</span> <span style="color: yellow">initialiseObjectPath</span>()</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: silver">ObjectPath</span> <span style="color: yellow">path</span> = <span style="color: gray">new</span> <span style="color: silver">ObjectPath</span>();</p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: yellow">initialiseObjectPath</span>(<span style="color: yellow">path</span>);</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Initialises the object path.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="path"></span><span style="color: green">The path.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">protected</span> <span style="color: silver">ObjectPath</span> <span style="color: yellow">initialiseObjectPath</span>(<span style="color: silver">ObjectPath</span> <span style="color: yellow">path</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: green">//Do we have a sort expression</span></p>
<p style="margin: 0px">            <span style="color: gray">if</span> (!<span style="color: gray">string</span>.<span style="color: yellow">IsNullOrEmpty</span>(<span style="color: yellow">m_SortExpression</span>) &#038;&#038; <span style="color: yellow">m_SortExpression</span>.<span style="color: yellow">Trim</span>().<span style="color: yellow">Length</span> > <span style="color: aqua">0</span>)</p>
<p style="margin: 0px">            {</p>
<p style="margin: 0px">                <span style="color: green">//Give me all the sort parameters</span></p>
<p style="margin: 0px">                <span style="color: gray">string</span>[] <span style="color: yellow">sortParams</span> = <span style="color: yellow">m_SortExpression</span>.<span style="color: yellow">Split</span>(<span style="color: red">&#8220;,&#8221;</span>.<span style="color: yellow">ToCharArray</span>());</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">                <span style="color: green">//Now go work out their object path</span></p>
<p style="margin: 0px">                <span style="color: gray">foreach</span> (<span style="color: gray">string</span> <span style="color: yellow">s</span> <span style="color: gray">in</span> <span style="color: yellow">sortParams</span>)</p>
<p style="margin: 0px">                {</p>
<p style="margin: 0px">                    <span style="color: green">//Work out the direction</span></p>
<p style="margin: 0px">                    <span style="color: silver">OrderByDirection</span> <span style="color: yellow">direction</span> = <span style="color: yellow">s</span>.<span style="color: yellow">IndexOf</span>(<span style="color: red">&#8220;DESC&#8221;</span>) > -<span style="color: aqua">1</span> ? <span style="color: silver">OrderByDirection</span>.<span style="color: yellow">Descending</span> : <span style="color: silver">OrderByDirection</span>.<span style="color: yellow">Ascending</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">                    <span style="color: green">//Work out the column</span></p>
<p style="margin: 0px">                    <span style="color: gray">string</span> <span style="color: yellow">orderby</span> = <span style="color: yellow">s</span>.<span style="color: yellow">Substring</span>(<span style="color: aqua">0</span>, <span style="color: yellow">s</span>.<span style="color: yellow">IndexOf</span>(<span style="color: red">&#8220;DESC&#8221;</span>) > -<span style="color: aqua">1</span> ? <span style="color: yellow">s</span>.<span style="color: yellow">IndexOf</span>(<span style="color: red">&#8220;DESC&#8221;</span>) : <span style="color: yellow">s</span>.<span style="color: yellow">Length</span>);</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">                    <span style="color: yellow">path</span>.<span style="color: yellow">AddOrderBy</span>(<span style="color: yellow">orderby</span>, <span style="color: yellow">direction</span>);</p>
<p style="margin: 0px">                }</p>
<p style="margin: 0px">            }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: yellow">path</span>;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Gets the Item as an item through a specified Object path.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="oPath"></span><span style="color: green">The Object path.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: yellow">T</span> <span style="color: yellow">GetOne</span>(<span style="color: gray">string</span> <span style="color: yellow">oPath</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: silver">StorageContext</span>.<span style="color: yellow">FindOne</span><<span style="color: yellow">T</span>>(<span style="color: gray">new</span> <span style="color: silver">ObjectPath</span>(<span style="color: yellow">oPath</span>));</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Finds the item by id and returns a list.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="Id"></span><span style="color: green">The id.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">FindById</span>(<span style="color: silver">Guid</span> <span style="color: yellow">Id</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">itemList</span> = <span style="color: silver">StorageContext</span>.<span style="color: yellow">Find</span><<span style="color: yellow">T</span>>(<span style="color: red">&#8220;Id=&#8217;{0}&#8217;&#8221;</span>, <span style="color: yellow">Id</span>.<span style="color: yellow">ToString</span>());</p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: yellow">itemList</span>.<span style="color: yellow">Count</span> > <span style="color: aqua">0</span> ? <span style="color: yellow">itemList</span> : <span style="color: gray">new</span> <span style="color: silver">ItemList</span><<span style="color: yellow">T</span>>() <span style="color: gray">as</span> <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>>;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Gets the item by id as an item.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="Id"></span><span style="color: green">The id.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: yellow">T</span> <span style="color: yellow">GetById</span>(<span style="color: silver">Guid</span> <span style="color: yellow">Id</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            <span style="color: silver">IItemList</span><<span style="color: yellow">T</span>> <span style="color: yellow">itemList</span> = <span style="color: yellow">FindById</span>(<span style="color: yellow">Id</span>);</p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: yellow">itemList</span>.<span style="color: yellow">Count</span> > <span style="color: aqua">0</span> ? <span style="color: yellow">itemList</span>[<span style="color: aqua">0</span>] : <span style="color: gray">new</span> <span style="color: yellow">T</span>();</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Inserts the specified item.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="item"></span><span style="color: green">The item.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: yellow">T</span> <span style="color: yellow">Insert</span>(<span style="color: yellow">T</span> <span style="color: yellow">item</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            ((<span style="color: silver">IItem</span>)<span style="color: yellow">item</span>).<span style="color: yellow">Save</span>();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: yellow">item</span>;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Updates the specified item.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="item"></span><span style="color: green">The item.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><returns></returns></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: yellow">T</span> <span style="color: yellow">Update</span>(<span style="color: yellow">T</span> <span style="color: yellow">item</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            ((<span style="color: silver">IItem</span>)<span style="color: yellow">item</span>).<span style="color: yellow">Save</span>();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">            <span style="color: gray">return</span> <span style="color: yellow">item</span>;</p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"><summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> Deletes the specified item.</span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray"></summary></span></p>
<p style="margin: 0px">        <span style="color: gray">///</span><span style="color: green"> </span><span style="color: gray">
<param name="item"></span><span style="color: green">The item.</span><span style="color: gray"></param></span></p>
<p style="margin: 0px">        <span style="color: gray">public</span> <span style="color: gray">virtual</span> <span style="color: gray">void</span> <span style="color: yellow">Delete</span>(<span style="color: yellow">T</span> <span style="color: yellow">item</span>)</p>
<p style="margin: 0px">        {</p>
<p style="margin: 0px">            ((<span style="color: silver">IItem</span>)<span style="color: yellow">item</span>).<span style="color: yellow">Delete</span>();</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px">        }</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
<p>This is the concrete implementation:</p>
<div style="font-size: 9pt; background: black; color: white; font-family: consolas">
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: gray">using</span> <span style="color: yellow">Fogcreek</span>.<span style="color: yellow">FogbugzEx</span>;</p>
<p style="margin: 0px"> </p>
<p style="margin: 0px"><span style="color: gray">namespace</span> <span style="color: yellow">TimeSheets</span>.<span style="color: yellow">Application</span>.<span style="color: yellow">Dao</span></p>
<p style="margin: 0px">{</p>
<p style="margin: 0px">    <span style="color: gray">public</span> <span style="color: gray">class</span> <span style="color: silver">TimesheetDao</span> : <span style="color: yellow">Base</span>.<span style="color: silver">BaseDataObject</span><<span style="color: silver">Timesheet</span>></p>
<p style="margin: 0px">    {</p>
<p style="margin: 0px">    }</p>
<p style="margin: 0px">}</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/09/23/base4-and-castle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Objectdatasource, gridview and custom paging</title>
		<link>http://flanders.co.nz/2006/08/31/objectdatasource-gridview-and-custom-paging/</link>
		<comments>http://flanders.co.nz/2006/08/31/objectdatasource-gridview-and-custom-paging/#comments</comments>
		<pubDate>Thu, 31 Aug 2006 11:29:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[Base4]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/08/31/objectdatasource-gridview-and-custom-paging/</guid>
		<description><![CDATA[I&#8217;ve spent the last couple of hours trying to work something out that boggled my mind.
I have a base4 class that I wrapped in a Dataobject in my Businesslayer.
On my page (actually in a user control) i have a gridview that binds to an object datasource and stores the list of retrieved values in the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last couple of hours trying to work something out that boggled my mind.</p>
<p>I have a <a class="" title="The coolest OR tool ever" href="http://www.base4.net" target="">base4</a> class that I wrapped in a Dataobject in my Businesslayer.</p>
<p>On my page (actually in a user control) i have a gridview that binds to an object datasource and stores the list of retrieved values in the viewstate. The business object is paged server side and supports sorting.</p>
<p>The business object looks at it&#8217;s simplest like this :</p>
<p>There are 2 methods for every retrieval function. the first method is the method that fetches the list of data to display and the second method just gives the full row count. There are 2 methods because their signatures need to be the same.</p>
<p>What i then did was handle the objectSelected event of the object datasource and pass the e.ReturnValue to a property of my control that stores the list in viewstate.<br />When i select something in the gridview I always got an exception thrown telling me that the variable in viewstate was null.</p>
<p>After a lot of debugging sessions (in a solution that takes about 10 minutes or a little longer to build) I found out that i get a value in the viewstate but then lost it again in the same operation.</p>
<p>And that&#8217;s when it hit me. The object datasource selected event gets also fired for the count method and empties the viewstate. So now I have a second round trip to my database to stick the values in the viewstate and everything works.</p>
<p>So if anybody comes across a similar problem this is how i got around it.<br />I do realize the importance of caching <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The objectdatasource definition: </p>
<p>
				<span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><asp:ObjectDataSource ID=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;ObjectDataSource1&#8243;</span> runat=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;server&#8221;</span> DataObjectTypeName=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;Smap.Data.Contact&#8221;</span><br />EnablePaging=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;True&#8221;</span> MaximumRowsParameterName=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;pageSize&#8221;</span> OldValuesParameterFormatString=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;original_{0}&#8221;</span><br />SelectCountMethod=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;GetByCompanyNameCount&#8221;</span> SelectMethod=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;GetByCompanyName&#8221;</span> SortParameterName=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;sortExpression&#8221;</span><br />TypeName=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;Smap.Businesslogic.Contacts.ContactSource&#8221;</span> EnableViewState=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;true&#8221;</span> OnSelected=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;ObjectDataSource1_Selected&#8221;</span>><br /><SelectParameters><br /><asp:ControlParameter ControlID=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;SearchList&#8221;</span> Name=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;searchString&#8221;</span> PropertyName=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;Text&#8221;</span><br />Type=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;String&#8221;</span> /><br /><asp:Parameter Name=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;sortExpression&#8221;</span> Type=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;String&#8221;</span> /><br /><asp:Parameter Name=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;startRowIndex&#8221;</span> Type=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;Int32&#8243;</span> /><br /><asp:Parameter Name=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;pageSize&#8221;</span> Type=<span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">&#8220;Int32&#8243;</span> /><br /></SelectParameters><br /></asp:ObjectDataSource></span>
		</p>
<p>
				<span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">And the objectdatasource selected event :</p>
<p></span>
		</p>
<div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
<p style="MARGIN: 0px">    <span style="COLOR: blue">protected</span><span style="COLOR: blue">void</span> ObjectDataSource1_Selected(<span style="COLOR: blue">object</span> sender, <span style="COLOR: teal">ObjectDataSourceStatusEventArgs</span> e)</p>
<p style="MARGIN: 0px">    {</p>
<p style="MARGIN: 0px">        <span style="COLOR: blue">if</span> (e.OutputParameters.Keys.Count > 0)</p>
<p style="MARGIN: 0px">        {</p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">foreach</span> (<span style="COLOR: blue">object</span> key <span style="COLOR: blue">in</span> e.OutputParameters.Keys)</p>
<p style="MARGIN: 0px">            {</p>
<p style="MARGIN: 0px">                Response.Write(<span style="COLOR: blue">string</span>.Format(<span style="COLOR: maroon">&#8220;Key: {0}, Value: {1}, Type: {2}<br />&#8220;</span>,key,e.OutputParameters[key],e.OutputParameters[key].GetType()));</p>
<p style="MARGIN: 0px">            }</p>
<p style="MARGIN: 0px">        }</p>
<p style="MARGIN: 0px">        Contacts = source.GetByCompanyNameByPage(SearchList.Text, gvContacts.SortExpression, gvContacts.PageIndex, gvContacts.PageSize) <span style="COLOR: blue">as</span><span style="COLOR: teal">ItemList</span><<span style="COLOR: teal">Contact</span>>;</p>
<p style="MARGIN: 0px">    }</p>
</p></div>
<p>
				<!--EndFragment--><br />
				<span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><br />
						<br />
				</span>
		</p>
<p>The business object :</p>
<div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
<div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
<p style="MARGIN: 0px">
								<span style="COLOR: blue">using</span> System;</p>
<p style="MARGIN: 0px">
								<span style="COLOR: blue">using</span> System.Collections.Generic;</p>
<p style="MARGIN: 0px">
								<span style="COLOR: blue">using</span> System.Text;</p>
<p style="MARGIN: 0px">
								<span style="COLOR: blue">using</span> System.ComponentModel;</p>
<p style="MARGIN: 0px">
								<span style="COLOR: blue">using</span> Smap.Data;</p>
<p style="MARGIN: 0px">
								<span style="COLOR: blue">using</span> Base4.Storage;</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">
								<span style="COLOR: blue">namespace</span> Smap.Businesslogic.Contacts</p>
<p style="MARGIN: 0px">{</p>
<p style="MARGIN: 0px">    [<span style="COLOR: teal">DataObject</span>]</p>
<p style="MARGIN: 0px">    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: teal">ContactSource</span></p>
<p style="MARGIN: 0px">    {</p>
<p style="MARGIN: 0px">        [<span style="COLOR: teal">DataObjectMethod</span>(<span style="COLOR: teal">DataObjectMethodType</span>.Select,<span style="COLOR: blue">true</span>)]</p>
<p style="MARGIN: 0px">        <span style="COLOR: blue">public</span><span style="COLOR: teal">IItemList</span><Smap.Data.<span style="COLOR: teal">Contact</span>> GetByCompanyName(<span style="COLOR: blue">string</span> searchString, <span style="COLOR: blue">string</span> sortExpression, <span style="COLOR: blue">int</span> startRowIndex, <span style="COLOR: blue">int</span> pageSize)</p>
<p style="MARGIN: 0px">        {</p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Set the default sortexpression is none is provided.</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">if</span> (<span style="COLOR: blue">string</span>.IsNullOrEmpty(sortExpression))</p>
<p style="MARGIN: 0px">                sortExpression = <span style="COLOR: maroon">&#8220;CompanyName&#8221;</span>;</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//The objectdatasource returns the index of the first row that is to be retrieved</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Base4 needs the page number</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">int</span> pageNumber = getPageNumber(startRowIndex, pageSize);</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//initialise the object path with the sort expression</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: teal">ObjectPath</span> path = initialiseObjectPath(sortExpression);</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Add our parameter</span></p>
<p style="MARGIN: 0px">            path.New(<span style="COLOR: maroon">&#8220;CompanyName&#8221;</span>).LIKE(<span style="COLOR: blue">string</span>.Format(<span style="COLOR: maroon">&#8220;%{0}%&#8221;</span>, searchString));</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Tell base4 which pages that need to be retrieved.</span></p>
<p style="MARGIN: 0px">            path.PageNumber = pageNumber;</p>
<p style="MARGIN: 0px">            path.PageSize = pageSize;</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Return our list to the object datasource</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">return</span><span style="COLOR: teal">StorageContext</span>.Find<Smap.Data.<span style="COLOR: teal">Contact</span>>(path);</p>
<p style="MARGIN: 0px">        }</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">        [<span style="COLOR: teal">DataObjectMethod</span>(<span style="COLOR: teal">DataObjectMethodType</span>.Select, <span style="COLOR: blue">true</span>)]</p>
<p style="MARGIN: 0px">        <span style="COLOR: blue">public</span><span style="COLOR: teal">IItemList</span><Smap.Data.<span style="COLOR: teal">Contact</span>> GetByCompanyNameByPage(<span style="COLOR: blue">string</span> searchString, <span style="COLOR: blue">string</span> sortExpression, <span style="COLOR: blue">int</span> pageNumber, <span style="COLOR: blue">int</span> pageSize)</p>
<p style="MARGIN: 0px">        {</p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Set the default sortexpression is none is provided.</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">if</span> (<span style="COLOR: blue">string</span>.IsNullOrEmpty(sortExpression))</p>
<p style="MARGIN: 0px">                sortExpression = <span style="COLOR: maroon">&#8220;CompanyName&#8221;</span>;</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//initialise the object path with the sort expression</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: teal">ObjectPath</span> path = initialiseObjectPath(sortExpression);</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Add our parameter</span></p>
<p style="MARGIN: 0px">            path.New(<span style="COLOR: maroon">&#8220;CompanyName&#8221;</span>).LIKE(<span style="COLOR: blue">string</span>.Format(<span style="COLOR: maroon">&#8220;%{0}%&#8221;</span>, searchString));</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Tell base4 which pages that need to be retrieved and their length.</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//The gridview returns the page index which is zero-based, base4 asks for a page number which starts at 1.</span></p>
<p style="MARGIN: 0px">            path.PageNumber = ++pageNumber;</p>
<p style="MARGIN: 0px">            path.PageSize = pageSize;</p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">return</span><span style="COLOR: teal">StorageContext</span>.Find<Smap.Data.<span style="COLOR: teal">Contact</span>>(path);</p>
<p style="MARGIN: 0px">        }</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">        <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> GetByCompanyNameCount(<span style="COLOR: blue">string</span> searchString, <span style="COLOR: blue">string</span> sortExpression, <span style="COLOR: blue">int</span> startRowIndex, <span style="COLOR: blue">int</span> pageSize)</p>
<p style="MARGIN: 0px">        {</p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//Gets the count of all the contacts.</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">return</span><span style="COLOR: teal">StorageContext</span>.FindAll<Smap.Data.<span style="COLOR: teal">Contact</span>>().Count;</p>
<p style="MARGIN: 0px">        }</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">        <span style="COLOR: blue">private</span><span style="COLOR: teal">ObjectPath</span> initialiseObjectPath(<span style="COLOR: blue">string</span> sortExpression)</p>
<p style="MARGIN: 0px">        {</p>
<p style="MARGIN: 0px">            <span style="COLOR: teal">ObjectPath</span> path = <span style="COLOR: blue">new</span><span style="COLOR: teal">ObjectPath</span>();</p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">if</span> (sortExpression.Trim().Length > 0)</p>
<p style="MARGIN: 0px">            {</p>
<p style="MARGIN: 0px">                <span style="COLOR: blue">string</span>[] sortParams = sortExpression.Split(<span style="COLOR: maroon">&#8220;,&#8221;</span>.ToCharArray());</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">                <span style="COLOR: blue">foreach</span> (<span style="COLOR: blue">string</span> s <span style="COLOR: blue">in</span> sortParams)</p>
<p style="MARGIN: 0px">                {</p>
<p style="MARGIN: 0px">                    <span style="COLOR: teal">OrderByDirection</span> direction = s.IndexOf(<span style="COLOR: maroon">&#8220;DESC&#8221;</span>) > -1 ? <span style="COLOR: teal">OrderByDirection</span>.Descending : <span style="COLOR: teal">OrderByDirection</span>.Ascending;</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">                    <span style="COLOR: blue">string</span> orderby = s.Substring(0, s.IndexOf(<span style="COLOR: maroon">&#8220;DESC&#8221;</span>) > -1 ? s.IndexOf(<span style="COLOR: maroon">&#8220;DESC&#8221;</span>) : s.Length);</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">                    path.AddOrderBy(orderby, direction);</p>
<p style="MARGIN: 0px">                }</p>
<p style="MARGIN: 0px">            }</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">return</span> path;</p>
<p style="MARGIN: 0px">        }</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">        <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> getPageNumber(<span style="COLOR: blue">int</span> startRowIndex, <span style="COLOR: blue">int</span> pageSize)</p>
<p style="MARGIN: 0px">        {</p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//if the start index is smaller than 0 return 0 otherwise return the index of the current page.</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">int</span> number = startRowIndex <= 0 ? 0 : (<span style="COLOR: blue">int</span>)<span style="COLOR: teal">Math</span>.Ceiling(<span style="COLOR: teal">Convert</span>.ToDouble(startRowIndex / pageSize));</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">            <span style="COLOR: green">//make our zero-based index into a number starting at 1;</span></p>
<p style="MARGIN: 0px">            <span style="COLOR: blue">return</span> ++number;</p>
<p style="MARGIN: 0px">        }</p>
<p style="MARGIN: 0px"> </p>
<p style="MARGIN: 0px">    }</p>
<p style="MARGIN: 0px">}</p>
</p></div>
<p>				<!--EndFragment-->
		</div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/08/31/objectdatasource-gridview-and-custom-paging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A generic builder for unit tests</title>
		<link>http://flanders.co.nz/2006/08/29/a-generic-builder-for-unit-tests/</link>
		<comments>http://flanders.co.nz/2006/08/29/a-generic-builder-for-unit-tests/#comments</comments>
		<pubDate>Tue, 29 Aug 2006 11:45:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[Base4]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2006/08/29/a-generic-builder-for-unit-tests/</guid>
		<description><![CDATA[
I&#8217;ve been using base4 quite a lot lately   . And obviously I like it. But anyway for unit testing i found myself writing
virtually the same builder class over and over again.

And since it is just test data that needs to be removed later it is always
very similar. I started thinking about my problem and [...]]]></description>
			<content:encoded><![CDATA[<div style="background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<p>I&#8217;ve been using <a href="http://www.base4.net/">base4</a> quite a lot lately  <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . And obviously I like it. But anyway for unit testing i found myself writing<br />
virtually the same builder class over and over again.
</p>
<p>And since it is just test data that needs to be removed later it is always<br />
very similar. I started thinking about my problem and came to the conclusion<br />
that I could easily enough build a generic class that iterates over the object<br />
and takes all the properties that belong to that type and not to any of the<br />
parent types and fill them with valid data for their returntype.
</p>
<p>I got to work and not so long after that I came up with the following class:
</p>
<p style="margin: 0px;">
						<span style="color: blue;">using</span> System;</p>
<p style="margin: 0px;">
						<span style="color: blue;">using</span> System.Collections.Generic;</p>
<p style="margin: 0px;">
						<span style="color: blue;">using</span> System.Text;</p>
<p style="margin: 0px;">
						<span style="color: blue;">using</span> Base4.Storage;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">
						<span style="color: blue;">namespace</span> NBlogr.NUnitTests.HelperClasses</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">    <span style="color: blue;">public</span><span style="color: blue;">class</span><span style="color: teal;">Builder</span><T> <span style="color: blue;">where</span> T : <span style="color: blue;">class</span>,<span style="color: teal;">IItem</span>,<span style="color: blue;">new</span>()</p>
<p style="margin: 0px;">    {</p>
<p style="margin: 0px;">        <span style="color: blue;">private</span><span style="color: teal;">List</span><T> items;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">public</span><span style="color: teal;">List</span><T> Items</p>
<p style="margin: 0px;">        {</p>
<p style="margin: 0px;">            <span style="color: blue;">get</span></p>
<p style="margin: 0px;">            {</p>
<p style="margin: 0px;">                <span style="color: blue;">if</span> (items == <span style="color: blue;">null</span>) items = <span style="color: blue;">new</span><span style="color: teal;">List</span><T>();</p>
<p style="margin: 0px;">                <span style="color: blue;">return</span> items;</p>
<p style="margin: 0px;">            }</p>
<p style="margin: 0px;">            <span style="color: blue;">set</span> { items = <span style="color: blue;">value</span>; }</p>
<p style="margin: 0px;">        }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">public</span><span style="color: blue;">virtual</span> T Add()</p>
<p style="margin: 0px;">        {</p>
<p style="margin: 0px;">            <span style="color: blue;">return</span> Add(<span style="color: blue;">null</span>);</p>
<p style="margin: 0px;">        }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">public</span> T Add(<span style="color: blue;">int</span>? index)</p>
<p style="margin: 0px;">        {</p>
<p style="margin: 0px;">            T t = <span style="color: blue;">new</span> T();</p>
<p style="margin: 0px;">            <span style="color: blue;">return</span> Add(t, index, <span style="color: blue;">true</span>);</p>
<p style="margin: 0px;">        }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">public</span><span style="color: blue;">virtual</span> T Add(T t, <span style="color: blue;">int</span>? index, <span style="color: blue;">bool</span> generateValues)</p>
<p style="margin: 0px;">        {</p>
<p style="margin: 0px;">            <span style="color: teal;">IItem</span> item = t;</p>
<p style="margin: 0px;">            <span style="color: blue;">if</span> (generateValues)</p>
<p style="margin: 0px;">            {</p>
<p style="margin: 0px;">                <span style="color: blue;">foreach</span> (<span style="color: teal;">PropertyImpl</span> p <span style="color: blue;">in</span> item.TypeDefinition.Properties)</p>
<p style="margin: 0px;">                {</p>
<p style="margin: 0px;">                    <span style="color: blue;">switch</span> (p.ReturnTypeName)</p>
<p style="margin: 0px;">                    {</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;bool&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;Boolean&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.Boolean&#8221;</span>:</p>
<p style="margin: 0px;">                            item[p.Name] = index.HasValue;</p>
<p style="margin: 0px;">                            <span style="color: blue;">break</span>;</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;string&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;String&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.String&#8221;</span>:</p>
<p style="margin: 0px;">                            <span style="color: blue;">if</span> (index.HasValue)</p>
<p style="margin: 0px;">                                item[p.Name] = <span style="color: blue;">string</span>.Format(<span style="color: maroon;">&#8220;Unittest {0} {1}&#8221;</span>, item.TypeDefinition.Name, index);</p>
<p style="margin: 0px;">                            <span style="color: blue;">else</span></p>
<p style="margin: 0px;">                                item[p.Name] = <span style="color: blue;">string</span>.Format(<span style="color: maroon;">&#8220;Unittest {0}&#8221;</span>, item.TypeDefinition.Name);</p>
<p style="margin: 0px;">                            <span style="color: blue;">break</span>;</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;uint&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;short&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;int&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;long&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;Int16&#8243;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;Int32&#8243;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;Int64&#8243;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.Int16&#8243;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.Int32&#8243;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.Int64&#8243;</span>:</p>
<p style="margin: 0px;">                            item[p.Name] = index.HasValue ? index.Value : <span style="color: blue;">new</span><span style="color: teal;">Random</span>().Next();</p>
<p style="margin: 0px;">                            <span style="color: blue;">break</span>;</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;byte&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;Byte&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.Byte&#8221;</span>:</p>
<p style="margin: 0px;">                            item[p.Name] = index.HasValue ? <span style="color: teal;">Convert</span>.ToByte(index.Value) : <span style="color: blue;">new</span><span style="color: blue;">byte</span>();</p>
<p style="margin: 0px;">                            <span style="color: blue;">break</span>;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;double&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;Double&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.Double&#8221;</span>:</p>
<p style="margin: 0px;">                            item[p.Name] = index.HasValue ? <span style="color: teal;">Convert</span>.ToDouble(index.Value) : <span style="color: blue;">new</span><span style="color: teal;">Random</span>().NextDouble();</p>
<p style="margin: 0px;">                            <span style="color: blue;">break</span>;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;byte[]&#8220;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;Byte[]&#8220;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.Byte[]&#8220;</span>:</p>
<p style="margin: 0px;">                            <span style="color: teal;">Byte</span>[] bytes = <span style="color: blue;">new</span><span style="color: blue;">byte</span>[128];</p>
<p style="margin: 0px;">                            <span style="color: teal;">Random</span> rnd = <span style="color: blue;">new</span><span style="color: teal;">Random</span>();</p>
<p style="margin: 0px;">                            rnd.NextBytes(bytes);</p>
<p style="margin: 0px;">                            item[p.Name] = bytes;</p>
<p style="margin: 0px;">                            <span style="color: blue;">break</span>;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;Guid&#8221;</span>:</p>
<p style="margin: 0px;">                        <span style="color: blue;">case</span><span style="color: maroon;">&#8220;System.Guid&#8221;</span>:</p>
<p style="margin: 0px;">                            item[p.Name] = <span style="color: teal;">Guid</span>.NewGuid();</p>
<p style="margin: 0px;">                            <span style="color: blue;">break</span>;</p>
<p style="margin: 0px;">                    }</p>
<p style="margin: 0px;">                }</p>
<p style="margin: 0px;">            }</p>
<p style="margin: 0px;">            item.Save();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">            items.Add((T)item);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">            <span style="color: blue;">return</span> item <span style="color: blue;">as</span> T;</p>
<p style="margin: 0px;">        }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">public</span><span style="color: blue;">void</span> BuildList()</p>
<p style="margin: 0px;">        {</p>
<p style="margin: 0px;">            BuildList(5);</p>
<p style="margin: 0px;">        }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">public</span><span style="color: blue;">void</span> BuildList(<span style="color: blue;">int</span> length)</p>
<p style="margin: 0px;">        {</p>
<p style="margin: 0px;">            <span style="color: blue;">if</span> (items == <span style="color: blue;">null</span>) items = <span style="color: blue;">new</span><span style="color: teal;">List</span><T>();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">            <span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = 0; i < length; i++)</p>
<p style="margin: 0px;">            {</p>
<p style="margin: 0px;">                <span style="color: blue;">int</span> index = i + 1;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">                Add(index);</p>
<p style="margin: 0px;">            }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">public</span><span style="color: blue;">void</span> CleanUp()</p>
<p style="margin: 0px;">        {</p>
<p style="margin: 0px;">            <span style="color: blue;">if</span> (items != <span style="color: blue;">null</span> &#038;&#038; items.Count> 0)</p>
<p style="margin: 0px;">            {</p>
<p style="margin: 0px;">                <span style="color: blue;">foreach</span> (<span style="color: teal;">IItem</span> item <span style="color: blue;">in</span> items)</p>
<p style="margin: 0px;">                {</p>
<p style="margin: 0px;">                    item.Delete();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">                }</p>
<p style="margin: 0px;">            }</p>
<p style="margin: 0px;">        }</p>
<p style="margin: 0px;">    }</p>
<p style="margin: 0px;">}</p>
</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2006/08/29/a-generic-builder-for-unit-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
