<?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>Red Recondite &#187; Development</title>
	<atom:link href="http://www.redrecondite.com/blog/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redrecondite.com/blog</link>
	<description>Red Recondite is slumber with a plunger</description>
	<lastBuildDate>Fri, 23 Oct 2009 01:49:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Footbreak 0.0</title>
		<link>http://www.redrecondite.com/blog/2009/10/22/footbreak-0-0/</link>
		<comments>http://www.redrecondite.com/blog/2009/10/22/footbreak-0-0/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 01:49:06 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.redrecondite.com/blog/?p=238</guid>
		<description><![CDATA[Footbreak is an alternative GUI for the Handbrake video encoding software.  It&#8217;s goal is to make ripping television shows as simple as possible.  Simply select an ISO file (that has been decrypted with DVD Decrypter), search for the television show, select the season, and relate each episode with a DVD Title.  Once you&#8217;ve done this [...]]]></description>
			<content:encoded><![CDATA[<p>Footbreak is an alternative GUI for the <a href="http://handbrake.fr/">Handbrake video encoding software</a>.  It&#8217;s goal is to make ripping television shows as simple as possible.  Simply select an ISO file (that has been decrypted with DVD Decrypter), search for the television show, select the season, and relate each episode with a DVD Title.  Once you&#8217;ve done this for all of your ISOs, specify your video settings, and walk away from your computer.</p>
<p>Version 0.0 is available for <a href="http://www.redrecondite.com/footbreak_0.0.zip">download</a> (155 Kb).  Full source code is included.</p>
<p>Screenshots that detail the wizard process are available after the jump.</p>
<p><span id="more-238"></span><img class="alignnone size-full wp-image-239" title="footbreak-1" src="http://www.redrecondite.com/blog/wp-content/uploads/2009/10/footbreak-1.png" alt="footbreak-1" width="450" height="396" /></p>
<p><img class="alignnone size-full wp-image-240" title="footbreak-2" src="http://www.redrecondite.com/blog/wp-content/uploads/2009/10/footbreak-2.png" alt="footbreak-2" width="450" height="396" /></p>
<p><img class="alignnone size-full wp-image-241" title="footbreak-3" src="http://www.redrecondite.com/blog/wp-content/uploads/2009/10/footbreak-3.png" alt="footbreak-3" width="450" height="396" /></p>
<p><img class="alignnone size-full wp-image-242" title="footbreak-4" src="http://www.redrecondite.com/blog/wp-content/uploads/2009/10/footbreak-4.png" alt="footbreak-4" width="450" height="396" /></p>
<p><img class="alignnone size-full wp-image-243" title="footbreak-5" src="http://www.redrecondite.com/blog/wp-content/uploads/2009/10/footbreak-5.png" alt="footbreak-5" width="450" height="396" /></p>
<p><img class="alignnone size-full wp-image-244" title="footbreak-6" src="http://www.redrecondite.com/blog/wp-content/uploads/2009/10/footbreak-6.png" alt="footbreak-6" width="450" height="393" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrecondite.com/blog/2009/10/22/footbreak-0-0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating Immutable Data Classes in C#&#8230; Quickly</title>
		<link>http://www.redrecondite.com/blog/2009/05/26/creating-immutable-data-classes-in-csharp-quickl/</link>
		<comments>http://www.redrecondite.com/blog/2009/05/26/creating-immutable-data-classes-in-csharp-quickl/#comments</comments>
		<pubDate>Wed, 27 May 2009 01:23:53 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.redrecondite.com/blog/?p=178</guid>
		<description><![CDATA[Of late, I&#8217;ve been tempted by F#.  In reading articles and familiarizing myself with the language, there seems to be something truly interesting there, but I just don&#8217;t grok functional programming yet.
One item in particular that I&#8217;ve seen is the Record data expression.  This allows you to create an immutable data structure, like so:
type Data [...]]]></description>
			<content:encoded><![CDATA[<p>Of late, I&#8217;ve been tempted by <a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx">F#</a>.  In reading articles and familiarizing myself with the language, there seems to be something truly interesting there, but I just don&#8217;t grok functional programming yet.</p>
<p>One item in particular that I&#8217;ve seen is the <a href="http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec2.aspx#_Toc207785609">Record</a> data expression.  This allows you to create an <a href="http://en.wikipedia.org/wiki/Immutable_object">immutable</a> data structure, like so:</p>
<pre name="code" class="c#">type Data = { Count : int; Name : string }
let data1 = { Count = 3; Name = "Hello"; }</pre>
<p>Then, if at a later time you wish to change Count but keep Name the same, that&#8217;s absurdly simple.</p>
<pre name="code" class="c#">let newData = data1 with Count = 4;</pre>
<p>C#&#8230; does not have anything like this.  To create a similar immutable data structure (including equality checking), you&#8217;d have to do something like this:</p>
<pre name="code" class="c#">using System;
using System.Collections.Generic;

public class Data : IEquatable&lt;Data&gt;
{
    private readonly int mCount;
    public int Count
    {
        get { return mCount; }
    }

    private readonly string mName;
    public string Name
    {
        get { return mName; }
    }

    public Data( int aCount, string aName )
    {
        mCount = aCount;
        mName = aName;
        return;
    }

    public Data ChangeCount( int aCount )
    {
        return new Data( aCount, mName );
    }

    public Data ChangeName( string aName )
    {
        return new Data( mCount, aName );
    }

    public bool Equals( Data aOther )
    {
        bool lResult = false;
        if ( aOther != null )
        {
            lResult = ( this.Count == aOther.Count &#038;&#038;
                        this.Name == aOther.Name );
        }
        return lResult;
    }

    public override bool Equals( object aOther )
    {
        bool lResult = false;
        if ( aOther is Data )
        {
            lResult = Equals( aOther as Data );
        }
        return lResult;
    }

    public override int GetHashCode()
    {
        return Name.GetHashCode();
    }

    public static bool operator ==( Data aLeft, Data aRight )
    {
        return EqualityComparer&lt;Data&gt;.Default.Equals( aLeft, aRight );
    }

    public static bool operator !=( Data aLeft, Data aRight )
    {
        return !EqualityComparer&lt;Data&gt;.Default.Equals( aLeft, aRight );
    }
}</pre>
<p>That&#8217;s a lot of work!  In F#, what takes a single line takes 70 in C#.  And a lot of that is nasty, crufty copy-paste code.  And its easy to forget to change some things, like the Equals method.</p>
<p>Well, let me correct myself.  That <b>would</b> be a lot of work&#8230; if I wrote that.  But I didn&#8217;t.  I just wrote this:</p>
<pre name="code" class="c#">&lt;#
this.Namespace = "Example";
this.ClassName = "Data";
this.ClassScope = "public";
this.ImplementINotifyProperty = false;
this.HashCodeVariable = "Name";
this.Variables = new List&lt;Variable&gt;()
{
    new Variable( "Count", "int", Options.Immutable | Options.ChangeMethod ),
    new Variable( "Name", "string", Options.Immutable | Options.ChangeMethod ),
};
#&gt;
&lt;#@ include file="DataClass.tt" #&gt;</pre>
<p>What is this mysterious mumbo-jumbo?  That, sir (or madam), is T4: Microsoft&#8217;s <a href="http://msdn.microsoft.com/en-us/library/bb126445.aspx">Text Template Transformation Toolkit</a> (aka a code generator).  It is included in Visual Studio 2008, but it isn&#8217;t widely advertised.</p>
<p>My DataClass.tt file is a horribly messy template that takes in the values I listed above, and translates them into the real source code example I pasted above.  Besides immutable data structures, it also supports mutable members, including support for INotifyPropertyChanged and [Member]Changed events.</p>
<p>I&#8217;m rather liking this so far.  If it turns out that this code generation is a horrible idea, I can simply delete my .tt files and use my auto-generated .cs files from then-on with little loss.</p>
<p>Note that the following source code is not well documented, and is not very error tolerant.  If you do something silly, chances are you&#8217;ll get an obtuse compilation error.  I recommend modifying it to suit your own needs.</p>
<p><a href="http://www.redrecondite.com/blog/wp-content/uploads/2009/05/dataclasscodegenerator.zip">Data Class Code Generator Source Code</a> (11 KB, requires Visual Studio 2008)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrecondite.com/blog/2009/05/26/creating-immutable-data-classes-in-csharp-quickl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Presenter First: Simple Presenters</title>
		<link>http://www.redrecondite.com/blog/2009/02/17/presenter-first-simple-presenters/</link>
		<comments>http://www.redrecondite.com/blog/2009/02/17/presenter-first-simple-presenters/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 01:35:22 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.redrecondite.com/blog/?p=104</guid>
		<description><![CDATA[While reading this article, please keep in mind that I am a novice in using Presenter First.  The following technique has not been fully tested in a production environment, and may have drawbacks that I have not anticipated.
In developing an obscenely large and complicated personal project, I have become a big fan of the Presenter [...]]]></description>
			<content:encoded><![CDATA[<p>While reading this article, please keep in mind that I am a novice in using Presenter First.  The following technique has not been fully tested in a production environment, and may have drawbacks that I have not anticipated.</p>
<hr />In developing an obscenely large and complicated personal project, I have become a big fan of the <a href="http://www.atomicobject.com/pages/Presenter+First">Presenter First</a> design pattern.  It &#8216;clicks&#8217; with me in a way that standard Model-View-Controller and Model-View-Presenter patterns simply have not.</p>
<p>A quick explanation of what makes Presenter First a little different: A Presenter contains a reference to a Model interface and a View interface.  The Presenter subscribes to events on the Model and View.  The Model and View can only communicate with the Presenter by raising these events.  The Model and View do not have any direct reference to each other.  This allows you to test the Model and Presenter logic without creating a View.</p>
<p>I highly recommend reading the <a href="http://www.atomicobject.com/files/PresenterFirstAgile2006.pdf">Presenter First white paper</a> (PDF) for more details.</p>
<p>In my project, I&#8217;ve been trying to follow a test-driven development approach, where I write test cases (using <a href="http://www.nunit.org">NUnit</a> and <a href="http://www.nmock.org/">NMock2</a>) before I write the actual code.</p>
<p>I immediately ran into issues testing event subscription and event firing.  It was difficult to test the presenter, because it required the test to fire an event owned by the mock Model.</p>
<p>For example, this was my presenter code for a simple History presenter.  The goal is the History model fires the MessageLogged event when a new message has been added to the History log, which will prompt the Presenter to call the View&#8217;s UpdateHistory function.</p>
<pre name="code" class="c#">public interface IHistoryModel
{
    event Action MessageLogged;
    string Message { get; }
}

public interface IHistoryView
{
    void UpdateHistory( string aMessage );
}

public class HistoryPresenter
{
    private readonly IHistoryModel mModel;
    private readonly IHistoryView mView;

    public HistoryPresenter( IHistoryModel aModel,
                             IHistoryView aView )
    {
        mModel = aModel;
        mView = aView;

        aModel.MessageLogged += OnMessageLogged;
    }

    private void OnMessageLogged()
    {
        mView.UpdateHistory( mModel.Message );
    }
}</pre>
<p>To test this, I mocked up a Model and View with <a href="http://www.nmock.org/">NMock2</a>, but NMock2 does not have any direct provisions for firing events that are on mock objects.  I googled around, found a way to <a href="http://manicprogrammer.com/cs/blogs/willeke/archive/2007/10/17/testing-delegates-with-nunit-and-nmock.aspx">create MockEvents</a>, and I found myself with a terrible, complicated test case.</p>
<p>To be fair, the Presenter First white paper does recommend that events should not be specified in the interface itself; they should be hidden by a separate function, like &#8216;SubscribeMessageLogged&#8217;.  I found this concept ridiculous, but I started to understand why.</p>
<p>After struggling with MockEvents for several days, I had a sudden epiphany that would greatly simplify everything.  I changed the Model event to provide the associated data as a parameter (a behavior that was also discouraged by the white paper) and transform the Presenter into a brain-dead connector.</p>
<pre name="code" class="c#">public interface IHistoryModel
{
    event Action&lt;string&gt; MessageLogged;
}

public interface IHistoryView
{
    void UpdateHistory( string aMessage );
}

public class HistoryPresenter
{
    public HistoryPresenter( IHistoryModel aModel,
                             IHistoryView aView )
    {
        aModel.MessageLogged += aView.UpdateHistory;
    }
}</pre>
<p>And&#8230; that&#8217;s it.  The Presenter doesn&#8217;t even need any additional methods outside of the constructor!</p>
<p>The test case is super simple as well:</p>
<pre name="code" class="c#">[TestFixture]
public class HistoryPresenterTest
{
    [Test]
    public void Constructor()
    {
        var lMockery = new Mockery();

        var lView = lMockery.NewMock&lt;IHistoryView&gt;();
        var lModel = lMockery.NewMock&lt;IHistoryModel&gt;();

        Expect.Once.On( lModel ).EventAdd(
            "MessageLogged",
            new Action(
                lView.UpdateHistory ) );

        new HistoryPresenter( lModel, lView );

        lMockery.VerifyAllExpectationsHaveBeenMet();
    }
}</pre>
<p>The mock Model expects that it will be connected to the View&#8217;s UpdateHistory method, and that&#8217;s all of the testing that is required.  There is no need to raise the MessageLogged event, because that would simply test the functionality of C# events.</p>
<p>The advantage of this simple presenter is even more profound as you add new events to the Model and View.  Now, all that is needed is one event, one method, one line connecting the model and view in the Presenter, and one line in the test case.</p>
<p>As long as each event can be tied to a corresponding method, this makes writing presenters (and their tests) extremely simple.</p>
<p><a href="http://www.redrecondite.com/blog/wp-content/uploads/2009/02/simplepresenterexample.zip">Simple Presenter Example Source Code</a> (26 KB, requires Visual Studio 2008 and Nunit 2.4.8)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrecondite.com/blog/2009/02/17/presenter-first-simple-presenters/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Playing Video in C#</title>
		<link>http://www.redrecondite.com/blog/2008/02/16/playing-video-in-c/</link>
		<comments>http://www.redrecondite.com/blog/2008/02/16/playing-video-in-c/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 20:41:30 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.redrecondite.com/blog/2008/02/16/playing-video-in-c/</guid>
		<description><![CDATA[I have been working on a WPF (Windows Presentation Framework) application using Visual C# 2008 Express.  Even though I am at the Initial Optimism phase of Software Development, and my imagination is running wild, I know that nothing will probably become of this work.
The basic goal is to play videos encoded with a number [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a WPF (Windows Presentation Framework) application using Visual C# 2008 Express.  Even though I am at the Initial Optimism phase of Software Development, and my imagination is running wild, I know that nothing will probably become of this work.</p>
<p>The basic goal is to play videos encoded with a number of different codecs (i.e. h.264, Xvid, and DivX).  So, I thought, before I went into all of the other features that this application will do, I&#8217;ll keep things simple and just play a video with the filename hard-coded.</p>
<p>It&#8217;s the year 2008.  I have the latest Microsoft tools available.  Playing a video can&#8217;t be that difficult, can it?<span id="more-23"></span></p>
<p>1) WPF has a native MediaElement&#8230; that only supports wmv files.</p>
<p>2) Microsoft provides a Windows Media Player ActiveX Control (AxWMPLib), that does not seem to be able to use any codecs.  The status displays &#8220;Locating codec&#8221;&#8230; &#8220;Error downloading codec&#8221;, and only plays the audio for the video file.  Using the example from the Windows SDK has the same result.</p>
<p>3) DirectX 9.0 includes a Video class in Microsoft.DirectX.AudioVideoPlayback&#8230; that throws an exception &#8220;Error in the application&#8221; whenever you try to play a video.  I even downloaded an example and built it in Visual Studio 2003, and that doesn&#8217;t work either.</p>
<p>4)  <a href="http://www.videolan.org/">VideoLAN</a> has a <a href="http://wiki.videolan.org/.Net_Interface_to_VLC">.NET Interface</a>&#8230; stored in a wiki.  I guess the concept of a .zip file to download is too much for some developers.  After copying-and-pasting the interface file-by-file, I built it, and got it to play video in the WPF application (by way of the WindowsFormsHost control).</p>
<pre>    VLanControl.VlcUserControl lVideo = new VLanControl.VlcUserControl();</pre>
<pre>    windowsFormsHost1.Child = lVideo;</pre>
<pre>    lVideo.AddToPlayList( "W:/tv/Curb Your Enthusiasm/curb.3x01 - Chet's Shirt.avi", "Curb", null );</pre>
<pre>    lVideo.Play();</pre>
<p>Hooray!  The video played!  I closed the application, ready to finish this off for good, when I experienced a blue screen of death.</p>
<p>As it turns out, you need to stop the video (and maybe clear the playlist) before you exit.</p>
<pre>    protected override void OnClosing( CancelEventArgs e )
    {
        if ( lVideo != null )
        {
            lVideo.Stop();
            System.Threading.Thread.Sleep( 1000 );
            lVideo.ClearPlayList();
            System.Threading.Thread.Sleep( 1000 );
        }
        base.OnClosing( e );
    }</pre>
<p>Be careful&#8230; in WPF, Microsoft decided to remove support for &#8216;OnClosing&#8217;-type events.  You can add an event handler for Closed, but not Closing.  At first, I had tried to add an event for Closed that would stop the video, but because this happened after the window had closed, I still experienced a blue screen.</p>
<p>Also note that the Sleep statements are absolutely necessary.  I tried to get rid of them once, and tried to wait until the VlcUserControl state was no longer &#8216;Playing&#8217;, but the BSOD decided to appear anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redrecondite.com/blog/2008/02/16/playing-video-in-c/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

