<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>TypeCasted</title>
	<atom:link href="http://brettedotnet.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://brettedotnet.wordpress.com</link>
	<description>My .Net Adventure</description>
	<lastBuildDate>Sun, 29 Jan 2012 21:58:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='brettedotnet.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>TypeCasted</title>
		<link>http://brettedotnet.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://brettedotnet.wordpress.com/osd.xml" title="TypeCasted" />
	<atom:link rel='hub' href='http://brettedotnet.wordpress.com/?pushpress=hub'/>
		<item>
		<title>RelayCommand, Yes Another One!</title>
		<link>http://brettedotnet.wordpress.com/2011/11/28/relaycommand-yes-another-one/</link>
		<comments>http://brettedotnet.wordpress.com/2011/11/28/relaycommand-yes-another-one/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 04:40:41 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[C# emm like totally!]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=490</guid>
		<description><![CDATA[Another RelayCommand First thing first I want to point out that there are many implementations of the Relay/Delegate command out there to choose from. My two personal favorites are Josh Smiths RelayCommand and of course the DelegateCommand from the Prism Library. That said, both of them miss things that many of my projects have required [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=490&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Another RelayCommand</h2>
<p>First thing first I want to point out that there are many implementations of the Relay/Delegate command out there to choose from. My two personal favorites are Josh Smiths <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090030">RelayCommand</a> and of course the <a href="http://msdn.microsoft.com/en-us/library/gg405484(v=pandp.40).aspx#sec10">DelegateCommand</a> from the <a href="http://compositewpf.codeplex.com/">Prism</a> Library. That said, both of them miss things that many of my projects have required and as a result I have had to either extend, or roll my own. So in this post I am going to add to the mix yet another implementation. I presented this implementation earlier this month as part of my MVVM discussion with the folks at the <a href="http://mankatodotnet.com/">Mankato .Net User Group</a> and a few people afterwards asked me about it so I have decided to make it public.</p>
<p>Use it if like or take and change it so it fits your needs more appropriately. Either way no warranty for you!</p>
<h2>Why Relay</h2>
<p>Relay commands are very basic implementations of the ICommand interface. WPF people may say what about RoutedCommand? Well, there are several reasons you don’t want to use RoutedCommands in our ViewModels, the most obvious is because they route! Aside from that they rely on the creation of a CommandBinding, and at the end of the day it’s just not real clean.</p>
<p>RelayCommand makes it very easy for our ViewModels to create command instances that our Views can bind to. At the same time RelayCommand with its delegate support allows our ViewModels to control the command implementation details. This helps make our code more testable, and limits the command class explosion that happens if you start creating a class for each command.</p>
<h2>What Relay</h2>
<p>So what do I want my RelayCommand to do? Below is a list of features that are not native to many other implementations that I find I cannot live without.</p>
<ol>
<li>Built-in support for Asynchronous processing (Fire and Forget, or with a Callback/Continuation)</li>
<li>Supports ‘busy’ cursor behavior when running Synchronously</li>
<li>Supports Predicate and Action delegate so ViewModels can own the implementation details</li>
<li>Hooks into the CommandManager’s RequerySuggested event so ViewModels don’t have to raise the CanExecuteChanged event all the time.</li>
</ol>
<p>So let’s take a look at the code that accomplishes this.</p>
<p><pre class="brush: csharp;">
using System;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Commanding
{
	public class RelayCommand : ICommand
	{
		#region Private Data Members

		/// &lt;summary&gt;
		/// Flag indicates that the command should be run on a seperate thread
		/// &lt;/summary&gt;
		private readonly bool mRunOnBackGroudThread;
		/// &lt;summary&gt;
		/// Predicate that that evaluates if this command can be executed
		/// &lt;/summary&gt;
		private readonly Predicate&lt;object&gt; mCanExecutePredicate;
		/// &lt;summary&gt;
		/// Action to be taken when this command is executed
		/// &lt;/summary&gt;
		private readonly Action&lt;object&gt; mExecuteAction;
		/// &lt;summary&gt;
		/// Run when action method is complete and run on a seperate thread
		/// &lt;/summary&gt;
		private readonly Action&lt;object&gt; mExecuteActionComplete;

		#endregion

		#region Constructor

		/// &lt;summary&gt;
		/// Initializes a new instance of the &lt;see cref=&quot;RelayCommand&quot;/&gt; class.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;canExecutePredicate&quot;&gt;The can execute predicate.&lt;/param&gt;
		/// &lt;param name=&quot;executeAction&quot;&gt;The execute action.&lt;/param&gt;
		/// &lt;param name=&quot;executeActionComplete&quot;&gt;The execute action complete.&lt;/param&gt;
		public RelayCommand(Predicate&lt;object&gt; canExecutePredicate, Action&lt;object&gt; executeAction, Action&lt;object&gt; executeActionComplete)
			: this(canExecutePredicate, executeAction, true)
		{
			if (executeActionComplete == null)
			{
				throw new ArgumentNullException(&quot;executeActionComplete&quot;);
			}
			mExecuteActionComplete = executeActionComplete;
		}

		/// &lt;summary&gt;
		/// Initializes a new instance of the &lt;see cref=&quot;RelayCommand&quot;/&gt; class.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;canExecutePredicate&quot;&gt;The can execute predicate.&lt;/param&gt;
		/// &lt;param name=&quot;executeAction&quot;&gt;The execute action.&lt;/param&gt;
		/// &lt;param name=&quot;runOnBackGroundTread&quot;&gt;if set to &lt;c&gt;true&lt;/c&gt; [run on back ground tread].&lt;/param&gt;
		public RelayCommand(Predicate&lt;object&gt; canExecutePredicate, Action&lt;object&gt; executeAction, bool runOnBackGroundTread)
			: this(canExecutePredicate, executeAction)
		{
			mRunOnBackGroudThread = runOnBackGroundTread;
		}

		/// &lt;summary&gt;
		/// Initializes a new instance of the &lt;see cref=&quot;RelayCommand&quot;/&gt; class.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;canExecutePredicate&quot;&gt;The can execute predicate.&lt;/param&gt;
		/// &lt;param name=&quot;executeAction&quot;&gt;The execute action.&lt;/param&gt;
		public RelayCommand(Predicate&lt;object&gt; canExecutePredicate, Action&lt;object&gt; executeAction)
		{
			if (canExecutePredicate == null)
			{
				throw new ArgumentNullException(&quot;canExecutePredicate&quot;);
			}

			if (executeAction == null)
			{
				throw new ArgumentNullException(&quot;executeAction&quot;);
			}

			mCanExecutePredicate = canExecutePredicate;
			mExecuteAction = executeAction;
		}

		/// &lt;summary&gt;
		/// Initializes a new instance of the &lt;see cref=&quot;RelayCommand&quot;/&gt; class.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;executeAction&quot;&gt;The execute action.&lt;/param&gt;
		public RelayCommand(Action&lt;object&gt; executeAction)
			: this(n =&gt; true, executeAction)
		{

		}

		#endregion

		#region ICommand Members

		/// &lt;summary&gt;
		/// Occurs when changes occur that affect whether or not the command should execute.
		/// &lt;/summary&gt;
		public event EventHandler CanExecuteChanged
		{
			add { CommandManager.RequerySuggested += value; }
			remove { CommandManager.RequerySuggested -= value; }
		}

		/// &lt;summary&gt;
		/// Defines the method that determines whether the command can execute in its current state.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;parameter&quot;&gt;Data used by the command.  If the command does not require data to be passed, this object can be set to null.&lt;/param&gt;
		/// &lt;returns&gt;
		/// true if this command can be executed; otherwise, false.
		/// &lt;/returns&gt;
		public bool CanExecute(object parameter)
		{
			return mCanExecutePredicate(parameter);
		}

		/// &lt;summary&gt;
		/// Defines the method to be called when the command is invoked.
		/// &lt;/summary&gt;
		/// &lt;param name=&quot;parameter&quot;&gt;Data used by the command.  If the command does not require data to be passed, this object can be set to null.&lt;/param&gt;
		public void Execute(object parameter)
		{
			using (new BusyCursor())
			{
				if (!mRunOnBackGroudThread)
				{
					mExecuteAction(parameter);
				}
				else
				{
					if (mExecuteActionComplete != null)
					{
						//Run with continuation
						var context = TaskScheduler.FromCurrentSynchronizationContext();
						Task.Factory.StartNew(mExecuteAction, parameter).ContinueWith(mExecuteActionComplete, context);
					}
					else
					{
						//Run as fire and forget
						Task.Factory.StartNew(mExecuteAction, parameter);
					}
				}
			}
		}

		#endregion
	}
}

</pre></p>
<h2>Constructors</h2>
<p>There are several overloaded constructors for this class; each of them implies how the command should behave (Sync or Async). This allows our ViewModels to dictate how these commands should function upon construction time.</p>
<h2>Delegates</h2>
<p>One of the core goals of an implementation like this it to allow the details of each command to remain in our ViewModels, the Predicate, and Action delegates help us with this quite nicely. Making the parameters to these delegates generic could make this even more flexible but the this example I have left that out.</p>
<h2>CanExecuteChanged</h2>
<p>Looking at the CanExecuteChanged event, notice how the CommandManager.RequestSuggested event is being wrapped. This is very nice because we put the burden of raising the CanExecuteChagned event on the shoulders of WPF. Additionally the RequestSuggested event is static so it will only hold onto our handlers as a weak reference, so we are good from a memory leak perspective.</p>
<h2>Execute</h2>
<p>The magic all comes together here, some simple logic to determine how the supplied Action delegate will be executed. Maybe it’s synchronous (with a busy cursor) maybe it’s asynchronous. Maybe a callback is executed once the work put on a separate thread is complete, maybe its fire and forget. All this goodness is dependent on the constructor you decided to call when you created your instance.</p>
<h2>Summary</h2>
<p>So while not earth shattering, this is the implementation (or a slight variance of it) that I use in most of my WPF projects. The command supports the provider concept by using delegates, sync and async processing, and leverages the command manager to raise the CanExecuteChanged event handler in a memory safe way. Hopefully you will get some use out of this.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/490/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/490/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/490/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=490&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2011/11/28/relaycommand-yes-another-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>
	</item>
		<item>
		<title>Don&#8217;t Play With the Monkeys (Ice-Breaker)</title>
		<link>http://brettedotnet.wordpress.com/2011/11/10/dont-play-with-the-monkeys-ice-breaker/</link>
		<comments>http://brettedotnet.wordpress.com/2011/11/10/dont-play-with-the-monkeys-ice-breaker/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 14:55:32 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[Toastmasters]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=484</guid>
		<description><![CDATA[The year was 2010 and the location was Botswana Africa inside a wild game reserve just south of the Zimbabwe border. I was walking back to our camp site from the showers wearing only the towel around my waist when I inadvertently crossed paths with a monkey that was tending to her young. Unhappy with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=484&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The year was 2010 and the location was Botswana Africa inside a wild game reserve just south of the Zimbabwe border. I was walking back to our camp site from the showers wearing only the towel around my waist when I inadvertently crossed paths with a monkey that was tending to her young. Unhappy with my presence she lunged at me chasing me back into the shower area. As I stared at the hissing monkey now blocking my exit I began frantically calculating my options.</p>
<ol>
<li>Run into the shower stall, but that would offer little protection</li>
<li>Try and run past the monkey, but wearing only a towel and flip flops this was great option</li>
<li>I could wait, risking a confrontation with the monkey.</li>
</ol>
<p>It was at this point I asked myself how on earth did I get end up here?</p>
<p>To answer that question I have to go back to 8<sup>th</sup> grade when my parents reluctantly purchased me my first guitar. I say reluctantly because my general pattern was to lose interest in everything I started very quickly. This was not the case with guitar however. I became obsessed with it; at school I joined the Jazz band, outside of school I played in rock bands, I started taking lessons two times a week, and even started to learn how to build them.</p>
<p>It was my obsession with guitar that led me to college. Mostly interested in Classical guitar by this time, I enrolled at the University of River Falls, while a school mostly known for agriculture they also have one of the best classical guitar instructors in the Midwest. Music became my life, six hour days in the practice rooms, music theory parties, composition contests it was a great time in my life.</p>
<p>About two years into my study, my guitar teacher expressed interest in developing a web site for his group the Minneapolis Guitar Quartet. Knowing absolutely nothing about computing at that time and even less about web development I volunteered to do it. Using my roommate’s computer and a HTML book from the computer science department’s library I built my first website. It was at this point that I found yet another obsession. Programming! Shortly after that I added an additional major in computer science. This was the happiest day of dad’s life, since he had hopes that I could actually get a job after college.</p>
<p>Fast forward 4 years, with my music degree and computer science degree in hand, I found myself in Winona, MN working as a web developer for a company called Fastenal. It was here where I met a woman from India name Pragya who after several months of begging finally agreed to go out on a date with me. While it’s true I begged for the first date, I want to make sure to state that it was her who asked me to marry her! In 2005 Pragya and I were married in New Delhi India, in a traditional Hindu wedding.</p>
<p>By now you must be thinking, what does this all have to do with the Monkey? I promise I am getting there!</p>
<p>When my wife came to Iowa for college her parents left India to start a manufacturing company in Africa. With half of her family in India and her parents in Africa we travel to both places quite a bit. In 2010 we went to Africa, and traveled to the Chobe game reserve for a safari, and this is where I found myself face to face with the angry monkey.</p>
<p>So how did I get here? My parents got me a guitar, guitar led me to college, college let me to computing, computing led me to Pragya, and Pragya let me to Africa and Africa to this very angry monkey.</p>
<p>So what happened? Well just as the monkey was about to lunge at me, out of nowhere a man with a big broom smacked the monkey out of the door way. The man started at me and said, “Don’t play with the monkeys”</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/484/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/484/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/484/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=484&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2011/11/10/dont-play-with-the-monkeys-ice-breaker/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>
	</item>
		<item>
		<title>Frameworks and Austrian Economics</title>
		<link>http://brettedotnet.wordpress.com/2011/10/18/frameworks-and-austrian-economics/</link>
		<comments>http://brettedotnet.wordpress.com/2011/10/18/frameworks-and-austrian-economics/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 19:50:45 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[Framework Goodness]]></category>
		<category><![CDATA[General Goodies]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=480</guid>
		<description><![CDATA[Inception An interesting thing happened to me a few years back while sitting in a Sprint Retrospective. A nameless developer on our team voiced some frustration with our UI Framework. Person X stated that that the UI Framework was too constraining. Since I was largely responsible for this aspect of the system I was interested in hearing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=480&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Inception</h2>
<p>An interesting thing happened to me a few years back while sitting in a Sprint Retrospective. A nameless developer on our team voiced some frustration with our UI Framework. Person X stated that that the UI Framework was too constraining. Since I was largely responsible for this aspect of the system I was interested in hearing the developers concerns. When pressed to describe the areas Person X felt were too limiting, it became clear that the developer was trying to work out of band and out of pattern. The developer was trying to introduce a new UI pattern not yet discussed or agreed upon by our team and users.  It was in this moment it occurred to me that while frameworks need to support the needs of the system, they should also prevent developers from introducing things that are not well understood at a whim.  This particular conversation was the seedling for my particular view of how frameworks should support applications. I call it Framework Organics.</p>
<h2>What is the Role of a Framework</h2>
<p>This question will likely elicit 10 different answers if you ask 10 different people. And though you did not ask here is my answer.</p>
<blockquote><p><em>A framework should box developers into the understood and agreed upon patterns while allowing for the necessary changes agreed upon over time.</em></p></blockquote>
<p>In greater detail a framework should provide support for concepts that are relevant to the system being developed. <strong>In stark contrast a framework absolutely should not support any random concept a developer can dream up.</strong> It should limit the ability of developers to travel to far off into the weeds. Protecting your users from cowboy coders who are spinner happy!</p>
<p>Along with limiting developers from introducing new concepts, a well-designed framework should be able to adapt to change over time. It should be resilient and extendable to meet any reasonable need that may arise throughout the development lifecycle. This does not mean that you need to build an over engineered goliath of a framework that supports every possible permutation possible. <strong>Because you can’t and no one I have ever met can. </strong></p>
<h2>Organics and Austrians</h2>
<p>One of my favorite economists <a href="http://www.youtube.com/watch?feature=player_detailpage&amp;v=d0nERTFo-Sk">F.A. Hayek</a> wrote an entire book called ‘<a href="http://en.wikipedia.org/wiki/The_Fatal_Conceit">The Fatal Conceit’</a>. In this book he makes the case against socialism. Political affiliation aside his premise is worth mentioning here. Hayek believed as many Austrian Economists did/do, that it was impossible for central planners to understand that millions of interactions of the millions of people they govern. He also argued that any attempt to plan around these interactions was a form of conceit that was doomed to fail. Austrians believe that the framework of society was grown overtime in a free market sort of way. If problems came up they were addressed and solved, it was this sort organic evolution that Austrians feel allow us to strive as we do today.</p>
<p>Again this is not meant to be a political rant. But parallels can be drawn between concepts in software design and economics.  <a href="http://www.youtube.com/watch?v=nvks70PD0Rs&amp;amp;sns=tw">The Agile Method</a> and the various approaches of iterative development it has spawned clearly harness the power of organic growth over time. Short cycles of problem/solution/repeat are much more in line with Hayek’s ideas than they are with say the Keynesian approach to planned government. In contrast the Waterfall methodology is more in line with Socialism. Waterfall is far more plan centric it’s ridged, and less adaptable to change over time. Waterfall does what it can to make sure change is as painful and costly as possible. It’s no wonder at all why that methodology is for the most part dead.</p>
<h2>Bringing Back In</h2>
<p>Ok so I am not an economist and I really do not want to be tagged a right wing radical because of this post. But the point here is simple, frameworks should evolve organically overtime. Yes this means constant refactoring of your core code throughout the life of a project. When new patterns are introduced, your framework will change and code sweeps will need to happen. As your product grows so will the level of support your framework provides but on an as needed basis. Keeping in mind the framework should also limit developers to the current set of patterns that are supported by the current revision of your framework.</p>
<p>The benefit of framework limitation should not be underestimated. By limiting concepts allowed in your systems users start to learn and understand stereotypes. As a result new screens seem familiar to them, less support questions arise, and your application is usable unlike ITunes for the PC. The benefits are not only seen by users. Developers now have a common language when designing new screens. “This fits our Master Detail pattern”; “This fits our search pattern”. And if a scenario does not seem to fit existing patterns perhaps the introduction of something new is needed. And the cycle continues in a nice organic sort of way!</p>
<p>&nbsp;</p>
<p>Enjoy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/480/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/480/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=480&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2011/10/18/frameworks-and-austrian-economics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>
	</item>
		<item>
		<title>IDataErrorInfo and FluentValidation</title>
		<link>http://brettedotnet.wordpress.com/2011/10/14/idataerrorinfo-and-fluentvalidation/</link>
		<comments>http://brettedotnet.wordpress.com/2011/10/14/idataerrorinfo-and-fluentvalidation/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 19:29:21 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[C# emm like totally!]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=462</guid>
		<description><![CDATA[I Got the chance to look at the FluentValidation.Net Framework this week. Overall its pretty spiffy! The API seems to handle most validation situations pretty well. Often times these things fall apart as soon as you run into a mildly complex situation such as dependent rule processing etc.  Using this for WPF and MVVM as it turns [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=462&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I Got the chance to look at the <a href="http://fluentvalidation.codeplex.com/">FluentValidation.Net Framework</a> this week. Overall its pretty spiffy! The API seems to handle most validation situations pretty well. Often times these things fall apart as soon as you run into a mildly complex situation such as dependent rule processing etc.  Using this for WPF and MVVM as it turns out is pretty simple. In this post I will show you a simple example of how to integrate FluentValidation.Net into your View Models, using the IDataErrorInfo interface and the databinding support provided by WPF.</p>
<p>Here is what I will cover in the post.</p>
<ol>
<li>Create a View for the MainWindow</li>
<li>Create a ViewModel for the MainWindow</li>
<li>Create a Validator for the MainWindowViewModel</li>
<li>Setup Dependency Injection so ViewModels and Validators are both Injected as needed</li>
<li>Implement IDataErrorInfo so it routes calls our Validator implementation</li>
</ol>
<blockquote>
<div>If you do not have Unity and the FluentValidation dll&#8217;s, please learn how to use <a href="http://nuget.org/">NuGet </a>and go get it.</div>
</blockquote>
<h2>The MainWindow View</h2>
<p>Very basic XAML here the intent is only to get the moving parts setup, not to win a beauty contest. Two things to notice here.</p>
<ol>
<li>I have the binding set to update its source upon <strong>PropertyChanged</strong> this is not needed but I like instant feedback when possible.</li>
<li>In order to support <strong>IDataErrorInfo</strong> implementations you must set the dependency property <strong>ValidatesOnDataErrors</strong> to true.</li>
</ol>
<p><pre class="brush: xml;">
&lt;ribbon:RibbonWindow
    x:Class=&quot;MoreFluent.MainWindow&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:ribbon=&quot;clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary&quot;
    Title=&quot;MainWindow&quot;
    x:Name=&quot;RibbonWindow&quot;
    Width=&quot;640&quot;
    Height=&quot;480&quot;&gt;
    &lt;Grid
        x:Name=&quot;LayoutRoot&quot;&gt;
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition
                Height=&quot;Auto&quot; /&gt;
            &lt;RowDefinition
                Height=&quot;*&quot; /&gt;
        &lt;/Grid.RowDefinitions&gt;
        &lt;ribbon:Ribbon
            x:Name=&quot;Ribbon&quot;&gt;
            &lt;ribbon:Ribbon.ApplicationMenu&gt;
                &lt;ribbon:RibbonApplicationMenu
                    SmallImageSource=&quot;Images\SmallIcon.png&quot;&gt;
                    &lt;ribbon:RibbonApplicationMenuItem
                        Header=&quot;Hello _Ribbon&quot;
                        x:Name=&quot;MenuItem1&quot;
                        ImageSource=&quot;Images\LargeIcon.png&quot; /&gt;
                &lt;/ribbon:RibbonApplicationMenu&gt;
            &lt;/ribbon:Ribbon.ApplicationMenu&gt;
            &lt;ribbon:RibbonTab
                x:Name=&quot;HomeTab&quot;
                Header=&quot;Home&quot;&gt;
                &lt;ribbon:RibbonGroup
                    x:Name=&quot;Group1&quot;
                    Header=&quot;Group1&quot;&gt;
                    &lt;ribbon:RibbonButton
                        x:Name=&quot;Button1&quot;
                        LargeImageSource=&quot;Images\LargeIcon.png&quot;
                        Label=&quot;Button1&quot; /&gt;
                    &lt;ribbon:RibbonButton
                        x:Name=&quot;Button2&quot;
                        SmallImageSource=&quot;Images\SmallIcon.png&quot;
                        Label=&quot;Button2&quot; /&gt;
                    &lt;ribbon:RibbonButton
                        x:Name=&quot;Button3&quot;
                        SmallImageSource=&quot;Images\SmallIcon.png&quot;
                        Label=&quot;Button3&quot; /&gt;
                    &lt;ribbon:RibbonButton
                        x:Name=&quot;Button4&quot;
                        SmallImageSource=&quot;Images\SmallIcon.png&quot;
                        Label=&quot;Button4&quot; /&gt;
                &lt;/ribbon:RibbonGroup&gt;
            &lt;/ribbon:RibbonTab&gt;
        &lt;/ribbon:Ribbon&gt;
        &lt;Grid
            Grid.Row=&quot;1&quot;
            Margin=&quot;7,7,7,7&quot;&gt;
            &lt;StackPanel
                Orientation=&quot;Horizontal&quot;
                Height=&quot;24&quot;
                Width=&quot;250&quot;&gt;
                &lt;Label&gt;Name&lt;/Label&gt;
                &lt;TextBox
                    Width=&quot;150&quot;
                    Text=&quot;{Binding Path=Name, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}&quot;&gt;&lt;/TextBox&gt;
            &lt;/StackPanel&gt;
        &lt;/Grid&gt;
    &lt;/Grid&gt;
&lt;/ribbon:RibbonWindow&gt;
</pre></p>
<h2>Not So Fancy eh?</h2>
<p>I suppose I should give you a screen shot. Not so pretty but good enough to get the point across!</p>
<p><img src="http://dl.dropbox.com/u/44480662/mainwindow.png" alt="Ugly Main Window!" /></p>
<h2>And The Code Behind</h2>
<p>And of course the CodeBehind. However minimal this is there are a few important things here to point out.</p>
<ol>
<li>The Dependency Attribute. Unity uses this attribute to facility property dependency injection upon build up.</li>
<li>The setter for the <strong>ViewModel</strong> property wraps the <strong>DataContext </strong>making <strong>MainWindowViewModel</strong> the <strong>DataContext</strong> for the view.</li>
</ol>
<p><pre class="brush: csharp;">
using Microsoft.Practices.Unity;
using Microsoft.Windows.Controls.Ribbon;

namespace Validation
{
    /// &lt;summary&gt;
    /// Interaction logic for MainWindow.xaml
    /// &lt;/summary&gt;
    public partial class MainWindow : RibbonWindow
    {
        /// &lt;summary&gt;
        /// Gets or sets the view model.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The view model.&lt;/value&gt;
        [Dependency]
        public MainWindowViewModel ViewModel
        {
            get { return (MainWindowViewModel)DataContext; }
            set { DataContext = value; }
        }

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref=&quot;MainWindow&quot;/&gt; class.
        /// &lt;/summary&gt;
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

</pre></p>
<h2>The MainWindow ViewModel</h2>
<p>The MainWindowViewModel exposes a single property and the implementation of the IDataErrorInfo interface. Notice again we are relying on Unity to inject the Validator. In real life the the IDataErrorInfo implementation would reside in some sort of base ViewModel class. For example purposes I will not be doing that here.</p>
<p>Notice the IDataErrorInfo indexer, this forwards the call to the Validator asking it to run any rules associated to the supplied property name. If any rules are broken the error messages are returned in a single string with line breaks between each error message. Additionally the Error property asks the Validator to Validate all of the rules on a given object and return the enumerated results, again including line breaks.</p>
<p><pre class="brush: csharp;">
using System;
using System.ComponentModel;
using System.Linq;
using FluentValidation;
using Microsoft.Practices.Unity;

namespace MoreFluent
{
    public class MainWindowViewModel : IDataErrorInfo
    {
        #region Dependencies

        /// &lt;summary&gt;
        /// Gets or sets the validator.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The validator.&lt;/value&gt;
        [Dependency]
        public AbstractValidator&lt;MainWindowViewModel&gt; Validator { get; set; }

        #endregion

        #region Properties

        /// &lt;summary&gt;
        /// Gets or sets the name.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The name.&lt;/value&gt;
        public string Name { get; set; }

        #endregion

        #region IDataErrorInfo Members

        /// &lt;summary&gt;
        /// Gets an error message indicating what is wrong with this object.
        /// &lt;/summary&gt;
        /// &lt;value&gt;&lt;/value&gt;
        /// &lt;returns&gt;An error message indicating what is wrong with this object. The default is an empty string (&quot;&quot;).&lt;/returns&gt;
        string IDataErrorInfo.Error
        {
            get
            {
                return Validator != null
                    ? string.Join(Environment.NewLine, Validator.Validate(this).Errors.Select(x =&gt; x.ErrorMessage).ToArray())
                    : string.Empty;
            }
        }

        /// &lt;summary&gt;
        /// Gets the &lt;see cref=&quot;System.String&quot;/&gt; with the specified property name.
        /// &lt;/summary&gt;
        /// &lt;value&gt;&lt;/value&gt;
        string IDataErrorInfo.this[string propertyName]
        {
            get
            {
                if (Validator != null)
                {
                    var results = Validator.Validate(this, propertyName);
                    if (results != null
                        &amp;&amp; results.Errors.Count() &gt; 0)
                    {
                        var errors = string.Join(Environment.NewLine, results.Errors.Select(x =&gt; x.ErrorMessage).ToArray());
                        return errors;
                    }
                }
                return string.Empty;
            }
        }

        #endregion
    }
}

</pre></p>
<h2>The Validator</h2>
<p>Of course this would be incomplete without the Validator so here it is! Just one simple rule.</p>
<p><pre class="brush: csharp;">namespace FluentValidation
{
    /// &lt;summary&gt;
    /// Validator for the MainWindowViewModel
    /// &lt;/summary&gt;
    public class MainWindowViewModelValidator : AbstractValidator&lt;MainWindowViewModel&gt;
    {
        #region Constructor

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref=&quot;MainWindowViewModelValidator&quot;/&gt; class.
        /// &lt;/summary&gt;
        public MainWindowViewModelValidator()
        {
            RuleFor(x =&gt; x.Name).NotEmpty().WithMessage(&quot;Name is Required&quot;);
        }

        #endregion
    }
}

</pre></p>
<h2>The Unity Setup</h2>
<p>Setting up Unity is simple. Two things need to be done.</p>
<ol>
<li>Remove the StartupUri from your App.xaml</li>
<li>Override OnStartup in your App.xaml.cs</li>
</ol>
<div>
<h2>The App.xaml</h2>
</div>
<p><pre class="brush: xml;">
&lt;Application x:Class=&quot;MoreFluent.App&quot;
             xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&gt;
    &lt;Application.Resources&gt;
		&lt;!-- Resources scoped at the Application level should be defined here. --&gt;

    &lt;/Application.Resources&gt;
&lt;/Application&gt;

</pre></p>
<h2>The App.xaml.cs</h2>
<p><pre class="brush: csharp;">
using System.Windows;
using FluentValidation;
using Microsoft.Practices.Unity;

namespace MoreFluent
{
    /// &lt;summary&gt;
    /// Interaction logic for App.xaml
    /// &lt;/summary&gt;
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            IUnityContainer container = new UnityContainer();
            container.RegisterType&lt;AbstractValidator&lt;MainWindowViewModel&gt;, MainWindowViewModelValidator&gt;();
            var mainWindow = container.Resolve&lt;MainWindow&gt;();
            mainWindow.Show();
        }
    }
}

</pre></p>
<p>Enjoy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/462/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=462&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2011/10/14/idataerrorinfo-and-fluentvalidation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>

		<media:content url="http://dl.dropbox.com/u/44480662/mainwindow.png" medium="image">
			<media:title type="html">Ugly Main Window!</media:title>
		</media:content>
	</item>
		<item>
		<title>Team Dynamics</title>
		<link>http://brettedotnet.wordpress.com/2010/06/17/the-ruin-that-is-indifference/</link>
		<comments>http://brettedotnet.wordpress.com/2010/06/17/the-ruin-that-is-indifference/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 01:30:00 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[General Goodies]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Things I Hate]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=367</guid>
		<description><![CDATA[Team dynamics play a large part in the success or failure of a project. Often times they play a bigger role in an application making it successfully to production then the collective skill set of a team. I have had the opportunity to work on teams that have had both good and bad dynamics. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=367&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Team dynamics play a large part in the success or failure of a project. Often times they play a bigger role in an application making it successfully to production then the collective skill set of a team. I have had the opportunity to work on teams that have had both good and bad dynamics. The difference is night and day. A team that works well together and collaborates  is far more motivated, excited, and concerned with over all quality of the end product. Sadly the experiences I have had on teams with lousy dynamics are just the opposite. Team members will isolate themselves, quality will drop exponentially and team members stop caring because they are frustrated. This reduces the chances of creating a usable finished product to almost zero.</p>
<p>Something that I have found to be true in my tenure in the software development business is that personalities to a very large degree make or break a team dynamic.  In fact more important than the enumerated skill sets of a team are the personalities of the team members. Personality say a lot about a developers ability to work within the confines of a team and a methodology. Below I describe some of the personality types that I have seen on the various teams I have been on over time.</p>
<h3>The Cherry Picker</h3>
<p>The cherry picker hunts and pecks away at the requirement backlog, only working on requirements he/she finds interesting or easiest. What is worse, is that often times a Cherry Picker will break down a given requirement into several parts, again only working on the aspects he/she finds simple or interesting. Cherry Pickers never finish a requirement. They are done when they get board or confused caring very little about the state of the work  when they quit. This leads to the endless cycle of a requirement going from dev to test and back to dev. Cherry Pickers are bad.</p>
<h3>The BA Developer</h3>
<p>The BA Developer is one of the most frustrating personality types to work with. A BA Developer will find things he/she believes are shortcomings or missing requirement in a current system, decide without consulting other team members that it is important and do the work right now <em>(99% of the time there is no defect or requirement to track the work against.) </em>Because the BA Developer knows that the actions he/she is taking will be looked down upon by other team members no design discussion happens leading to fragile implementations of &#8216;features&#8217; that may or may not be needed. Once the BA Developer completes his/her &#8216;enhancement&#8217; the BA Developer will contact the team member he/she feels will be least appalled by the actions taken by the BA Developer. The BA Developer will then show the perceived weak team member the changes that were made. A BA Developer if confronted will claim things like &#8216;I have not checked anything in, I just wanted to see how it would look&#8217; caring very little to the untracked wasted time that brings down the overall velocity of a sprint. The BA Developer is in my opinion one of the most toxic personality types to have on a team. Trumped only by the absolute worse The Sneaker.</p>
<h3>The Sneaker</h3>
<p>The Sneaker does not care about process, teamwork, standards, patterns, requirements or quality. You may be totally unaware that a Sneaker is among you until  you see first hand their handy work. The Sneaker is much like BA Developer with one critical infuriating difference. The Sneaker skips the <strong>showing</strong>, checks in the code and says nothing of it. When source control fingers The Sneaker, and you choose to confront the offender The Sneaker will say things like &#8216;well I mentioned it&#8217;, or &#8216;I talked to this person or that person&#8217;. You should fear above all other personality types The Sneaker.</p>
<h3>The No Google-er</h3>
<p>The No Google-er seems harmless at first, though somewhat annoying. When faced with a problem, their first instinct is to ask whoever is near by. Overtime if other developers allow this to continue, The No Google-er actually forgets about the vast resources available to us by simply asking a question to the handy text box on <a href="http://www.google.com">www.google.com</a>. Often times they are in denial that a thing called the &#8216;internet&#8217; exists. The No Google-er not only wastes other team members time he/she is responsible for a disproportionate percentage of defects reported, a problem that is greatly compounded around vacation season when their human search engines are out of town.</p>
<h3>The Watcher</h3>
<p>The Watcher is a strange personality type who&#8217;s motivation is as illusive as it is unpredictable. The single trait that all Watchers have in common however, is that they will hold others up to standard they themselves refuse to follow. A Watcher is the first to comment about other developers non-standard development practices while ignoring broken build notifications. Those who can do, those who can&#8217;t watch.</p>
<h3>The Waiter</h3>
<p>The Waiter is harmless enough, however they can be frustrating. Waiters are very common and come full of wonderful catch phrases like, &#8216;we are kind of low on work, do I did some online reading&#8217;, &#8216;I am waiting on ______&#8217;. Or the classic &#8216;I am ready to take on something new&#8217;. The Waiter is good in that they do not do to much work thus limiting the damage they can do. However they often times pass on work to more advanced team member out of sheer laziness stating that the work is above their skill level.</p>
<p>So there it is! The most common personality types I have run into in my career so far. I am sure you all have your own list, feel free to add them.</p>
<h2><span style="font-weight:normal;"><br />
</span></h2>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/367/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/367/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/367/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=367&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2010/06/17/the-ruin-that-is-indifference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>
	</item>
		<item>
		<title>Lets Date!(An Approach)</title>
		<link>http://brettedotnet.wordpress.com/2009/11/16/lets-datean-approach/</link>
		<comments>http://brettedotnet.wordpress.com/2009/11/16/lets-datean-approach/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 05:14:08 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[C# emm like totally!]]></category>
		<category><![CDATA[Framework Goodness]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=327</guid>
		<description><![CDATA[Dates always seem to give me a headache when working with business apps. Trying to come up with framework level support for handling them is not always easy.  In this post I will outline an approach to dealing with dates that we are using with some success in my current project. Much praise to Matt [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=327&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Dates always seem to give me a headache when working with business apps. Trying to come up with framework level support for handling them is not always easy.  In this post I will outline an approach to dealing with dates that we are using with some success in my current project. Much praise to Matt Lindstrom for the actual implementation of what I am going to outline here.</p>
<p><strong>ORM Mapping</strong></p>
<p>In most databases columns defined as date types can be built to allow nulls. This makes sense when you consider the implications for reporting etc. In .Net the native DateTime object is a value type, thus it cannot represent null. To correct this inconsistency we leverage Nullable&lt;DateTime&gt; for all date properties. And to prevent all the nasty &#8216;HasValue&#8217; checking in our ORM methods we use an extension method on Nullable&lt;DateTime&gt; as follows.</p>
<p><pre class="brush: csharp;">
       /// &lt;summary&gt;
        /// Prepares for database.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;dateTime&quot;&gt;The date time.&lt;/param&gt;
        /// &lt;param name=&quot;includeTimeStamp&quot;&gt;if set to &lt;c&gt;true&lt;/c&gt; [include time stamp].&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static object PrepareForDatabase(this Nullable&lt;DateTime&gt; dateTime)
        {
            if (dateTime.HasValue)
            {
                return dateTime.Value;
            }
            return DBNull.Value;
        }
</pre></p>
<p>This method could be used the following way.</p>
<p><pre class="brush: csharp;">

            /// &lt;summary&gt;
            /// Method used to build command
            /// &lt;/summary&gt;
            /// &lt;param name=&quot;database&quot;&gt;Database to run command against&lt;/param&gt;
            /// &lt;returns&gt;Fully loaded command object ready to execute&lt;/returns&gt;
            public override DbCommand GetCommand(Database database)
            {
                DbCommand command = database.GetStoredProcCommand(&quot;MyInsertCommand&quot;);
                database.AddInParameter(command, &quot;DATE_in&quot;, DbType.DateTime, SomeNullableDate.PrepareForDatabase());
                return command;
            }
</pre></p>
<p>Of course this code only covers the mapping to the data store some additional work is needed when saturating objects with data. Again to support this we added an extension method on the CSLA SafeDataReader. Here we also account for the MinDate assuming that it is the same as a null date.</p>
<p><pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// Gets the nullable date time.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;data&quot;&gt;The data.&lt;/param&gt;
        /// &lt;param name=&quot;i&quot;&gt;The i.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public static DateTime? GetNullableDateTime(this SafeDataReader data, int i)
        {
            if (data.GetDateTime(i).Equals(DateTime.MinValue))
            {
                return null;
            }
            return data.GetDateTime(i);
        }

</pre></p>
<p>And in practice</p>
<p><pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// Method used for ORM mapping of CompRehabCase
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;data&quot;&gt;SafeDataReader&lt;/param&gt;
        private void Populate(SafeDataReader data)
        {
            LoadProperty&lt;Nullable&lt;DateTime&gt;&gt;(SomeNullableDateTime, data.GetNullableDateTime(data.GetOrdinal(&quot;SOME_DATE&quot;)));
        }
</pre></p>
<p>And that all folks.</p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:0;width:1px;height:1px;">
<pre>Nullable&lt;DateTime&gt;</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/327/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=327&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2009/11/16/lets-datean-approach/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>
	</item>
		<item>
		<title>Do You DoEvents?</title>
		<link>http://brettedotnet.wordpress.com/2009/11/11/do-you-doevents/</link>
		<comments>http://brettedotnet.wordpress.com/2009/11/11/do-you-doevents/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 03:56:43 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[General Goodies]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=308</guid>
		<description><![CDATA[Often times during the development of enterprise software requirements arise stating that specific operations need to be handled both synchronously and asynchronously. A perfect example of this is printing. Perhaps a user wishes to print a document and wait for confirmation of a successful print operation before moving on to the next step of their [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=308&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Often times during the development of enterprise software requirements arise stating that specific operations need to be handled both synchronously and asynchronously. A perfect example of this is printing. Perhaps a user wishes to print a document and wait for confirmation of a successful print operation before moving on to the next step of their business process. Or perhaps the user wants to request a print operation for multiple documents in a fire and forget fashion. In one case we should provide some sort of user interface cue as to the status of the print operation and in the other we just fire and forget, while hoping everything works out.</p>
<h3>Thinking Synchronously</h3>
<p>So we have a WPF window with a Print Button we also have a label to indicate the status of the running print job.</p>
<h4>Some XAML</h4>
<p><pre class="brush: xml;">
&lt;Window x:Class=&quot;WpfApplication2.Print&quot;
 xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
 xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
 Title=&quot;Print&quot; Height=&quot;300&quot; Width=&quot;300&quot;&gt;
 &lt;Grid&gt;
 &lt;StackPanel&gt;
 &lt;Button Command=&quot;{Binding Path=PrintCommand}&quot;&gt;Print&lt;/Button&gt;
 &lt;Label Content=&quot;{Binding Path=PrintStatus}&quot;/&gt;
 &lt;/StackPanel&gt;
 &lt;/Grid&gt;
&lt;/Window&gt;
</pre></p>
<h4>Code Behind</h4>
<p><pre class="brush: csharp;">
using System.ComponentModel;
using System.Threading;
using System.Windows;

namespace WpfApplication2
{
    /// &lt;summary&gt;
    /// Interaction logic for Print.xaml
    /// &lt;/summary&gt;
    public partial class Print : Window, INotifyPropertyChanged
    {
        #region Private Data Members

        private string mPrintStatus;

        #endregion

        #region Constructor

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref=&quot;Print&quot;/&gt; class.
        /// &lt;/summary&gt;
        public Print()
        {
            InitializeComponent();
            DataContext = this;
            PrintCommand = new RelayCommand(PrintExecuted);
            PrintStatus = &quot;Ready&quot;;
        }

        #endregion

        #region Private Methods

        /// &lt;summary&gt;
        /// Prints the specified parameter.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;parameter&quot;&gt;The parameter.&lt;/param&gt;
        private void PrintExecuted(object parameter)
        {
            PrintStatus = &quot;Print Executed&quot;;
            //Long Running Print Operatoin
            Thread.Sleep(1000);
            PrintStatus = &quot;Print Completed&quot;;
        }

        #endregion

        #region Public Properties

        /// &lt;summary&gt;
        /// Gets or sets the print status.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The print status.&lt;/value&gt;
        public string PrintStatus
        {
            get
            {
                return mPrintStatus;
            }
            private set
            {
                mPrintStatus = value;

                var handler = PropertyChanged;
                if (handler != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(&quot;PrintStatus&quot;));
                }
            }
        }

        /// &lt;summary&gt;
        /// Gets or sets the print command.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The print command.&lt;/value&gt;
        public RelayCommand PrintCommand
        {
            get;
            private set;
        }

        #endregion

        #region INotifyPropertyChanged Members

        /// &lt;summary&gt;
        /// Occurs when a property value changes.
        /// &lt;/summary&gt;
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}

</pre></p>
<p>Looking at the code here you can see that the intended behavior is as follows.</p>
<ol>
<li>User Clicks Print Button</li>
<li>PrintCommand is executed</li>
<li>A label used to show the print status is updated from &#8216;Ready&#8217; to &#8216;Print Executed&#8217;</li>
<li>The long running Thread.Sleep is called simulating a synchronous print operation</li>
<li>Once complete the status is again changed to &#8216;Print Completed&#8217;</li>
</ol>
<p>This sequence of events does actually happen, the problem however is that it all happens within the execution scope of the  PrintExecuted method. Since this method is blocking until completed the user never sees the nice status updates we provide.</p>
<div id="attachment_319" class="wp-caption alignleft" style="width: 293px"><img class="size-full wp-image-319" title="Before Click" src="http://brettedotnet.files.wordpress.com/2009/10/croppercapture7.png?w=700" alt="Before Click"   /><p class="wp-caption-text">Before Click</p></div>
<p>When the window is loaded the status is set to &#8216;Ready&#8217; as seen in the image on the left. Once the print button is clicked we want to change the status to &#8216;Print Executed&#8217; and finally when the PrintCommand is complete to &#8216;Print Complete&#8217;. However since the updates to the status all happen while the UI thread is blocking, the status of &#8216;Print Executed&#8217; never makes it to the user. Instead the status will transition from &#8216;Ready&#8217; directly to &#8216;Print Completed&#8217;  upon command completion. This presents a pretty serious issue if you need to give the user meaningful feedback about what is going on. On interesting way to get around this is to use DoEvents.</p>
<h3>Do a What?</h3>
<p>If you came to the wonderful world of WPF DoEvents was something new to you. In fact when I first presented this problem to a colleague with a strong Win Forms background he was quick to mention this. So what is it?</p>
<p><a href="http://" target="_blank">Take a look</a></p>
<p>To make a long story short DoEvents allows you to interrupt current event processing in order to process waiting events in the message pumps message queue. The good/bad news depending on your view of such things, is that if you need to replicated DoEvents in WPF you can. Because  WPF and WinForms both leverage the User32 message pump. the solution ends up to be very simple Lets take a look and what our PrintExecuted method might look like.</p>
<p><pre class="brush: csharp;">
#region Private Methods

        /// &lt;summary&gt;
        /// Prints the specified parameter.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;parameter&quot;&gt;The parameter.&lt;/param&gt;
        private void PrintExecuted(object parameter)
        {
            PrintStatus = &quot;Print Executed&quot;;
            Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
            Thread.Sleep(1000);
            PrintStatus = &quot;Print Completed&quot;;
        }

        #endregion
</pre></p>
<p>This approach give us the desired behavior of all of the status updates being presented to the user. Why this may not be a great illustration of proper use of an admitted hack. It is always good to have another tool in your toolbox.</p>
<p>Enjoy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/308/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=308&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2009/11/11/do-you-doevents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>

		<media:content url="http://brettedotnet.files.wordpress.com/2009/10/croppercapture7.png" medium="image">
			<media:title type="html">Before Click</media:title>
		</media:content>
	</item>
		<item>
		<title>AcroRd32.exe I hate you (well kinda).</title>
		<link>http://brettedotnet.wordpress.com/2009/10/13/acrord32-exe-i-hate-you-well-kinda/</link>
		<comments>http://brettedotnet.wordpress.com/2009/10/13/acrord32-exe-i-hate-you-well-kinda/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 19:08:17 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[C# emm like totally!]]></category>
		<category><![CDATA[General Goodies]]></category>
		<category><![CDATA[Things I Hate]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=269</guid>
		<description><![CDATA[The WebBrowser control is a pretty cool thing. You can use it to host many different document types allowing the user to work with a specific type of document in its most common user interface, at the same time the WebBrowser control frees the developer from writing much of the interop code that would be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=269&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The WebBrowser control is a pretty cool thing. You can use it to host many different document types allowing the user to work with a specific type of document in its most common user interface, at the same time the WebBrowser control frees the developer from writing much of the interop code that would be needed otherwise. And that is always a plus!</p>
<p>However as with any kind of inter-operation between disparate technologies you run into hiccups. A good example of this is what happens when you use the WebBrowser control as a container for AcroRd32.exe to view PDF documents. To understand this &#8216;hiccup&#8217; we can look to Adobe knowledge base for some guidance.</p>
<blockquote><p>Adobe Acrobat and Adobe Reader are designed to continue running for a few minutes after you close the browser window in which you viewed PDF files.</p></blockquote>
<p>If you are interested in a more detailed description take take a gander at this <a href="http://kb2.adobe.com/cps/331/331506.html">KB</a>.</p>
<p>Adobes &#8216;Design&#8217; decisions present several challenges when working with PDF documents in a WebBrowser control. The following use case illustrates it best.</p>
<ol>
<li>User searches for a document.</li>
<li>User views document (Presumably in a WebBrowser control).</li>
<li>User closes document.</li>
<li>User attempts to delete the document after closing it.</li>
</ol>
<p>A issue arises when the user attempts to delete the document upon closing it. Because AcroRd32.exe will hang on to your precious PDF document for &#8216;few minutes&#8217; upon closure any attempt to delete said document will result in the following error.</p>
<blockquote><p>The process cannot access the file &#8216;YourPdf.pdf&#8217; because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)</p></blockquote>
<p>This is a problem. Adobe is holding our document hostage. <strong>This aggression will not stand man!</strong> Outside of killing the AcroRd32 process (an option that results in all open PDF documents being closed) we have very little recourse against Adobe&#8217;s design decision. Getting around this little hiccup ends up being pretty simple and involves always loading a &#8216;working&#8217; version of the file. Or simply stated every document you load with the WebBrowser control should be a copy of actual document you want to work with. So how do we manage that copy? I suppose there are several ways to do this. However one I found particularly interesting was to use the use the <a title="TempFileCollection" href="http://msdn.microsoft.com/en-us/library/system.codedom.compiler.tempfilecollection.aspx" target="_blank">TempFileCollection </a>in the System.CodeDom.Compiler namespace. This was interesting to me for one major reason,  when adding a file to this collection you can supply a flag to indicated that it should be removed upon garbage collection. This is perfect when you truly want a working file and you want it to be gone when you are done with it. Lets take a look at some code that might do this.</p>
<p><pre class="brush: plain;">&lt;Window x:Class=&quot;PDFSample.Window1&quot;
 xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
 xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
 Title=&quot;Window1&quot;&gt;
 &lt;Grid&gt;
 &lt;Grid.ColumnDefinitions&gt;
 &lt;ColumnDefinition /&gt;
 &lt;/Grid.ColumnDefinitions&gt;
 &lt;WebBrowser x:Name=&quot;wbPdfViewer&quot;
 Grid.Column=&quot;0&quot; /&gt;
 &lt;/Grid&gt;

&lt;/Window&gt;

</pre></p>
<p>and the code behind&#8230;.</p>
<p><pre class="brush: csharp;">
using System;
using System.CodeDom.Compiler;
using System.Windows;

namespace PDFSample
{
    /// &lt;summary&gt;
    /// Interaction logic for Window1.xaml
    /// &lt;/summary&gt;
    public partial class Window1 : Window
    {
        #region Private Data Members

        private readonly TempFileCollection mTempFile = new TempFileCollection();

        #endregion

        #region Constructor

        /// &lt;summary&gt;
        /// Initializes a new instance of the &lt;see cref=&quot;Window1&quot;/&gt; class.
        /// &lt;/summary&gt;
        public Window1()
        {
            InitializeComponent();
            wbPdfViewer.Source = new Uri(GetWorkingDocumentPath());
        }

        #endregion

        /// &lt;summary&gt;
        /// Gets the working document path.
        /// &lt;/summary&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        private string GetWorkingDocumentPath()
        {
            string workingFile = string.Concat(System.IO.Path.GetTempPath(), &quot;MySampleApp_&quot;, Guid.NewGuid(),&quot;.pdf&quot;);
            System.IO.File.Copy(@&quot;C:\Unity-v1p2-October08.pdf&quot;, workingFile);
            mTempFile.AddFile(workingFile, false);
            return workingFile;
        }
    }
}

</pre></p>
<p>Enjoy!</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/269/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=269&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2009/10/13/acrord32-exe-i-hate-you-well-kinda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>
	</item>
		<item>
		<title>I Hate Trees</title>
		<link>http://brettedotnet.wordpress.com/2009/08/21/i-hate-trees/</link>
		<comments>http://brettedotnet.wordpress.com/2009/08/21/i-hate-trees/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 23:49:03 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[C# emm like totally!]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Things I Hate]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=255</guid>
		<description><![CDATA[So not really. I don&#8217;t particularly mind trees. Tree controls on the other hand I hate. Take for example a simple requirement of launching a new window each time a tree item is selected. Simple right? Well not in WPF. Lets look at a quick example. The idea here is simple. I want to click [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=255&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So not really. I don&#8217;t particularly mind trees. Tree controls on the other hand I <strong>hate</strong>. Take for example a simple requirement of launching a new window each time a tree item is selected. Simple right? Well not in WPF. Lets look at a quick example.</p>
<p><pre class="brush: xml;">
&lt;Window x:Class=&quot;WpfApplication1.Window1&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    Title=&quot;Window1&quot; Height=&quot;300&quot; Width=&quot;300&quot;&gt;
    &lt;Grid&gt;
        &lt;TreeView&gt;
            &lt;TreeViewItem Header=&quot;Root&quot;&gt;
                &lt;TreeViewItem Header=&quot;Parent&quot; &gt;
                    &lt;TreeViewItem Header=&quot;Child&quot; Selected=&quot;ChildTreeViewItem_Selected&quot;&gt;&lt;/TreeViewItem&gt;
                &lt;/TreeViewItem&gt;
            &lt;/TreeViewItem&gt;
        &lt;/TreeView&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;
</pre></p>
<div id="attachment_257" class="wp-caption alignnone" style="width: 310px"><img class="size-full wp-image-257" title="Nice Tree!" src="http://brettedotnet.files.wordpress.com/2009/08/croppercapture3.png?w=700" alt="Pile!"   /><p class="wp-caption-text">Pile!</p></div>
<p>The idea here is simple. I want to click on the TreeViewItem labeled &#8216;child&#8217; and launch a new Window when the its Selected event is raised.</p>
<p><pre class="brush: csharp;">
namespace WpfApplication1
{
    /// &lt;summary&gt;
    /// Interaction logic for Window1.xaml
    /// &lt;/summary&gt;
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void ChildTreeViewItem_Selected(object sender, RoutedEventArgs e)
        {
            new Window().Show();
        }
    }
}
</pre></p>
<p>Ok so maybe that is not <em>all</em> want. Along with a new window launching, I want it to have focus, and I want the TreeViewItem clicked to turn gray indicating the selection made. Sadly however, this is not what I get. Instead the window is launched *not to bad*, however the new window does not have focus after it is activated *who needs focus*. If that is not bad enough adding insult to injury the TreeViewControl in what I can only imagine is a last ditch effort to handle focus raises a second Selection event on the the TreeViewItem labeled Parent. This *bonus* event sets focus back to the TreeViewControl, showing the incorrect TreeViewItem selected. Like so.</p>
<div id="attachment_262" class="wp-caption aligncenter" style="width: 310px"><img class="size-medium wp-image-262" title="I Hate You" src="http://brettedotnet.files.wordpress.com/2009/08/croppercapture4.png?w=300&#038;h=141" alt="HATE YOU" width="300" height="141" /><p class="wp-caption-text">HATE YOU</p></div>
<p>Humm this image is not so clear how is this.</p>
<div id="attachment_264" class="wp-caption aligncenter" style="width: 358px"><img class="size-full wp-image-264" title="More Pile" src="http://brettedotnet.files.wordpress.com/2009/08/croppercapture5.png?w=700" alt="Pile"   /><p class="wp-caption-text">Pile</p></div>
<p>In the image above you will see that the &#8216;Parent&#8217; node is selected. That would be fine if that is what I clicked!</p>
<p>Okay okay rant done. How to fix this? Well I spent a day on this sadly, hence the blog posting. Turns out in order to get this to work you need to use the dispatcher. I am not sure why but when I use a simple Action delegate to launch the window using the Dispatcher it all works just fine. Here is the code.</p>
<p><pre class="brush: csharp;">
namespace WpfApplication1
{
    /// &lt;summary&gt;
    /// Interaction logic for Window1.xaml
    /// &lt;/summary&gt;
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void ChildTreeViewItem_Selected(object sender, RoutedEventArgs e)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =&gt; new Window().Show()));
        }
    }
}
</pre></p>
<p>Anyone care to comment on why this works? Well at least it does!</p>
<p>Enjoy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/255/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=255&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2009/08/21/i-hate-trees/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>

		<media:content url="http://brettedotnet.files.wordpress.com/2009/08/croppercapture3.png" medium="image">
			<media:title type="html">Nice Tree!</media:title>
		</media:content>

		<media:content url="http://brettedotnet.files.wordpress.com/2009/08/croppercapture4.png?w=300" medium="image">
			<media:title type="html">I Hate You</media:title>
		</media:content>

		<media:content url="http://brettedotnet.files.wordpress.com/2009/08/croppercapture5.png" medium="image">
			<media:title type="html">More Pile</media:title>
		</media:content>
	</item>
		<item>
		<title>A Better Sandwich!</title>
		<link>http://brettedotnet.wordpress.com/2009/08/02/a-better-sandwich/</link>
		<comments>http://brettedotnet.wordpress.com/2009/08/02/a-better-sandwich/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 22:02:20 +0000</pubDate>
		<dc:creator>brettedotnet</dc:creator>
				<category><![CDATA[General Goodies]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brettedotnet.wordpress.com/?p=246</guid>
		<description><![CDATA[When considering topics for blog posts more often then not I filter out ideas based on their technical merit. I try my best to offer solutions to problems that I face everyday as a software developer in an attempt to repay the many others who&#8217;s blog postings have helped me. This post however does not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=246&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When considering topics for blog posts more often then not I filter out ideas based on their technical merit. I try my best to offer solutions to problems that I face everyday as a software developer in an attempt to repay the many others who&#8217;s blog postings have helped me. This post however does not fall into that category. So feel free to ignore it.</p>
<p>In a recent dinner with my wife and her parents. I retold a story that  my wife has heard many times before. This particular time however, I managed to make some correlations to software development that had not previously occurred to me. So before I go any further let me retell the story&#8230;. Again&#8230;</p>
<p>In the beginning&#8230;. Wait wrong story.</p>
<p>When I was in high school I was dating a girl who in all accounts was much smarter then I was. However since I was a rocking guitar player and all around rebel she found my charms irresistible.</p>
<p>*The statement above is a <strong>complete embellishment</strong> except for the fact that she was indeed much smarter then I am*</p>
<p>One night while the two of us sat in my parents kitchen, I decided to take full advantage of the refrigerator filled with all of the parental subsidized food you could imagine, and make us some sandwiches. I grabbed some lunch meat, lettuce, tomatoes, mustard and all the other standard sandwich fixings available. I reached for the bread box to grab the bread, and the sandwich making commenced. </p>
<p>First up my sandwich (because I am selfish). I slapped down two slices of bread and started to add the fixings. On one slice went the meat, and on the other slice all of the fixings, salad, mustard, onions etc. Once all of the fixings were in place I grabbed each fully loaded slice and tried my best to marry the two without dumping the fixings all over. I managed to get the sandwich together like I had with all sandwiches before. After all I was not at all new to the art of sandwich making with free ingredients. I took a look over at my girlfriend expecting a look of awe as she basked in my artistry. Instead I got a look of utter confusion mixed in with a little disgust. She said, &#8220;Really? That is how you make a sandwich?&#8221; <em>This was the beginning of the end for use as a couple</em>. She then continued to tell my how much easier it would have been if I put all of the fixings on one slice of bread, and simply placed the second slice on top.</p>
<p>Her words flipped my world upside down. I could not believe what she was saying! It was a perfect solution. A perfect solution to a problem I never thought existed! I then proceeded to make her the most efficiently crafted sandwich I had ever made. It was a work of art that would bring the likes of Picasso to tears.</p>
<p>And that is the story. My story of a better sandwich! So why blog about it?</p>
<p>Well at that moment when my girlfriend pointed out the problems in my process I realized that had she not done so, I would have continued making sandwiches that way. Who knows how long or how many sandwiches would have fallen victim to my intellectual laziness. The reason this horrible process would have continued is because despite its short comings it did in fact work. At the end of this process I could always partake in some tasty sandwich goodness.</p>
<p>The point here is simple. You can go years and years doing what you do the way you always have. The results after all in this case were just fine. The same is true in software development. We can follow all of the patterns we have always followed. We use all of the best practices we have spent so long learning and mastering over and over again. And as long as we do that and nothing major changes we can turn our brains off and churn out application after application, object after object, and pattern after pattern. And all along never even considering that there may be a much better way to make a sandwich. And if we are not looking for ways to make our sandwiches better, what the hell is the point!</p>
<p>Enjoy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/brettedotnet.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/brettedotnet.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/brettedotnet.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/brettedotnet.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/brettedotnet.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/brettedotnet.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/brettedotnet.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/brettedotnet.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/brettedotnet.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/brettedotnet.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/brettedotnet.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/brettedotnet.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/brettedotnet.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/brettedotnet.wordpress.com/246/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=brettedotnet.wordpress.com&amp;blog=7263997&amp;post=246&amp;subd=brettedotnet&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://brettedotnet.wordpress.com/2009/08/02/a-better-sandwich/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e418545b0a91e17d96e216530bffeb45?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brette.Net</media:title>
		</media:content>
	</item>
	</channel>
</rss>
