<?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>FearTheCowboy</title>
	<atom:link href="http://fearthecowboy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://fearthecowboy.com</link>
	<description>Life of an Open Source Developer</description>
	<lastBuildDate>Sat, 03 Sep 2011 00:30:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Fixing WebRequest&#8217;s desire to throw exceptions instead of returning status</title>
		<link>http://fearthecowboy.com/2011/09/02/fixing-webrequests-desire-to-throw-exceptions-instead-of-returning-status/</link>
		<comments>http://fearthecowboy.com/2011/09/02/fixing-webrequests-desire-to-throw-exceptions-instead-of-returning-status/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 00:30:19 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[CoApp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Asynchronous]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/?p=218</guid>
		<description><![CDATA[My pappy always used to tell me &#8220;There are three kinds of men: The ones that learn by reading. The few who learn by observation. The rest of &#8216;em have to pee on the electric fence.&#8221; &#8230; somedays, I&#8217;m surprised how often I get to pee on the damn fence. So, here I am writing [...]]]></description>
			<content:encoded><![CDATA[<p>My pappy always used to tell me <i>&#8220;There are three kinds of men: The ones that learn by reading. The few who learn by observation. The rest of &#8216;em have to pee on the electric fence.&#8221;</i> &#8230; somedays, I&#8217;m surprised how often I get to pee on the damn fence.</p>
<p>So, here I am writing some code to download files from remote servers, and I wandered across one of the dumbest designs in the .NET framework.</p>
<p>When using <code>WebRequest</code> (really, the child class <code>HttpWebRequest</code> ) write some code to make an HTTP request of the faraway server (I&#8217;m showing the non-async way to keep it simple):</p>
<pre class="brush: c-sharp; toolbar: false">var webRequest = (HttpWebRequest) WebRequest.Create("http://microsoft.com/foo");
webRequest.AllowAutoRedirect = true;
webRequest.Method = WebRequestMethods.Http.Get;

var webResponse = webRequest.GetResponse() as HttpWebResponse;

if( webResponse != null ) {
    Console.WriteLine("Status: {0}", webResponse.StatusCode );

    // ... finish reading from the webResponse....
}</pre>
<p>That&#8217;s fine and dandy. Except one thing; if the request returns 404 NOT FOUND, <code>GetResponse</code> throws an Exception!?!</p>
<p>Now, I can understand how someone might <b>think</b> that not finding the requested resource is exceptional behavior, but it&#8217;s not a condition that I can check for before making the request itself.  It&#8217;s <b>certainly</b> not in the same class of responses as timing out, or not having network connectivity.  </p>
<p>So, through no fault of my own, the code throws an exception without even letting me check to see the result. Which is at best, rude and at worst, the lousiest way to handle that which is not <i><b>exceptional behavior</b></i>. </p>
<p><a href="http://blogs.msdn.com/b/ericlippert/">Eric Lippert</a> calls these <i><a href="http://blogs.msdn.com/b/ericlippert/archive/2008/09/10/vexing-exceptions.aspx">&#8220;Vexing Exceptions&#8221;</a></i></p>
<p>This only gets worse when using the Task Parallel Library in .NET 4.0 :</p>
<pre class="brush: c-sharp; toolbar: false">var webRequest = (HttpWebRequest) WebRequest.Create("http://microsoft.com/foo");
webRequest.AllowAutoRedirect = true;
webRequest.Method = WebRequestMethods.Http.Get;

var task = Task.Factory.FromAsync&lt;WebResponse&gt;(webRequest.BeginGetResponse, webRequest.BetterEndGetResponse , this)
    .ContinueWith(asyncResult =&gt; {
        var webResponse = asyncResult.Result as HttpWebResponse;
        Console.WriteLine("Status: {0}", webResponse.StatusCode );
        // ... finish reading from the webResponse....
    } );
</pre>
<p>So now, rather than checking the response, I have to check the <code>asyncResult.IsFaulted</code> property, grab the <code>asyncResult.Exception</code> property (which is actually an <code>AggregateException</code>), call <code>aggregateException.Flatten()</code> and iterate thru the collection to find the <code>WebException</code>, and ask that object for the <code>WebResponse</code> and from there, get the damn <code>StatusCode</code>&#8230; just so I can find out <b>WHY</b> the damn call failed!</p>
<p>I searched all the way thru the source code in the .NET framework, and I didn&#8217;t see any workaround&#8230; then it hit me. All we have to do is make the call not throw a bleedin&#8217; exception when it actually created a WebResponse.</p>
<p>A quick little static class with a couple extension methods fixes the problem nicely (taken from the CoApp project for where I wrote it):</p>
<pre class="brush: c-sharp; toolbar: false">//-----------------------------------------------------------------------
//
//     Copyright (c) 2011 Garrett Serack. All rights reserved.
//
//
//     The software is licensed under the Apache 2.0 License (the "License")
//     You may not use the software except in compliance with the License.
//
//-----------------------------------------------------------------------

namespace CoApp.Toolkit.Extensions {
    using System;
    using System.Net;

    public static class WebRequestExtensions {
        public static WebResponse BetterEndGetResponse(this WebRequest request, IAsyncResult asyncResult) {
            try {
                return request.EndGetResponse(asyncResult);
            }
            catch (WebException wex) {
                if( wex.Response != null ) {
                    return wex.Response;
                }
                throw;
            }
        }

        public static WebResponse BetterGetResponse(this WebRequest request) {
            try {
                return request.GetResponse();
            }
            catch (WebException wex) {
                if( wex.Response != null ) {
                    return wex.Response;
                }
                throw;
            }
        }
    }
}</pre>
<p>Now, just call <code>webRequest.BetterGetResponse()</code> or <code>webRequest.BetterEndGetResponse()</code> for the async version. Presto, it returns the <code>WebResponse</code> object instead of throwing (and will still throw for truly exceptional reasons.)</p>
<p>If you want to use it with the TPL&#8217;s <code>FromAsync</code> methods, prefix your <code>webRequest.BetterEndGetResponse</code> with the a cast to <code>(Func&lt;IAsyncResult, WebResponse&gt;)</code> before it so that the compiler can curry the extension method into the appropriate delegate for you: </p>
<pre class="brush: c-sharp; toolbar: false">var task = Task.Factory.FromAsync&lt;WebResponse&gt;(
    webRequest.BeginGetResponse, (Func&lt;IAsyncResult, WebResponse&gt;)webRequest.BetterEndGetResponse , this)
    .ContinueWith(asyncResult =&gt; {
        // ... yada yada yada....
    } );
</pre>
<p>Of course, this does mean that you <b>MUST</b> check the <code>webResponse.StatusCode</code>, and that you probably still need want an exception handler, but if you&#8217;re trying to handle truly exceptional cases differently than simple response conditions, I think you&#8217;ll like what you see here.</p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/09/02/fixing-webrequests-desire-to-throw-exceptions-instead-of-returning-status/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A new full-time member for CoApp</title>
		<link>http://fearthecowboy.com/2011/06/02/a-new-full-time-member-for-coapp/</link>
		<comments>http://fearthecowboy.com/2011/06/02/a-new-full-time-member-for-coapp/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 15:31:51 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[CoApp]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/2011/06/02/a-new-full-time-member-for-coapp/</guid>
		<description><![CDATA[I’d like to introduce a new member of our team; Tim Rogers. &#160; Tim is a new full time employee at Microsoft who started this week, and as he just found out yesterday (his first day in the office), is going to be working as a full-time test resource for CoApp. &#160; Tim has a [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;">I’d like to introduce a new member of our team; Tim Rogers. </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;</p>
<p><span style="color: #000000; font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;">Tim is a new full time employee at Microsoft who started this week, and as he just found out yesterday (his first day in the office), is going to be working as a full-time test resource for CoApp. </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;</p>
<p><span style="color: #000000; font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;">Tim has a few words about himself; </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;</p>
<p><span style="color: #000000; font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in;"><span style="color: #1f497d;"><span style="font-family: Calibri;"><span style="font-size: small;">“Tim Rogers is new to Microsoft, fresh out of college.  He has been living in Iowa, attending Iowa State University.  Major interests include technical theater, bicycles, strategy games, and reading.  Tim insists that he is a boring and unimaginative person, so throwing rocks and other things at him is to be encouraged.  This bio was written by the aforementioned boring and unimaginative person.  Feel free to adjust or make things up to your hearts content.</span><span style="font-size: small;">&#8220;</span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="color: #1f497d;"> </span></p>
<p><span style="font-family: Calibri; font-size: small;"> </span></p>
<p>&nbsp;</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;">Apparently, Tim likes to talk about himself in the third person. </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;</p>
<p><span style="color: #000000; font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;">Tim is going to start by tackling the orchestration and test writing for the CoApp engine—the component that gets the most end-user exposure. </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;</p>
<p><span style="color: #000000; font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;">As he gets up to speed, he’ll likely start blogging and filling in the documentation where he can as well. </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;</p>
<p><span style="color: #000000; font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;</p>
<p><span style="color: #000000; font-family: Calibri; font-size: small;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="color: #000000;"><span style="font-family: Calibri;">The Garrett welcomes Tim! </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;">&nbsp;</p>
<p><span style="color: #000000; font-family: Calibri; font-size: small;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/06/02/a-new-full-time-member-for-coapp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shallow-forking a project</title>
		<link>http://fearthecowboy.com/2011/05/09/shallow-forking-a-project/</link>
		<comments>http://fearthecowboy.com/2011/05/09/shallow-forking-a-project/#comments</comments>
		<pubDate>Mon, 09 May 2011 19:19:06 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[CoApp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/?p=192</guid>
		<description><![CDATA[&#160; We’re nearing the point where we’re able to take open source projects and produce happy-shiny packages for them—uh yeah, nearing.  It’s gonna be a couple more weeks shaking out the tools that generate new Visual Studio project files for a given project and wire all that stuff up. The good news though, is that [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>We’re nearing the point where we’re able to take open source projects and produce happy-shiny packages for them—uh yeah, <strong>nearing</strong>.  It’s gonna be a couple more weeks shaking out the tools that generate new Visual Studio project files for a given project and wire all that stuff up.</p>
<p>The good news though, is that we’re ready to have people start shallow-forking projects and sticking them into <a href="https://github.com/">Github</a>.</p>
<p>&nbsp;</p>
<h2>What’s a “shallow-fork” you say?</h2>
<p>A <a href="http://en.wikipedia.org/wiki/Fork_(software_development)"><strong><em>fork</em></strong></a><strong><em> </em></strong>happens when developers take a copy of source code from one software package and starts independent development on it, creating a distinct piece of software.  A <strong><em>shallow-fork</em></strong> is when the independent development continually brings forward changes from the original project, and attempts not to stray very far from it.  We do this so that we can make appropriate Windows changes (like new build scripts, or better API support) keep compatibility and not break the original project.  If the upstream project is willing to accept changes, great! If not (for whatever reason)… great! Either way, the package maintainer for the CoApp project will aim to keep the projects in sync as much as possible.</p>
<p>Linux distributions do this sort of thing all the time, in order to build packages for their specific version of Linux.  We’re essentially following in the same footsteps, but following the procedure that I’m setting out here, so that we can eventually produce packages of software for CoApp.</p>
<p>&nbsp;</p>
<h2>Can You Help?</h2>
<p>We’re looking for people to start the leg-work for building packages—right now, this means creating a fork in github, and doing the work to get it compiling under Windows—no matter how it’s done (i.e., you can use a makefile, VS project files, a batch file… whatever). The idea is to just get a successful build that can be replicated on a known configuration&#8211;Visual Studio 2010 (even <a href="http://www.microsoft.com/express/Downloads/"><em>VS 2010 express</em></a>), and the <a href="http://download.microsoft.com/download/A/6/A/A6AC035D-DA3F-4F0C-ADA4-37C8E5D34E3D/winsdk_web.exe">Windows SDK 7.1</a> … We’ll be automating the work later that creates well-built VS 2010 project files (and eventually other builds like mingw, etc), but that work will leverage the effort done now to create consistent shallow-forks.</p>
<p>&nbsp;</p>
<h2>What do you need?</h2>
<ol>
<li>The aforementioned Visual Studio 2010 (<a href="http://www.microsoft.com/express/Downloads/"><em>the express version</em></a> will do), and the <a href="http://download.microsoft.com/download/A/6/A/A6AC035D-DA3F-4F0C-ADA4-37C8E5D34E3D/winsdk_web.exe">Windows SDK 7.1</a> .&nbsp;</li>
<li><a href="https://github.com/signup/free">An account on github</a>, and the ability to check stuff in (you can use <a href="http://code.google.com/p/msysgit/">msysgit</a> or <a href="http://code.google.com/p/tortoisegit/">tortoisegit</a> , or any other git client for Windows—even the <a href="http://mercurial.selenic.com/downloads/">Mercurial</a> plugin <a href="http://hg-git.github.com/">hg-git</a>, which lets you use git repositories as if they were mercurial repositories. (<strong>Note</strong>: <em>I tried the hg-git plugin, and had to use the version </em><a href="https://github.com/sampsyo/hg-git"><em>here</em></a><em> to get it to work</em>)&nbsp;</li>
<li>The ability to build software using Visual Studio—we need command line builds, but if you get it working from inside the IDE, we can show you how to automate that from the command line in a single step.</li>
<li>The ability to follow the pretty-darn-simple process below to produce the necessary build.</li>
<li>A current build of the CoApp tools. You can <a href="http://fearthecowboy.com/2011/04/26/weve-moved-coapp-code-hosting-to-github/">compile them yourself</a>, or just download <a href="http://coappstorage.blob.core.windows.net/files/coapp-tools-snapshot.zip">my latest snapshot build</a>. Make it easy on yourself, put them in a folder that’s in the %PATH%.</li>
</ol>
<ul>
<h5></h5>
</ul>
<h2>Becoming a package maintainer</h2>
<p>The first thing is to get yourself added as a CoApp package-maintainer on github—no worries, signing up for this isn’t a lifelong commitment. If you are interested in keeping it moving over the long haul, that’s great, but even if you can just do up a few projects and get them checked in, we’ll figure out the long term maintenance strategy later.</p>
<p>In order to get added to the package maintainer group you can send me a message on github (fearthecowboy) or via <a href="mailto:garretts@microsoft.com">email</a>, or heck, even just send me a <a href="http://twitter.com/home?status=Hey%2C+%40fearthecowboy%21+I%27d+like+to+become+a+%23CoApp+package+maintainer.+My+github+id+is+..." target="”_blank”">tweet me</a>. All I need is your github account id, and I’ll add you to the group.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Wait! Before You Begin…</h2>
<p>Since shallow-forking is intended to continually merge in changes from upstream, please keep changes to the project and its files to an absolute minimum—don’t do any unnecessary changes, don’t reorganize the files, and don’t try to rebuild a ‘cleaner’ build process.  You only need to get it to the point where it builds a viable output.  As we progress, we’ll capture the data from the process and build shiny new project files that are much nicer—expending extra effort now doesn’t get you anywhere.</p>
<h2></h2>
<p>&nbsp;</p>
<h2>If you run into trouble, and need help</h2>
<p>Check on IRC—#coapp on freenode.net (try the <a href="http://webchat.freenode.net/">webclient</a> if you don’t have IRC installed)—if I’m there, I’m more than willing you help you thru the steps (and fix stuff that needs fixing), or failing that on the <a href="https://launchpad.net/~coapp-developers">mailing list.</a></p>
<p>&nbsp;</p>
<h2></h2>
<h2>The Process for Shallow-Forking for CoApp packages</h2>
<p><em><strong>Quick Note: </strong>This is the first iteration of the Shallow-Fork process—there are a number of deeper issues when forking projects that have multiple active branches, several configurations, etc.  What we’re trying to do here is lay out a common approach so that as we proceed, we can automate as much as possible over the long run.   This procedure is likely to evolve quite a bit as we account for more scenarios and add support for additional compilers, configurations and build types.</em></p>
<p>&nbsp;</p>
<ol>
<li>Find an open source C/C++ library or application that you’d like to fork.  You can <a href="http://wiki.coapp.org/Shallow-Fork-Package-List.ashx">select one off the list of things that we know we really need</a>, or something else that of particular interest to you, and for which you’d like to see a CoApp package created.  If the project that you want to build has things that it depends on, you may need to go ahead and provide the shallow-fork for that as well—we do not want to rely on binary builds that someone else has provided, that would be kinda silly.&nbsp;</li>
<li>Create a project in Github. Depending on what you’re trying to make a fork of, you’re going to do this in one of a few different ways.  If the project is already on github, create a fork for it in the coapp-packages organization. If the source is posted as a zip file, unpack it and create the project manually. If it’s in another VCS, there may be a generally-acceptable method to creating a fork in git.  Bottom line, get the project into Github in a project in the coapp-packages organization.</li>
<li>Clone the source code into your working directory.</li>
<li>Create a folder in the root of the project called <strong>COPKG</strong>.&nbsp;</li>
<li>Create a text file in the folder called <strong>.buildinfo</strong>—this is the file that you will be putting the build steps into.The format of the <strong>.buildinfo </strong>file can be thought of something akin to a .css file.  Simple values need not be quoted (but it’s ok to do so).  It supports comments ( double-slash and /* */), C# style string literals (may be preceded by an @ symbol to make a string multi-line).
<p>Inside the <strong>.buildinfo </strong>file,  insert the following:</p>
<pre class="brush: c-sharp; toolbar: false">#product-info  {
    product-name: "";
    version: "";
    original-source-location: "";
    original-source-website: "";
    license: "";
    packager: "";
}</pre>
<p>You can fill in the values of each of the fields. An example for libjpeg (done by <a href="http://withinwindows.com">Rafael</a>)</p>
<pre class="brush: c-sharp; toolbar: false">#product-info  {
    product-name: "libjpeg";
    version: "8c";
    original-source-location: "http://ijg.org/files/jpegsr8c.zip";
    original-source-website: "http://ijg.org";
    license: "Custom license, see README";
    packager: "Rafael Rivera &lt;rafael@withinwindows.com&gt;";
}</pre>
</li>
<li>Create one or more <strong>Build Configurations</strong>A “Build Configuration” is analogous to a build configuration with Visual Studio—You can create builds for x86, x64, as well as for different flavors (static library vs. dynamic library) etc.  It’s not necessary to explicitly create multiple build configuration for x86 and x64 if project compiles well under both without different commands (save for the selection of which platform).  You <strong>do </strong>want multiple configurations when the steps change between platforms (or you know that different files get processed—in some libraries, there are separate files for x86 vs. x64), or if you have different expected outputs—i.e. some libraries allow you to generate a static and a dynamic version of the same library).  Generally speaking, err on the side of caution and don’t create multiple build configurations excessively—for projects that behave themselves, we’ll autogenerate the alternate configurations when we get around to creating new Visual Studio projects.
<p>The build configuration syntax:</p>
<pre class="brush: c-sharp; toolbar: false">name  {
    /* optional -- defaults to vc10-x86 */
    compiler: compiler-tag ;
            // currently supported values are vc10-x86 and vc10-x64
            //... we'll add more compilers in the future.

    /* optional -- only used if this project has dependencies on others
                -- may be specified mutiple times */
    uses: bld-cfg="..\path" ;
            // bld-cfg is the build configuration in dependent project
            // the 'blg-cfg=' part can be omitted to depend on the default
            // path is to the root path of the dependent project that
            // contains a COPKG\.buildinfo file.

    targets: { ... } ;
            // a comma seperated list of the binary files that are output
            // that are of significance

    build-command: "";
            // either a single command line, or a batch script
            // that has the commands to build the targets listed above.

    clean-command: "";
            // either a single command line, or a batch script
            // that has the commands to remove all temporary files
            // created during a build.
}</pre>
<p>The above libjpeg example continued – note that there isn’t any <strong>uses </strong>option:</p>
<pre class="brush: c-sharp; toolbar: false">x86 {
    compiler: vc10-x86;

    targets: {
        // main library
        "Release\jpeg.lib",

        // extra utilities
        "cjpeg\Release\cjpeg.exe",
        "djpeg\Release\djpeg.exe",
        "jpegtran\Release\jpegtran.exe",
        "rdjpgcom\Release\rdjpgcom.exe",
        "wrjpgcom\Release\wrjpgcom.exe",
    };

    build-command:@"
        copy jconfig.vc jconfig.h
        copy makejsln.v10 makejsln.sln
        copy makeasln.v10 makeasln.sln
        copy makejvcx.v10 jpeg.vcxproj
        copy makecvcx.v10 cjpeg.vcxproj
        copy makedvcx.v10 djpeg.vcxproj
        copy maketvcx.v10 jpegtran.vcxproj
        copy makewvcx.v10 wrjpgcom.vcxproj
        copy makervcx.v10 rdjpgcom.vcxproj
        msbuild /p:Platform=Win32 /p:Configuration=Release makejsln.sln
        msbuild /p:Platform=Win32 /p:Configuration=Release makeasln.sln
    ";

    clean-command:@"
        attrib -S -H -R *
        del /Q *.sdf *.suo *.sln *.vcxproj *.user jconfig.h 2&gt;NUL
        rmdir /S /Q Release 2&gt;NUL

        rmdir /S /Q cjpeg 2&gt;NUL
        rmdir /S /Q djpeg 2&gt;NUL
        rmdir /S /Q ipch 2&gt;NUL
        rmdir /S /Q jpegtran 2&gt;NUL
        rmdir /S /Q rdjpgcom 2&gt;NUL
        rmdir /S /Q wrjpgcom 2&gt;NUL
    ";
};</pre>
<p>&nbsp;</li>
<li>Once you have the .buildinfo file complete, you can run the pTk tool from the command line (make sure you’re in the root of the project).<strong>You should be able to run a build: </strong>
<pre class="brush: plain; toolbar: false">C:\forks\libjpeg&gt;ptk clean

CoApp Project pTk Version 1.0.2.906 for x64
Copyright (c) Garrett Serack, CoApp Contributors 2010-2011. All rights reserved
CoApp portingToolkit for porting apps
-------------------------------------------------------------------------------

    ( build happens here ... )

Project Built.

C:\forks\libjpeg&gt;</pre>
<p><strong>&#8230; and a clean : </strong></p>
<pre class="brush: plain; toolbar: false">C:\forks\libjpeg&gt;ptk clean

CoApp Project pTk Version 1.0.2.906 for x64
Copyright (c) Garrett Serack, CoApp Contributors 2010-2011. All rights reserved
CoApp portingToolkit for porting apps
-------------------------------------------------------------------------------

    ( build happens here ... )

Project Built.

C:\forks\libjpeg&gt;</pre>
<p><strong>&#8230; and a verify (where it builds, verifies the build targets, cleans, and verifies everything is clean): </strong></p>
<pre class="brush: plain; toolbar: false">C:\forks\libjpeg&gt;ptk verify
CoApp Project pTk Version 1.0.2.906 for x64
Copyright (c) Garrett Serack, CoApp Contributors 2010-2011. All rights reserved
CoApp portingToolkit for porting apps
-------------------------------------------------------------------------------
 ( build happens here ... )

Targets Verified.
Project Verified.

C:\forks\libjpeg&gt;</pre>
<p>&nbsp;</li>
<li>Once it does what you expect, commit and push the clean version up to github, and give me a shout.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/05/09/shallow-forking-a-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speaking tomorrow at VanLUG!</title>
		<link>http://fearthecowboy.com/2011/05/04/speaking-tomorrow-at-vanlug/</link>
		<comments>http://fearthecowboy.com/2011/05/04/speaking-tomorrow-at-vanlug/#comments</comments>
		<pubDate>Wed, 04 May 2011 15:18:24 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Speaking]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/?p=186</guid>
		<description><![CDATA[I&#8217;ll be in Canada tomorrow at the Vancouver Linux User Group meeting. I&#8217;ll be talking about Microsoft, Open Source and CoApp. If you are interested in showing up: Time: 7:30 PM-10 PM Where: iQmetrix offices 250 Howe Street &#8211; Suite 1210 Vancouver, BC V6C 3R8 CANADA I&#8217;d love to have ya&#8217;ll out! And, Pizza &#038; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be in Canada tomorrow at the Vancouver Linux User Group meeting. I&#8217;ll be talking about Microsoft, Open Source and CoApp.</p>
<p>If you are interested in showing up:</p>
<p><strong>Time</strong>: 7:30 PM-10 PM<br />
<strong>Where</strong>:  iQmetrix offices<br />
250 Howe Street &#8211; Suite 1210<br />
Vancouver, BC<br />
V6C 3R8 CANADA</p>
<p>I&#8217;d love to have ya&#8217;ll out!</p>
<p>And, Pizza &#038; drinks are provided!</p>
<p>G</p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/05/04/speaking-tomorrow-at-vanlug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yeah, we&#8217;re still Alive!</title>
		<link>http://fearthecowboy.com/2011/05/03/yeah-we-rsquo-re-still-alive/</link>
		<comments>http://fearthecowboy.com/2011/05/03/yeah-we-rsquo-re-still-alive/#comments</comments>
		<pubDate>Tue, 03 May 2011 15:30:53 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/2011/05/03/yeah-we-rsquo-re-still-alive/</guid>
		<description><![CDATA[It has been an extreme amount of time since I’ve done a status update—we’ve been working hard here, honest!&#160; Under a stack of what seems like a million little things, blogging has taken a backseat to development in recent months, but I’m hoping to correct that (and have some others do some blog posts too!) [...]]]></description>
			<content:encoded><![CDATA[<p>It has been an extreme amount of time since I’ve done a status update—we’ve been working hard here, honest!&#160; Under a stack of what seems like a million little things, blogging has taken a backseat to development in recent months, but I’m hoping to correct that (and have some others do some blog posts too!)</p>
<p align="left">As you can see, we’re on a new site; this is powered by <a href="http://orchardproject.net/">Orchard</a>, an open source CMS for Windows.&#160; I chose this, primarily because it’s built to run on <a href="http://www.microsoft.com/windowsazure/">Azure</a> as well as Windows Server, and the kind folks at Microsoft have given me an Azure account with plenty of resources.&#160; I also spun up a <a href="http://screwturn.eu/">Screwturn</a> Wiki for documentation (it’s what the Orchard guys use for their site, so I followed suit).&#160; </p>
<p align="left">The new site is a tad bare right now, but hopefully we’ll get this all put together over the next couple of weeks.</p>
<h2>A new code repository</h2>
<p>As I <a href="http://fearthecowboy.com/2011/04/26/weve-moved-coapp-code-hosting-to-github/">mentioned on my blog last week</a>, we also moved our code repository over to github: </p>
<ul>
<ul>
<li><em>While I liked a lot of the things about Launchpad, the website is feeling slower and slower some days, and Bazaar, while offering the features that I like, isn’t getting the attention (and developer resources) that git is.&#160; Combined with the fantastic innovation happening at Github, it’s undeniably the go-to place for open source development these days.          <br /></em></li>
<li><em>And, having done some recent tests with git on Windows, it’s clear that it’s stable and feature rich enough for all my purposes.</em> </li>
</ul>
</ul>
<p><em></em></p>
<p>Along with that I also talk about how to checkout the code and compile it up.&#160; Yes, it’s still an iceberg (most of the code isn’t about what you see) but beneath that surface there is a huge amount of functionality lurking.</p>
<h2>Current Status</h2>
<p>The last six months have had a flurry of code development done, including essentially the entire CoApp engine—originally we were hoping that the volunteer work by the group at the University of Syracuse would produce a functional prototype,&#160; it turned out to be too-aggressive of a goal.&#160; Consequently, the entire engine was written in three months, and diverted my attention away from other things (this site being one of them)</p>
<h4>Where we at:</h4>
<h5>&#160;</h5>
<h5>CoApp Core: </h5>
<ul>
<li><strong>CoApp toolkit </strong>– all of CoApp’s shared code ends up in the toolkit project. A cornucopia of functionality, it provides a tremendous amount of simple, reusable functionality that is shared across all projects.       </li>
<li><strong>CoApp Engine </strong>– we have a managed version of the engine with the basic v1 functionality complete, I’d say that it’s in a solid beta stage at this point.&#160; </li>
<li><strong></strong></li>
<li><strong>CoApp Command Line Client </strong>– the command line client works pretty good, if a tad verbose on the command line. It’s pretty optimized for the happy-path at this point, but still a pretty good beta. </li>
</ul>
<p>&#160;</p>
<h5>Publisher Tools:</h5>
<ul>
<li><strong>mkPackage</strong> – the first tool to create packages for CoApp has been working, but it turned out it took an awful lot of effort to build a package, so we’ve depricated that, and gone back to the drawing board. The result, is Autopackage—a tool designed to do what we really wanted, which is creating packages without messy XML, no need to understand MSI or WiX, or even code signing.&#160; </li>
<li><strong>Autopackage</strong>—is designed to eliminate 100% of the understanding and guesswork in creating packages for consumption.&#160; It’s already functional and able to produce packages, and is nearing the ‘alpha’ stage.&#160; Eric has done an amazing amount of work in a short time to produce something that is going to get a lot of attention. </li>
<li><strong>simplesigner – </strong>even simple code signing operations are a hassle in Windows, and when you add .NET strong-naming into the mix, it’s all a little difficult to get a hold of, so I wrote the simplesigner tool.. It does exactly what it says, <em>makes digital signing software </em>on Windows <strong>simple</strong>.&#160; For .NET executable binaries, it both signs and strong-names the result, and eliminates the guesswork and frustration entirely. </li>
<li></li>
</ul>
<h5>Developer Tools:</h5>
<ul>
<li><strong>Scan</strong>—Trevor knocked out the first beta of this tool way back in October,&#160; It does exactly as I‘d hoped, a very useful scan of a source tree, and brings back a very large amount of useful data.&#160; On top of it’s use as part of mkSpec, it’s also quite handy on it’s own to get an idea of what a project uses, and how it all fits together. Solid 1.0 material. </li>
<li><strong>Trace</strong>—The ultimate evolution of my original 32 bit trace utility, Rafael and I have put an insane amount of work into this tool.&#160; Trace can watch a program, and all of its child processes and record every single file access (and <em>how </em>it was accessed), and record the environment, and command lines for every process.&#160; It works for nearly every type of application we’ve thrown at it: 32bit, 64bit, .NET, cygwin, native… The data it gets back is extremely valuable—we use it primarily to feed into the mkSpec tool to produce project files, but it has a lot of use on it’s own.&#160; It even captures some data that you can’t get from Sysinternals’ ProcMon. We’re pretty much 1.0 gold here.
<p><strong>mkSpec</strong>—The tool that generates a ‘compiler-independent’ project file from scan and trace data.&#160; It’s getting really close to beta stage—I just need to leverage the latest trace info and we should be on our way.       </p>
<p><strong>mkProject</strong> – the secret sauce of the entire CoApp project.&#160; mkProject takes project info from mkSpec and produces Visual Studio project files that are consistent, clean and support easy use of advanced features like PGO optimization, etc.&#160; Still a work in progress—probably a few weeks away from a beta.       </li>
<li><strong>testpackagemaker – </strong>development of the package manager requires a lot of testing examples, and this tool simplifies the generation of native and .NET executables and libraries that support side-by-side so we can build packages for testing. Solid 1.0 stuff here. </li>
<li><strong>pTk </strong>– a recent addition to the CoApp developer tool lineup, pTk (aka the <strong><em>porting Toolkit</em></strong>)&#160; is a build automation tool (no, not like make or msbuild).&#160; pTk provides a method for package maintainers to express ‘how-to-build’ a given project so that the process can be automated by other tools without understanding anything about the build whatsoever (this will let us automate the trace/mkSpec/mkProject process <strong>*a lot*.</strong>)&#160; Rather than having the package maintainer/developer express a build process in its terms, it simply is a way of letting the developer write down the commands to build a given project (as a command, or batch script, or whatever) and provides an automatable wrapper for that.&#160; This is definitely release candidate material. </li>
</ul>
<p>&#160;</p>
<h5>Productivity Tools:</h5>
<ul>
<li><strong>quicktool </strong>– During development, it’s always so useful to share code, screenshots etc. when working remotely (either live, via Skype, Lync or IRC) or even via Twitter or email. quicktool provides a system-wide hot-key to uploading images, formatted source snippets, and shortening URLs without having to bring up a separate tool or browser to do so.&#160; Faster and more convenient than clumsy websites like pastebin, it allows developers to easily share information at a single keypress. </li>
<li></li>
</ul>
<p>&#160;</p>
<p>That’s about it for today… over the next few days I’ll be posting some tutorials (ie, how to shallow fork a Project for CoApp) and some more information on how you can get involved if you’re inclined.</p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/05/03/yeah-we-rsquo-re-still-alive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting bazaar repositories to git</title>
		<link>http://fearthecowboy.com/2011/04/29/converting-bazaar-repositories-to-git/</link>
		<comments>http://fearthecowboy.com/2011/04/29/converting-bazaar-repositories-to-git/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 17:06:45 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[bzr]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/?p=177</guid>
		<description><![CDATA[I recently moved the CoApp source repositories from Launchpad to github, and I wanted make sure that I preserved all the commit history along with it. Fortunately, it’s not too terribly difficult to move from one to the other (provided you jump thru the hoops to getting fast-import working on bzr for Windows). Fixing Bzr [...]]]></description>
			<content:encoded><![CDATA[<p>I recently moved the CoApp source repositories from Launchpad to github, and I wanted make sure that I preserved all the commit history along with it. Fortunately, it’s not too terribly difficult to move from one to the other (provided you jump thru the hoops to getting fast-import working on bzr for Windows).</p>
<h2>Fixing Bzr for Windows</h2>
<p>Bzr on Windows supports fast import—except that the installer doesn’t install the fast-import python module when it installs python.&#160; Easy enough to fix. You need to grab a copy of the <strong>fast-import </strong>module from launchpad:</p>
<pre class="brush: plain; toolbar: false">C:\tmp&gt;bzr clone lp:python-fastimport
Connected (version 2.0, client Twisted)
Authentication (publickey) successful!
Secsh channel 1 opened.
Branched 301 revision(s).</pre>
<p>And then combine it with the library.zip file that’s already in the Bazaar install directory using zip (I used the command line zip utility from <a href="ftp://ftp.info-zip.org/pub/infozip/win32/zip232dn.zip">infozip</a>) &#8230;</p>
<pre class="brush: plain; toolbar: false">C:\tmp&gt;cd python-fastimport

C:\tmp\python-fastimport&gt;zip -r &quot;c:\Program Files (x86)\Bazaar\lib\library.zip&quot; *</pre>
<p>&#160;</p>
<p>Once you’ve done that, it’s really trivial to move a .bzr repository to a git one:</p>
<pre class="brush: plain; toolbar: false">C:\tmp&gt;mkdir someproject

C:\tmp&gt;cd someproject

C:\tmp\someproject&gt;git init
Initialized empty Git repository in C:/tmp/someproject/.git/

C:\tmp\someproject&gt;bzr fast-export --plain YOUR-BZR-REPO | git fast-import</pre>
<p>&#160;</p>
<p>Where <strong>YOUR-BZR-REPO</strong> is the path to your bazaar repository&#8211;it can be a path to a local repo, or a remote location (like, lp:projectname).<br />
  </p>
<p>It will spit out some information, and then you need to:</p>
<pre class="brush: plain; toolbar: false">C:\tmp\someproject&gt;git checkout master
Already on 'master'</pre>
<p>&#160;</p>
<p>Now, you&#8217;ve got a shiny new git repo from your bazaar repo, and you can play with it as you will.</p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/04/29/converting-bazaar-repositories-to-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We&#8217;ve Moved CoApp code hosting to Github</title>
		<link>http://fearthecowboy.com/2011/04/26/weve-moved-coapp-code-hosting-to-github/</link>
		<comments>http://fearthecowboy.com/2011/04/26/weve-moved-coapp-code-hosting-to-github/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 22:47:46 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[CoApp]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/?p=171</guid>
		<description><![CDATA[Just a quick update today—we’ve moved the source repositories for CoApp from Launchpad to Github. While I liked a lot of the things about Launchpad, the website is feeling slower and slower some days, and Bazaar, while offering the features that I like, isn’t getting the attention (and developer resources) that git is.  Combined with [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick update today—we’ve moved the source repositories for CoApp from Launchpad to <a href="https://github.com/coapp">Github</a>.</p>
<p>While I liked a lot of the things about Launchpad, the website is feeling slower and slower some days, and Bazaar, while offering the features that I like, isn’t getting the attention (and developer resources) that git is.  Combined with the fantastic innovation happening at Github, it’s undeniably the go-to place for open source development these days.</p>
<p>&nbsp;</p>
<p>And, having done some recent tests with git on Windows, it’s clear that it’s stable and feature rich enough for all my purposes.</p>
<p>&nbsp;</p>
<p>Updated for use on Github:</p>
<p><strong><span style="text-decoration: underline;">The following is the instructions on how to build the current CoApp bits:</span></strong></p>
<p><strong> </strong></p>
<p><strong>0. You need to have the following tools installed in order to build CoApp:</strong></p>
<p>Visual Studio 2010 (I&#8217;m told that VS 2010 Express will work)</p>
<p>Windows SDK 7.0 or higher &#8212; <a href="http://bit.ly/bOoxJT">http://bit.ly/bOoxJT</a></p>
<p>Windows WDK 7.1 &#8212; <a href="http://bit.ly/cU1lvH">http://bit.ly/cU1lvH</a></p>
<p>msysgit for Windows 1.7.4 &#8212; <a href=http://code.google.com/p/msysgit/downloads/detail?name=Git-1.7.4-preview20110204.exe">http://code.google.com/p/msysgit/downloads/detail?name=Git-1.7.4-preview20110204.exe</a><br />
(this is a command line git client &#8211;there are also other GUIs available.)</p>
<p>Putty (&amp; Pageant) &#8212; <a href="http://bit.ly/awE3jd">http://bit.ly/awE3jd</a> &#8211;get the putty-0.60-installer.exe</p>
<p><strong><br />
</strong></p>
<p><strong>NOTE: I had issues with the SSH client in msysgit; you may need to run the command :<br />
</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<pre class="brush: php; toolbar: false">c:\coapp&gt; SET GIT_SSH=PLINK.EXE</pre>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>(assuming that PLINK is installed in your PATH somewhere)</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>1.0. Create and account for Github.</strong></p>
<p><strong>1.1. Run Pageant, load your private key.</strong></p>
<p><strong>2. Download the following script:</strong></p>
<p><strong> </strong></p>
<p><strong> </strong><a href="https://github.com/downloads/fearthecowboy/coapp/coapp-src.cmd">https://github.com/downloads/fearthecowboy/coapp/coapp-src.cmd</a></p>
<p><strong> </strong></p>
<p><strong>3. Unzip the script into your working directory (where you want to check out the source to)</strong></p>
<p><strong> </strong></p>
<p><strong>4. From the command line:</strong></p>
<p><strong> </strong></p>
<pre class="brush: php; toolbar: false"> C:\coapp&gt; coapp-src

   Usage:
   ------
   coapp-src.cmd [OPTION]

   where [OPTION] is one or more of:

       core        - just the core projects to build the package manager
       gui         - the prototype work on the GUI client
       tools       - the developer and publisher tools
       guts        - the guts of the bootstrap and installershim
       other       - garrett's other tools and oddities
       all         - all of the above

       update      - merges updates for any projects that are already checked out.

    You can check out a portion of the code (or all, if you want) by using the script:

   C:\coapp&gt; coapp-src core</pre>
<p><strong> </strong></p>
<p><strong> Will check out just the core (coapp-cli, coapp-toolkit and coapp-solution).</strong></p>
<p>&nbsp;</p>
<p><strong> </strong></p>
<p><strong>4. Open the coapp-solution\coapp-tools.sln solution file in Visual Studio 2010</strong></p>
<p>If you didn’t get all of the projects, you’ll see an error when visual studio tries to load</p>
<p>projects that are not checked out; this is ok, you can ignore the error (or delete the</p>
<p>projects that are missing from your solution file)</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>5. Build it. (ctrl-shift-b) </strong><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong>Make sure you build the <strong>debug</strong> version, you won’t be able to build the release</p>
<p>(you’d need my private cert, and it does some funky stuff during the build process)</p>
<p><strong> </strong></p>
<p><strong>6. The output will be in [root]\output\any\debug\bin:</strong></p>
<p><img src="https://lists.launchpad.net/coapp-developers/pngmCpn5LaqLk.png" border="0" alt="" /></p>
<p>And you should be able to run the coapp.exe in that directory:</p>
<p><img src="https://lists.launchpad.net/coapp-developers/pngCeGiItLv6e.png" border="0" alt="" /></p>
<p>You’ll notice the packages that I installed from the <a href="http://coapp.org">http://coapp.org</a> website are installed.</p>
<p>All coapp binaries (except for the bootstrapper itself) are built as ‘any’ (meaning they will run 64bit on x64 systems, and 32bit on x86  systems)</p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/04/26/weve-moved-coapp-code-hosting-to-github/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Binding Events to .NET 4.0 Tasks instead of Objects (Part 2)</title>
		<link>http://fearthecowboy.com/2011/04/13/binding-events-to-net-4-0-tasks-instead-of-objects-part-2/</link>
		<comments>http://fearthecowboy.com/2011/04/13/binding-events-to-net-4-0-tasks-instead-of-objects-part-2/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 21:39:19 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[CoApp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Asynchronous]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/?p=160</guid>
		<description><![CDATA[In my last post, I showed how we’re binding event handlers to the Task after it’s already been started. This of course, is probably not what you want, as it’s possible to lose some events if the task starts up quick enough. So, the CoTask task factory also lets you pass the event listeners as [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://fearthecowboy.com/2011/04/13/binding-events-to-net-4-0-tasks-instead-of-objects-part-1/">last post</a>, I showed how we’re binding event handlers to the Task after it’s already been started. This of course, is probably not what you want, as it’s possible to lose some events if the task starts up quick enough.</p>
<p>So, the <strong>CoTask</strong> task factory also lets you pass the event listeners as part of the task creation call, you just have to instantiate the TestEvents class and use an object initializer to set the value of the event handler:</p>
<pre class="brush: c-sharp; toolbar: false">// *** Example Two ***
// Listening to events
// but attaching before the task is started
var taskTwo = CoTask.Factory.StartNew(() =&gt; {
    for (var q = 10; q &gt; 0; q--) {
        // simulate a longer running operation
        Thread.Sleep(200);

        // that occasionally notifies anyone who cares to listen.
        TestEvents.Invoke.Message1("Message From taskTwo", q);
    }
}, new TestEvents {
    Message1 = (s, i) =&gt; {
        Console.WriteLine("The Task said: [{0}] and [{1}] ", s, i);
    }
} );

Console.WriteLine("\r\n(Main Thread Completed)======&gt;Press Enter to end.\r\n");
Console.ReadLine();</pre>
<p>In line 12 you can see where I just tack on the instance of the TestEvents class as the last parameter in the call to StartNew() .  By passing the event listener earlier, this allows the caller to not miss out on any events:</p>
<p><a href="http://fearthecowboy.com/wp-content/uploads/2011/04/task_2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" title="task_2" src="http://fearthecowboy.com/wp-content/uploads/2011/04/task_2_thumb.png" border="0" alt="task_2" width="646" height="230" /></a></p>
<p>Much Better!</p>
<p>Now, what if the class that had the events in it had more than one event:</p>
<pre class="brush: c-sharp; toolbar: false"> public class TestEvents : MessageHandlers&lt;TestEvents&gt; {
     public Action&lt;string, int&gt; Message1;
     public Action&lt;string, string&gt; Message2;
     public Action&lt;string&gt; Message3;
 }</pre>
<p>Well, can go ahead and implement the ones you want, and leave the ones you don’t:</p>
<pre class="brush: c-sharp; toolbar: false">// *** Example Three ***
// Listening to multiple events
var taskThree = CoTask.Factory.StartNew(() =&gt; {
    for (var q = 10; q &gt; 0; q--) {
        // simulate a longer running operation
        Thread.Sleep(200);

        // fire a different message for different values:
        switch(q % 3) {
            case 0:
                TestEvents.Invoke.Message1("Message1 From taskThree", q);
                break;
            case 1:
                TestEvents.Invoke.Message2("Message2 From taskThree", "Just more text");
                break;
            case 2:
                TestEvents.Invoke.Message3("Message3 From taskThree");
                break;

        }
    }
}, new TestEvents {
    Message1 = (aString, anInt) =&gt; {
        Console.WriteLine("The Task said a string and an int: [{0}] and [{1}] ", aString, anInt);
    },
    Message2 = (aString1, aString2) =&gt; {
        Console.WriteLine("The Task said two strings: [{0}] and [{1}] ", aString1, aString2);
    }
} );

Console.WriteLine("\r\n(Main Thread Completed)======&gt;Press Enter to end.\r\n");
Console.ReadLine();</pre>
<p>And when you run that, you see that we’re able to handle the messages that we’re interested in:</p>
<p><a href="http://fearthecowboy.com/wp-content/uploads/2011/04/task_3.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" title="task_3" src="http://fearthecowboy.com/wp-content/uploads/2011/04/task_3_thumb.png" border="0" alt="task_3" width="647" height="186" /></a></p>
<p>Note the lack of messages for <strong>Message3</strong>.</p>
<p>You can also have the Task actually ask for a result from the listener as well—if nobody’s listening, it’ll return the ‘default’ value (0 or null) for the type requested:</p>
<pre class="brush: c-sharp; toolbar: false">public class TestEvents : MessageHandlers&lt;TestEvents&gt; {
    public Action&lt;string, int&gt; Message1;
    public Action&lt;string, string&gt; Message2;
    public Action&lt;string&gt; Message3;
    public Func&lt;int, bool&gt; ShouldWeCancel;
}</pre>
<p>And, a little code showing how it’s used:</p>
<pre class="brush: c-sharp; toolbar: false">// *** Example Four ***
// Listening to multiple events
var taskFour = CoTask.Factory.StartNew(() =&gt; {
    for (var q = 0; q &gt; 100; q++) {
        // simulate a longer running operation
        Thread.Sleep(200);

        if( TestEvents.Invoke.ShouldWeCancel(q)) {
            // Note: this is not a really good way to actually cancel a Task
            //       you should really use a TaskCancellationSource object
            //       and do it right.
            break;
        }

        // fire a different message for different values:
        switch(q % 3) {
            case 0:
                TestEvents.Invoke.Message1("Message1 From taskFour", q);
                break;
            case 1:
                TestEvents.Invoke.Message2("Message2 From taskFour", "Just more text");
                break;
            case 2:
                TestEvents.Invoke.Message3("Message3 From taskFour");
                break;
        }
    }
}, new TestEvents {
    Message1 = (aString, anInt) =&gt; {
        Console.WriteLine("The Task said a string and an int: [{0}] and [{1}] ", aString, anInt);
    },
    Message2 = (aString1, aString2) =&gt; {
        Console.WriteLine("The Task said two strings: [{0}] and [{1}] ", aString1, aString2);
    },
    ShouldWeCancel = (anInt) =&gt; {
        if( anInt &gt; 12 ) {
            return true;
        }
        return false;
    }
} );

Console.WriteLine("\r\n(Main Thread Completed)======&gt;Press Enter to end.\r\n");
Console.ReadLine();</pre>
<p>Voila! The task is now asking for information from the listener:</p>
<p><a href="http://fearthecowboy.com/wp-content/uploads/2011/04/task_4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" title="task_4" src="http://fearthecowboy.com/wp-content/uploads/2011/04/task_4_thumb.png" border="0" alt="task_4" width="643" height="210" /></a></p>
<p>You can see that the Task broke out of the loop when the listener responded to the ShouldWeCancel query with true.</p>
<p>&nbsp;</p>
<p>There are obviously a few limitations in using a function to get data back from the listener—it’s only able to get a value back from the first listener that responds (I’ve got an idea for how to aggregate up stuff, but not an actual personal use case yet, so unless someone asks, that’ll be on the ‘todo later’ list … <img src='http://fearthecowboy.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  ) … and you can’t tell the difference between a zero or null response and the lack of response. Still, kinda handy in a couple of cases.</p>
<p>&nbsp;</p>
<p>Next time, I’ll show you how events bubble their way up—from any code that the Task ends up calling, as well as from any child tasks that are created.</p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/04/13/binding-events-to-net-4-0-tasks-instead-of-objects-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binding Events to .NET 4.0 Tasks instead of Objects (Part 1)</title>
		<link>http://fearthecowboy.com/2011/04/13/binding-events-to-net-4-0-tasks-instead-of-objects-part-1/</link>
		<comments>http://fearthecowboy.com/2011/04/13/binding-events-to-net-4-0-tasks-instead-of-objects-part-1/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 16:53:04 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[CoApp]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Asynchronous]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/?p=128</guid>
		<description><![CDATA[During the development of CoApp, I’ve enthusiastically embraced the .NET 4.0 Task Parallel Library (aka, the TPL).  It’s a set of APIs that make developers more productive by significantly simplifying the process of adding parallelism and concurrency to applications. I got religion around this last fall when I saw the PDC presentation that Anders Hejlsberg [...]]]></description>
			<content:encoded><![CDATA[<p>During the development of CoApp, I’ve enthusiastically embraced the .NET 4.0 <a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx">Task Parallel Library</a> (aka, the <strong>TPL</strong>).  It’s a set of APIs that make developers more productive by significantly simplifying the process of adding parallelism and concurrency to applications. I got religion around this last fall when I saw the PDC presentation that Anders Hejlsberg gave on “<a href="http://channel9.msdn.com/Events/PDC/PDC10/FT09">The Future of C# and VB</a>”.  In there Anders talks about the shift to a fully asynchronous programming methodology. While the technology that he spoke of isn’t yet ready for production use today, the Task Parallel Library in .NET 4.0 provides the underlying framework that we can take advantage of right now.</p>
<h4>Before we get too deep…</h4>
<p>I should note that asynchronous code in .NET 4 make rather extensive use of <a href="http://blogs.msdn.com/b/ericwhite/archive/2006/10/03/lambda-expressions.aspx">Lambda Expressions</a>—If you’re not familiar with lambdas, you’d better go get familiar, because this stuff is gonna be a tad hard to understand without it. It’s ok, I’ll wait…</p>
<p>&nbsp;</p>
<p>And, I’m not going to go into too much detail about <a href="http://msdn.microsoft.com/en-us/library/dd537609.aspx">the basics of using the TPL</a>; I recommend that you watch Ander’s video (to get an idea of the motivation) and perhaps read thru <a href="http://blogs.msdn.com/b/ericlippert/archive/tags/async/">Eric Lippert’s blog posts on Asynchrony</a> (and really, start with his earlier posts on <a href="http://blogs.msdn.com/b/ericlippert/archive/tags/continuation+passing+style/">Continuation Passing Style</a>)—if you are a .NET developer, this stuff will change your life.</p>
<p>The following is a simple example for how we start an asynchronous task using the TPL:</p>
<pre class="brush: c-sharp; toolbar: false">// *** Example Zero ***
// Starting a task using the TPL
var taskZero = Task.Factory.StartNew(() =&gt; {
    for (var q = 10; q &gt; 0; q--) {
        // simulate a longer running operation
        Thread.Sleep(200);

        // Wish we could tell someone about
        // what's going on in this operation
        // and Writeline is hardly a good idea
        // when you are in another thread.
        Console.WriteLine("Progress Message from taskZero", q);
    }
});

Console.WriteLine("(Main Thread Completed)======&gt;Press Enter to end.\r\n");
Console.ReadLine();</pre>
<p>Which will produce output like:</p>
<p><a href="http://fearthecowboy.com/wp-content/uploads/2011/04/task_0.png"><img style="background-image: none; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; padding-top: 0px; border-width: 0px;" title="task_0" src="http://fearthecowboy.com/wp-content/uploads/2011/04/task_0_thumb.png" border="0" alt="task_0" width="644" height="235" /></a></p>
<p>You’ll notice that the main thread completes (and is sitting around waiting at the <strong>ReadLine()</strong> ) while the Task executes.</p>
<h4>And getting to the point…</h4>
<p>Ok, so now I can illustrate some code that I’ve written as part of CoApp that fills a void where I was creating complex asynchronous operations and wanted to be able to broadcast arbitrary events from that operation, without having to pass an object along to each step in the operation.</p>
<p>Let me put this another way…</p>
<p>I’d like to start an operation—say, “Install a package”—and I’d like the calling context to be able to subscribe to events for that particular operation (regardless of what events the operation directly (or indirectly) broadcasts.  Yes, I *<strong>could</strong>* create a class that has a bunch events, and pass that from function to function in the entire call tree for that operation, but that would be terribly unwieldy, and frankly, would be a real pain when I wanted to reuse other asynchronous tasks as child tasks, and they may not take the same class for events.</p>
<p>Additionally, that asynchronous operation may spawn off additional asynchronous operations of its own—perhaps to download some dependencies—and it’d be nice to be able to pick up download progress notifications so we could show some UI that keeps the user informed as to what’s actually going on.</p>
<p>&nbsp;</p>
<p>Hrm… Howsabout I explain this with some code.  Let’s assume my little task has an event that it’d like to notify. First, we declare a class for the messages:</p>
<pre class="brush: c-sharp; toolbar: false">public class TestEvents : MessageHandlers&lt;TestEvents&gt; {
    public Action&lt;string, int&gt; Message1;
}</pre>
<p>And then an example of the task firing the event:</p>
<pre class="brush: c-sharp; toolbar: false; highlight: [3,9]">// *** Example One ***
// Firing an event
var taskOne = CoTask.Factory.StartNew(() =&gt; {
    for (var q = 10; q &gt; 0; q--) {
        // simulate a longer running operation
        Thread.Sleep(200); 

        // that occasionally notifies anyone who cares to listen.
        TestEvents.Invoke.Message1("Message From taskOne", q);
    }
});</pre>
<p>Now,  you should notice two things (‘specially since I highlighted the lines…). First, I use my own <strong>CoTask </strong>Task factory instead of the TPL’s Task—this just lets me track tasks a bit better, and handles some background work for all this stuff. Functionally, it should be identical, and still returns the same Task objects. Second, I can now use the class I created before to fire off a message (in this case, <strong>Message1 </strong>takes a <strong>string </strong>and an <strong>int </strong>for parameters) using some mysterious static Invoke dohickey on my <strong>TestEvents </strong>class .</p>
<p>Of course, nothing is listening to the events yet, let’s wire that up:</p>
<pre class="brush: c-sharp; toolbar: false">// perhaps we'll slack off for a while
Thread.Sleep(400); 

// start listening to messages after the task has started.
// (we probably missed some!)
((TestEvents)taskOne).Message1 += (aString, anInt ) =&gt; {
    Console.WriteLine("The Task said: [{0}] and [{1}] ", aString, anInt);
};

Console.WriteLine("(Main Thread Completed)\r\n**Press Enter to end**")
Console.ReadLine();</pre>
<p>When we run this, we’ll end up with some rather interesting output:</p>
<p><a href="http://fearthecowboy.com/wp-content/uploads/2011/04/task_1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;" title="task_1" src="http://fearthecowboy.com/wp-content/uploads/2011/04/task_1_thumb.png" border="0" alt="task_1" width="642" height="226" /></a></p>
<p>Shiny! You’ll notice in this example, that we’ve actually missed a couple of events (exacerbated by the <strong>Thread.Sleep()</strong> in line 2.). Regardless, the main thread completes and waits, and you can see my event handler in the lambda expression is getting called.<br />
The beauty of this approach is that we can see how I can launch a longer running operation, and accept events from it, without having to explicitly tell the code in the operation about the event listener.</p>
<p>In the next part as I dig deeper, I’ll show how we can ensure we never miss our messages, and how we can listen for more than one at a time.</p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/04/13/binding-events-to-net-4-0-tasks-instead-of-objects-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Simulating Symlinks for Windows XP/2003</title>
		<link>http://fearthecowboy.com/2011/04/07/simulating-symlinks-for-windows-xp2003/</link>
		<comments>http://fearthecowboy.com/2011/04/07/simulating-symlinks-for-windows-xp2003/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 15:59:45 +0000</pubDate>
		<dc:creator>Garrett</dc:creator>
				<category><![CDATA[CoApp]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://fearthecowboy.com/?p=125</guid>
		<description><![CDATA[(cross-posted from the mailing list) As I mentioned in my last post, CoApp’s design relies heavily on the use of Symbolic Links (symlinks)—a feature which is implemented fairly well in Windows Vista and beyond, but is missing in earlier versions of Windows. Cygwin tried to work around the limitation by using shortcuts (.LNK files), which [...]]]></description>
			<content:encoded><![CDATA[<p><em><span style="font-size: xx-small;">(cross-posted from the </span><a href="https://launchpad.net/~coapp-developer"><span style="font-size: xx-small;">mailing list</span></a><span style="font-size: xx-small;">) </span></em></p>
<p>As I mentioned in my last post, CoApp’s design <a href="http://fearthecowboy.com/2011/04/04/coapp-package-composition/">relies heavily</a> on the use of <a href="http://en.wikipedia.org/wiki/Symlinks">Symbolic Links</a> (symlinks)—a feature which is implemented fairly well in Windows Vista and beyond, but is missing in earlier versions of Windows.</p>
<p>Cygwin tried to work around the limitation by using shortcuts (.LNK files), which are files used by the Windows Shell for all the shortcuts in the start menu.  Not a bad way to go, but unfortunately, not very compatible with a lot of things, since most programs don’t specially recognize .LNK files, although the POSIX emulation in cygwin did.</p>
<p>I was thinkin’ that any acceptable solution should work with as much software as possible, without requiring special understanding, nor should any additional software be required (ie, a filter driver of some sort).</p>
<p>Our options then, are somewhat limited. On Windows XP and Windows Server 2003 we *do* have features like junctions (like symlinks, but only for directories, and only on the same volume), hard links (where more than one directory entry points to the same physical file) and alternate streams (the ability to store extra data with a file).</p>
<p>Hmmm.</p>
<p>Junctions seem to work fairly well for directories, with the caveat that actually manipulating junctions requires some tricky code with DeviceIOControl calls.</p>
<p>&nbsp;</p>
<p>For file symlinks, I’ve used NTFS hardlinks, but when I create the link, I store some additional metadata with the file itself in an alternate stream (under the name “legacySymlinkInfo”) which allows tools to find out what the canonical filename really is, and also to find out what other files are linked to the same physical file.</p>
<p>Of course, non-CoApp software could still manipulate these files for little regard as to their status as ‘symlinks’, so the legacySymlinkInfo really can’t always be relied upon. But we can make a pretty good effort to ‘clean-as-we-go’ to keep that information up-to-date. If a file gets renamed or moved, the metadata may not be entirely accurate, so when we check the data, we make an attempt to validate that it is accurate, and update it with what we know. If it sounds like this is dodgy, I wouldn’t disagree, but in practice this seems to work really well.</p>
<p>&nbsp;</p>
<p>Lastly, we need to be able to redirect a symlink, even when it is in use.  This seems trivial enough to do with junctions, but with files, we have to resort to moving the file out of the way, and creating a new linked file (which we can do, even if the file locked).</p>
<p>&nbsp;</p>
<p>Admittedly, there are a few limitations that this design has:</p>
<blockquote><p>Symlinks are only supported on the local system (no cross volume links, nor can they link to UNC paths)</p>
<p>Symlinks must be absolute references (not linking to relative paths)</p>
<p>The relationship between the linked file and the canonical file is potentially ephemeral, but simple examination of the files allows us to rebuild the information.</p>
<p>In the worst case scenario, if files get unlinked, they still work as regular files.</p>
<p>&nbsp;</p></blockquote>
<p>Luckily, CoApp’s requirements for what symbolic links need to do doesn’t have to be as flexible as full blown symlinks, and these limitations are not a hindrance at all.</p>
<p>I’ve just added this code to the CoApp toolkit (written in C#), and I’ll be playing with it quite a bit over the next few weeks. Once I’m sure that everything works as I like, if there is interest, I may implement a pure native version of the code so that other utilities and software can do the same thing and play nice too.</p>
<hr />
<p><strong><em>You can either comment here, come join mailing list (join the team at </em></strong><a href="https://launchpad.net/~coapp-developers"><strong><em>https://launchpad.net/~coapp-developers</em></strong></a><strong><em>) and continue the conversation!</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://fearthecowboy.com/2011/04/07/simulating-symlinks-for-windows-xp2003/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  fearthecowboy.com/feed/ ) in 0.26661 seconds, on Feb 5th, 2012 at 3:26 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 5th, 2012 at 3:32 am UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  fearthecowboy.com/feed/ ) in 0.00033 seconds, on Feb 5th, 2012 at 3:27 am UTC. -->
