<?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" >

<channel>
	<title>Even the wrong words seem to rhyme &#187; c#</title>
	<atom:link href="http://www.kevinblake.co.uk/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kevinblake.co.uk</link>
	<description>a blog-life by Kevin Blake</description>
	<lastBuildDate>Thu, 13 May 2010 22:27:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>C# Joins with Linq and Lambdas</title>
		<link>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/</link>
		<comments>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 12:16:14 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=647</guid>
		<description><![CDATA[I&#8217;m always forgetting the syntax for lambda joins in C#, because I never use them enough and get bored looking for reminders enough that I just revert back my old ways and use the query expression instead. So rather than find a good tutorial and bookmark it, I&#8217;ll post it here instead. By the time [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m always forgetting the syntax for lambda joins in C#, because I never use them enough and get bored looking for reminders enough that I just revert back my old ways and use the query expression instead.  So rather than find a good tutorial and bookmark it, I&#8217;ll post it here instead.  By the time it falls off the front page, I&#8217;ll just about have remembered how to do it without needing this anyway <img src='http://www.kevinblake.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Query Syntax</strong></p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">var products <span class="sy0">=</span> from audio <span class="kw1">in</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span>
join product <span class="kw1">in</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span> on audio.<span class="me1">ProductId</span> equals product.<span class="me1">ProductId</span>
select <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> <span class="br0">&#123;</span> Product <span class="sy0">=</span> product, Audio <span class="sy0">=</span> audio <span class="br0">&#125;</span><span class="sy0">;</span></pre></div></div>
<p><strong>Lambda Syntax</strong></p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">var products <span class="sy0">=</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span>.<span class="me1">Join</span><span class="br0">&#40;</span>
                DbContext.<span class="me1">DataContext</span>.<span class="me1">Products</span>,
                audio <span class="sy0">=&gt;</span> audio.<span class="me1">ProductId</span>,
                product <span class="sy0">=&gt;</span> product.<span class="me1">ProductId</span>,
                <span class="br0">&#40;</span>audio, product<span class="br0">&#41;</span> <span class="sy0">=&gt;</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> <span class="br0">&#123;</span> Product <span class="sy0">=</span> product, Audio <span class="sy0">=</span> audio <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>It might look like more code because of my formatting, but I find the lambda syntax much convenient when chaining queries together with other where&#8217;s and groupby&#8217;s, especially when that might be split across different methods.  It also isolates your join nicely, whereas I find the query syntax will start to get particularly unreadable with more complex queries.</p>
<p>Last but not least, another piece of linq-join-related syntax I&#8217;m finding myself always having to look up a lot is for left outer joins.  Fortunately I always end up at MSDN for that one, so I&#8217;ll just link to it here:<br />
<a href="http://msdn.microsoft.com/en-us/library/bb397895.aspx">How to: Perform Left Outer Joins</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running Ruby methods within C# / .NET</title>
		<link>http://www.kevinblake.co.uk/running-ruby-methods-within-c-net/631/</link>
		<comments>http://www.kevinblake.co.uk/running-ruby-methods-within-c-net/631/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 21:16:04 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=631</guid>
		<description><![CDATA[The last example might have been a little too trivial, even by my standards. Even I struggled to imagine a scenario where I might ever need to use it. So hopefully this one will be a little bit more interesting and demonstrate something more useful. Useful, but still just as simple as the previous examples, [...]]]></description>
			<content:encoded><![CDATA[<p>The last example might have been a little too trivial, even by my standards.  Even I struggled to imagine a scenario where I might ever need to use it.  So hopefully this one will be a little bit more interesting and demonstrate something more useful.</p>
<p>Useful, but still just as simple as the previous examples, that is.  Again &#8211; you&#8217;ll need your references from the downloaded IronRuby bin/ folder.  And as you&#8217;ve come to expect, a very simple ruby script defining a lambda function.</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="ruby" style="font-family:monospace;"><span class="re0">$m</span> = <span class="kw3">lambda</span> <span class="br0">&#123;</span>
            a = <span class="kw3">Array</span>.<span class="me1">new</span>
            a.<span class="me1">push</span><span class="br0">&#40;</span>2, 3<span class="br0">&#41;</span>
            <span class="br0">&#40;</span>4..50<span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span>
               <span class="sy0">|</span>i<span class="sy0">|</span>
               <span class="br0">&#40;</span>2..<span class="br0">&#40;</span><span class="kw4">Math</span>.<span class="me1">sqrt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">ceil</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span>
                  <span class="sy0">|</span>thing<span class="sy0">|</span>
                  <span class="kw1">if</span> <span class="br0">&#40;</span>i.<span class="me1">divmod</span><span class="br0">&#40;</span>thing<span class="br0">&#41;</span><span class="br0">&#91;</span>1<span class="br0">&#93;</span> == 0<span class="br0">&#41;</span>
                     a.<span class="me1">push</span> i
                     <span class="kw1">break</span>
                  <span class="kw1">end</span>
               <span class="kw1">end</span>
            <span class="kw1">end</span>
            <span class="kw2">return</span> a
         <span class="br0">&#125;</span></pre></div></div>
<p>From this, we&#8217;ll get an array of the prime numbers.  The function can then be executed rather nicely from within your .NET code like this:</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="pascal" style="font-family:monospace;"><span class="kw1">var</span> ruby <span class="sy0">=</span> Ruby.<span class="me1">GetEngine</span><span class="br0">&#40;</span>Ruby.<span class="me1">CreateRuntime</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
ruby.<span class="me1">Execute</span><span class="br0">&#40;</span>@<span class="st0">&quot;
    $m = lambda {
//.. snip..
            return a
         }
&quot;</span><span class="br0">&#41;</span>;
<span class="kw1">var</span> rubyContext <span class="sy0">=</span> Ruby.<span class="me1">GetExecutionContext</span><span class="br0">&#40;</span>ruby<span class="br0">&#41;</span>;
<span class="kw1">var</span> m <span class="sy0">=</span> <span class="br0">&#40;</span>Proc<span class="br0">&#41;</span>rubyContext.<span class="me1">GetGlobalVariable</span><span class="br0">&#40;</span><span class="st0">&quot;m&quot;</span><span class="br0">&#41;</span>;
<span class="kw1">var</span> rubyArray <span class="sy0">=</span> <span class="br0">&#40;</span>RubyArray<span class="br0">&#41;</span> m.<span class="me1">Call</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
foreach <span class="br0">&#40;</span><span class="kw1">var</span> o <span class="kw1">in</span> rubyArray<span class="br0">&#41;</span>
<span class="coMULTI">{
    Console.Write(string.Format(&quot;{0}</span><span class="sy0">,</span><span class="st0">&quot;, o));
}</span></pre></div></div>
<p>Now we&#8217;re really starting to leverage that syntactical beauty of ruby within .NET and jumping (almost) seamlessly between the two.  Now, I really should do some demos on something more useful than prime numbers, and perhaps get into one of the big areas of interest of Ruby &#8211; testing frameworks.  Not tonight though <img src='http://www.kevinblake.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Demo project available as usual:</p>
<ul>
<li><a href="http://www.kevinblake.co.uk/wp-content/uploads/2009/07/csharp-execute-ironruby-methods.zip">Download C# IronRuby Method Wrapper</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/running-ruby-methods-within-c-net/631/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Executing complete (Iron)Ruby scripts from within native C# / .NET</title>
		<link>http://www.kevinblake.co.uk/executing-complete-ironruby-scripts-from-within-native-c-net/624/</link>
		<comments>http://www.kevinblake.co.uk/executing-complete-ironruby-scripts-from-within-native-c-net/624/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 20:26:15 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=624</guid>
		<description><![CDATA[Running Ruby code as-is within .NET is almost too simple to even write home about. In fact I almost didn&#8217;t, but after I wrote it the solution stared up at me with its big brown eyes, and I couldn&#8217;t resist. I&#8217;m not totally sure when I&#8217;d ever need to use this, but perhaps taking some [...]]]></description>
			<content:encoded><![CDATA[<p>Running Ruby code as-is within .NET is almost too simple to even write home about.  In fact I almost didn&#8217;t, but after I wrote it the solution stared up at me with its big brown eyes, and I couldn&#8217;t resist.  I&#8217;m not totally sure when I&#8217;d ever need to use this, but perhaps taking some legacy Ruby scripts where I don&#8217;t really care about the results, and still want to run them amongst some other .NET tasks.  It might come up in some obscure unit testing one day.  You never know.</p>
<p>So, this still serves as an example of how simple it can be to run ruby scripts within .NET.  We&#8217;ll get to making use of some return values, and running individual methods in the next post.</p>
<p>Following on from the last example, the following ruby script prints all the prime numbers between 1 and 50.</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="ruby" style="font-family:monospace;">state = <span class="kw4">Numeric</span>.<span class="me1">new</span>
<span class="kw3">print</span> <span class="st0">&quot;2,3,&quot;</span>
<span class="br0">&#40;</span>4..50<span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span>
   <span class="sy0">|</span>i<span class="sy0">|</span>
   <span class="br0">&#40;</span>2..<span class="br0">&#40;</span><span class="kw4">Math</span>.<span class="me1">sqrt</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span>.<span class="me1">ceil</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span>
      <span class="sy0">|</span>thing<span class="sy0">|</span>
      state = 1
      <span class="kw1">if</span> <span class="br0">&#40;</span>i.<span class="me1">divmod</span><span class="br0">&#40;</span>thing<span class="br0">&#41;</span><span class="br0">&#91;</span>1<span class="br0">&#93;</span> == 0<span class="br0">&#41;</span>
         state = 0
         <span class="kw1">break</span>
      <span class="kw1">end</span>
   <span class="kw1">end</span>
   <span class="kw3">print</span> <span class="st0">&quot;#{i}<span class="es0">\,</span>&quot;</span> <span class="kw1">unless</span> <span class="br0">&#40;</span>state == 0<span class="br0">&#41;</span>
<span class="kw1">end</span></pre></div></div>
<p>With the ruby script complete (you can also run this with the ir.exe that ships with IronRuby if you like)&#8230; Next start up a new project within Visual Studio, and add some references from your downloaded IronRuby bin folder (IronRuby.dll, IronRuby.Libraries.dll etc&#8230;).</p>
<p>You only need a few lines of code to execute your ruby script.</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="kw1">using</span> <span class="co3">IronRuby</span><span class="sy0">;</span>
<span class="co1">// ..</span>
var runtime <span class="sy0">=</span> Ruby.<span class="me1">CreateRuntime</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
runtime.<span class="me1">ExecuteFile</span><span class="br0">&#40;</span><span class="st_h">@&quot;ruby/run.rb&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>As before, you can download the full example to check it and run for yourself.  And also as before, you will also need <a href="http://www.ironruby.net/Download" target="_blank">IronRuby.<br />
</a></p>
<ul>
<li><a href='http://www.kevinblake.co.uk/wp-content/uploads/2009/07/ruby-execute-full-script-within-csharp-demo.zip'>Download C# IronRuby Wrapper</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/executing-complete-ironruby-scripts-from-within-native-c-net/624/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using C# / .NET libraries within IronRuby</title>
		<link>http://www.kevinblake.co.uk/using-c-net-libraries-within-ironruby/602/</link>
		<comments>http://www.kevinblake.co.uk/using-c-net-libraries-within-ironruby/602/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 09:34:10 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[vistasquad]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=602</guid>
		<description><![CDATA[I attended my first VistaSquad meeting on Wednesday. Part of the evening was a very interesting talk from @ben_hall on IronRuby, which among many other things included how to use any .NET CLR libraries direct from your IronRuby script (running via the .NET DLR). Whilst my example below is extremely trivial, it shows how you [...]]]></description>
			<content:encoded><![CDATA[<p>I attended my first <a href="http://vistasquad.co.uk/" target="_blank">VistaSquad</a> meeting on Wednesday.  Part of the evening was a very interesting talk from <a href="http://www.twitter.com/ben_hall">@ben_hall</a> on IronRuby, which among many other things included how to use any .NET CLR libraries direct from your IronRuby script (running via the .NET DLR).</p>
<p>Whilst my example below is extremely trivial, it shows how you might make use of any existing libraries within your Ruby scripts.  This same technique applies to any .NET libraries, whether they&#8217;re custom, part of the framework, or created by your gran.  I don&#8217;t think I really need to sell it in &#8211; but I love the flexibility that this provides.</p>
<p>So to get to the example, this simple piece of C# displays all the prime numbers between 0 and maxNumber:</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw4">int</span><span class="br0">&#91;</span><span class="br0">&#93;</span> DisplayPrimeNumbers<span class="br0">&#40;</span><span class="kw4">int</span> maxNumber<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    <span class="kw4">int</span> max <span class="sy0">=</span> maxNumber<span class="sy0">;</span>
    List previousPrimes <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> List<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    previousPrimes.<span class="me1">Add</span><span class="br0">&#40;</span>2<span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">&#40;</span>max <span class="sy0">&lt;</span> 2<span class="br0">&#41;</span> <span class="kw1">return</span> null<span class="sy0">;</span> <span class="co1">// none</span>
    <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">3</span><span class="sy0">;</span> i  maxDivisor<span class="br0">&#41;</span> break<span class="sy0">;</span>
            <span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>i <span class="sy0">%</span> previousPrimes<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="sy0">==</span> 0<span class="br0">&#41;</span>
            <span class="br0">&#123;</span>
                foundDivisor <span class="sy0">=</span> true<span class="sy0">;</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>foundDivisor<span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            previousPrimes.<span class="me1">Add</span><span class="br0">&#40;</span>i<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
    <span class="kw1">return</span> previousPrimes.<span class="me1">ToArray</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>We can build that up into a class library and using IronRuby, manipulate the return of the method the same as though we had been running native ruby.</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="ruby" style="font-family:monospace;"><span class="kw3">require</span> <span class="st0">'mscorlib'</span>
<span class="kw3">require</span> <span class="st0">'CSharpLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'</span>;
prime_numbers = <span class="re2">CSharpLib::PrimeNumbers</span>.<span class="me1">new</span>
<span class="br0">&#40;</span>prime_numbers.<span class="me1">DisplayPrimeNumbers</span> 20<span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span> <span class="sy0">|</span>num<span class="sy0">|</span>
	<span class="kw3">puts</span> num
<span class="kw1">end</span></pre></div></div>
<p>You can download the full sample below, a C# console app is also included for completeness (although isn&#8217;t a part of the IronRuby process).  You will of course, need to <a href="http://www.ironruby.net/Download">download IronRuby</a> first, and add the installed bin/ folder to your path.  Then just change to the <em>&lt;sample&gt;</em>/ruby/ directory, and run it with:</p>
<p><code>ir run.rb</code></p>
<ul>
<li><a href='http://www.kevinblake.co.uk/wp-content/uploads/2009/07/primenumber-ruby-csharp.zip'>Download IronRuby / C# prime number sample</a></li>
</ul>
<p>It&#8217;s probably worth noting that IronRuby is still a way off from a 1.0 release, but it&#8217;s already very usable and looking rather cool.  Since it&#8217;s on <a href="http://www.kevinblake.co.uk/todo/594/">my recent //TODO list</a>, I&#8217;ll be doing a few more examples here &#8211; next time turning this one its head and executing your ruby scripts from within C#.  In the meantime, you can check out <a href="http://www.slideshare.net/BenHalluk/ironruby" target="_blank">Ben&#8217;s set of slides</a> from Wednesday on Slideshare.</int></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/using-c-net-libraries-within-ironruby/602/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gallery2 remote API C# wrapper</title>
		<link>http://www.kevinblake.co.uk/gallery2-remote-api-c-wrapper/586/</link>
		<comments>http://www.kevinblake.co.uk/gallery2-remote-api-c-wrapper/586/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 17:59:22 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[gallery2]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=586</guid>
		<description><![CDATA[I stumbled across the Gallery.NET Toolkit on Twitter, while I should have been doing something more useful; some great work from @rmaclean (thanks for sharing / codeplexing  it). The API wraps up a lot of the Gallery2 remote services into some easy to use C# functions. Hopefully I&#8217;ll find an excuse to use this one day.]]></description>
			<content:encoded><![CDATA[<p>I stumbled across the <a href="http://gallery2.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29252" target="_blank">Gallery.NET Toolkit</a> on Twitter, while I should have been doing something more useful; some great work from <a href="http://www.twitter.com/rmaclean" target="_blank">@rmaclean</a> (thanks for sharing / codeplexing  it).</p>
<p>The API wraps up a lot of the Gallery2 remote services into some easy to use C# functions.</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">Actions a <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> SADev.<span class="me1">Gallery2</span>.<span class="me1">Protocol</span>.<span class="me1">Actions</span><span class="br0">&#40;</span><span class="st0">&quot;http://www.blakepics.com&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw4">string</span> authToken <span class="sy0">=</span> a.<span class="me1">Login</span><span class="br0">&#40;</span><span class="st0">&quot;*************&quot;</span>, <span class="st0">&quot;*************&quot;</span><span class="br0">&#41;</span>.<span class="me1">AuthToken</span><span class="sy0">;</span>
a.<span class="me1">FetchAlbums</span><span class="br0">&#40;</span>authToken<span class="br0">&#41;</span>.<span class="me1">Albums</span>.<span class="kw1">ForEach</span><span class="br0">&#40;</span>
    album <span class="sy0">=&gt;</span>
    <span class="br0">&#123;</span>
        Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>album.<span class="me1">Title</span><span class="br0">&#41;</span><span class="sy0">;</span>
        a.<span class="me1">FetchImages</span><span class="br0">&#40;</span>authToken, album.<span class="me1">Name</span><span class="br0">&#41;</span>.<span class="me1">Images</span>.<span class="kw1">ForEach</span><span class="br0">&#40;</span>image <span class="sy0">=&gt;</span>
            Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span><span class="st0">&quot;<span class="es0">\t</span>&quot;</span> <span class="sy0">+</span> image.<span class="me1">Url</span><span class="br0">&#41;</span>
        <span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
    <span class="br0">&#41;</span><span class="sy0">;</span>
Console.<span class="me1">ReadKey</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>Hopefully I&#8217;ll find an excuse to use this one day.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/gallery2-remote-api-c-wrapper/586/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting document reports from Amazon Seller Central SOAP services (C#)</title>
		<link>http://www.kevinblake.co.uk/getting-document-reports-from-amazon-seller-central-soap-services-c/457/</link>
		<comments>http://www.kevinblake.co.uk/getting-document-reports-from-amazon-seller-central-soap-services-c/457/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 10:29:50 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[amazon seller central]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=457</guid>
		<description><![CDATA[Developing against the Amazon API becomes a lot more straightforward with being able to get at the errors with your XML documents. Validating against the XSDs is only part of the solution, but even downloading reports can be tricky. Trouble is, the documentation from Amazon is a very closed &#038; private sort of affair &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Developing against the Amazon API becomes a lot more straightforward with being able to get at the errors with your XML documents.  Validating against the XSDs is only part of the solution, but even downloading reports can be tricky.  Trouble is, the documentation from Amazon is a very closed &#038; private sort of affair &#8211; sometimes out of date and sometimes very sparse.  Perhaps they should think about a wiki <img src='http://www.kevinblake.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Getting at your reports consists of two parts, firstly &#8211; use the Document ID (long) you got from posting the XML in the first place.</p>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="kw1">public</span> DocumentProcessingInfo DocumentStatus<span class="br0">&#40;</span><span class="kw4">long</span> DocumentID<span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
        <span class="co1">//Setup the service interface, set the URL of the service</span>
        <span class="co1">//and add our credentials.</span>
        merchantinterfacedime myAmazon <span class="sy0">=</span>
            <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> merchantinterfacedime<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        myAmazon.<span class="me1">Url</span> <span class="sy0">=</span> ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;URL&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
        myAmazon.<span class="me1">Credentials</span> <span class="sy0">=</span>
            <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> NetworkCredential<span class="br0">&#40;</span>
                ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;UserName&quot;</span><span class="br0">&#93;</span>,
                ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;Password&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Setup our merchant details.</span>
        Merchant myMerchant <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> Merchant<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        myMerchant.<span class="me1">merchantIdentifier</span> <span class="sy0">=</span>
            ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;MerchantIdentifier&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
        myMerchant.<span class="me1">merchantName</span> <span class="sy0">=</span>
            ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;MerchantName&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
        <span class="co1">//Send it all off to Amazon.</span>
        DocumentProcessingInfo myStatus <span class="sy0">=</span>
            myAmazon.<span class="me1">getDocumentProcessingStatus</span><span class="br0">&#40;</span>
            myMerchant, DocumentID<span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Return the status of the document.</span>
        <span class="kw1">return</span> myStatus<span class="sy0">;</span>
    <span class="br0">&#125;</span></pre></div></div>
<p>This will give you the status of your upload, as well as whether it&#8217;s complete or not.  It also gives you another document ID, which you can use to get at your much-needed reports.</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw4">string</span> GetDocument<span class="br0">&#40;</span><span class="kw4">string</span> id<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        StringBuilder report <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        merchantinterfacedime myAmazon <span class="sy0">=</span>
            <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> merchantinterfacedime<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        myAmazon.<span class="me1">Url</span> <span class="sy0">=</span> ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;URL&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
        myAmazon.<span class="me1">Credentials</span> <span class="sy0">=</span>
            <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> NetworkCredential<span class="br0">&#40;</span>
                ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;UserName&quot;</span><span class="br0">&#93;</span>,
                ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;Password&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">//Setup our merchant details.</span>
        Merchant myMerchant <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> Merchant<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        myMerchant.<span class="me1">merchantIdentifier</span> <span class="sy0">=</span>
            ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;MerchantIdentifier&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
        myMerchant.<span class="me1">merchantName</span> <span class="sy0">=</span>
            ConfigurationManager.<span class="me1">AppSettings</span><span class="br0">&#91;</span><span class="st0">&quot;MerchantName&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span>
        ReferencedBinary incomingDoc <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> ReferencedBinary<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="co1">// the seven-digit string is the document ID number</span>
        myAmazon.<span class="me1">getDocument</span><span class="br0">&#40;</span>myMerchant, id, <span class="kw1">out</span> incomingDoc<span class="br0">&#41;</span><span class="sy0">;</span>
        IEnumerator enumer <span class="sy0">=</span> myAmazon.<span class="me1">ResponseSoapContext</span>.<span class="me1">Attachments</span>.<span class="me1">GetEnumerator</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="kw1">while</span> <span class="br0">&#40;</span>enumer.<span class="me1">MoveNext</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
        <span class="br0">&#123;</span>
            <span class="co1">// Print the document to standard out</span>
            Attachment downloadedDoc <span class="sy0">=</span> enumer.<span class="me1">Current</span> <span class="kw1">as</span> Attachment<span class="sy0">;</span>
            StreamReader r <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> StreamReader<span class="br0">&#40;</span>downloadedDoc.<span class="me1">Stream</span><span class="br0">&#41;</span><span class="sy0">;</span>
            report.<span class="me1">Append</span><span class="br0">&#40;</span>r.<span class="me1">ReadToEnd</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
        <span class="kw1">return</span> report.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>And tying it all together:</p>
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="kw4">long</span> amazonId <span class="sy0">=</span> <span class="co2">#######</span>
<span class="kw4">string</span> report <span class="sy0">=</span> GetDocument<span class="br0">&#40;</span>DocumentStatus<span class="br0">&#40;</span>amazonId<span class="br0">&#41;</span>.<span class="me1">processingReport</span>.<span class="me1">documentID</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>Your report will be in XML, and give you any validation errors that might be preventing your feed from working properly, as well as some very helpful status on the number of items processed.  How did you ever live without it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/getting-document-reports-from-amazon-seller-central-soap-services-c/457/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Code highlighting, and the magic of LINQ</title>
		<link>http://www.kevinblake.co.uk/code-highlighting-and-the-magic-of-linq/182/</link>
		<comments>http://www.kevinblake.co.uk/code-highlighting-and-the-magic-of-linq/182/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 14:37:19 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[geshi]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=182</guid>
		<description><![CDATA[I&#8217;ve had a small block of code in my drafts folder for quite some time now, just looking for an excuse to publish it.  I&#8217;ve been using LINQ a lot in the past 6 months, and it&#8217;s one of the recent additions to the language that&#8217;s made me think twice before using PHP or Perl [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had a small block of code in my drafts folder for quite some time now, just looking for an excuse to publish it.  I&#8217;ve been using <abbr title="Language Integrated Query">LINQ</abbr> a lot in the past 6 months, and it&#8217;s one of the recent additions to the language that&#8217;s made me think twice before using PHP or Perl for my own projects (despite the existence of <a href="http://www.codeplex.com/PHPLinq" target="_blank">PHPLinq</a>).</p>
<blockquote><p>HIM: LINQ&#8217;s like pringles<br />
ME: only makes sense after drugs?<br />
HIM: once you pop you can&#8217;t stop</p></blockquote>
<p>But I didn&#8217;t really want to write a full post on LINQ.  It seemed dull.  It&#8217;d been done before.  It&#8217;s old news.</p>
<p>So I picked up the <a href="http://www.fractalizer.ru/freeware-projects/wordpress-plugins/wp-synhighlight/" target="_blank">WP-SynHighlight</a> extension for WordPress.  Which gives some rather cool code-highlighting through <abbr title="Generic Syntax Highlighter">GeSHi</abbr>.</p>
<p>So here&#8217;s some highlighted stylised C# LINQ demonstrating how simple it is to combine LINQ to SQL with LINQ to XML data sources.<br />
<div id="wpshdo_13" class="wp-synhighlighter-outer"><div id="wpshdt_13" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_13"></a><a id="wpshat_13" class="wp-synhighlighter-title" href="#codesyntax_13"  onClick="javascript:wpsh_toggleBlock(13)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_13" onClick="javascript:wpsh_code(13)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_print(13)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_13" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">var answers <span class="sy0">=</span> <span class="br0">&#40;</span>from a <span class="kw1">in</span> poll.<span class="me1">Descendants</span><span class="br0">&#40;</span><span class="st0">&quot;AnswerSet&quot;</span><span class="br0">&#41;</span>.<span class="me1">Descendants</span><span class="br0">&#40;</span><span class="st0">&quot;Answer&quot;</span><span class="br0">&#41;</span>
join aCount <span class="kw1">in</span> dbVotes
on a.<span class="me1">Attribute</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span>.<span class="me1">Value</span>  equals aCount.<span class="me1">AnswerId</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span> into aJoined
from o <span class="kw1">in</span> aJoined.<span class="me1">DefaultIfEmpty</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
select <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> <span class="br0">&#123;</span>
id <span class="sy0">=</span> a.<span class="me1">Attribute</span><span class="br0">&#40;</span><span class="st0">&quot;id&quot;</span><span class="br0">&#41;</span>.<span class="me1">Value</span>,
percentage <span class="sy0">=</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>o <span class="sy0">==</span> <span class="kw1">null</span> <span class="sy0">?</span> 0 <span class="sy0">:</span> o.<span class="me1">VotesCount</span><span class="br0">&#41;</span> <span class="sy0">/</span> dbVotes.<span class="me1">Sum</span><span class="br0">&#40;</span>b <span class="sy0">=&gt;</span> b.<span class="me1">VotesCount</span>.<span class="me1">GetValueOrDefault</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>  <span class="sy0">*</span> 100<span class="br0">&#41;</span>,
count <span class="sy0">=</span> o <span class="sy0">==</span> <span class="kw1">null</span> <span class="sy0">?</span> 0 <span class="sy0">:</span> o.<span class="me1">VotesCount</span>, text <span class="sy0">=</span> a.<span class="me1">Value</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></p>
<p>Now if only Microsoft would release LINQ to XSD out of preview.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/code-highlighting-and-the-magic-of-linq/182/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
