<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[DannyDouglass.com]]></title>
  
  <link href="http://DannyDouglass.com/" />
  <updated>2012-08-05T23:34:02-04:00</updated>
  <id>http://DannyDouglass.com/</id>
  <author>
    <name><![CDATA[Danny Douglass]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/DannyDouglass" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="dannydouglass" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <title type="html"><![CDATA[How to: Create a Recursive Ruby Script to replace File/Directory Names and File Contents]]></title>
    <link href="http://DannyDouglass.com/2011/02/24/create-a-recursive-ruby-script-to-replace-file-and-directory-names-and-file-contents/" />
    <updated>2011-02-24T10:02:54-05:00</updated>
    <id>http://DannyDouglass.com/2011/02/24/create-a-recursive-ruby-script-to-replace-file-and-directory-names-and-file-contents</id>
    <content type="html"><![CDATA[<p>Over this past weekend I began templating a project structure that we use at my <a href="http://dannydouglass.com/aboutme/">day/evening/night job</a> to allow developers to simply execute a script and provide a few parameters to
initialize a new development project (including build script, fxcop analysis, unit testing, visual studio projects, etc.).  I didn’t think this would take that long despite being relatively new to the Ruby world.</p>

<p>Oddly enough, I had trouble finding similar examples on the <a href="http://www.urbandictionary.com/define.php?term=interwebs">interwebs</a> – even StackOverflow didn’t have the answer!  <a href="http://en.wikipedia.org/wiki/Hea%20rt_of_Darkness">The horror, the horror</a>!</p>

<p>No matter, I’m a developer after all and <strike>should be</strike>, <em>better be </em>capable of handling this simple script.  I decided to start simple and just use the directory global searching method to recursively get everything within my project template’s directory:</p>

<pre><code>def packageInitiator( startDirectory )  
    Dir.glob( startDirectory ).each do | path | 
        puts path
    end
end  
packageInitiator( './**/*' )
</code></pre>

<p>OK, good start.  Now I have all the items (files and directories) within my current executing directory.  I figured it would be easy to then replace the templated text in the directory and file paths at that point.</p>

<p><strong>Not so fast!</strong></p>

<p>The global directory search - <em>Dir.glob()</em> – actually traverses the directory structure and returns an array of all the file/directory names within the executing directory.  Take a look at the ruby documentation on the it <a href="http://ruby-doc.org/core/classes/Dir.html">here</a>.  What ended up happening was that as I changed directory names using a <strong>top-down</strong> approach, I was
invalidating paths used later in the loop.  For example, <em>/project/store</em> is the first directory to change in the example structure below:</p>

<p><strong>Original Directory Structure</strong></p>

<ul>
<li>/project/store/  - [<em>first to change</em>]</li>
<li>/project/store/hats</li>
<li>/project/store/jackets</li>
</ul>


<p>When we try to change <em>/project/store/hats</em> ruby throws an error because the root path <em>/project/store</em> would have changed.  The fix for this was simple,reverse the array and go from <strong>bottom-up</strong>:</p>

<pre><code>def packageInitiator( startDirectory )   
    directoryItems = Dir.glob( startDirectory ).reverse
    directoryItems.each do | path | 
        puts path
    end
end  
packageInitiator( './**/*' )
</code></pre>

<p>Better.  Time to add the logic to replace the placeholders I put in the file and directory names.  At this point I don’t care about whether the item is a file or directory so I treat them the same:</p>

<pre><code>def packageInitiator( startDirectory, patternToReplace )   
    directoryItems = Dir.glob( startDirectory ).reverse
    directoryItems.each do | path | 
        if( path.include? patternToReplace )
            oldPath = File.dirname(path)
            newPath = oldPath + '/' + File.basename( path ).gsub( patternToReplace, 'MyNewProjectName' )

            File.rename( path, newPath )    
        end
    end
end  
packageInitiator( './**/*', '{projectName}' )
</code></pre>

<p>Much better.  Now I need to determine if I am dealing with a file or a directory since I will need to replace the contents of files where I find the placeholder text as well.  Turns out that was pretty darn simple.</p>

<h4>Final Script</h4>

<pre><code>def replaceFileContents( path, patternToReplace, newProjectName )
    fileContents = File.read ( path )
    fileContents = fileContents.gsub( patternToReplace, newProjectName )
    File.open( path, 'w' ) { | file | file.puts fileContents }
end  
def packageInitiator( startDirectory, patternToReplace, newProjectName )   
    directoryItems = Dir.glob( startDirectory ).reverse
    directoryItems.each do | path | 

        # ignoring ruby scripts so I don't change contents of this file
        if( FileTest.file? ( path ) and File.extname( path ) != '.rb' )
                replaceFileContents( path, patternToReplace, newProjectName )
        end

        if( path.include? patternToReplace )
            oldPath = File.dirname(path)
            newPath = oldPath + '/' + File.basename( path ).gsub( patternToReplace, newProjectName )

            File.rename( path, newPath )    
        end

    end
end  
packageInitiator( './**/*', '{projectName}', 'MyNewProjectName' )
</code></pre>

<p>I can think of a lot of ways to improve this for more complicated scenarios, but this worked just fine for my needs.  Hopefully this helps someone else too.  And as I mentioned previously, I’m relatively new to Ruby and welcome and constructive feedback or suggestions for improvement that any Ruby experts have for me.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Simplify Using Xml Data with AutoMapper and Linq-to-Xml]]></title>
    <link href="http://DannyDouglass.com/2010/11/06/simplify-using-xml-data-with-automapper-and-linqtoxml/" />
    <updated>2010-11-06T13:50:09-04:00</updated>
    <id>http://DannyDouglass.com/2010/11/06/simplify-using-xml-data-with-automapper-and-linqtoxml</id>
    <content type="html"><![CDATA[<p>I recently ran into a scenario at work that required manually consuming several SOAP web services, which I’m sure you can imagine was rather monotonous. A co-worker (Seth Carney) and I tried a few different approaches, but we finally settled on a solution that simplified consumption of the xml and ultimately made the code more testable.  That solution centered around leveraging <a href="https://github.com/jbogard/AutoMapper">AutoMapper</a>, an open source object-object mapping tool, to create a link between the <a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.aspx">XElements</a> returned in the SOAP messages and custom contracts we created - in a reusable manner.</p>

<p>I put together a quick demo that shows how you could use the same approach to consume and display the <a href="http://api.twitter.com/1/statuses/public_timeline.xml">Twitter Public Timeline</a> (using the API’s Xml response type).</p>

<p><strong>Note</strong>: The source code for the following example can be found on my GitHub page: <a href="https://github.com/DannyDouglass/AutoMapperXmlMappingDemo">https://github.com/DannyDouglass/AutoMapperXmlMappingDemo</a></p>

<h3>1. Getting the Project Setup</h3>

<p>After creating a basic MVC3 (<a href="http://www.asp.net/mvc/mvc3">download beta</a>) project and the associated test project, the first step was to get the AutoMapper package installed.  I have been using <a href="http://nuget.codeplex.com/">NuGet</a>, Microsoft’s recently announced package management system, to install any open source dependencies.  The following command was all that was needed to setup AutoMapper in my MVC3 project (read more about NuGet <a href="http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx%20http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx%20http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx%20http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx">here</a> and <a href="http://www.hanselman.com/blog/CategoryView.aspx?category=Nupack">here</a>):</p>

<pre><code>PM&gt; add-package AutoMapper
</code></pre>

<h3>2. Creating the Mapping</h3>

<p>With AutoMapper installed I’m ready to get started creating the components necessary for the xml-to-object mapping.  The first step is creating a quick contract used in my application to represent the Tweet object:</p>

<pre><code>public interface ITweetContract
{
    ulong Id { get; set; }
    string Name { get; set; }
    string UserName { get; set; }
    string Body { get; set; }
    string ProfileImageUrl { get; set; }
    string Created { get; set; }
}
</code></pre>

<p>Nothing crazy here – just a simple entity.  These are all fields that are provided in the response from the Twitter API using a different name for some fields.  In simple cases where the source and destination objects have the same name you can setup a map very quickly using this syntax:</p>

<pre><code>Mapper.CreateMap&lt;SourceObj, DestinationObj&gt;();
</code></pre>

<p>However, AutoMapper does not support Xml by default I have to specify the fields that I will be mapping.  Using the Fluent API in AutoMapper I’m able to chain my field mappings.  Take a look at one example field mapped in my example – the tweet’s <strong>Body:</strong></p>

<pre><code>Mapper.CreateMap&lt;XElement, ITweetContract&gt;()
    .ForMember(
        dest =&gt; dest.Body,
        options =&gt; options.ResolveUsing&lt;XElementResolver&lt;string&gt;&gt;()
            .FromMember(source =&gt; source.Element("text")))
</code></pre>

<p>It may look complicated at first, but all that is really happening here is that we are providing details to AutoMapper on what value to use in my source object and how to map it to the destination object’s property.  There is one particular line I would like to focus on in the above <strong>Body</strong> field mapping:</p>

<pre><code>options =&gt; options.ResolveUsing&lt;XElementResolver&lt;ulong&gt;&gt;()
                        .FromMember(source =&gt; source.Element("id")))  
</code></pre>

<p>The <em>XElementResolver </em>is a <a href="http://automapper.codeplex.com/wikipage?title=Custom%20Value%20Resolvers">custom value resolver</a> that Seth came up with to handle parsing the XmlElement source object to retrieve a strongly-typed value for use in the mapping.  I’ll detail that more in a moment, but before we move on take a look at my full mapping:</p>

<pre><code>Mapper.CreateMap&lt;XElement, ITweetContract&gt;()
    .ForMember(
        dest =&gt; dest.Id,
        options =&gt; options.ResolveUsing&lt;XElementResolver&lt;ulong&gt;&gt;()
            .FromMember(source =&gt; source.Element("id")))
    .ForMember(
        dest =&gt; dest.Name,
        options =&gt; options.ResolveUsing&lt;XElementResolver&lt;string&gt;&gt;()
            .FromMember(source =&gt; source.Element("user")
                .Descendants("name").Single()))
    .ForMember(
        dest =&gt; dest.UserName,
        options =&gt; options.ResolveUsing&lt;XElementResolver&lt;string&gt;&gt;()
            .FromMember(source =&gt; source.Element("user")
                .Descendants("screen_name").Single()))
    .ForMember(
        dest =&gt; dest.Body,
        options =&gt; options.ResolveUsing&lt;XElementResolver&lt;string&gt;&gt;()
            .FromMember(source =&gt; source.Element("text")))
    .ForMember(
        dest =&gt; dest.ProfileImageUrl,
        options =&gt; options.ResolveUsing&lt;XElementResolver&lt;string&gt;&gt;()
            .FromMember(source =&gt; source.Element("user")
                .Descendants("profile_image_url").Single()))
    .ForMember(
        dest =&gt; dest.Created,
        options =&gt; options.ResolveUsing&lt;XElementResolver&lt;string&gt;&gt;()
            .FromMember(source =&gt; source.Element("created_at")));
</code></pre>

<h3>3. The Generic XElementResolver</h3>

<p>This custom value resolver is the real key that allowed these XElement-to-Contract maps to work in the original solution.  I’ve reused this resolver in this example as we saw above.  This was all that was necessary to create the custom resolver class:</p>

<pre><code>public class XElementResolver&lt;T&gt; : ValueResolver&lt;XElement, T&gt;
{
    protected override T ResolveCore(XElement source)
    {
        if (source == null || string.IsNullOrEmpty(source.Value))
            return default(T);  
        return (T)Convert.ChangeType(source.Value, typeof(T));
    }
}
</code></pre>

<p>This generic XElementResolver allows use to easily pass the type of the value retrieved in our mapping above.  For example, the following syntax is used to strongly type the value retrieved from the XmlElement in the <em>Id</em> field’s <em>.ForMember()</em> declaration above:</p>

<pre><code>ResolveUsing&lt;XElementResolver&lt;ulong&gt;&gt;()
</code></pre>

<p>With my mapping completely configured and instantiated, I’m ready to invoke the Twitter API and leverage AutoMapper to display that latest Public Timeline.</p>

<h3>4. Putting the Pieces Together</h3>

<p>I created a simple class responsible for retrieving the Twitter API response:</p>

<pre><code>public class TwitterTimelineRetriever
{
    private readonly XDocument _twitterTimelineXml;  
    public TwitterTimelineRetriever()
    {
        _twitterTimelineXml = XDocument
            .Load("http://api.twitter.com/1/statuses/public_timeline.xml");
    }  
    public IEnumerable&lt;ITweetContract&gt; GetPublicTimeline(int numberOfTweets)
    {
        var tweets = _twitterTimelineXml.Descendants("status")
            .Take(numberOfTweets);  
        return tweets.Select(Mapper.Map&lt;XElement, ITweetContract&gt;).ToList();
    }
}
</code></pre>

<p>The <em>GetPublicTimeline</em> method is a simple method returning, you guessed it, the Twitter Public Timeline by leveraging the map we created earlier:</p>

<pre><code>return tweets.Select(Mapper.Map&lt;XElement, ITweetContract&gt;).ToList();
</code></pre>

<p>In my MVC3 site’s <em>HomeController </em>I can make a quick call to the retrieval method, requesting the last 10 results:</p>

<pre><code>public class HomeController : Controller
{
    private TwitterTimelineRetriever _twitterTimelineRetriever;  
    public ActionResult Index()
    {
        _twitterTimelineRetriever = new TwitterTimelineRetriever();  
        ViewModel.Message = "Twitter Public Timeline";  
        return View(_twitterTimelineRetriever.GetPublicTimeline(10));
    }
}
</code></pre>

<p>And finally, after a little formatting in my <a href="https://github.com/DannyDouglass/AutoMapperXmlMappingDemo/blob/master/AutoMapperXmlDemo.Web/Views/Home/Index.cshtml">View</a> using the new <a href="http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx">Razor</a> view engine from Microsoft, I have my public timeline displaying!</p>

<p><a href="http://dannydouglass.com/images/2010-11-06-simplify-using-xml-data-with-automapper-and-linqtoxml/Screenshot_TwitterAutoMapperXmlMappingDemo_thumb.png"><img src="http://DannyDouglass.com/images/2010-11-06-simplify-using-xml-data-with-automapper-and-linqtoxml/Screenshot_TwitterAutoMapperXmlMappingDemo_thumb.png" alt="Screenshot_TwitterAutoMapperXmlMappingDemo" /></a></p>

<p>I know we had a hard time finding a lot of content on how to leverage AutoMapper to map Xml sources, so hopefully this is as helpful to you as it was for us.  As I mentioned before, the source is available on my <a href="https://github.com/DannyDouglass/">GitHub page</a> (that I am just starting to utilize):</p>

<p><a href="https://github.com/DannyDouglass/AutoMapperXmlMappingDemo">https://github.com/DannyDouglass/AutoMapperXmlMappingDemo</a></p>

<p>I’d love to hear any other ways people are using AutoMapper with an Xml source.  Shoot me an email at <a href="mailto:me@DannyDouglass.com">me@DannyDouglass.com</a> if you have an alternative solution.</p>

<p>Cheers!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Better Hg Command Line Interface: Console2 + PowerShell + Posh-Hg]]></title>
    <link href="http://DannyDouglass.com/2010/10/27/console2powershellposhhg/" />
    <updated>2010-10-27T07:52:08-04:00</updated>
    <id>http://DannyDouglass.com/2010/10/27/console2powershellposhhg</id>
    <content type="html"><![CDATA[<p>Moving from Subversion to <a href="http://mercurial.selenic.com/">Mercurial</a> was more than a change from a centralized version control system to a distributed solution.  I also found myself moving away from the explorer integration provided by the <a href="http://tortoisehg.bitbucket.org/">Tortoise</a> products to the command line for the execution of my hg commands.  This approach is dramatically faster once you get used to the syntax, which really only takes a hot minute.</p>

<p>Certain features in <a href="http://tortoisehg.bitbucket.org/">TortoiseHg</a> still provide visual advantages that I find useful, such as the visual repository log.  During an Agile.Net Bootcamp with <a href="http://www.lostechies.com/blogs/jimmy_bogard/">Jimmy Bogard</a> he showed us an collection of tools he utilizes to provide an improved Mercurial command line experience.  The final product is a more descriptive prompt that displays branch information, as well as the number and types of changes made since your last commit:</p>

<p><a href="http://dannydouglass.com/images/2010-10-27-console2powershellposhhg/poshhg_thumb.png"><img src="http://DannyDouglass.com/images/2010-10-27-console2powershellposhhg/poshhg_thumb.png" alt="posh-hg" /></a></p>

<h3>1. Console 2</h3>

<p><a href="http://sourceforge.net/projects/console/">http://sourceforge.net/projects/console/</a></p>

<p>You may already being using this very useful command prompt shell, but in case you are not go download it now!  This tool provides certain advantages over a standard command prompt, such as tabbed prompts, ability to integrate other shells (e.g. PowerShell), modified styles, control over keyboard commands, and much more.  Once you have downloaded console 2, just extract it somewhere (I used my c:\Program Files directory).</p>

<h3>2. Windows PowerShell</h3>

<p>You can read more on Windows PowerShell <a href="http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx">here</a> and <a href="http://technet.microsoft.com/en-us/library/ee692944.aspx">here</a>.  It comes with Windows 7, but you also <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx">download</a> it for other versions of Windows.  If you do not have it, download and install Windows PowerShell.</p>

<p>After installing PowerShell, we want to create a physical PowerShell profile file.  The default location on Windows 7 is <em>c:/users/username/document/WindowsPowerShell/</em> and you can force the creation of your PowerShell profile file by executing the following command in a PowerShell prompt:</p>

<pre><code>New-Item -path $profile -type file -force
</code></pre>

<p>After executing that command you can verify the file was created:</p>

<p><a href="http://dannydouglass.com/images/2010-10-27-console2powershellposhhg/PowerShellProfileCreation_thumb.png"><img src="http://DannyDouglass.com/images/2010-10-27-console2powershellposhhg/PowerShellProfileCreation_thumb.png" alt="PowerShellProfileCreation" /></a></p>

<h3>3. Posh-Hg Download and PowerShell Integration</h3>

<p><a href="http://poshhg.codeplex.com/">http://poshhg.codeplex.com/</a></p>

<p>Posh-Hg was inspired by the <a href="http://github.com/dahlbyk/posh-git">Posh-Git</a>, which provides a “custom prompt and tab expansion when using Mercurial from within a Windows PowerShell command line”.  There’s more information on this <a href="http://www.jeremyskinner.co.uk/2010/04/21/using-mercurial-with-windows-powershell/">blog post</a> about Posh-Hg.  You will want to download this file and place it somewhere on disk.  <strong>Important</strong>:  Before unzipping, make sure to right-click on the posh-hg-1.0 zip file and <strong>Unblock</strong> it, otherwise you will run into security issues executing the scripts each and every time (very, very annoying):</p>

<p><a href="http://dannydouglass.com/images/2010-10-27-console2powershellposhhg/Capture_thumb.png"><img src="http://DannyDouglass.com/images/2010-10-27-console2powershellposhhg/Capture_thumb.png" alt="Capture" /></a></p>

<p>Once you’ve unblocked the file you need to unzip it.  I recommend saving it the same location as your Windows PowerShell profile.  In my case that was <em>C:\Users\Danny\Documents\WindowsPowerShell</em>.  Now you are set to add posh-hg to you PowerShell profile.  Simply open your PowerShell profile file and add the following text to it, making sure to modify the path to the posh-hg <em>profile.example.ps1</em> file appropriately:</p>

<pre><code>. path\to\posh-hg\profile.example.ps1
</code></pre>

<p>You can now open a new PowerShell prompt and verify the installation by navigating to a Hg repository on disk.  You may receive an error explaining that your profile “<em>cannot be loaded because the execution of scripts is disabled on this system</em>”.  If that happens you will need to adjust the PowerShell script policy by executing the following command (type [Y] when prompted):</p>

<pre><code>Set-ExecutionPolicy Unrestricted
</code></pre>

<p>If you needed to set your execution policy, you will need to close your current PowerShell prompt and open a new one for the changes to take affect and allow for your profile to be loaded.  Try navigation to a Hg repository on disk and you’ll see a much more friendly prompt:</p>

<p><a href="http://dannydouglass.com/images/2010-10-27-console2powershellposhhg/Capture2_thumb.png"><img src="http://DannyDouglass.com/images/2010-10-27-console2powershellposhhg/Capture2_thumb.png" alt="Capture2" /></a></p>

<h3>4. PowerShell Integration with Console2 and Posh-Hg</h3>

<p>With everything installed and configured outside of Console2 we are set to add PowerShell to our Console2 installation.  You can <a href="http://DannyDouglass.com/wp-content/uploads/2010/10/console2-powershell-poshhg.zip">download</a> the files to update your Console2 installation (the console.xml file).  If you have not customized anything previously with Console2, you can just override the existing file without causing any harm. Drop the powershell.ico icon file in the Console2 directory and you are ready to test out the changes in Console2.  Open your console, navigate to a Mercurial repository on disk and you should see the changes:</p>

<p><a href="http://dannydouglass.com/images/2010-10-27-console2powershellposhhg/Capture_thumb1.png"><img src="http://DannyDouglass.com/images/2010-10-27-console2powershellposhhg/Capture_thumb1.png" alt="Capture" /></a></p>

<p>Here is a breakdown of the meaning the symbol/number combinations:</p>

<ul>
<li>“+<number>” – # of files that have been added (not committed)</li>
<li>“~<number>” – # of files that have been modified (not committed)</li>
<li>“-<number>” – # of files that have been removed (not committed)</li>
<li>“?<number>” – # of untracked files in your repo</li>
<li>“!<number>” – # of missing files</li>
</ul>


<p>You can edit how the Hg details are display as well.  Take a look at the <a href="http://poshhg.codeplex.com/">posh-hg codeplex page</a> for those details.</p>

<p>This <a href="http://www.vcritical.com/2009/02/better-console-for-powershell-and-vitk/">blog post</a> helped me accomplish the 4th step of my install and provided the zip file (which I slightly modified) used to update the console2 configuration.</p>

<h3>Done!</h3>

<p>You are now setup with a significantly more useful PowerShell command prompt that can help you visually get a feel for the state of your repository immediately.  Of course, I’m positive you <a href="http://www.codinghorror.com/blog/2008/08/check-in-early-check-in-often.html">check in early and often</a>, which results in this information being substantially more helpful.  If I’m always showing changes to 50 - 100+ files, how much does that really help me???</p>

<p><strong>Added Bonus: </strong>Take a look at ScottHa’s <a href="http://www.hanselman.com/blog/IntroducingPowerShellPromptHere.aspx">blog post</a> on adding a “PowerShell Prompt Here” context menu item for Windows Explorer.  Very Handy!</p>

<p>Hope you enjoy this as much as I did – thanks to <a href="www.lostechies.com/blogs/jimmy_bogard/">Jimmy Bogard</a> for the exposure to Posh-Hg!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[NuPack vs. Nu (Nubular) vs. OpenWrap]]></title>
    <link href="http://DannyDouglass.com/2010/10/06/nupack-vs-nuproj-vs-openwrap/" />
    <updated>2010-10-06T09:32:25-04:00</updated>
    <id>http://DannyDouglass.com/2010/10/06/nupack-vs-nuproj-vs-openwrap</id>
    <content type="html"><![CDATA[<p>The <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=0abac7a3-b302-4644-bd43-febf300b2c51">ASP.NET MVC 3 Beta</a> was unofficially released yesterday (as far as I can tell) and the release notes include a quote about a package manager named NuPack:</p>

<blockquote><p>ASP.NET MVC 3 includes NuPack Package Manager, which is an integrated package management tool for adding libraries and tools to Visual Studio projects. For the most part, it automates the steps that developers take todayto get a library into their source tree.</p>

<p>You can work with NuPack as a command line tool, as an integrated console
window inside Visual Studio 2010, from the Visual Studio context menu, and as
set of PowerShell cmdlets.</p>

<p>For more information about NuPack, visit <a href="http://nupack.codeplex.com/">http://nupack.codeplex.com/</a> and read the <a href="http://nupack.codeplex.com/documentation?title=Getting%20Started">Getting Started Guide</a>.</p></blockquote>

<p>Unfortunately, the CodePlex site is currently not published and many are waiting to take a look at what’s being released here by Microsoft.  There seems to be a good deal of confusion on Twitter revolving around this project so I thought a quick post outlining each of the 3 main package managers in .NET would be helpful.  I’ve listed them in alphabetical order:</p>

<p><strong><em>Update</em></strong>:  Thanks to a comment below from Keith Dahlby…it appears that NuPack may be a joint effort between the creators of Nu and Microsoft.  You can read more about it on the <a href="http://www.outercurve.org/News/articleType/ArticleView/articleId/20/Outercurve-Foundation-Announces-NuPack-as-Fifth-Project-in-ASPNET-Open-Source-Gallery">Outercurve Foundation announcement.</a></p>

<p><strong>Update #2</strong>: Microsoft has <a href="http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx">announced</a> NuPack was named with the blessing of the Nu (Nubular) team and the projects appears to merging to some extent.  Nu will continue moving forward, but may ultimately die-off in favor of NuPack’s native .NET solution.</p>

<ul>
<li><em><strong>Nu (Nubular)</strong>:</em> Nu is a project started by <a href="http://codebetter.com/blogs/dru.sellers/default.aspx">Dru Sellers</a> and <a href="http://devlicio.us/blogs/rob_reynolds/default.aspx">Rob Reynolds</a> that I have blogged about <a href="http://dannydouglass.com/2010/08/whats-new-in-the-dotnet-world/">here</a> and <a href="http://dannydouglass.com/2010/08/whats-nu-in-the-dotnet-world-part2-creating-a-gem/">here</a>.  It leverages the Ruby gems platform to bring gems to the .NET world. </li>
</ul>


<p>Twitter hashtag <strong>#NuProj</strong></p>

<ul>
<li><strong><em>NuPack</em></strong>: Microsoft’s package management tool included in the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=0abac7a3-b302-4644-bd43-febf300b2c51">ASP.NET MVC 3 Beta</a>.  The source is located on <a href="http://nupack.codeplex.com/">CodePlex</a>, but is not published at this time (9:15 EST). <em>Update</em> – source is available!  See update #2 above.</li>
</ul>


<p>Twitter hashtag <strong>#NuPack</strong></p>

<ul>
<li><strong><em>OpenWrap</em></strong>: A native .NET package management solution by <a href="http://serialseb.blogspot.com/">Sebastien Lambla</a> that aims at managing dependencies in a manner that will allow runtime resolution to dependency issues as well.</li>
</ul>


<p>Twitter hashtag <strong>#OpenWrap</strong></p>

<p>Without hearing more on NuPack’s approach to managing .NET packages it is hard to compare the 3.  I am sure that an announcement will come in the near future from someone on the ASP.NET team at Microsoft regarding the ASP.NET MVC3 beat and NuPack.  In the meantime, I hope this helps clarify the difference between the different .NET Package Managers.</p>

<p>Stay tuned for more…</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Presentation Materials from ALT.NET Presentation on Package Management]]></title>
    <link href="http://DannyDouglass.com/2010/10/01/dcaltnet-package-management-presentation/" />
    <updated>2010-10-01T09:17:28-04:00</updated>
    <id>http://DannyDouglass.com/2010/10/01/dcaltnet-package-management-presentation</id>
    <content type="html"><![CDATA[<p>Below I have provided a variety of material/links from my presentation last night - “<strong>The Current State of Package Management in .NET</strong>”.  Please feel free to contact me using any of the communication channels available in the right column of my blog.  I would happy to provide any further information regarding <strong>Nu</strong> or <strong>OpenWrap</strong>, or just to discuss your thoughts on the topic of package management.</p>

<p>I want to thank everyone that battled the weather last night to make it to the presentation.  I really enjoyed my first opportunity to present at an ALT.NET event.  Also, thanks to <a href="http://weblogs.asp.net/Podwysocki/">Matthew Podwysocki</a> for allowing me to speak last night.  I believe I’ve included everything below that I discussed last night. If you take time to review the slideshow, I’d recommended using one of the two links below the embedded slideshow as they contain the speaker notes with a lot of information.</p>

<p><a href="https://docs.google.com/present/view?id=dg63kd2x_69f9mmx5cx">Link to Google Presentation</a> |
<a href="http://DannyDouglass.com/downloads/The_Current_State_of_Package_Management_in_ASPNET.ppt">Download PowerPoint</a><br/>
<em>both links offer speaker notes with more information</em></p>

<h3>Gem Creation Example</h3>

<p>I showed how to use Nu to download and install packages, as well as how to actually create a Ruby gem that can be utilized with Nu.  Below are the links to the PagedList project before refactoring for gem creation and after I modified the project.</p>

<ul>
<li><strong>Before</strong>: <a href="http://github.com/TroyGoode/PagedList">http://github.com/TroyGoode/PagedList</a> [May 7, 2010 Commit]</li>
<li><strong>After</strong>: <a href="http://github.com/DannyDouglass/PagedList">http://github.com/DannyDouglass/PagedList</a> [Gem built and pushed from this code]</li>
<li><strong>Resulting Gem</strong>: <a href="http://rubygems.org/gems/PagedList">http://rubygems.org/gems/PagedList</a></li>
</ul>


<h3>Helpful Links</h3>

<ul>
<li><strong>Nu Google Group</strong>: <a href="http://groups.google.com/group/nu-net?pli=1">http://groups.google.com/group/nu-net?pli=1</a></li>
<li><strong>Herding Code Podast w/ Nu Creators</strong>: <a href="http://herdingcode.com/?p=272">http://herdingcode.com/?p=272</a></li>
<li><strong>Nu Introduction</strong>: <a href="http://dannydouglass.com/2010/08/whats-new-in-the-dotnet-world/">http://dannydouglass.com/2010/08/whats-new-in-the-dotnet-world/</a></li>
<li><strong>Nu &amp; Creating a Gem Introduction</strong>: <a href="http://dannydouglass.com/2010/08/whats-nu-in-the-dotnet-world-part2-creating-a-gem/">http://dannydouglass.com/2010/08/whats-nu-in-the-dotnet-world-part2-creating-a-gem/</a></li>
<li><strong>Nu for Visual Studio</strong>: <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/ba0f6da5-3660-4983-b8fb-d5abfc45093e">http://visualstudiogallery.msdn.microsoft.com/en-us/ba0f6da5-3660-4983-b8fb-d5abfc45093e</a></li>
<li><strong>OpenWrap Introduction</strong>: <a href="http://serialseb.blogspot.com/2010/07/intro-to-what-openwrap-is.html">http://serialseb.blogspot.com/2010/07/intro-to-what-openwrap-is.html</a></li>
<li><strong>Ruby Gems Website</strong>: <a href="http://rubygems.org/">http://rubygems.org/</a></li>
<li><strong>Ruby Download</strong>: <a href="http://rubyinstaller.org/">http://rubyinstaller.org/</a></li>
<li><strong>Semantic Versioning</strong>: <a href="http://semver.org">http://semver.org</a></li>
</ul>


<p>Cheers!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What’s Nu in the .NET World Part 2: Creating a Gem]]></title>
    <link href="http://DannyDouglass.com/2010/08/11/whats-nu-in-the-dotnet-world-part2-creating-a-gem/" />
    <updated>2010-08-11T20:39:37-04:00</updated>
    <id>http://DannyDouglass.com/2010/08/11/whats-nu-in-the-dotnet-world-part2-creating-a-gem</id>
    <content type="html"><![CDATA[<p>If you are not familiar with the Nu project start by reading my <a href="http://dannydouglass.com/2010/08/whats-new-in-the-dotnet-world/">first post in this series</a> that gives an introduction to getting started with this promising tool.  As a quick reference I’ll post a paragraph from the last post introducing Nu:</p>

<p><strong>“Nu </strong>is an open source tool built by <a href="http://codebetter.com/blogs/dru.sellers/default.aspx">Dru Sellers</a> (and several others) that aims at bringing <a href="http://rubygems.org/">Gems</a>, one of Ruby’s most revered features, to the .NET world.  If you are not familiar with Gems I suggest you take a minute to <a href="http://docs.rubygems.org/read/book/3">read up on them</a>.  I would venture a bet that you are already familiar with at least one gem – <a href="http://rubyonrails.org">Ruby on Rails</a>.  The following line of code is all that is required to install the Ruby on Rails gem (after installing the Ruby library of course)…”</p>

<p>This post is focused on sharing my experience in creating my first gem for the <a href="http://sparkviewengine.com/">Spark View Engine</a>.  I would be doing you a great disservice if I did not start by saying how easy it is to create a gem. Actually easy is the wrong phrase – <strong>crazy easy</strong> is more telling.  Since I would never ask you to take my word for it, it must mean it is time to show some code.</p>

<p><strong><em>Getting Started</em></strong></p>

<p>After downloading the latest release for the Spark View Engine <a href="http://sparkviewengine.codeplex.com/releases/view/27601">here</a>, the first step was to create a directory to hold my gem specification anywhere on my machine, c:/Gems/SparkViewEngine was my choice:</p>

<p><a href="http://dannydouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb3.png"><img src="http://DannyDouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb3.png" alt="image" /></a></p>

<p><strong><em>Creating the Gem Specification</em> </strong>(GemSpec)</p>

<p><a href="http://devlicio.us/blogs/rob_reynolds/default.aspx">Rob Reynolds</a> described this file as “the most important file for this entire process”.  The gemspec file will be named after the project – in this case it is named <strong>sparkviewengine.gemspec</strong> and will be placed inside my sparkviewengine directory.  While we are creating files we can also create a <strong>VERSION</strong> file that, you may have guessed, stores the version of the gem.  We now have a directory with 2 files:</p>

<p><a href="http://dannydouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb4.png"><img src="http://DannyDouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb4.png" alt="image" /></a></p>

<p>Below is the code from my <strong>sparkviewengine.gemspec</strong> file, you would simply replace the values with those applicable to the gem you are creating:</p>

<pre><code>version = File.read(File.expand_path("../VERSION",__FILE__)).strip  

Gem::Specification.new do |spec|  
  spec.platform    = Gem::Platform::RUBY  
  spec.name        = 'sparkviewengine'  
  spec.version     = version  
  spec.files       = Dir['lib/**/*'] + Dir['docs/**/*']  

  spec.summary     = 'Spark View Engine for Asp.Net Mvc and Castle Project MonoRail'  
  spec.description = &lt;&lt;-EOF
    Spark is a view engine for Asp.Net Mvc and Castle Project MonoRail frameworks. 
    The idea is to allow the html to dominate the flow and the code to fit seamlessly.
  EOF

  spec.authors           = 'Louis Dejardin'
  spec.email             = 'spark-dev@googlegroups.com'  
  spec.homepage          = 'http://sparkviewengine.com'  
  spec.rubyforge_project = 'sparkviewengine'  
end  
</code></pre>

<p>The VERSION file is much simpler.  I found the version below by opening <a href="http://www.red-gate.com/products/reflector/">Reflector</a> and locating the version of the Spark.dll.  Be sure to check out Rob Reynold’s <a href="http://devlicio.us/blogs/rob_reynolds/archive/2010/07/17/how-to-gems-%20and-net-dependencies-references.aspx">blog post</a> for the explanation on why you need to use Reflector and cannot trust the windows explorer properties panel.</p>

<pre><code>1.1.0.0
</code></pre>

<p><strong><em>Adding the Library Files</em></strong></p>

<p>The hard part is finished in creating our basic gem, now we need to include the spark compiled dlls.  For this example we are creating a basic gem and do not have to deal with dependencies.  My next gem will be more detailed and I will discuss what steps are necessary to <a href="http://devlicio.us/blogs/rob_reynolds/archive/2010/07/17/how-to-gems-and-net-dependencies-references.aspx">handle dependencies</a>.</p>

<p>For the SparkViewEngine gem we can simply copy the libraries from the bin directory of the Spark 1.1.0.0 release:</p>

<p><a href="http://dannydouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb5.png"><img src="http://DannyDouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb5.png" alt="image" /></a></p>

<p>and place them into a new <strong>lib</strong> directory in my SparkViewEngine gem directory:</p>

<p><a href="http://dannydouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb6.png"><img src="http://DannyDouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb6.png" alt="image" /></a></p>

<p><strong>Documentation</strong></p>

<p>Any documentation can be stored in a <strong>docs</strong> directory.  I added the
index.html and zipped up the samples that came with the Spark 1.1.0.0 release:</p>

<p><a href="http://dannydouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb7.png"><img src="http://DannyDouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb7.png" alt="image" /></a></p>

<p>That’s it for the setup!  My gem specification is ready to be built and uploaded to <a href="http://RubyGems.org">RubyGems.org</a>.</p>

<p><strong><em>Building the Gem Specification</em></strong></p>

<pre><code>gem build sparkviewengine.gemspec
</code></pre>

<p><a href="http://dannydouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb8.png"><img src="http://DannyDouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb8.png" alt="image" /></a></p>

<p>That creates my versioned gem:</p>

<p><a href="http://dannydouglass.com//images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb9.png"><img src="http://DannyDouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb9.png" alt="image" /></a></p>

<p><strong><em>Pushing the Gem to RubyGems.org</em></strong></p>

<p>You need to have an account created on RubyGems.org before you can push.  Once that is created simply execute the following code, enter your credentials, and watch as your gem is pushed out to the world!</p>

<pre><code>gem push sparkviewengine-1.1.0.0.gem
</code></pre>

<p><a href="http://dannydouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb10.png"><img src="http://DannyDouglass.com/images/2010-08-11-whats-nu-in-the-dotnet-world-part2-creating-a-gem/image_thumb10.png" alt="image" /></a></p>

<p><strong>That’s all folks!</strong></p>

<p>I can now install the <a href="http://rubygems.org/gems/sparkviewengine">SparkViewEngine gem</a> into my .NET Project using the command:</p>

<pre><code>nu install sparkviewengine
</code></pre>

<p><strong><em>Wrapping Up</em></strong></p>

<p>If you have been looking for that opportunity to contribute to the Open Source community, but keep finding yourself saying, ‘I just do not have the time’, then I am happy to say your chance is here.  Go out and create your first gem. You will be surprised out just how easy, errrr <strong>crazy easy</strong> it is to complete.</p>

<p>Here are some of the resources that aided me in creating my first gem:</p>

<ul>
<li><p><strong>Rob Reynold’s Blog Post: </strong><a href="http://devlicio.us/blogs/rob_reynolds/archive/2010/07/16/how-to-gems-and-net.aspx">http://devlicio.us/blogs/rob_reynolds/archive/2010/07/16/how-to-gems-and-net.aspx</a></p></li>
<li><p><strong>Nu Google Group Post:</strong> <a href="http://groups.google.com/group/nu-net/web/gempublishers?pli=1">http://groups.google.com/group/nu-net/web/gempublishers?pli=1</a></p></li>
<li><p><strong>Nu Google Group Thread:</strong> <a href="http://groups.google.com/group/nu-net/browse_thread/thread/3d4a9618412fd2a4">http://groups.google.com/group/nu-net/browse_thread/thread/3d4a9618412fd2a4</a></p></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What's Nu in the .NET World?]]></title>
    <link href="http://DannyDouglass.com/2010/08/09/whats-new-in-the-dotnet-world/" />
    <updated>2010-08-09T09:20:36-04:00</updated>
    <id>http://DannyDouglass.com/2010/08/09/whats-new-in-the-dotnet-world</id>
    <content type="html"><![CDATA[<p>If you thought the word &#8221;<em>Nu</em>&#8221; in the title of this blog post was misspelled, you are in for a treat.  And trust me, you are not the only one who made that grammatical assumption.</p>

<p><strong>Nu </strong>is an open source tool built by <a href="http://codebetter.com/blogs/dru.sellers/default.aspx">Dru Sellers</a> that aims at bringing <a href="http://rubygems.org/">Gems</a>, one of Ruby’s most revered features, to the .NET world.  If you are not familiar with Gems I suggest you take a minute to <a href="http://docs.rubygems.org/read/book/3">read up on them</a>.  I would venture a bet that you are already familiar with at least one gem – <a href="http://rubyonrails.org">Ruby on Rails</a>.  The following line of code is all that is required to install the Ruby on Rails gem (after installing the Ruby library of course):</p>

<pre><code>gem install rails 
</code></pre>

<p>Compare that to what is required to install ASP.NET MVC.  Despite having ASP.NET installed, I may need to download a separate installer for a specific version of Visual Studio.  Semantics aside, it is just plain more difficult. That is not to say installing ASP.NET MVC is overly complex, nor am I attempting to disrespect the ASP.NET MVC framework.  I’m actually a <em>big fan</em> of ASP.NET MVC. My intention is to show that the gem installation is just <em>crazy simple<strong> </strong></em>and a piece of the programmatic puzzle missing in .NET development.  Many, including myself, are hoping that <strong>Nu</strong> proves to be the solution to this shortcoming.</p>

<p>This is not the first time someone has attempted to solve the “Missing Gem” (as I have decided to label it) mystery in the .NET world.  I recall my friend <a href="http://SquaredRoot.com">Troy Goode</a> discussing this exact problem with <a href="http://stephenwalther.com/blog/default.aspx">Stephen Walther</a> just prior to him joining Microsoft way back in early 2008.  Many others have tried to <strong>replace</strong> Ruby Gems in the .NET world, but none have been successful.  <a href="http://codebetter.com/blogs/dru.sellers/default.aspx">Dru Sellers</a> decided to take a different approach and leverage the existing Ruby Gems tools and expand upon it to bring gems to .NET.  Brilliant.</p>

<p>Enough discussion about Nu – I will let the code speak for itself.  In the following example I will create a basic ASP.NET MVC 2 web application (.NET 4.0) and use the Nu package installer to hook in <a href="http://code.google.com/p/autofac/">AutoFac</a>, a .NET <a href="http://martinfowler.com/articles/injection.html">IoC container</a>.  Do not be alarmed if you do not know what AutoFac or IoC are at this point.  Just understand that I have an external component that I would like to utilize in my project.  For a list of all the currently available Nu packages you can take a look at the <a href="http://nu.wikispot.org/Current_Packages">Current .NET Nu Packages</a> page on the Nu wiki.  Now let’s see the code!</p>

<p><strong>Note</strong>: You must <a href="http://rubyinstaller.org/downloads/">install Ruby</a> as a prerequisite to using Nu since it leverages Ruby’s Gem tool.</p>

<p>The first step is to create a new ASP.NET MVC 2 application:</p>

<p><a href="http://dannydouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/image_thumb.png"><img src="http://DannyDouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/image_thumb.png" alt="image" /></a>)</p>

<p>Once the application is created I can quickly run it and see the screen that anyone who has read about or used ASP.NET MVC before is very familiar with:</p>

<p><a href="http://dannydouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/image_thumb1.png"><img src="http://DannyDouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/image_thumb1.png" alt="image" /></a></p>

<p>Now that I have my project created I want to download the AutoFac library and bring it into my project.  Prior to Nu, I would do this by opening a browser, finding the AutoFac download page, download, possibly unzip the files, etc. Nu makes this much simpler.  First thing I want to do install Nu using the Ruby gem tool by simply executing the command <strong>gem install nu</strong>.</p>

<p><a href="http://dannydouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/NuGemInstall_thumb.png"><img src="http://DannyDouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/NuGemInstall_thumb.png" alt="NuGemInstall" /></a></p>

<p>Once I have installed Nu, I can easily download the AutoFac gem by executing the command <strong>nu install autofac</strong>.</p>

<p><a href="http://dannydouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/image_thumb2.png"><img src="http://DannyDouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/image_thumb2.png" alt="image" /></a></p>

<p>Note that by default Nu will install your gems local (in a new <em>lib</em> directory) to the folder where you execute the <strong>nu install #somegem#</strong> command.  Taking a look at my <em>c:\projects\Nu_AspNetMvc2_Demo</em> directory I can see that two folders were created: .<em>nu</em> and <em>lib</em>.  The <em>lib </em>folder will hold all of the gems I install in this directory from here on out, unless I override the default at a later time.  I will not go into further details, but my AutoFac dlls are now stored inside of my <em>/lib/autofac </em>package directory.You can take a look at the <a href="http://dl.dropbox.com/u/5632950/Nu_AspNetMvc2_Demo.zip">example’s source</a> to see more about the package directory structure.</p>

<p><a href="http://dannydouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/NuAutofacInstallFolders_thumb.png"><img src="http://DannyDouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/NuAutofacInstallFolders_thumb.png" alt="NuAutofacInstallFolders" /></a></p>

<p>Currently Nu is in its early stages and I am still required to add the DLLs to my project manually, but very soon this will not be the case.  A Nu for Visual Studio plugin is in the works that will simplify this step – take a look at <a href="http://www.youtube.com/watch?v=0-1UPrKu3wg">this video preview</a> to see it in action.  I imagine there will be other ways to accomplish this as well.  For now, I will simply add the required references as I would with any other library I downloaded to my Visual Studio Project:</p>

<p><a href="http://dannydouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/ProjectReferences_thumb.png"><img src="http://DannyDouglass.com/images/2010-08-09-whats-new-in-the-dotnet-world/ProjectReferences_thumb.png" alt="ProjectReferences" /></a></p>

<p>Now all I need to do is follow <a href="http://code.google.com/p/autofac/wiki/MvcIntegration">these instructions</a> to hookup AutoFac 2 in my <em>global.asax.cs (code shown below)</em> and I am good to go! Running my project shows me that same familiar MVC homepage, however this time my controller factory is running using the AutoFac controller factory (see line 33 below):</p>

<pre><code>using System.Reflection;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Autofac;
using Autofac.Integration.Web;
using Autofac.Integration.Web.Mvc;  
namespace Nu_AspNetMvc2_Demo
{
    public class MvcApplication : HttpApplication, IContainerProviderAccessor
    {
        private static IContainerProvider _containerProvider;  
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );  
        }  
        protected void Application_Start()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            _containerProvider = new ContainerProvider(builder.Build());
            ControllerBuilder.Current.SetControllerFactory(new AutofacControllerFactory(ContainerProvider));  
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
        }  
        public IContainerProvider ContainerProvider
        {
            get { return _containerProvider; }
        }
    }
}
</code></pre>

<p>As you can see there is a lot of power in using Nu.  There are many other areas I could have gone into further detail, but I wanted this to be a simple introduction to the power of Nu packages.  I plan on following up with additional posts to show other features of Nu and maybe even a post on creating your very own Gem.  In the meantime I want to include a few resources to help you learn more about Nu:</p>

<ol>
<li><p><strong>Nu Wiki | </strong><a href="http://nu.wikispot.org/">http://nu.wikispot.org</a></p></li>
<li><p><strong>Nu Google Group |</strong> <a href="http://groups.google.com/group/nu-net">http://groups.google.com/group/nu-net</a></p></li>
<li><p><strong>The Power of Nu Video</strong> <strong>|</strong> <a href="http://www.youtube.com/watch?v=IvxAa4XURss&amp;feature=youtu.be">http://www.youtube.com/watch?v=IvxAa4XURss&amp;feature=youtu.be</a></p></li>
</ol>


<p><strong><a href="http://dannydouglass.com/downloads/Nu_AspNetMvc2_Demo.zip">Download this Example’s Source Code</a></strong></p>

<p><a href="http://dotnetshoutout.com/Whats-Nu-in-the-NET-World-DannyDouglasscom"><img src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fdannydouglass.com%2F2010%2F08%2Fwhats-new-in-the-dotnet-world%2F" alt="Shout it" /></a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Mercurial: Create Remote Repositories Using PowerShell]]></title>
    <link href="http://DannyDouglass.com/2010/08/02/mercurial-create-remote-repositories-using-powershell/" />
    <updated>2010-08-02T19:12:14-04:00</updated>
    <id>http://DannyDouglass.com/2010/08/02/mercurial-create-remote-repositories-using-powershell</id>
    <content type="html"><![CDATA[<p>In case you are not familiar with Mercurial (Hg), it is a Distributed Version Control System (DVCS) aimed at simplifying revision control.  The purpose of this post is not to introduce Mercurial, but you can read more about Mercurial at the following links to get better acquainted with the software:</p>

<ul>
<li><a href="http://hginit.com/">HgInit</a> | <a href="http://www.joelonsoftware.com/">Joel Spolsky’s</a> detailed introduction to Mercurial</li>
<li><a href="http://hgbook.red-bean.com/read/">Mercurial: The Definitive Guide</a> | A comprehensive guide to using Mercurial</li>
<li><a href="http://code.google.com/p/support/wiki/DVCSAnalysis">Mercurial vs. Git Comparison</a> | Google Code wiki analysis of two DVCS solutions</li>
<li><a href="http://mercurial.selenic.com/wiki/">Official Mercurial Wiki</a> | Selenic’s official Mercurial wiki and guides</li>
</ul>


<p>Now that we are all comfortable with Hg (the chemical symbol for Mercury and nickname for Mercurial), I would like to take present an issue I spent some time working on today.  There are several different <a href="http://mercurial.selenic.com/wiki/PublishingRepositories">publishing mechanisms</a> in Mercurial, but for the setup at my company we decided to simply use http being that our provider is only internally available and protected by several firewalls and other security measures.  We chose this approach over the more popular SSH publishing mechanism being that we are hosting our Mercurial installation on a Windows 2008 R2 server.  Had we installed it on a box running something other than Windows, SSH would have solved the problem I’m about to describe below.  Here’s a quick view of our basic setup:</p>

<p><a href="http://dannydouglass.com/images/2010-08-02-mercurial-create-remote-repositories-using-powershell/MercurialSetupOverHttp_thumb.png"><img src="http://DannyDouglass.com/images/2010-08-02-mercurial-create-remote-repositories-using-powershell/MercurialSetupOverHttp_thumb.png" alt="Mercurial Setup Over Http" /></a></p>

<p>One limitation when using http as a publishing mechanism is that you <a href="http://ry4an.org/unblog/UnBlog/2009-09-17">cannot create a repository remotely</a>; no if, ands, or buts about it.  Another twist was that our CM (Configuration Management) procedures dictate that our developers are not permitted to RDP into the Mercurial server.  This left us trying to decide how to allow developers to create repositories remotely since our http communication channel does not allow remote repository creation.</p>

<p><a href="http://SquaredRoot.com">Troy Goode</a>, a good friend and colleague, suggested that we leverage PowerShell to solve the problem.  After spending a little bit of time with the Configuration Manager a PowerShell solution was in place. Using the following basic PowerShell command, a remote session was initiated without making the developer an administrator on the machine with RDP access:</p>

<pre><code>ENTER-PSSession your-server-name-or-ipaddress
</code></pre>

<p>I originally encountered an <strong>Access Denied</strong> error, which we discovered was caused by my account not have the appropriate permissions on the Mercurial server to create a remote PowerShell session.  This is pretty easy to remedy and you can read more about it on the <a href="http://technet.microsoft.com/en-us/library/dd819508.aspx">TechNet library page</a>.  Simply execute the following cmdlet <em>on the server</em> to manage the PowerShell remote session security configuration:</p>

<pre><code>set-pssessionConfiguration -name Microsoft.PowerShell -showSecurityDescriptorUI
</code></pre>

<p>The last change is to set the appropriate directory permissions on the remote server to the location where developers are permitted to create repositories. That should be straightforward enough without going into any examples since repository architectures can differ drastically.</p>

<p>It can’t be that easy, can it? Well, good news – it is that simple!  With those changes you should be able to remote manage (create and delete) your Mercurial (Hg) repositories via PowerShell.  Hopefully this helps you save some time in your setup of Mercurial – a very awesome, and my current favorite, Version Control System.</p>
]]></content>
  </entry>
  
</feed>
