<?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; C#</title>
	<atom:link href="http://flanders.co.nz/category/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://flanders.co.nz</link>
	<description>thoughts.each { &#38;:propagandise }</description>
	<lastBuildDate>Sat, 03 Sep 2011 09:56:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>IronRuby just got a mocking framework &#8211; kind of</title>
		<link>http://flanders.co.nz/2009/05/14/ironruby-just-got-a-mocking-framework-kind-of/</link>
		<comments>http://flanders.co.nz/2009/05/14/ironruby-just-got-a-mocking-framework-kind-of/#comments</comments>
		<pubDate>Thu, 14 May 2009 22:31:50 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[caricature]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[CLR interop]]></category>
		<category><![CDATA[Mocking]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2009/05/14/ironruby-just-got-a-mocking-framework-kind-of/</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2009/05/14/ironruby-just-got-a-mocking-framework-kind-of/" title="IronRuby just got a mocking framework &ndash; kind of"></a>As I mentioned in a previous post.&#160; I started working on a small mocking framework. It has now progressed far enough to handle the most common mocking tasks. Below I pasted the output of the integration tests for CLR interop. &#8230;<p class="read-more"><a href="http://flanders.co.nz/2009/05/14/ironruby-just-got-a-mocking-framework-kind-of/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2009/05/14/ironruby-just-got-a-mocking-framework-kind-of/" title="IronRuby just got a mocking framework &ndash; kind of"></a><p>As I mentioned in a previous <a href="http://flanders.co.nz/2009/05/03/mocking-for-ironruby/">post</a>.&#160; I started working on a small mocking framework. It has now progressed far enough to handle the most common mocking tasks.</p>
<p>Below I pasted the output of the integration tests for CLR interop.</p>
<blockquote><p>when isolating CLR interfaces      <br />- should work without expectations       <br />- should work with an expectation with any arguments       <br />- should work with an expectation getting different method call result       <br />- should work for an assertion on a specific argument </p>
<p>when isolating CLR classes      <br />- should work without expectations       <br />- should work with an expectation for any arguments       <br />- should work with an assertion for specific arguments       <br />- should fail for an assertion with wrong arguments </p>
<p>when isolating CLR instances      <br />- should work without expectations       <br />- should work with an expectation for any arguments       <br />- should fail for an assertion for specific arguments       <br />- should allow to delegate the method call to the real instance (partial mock)</p>
</blockquote>
<p>you will need bacon installed to run the specs. you should issue the command <em>igem install bacon</em> for that.</p>
<p>you can then install the caricature gem in ironruby by issueing</p>
<p><em>igem install caricature</em></p>
<p>To use it there are some examples in the file spec/integration_spec.rb </p>
<pre name="code" class="ruby">

require 'rubygems'
require 'bacon'
require 'caricature'

ninja.when_told_to(:survive_attack_with).return(5) 

weapon.attack(ninja).should.equal 5 

ninja.was_told_to?(:survive_attack_with).with(:any).should.be.successful
</pre>
<p>There is a gotcha though, when you use it in a CLR class you&#8217;re bound to CLR rules and it only overrides the methods that are marked as virtual. We also can&#8217;t isolate static or sealed types at the moment.<br />
  </p>
<p>I took the approach of doing away with the terminology of mocking and subbing and instead chose the much clearer Isolation. By default any method returns null or the default value of a value type. You can tell an isolation to return a specific value or raise an error etc.&#160; Later on you can then assert if the method was actually called.&#160; </p>
<p>This fits in better with the way you probably structure your tests. </p>
<p>I hope you like it.</p>
<p>You can find the source in my github account.<br />
  <br /><a href="http://github.com/casualjim/caricature">http://github.com/casualjim/caricature</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2009/05/14/ironruby-just-got-a-mocking-framework-kind-of/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ninject knows a new trick</title>
		<link>http://flanders.co.nz/2009/03/15/ninject-knows-a-new-trick/</link>
		<comments>http://flanders.co.nz/2009/03/15/ninject-knows-a-new-trick/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 00:32:30 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[Ninject]]></category>
		<category><![CDATA[dlr]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2009/03/15/ninject-knows-a-new-trick/</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2009/03/15/ninject-knows-a-new-trick/" title="Ninject knows a new trick"></a>Earlier this week Nate already said that I was doing some work on Ninject, now I have it working .&#160; Everything I’m about to talk about is currently in the master tree of the ninject github repository.&#160; Getting IronRuby to &#8230;<p class="read-more"><a href="http://flanders.co.nz/2009/03/15/ninject-knows-a-new-trick/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2009/03/15/ninject-knows-a-new-trick/" title="Ninject knows a new trick"></a><p>Earlier this week Nate <a href="http://kohari.org/2009/03/13/ninject-github-crazy-delicious/" target="_blank">already said</a> that I was doing some work on <a href="http://ninject.org" target="_blank">Ninject</a>, now I have it working <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .&#160; Everything I’m about to talk about is currently in the master tree of the <a href="http://github.com/enkari/ninject" target="_blank">ninject github</a> repository.&#160; Getting <a href="http://ironruby.net" target="_blank">IronRuby</a> to play nice with <a href="http://ninject.org" target="_blank">Ninject</a> was surprisingly easy <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ,</p>
<p> <span id="more-311"></span>
<p>There was only one place that required some kind of weird workaround and from that workaround I’m entirely sure that it will go away by the time .NET 4.0 will be here.&#160; The DLR duplicates a number of delegates from .NET 4.0 but .NET 3.5 also defines them (i.e. System.Func&lt;T, TT&gt;) and then you get great exception messages like: System.Func is not of type System.Func. The solution is to not reference System.Core in your project. Except that Ninject expects the System.Core variant at some point and that was solved by aliasing the System.Core assembly and talking to the types in that assembly by their alias.</p>
<p>Anyway the juicy stuff <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  How can you take advantage of Ninjects newly found friendship with <a href="http://ironruby.net" target="_blank">IronRuby</a>. </p>
<p><a href="http://ninject.org" target="_blank">Ninject</a> now has 2 flavors of Kernels. We have a StandardKernel that knows how to deal with the module configuration system that uses a fluent interface defined in C#.&#160; And now we also have a DlrKernel that extends the StandardKernel with a RubyModuleLoader plugin. If you tell the DlrKernel to look inside a path for configuration files it will scan those folders for *.dll or *.rb files. Those files should contain the configuration for the ninject bindings.</p>
<p>So to create a Kernel that is ruby enabled you would use the following code:</p>
<pre class="code"><span style="color: #2b91af">IKernel </span>kernel = <span style="color: blue">new </span><span style="color: #2b91af">DlrKernel</span>();
kernel.AutoLoadModulesRecursively();

<span style="color: blue">var </span>samurai = kernel.Get&lt;<span style="color: #2b91af">IWarrior</span>&gt;();
System.<span style="color: #2b91af">Console</span>.WriteLine(samurai.Weapon.Name);</pre>
<pre class="code">&#160;</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The above snippet could then for example load a configuration file that has been defined like this:</p>
<pre class="code">require <span style="color: gray">File</span>.<span style="color: #8f20ff">dirname</span><span style="color: gray">(</span><span style="color: blue">__FILE__</span><span style="color: gray">) </span>+ <span style="color: #a31515">'/../Ninject.Tests.dll'
</span>include <span style="color: gray">Ninject</span>::<span style="color: gray">Tests</span>::<span style="color: gray">Fakes

</span>to_configure_ninject <span style="color: blue">do </span>|ninject|
  ninject.<span style="color: #8f20ff">bind </span><span style="color: gray">IWeapon</span>, <span style="color: #c60000">:to </span>=&gt; <span style="color: gray">Sword
  </span>ninject.<span style="color: #8f20ff">bind </span><span style="color: gray">IWarrior</span>, <span style="color: #c60000">:to </span>=&gt; <span style="color: gray">Samurai
</span><span style="color: blue">end</span></pre>
<pre class="code"><span style="color: blue"></span>&#160;</pre>
<p><a href="http://11011.net/software/vspaste"></a>The configuration above shows how most of a typical configuration would be defined by you the full configuration API at your disposal. All the options for the configuration can be specified in 2 ways. The first way is in a hash like syntax and the second way uses a more fluent syntax.</p>
<p>to_configure_ninject do |ninject|<br />
  <br />&#160; ninject.bind IServiceA, :to =&gt; ServiceA, :as =&gt; :singleton,</p>
<p>&#160;&#160;&#160; :meta =&gt; { :type =&gt; &quot;superservice&quot; },</p>
<p>&#160;&#160;&#160; :name =&gt; &quot;aaaaa&quot;,</p>
<p>&#160;&#160;&#160; :with =&gt; { </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; :parameter =&gt; { :my_param =&gt; lambda { |context| &quot;param_value&quot; } },</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; :constructor_arguments =&gt; {:const_arg =&gt; 56 },</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; :property_values =&gt; {:property_name =&gt; 94 },</p>
<p>&#160;&#160;&#160; },</p>
<p>&#160;&#160;&#160; <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> n_activation =&gt; lambda { |obj| obj.do_some_work },</p>
<p>&#160;&#160;&#160; <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> n_deativated =&gt; lambda { |obj| obj.do_some_cleanup },</p>
<p>&#160;&#160;&#160; :when =&gt; lambda { |context| &quot;a value&quot; } or</p>
<p>&#160;&#160;&#160; :when =&gt; { :injected_into =&gt; ServiceB } or</p>
<p>&#160;&#160;&#160; :when =&gt; { :target_has =&gt; AnAttribute } or</p>
<p>&#160;&#160;&#160; :when =&gt; { :member_has =&gt; AnAttribute } or</p>
<p>&#160;&#160;&#160; :when =&gt; { :class_has =&gt; AnAttribute }</p>
<p>&#160;&#160;&#160; }</p>
<p>end </p>
<p>Or </p>
<p>to_configure_ninject do |ninject|<br />
  <br />&#160; ninject.bind IServiceA, :to =&gt; ServiceA, :as =&gt; :singleton do</p>
<p>&#160;&#160;&#160; meta :type =&gt; &quot;superservice&quot; </p>
<p>&#160;&#160;&#160; name &quot;aaaaa&quot;</p>
<p>&#160;&#160;&#160; with :parameter =&gt; { :my_param =&gt; lambda { |context| &quot;param_value&quot; } }</p>
<p>&#160;&#160;&#160; with :constructor_arguments =&gt; { :const_arg =&gt; 56 }</p>
<p>&#160;&#160;&#160; with :property_values =&gt; { property_name =&gt; 94 }</p>
<p>&#160;&#160;&#160; on_activation do |obj| </p>
<p>&#160;&#160;&#160;&#160;&#160; obj.do_some_work </p>
<p>&#160;&#160;&#160; end</p>
<p>&#160;&#160;&#160; on_deativation { |obj| obj.do_some_cleanup }</p>
<p>&#160;&#160;&#160; condition do |context| </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; true</p>
<p>&#160;&#160;&#160; end or</p>
<p>&#160;&#160;&#160; condition :injected_into =&gt; SomeClass or &#8230;</p>
<p>&#160; end</p>
<p>end </p>
<p>Some of the nicer consequences of using Ruby as a configuration language is the syntax for open generics. The example below shows how to configure types with open generics.</p>
<pre class="code">require <span style="color: gray">File</span>.<span style="color: #8f20ff">dirname</span><span style="color: gray">(</span><span style="color: blue">__FILE__</span><span style="color: gray">) </span>+ <span style="color: #a31515">'/../Ninject.Tests.dll'
</span>include <span style="color: gray">Ninject</span>::<span style="color: gray">Tests</span>::<span style="color: gray">Fakes
</span>include <span style="color: gray">Ninject</span>::<span style="color: gray">Tests</span>::<span style="color: gray">Integration</span>::<span style="color: gray">StandardKernelTests

</span><span style="color: green"># IGeneric is a generic interface and GenericService is a generic type
# we don't have to specify any special notation for open generics

</span>to_configure_ninject <span style="color: blue">do </span>|ninject|
  ninject.<span style="color: #8f20ff">bind </span><span style="color: gray">IGeneric</span>, <span style="color: #c60000">:to </span>=&gt; <span style="color: gray">GenericService, <span style="color: #c60000">:as </span>=&gt; <span style="color: #c60000">:transient </span>
  </span>ninject.<span style="color: #8f20ff">bind </span><span style="color: gray">IGeneric</span>, <span style="color: #c60000">:to </span>=&gt; <span style="color: gray">GenericService2
</span><span style="color: blue">end</span></pre>
<p>To specify a condition the syntax would look like this</p>
<pre class="code">require <span style="color: gray">File</span>.<span style="color: #8f20ff">dirname</span><span style="color: gray">(</span><span style="color: blue">__FILE__</span><span style="color: gray">) </span>+ <span style="color: #a31515">'/../Ninject.Tests.dll'
</span>include <span style="color: gray">Ninject</span>::<span style="color: gray">Tests</span>::<span style="color: gray">Fakes

</span>to_configure_ninject <span style="color: blue">do </span>|ninject|
  ninject.<span style="color: #8f20ff">bind </span><span style="color: gray">IWeapon</span>, <span style="color: #c60000">:to </span>=&gt; <span style="color: gray">Shuriken </span><span style="color: blue">do
    </span>condition <span style="color: blue">do </span>|request|
        request.<span style="color: #8f20ff">target</span>.<span style="color: #8f20ff">nil? </span></pre>
<pre class="code"><span style="color: #8f20ff">             </span>? <span style="color: blue">false </span></pre>
<pre class="code"><span style="color: blue">             </span>: request.<span style="color: #8f20ff">target</span>.<span style="color: #8f20ff">member</span>.<span style="color: #8f20ff">reflected_type </span>== <span style="color: gray">Samurai</span>.<span style="color: #8f20ff">to_clr_type
      </span><span style="color: blue">end
  end
  </span>ninject.<span style="color: #8f20ff">bind </span><span style="color: gray">IWeapon</span>, <span style="color: #c60000">:to </span>=&gt; <span style="color: gray">Sword
  </span>ninject.<span style="color: #8f20ff">bind </span><span style="color: gray">IWarrior</span>, <span style="color: #c60000">:to </span>=&gt; <span style="color: gray">Samurai
</span><span style="color: blue">end</span></pre>
<p>Well that’s all. I hope you like it. I will be looking into more ways to integrate DLR stuff into <a href="http://ninject.org" target="_blank">Ninject</a> the most obvious is allowing you to inject dynamic types into static classes.</p>
<div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:386b881d-da05-4d9e-ab88-124455495508" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/IronRuby" rel="tag">IronRuby</a>,<a href="http://technorati.com/tags/Ninject" rel="tag">Ninject</a>,<a href="http://technorati.com/tags/DLR" rel="tag">DLR</a></div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2009/03/15/ninject-knows-a-new-trick/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Beating a dead horse: Stored Procedures</title>
		<link>http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/</link>
		<comments>http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 18:37:23 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[stored procedure]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/" title="Beating a dead horse: Stored Procedures"></a>I seem to be having the same conversations with the dev teams whenever I switch clients. The topic of this post is one that many people have written about before. I&#8217;m just going to put my opinion on my blog &#8230;<p class="read-more"><a href="http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/" title="Beating a dead horse: Stored Procedures"></a><p>I seem to be having the same conversations with the dev teams whenever I switch clients. The topic of this post is one that many people have written about before. I&#8217;m just going to put my opinion on my blog so I can refer people to it in the future instead of having to repeat myself every time.<br />
What prompted this post is that since I&#8217;ve moved to Belgium I&#8217;ve had to take a step back from living on the bleeding edge and using open source projects. Most of the work is concentrated in Brussels and is at big corporates or banks not exactly what you&#8217;d see as the progressive thinkers (with reason).<br />
I guess it would be safe to say that I&#8217;ve been immersed in &#8220;enterprise&#8221; development. In short I still haven&#8217;t seen anything that is more complicated than a web app like [Xero](http://www.xero.com). But perhaps more about that in another post. This one is about stored procedures and their valid uses.</p>
<p><span id="more-260"></span><br />
My current client is pretty interested in the newer technologies (anything that is out of beta) and how to put them into production.  As such they use LINQ as their data layer. They follow the classic MS guidance of data logic, business logic and &#8211; the trigger for this post &#8211; stored procedures to encapsulate all the data access.<br />
People that have worked with me in the past will be able to vouch for the fact that I feel strongly against stored procedures. But before we get to why I don&#8217;t want to use them, let&#8217;s look at some of the reasons people have given me in the past why they were using them.</p>
<p>* Performance. Because stored procedures are (pre)compiled<br />
* Security. They can lock down tables from being accessed by users directly but they can get to the database through the stored procedures layer<br />
* Maintenance. You can change a stored procedure more easily than deploying a new build of your application because no compilation is needed.<br />
* Less data to send over the wire because stored procedures can execute more sql statements at once.</p>
<p>All of that stuff sounds pretty great right? As I&#8217;ve said before my current client has developed their data layer in their framework using Linq2Sql. I think Linq2Sql is not too bad, at least it gets the corporates into an ORM mindset because it comes from MS which makes it a vastly easier technology to sell than NHibernate for example.<br />
But when you&#8217;re going to use Linq in conjunction with stored procedures for basic CRUD operations I think you&#8217;re kind of missing the whole point of Linq2Sql or ORM&#8217;s altogether for that matter. So there you have it, this is why I cannot resist posting about this subject although many people have said pretty much the same as I&#8217;m going to say in this post.</p>
<p>###Credit where credit is due<br />
The list of people below have helped me in forming my opinion on this subject. I&#8217;ve had the pleasure of having lengthy discussion on this topic with the first 3 people on the list. I consider the people on this list to be authorities in .NET development and 4 of them have written their own ORM in the past. Alex James and Andrew Peters now both work on the Entity Framework team.<br />
* [Alex James](http://blogs.msdn.com/alexj)<br />
* [Andrew Peters](http://andrewpeters.net)<br />
* [Jeremy Boyd](http://turtle.net.nz)<br />
* [Frans Bouma](http://weblogs.asp.net/fbouma)<br />
* [Ayende (Oren Eini)](http://ayende.com/Blog)<br />
* [Jeremy D. Miller](http://codebetter.com/jmiller)<br />
* [Jeff Atwood](http://codinghorror.com)</p>
<p>Let&#8217;s look at the reasons mentioned above and work our way through them seeing how they pan out in the end and you can draw your own conclusions on the matter.</p>
<p>###Performance<br />
####Stored procedures are precompiled<br />
The fact that stored procedures are precompiled and dynamic queries aren&#8217;t is a complete myth. Ever since Sql Server 7.0 the query plans are cached for both of them. If you change a parameter in a stored procedure it has to be recompiled too.You can check the Sql documentation to verify that.<br />
IMHO this also falls in the category premature optimizations. It could be that you have a query that is so complex or that is a real bottleneck for your application then it might be worth it to invest the time and write a stored procedure for it that queries the database differently and as such get rid of the bottle neck but take on a higher maintenance cost.<br />
####Batching of queries and returning multiple result sets<br />
Another argument people often bring to the table is that in a stored procedure I can issue many sql statements on the same database connection. I hate to break the news to you but you get the same benefits when you&#8217;re using dynamic sql (preferably the parameterized kind). You could issue one command that returns multiple result sets just like the body of your stored procedure. Or you could issue more than one command on the same connection and still get a very similar result.</p>
<p>###Security<br />
####Sql Injection attacks<br />
Another argument I keep hearing is the fact that when you build dynamic sql statements you open yourself up for sql injection attacks which isn&#8217;t that case for stored procedures.<br />
There is some truth in that but it definitely isn&#8217;t the whole truth. What they mean by that is that if you&#8217;re going to build your dynamic query by concatenating strings then you could indeed open yourself up to a sql injection attack but I&#8217;ve seen this happen in stored procedures too it&#8217;s just a little bit harder to do it there.<br />
However if you build your sql statement by using a parameterized query you get the same security benefits as a stored procedure would give you.</p>
<p>####Different permissions on tables and stored procedures<br />
This isn&#8217;t such a big problem. I&#8217;ve mostly seen people use one dedicated user to access the database. Lots of times there is a SOA like architecture that allows the client application to not even know what type of database it&#8217;s connecting too.  I haven&#8217;t seen many places yet where they actually implement security that is that strict.<br />
So the reasoning goes if you secure your application properly then this shouldn&#8217;t be a big problem.<br />
Ayende has a more elaborate post on the subject: [Stored Procedures for Security](http://ayende.com/Blog/archive/2006/04/05/StoredProceduresForSecurity.aspx)</p>
<p>###Maintenance<br />
This is probably a very ambiguous problem. From a development point of view this might probably be the worst argument in favor for stored procedures. However if you look at it from the POV of the enterprise it might actually hold some value.<br />
At my current client all the applications have to be distributed by a separate team, and that makes the deployment a costly scenario.<br />
That is because once your application goes into production and something small needs to change the deployment team has to go around and deploy that application again on every workstation in the company. I know about click-once but nobody has any rights to install anything on their pc which makes that pretty hard to do.<br />
Now from my POV this is the most invalid argument of all of them because of the maintenance overhead it adds.<br />
When you give stored procs to a developer they see shiny quick shortcuts to quickly get some data out and perhaps already transform some of that data in their query. That is all good the first time you have to deploy the application. But the next person needs to add a column to a table and suddenly he will have to go through all the stored procedures (at least 3 of them for the C,R and D of CRUD) to add the column. Then he has to go in the data layer of your n-tiered application and modify the entity and perhaps the methods that map to the stored procedures.  Then comes time to deploy and you forgot to modify your update script with that one column you added to a stored proc. Of course this stored proc is the one that saves one of the core entities of your application and suddenly the new release is throwing errors all over the place.<br />
I skipped the part of transforming some data. As [my previous post](http://flanders.co.nz) suggests: that stuff is business logic and doesn&#8217;t belong in a stored procedure.</p>
<p>###Some more reading on the subject<br />
* Jeff Atwood claiming that T-SQL is the assembly language of contemporary development.</p>
<p>[Who Needs Stored Procedures, Anyways?](http://www.codinghorror.com/blog/archives/000117.html)<br />
* Frans Bouma explaining his point of view:</p>
<p>[Stored procedures are bad, m'kay?](http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx)<br />
* Jeremy Miller swearing this is really going to be his last post on stored procedures:</p>
<p>[Why I do not use Stored Procedures](http://codebetter.com/blogs/jeremy.miller/archive/2006/05/25/145450.aspx)</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/10/23/beating-a-dead-horse-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>If you ever wanted to play fur elise in the console</title>
		<link>http://flanders.co.nz/2008/10/22/if-you-ever-wanted-to-play-fur-elise-in-the-console/</link>
		<comments>http://flanders.co.nz/2008/10/22/if-you-ever-wanted-to-play-fur-elise-in-the-console/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 13:08:53 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/?p=257</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2008/10/22/if-you-ever-wanted-to-play-fur-elise-in-the-console/" title="If you ever wanted to play fur elise in the console"></a>At work today we were playing around with the console.. here&#8217;s one of our experiments whilst creating a stoplight workflow (WF). private static void FurElise() { Console.Beep(420, 200); Console.Beep(400, 200); Console.Beep(420, 200); Console.Beep(400, 200); Console.Beep(420, 200); Console.Beep(315, 200); Console.Beep(370, 200); &#8230;<p class="read-more"><a href="http://flanders.co.nz/2008/10/22/if-you-ever-wanted-to-play-fur-elise-in-the-console/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2008/10/22/if-you-ever-wanted-to-play-fur-elise-in-the-console/" title="If you ever wanted to play fur elise in the console"></a><p>At work today we were playing around with the console.. here&#8217;s one of our experiments whilst creating a stoplight workflow (WF).</p>
<pre name="code" class="csharp">
private static void FurElise()
        {
            Console.Beep(420, 200);
            Console.Beep(400, 200);
            Console.Beep(420, 200);
            Console.Beep(400, 200);
            Console.Beep(420, 200);
            Console.Beep(315, 200);
            Console.Beep(370, 200);
            Console.Beep(335, 200);
            Console.Beep(282, 600);
            Console.Beep(180, 200);
            Console.Beep(215, 200);
            Console.Beep(282, 200);
            Console.Beep(315, 600);
            Console.Beep(213, 200);
            Console.Beep(262, 200);
            Console.Beep(315, 200);
            Console.Beep(335, 600);
            Console.Beep(213, 200);
            Console.Beep(420, 200);
            Console.Beep(400, 200);
            Console.Beep(420, 200);
            Console.Beep(400, 200);
            Console.Beep(420, 200);
            Console.Beep(315, 200);
            Console.Beep(370, 200);
            Console.Beep(335, 200);
            Console.Beep(282, 600);
            Console.Beep(180, 200);
            Console.Beep(215, 200);
            Console.Beep(282, 200);
            Console.Beep(315, 600);
            Console.Beep(213, 200);
            Console.Beep(330, 200);
            Console.Beep(315, 200);
            Console.Beep(282, 600);
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/10/22/if-you-ever-wanted-to-play-fur-elise-in-the-console/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Common mistakes in software development (part 2): Mixing up the tiers</title>
		<link>http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/</link>
		<comments>http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 04:10:54 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[n-tier]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/" title="Common mistakes in software development (part 2): Mixing up the tiers"></a>In my [previous post](http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/) I explained some very quick wins to make your code a little bit cleaner. As I&#8217;ve been appointed an [asp.net](http://www.asp.net) project at work at the moment I have the chance to get more ammunition for blogging &#8230;<p class="read-more"><a href="http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/" title="Common mistakes in software development (part 2): Mixing up the tiers"></a><p>In my [previous post](http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/) I explained some very quick wins to make your code a little bit cleaner. As I&#8217;ve been appointed an [asp.net](http://www.asp.net) project at work at the moment I have the chance to get more ammunition for blogging <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
This time I&#8217;d like to talk about properly separating your tiers so that the next person doesn&#8217;t have to go through the complete application and make changes everywhere just to make a minor change to the application.</p>
<p>One  of the problems; one of the most time consuming that is; I&#8217;ve seen is that people are confused on what they have to put in the data logic layer and what is business logic. In my case this is fairly extreme because there isn&#8217;t an ORM tool but rather every entity gets populated by calling a stored procedure and then in the code the graph objects get set. Whether this is a good approach for fetching your data or not is not within the scope of this blog post, but I&#8217;m guessing there are more people who are facing this type of situation.</p>
<p>Anyway let&#8217;s start with the beginning and explain the typical [n-tier architecture](http://en.wikipedia.org/wiki/N-tier) people seem to follow. This is not a particular pattern like [MVC](http://en.wikipedia.org/wiki/Model-view-controller) or [MVP](http://en.wikipedia.org/wiki/Model-view-presenter) that people are talking about so much lately. This goes back to the guidance that can be found on the [msdn website](http://msdn.microsoft.com).  This type of architecture is often used in combination with data sets but not in my example for this post. This architecture is generally divided in 3 parts that can, but don&#8217;t have to, run on different machines if needs be.  When talking about this type of architecture people mostly talk about an n-tier application.</p>
<p>##The first part is the data layer (tier).<br />
The golden rule for this one: this is the gateway between the rest of your application and the database. **NONE** of the other layers should be talking directly to the database but instead should be doing their talking through this layer.  That means if you have stored procedures you provide wrappers for them in this layer. You populate your entities in this layer too.<br />
Other functions you can perform in this layer is setting the graph members (populating relationships). IMHO if you&#8217;re talking to the database (open/close connection) you&#8217;re doing stuff that belongs in the data layer which includes populating relationships.</p>
<p>Encapsulating this logic in it&#8217;s own layer, which could potentially be walled off through only exposing it with remoting or WCF, allows you to reuse the code in different places of your applications or sharing this data access assembly with multiple applications.</p>
<p>##The second part is the business logic layer (tier).<br />
This layer encapsulates all the operations you do on entities to express the business rules. That means you would probably do most of your work in this layer. Basically **all** of the programming you will be doing for the business rules should be done here. Business logic doesn&#8217;t live in stored procedures, it doesn&#8217;t live in the UI or the data layer. Nope this layer is where it lives and nowhere else.  This statement may raise some eyebrows but only and only when you find that a certain routine is a bottleneck and it is really data intensive you can put it in a stored procedure but more on that subject in another blog post.<br />
If you find yourself transforming data so you can display it in your GUI then you&#8217;re probably expressing business rules that aren&#8217;t explicitly stated as a business rule.<br />
When you find yourself to be concatenating strings or writing logic to translate your pages in your GUI layer then you&#8217;re probably expressing business logic (business logic doesn&#8217;t have to come from business <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  in case that wasn&#8217;t clear).<br />
Another common find in business logic is validation for example because this generally expresses some kind of strict rule that comes from the business domain your application deals with. Validation is a tricky one but the rule is you should do **all** validation in your business logic. To provide a better user experience you can maybe reuse that validation on the client side. In the case of web development you probably will have to duplicate that validation in javascript if you really need it.</p>
<p>Separating these rules into their own layer allows you to reuse the methods and classes you create in the business logic layer, in different parts of your UI or even reuse it in different applications.<br />
By separating this logic it should be easier for you to do some automated testing like unit testing and/or integration testing of that code.</p>
<p>##The third and last layer (tier)<br />
This is typically the UI layer but you could easily use web/WCF services as an interface to your logic. The UI doesn&#8217;t have to be a GUI it can also be a CLI (Command-Line Interface) or something. But that is how you interact with the user or external application. The idea is that in this layer you have virtually no logic except for what&#8217;s on the screen **everything** else should be handled by your business logic. To clarify this statement: you can show/hide UI elements or add/remove elements to the UI and respond to events triggered by user actions but the data of that response and the processing really belongs in the business logic layer.</p>
<p>The UI layer can talk to both the business logic and data logic layers. If for example you&#8217;re getting a category list with just an id and name from the database chances are you won&#8217;t need to transform that data so your UI can bind directly to the entities returned by your data layer. But more complex items like an invoice for example will probably need some processing and then it should probably pass through the business logic layer.</p>
<p>This is typically a somewhat harder part of your application to provide tests for although there are some libraries out there that make it easier but still there are easier parts to test in your application.</p>
<p>So that was a quick refresher on what the classic n-tier architecture is about an how it should be structured. I hope you will agree with me into stating that its not that hard and pretty straight-forward to implement, but what I find in the &#8220;enterprise&#8221; is far from the points mentioned above.<br />
It is a bloody mix of everything everywhere, leaving me thinking -come on guys it&#8217;s not that hard-:<br />
*talking to the database =&gt; datalayer*<br />
*showing windows/adding UI elements,&#8230; =&gt; UI layer*<br />
*everything else =&gt; business logic*</p>
<p>Failing to abide by the previous simple rules will result in hell freezing over, entire plagues will be released upon the world; to cut a long story short: the world as you know it will seize to exist and turn into complete chaos.<br />
Following the rules should result in less code duplication, an instantaneously easier to maintain codebase and probably more happy successors for when you move on to the next project.  It should also give you a higher degree of code reuse.<br />
If there is one thing you should take away from this article then it should be:<br />
**Don&#8217;t mix your tiers**</p>
<p>Of course there are a couple of situations when you can diverge from the ideas presented in this post but you should always be able to justify why you break the rule. So you need a good reason to break the proposed architecture and that would probably also warrant a comment so the next guy also knows what&#8217;s going on.<br />
The most important part is to separate all non-UI logic out from the UI layer and put it in one of the lower layers.</p>
<p>Thanks for reading<br />
Ivan &#8211; writing for more maintainable software -</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/10/01/common-mistakes-in-software-development-part-2-mixing-up-the-tiers/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Common mistakes in software development</title>
		<link>http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/</link>
		<comments>http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 10:31:44 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 2.0]]></category>
		<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/?p=247</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/" title="Common mistakes in software development"></a>***** Rant Alert ****** &#60;rant&#62; At my current client I&#8217;ve got to do mainly maintenance on existing applications. This gives me the chance to look into codebases that have been created by other people and that don&#8217;t really reflect how &#8230;<p class="read-more"><a href="http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/" title="Common mistakes in software development"></a><p>***** Rant Alert ******</p>
<p>&lt;rant&gt;</p>
<p>At my current client I&#8217;ve got to do mainly maintenance on existing applications. This gives me the chance to look into codebases that have been created by other people and that don&#8217;t really reflect how I would write things. That is all good though it gives me a chance to learn new ways of doing things and when I think their way is better I&#8217;ll surely adopt.</p>
<p>Anyway when I&#8217;m browsing these codebases I do find a lot of things that could have been done better or more correctly and that&#8217;s what I&#8217;ll be writing about a little today.</p>
<p>The first one is returning bools:</p>
<p>I&#8217;ve found this in just about every project I&#8217;ve been in:</p>
<pre class="csharp" name="code">public bool IsNull(){
  if(obj == null)
    return true;
  else
    return false;
}</pre>
<p>The snippet above is a very long winded way of writing. IMHO this hurts readability and you&#8217;re saying the same thing twice. obj == null already returns a bool it makes no sense writing it again.</p>
<pre class="csharp" name="code">public bool IsNull() { return obj == null; }</pre>
<p>Another thing I keep seeing is very liberal use of try..catch blocks that catch all exceptions. Admittedly try..catch is cool but it should be used at times you are actually interested in the exception that is thrown. But it shouldn&#8217;t be used as a safeguard to swallow exceptions you don&#8217;t want to fix at this moment.  I keep seeing this code in projects:</p>
<pre class="csharp" name="code">try{
  myBLObject.FindSomething(someId).SomeMethod();
}
catch(Exception){
// Nothing to be done but error stops
}</pre>
<p>Now that can be easily written so that it won&#8217;t throw an exeption and then the try catch isn&#8217;t necessary anymore at all. Try..catch blocks most certainly have their use but throwing and catching exceptions definitely hurts performance because the system has to generate a complete stack trace etc. for every exception that is being thrown.</p>
<pre class="csharp" name="code">var result = myBLObject.FindSomething(someId);
if(result != null) result.SomeMethod();</pre>
<p>The code becomes a lot more readable, not to mention faster. I&#8217;ve seen this being used in OnRowDataBound events etc on grids with 500+ rows, removing the try catch blocks more than doubles the speed of that page.</p>
<p>The next one on the list is using if,else and switch statements. They are sometimes a cause of code bloat. To put it in the words of <a href="http://www.hanselman.com/blog/BackToBasicsLifeAfterIfForAndSwitchLikeADataStructuresReminder.aspx" target="_blank">Scott Hanselman</a>:</p>
<blockquote><p><strong>I think that using only <em>if</em>, <em>for </em>and <em>switch </em>is the Computer Programmer equivalent of using &#8220;like&#8221; in every sentence.</strong></p></blockquote>
<p>Scott does a great job explaining why they can be pretty evil so I&#8217;ll just leave you with a <a href="http://www.hanselman.com/blog/BackToBasicsLifeAfterIfForAndSwitchLikeADataStructuresReminder.aspx" target="_blank">link</a> to his post</p>
<p>I have another couple of posts in the making on this subject but I had to get this out of my system. These are also very quick wins the other things I&#8217;m going to talk about are application architecture and stored procs&#8230;.<br />
&lt;/rant&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/09/24/common-mistakes-in-software-development/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>IronNails : Rails like development for IronRuby with WPF/Silverlight</title>
		<link>http://flanders.co.nz/2008/08/07/ironnails-introduction/</link>
		<comments>http://flanders.co.nz/2008/08/07/ironnails-introduction/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 14:23:43 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ironnails]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[dlr]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2008/08/07/ironnails-introduction/</guid>
		<description><![CDATA[For my book IronRuby I'm working on chapter 4. That chapter is about doing WPF development with IronRuby. I started out with a straight port of Witty to IronRuby. As I was doing that the cogs started turning and I came up with a way to bring the rails style of development to WPF.   I decided to investigate that route a little bit further and now I have a small framework that enables you to write WPF applications with the MVC paradigm. I decided to open that code up as open source and host it on github.<p class="read-more"><a href="http://flanders.co.nz/2008/08/07/ironnails-introduction/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2008/08/07/ironnails-introduction/" title="IronNails : Rails like development for IronRuby with WPF/Silverlight"></a><p>For my book IronRuby I&#8217;m working on chapter 4. That chapter is about doing WPF development with IronRuby. I started out with a straight port of <a href="http://code.google.com/p/wittytwitter" target="_blank">Witty</a> to IronRuby. As I was doing that the cogs started turning and I came up with a way to bring the rails style of development to WPF.&#160;&#160; I decided to investigate that route a little bit further and now I have a small framework that enables you to write WPF applications with the MVC paradigm. I decided to open that code up as open source and host it on github.&#160; </p>
<p>At first I used the name Sails for my framework but it turns out there is java clone of rails that is called opensails. So to avoid confusion David M. Peterson proposed the name IronNails.</p>
<blockquote><p>On Sat, 02 Aug 2008 08:00:44 -0600, Charles Oliver Nutter wrote: </p>
<p>&#160;&#160;&#160; FYI, there&#8217;s already a framework named &quot;Sails&quot; for Java:      <br /><a href="http://www.opensails.org/">http://www.opensails.org/</a></p>
<p>For the sake of sticking to the &quot;Iron&quot; theme, why not replace the &#8216;S&#8217; with an &#8216;N&#8217; and go with IronNails. <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> &#160; Maybed it&#8217;s just me, but if given the choice, I&#8217;d much rather nail it than sail it any day of the week. <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  </p>
<p>&#8211;      <br />/M:D </p>
<p>M. David Peterson</p>
</blockquote>
<p>You can find the project here: <a href="http://github.com/casualjim/ironnails">http://github.com/casualjim/ironnails</a></p>
<p>At this moment it&#8217;s definitely not finished at all, but it does work. The remainder of the week I&#8217;ll move my previous demo code onto this framework, update the code samples in my chapter and finish the content. I hope I will have all of this done by the end of next week.</p>
<p>Back to the IronNails project:</p>
<p>Because DLR objects cannot be used to bind to in WPF you have to define a skeleton of the ViewModel in C#, but this will change in the future. When that changes I&#8217;ll look at extending the framework to make use of some other WPF patterns like defining a DependencyObject and Behaviors. Once those are defined you get a very clean separation between design and behavior.</p>
<p>This is abstracted away from you but in the background the framework works with the View &#8211; ViewModel &#8211; Model &#8211; Controller pattern although I&#8217;ve tried to keep your exposure to the view model to a minimum. The framework follows naming conventions per language. So in C# and XAML you camel case stuff and in IronRuby you underscore stuff.</p>
<p>The very core of the framework is defined in C# but most of the code is IronRuby, depending on how hard it will be after the DLR RTM&#8217;s I may look at adding support for all the DLR languages.</p>
<blockquote><p>IronNails      <br />========= </p>
<p>IronNails is a framework inspired by the Rails and rucola frameworks. It offers a rails-like way of developing      <br />applications with IronRuby and Windows Presentation Foundation (WPF).       <br />This framework uses the pattern Model &#8211; ViewModel &#8211; View &#8211; Controller (M-VM-V-C). It should be able to run on both WPF       <br />and Silverlight.       <br />The idea is that the views can be created using a design tool like Blend for example and just save that xaml as is. The       <br />designer should not need to use anything else than drag and drop to create a GUI design. The behaviors are then added to       <br />the view by using predefined behaviors in the framework or by defining your own behavior.       <br />The framework then generates a proxy for the view which will be used to transparently wire up the commands in the       <br />behaviors to controller actions. </p>
</blockquote>
<p>You are now able to write the following code for a controller: </p>
<pre class="ruby" name="code">class MyController &lt; IronNails::Controller::Base

  view_action :show_message, :triggers =&gt; :my_button do
    MessageBox.show &quot;This is the great message from a block&quot;
  end

  view_action :change_color, :triggers =&gt; { :element =&gt; :my_text_block, :event =&gt; :mouse_enter }
  view_action :reset_color, :triggers =&gt; { :element =&gt; :my_text_block, :event =&gt; :mouse_leave } do |view|
    view.my_text_block.foreground = :black.to_brush
  end

  view_object :people, Person.find_all

  def change_color(view)
    view.my_text_block.foreground = :red.to_brush
  end

end</pre>
<p></p>
<p>At this moment the project has 0 unit tests, it has below minimal documentation and it still needs a work like defining the behaviors. I have to move on with my book but intend to continue developing this framework after my book is finished and IronRuby RTM&#8217;s.&#160; There are some more workarounds in the project that will all disappear as IronRuby progresses.</p>
<div><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fflanders.co.nz%2f2008%2f08%2f07%2fironnails-introduction%2f"><img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fflanders.co.nz%2f2008%2f08%2f07%2fironnails-introduction%2f" border="0" /></a> </div>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b145efcd-14b0-4d36-9aa2-efed49897e0d" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/IronRuby" rel="tag">IronRuby</a>,<a href="http://technorati.com/tags/IronRubyInAction" rel="tag">IronRubyInAction</a>,<a href="http://technorati.com/tags/IronNails" rel="tag">IronNails</a>,<a href="http://technorati.com/tags/WPF" rel="tag">WPF</a></div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/08/07/ironnails-introduction/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dynamic Script Control</title>
		<link>http://flanders.co.nz/2008/06/12/dynamic-script-control/</link>
		<comments>http://flanders.co.nz/2008/06/12/dynamic-script-control/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 05:13:42 +0000</pubDate>
		<dc:creator>Ivan Porto Carrero</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[IronRuby]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://flanders.co.nz/2008/06/12/dynamic-script-control/</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2008/06/12/dynamic-script-control/" title="Dynamic Script Control"></a>Both Silverlight and WPF use XAML markup to describe their user interface.&#160; As I&#8217;m currently writing my chapter on WPF for my book IronRuby In Action and I want to use some xaml that has been generated before for a &#8230;<p class="read-more"><a href="http://flanders.co.nz/2008/06/12/dynamic-script-control/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2008/06/12/dynamic-script-control/" title="Dynamic Script Control"></a><p>Both Silverlight and WPF use XAML markup to describe their user interface.&#160; As I&#8217;m currently writing my chapter on WPF for my book IronRuby In Action and I want to use some xaml that has been generated before for a different project but with an IronRuby class to load the xaml I&#8217;m in trouble. This is because you can declare assembly references in the xml namespace declarations so you can use the types in that assembly from xaml.&#160; </p>
<p>The DLR based languages don&#8217;t compile into static assemblies and this means that you can&#8217;t use those xml namespace definitons to reference your assemblies.&#160; I wrote a fairly trivial control that acts like a hook for DLR based controls in the XAML tree.</p>
<p>You can check it out at codeplex.    <br /><a href="http://codeplex.com/dynamicscriptcontrol" target="_blank">http://codeplex.com/dynamicscriptcontrol</a></p>
<p>The idea behind this control is that you can &quot;hook&quot; your DLR based control into the visual tree by setting some properties.&#160; You can set properties on the DLR based control by setting the Attributes property on the DynamicScriptControl</p>
<p>Let&#8217;s look at a quick example:</p>
<p>1. The ruby file defining a custom TextBox. But you can do whatever&#160; you want in that ruby file of course.</p>
<p><a href="http://flanders.co.nz/wp-content/uploads/2008/06/dynamic-script-control-rubyscript.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="120" alt="dynamic_script_control_rubyscript" src="http://flanders.co.nz/wp-content/uploads/2008/06/dynamic-script-control-rubyscript-thumb.png" width="327" border="0" /></a> </p>
<p>All this textbox does is preset it&#8217;s text property to &quot;I&#8217;m prefilled&quot; </p>
<p>2. The xaml for the window</p>
<p><a href="http://flanders.co.nz/wp-content/uploads/2008/06/dynamic-script-control-window-xaml.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="376" alt="dynamic_script_control_window_xaml" src="http://flanders.co.nz/wp-content/uploads/2008/06/dynamic-script-control-window-xaml-thumb.png" width="717" border="0" /></a>&#160;</p>
<p>You first declare a namespace for the assembly that has the DynamicScriptControl. Next I have a StackPanel that contains 2 DynamicScriptControls. The first just contains the 2 mandatory properties. We need to know which class you want to instantiate in the file you provide by setting the ScriptFile property. This script file property is a path to your ruby file in my case prefilled_text_box.rb.    <br />The second DynamicScriptControl is one where I want to initialize the control with my own text property. To declare those properties you have to add them to the Attributes collection of the DynamicScriptControl. At this moment it&#8217;s not smart enough to know which datatype you give it so you can specify a format string which was necessary in this case because text is a string.</p>
<p>3. The result</p>
<p><a href="http://flanders.co.nz/wp-content/uploads/2008/06/dynamic-script-control-window.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="309" alt="dynamic_script_control_window" src="http://flanders.co.nz/wp-content/uploads/2008/06/dynamic-script-control-window-thumb.png" width="305" border="0" /></a> </p>
<p>Michael Foord the author of IronPython In Action will provide the python integration in this control. </p>
<p>There was a release of the Dynamic Silverlight SDK earlier this week which contained the necessary source code files to compile a common DLR for both IronRuby and IronPython.&#160; That is what makes it possible to support multiple scripting languages from the start.&#160; </p>
<p>I&#8217;ve hosted the source code on google and you can find that at:</p>
<p><a title="The google code project" href="http://code.google.com/p/dynamic-script-control" target="_blank">http://code.google.com/p/dynamic-script-control</a></p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:4015ed95-7a36-4820-ac0b-6344a61307ee" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/ironruby" rel="tag">ironruby</a>,<a href="http://technorati.com/tags/WPF" rel="tag">WPF</a>,<a href="http://technorati.com/tags/DLR" rel="tag">DLR</a>,<a href="http://technorati.com/tags/ironpython" rel="tag">ironpython</a>,<a href="http://technorati.com/tags/Silverlight" rel="tag">Silverlight</a></div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/06/12/dynamic-script-control/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Consuming YouTube using XLinq</title>
		<link>http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/</link>
		<comments>http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 02:28:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2008/02/27/consuming-youtube-using-xlinq/</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/" title="Consuming YouTube using XLinq"></a>I had to implement an integration with youtube for a client yesterday. Google provides API&#8217;s but they are for Java and PHP. I&#8217;m using C# for this project. So I decided to use XLinq to fetch the feeds and parse &#8230;<p class="read-more"><a href="http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/" title="Consuming YouTube using XLinq"></a><p>I had to implement an integration with youtube for a client yesterday. Google provides API&#8217;s but they are for Java and PHP. I&#8217;m using C# for this project. So I decided to use XLinq to fetch the feeds and parse them into classes for what I needed. </p>
<p>I only need titles, movies and a thumbnail for each item. So I haven&#8217;t implemented all of the properties. And I am impressed. From having no exposure to XLinq whatsoever to having it parse feeds and being able to use those feeds in my monorail application took me about an hour. Since this is the very first time I use XLinq I imagine there is room for improvement, please tell me so when I&#8217;m wrong.</p>
<p>The classes I show here can be used as follows:    </p>
<pre class="csharp" name="code">YouTubePlayList.LoadForUser("<<username>>").ForEach(pl => Response.Write("<span style="color: blue">" + pl.Id + "</span>"));

var url = http://gdata.youtube.com/feeds/api/playlists/<
<playlistid>;
YouTubeCollection.LoadFrom(url).ForEach(yt => Response.Write(yt.Title + ", " + yt.MovieUrl + ""));</pre>
</p>
<pre class="csharp" name="code">
public class YouTubeCollection : List<YouTubeItem>
    {
        public YouTubeCollection()
        {
        }

        public YouTubeCollection(IEnumerable<YouTubeItem> collection)
            : base(collection)
        {
        }

        public static YouTubeCollection LoadFrom(string uri)
        {
            var feed = XElement.Load(uri);

            XNamespace ns = "http://www.w3.org/2005/Atom";
            XNamespace media = "http://search.yahoo.com/mrss/";

            var list = new YouTubeCollection(from item in feed.Elements(ns + "entry").Elements(media + "group")
                        select new YouTubeItem
                        {
                            Title = item.Element(media + "title").Value,
                            MovieUrl = (from el in item.Elements(media + "content")
                                     where el.Attribute("type").Value == "application/x-shockwave-flash"
                                     select el.Attribute("url").Value).First(),
                             ThumbnailUrl = (from el in item.Elements(media + "thumbnail")
                                             select el.Attribute("url").Value).First()
                        });

            return list;
        }

    }

    public class YouTubePlayList : List<YouTubePlayListItem>
    {
        public YouTubePlayList()
        {
        }

        public YouTubePlayList(IEnumerable<YouTubePlayListItem> collection) : base(collection)
        {
        }

        public static YouTubePlayList LoadForUser(string user)
        {
            var url = string.Format("http://gdata.youtube.com/feeds/api/users/{0}/playlists", user);

            var feed = XElement.Load(url);

            XNamespace ns = "http://www.w3.org/2005/Atom";
            XNamespace gd = "http://schemas.google.com/g/2005";

            var list = new YouTubePlayList(from item in feed.Elements(ns + "entry")
                                           select new YouTubePlayListItem
                                             {
                                                 Name = item.Element(ns + "title").Value,
                                                 Id = item.Element(gd + "feedLink").Attribute("href").Value
                                             });

            return list;
        }
    }

    [DataContract]
    public class YouTubePlayListItem
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string Id { get; set; }
    }

    [DataContract]
    public class YouTubeItem
    {
        private string _id;
        [DataMember]
        public string Id
        {
            get
            {
                return MovieUrl.Split('/').Last();
            }
            set
            {
                _id = value;
            }
        }

        [DataMember]
        public string Title { get; set; }

        [DataMember]
        public string MovieUrl { get; set; }

        [DataMember]
        public string ThumbnailUrl { get; set; }
    }</pre>
<p> </p>
</p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:146f067f-4d66-4d0d-af7b-b18e191829ef" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/XLinq" rel="tag">XLinq</a>,<a href="http://technorati.com/tags/youtube" rel="tag">youtube</a></div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2008/02/27/consuming-youtube-using-xlinq/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New view engines in the MvcContrib project for asp.net mvc</title>
		<link>http://flanders.co.nz/2007/12/26/new-view-engines-in-the-mvccontrib-project-for-aspnet-mvc/</link>
		<comments>http://flanders.co.nz/2007/12/26/new-view-engines-in-the-mvccontrib-project-for-aspnet-mvc/#comments</comments>
		<pubDate>Wed, 26 Dec 2007 05:47:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.koolkraft.net/2007/12/26/new-view-engines-in-the-mvccontrib-project-for-aspnet-mvc/</guid>
		<description><![CDATA[<a href="http://flanders.co.nz/2007/12/26/new-view-engines-in-the-mvccontrib-project-for-aspnet-mvc/" title="New view engines in the MvcContrib project for asp.net mvc"></a>When I got back from visiting my parents over the christmas holiday I checked the MvcContrib project to find out that both Andrew Peter&#8217;s NHAML view engine and my XSLT view engine have been accepted in the trunk of those &#8230;<p class="read-more"><a href="http://flanders.co.nz/2007/12/26/new-view-engines-in-the-mvccontrib-project-for-aspnet-mvc/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://flanders.co.nz/2007/12/26/new-view-engines-in-the-mvccontrib-project-for-aspnet-mvc/" title="New view engines in the MvcContrib project for asp.net mvc"></a><p>When I got back from visiting my parents over the christmas holiday I checked the <a href="http://www.codeplex.com/MVCContrib">MvcContrib</a> project to find out that both Andrew Peter&#8217;s <a href="http://andrewpeters.net/2007/12/19/introducing-nhaml-an-aspnet-mvc-view-engine/">NHAML view engine</a> and my <a href="http://flanders.co.nz/blog/archive/2007/12/15/xsltviewengine-patch-submitted.aspx">XSLT view engine</a> have been accepted in the trunk of those projects.</p>
<p>What&#8217;s left to do for me is provide a sample site that shows usage of the view engine.  This has been a very rewarding experience so far <img src='http://flanders.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I found out about IViewSourceLoader to get the path to the current view file for example.</p>
<p>I also learnt a new trick to increase my test coverage and be able to test the content of the rendered view. </p>
<p>To get the mvc contrib project you can either download it from the <a href="http://www.codeplex.com/MVCContrib/Release/ProjectReleases.aspx">releases section</a> on the codeplex site.</p>
<p>Or you can check out the source code and build it yourself from the <a href="http://mvccontrib.googlecode.com/svn/trunk">subversion repository</a></p>
</p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:516204c8-d219-44cf-8431-a703dba87893" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">del.icio.us Tags: <a href="http://del.icio.us/popular/aspnetmvc" rel="tag">aspnetmvc</a>,<a href="http://del.icio.us/popular/mvccontrib" rel="tag">mvccontrib</a></div>
<p> 
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e4d9ec6e-3113-4a8a-a0ec-7e746d138e66" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/aspnetmvc" rel="tag">aspnetmvc</a></div>
</p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:4e8051a5-2cbe-4c08-b865-8f4340ad2f02" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><!--dotnetkickit--></div>
]]></content:encoded>
			<wfw:commentRss>http://flanders.co.nz/2007/12/26/new-view-engines-in-the-mvccontrib-project-for-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

