<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>IWriteCode - Adrian Tosca</title>
	<atom:link href="http://aleris.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://aleris.wordpress.com</link>
	<description>programming, life, universe, ... should I stop?</description>
	<lastBuildDate>Tue, 01 Sep 2009 14:01:03 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='aleris.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/9f5e28f7ac1756b92ca8c666cfe55dec?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>IWriteCode - Adrian Tosca</title>
		<link>http://aleris.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://aleris.wordpress.com/osd.xml" title="IWriteCode &#8211; Adrian Tosca" />
		<item>
		<title>Benchmarking &#8211; a marketing tool</title>
		<link>http://aleris.wordpress.com/2009/09/01/benchmarking-a-marketing-tool/</link>
		<comments>http://aleris.wordpress.com/2009/09/01/benchmarking-a-marketing-tool/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 13:59:46 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[1]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=153</guid>
		<description><![CDATA[There has been a recently heated discussion when http://ormbattle.net/ published benchmarks that demonstrates that NHibernate performance is poor compared with other ORM frameworks. At first sight it looks like an valuable tool for assessing different frameworks speeds, but at a deeper analysis and in the light of the comments on Ayanide post «Benchmarks are useless, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=153&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There has been a recently heated discussion when <a href="http://ormbattle.net/">http://ormbattle.net/</a> published benchmarks that demonstrates that NHibernate performance is poor compared with other ORM frameworks. At first sight it looks like an valuable tool for assessing different frameworks speeds, but at a deeper analysis and in the light of the comments on Ayanide post «<a href="http://ayende.com/Blog/archive/2009/08/15/benchmarks-are-useless-yes-again.aspx">Benchmarks are useless, yes, again</a>» it isn&#8217;t as clear anymore:</p>
<blockquote><p>Trying to compare different products without taking into account their differences is a flawed approach. Moreover, this benchmark is intentionally trying to measure something that NHibernate was never meant to perform. We don’t need to try to optimize those things, because they are meaningless, we have <em>much </em>better ways to resolve things.</p></blockquote>
<p>Making a benchmark is simple, make a loop and measure things. But this kind of benchmark only shows as much as the speed of runing some meaningless instructions in a non realistic loop.  Making a benchmark that handles real world scenarios is a much harder undertaking, one that could possibly show real insight into using a framework or another. But the frameworks are usualy very different and one way to do things in the first framework has no direct correspondence  in the other. It will just be a different thing to measure. In the end is all about marketing stuff.</p>
<p>If you want to show something is faster you can certainly make a benchmark to show it as <a href="http://www.infoq.com/articles/WebSphere-Windows-.NET-Debate">another interesing battle</a> at a whole another level clearly demonstrates. Microsoft published on <a href="http://www.microsoft.com/windowsserver/mainframe/whoknew/thebottomline.aspx">its site</a> a benchmark report entitled «Benchmarking IBM WebSphere 7 on IBM Power6 and AIX vs. Microsoft .NET on HP BladeSystem and Windows Server 2008» that demonstrates .NET on Windows is much better in terms of speed than WebShepre on AIX. IBM response was to make <a href="http://www.infoq.com/articles/WebSphere-Windows-.NET-Debate">a benchmark of its own</a> showing the opposite.</p>
<p>The bottom line is that benchmarks should be seen with reserves as most often are just marketing tools.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/153/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=153&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/09/01/benchmarking-a-marketing-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>
	</item>
		<item>
		<title>Working hard versus working smart</title>
		<link>http://aleris.wordpress.com/2009/07/11/working-hard-versus-working-smart/</link>
		<comments>http://aleris.wordpress.com/2009/07/11/working-hard-versus-working-smart/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 13:48:13 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Practices]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=145</guid>
		<description><![CDATA[Working hard on a project doesn&#8217;t always give the best productivity, there are actually more times when it doesn&#8217;t. Here are some of the approaches I&#8217;ve seen on projects:
Working hard

The code like hell approach may work for a small project, but on any project larger than a couple of month it will go wrong. After [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=145&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Working hard on a project doesn&#8217;t always give the best productivity, there are actually more times when it doesn&#8217;t. Here are some of the approaches I&#8217;ve seen on projects:</p>
<p><strong>Working hard</strong></p>
<p><img class="alignnone size-full wp-image-142" title="Work by starting hard" src="http://aleris.files.wordpress.com/2009/07/work-start-hard.png?w=501&#038;h=215" alt="Work by starting hard" width="501" height="215" /></p>
<p>The code like hell approach may work for a small project, but on any project larger than a couple of month it will go wrong. After the initial time the fatigue will prevail and the end will not make anyone on the team happy even if the project eventually delivers it&#8217;s product.</p>
<p><strong>Fuzzy start</strong></p>
<p><img class="alignnone size-full wp-image-148" title="Fuzzy start" src="http://aleris.files.wordpress.com/2009/07/work-start-fuzy2.png?w=563&#038;h=215" alt="Fuzzy start" width="563" height="215" /></p>
<p>There are times when the start of a project is not so clear, nobody knows what to do and there is a lot of fuzziness in the work that it is done.  When starting a big project it seems that there is so much time that  a lot of activities that are not very productive are allowed to take place. But after some time the schedule start to ring a bell and everyone is starting to work hard. In the end everybody is tired and the overall productivity is not very high.</p>
<p><strong>Working smart</strong></p>
<p><img class="alignnone size-full wp-image-144" title="Work smart" src="http://aleris.files.wordpress.com/2009/07/work-smart.png?w=618&#038;h=239" alt="Work smart" width="618" height="239" />\</p>
<p>But there is a way, working smart means to work as hard as you can to keep a steady peace forever. The productivity may not be the highest when measured on small periods but overall is higher than with any other approach.</p>
<p>So try to work smart and you will do more than trying to work hard!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/145/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=145&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/07/11/working-hard-versus-working-smart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>

		<media:content url="http://aleris.files.wordpress.com/2009/07/work-start-hard.png" medium="image">
			<media:title type="html">Work by starting hard</media:title>
		</media:content>

		<media:content url="http://aleris.files.wordpress.com/2009/07/work-start-fuzy2.png" medium="image">
			<media:title type="html">Fuzzy start</media:title>
		</media:content>

		<media:content url="http://aleris.files.wordpress.com/2009/07/work-smart.png" medium="image">
			<media:title type="html">Work smart</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding Liskov Substitution Principle</title>
		<link>http://aleris.wordpress.com/2009/06/14/understanding-liskov-substitution-principle/</link>
		<comments>http://aleris.wordpress.com/2009/06/14/understanding-liskov-substitution-principle/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 13:19:27 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=132</guid>
		<description><![CDATA[The Liskov Substitution Principle, in its simplified, object oriented language way, says that:
Derived classes must be substitutable for their base classes.
The principle looks simple and obvious; at first look we are tempted to question that the opposite is true: can one make a class that is not substitutable for their base class? Technically speaking no. If [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=132&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The Liskov Substitution Principle, in its simplified, object oriented language way, says that:</p>
<blockquote><p>Derived classes must be substitutable for their base classes.</p></blockquote>
<p>The principle looks simple and obvious; at first look we are tempted to question that the opposite is true: can one make a class that is not substitutable for their base class? Technically speaking no. If one makes a derived class and the compiler does not complain everything should be fine. Or is it not?</p>
<p>Let&#8217;s see a simple example:</p>
<pre class="brush: csharp;">
public class MusicPlayer {
    public virtual void Play(string fileName) {
        // reference implementation for playing
    }
}

// Optimized mp4 player
public class Mp4MusicPlayer : MusicPlayer {
    public override void Play(string fileName) {
        if (Path.GetExtension(fileName) != &quot;mp4&quot;)
            throw new ArgumentException(&quot;can only play mp4&quot;);
        // optimized implementation for playing
    }
}
</pre>
<p>In the above example we have a reference implementation for a music player. The reference implementation would play all types of files but maybe not with the best performance or quality. An optimized player for a certain type of file, for example for a MP4 file type, is as far as the c# interface is concerned a specialized type of music player.</p>
<p>So what&#8217;s the problem? The above Mp4MusicPlayer class just violated the Liskov substitution principle. One cannot substitute MusicPlayer with Mp4MusicPlayer bacause the later works only with certain specific music files. Where MusicPlayer would work with a MP3 file, the Mp4MusicPlayer would throw an exception and the program will fail.</p>
<p>Where did this go wrong? As it seems, there is more to an interface that meets the eye. In our case the preconditions of the derived class are stronger than those of the base class and even if in c# the interface does not contain in it&#8217;s definition the preconditions you will have to keep them in mind when designing the inheritance tree.</p>
<p>But there is more than that. The above is only one way in which the Liskov substitution principle can be violated. In a more general terms is a problem of abstractions. When one defines a base class or an interface it actually defines an abstraction. And when one makes a derived class implicitly agrees to satisfy the same abstraction.</p>
<p>In the example above the MusicPlayer abstraction is<strong><em> &#8220;something that can play any music file&#8221;</em></strong><br />
But Mp4MusicPlayer abstraction is <em><strong>&#8220;something that can play MP4 music files&#8221;</strong></em></p>
<p>The abstractions are different, and this is the root cause of the problem. When the abstractions are not appropriate the situation can get nasty.</p>
<div id="attachment_138" class="wp-caption alignnone" style="width: 593px"><img class="size-full wp-image-138" title="Liskov Abstraction" src="http://aleris.files.wordpress.com/2009/06/liskovabstraction.png?w=583&#038;h=417" alt="Liskov substitution principle is all about abstractions" width="583" height="417" /><p class="wp-caption-text">Liskov substitution principle is all about abstractions</p></div>
<p>There are multiple ways in which the abstraction can be broken. A wrong abstraction can be hacked in simple cases but eventually it will come back to byte you. We might be able to install an electronic device on the wooden horse in the right of the above image if we need the &#8220;horse&#8221; abstraction to neigh but we will never persuade it to eat a hand of hay.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/132/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=132&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/06/14/understanding-liskov-substitution-principle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>

		<media:content url="http://aleris.files.wordpress.com/2009/06/liskovabstraction.png" medium="image">
			<media:title type="html">Liskov Abstraction</media:title>
		</media:content>
	</item>
		<item>
		<title>DBF Data Export Library</title>
		<link>http://aleris.wordpress.com/2009/05/10/dbf-data-export-library/</link>
		<comments>http://aleris.wordpress.com/2009/05/10/dbf-data-export-library/#comments</comments>
		<pubDate>Sun, 10 May 2009 09:35:18 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[DBF]]></category>
		<category><![CDATA[TeamNet Data File Export]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=126</guid>
		<description><![CDATA[Recently I&#8217;ve written a small library for exporting data to DBF and other format files for an internal application at my current employer. This library is now open source and can be downloaded from codeplex.
The application required data exported for integration with several 3&#8242;rd party applications we do not control. These applications require the old [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=126&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently I&#8217;ve written a small library for exporting data to DBF and other format files for an internal application at my current employer. This library is now open source and can be <a href="http://datafileexport.codeplex.com/">downloaded from codeplex</a>.</p>
<p>The application required data exported for integration with several 3&#8242;rd party applications we do not control. These applications require the old DBF file format or CSV format. We also needed export in excel files, this time as a strategic feature. We had a couple of attempts for DBF/CSV files using existing methods but we found several problems.</p>
<ul>
<li>JET using Microsoft.Jet.OLEDB was plain unusable because of wrong formatting in some cases or data files not always read by our target applications</li>
<li>Using OLE DB Provider for Visual FoxPro was a lot better, we didn&#8217;t have any problem with it, until we needed to move the application to a 64 bit system. VPFOleDB does not work in a 64bit environment and there are no plans to do so. This was a show stopper for us.</li>
</ul>
<p>At this point we considered using a plain c# solution without any other dependency. This solution will allow us to fix future problems without totally replacing the underlying technology like we had to do with OLEDB external drivers. We believe this solution will pay its initial development time on the long run.</p>
<p>While there are several other solutions out there for writing DBF/CSV files, none did satisfy our requirements. The libraries we found were either of poorly quality or oriented toward data manipulation for specific file formats. We needed a library for exporting data from an existing data source to several file formats (DBF and CSV mainly, but also others to come). Mashing up existing libraries and trying to adapt them for our requirements looked daunting, so we decided to be better of writing a library form scratch. Heavy integration systems like BizTalk were also a no go.</p>
<p>The result was <a href="http://datafileexport.codeplex.com/">TeamNet Data File Export</a>, a small c# library that can take data from existing source (DataSet and IList are currently implemented) and write files to different formats (DBF and CSV are currently implemented). The library was designed for extensibility so adding other formats should be pretty easy. Office XML (Excel 2003) support is planned and will probably be added the next days.</p>
<p>The library is very easy to use and has a fluent interface. This is an example of using a data set as data source to export data to a DBF file:</p>
<pre class="brush: csharp;">
DataFileExport
        .CreateDbf(sourceDataSet)
        .AddCharacterField(&quot;AString&quot;, 30)
        .AddNumericField(&quot;ANumber&quot;, 10, 0)
        .Write(filePath);
</pre>
<p>While DBF files are certainly not trilling to work with, there are times when you need them. I hope to find this library handy then.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=126&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/05/10/dbf-data-export-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>
	</item>
		<item>
		<title>Backup Database in SqlServer with Date and Time Information in the File Name</title>
		<link>http://aleris.wordpress.com/2009/05/05/backup-database-in-sqlserver-with-date-and-time-information-in-the-file-name/</link>
		<comments>http://aleris.wordpress.com/2009/05/05/backup-database-in-sqlserver-with-date-and-time-information-in-the-file-name/#comments</comments>
		<pubDate>Tue, 05 May 2009 10:48:48 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[SqlServer]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=119</guid>
		<description><![CDATA[The build-in back-up mechanism of SqlServer allows to either override the back-up file or append to it. I usually prefer to have each back-up in it&#8217;s file, this way I can easily choose which older back-ups to delete, and immediately see the last one. The following script makes a back-up with a file name that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=119&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The build-in back-up mechanism of SqlServer allows to either override the back-up file or append to it. I usually prefer to have each back-up in it&#8217;s file, this way I can easily choose which older back-ups to delete, and immediately see the last one. The following script makes a back-up with a file name that contains date and time information and can be used in a job step:</p>
<pre class="brush: sql;">

declare @currentDate datetime
set @currentDate = GetDate()

declare @fileName varchar(255)
set @fileName = 'C:\BKP\MyDatabase'
	+ cast(Year(@currentDate) as varchar(4))
	+ Replicate('0', 2 - Len(cast(Month(@currentDate) as varchar(2))))
            + cast(Month(@currentDate) as varchar(2))
	+ Replicate('0', 2 - Len(cast(Day(@currentDate) as varchar(2))))
            + cast(Day(@currentDate) as varchar(2))
	+ '_' +
	+ Replicate('0', 2 - Len(cast(DatePart(hour, @currentDate) as varchar(2))))
            + cast(DatePart(hour, @currentDate) as varchar(2))
	+ Replicate('0', 2 - Len(cast(DatePart(minute, @currentDate) as varchar(2))))
            + cast(DatePart(minute, @currentDate) as varchar(2)) + '.bak'

backup database [MyDatabase] to disk = @fileName with NOFORMAT, NOINIT,
    name = N'MyDatabase-Full Database Backup',
    SKIP, NOREWIND, NOUNLOAD,  STATS = 10
</pre>
<p>The back-up will be written to the file with a name like <em>C:\BKP\MyDatabase_20090505_1346.bak</em>.</p>
<p>Hope it helps.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/119/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=119&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/05/05/backup-database-in-sqlserver-with-date-and-time-information-in-the-file-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>
	</item>
		<item>
		<title>Implementing a Simple Generic Repository with LinqToSql</title>
		<link>http://aleris.wordpress.com/2009/04/17/implementing-a-simple-generic-repository-with-linqtosql/</link>
		<comments>http://aleris.wordpress.com/2009/04/17/implementing-a-simple-generic-repository-with-linqtosql/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 08:24:11 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Repository]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=77</guid>
		<description><![CDATA[The Repository pattern
The Repository is a design pattern often used in Domain Driven Design (DDD) to help the domain layer access data needed from the underlying persistence layer.
The Repository pattern was described by Martin Fowler as:
A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=77&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>The Repository pattern</h3>
<p>The Repository is a design pattern often used in Domain Driven Design (DDD) to help the domain layer access data needed from the underlying persistence layer.</p>
<p>The Repository pattern was <a href="http://martinfowler.com/eaaCatalog/repository.html">described</a> by Martin Fowler as:</p>
<blockquote><p>A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications decoratively and submit them to Repository for satisfaction. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes. Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer.</p></blockquote>
<p>In DDD the repository is tightly linked with the <em>aggregate</em> notion. The aggregate is a hierarchy of objects that are treated as a unit for the purpose of data changes. The aggregate components are accessed only from its root object. A repository is usually build around an aggregate.</p>
<p>As an example we may have a Car aggregate that has a collection of Wheels.</p>
<p><img class="alignnone size-full wp-image-104" title="Car and Wheels Model" src="http://aleris.files.wordpress.com/2009/04/carandwheels.png?w=472&#038;h=152" alt="Car and Wheels Model" width="472" height="152" /></p>
<p>In our domain we will never refer to a wheel directly but first get a car and have access to its wheels.</p>
<p><img class="alignnone size-full wp-image-80" title="Get Car Aggregate from Repository" src="http://aleris.files.wordpress.com/2009/04/repositorygetcaraggregate.png?w=507&#038;h=259" alt="Get Car Aggregate from Repository" width="507" height="259" /></p>
<p>Most of the time we need just a couple of operations to deal with aggregates on the repository.  With the above example we would have to implement in the repository methods to:</p>
<ul>
<li>Add a new Car</li>
<li>Remove a Car</li>
<li>Get the Car by Id</li>
<li>Get a filtered list of Cars</li>
</ul>
<p>Implementing this in LinqToSql is pretty straightforward but it has its catches.</p>
<h3>Add and Remove</h3>
<p>The simplest to implement are the add and remove methods:</p>
<pre class="brush: csharp;">
    public class Repository&lt;T&gt; where T : class {
        CarsDataContext _dataContext = new CarsDataContext();
        public void Add(T entity) {
            DataContext.GetTable&lt;T&gt;().InsertOnSubmit(entity);
            DataContext.SubmitChanges();
        }
        public void Remove(T entity) {
            DataContext.GetTable&lt;T&gt;().DeleteOnSubmit(entity);
            DataContext.SubmitChanges();
        }
    }
</pre>
<p>Nothing special here. The generic GetTable of the LinqToSQL data context is used to insert/delete the entity and then SubmitChanges is called to send the changes to the database. The methods can be used like this:</p>
<pre class="brush: csharp;">
    Repository&lt;Car&gt; carRepository = new Repository&lt;Car&gt;();

    // create a new car and add it
    Car newCar = new Car();
    carRepository.Add(newCar);

    // get an existingCar, then remove it
    Car existingCar = ...
    carRepository.Remove(existingCar);
</pre>
<h3>Get By Id</h3>
<p>Implementing the get by id method is a little more challenging. The first thing is to ensure that the model has the &#8216;Id&#8217; notion. By default the LinqToSql classes do not have a direct way of exposing an identifier meta-data. We can have this by adding an interface and ensure the classes implements it:</p>
<pre class="brush: csharp;">
    public interface IIdentifiable {
        int Id { get; }
    }
    public partial class Car : IIdentifiable {
    }
</pre>
<p>All the classes that need to be get by Id will have to implement the IIdentifiable  interface. This is done in the code above by adding a partial class that implements the IIdentifiable  interface. There is a catch here. If a consistent naming convention is used and all the classes have an &#8216;Id&#8217; property then the above code is all we need.</p>
<p>With the classes prepared we can then write:</p>
<pre class="brush: csharp;">
    public class Repository&lt;T&gt; where T : class, IIdentifiable {
        public T GetById(int id) {
            T entity = DataContext.GetTable&lt;T&gt;().SingleOrDefault(e =&gt; e.Id.Equals(id));
            return entity;
        }
    }
</pre>
<p>Please note the <em>e.Id.Equals(id)</em> above. LinqToSql does not know how to generate the == operator when interfaces are involved but it knows to generate the proper expression tree with Equals.</p>
<p>The GetById method can then be used like:</p>
<pre class="brush: csharp;">
    Repository&lt;Car&gt; carRepository = new Repository&lt;Car&gt;();
    Car existingCar = carRepository.GetById(1);
</pre>
<p>The generated SQL contains what we expect, a parametrized query:</p>
<pre class="brush: sql;">
    exec sp_executesql N'SELECT [t0].[Id], [t0].[Make], [t0].[Year]
    FROM [dbo].[Car] AS [t0]
    WHERE [t0].[Id] = @p0',N'@p0 int',@p0=1
</pre>
<h3>Getting Aggregate Elements</h3>
<p>As LinqToSql supports lazy loading so all is needed is to access the elements from the root.</p>
<pre class="brush: csharp;">
    Car car = carRepository.GetById(1);
    Console.WriteLine(car.Make);
    Console.WriteLine(car.Wheels.Count); // additional query will hit the database
</pre>
<p>Clean and easy. For more complex scenarios where one would need to control the loading behavior the DataLoadOptions of the LinqToSql can be used.</p>
<h3>Get a Filtered List</h3>
<p>The simplest to implement this is to allow expression filters as parameters:</p>
<pre class="brush: csharp;">
    public IQueryable&lt;T&gt; GetByFilter(Expression&lt;Func&lt;T, bool&gt;&gt; filter) {
        return DataContext.GetTable&lt;T&gt;().Where(filter);
    }
    // and this can be used like:
    IQueryable&lt;Car&gt; cars = carRepository.GetByFilter(e =&gt; e.Year == 2009 &amp;&amp; e.Make == &quot;Ford&quot;);
</pre>
<p>An IQueryable is returned to allow simple UI integration. For example using a GridView with a LinqToSql source will automatically have sorting and paging implemented with this approach. The downside of this approach is that the DataContext will remain open up to the UI layer and this might introduce performance penalties. The alternative would be to return an IEnumerable instead and let the UI handle the pagination and sorting.</p>
<h3>Conclusion</h3>
<p>The solution presented is not without flaws. The biggest one is the tight link between the DB implementation and the model, forced by the LinqToSql architecture. There is also the inconvenient of having all primary keys named &#8216;Id&#8217; and having to write partial classes for implementing the IIdentifiable interface. But there are also a couple of nice things like a very simple and clean usage, the possibility to use generics with aggregates and, maybe the best one, the possibility of avoiding boiler plate code.</p>
<p><a href="http://www.box.net/shared/c44pabik53">Download the supporting code</a> for this article (12.0 KB).</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=77&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/04/17/implementing-a-simple-generic-repository-with-linqtosql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>

		<media:content url="http://aleris.files.wordpress.com/2009/04/carandwheels.png" medium="image">
			<media:title type="html">Car and Wheels Model</media:title>
		</media:content>

		<media:content url="http://aleris.files.wordpress.com/2009/04/repositorygetcaraggregate.png" medium="image">
			<media:title type="html">Get Car Aggregate from Repository</media:title>
		</media:content>
	</item>
		<item>
		<title>New Version of jQuery Dropdown Checkbox List Plugin</title>
		<link>http://aleris.wordpress.com/2009/04/11/new-version-of-jquery-dropdown-checkbox-list-plugin/</link>
		<comments>http://aleris.wordpress.com/2009/04/11/new-version-of-jquery-dropdown-checkbox-list-plugin/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 12:54:04 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[dropdown-check-list]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=69</guid>
		<description><![CDATA[One of the users of the dropdown-check-list plugin added a patch containing an update to take into consideration the optgroup tags, part of the select HTML element. After playing around with it and adding a few modifications, I uploaded a new version to the codebase that has this feature:
The above image corresponds to the following html code:


 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=69&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>One of the users of the <a title="Dropdown Checkbox List Plugin on Google Code" href="http://code.google.com/p/dropdown-check-list/">dropdown-check-list</a> plugin added a patch containing an update to take into consideration the optgroup tags, part of the select HTML element. After playing around with it and adding a few modifications, I uploaded a new version to the codebase that has this feature:</p>
<div id="attachment_70" class="wp-caption alignnone" style="width: 525px"><img class="size-full wp-image-70" title="dropdown-check-list-groups" src="http://aleris.files.wordpress.com/2009/04/dropdown-check-list-groups.png?w=515&#038;h=330" alt="Groups in dropdown-check-list plugin" width="515" height="330" /><p class="wp-caption-text">Groups in dropdown-check-list plugin</p></div>
<p>The above image corresponds to the following html code:</p>
<pre class="brush: xml;">

    &lt;select id=&quot;s6&quot; multiple=&quot;multiple&quot;&gt;
        &lt;optgroup label=&quot;Letters&quot;&gt;
            &lt;option&gt;A&lt;/option&gt;
            &lt;option&gt;B&lt;/option&gt;
            &lt;option selected=&quot;selected&quot;&gt;C&lt;/option&gt;
        &lt;/optgroup&gt;
        &lt;optgroup label=&quot;Numbers&quot;&gt;
            &lt;option&gt;1&lt;/option&gt;
            &lt;option&gt;2&lt;/option&gt;
            &lt;option selected=&quot;selected&quot;&gt;3&lt;/option&gt;
        &lt;/optgroup&gt;
    &lt;/select&gt;
</pre>
<p>The optgroup tags of the HTML select element marked with multiple attribute are inserted in the drop down container with their own css class ui-dropdownchecklist-group. The options that are part of an optgroup get a ui-dropdownchecklist-indent css class for custom indentation.</p>
<p>The new version can be downloaded from the <a href="http://code.google.com/p/dropdown-check-list/downloads/list">google code project</a>.</p>
<p>Hope to find this new feature usefull.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=69&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/04/11/new-version-of-jquery-dropdown-checkbox-list-plugin/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>

		<media:content url="http://aleris.files.wordpress.com/2009/04/dropdown-check-list-groups.png" medium="image">
			<media:title type="html">dropdown-check-list-groups</media:title>
		</media:content>
	</item>
		<item>
		<title>It Takes All the Running You Can Do, to Keep in the Same Place</title>
		<link>http://aleris.wordpress.com/2009/04/02/it-takes-all-the-running-you-can-do-to-keep-in-the-same-place/</link>
		<comments>http://aleris.wordpress.com/2009/04/02/it-takes-all-the-running-you-can-do-to-keep-in-the-same-place/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 15:48:39 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Software development]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=61</guid>
		<description><![CDATA[Leigh Van Valen proposed the Red Queen evolutionary hypothesis  that introduced the idea that there is a constant &#8216;arms race&#8217; between co-evolving species. The term is taken from the  Lewis Carroll&#8217;s Through the Looking-Glass where Red Queen tells Alice:

it takes all the running you can do, to keep in the same place. If you want to get somewhere else, you must run at least twice as fast as that.

Van Valen found that improvement in one species will lead to improvement in the co-evolving [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=61&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Leigh Van Valen proposed the <a title="Red Queen" href="http://en.wikipedia.org/wiki/Red_Queen">Red Queen</a> evolutionary hypothesis  that introduced the idea that there is a constant &#8216;arms race&#8217; between co-evolving species. The term is taken from the  Lewis Carroll&#8217;s <a title="Through the Looking-Glass" href="http://en.wikipedia.org/wiki/Through_the_Looking-Glass">Through the Looking-Glass</a> where Red Queen tells <span style="white-space:nowrap;">Alice:</span></p>
<blockquote>
<div>it takes all the running you can do, to keep in the same place. If you want to get somewhere else, you must run at least twice as fast as that.</div>
</blockquote>
<p>Van Valen found that improvement in one species will lead to improvement in the co-evolving species because when a species develops a special ability (for example foxes running faster) it&#8217;s co-evolving species will also  improve its ability (for example, rabbits running faster).</p>
<p style="text-align:center;"><img class="aligncenter" src="http://www.rain.org/~mkummel/stumpers/11feb00a.jpg" alt="John Tenniel's classic illustration of Alice and the Red Queen running" /></p>
<p>OK, so what all that has to do with software development? It just occurred to me that there are a couple of parallels we can draw with that:</p>
<h4>Competitive frameworks are improving side by side.</h4>
<p>If a framework stops to evolve it is likely a target for extinction. It is a very visible phenomenon these days that if a framework improve a certain aspect it is borrowed by other frameworks. The same is true with programming languages.</p>
<h4>Software developers are continously improving their skills</h4>
<p>There are always new things to learn and if you stop, you will drift away. If one does not learn, the others will and he&#8217;s knowledge will sun be obsolete. You must lean every day just to stay in the same place!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/61/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/61/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/61/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=61&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/04/02/it-takes-all-the-running-you-can-do-to-keep-in-the-same-place/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>

		<media:content url="http://www.rain.org/~mkummel/stumpers/11feb00a.jpg" medium="image">
			<media:title type="html">John Tenniel's classic illustration of Alice and the Red Queen running</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Spark View Engine to ASP.NET MVC: A Step by Step Guide</title>
		<link>http://aleris.wordpress.com/2009/03/29/adding-spark-view-engine-to-aspnet-mvc-a-step-by-step-guide/</link>
		<comments>http://aleris.wordpress.com/2009/03/29/adding-spark-view-engine-to-aspnet-mvc-a-step-by-step-guide/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 10:34:09 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Spark View Engine]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=52</guid>
		<description><![CDATA[The installation of Spark view engine is not difficult but it is better to know where to start. As currently there is no official installation guide, I put up a little list to help get started:
1. Download the spark view engine release zip archive
The release zip contains all the binaries, a Visual Studio integration msi [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=52&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The installation of Spark view engine is not difficult but it is better to know where to start. As currently there is no official installation guide, I put up a little list to help get started:</p>
<p><strong>1. Download the </strong><a href="http://sparkviewengine.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24940"><strong>spark view engine release zip archive</strong></a></p>
<p style="padding-left:30px;">The release zip contains all the binaries, a Visual Studio integration msi and samples. The samples contain a lot of examples with the ASP.NET MVC framework.</p>
<p><strong>2. Install SparkVsIntegration-1.0.39890.0-release.msi from the root folder of the zip archive.</strong></p>
<p style="padding-left:30px;">The installer is a bit weird in the sense that does not say anything and closes after installation. If you do not receive any error is supposed to be correctly installed. To be  sure there are no problem with the installation, have all instances of Visual Studio closed. The VS integration of the engine is not great at the moment, be sure to check <a href="http://sparkviewengine.com/usage/intellisense">intelisense information</a> on the official site. </p>
<p><strong>3. Copy the following binary files from Spark\Bin in the extracted zip archive  to a folder in your solution (usually &#8216;Dependencies&#8217;):</strong></p>
<p style="padding-left:30px;">Spark.dll<br />
Spark.pdb<br />
Spark.Web.Mvc.dll<br />
Spark.Web.Mvc.pdb</p>
<p><strong>4. Add references in your web mvc project to Spark.dll and Spark.Web.Mvc.dll.</strong></p>
<p style="padding-left:30px;">At this point the engine is ready to use, and only needs to be configured. For example configuration, the provided samples in the zip archive are very handy.</p>
<p><strong>5. Open Global.asax.cs in the root folder of your application and add the following method:</strong></p>
<pre class="brush: csharp;">
        public static void RegisterViewEngine(ViewEngineCollection engines) {
            var settings = new SparkSettings();

            // comment this if you want to use Html helpers with the ${} syntax:
            // otherwise you would need to use the &lt;%= %&gt; syntax with anything that outputs html code
            settings.SetAutomaticEncoding(true); 

            settings
                .AddNamespace(&quot;System&quot;)
                .AddNamespace(&quot;System.Collections.Generic&quot;)
                .AddNamespace(&quot;System.Linq&quot;)
                .AddNamespace(&quot;System.Web.Mvc&quot;)
                .AddNamespace(&quot;System.Web.Mvc.Html&quot;)
                .AddNamespace(&quot;Microsoft.Web.Mvc&quot;);
                // Add here more namespaces to your model classes
                // or whatever classes you need to use in the views

            settings
                .AddAssembly(&quot;Microsoft.Web.Mvc&quot;)
                .AddAssembly(&quot;Spark.Web.Mvc&quot;)
                .AddAssembly(&quot;System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot;)
                .AddAssembly(&quot;System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot;);

            engines.Add(new SparkViewFactory(settings));
        }
</pre>
<p style="padding-left:30px;">The method is called on Application_Start to actually register the spark engine with the ASP.NET MVC view engines.</p>
<pre class="brush: csharp;">
    protected void Application_Start() {
        RegisterViewEngine(ViewEngines.Engines);
        RegisterRoutes(RouteTable.Routes);
    }
</pre>
<p><strong>and&#8230; done</strong></p>
<p>At this point the engine is configured and ready to use. The simplest way to start using it is to rename one of the aspx views into .spark file and start replacing the code with the spark syntax. The beauty is that the two engines can work with no problem side by side so there is no need to replace all the pages at once with the spark syntax!</p>
<p>For example you could rename Home/Index.aspx to Home/Index.spark and replace the content with:</p>
<pre class="brush: xml;">
&lt;h2&gt;${Html.Encode(ViewData[&quot;Message&quot;])}&lt;/h2&gt;
To learn more about ASP.NET MVC visit
&lt;a title=&quot;ASP.NET MVC Website&quot; href=&quot;http://asp.net/mvc&quot;&gt;http://asp.net/mvc&lt;/a&gt;.
</pre>
<p>To enable the <em>master pages</em> you will need to add an Application.spark file in the Views/Shared folder. To use <em>strongly typed views</em> add the following at the beginning of the .spark file:</p>
<pre class="brush: xml;">
    &lt;viewdata model=&quot;YourModelViewClass&quot;/&gt;
</pre>
<p>The samples in the spark binaries contain a lot more examples and more advanced stuff so be sure to check it out.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/52/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/52/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/52/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=52&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/03/29/adding-spark-view-engine-to-aspnet-mvc-a-step-by-step-guide/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>
	</item>
		<item>
		<title>Combining Explicit Mappings and Conventions in Fluent NHibernate</title>
		<link>http://aleris.wordpress.com/2009/03/28/combining-explicit-mappings-and-conventions-in-fluent-nhibernate/</link>
		<comments>http://aleris.wordpress.com/2009/03/28/combining-explicit-mappings-and-conventions-in-fluent-nhibernate/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 15:57:14 +0000</pubDate>
		<dc:creator>aleris</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Fluent NHibernate]]></category>

		<guid isPermaLink="false">http://aleris.wordpress.com/?p=38</guid>
		<description><![CDATA[Fluent NHibernate has got a lot of hype recently and for good reasons: the XML configuration is not the funniest part of using Hibernate. The big advantage of the framework is the ability to build up the NHibernate configuration in a type safe manner. But on top of that, the library has a number of features that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=38&subd=aleris&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a title="Fluent NHibernate Home" href="http://fluentnhibernate.org/">Fluent NHibernate</a> has got a lot of hype recently and for good reasons: the XML configuration is not the funniest part of using Hibernate. The big advantage of the framework is the ability to build up the NHibernate configuration in a type safe manner. But on top of that, the library has a number of features that greatly simplifies the initial work of configuration.</p>
<p><strong>Automapping</strong></p>
<p>The <a href="http://wiki.fluentnhibernate.org/show/AutoMapping">auto mapper mechanism</a> can automatically map all the entities in the domain based on a set of conventions. </p>
<pre class="brush: csharp;">
ISessionFactory sessionFactory =
    Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
            cs =&gt; cs.Is(&quot;connection string&quot;))
        .Mappings(m =&gt; m.AutoMappings.Add(
            AutoPersistenceModel.MapEntitiesFromAssemblyOf&lt;Location&gt;()))
        .BuildSessionFactory();
</pre>
<p>And that&#8217;s all. In this example the database is configured with SqlServer 2005 but it can be anything else of course. You get a set of of mappings based on a set of standard conventions. The auto-mapper has the possibility to override the default conventions. Unfortunately it is not always easy to both have a set of conventions and make adjustments where needed. In theory this sounds great but in practice there are always exceptions and before you know it you find yourself with a lot of weird &#8216;conventions&#8217; that are made only to resolve a particular problem. Overriding the conventions only when needed also sound great but it can become a nightmare to maintain.</p>
<p>In practice a compromise between manual mappings and limited a set of conventions might be a better approach most of the time.</p>
<p><strong>Mappings and conventions</strong></p>
<p>The compromise is to build the normal mappings but only with the non repetitive code that is better to stay in conventions. You could have:</p>
<pre class="brush: csharp;">
    public class Location {
        public virtual Guid Id { get; set; }
        public virtual string Name { get; set; }
        public virtual Country Country { get; set; }
    }

    public class LocationMapping : ClassMap&lt;Location&gt; {
        public LocationMapping() {
            Id(e =&gt; e.Id);
            Map(e =&gt; e.Name).Unique();
            References(e =&gt; e.Country).Not.LazyLoad();
        }
    }
</pre>
<p>And then have a number of conventions that are general for all the entities. For example we could have all id&#8217;s generated with the GuidComb generator:</p>
<pre class="brush: csharp;">
    public class PrimaryKeyGeneratorConvention : IIdConvention {
        public bool Accept(IIdentityPart id) {
            return true;
        }
        public void Apply(IIdentityPart id) {
            id.GeneratedBy.GuidComb();
        }
    }
</pre>
<p>And all columns that are named &#8216;Name&#8217; could have a certain storage column length:</p>
<pre class="brush: csharp;">
    public class PropertyNameLengthConvention : IPropertyConvention {
        public bool Accept(IProperty property) {
            return property.Property.Name == &quot;Name&quot;;
        }
        public void Apply(IProperty property) {
            property.WithLengthOf(255);
        }
    }
</pre>
<p>The following code will generate a configuration that reads the mappings and apply the conventions:</p>
<pre class="brush: csharp;">
ISessionFactory sessionFactory =
    Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
            cs =&gt; cs.Is(&quot;connection string&quot;))
        .Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;LocationMapping&gt;()
        .ConventionDiscovery.AddFromAssemblyOf&lt;PrimaryKeyGeneratorConvention&gt;()
        .BuildSessionFactory();
</pre>
<p>I found that is better to avoid combining the convention in the same class even if they refer to the same piece of configuration. For example would be better to just make another convention PrimaryKeyNamingConvention if the primary key should be named &#8216;Id&#8217;.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aleris.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aleris.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aleris.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aleris.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aleris.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aleris.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aleris.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aleris.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aleris.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aleris.wordpress.com/38/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aleris.wordpress.com&blog=6768394&post=38&subd=aleris&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aleris.wordpress.com/2009/03/28/combining-explicit-mappings-and-conventions-in-fluent-nhibernate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/edcfe09aed6a3c47da116cde7b715ecb?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">aleris</media:title>
		</media:content>
	</item>
	</channel>
</rss>