<?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>blog.cleverswine.net &#187; Hacking</title>
	<atom:link href="http://blog.cleverswine.net/tag/hacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cleverswine.net</link>
	<description>Kevin Noone</description>
	<lastBuildDate>Mon, 26 Sep 2011 23:13:34 +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>WCF Client and the &#8220;using&#8221; Statement</title>
		<link>http://blog.cleverswine.net/2011/09/26/wcf-client-and-the-using-statement/</link>
		<comments>http://blog.cleverswine.net/2011/09/26/wcf-client-and-the-using-statement/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 22:55:56 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://blog.cleverswine.net/?p=735</guid>
		<description><![CDATA[As I was researching patterns and practices for a WCF client implementation, I came across a bug in the .Net implementation of ClientBase&#60;T&#62; (whether it's actually a bug is arguable). It's well documented on the web, but it could cause major headaches if you happened to miss it. The core of the issue is that [...]]]></description>
			<content:encoded><![CDATA[<p>As I was researching patterns and practices for a WCF client implementation, I came across a bug in the .Net implementation of ClientBase&lt;T&gt; (whether it's actually a bug is arguable). It's well documented on the web, but it could cause major headaches if you happened to miss it.</p>
<p>The core of the issue is that ClientBase&lt;T&gt; implements IDisposable. With this knowledge, just about any programmer would naturally wrap its usage in a using{} block. Digging deeper, you'll find that the ClientBase&lt;T&gt; Dispose() method simply calls Close() on the underlying connection. This is problematic because in certain connection states (such as "Faulted"), the Close() will fail.  As I said, this is well documented elsewhere, for example: <a title="Avoiding Problems with the Using Statement" href="http://msdn.microsoft.com/en-us/library/aa355056.aspx" target="_blank">on MSDN</a>, <a href="http://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-block-issue" title="What is the best workaround for the WCF client `using` block issue?" target="_blank">Stack Overflow</a>, and <a href="http://blogs.msdn.com/b/jjameson/archive/2010/03/18/avoiding-problems-with-the-using-statement-and-wcf-service-proxies.aspx" title="Avoiding Problems with the Using Statement and WCF Service Proxies" target="_blank">here</a>.</p>
<p>There are a few different solutions to this issue. I went with a simple Disposable wrapper...</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Get a disposable MyClientWrapper object</span>
<span style="color: #0600FF; font-weight: bold;">using</span><span style="color: #008000;">&#40;</span>var clientWrapper <span style="color: #008000;">=</span> ClientFactory<span style="color: #008000;">.</span><span style="color: #0000FF;">GetMyClientWrapper</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    clientWrapper<span style="color: #008000;">.</span><span style="color: #0000FF;">Client</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DoSomething</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyClientWrapper <span style="color: #008000;">:</span> IDisposable
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> MyClient _client<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> MyClientWrapper<span style="color: #008000;">&#40;</span>Binding binding, Uri endpoint<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// creates an instance of MyClient, which is derived from ClientBase&lt;T&gt;</span>
        _client <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MyClient<span style="color: #008000;">&#40;</span>binding, <span style="color: #008000;">new</span> EndpointAddress<span style="color: #008000;">&#40;</span>endpoint<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> MyClient Client
    <span style="color: #008000;">&#123;</span>
        get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> _client<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Dispose<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// safe dispose with extension method (below)</span>
        _client<span style="color: #008000;">.</span><span style="color: #0000FF;">CloseProxy</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// extension method for safe Close() on ClientBase&lt;T&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> CloseProxy<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> ClientBase<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> proxy<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">class</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">try</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">State</span> <span style="color: #008000;">!=</span> CommunicationState<span style="color: #008000;">.</span><span style="color: #0000FF;">Closed</span> 
                <span style="color: #008000;">&amp;&amp;</span> proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">State</span> <span style="color: #008000;">!=</span> CommunicationState<span style="color: #008000;">.</span><span style="color: #0000FF;">Faulted</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// may throw exception while closing</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">else</span>
        <span style="color: #008000;">&#123;</span>
            proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Abort</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>CommunicationException<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        proxy<span style="color: #008000;">.</span><span style="color: #0000FF;">Abort</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">throw</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2011/09/26/wcf-client-and-the-using-statement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Find/Kill a Linux Process by Name</title>
		<link>http://blog.cleverswine.net/2011/09/09/findkill-a-linux-process-by-name/</link>
		<comments>http://blog.cleverswine.net/2011/09/09/findkill-a-linux-process-by-name/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 22:19:40 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[MiscTech]]></category>

		<guid isPermaLink="false">http://blog.cleverswine.net/?p=730</guid>
		<description><![CDATA[I was doing some research to figure out how to easily kill a Linux process given part of it's name. It's fairly simple to do it manually, but if you didn't already know, programmers are lazy. The first thing I was doing... > ps aux &#124; grep Foo find the process ID (PID) with my [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing some research to figure out how to easily kill a Linux process given part of it's name.  It's fairly simple to do it manually, but if you didn't already know, programmers are lazy.</p>
<p>The first thing I was doing...<br />
> ps aux | grep Foo<br />
find the process ID (PID) with my eyes, and then kill it...<br />
> kill -9 123456</p>
<p>Next, I started finding complex piped commands to find and extract the PID.  For instance...<br />
> pid=`ps -eo pid,args | grep Foo | grep -v grep | cut -c1-6`</p>
<p>and slightly simpler...<br />
> ps aux | grep Foo | grep -v grep | awk '{print $2}'</p>
<p>Finally, I discovered <a href="http://www.linuxmanpages.com/man1/pgrep.1.php" title="pgrep" target="_blank">pgrep and pkill</a>.  There are quite a few options for each command, but simply put:</p>
<p>To get the PID for a process with a name containing 'Foo'...<br />
> pgrep Foo</p>
<p>To get the PID for a process with a command line containing 'Bar' (as in > Foo -n Bar)...<br />
> pgrep -f Bar</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2011/09/09/findkill-a-linux-process-by-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Moq</title>
		<link>http://blog.cleverswine.net/2011/04/20/simple-moq/</link>
		<comments>http://blog.cleverswine.net/2011/04/20/simple-moq/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 22:40:32 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://blog.cleverswine.net/?p=690</guid>
		<description><![CDATA[I recently worked on a project in which 90% of its tests were integration tests because the core purpose of the project was to interact with external entities. In an effort create more unit tests, I employed Moq (and lots of refactoring).  This is an example of basic Moq usage. Let's say we have a [...]]]></description>
			<content:encoded><![CDATA[<p>I recently worked on a project in which 90% of its tests were integration tests because the core purpose of the project was to interact with external entities. In an effort create more unit tests, I employed <a title="Moq" href="http://code.google.com/p/moq/" target="_blank">Moq</a> (and lots of refactoring).  This is an example of basic Moq usage.</p>
<p>Let's say we have a repository that gets documents from a database.  The assumption is that a repository interface, IDocumentRepository, is being implemented.</p>
<p>In my case, I found it easier to deserialize results from file, rather than building the results by hand for each mocked response.  I used System.Xml.Serialization to serialize real responses to file.</p>
<p>Let's Moq it...</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var mockRepository <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Mock<span style="color: #008000;">&lt;</span>IDocumentRepository<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// if the query is for text/plain documents only, mock a response for that</span>
mockRepository<span style="color: #008000;">.</span><span style="color: #0000FF;">Setup</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">FindDocuments</span><span style="color: #008000;">&#40;</span>
	It<span style="color: #008000;">.</span><span style="color: #008000;">Is</span><span style="color: #008000;">&lt;</span>DocumentQueryParams<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>q <span style="color: #008000;">=&gt;</span> q<span style="color: #008000;">.</span><span style="color: #0000FF;">MimeType</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;text/plain&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">.</span><span style="color: #0000FF;">Returns</span><span style="color: #008000;">&#40;</span>DeSerializeResults<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span>Document<span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;TextDocuments.xml&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// use It.IsAny to return the same result regardless of the parameters</span>
mockRepository<span style="color: #008000;">.</span><span style="color: #0000FF;">Setup</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">FindDocuments</span><span style="color: #008000;">&#40;</span>
	It<span style="color: #008000;">.</span><span style="color: #0000FF;">IsAny</span><span style="color: #008000;">&lt;</span>DocumentQueryParams<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">.</span><span style="color: #0000FF;">Returns</span><span style="color: #008000;">&#40;</span>DeSerializeResults<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span>Document<span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;AllDocuments.xml&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2011/04/20/simple-moq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Complex XSDs as Embedded Resources</title>
		<link>http://blog.cleverswine.net/2011/03/17/using-complex-xsds-as-embedded-resources/</link>
		<comments>http://blog.cleverswine.net/2011/03/17/using-complex-xsds-as-embedded-resources/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 23:44:43 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://blog.cleverswine.net/?p=662</guid>
		<description><![CDATA[I was recently tasked with validating XML files against a very complex set of XSD schema files.  This is easily accomplished if your XSD files live on the filesystem, because the .Net xml resolver can find referenced schemas via a relative or absolute Uri.  In my case, the schema files were compiled as embedded resources [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently tasked with validating XML files against a very complex set of XSD schema files.  This is easily accomplished if your XSD files live on the filesystem, because the .Net xml resolver can find referenced schemas via a relative or absolute Uri.  In my case, the schema files were compiled as embedded resources in my project.  As expected, the XML schema loader didn't know how to find referenced schemas - it was likely searching for them  in the path of the running application.  To solve this, I had to help out the schema loader by implementing a custom resolver that knew how to pull schema from the embedded resources.  The code...</p>
<p>Implement a custom XmlUrlResolver to find schema references as embedded resources.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ManifestResourceResolver <span style="color: #008000;">:</span> XmlUrlResolver
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Assembly _resourceAssembly<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span> _baseNamespaceForReferences<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> ManifestResourceResolver<span style="color: #008000;">&#40;</span>Assembly resourceAssembly, <span style="color: #6666cc; font-weight: bold;">string</span> baseNamespaceForReferences<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        _resourceAssembly <span style="color: #008000;">=</span> resourceAssembly<span style="color: #008000;">;</span>
        _baseNamespaceForReferences <span style="color: #008000;">=</span> baseNamespaceForReferences<span style="color: #008000;">.</span><span style="color: #0000FF;">EndsWith</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;.&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> baseNamespaceForReferences <span style="color: #008000;">:</span> baseNamespaceForReferences <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">object</span> GetEntity<span style="color: #008000;">&#40;</span>Uri absoluteUri, <span style="color: #6666cc; font-weight: bold;">string</span> role, Type ofObjectToReturn<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>absoluteUri<span style="color: #008000;">.</span><span style="color: #0000FF;">IsFile</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            var file <span style="color: #008000;">=</span> Path<span style="color: #008000;">.</span><span style="color: #0000FF;">GetFileName</span><span style="color: #008000;">&#40;</span>absoluteUri<span style="color: #008000;">.</span><span style="color: #0000FF;">AbsolutePath</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            var stream <span style="color: #008000;">=</span> _resourceAssembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetManifestResourceStream</span><span style="color: #008000;">&#40;</span>_baseNamespaceForReferences <span style="color: #008000;">+</span> file<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> stream<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Create a XmlSchemaSet, and set the XmlResolver property to the custom resolver implemented above.  Then, load up the main XSD schema.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var xmlSchemaSet <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSchemaSet<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
xmlSchemaSet<span style="color: #008000;">.</span><span style="color: #0000FF;">XmlResolver</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ManifestResourceResolver<span style="color: #008000;">&#40;</span>Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExecutingAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;MyApp.Schemas&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>var stream <span style="color: #008000;">=</span> Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCallingAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetManifestResourceStream</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MyApp.Schemas.MainSchema.xsd&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    var xmlSchema <span style="color: #008000;">=</span> XmlSchema<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span>stream, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    xmlSchemaSet<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>xmlSchema<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Create a XmlReaderSettings object and set the Schemas property to the schema set loaded above.  Lastly, load up an XML file with an XmlReader and read it.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">XmlReaderSettings settings <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlReaderSettings<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
settings<span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationType</span> <span style="color: #008000;">=</span> ValidationType<span style="color: #008000;">.</span><span style="color: #0000FF;">Schema</span><span style="color: #008000;">;</span>
settings<span style="color: #008000;">.</span><span style="color: #0000FF;">Schemas</span> <span style="color: #008000;">=</span> xmlSchemaSet<span style="color: #008000;">;</span>
settings<span style="color: #008000;">.</span><span style="color: #0000FF;">ValidationEventHandler</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> ValidationEventHandler <span style="color: #008000;">&#40;</span>ValidationCallBack<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
XmlReader reader <span style="color: #008000;">=</span> XmlReader<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;SomeXml.xml&quot;</span>, settings<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>reader<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The validation callback function will be invoked on each validation error while reading the file with the XmlReader.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> ValidationCallBack<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, ValidationEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Validation Error: {0}&quot;</span>, e<span style="color: #008000;">.</span><span style="color: #0000FF;">Message</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>References:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/as3tta56%28v=VS.90%29.aspx">Validation Using the XmlSchemaSet</a></li>
<li><a href="http://www.hanselman.com/blog/LoadingXmlSchemaFilesOutOfAssemblyResources.aspx">Loading XmlSchema files out of Assembly Resources</a><br/> (contains some obsoleted code, but it was still helpful)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2011/03/17/using-complex-xsds-as-embedded-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC3 + MongoDB + Autofac</title>
		<link>http://blog.cleverswine.net/2011/03/08/mvc3-mongodb-autofac/</link>
		<comments>http://blog.cleverswine.net/2011/03/08/mvc3-mongodb-autofac/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 03:31:08 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://blog.cleverswine.net/?p=646</guid>
		<description><![CDATA[I recently posted a brief summary of creating a recipe database.  I decided to expand on that and go into the implementation details of using ASP.NET MVC3 with MongoDB and Autofac.  This code depends on the NoRM driver for MongoDB, Autofac, and MVC3 (and it's dependencies). This is by no means the only (or best) [...]]]></description>
			<content:encoded><![CDATA[<p>I recently posted a <a href="http://blog.cleverswine.net/2011/03/08/a-diet-and-an-application/">brief summary</a> of creating a recipe database.  I decided to expand on that and go into the implementation details of using ASP.NET MVC3 with MongoDB and Autofac.  This code depends on the <a href="https://github.com/atheken/NoRM">NoRM</a> driver for <a href="http://www.mongodb.org/">MongoDB</a>, <a href="http://code.google.com/p/autofac/">Autofac</a>, and <a href="http://www.asp.net/mvc">MVC3</a> (and it's dependencies).  This is by no means the only (or best) way to do things, but this is how I chose to do it.  I've simplified the repository to one method for brevity, but you'd obviously want to add all of the required CRUD operations.</p>
<p>First, we'll want to create an interface for our database session.  The implementation of this interface can be swapped out depending on the backing store.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">interface</span> ISession <span style="color: #008000;">:</span> IDisposable
<span style="color: #008000;">&#123;</span>
    <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Linq</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IQueryable</span><span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> All<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">class</span>, <span style="color: #008000;">new</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Add a MongoDB implementation of ISession.  This implementation will eventually be used in our repository.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MongoSession <span style="color: #008000;">:</span> ISession
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> IMongo _provider<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> MongoSession<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//this looks for a connection string in your Web.config</span>
        <span style="color: #008080; font-style: italic;">//&lt;connectionStrings&gt;</span>
        <span style="color: #008080; font-style: italic;">//  &lt;add name=&quot;db&quot; connectionString=&quot;mongodb://localhost/testdb?strict=true&quot;/&gt;</span>
        <span style="color: #008080; font-style: italic;">//&lt;/connectionStrings&gt;</span>
        _provider <span style="color: #008000;">=</span> Mongo<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;db&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> IQueryable<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> All<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">class</span>, <span style="color: #008000;">new</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> _provider<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCollection</span><span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">AsQueryable</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Dispose<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        _provider<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Create an interface for the repository.  This is what the controller will expect to be injected via it's constructor.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">interface</span> IRecipeRepository
<span style="color: #008000;">&#123;</span>
    IEnumerable<span style="color: #008000;">&lt;</span>RecipeCard<span style="color: #008000;">&gt;</span> GetAll<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> page <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, <span style="color: #6666cc; font-weight: bold;">int</span> pageSize <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Add the IRecipeRepository implementation, which is created with a new()-able type of ISession.  Why didn't I just inject an ISession into the repository?  It's because Mongo sessions are expected to be disposed of after use, as connections are pooled and reused.  Therefore we have to create and dispose of our sessions when using them.  This might require some workarounds if you really did switch repositories (do nothing on Dispose(), etc).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> RecipeRepository<span style="color: #008000;">&lt;</span>SessionT<span style="color: #008000;">&gt;</span> <span style="color: #008000;">:</span> IRecipeRepository <span style="color: #0600FF; font-weight: bold;">where</span> SessionT <span style="color: #008000;">:</span> ISession, <span style="color: #008000;">new</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> IEnumerable<span style="color: #008000;">&lt;</span>RecipeCard<span style="color: #008000;">&gt;</span> GetAll<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> page <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>, <span style="color: #6666cc; font-weight: bold;">int</span> pageSize <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>var session <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SessionT<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> session<span style="color: #008000;">.</span><span style="color: #0000FF;">All</span><span style="color: #008000;">&lt;</span>RecipeCard<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OrderByDescending</span><span style="color: #008000;">&#40;</span>r <span style="color: #008000;">=&gt;</span> r<span style="color: #008000;">.</span><span style="color: #0000FF;">UpdatedDate</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Skip</span><span style="color: #008000;">&#40;</span>pageSize <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span>page <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Take</span><span style="color: #008000;">&#40;</span>pageSize<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Now it's time set up our IoC container.  We'll do this in the Global.asax.cs.  Here we are registering a recipe repository of type MongoSession such that any controller that expects an IRecipeRepository in the constructor will get this.  We're letting Autofac handle controller creation and dependency injection.  See the <a href="http://code.google.com/p/autofac/wiki/Mvc3Integration">Autofac MVC3 integration page</a> for more details.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    var builder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ContainerBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    builder<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span>r <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">new</span> RecipeRepository<span style="color: #008000;">&lt;</span>MongoSession<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">As</span><span style="color: #008000;">&lt;</span>IRecipeRepository<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">InstancePerLifetimeScope</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    builder<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterControllers</span><span style="color: #008000;">&#40;</span>Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExecutingAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    var container <span style="color: #008000;">=</span> builder<span style="color: #008000;">.</span><span style="color: #0000FF;">Build</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    DependencyResolver<span style="color: #008000;">.</span><span style="color: #0000FF;">SetResolver</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> AutofacDependencyResolver<span style="color: #008000;">&#40;</span>container<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    AreaRegistration<span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterAllAreas</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    RegisterGlobalFilters<span style="color: #008000;">&#40;</span>GlobalFilters<span style="color: #008000;">.</span><span style="color: #0000FF;">Filters</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    RegisterRoutes<span style="color: #008000;">&#40;</span>RouteTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Routes</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Finally, here is our controller.  Notice we never have to create a repository object - one was injected for us.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> IRecipeRepository recipeRepository<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> RecipesController<span style="color: #008000;">&#40;</span>IRecipeRepository recipeRepository<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">recipeRepository</span> <span style="color: #008000;">=</span> recipeRepository<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> ViewResult Index<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span>recipeRepository<span style="color: #008000;">.</span><span style="color: #0000FF;">GetAll</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>That's it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2011/03/08/mvc3-mongodb-autofac/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Diet and an Application</title>
		<link>http://blog.cleverswine.net/2011/03/08/a-diet-and-an-application/</link>
		<comments>http://blog.cleverswine.net/2011/03/08/a-diet-and-an-application/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 01:13:27 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://blog.cleverswine.net/?p=639</guid>
		<description><![CDATA[I've started on the Paleo Diet, which, of course, means I have to create a software application to go along with it. I decided this was a good time to give MVC3 and MongoDB a test drive.  After diving in, I realized that I could benefit from some dependency injection via MVC3's DependencyResolver.  I've been [...]]]></description>
			<content:encoded><![CDATA[<p>I've started on the <a title="Paleo Lifestyle" href="http://paleodietlifestyle.com/" target="_blank">Paleo Diet</a>, which, of course, means I have to create a software application to go along with it.</p>
<p>I decided this was a good time to give <a title="Asp.net MVC" href="http://www.asp.net/mvc" target="_blank">MVC3</a> and <a title="MongoDB" href="http://www.mongodb.org/" target="_blank">MongoDB</a> a test drive.  After diving in, I realized that I could benefit from some dependency injection via MVC3's DependencyResolver.  I've been wanting to learn <a title="Autofac" href="http://code.google.com/p/autofac/" target="_blank">Autofac</a>, so I threw that in as the container.  This was sweet, as it injected my repository implementations into my controllers with very little setup.</p>
<p>At this point, I've learned all about the Razor view engine, DI with Autofac and DependencyResolver, MongoDB with the NoRM driver, jQuery, jQuery-ui, and some other MVC3 goodness.</p>
<p>For various reasons, including the fact that my web hosting provider is a Linux/non-ASP.NET provider, I ported the whole thing to Rails/MySql.  I'm glad I went through the MVC3 process, because I learned a lot, but in the end, Rails is just simpler.  As for MongoDB, and NoSQL in general, I think it's best served as an edge case storage medium for fast read operations.  Data is relational.</p>
<p>Alas, here is a screenshot of the recipe database.  I'll be adding lots of features, including menus and weight management.  You can't see it here, but it has a cool tag cloud feature and theme switching.</p>
<p><a href="http://blog.cleverswine.net/wp-content/uploads/2011/03/recipes.png"><img class="alignnone size-medium wp-image-640" title="recipes" src="http://blog.cleverswine.net/wp-content/uploads/2011/03/recipes-300x139.png" alt="Recipes" width="300" height="139" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2011/03/08/a-diet-and-an-application/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What I&#8217;m Working On</title>
		<link>http://blog.cleverswine.net/2009/11/23/what-im-working-on/</link>
		<comments>http://blog.cleverswine.net/2009/11/23/what-im-working-on/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 18:32:54 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[WebSite]]></category>

		<guid isPermaLink="false">http://blog.cleverswine.net/?p=606</guid>
		<description><![CDATA[Here's what I'm working on What I worked on.  Right now it's just a basic display of feeds from some of my social networks.  I'd like to fancy it up a bit at some point, perhaps with some nice jQuery tooltips.  I'm using the SimplePie PHP library to fetch the feeds (each one asynchronously).  The [...]]]></description>
			<content:encoded><![CDATA[<p><del datetime="2011-03-18T00:50:48+00:00">Here's what I'm working on</del> <a title="Test Site" href="http://cleverswine.net/" target="_blank">What I worked on</a>.  Right now it's just a basic display of feeds from some of my social networks.  I'd like to fancy it up a bit at some point, perhaps with some nice jQuery tooltips.  I'm using the SimplePie PHP library to fetch the feeds (each one asynchronously).  The design is borrowed from <a title="Popurls" href="http://popurls.com/" target="_blank">Popurls</a>.  I know it's not that interesting, but it's fun for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2009/11/23/what-im-working-on/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ID3 Tag Parsing</title>
		<link>http://blog.cleverswine.net/2009/03/25/id3-tag-parsing/</link>
		<comments>http://blog.cleverswine.net/2009/03/25/id3-tag-parsing/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 03:29:26 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[MP3]]></category>
		<category><![CDATA[Music]]></category>

		<guid isPermaLink="false">http://cleverswine.net/?p=544</guid>
		<description><![CDATA[I've been working on a project to read and update ID3 tags on my music collection. An ID3 tag is the meta data embedded in mp3 files that contains artist and other information. My initial goal is to batch update the "genre" field in my mp3 files. I've written a simple .Net forms application to [...]]]></description>
			<content:encoded><![CDATA[<p>I've been working on a project to read and update <a href="http://www.id3.org/Home">ID3 tags</a> on my music collection.  An ID3 tag is the meta data embedded in mp3 files that contains artist and other information.  My initial goal is to batch update the "genre" field in my mp3 files.  I've written a simple .Net forms application to do this.  I found a really good library created by Novell called <a href="http://developer.novell.com/wiki/index.php/TagLib_Sharp">TagLib Sharp</a>.  The library makes it super easy to read and write ID3 tags.<br />
<code><br />
                TagLib.File tagFile = TagLib.File.Create(filePath);<br />
                Tag tagId3v2 = tagFile.GetTag(TagTypes.Id3v2);<br />
                if (tagId3v2 != null) tagId3v2.Genres = genreArray;<br />
                Tag tagId3v1 = tagFile.GetTag(TagTypes.Id3v1);<br />
                if (tagId3v1 != null) tagId3v1.Genres = genreArray;<br />
                tagFile.Save();<br />
</code></p>
<p>The UI is pretty lame, but it works...<br />
<a href="http://www.flickr.com/photos/cleverswine/3388496248/sizes/o/"><img src="http://farm4.static.flickr.com/3537/3388496248_76046f444e_m_d.jpg" alt="tagger" /></a></p>
<p><a href="http://www.flickr.com/photos/cleverswine/3388496280/sizes/o/"><img src="http://farm4.static.flickr.com/3471/3388496280_11c16fdeb1_m_d.jpg" alt="tagger" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2009/03/25/id3-tag-parsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dr. Dobb&#8217;s Journal</title>
		<link>http://blog.cleverswine.net/2009/03/17/dr-dobbs-journal/</link>
		<comments>http://blog.cleverswine.net/2009/03/17/dr-dobbs-journal/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 16:56:22 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[MiscTech]]></category>
		<category><![CDATA[Science]]></category>

		<guid isPermaLink="false">http://cleverswine.net/?p=540</guid>
		<description><![CDATA[I've been subscribing to Dr. Dobb's Journal for at least 10 years. It has always been my favorite technical magazine because of it's diversity of topics and brain-stirring articles. I got a letter in the mail last week saying that they were ceasing production of the full magazine. Instead, they will offer a Dr. Dobb's [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dobbschallenge2.com/"><img src="http://blog.cleverswine.net/wp-content/uploads/2009/03/dd2.jpg" alt="" title="dd2" width="125" height="100" class="alignleft size-full wp-image-541" /></a> I've been subscribing to <a href="http://www.ddj.com/">Dr. Dobb's Journal</a> for at least 10 years.  It has always been my favorite technical magazine because of it's diversity of topics and brain-stirring articles.  I got a letter in the mail last week saying that they were ceasing production of the full magazine.  Instead, they will offer a Dr. Dobb's Report stuffed into issues of InformationWeek.  I'll have to spend more time on their web site, as it looks like they have some good content on there.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2009/03/17/dr-dobbs-journal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kevin Enjoys Things</title>
		<link>http://blog.cleverswine.net/2009/01/06/kevin-enjoys-things/</link>
		<comments>http://blog.cleverswine.net/2009/01/06/kevin-enjoys-things/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 00:13:30 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://cleverswine.net/?p=513</guid>
		<description><![CDATA[Ted has been vigorously working on a rad new site called enjoys things. He has been adding new features almost daily for the past few weeks, and it's shaping up nicely. Check what I enjoy and see how cool it is. When I find some room on my front page, I'll add my enjoys things [...]]]></description>
			<content:encoded><![CDATA[<p>Ted has been vigorously working on a rad new site called <a href="http://enjoysthin.gs">enjoys things</a>.  He has been adding new features almost daily for the past few weeks, and it's shaping up nicely.  <a href="http://cleverswine.enjoysthin.gs/">Check what I enjoy</a> and see how cool it is.  When I find some room on my front page, I'll add my enjoys things badge.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2009/01/06/kevin-enjoys-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning WPF</title>
		<link>http://blog.cleverswine.net/2008/12/22/learning-wpf/</link>
		<comments>http://blog.cleverswine.net/2008/12/22/learning-wpf/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 16:38:48 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://cleverswine.net/?p=507</guid>
		<description><![CDATA[Since I'm pretty much stuck in the house due to the snow (and lack of a job), I've decided to learn something new. I've begun writing a Windows Presentation Foundation (WPF) application. WPF has some insanely cool UI features, including declarative UI effects. My first project is a simple screensaver that pulls photos from Flickr [...]]]></description>
			<content:encoded><![CDATA[<p>Since I'm pretty much stuck in the house due to the snow (and lack of a job), I've decided to learn something new.  I've begun writing a <a href="http://windowsclient.net/">Windows Presentation Foundation</a> (WPF) application.  WPF has some insanely cool UI features, including declarative UI effects.  My first project is a simple screensaver that pulls photos from Flickr and displays them as a slideshow with cool transition effects.  Eventually, I'd like to create a dashboard type application that displays news, weather, email, etc.  The dashboard will be more UI intensive, so I'm not quite ready for that.  Creating WPF forms is very different than creating traditional Windows forms.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2008/12/22/learning-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Windows Live Writer</title>
		<link>http://blog.cleverswine.net/2008/12/03/testing-windows-live-writer/</link>
		<comments>http://blog.cleverswine.net/2008/12/03/testing-windows-live-writer/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 17:35:29 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://cleverswine.net/2008/12/03/testing-windows-live-writer/</guid>
		<description><![CDATA[Technorati Tags: Hacking,Personal I just installed Windows Live Writer as a tool to publish stories to my web site.&#160; It has some promising features, and works with WordPress (yay MS). I also just installed DropBox because I've been meaning to find a way to create offsite copies of some of our important files.&#160; I haven't [...]]]></description>
			<content:encoded><![CDATA[<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f3d6c94e-065d-4cb6-baa3-caa8ce76972e" 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/Hacking" rel="tag">Hacking</a>,<a href="http://technorati.com/tags/Personal" rel="tag">Personal</a></div>
<p>I just installed <a href="http://get.live.com/writer/overview">Windows Live Writer</a> as a tool to publish stories to my web site.&#160; It has some promising features, and works with WordPress (yay MS).</p>
<p>I also just installed DropBox because I've been meaning to find a way to create offsite copies of some of our important files.&#160; I haven't tried it yet, but I hear good things about it.</p>
<p>Hmm, now that I'm about to publish, I'm wondering if it will handle WordPress tags...  it did not.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2008/12/03/testing-windows-live-writer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fennec Alpha 1 Testing</title>
		<link>http://blog.cleverswine.net/2008/10/20/fennec-alpha-1-testing/</link>
		<comments>http://blog.cleverswine.net/2008/10/20/fennec-alpha-1-testing/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 22:19:48 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://cleverswine.net/?p=479</guid>
		<description><![CDATA[I installed the mobile version of Firefox, named Fennec, on my Nokia n800 today. It's intolerably slow (but it's alpha, so that can be ignored for now), but has some potentially cool features like tabbed browsing and a "smart" URL bar.]]></description>
			<content:encoded><![CDATA[<p>I installed the mobile version of Firefox, named <a href="http://www.mozilla.org/projects/fennec/1.0a1/releasenotes/">Fennec</a>, on my Nokia n800 today.  It's intolerably slow (but it's alpha, so that can be ignored for now), but has some potentially cool features like tabbed browsing and a "smart" URL bar.</p>
<p><a href="http://www.flickr.com/search/?q=fennec&#038;w=28573526%40N00"><img src="http://farm4.static.flickr.com/3202/2959865912_6926b51af5_m_d.jpg" alt="fennec" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2008/10/20/fennec-alpha-1-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We Like the Dark</title>
		<link>http://blog.cleverswine.net/2008/10/15/we-like-the-dark/</link>
		<comments>http://blog.cleverswine.net/2008/10/15/we-like-the-dark/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 18:05:57 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://cleverswine.net/?p=477</guid>
		<description><![CDATA[Most software engineers prefer to avoid the sun and bright lights. At my office, we keep the lights out and the window shades closed. However, when we do choose to look out the window, this is what we see...]]></description>
			<content:encoded><![CDATA[<p>Most software engineers prefer to avoid the sun and bright lights.  At my office, we keep the lights out and the window shades closed.  However, when we do choose to look out the window, this is what we see...<br />
<a href="http://www.flickr.com/photos/cleverswine/"><img src="http://farm4.static.flickr.com/3230/2959923652_d260474503_m_d.jpg" alt="view" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2008/10/15/we-like-the-dark/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Look</title>
		<link>http://blog.cleverswine.net/2008/10/07/new-look/</link>
		<comments>http://blog.cleverswine.net/2008/10/07/new-look/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 21:48:25 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[WebSite]]></category>

		<guid isPermaLink="false">http://cleverswine.net/?p=462</guid>
		<description><![CDATA[I found the Aeros wordpress theme, downloaded it, made some modifications, added my photos/movies/music widget, and here it is! I've only tested in Firefox 3 and Internet Explorer 7. The font looks a bit strange in IE7... Anyway, I'll be fiddling with it some more over time. Let me know if something doesn't look right [...]]]></description>
			<content:encoded><![CDATA[<p>I found the <a href="http://thebuckmaker.com/aeros">Aeros</a> wordpress theme, downloaded it, made some modifications, added my photos/movies/music widget, and here it is!  I've only tested in Firefox 3 and Internet Explorer 7.  The font looks a bit strange in IE7...  Anyway, I'll be fiddling with it some more over time.  Let me know if something doesn't look right in your browser.</p>
<p>I know the sidebar isn't very elegant (especially the photos/movies/music links).  I am soooo bad at design.  Fooling around with those 3 links took longer than anything else I've done with this update.  Every time I tried to get fancy, the layout would go to hell.  I have grand ideas - really.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cleverswine.net/2008/10/07/new-look/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

