<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Recursive Erudition</title>
	<atom:link href="http://erudition.radianttiger.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://erudition.radianttiger.com</link>
	<description>Learn. Teach. Learn.</description>
	<lastBuildDate>Wed, 25 Nov 2009 08:45:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Too Easy: Instant Data Access Layer with SubSonic and SQLite</title>
		<link>http://erudition.radianttiger.com/?p=88</link>
		<comments>http://erudition.radianttiger.com/?p=88#comments</comments>
		<pubDate>Tue, 20 Oct 2009 23:41:55 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/?p=88</guid>
		<description><![CDATA[It’s frightening just how much pain I have in starting a new application project. Creating an SQL database, deploying a schema, building an ORM access layer, and putting all the pieces into source control to deploy, version, update that database, both on the development SQL Express, and the production SQL Server instances&#8212;it takes time. It [...]]]></description>
			<content:encoded><![CDATA[<p>It’s frightening just how much pain I have in starting a new application project. Creating an SQL database, deploying a schema, building an ORM access layer, and putting all the pieces into source control to deploy, version, update that database, both on the development SQL Express, and the production SQL Server instances&#8212;it takes time. It takes work. The only thing worse than putting in all that effort is doing the cowboy bit with the tools and NOT doing it. Then you have various unsynchronized, untestable, messy databases and deployed versions of code. Oook!</p>
<p><a href="http://www.subsonicproject.com/">SubSonic 3.0</a> introduced the <a href="http://subsonicproject.com/docs/Using_SimpleRepository">SimpleRepository</a> and <a href="http://www.subsonicproject.com/docs/3.0_Migrations">Auto-Migrations</a>. These Ruby-on-Rails-inspired features, when coupled with SQLite can make your DAL-creation tasks just disappear. Let’s give it a try!</p>
<ol>
<li><font style="background-color: #ffffff">Download and install <a href="http://sqlite.phxsoftware.com/">System.Data.SQLite</a>. This distribution of SQLite is a single mixed-mode dll that contains a recent SQLite build as well as ADO.NET bindings for the database. Also in the package is a linq provider, and Visual Studio Server Explorer support. </font><a href="http://erudition.radianttiger.com/wp-content/uploads/2009/10/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://erudition.radianttiger.com/wp-content/uploads/2009/10/image_thumb.png" width="404" height="148" /></a> </li>
<li>Download <a href="http://subsonicproject.com/Download">SubSonic 3</a>. There’s all sorts of great stuff in this download. Three different data access models. Modifiable templates. Examples. But you only need the single dll from the binaries folder. Toss the rest in a drawer and look at it later. </li>
<li>Add some the references to your project.      <br /><a href="http://erudition.radianttiger.com/wp-content/uploads/2009/10/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://erudition.radianttiger.com/wp-content/uploads/2009/10/image_thumb1.png" width="176" height="131" /></a>&#160; </li>
<li>Create a RepositoryFactory class:      <br /> 
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> SubsonicRepositoryFactory{    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> SimpleRepository GetRepository()    {        var provider = SubSonic.DataProviders.ProviderFactory.GetProvider(<span style="color: #006080">&quot;Data Source=|DataDirectory|my.db&quot;</span>, <span style="color: #006080">&quot;System.Data.SQLite&quot;</span>);        var repository = <span style="color: #0000ff">new</span> SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);        <span style="color: #0000ff">return</span> repository;    }}</pre>
<p></div>
<p>This isn’t strictly necessary…but I hate putting my connection strings in all those angle brackets, and prefer to detect my production/test/development environments in code rather than in XML. </li>
<li>You’re done! Make your own POCOs and use commands like SubsonicRepositoryFactory.GetRepository().Add(myObject);</li>
<li>Go home. You’ve worked hard. Relax.</li>
</ol>
<p>This is good stuff, and it certainly can take some of the pressure off of starting up a new project. With data access and persistence just ‘done’, you can get to logic and value quicker. And you always have the option of upgrading to a more ‘serious’ data layer if you need it later. I’m really curious if SubSonic/SQLite can provide a reasonably performant small-to-midsize backing store to a web service application server. If your applications and various UIs all access their data through the web services, who cares what the persistence storage is, and until that back end is doing enough work to require multiple servers, how much trouble can you get into by caching your objects in memory and persisting them to disk using SQLite?</p>
<p>It’s also worth noting that SimpleRepository doesn’t have any wiring for child collections yet. Rob has said on StackOverflow that he intends to do some work on that, but it’s not in there yet. However, it shouldn’t be too hard to drop some convenience methods on your POCOs (extension methods if you’re worried about polluting your classes) to emit Lists or IEnumerables of linked collections.</p>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=88</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t plug your Clear Wireless Modem into your Macintosh</title>
		<link>http://erudition.radianttiger.com/?p=87</link>
		<comments>http://erudition.radianttiger.com/?p=87#comments</comments>
		<pubDate>Tue, 20 Oct 2009 21:53:34 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[Editorial]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/?p=87</guid>
		<description><![CDATA[Update: The most recent versions of the drivers may have solved these problems. Works for me now. WARNING! If you plug your Clear Wireless modem into a Macintosh computer with Clear’s driver installed, the modem will be flashed with a firmware that makes it incompatible with Windows. This firmware flash is not reversible. You will [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: </strong>The most recent versions of the drivers may have solved these problems. Works for me now.</p>
<p><strong>WARNING! </strong>If you plug your Clear Wireless modem into a Macintosh computer with Clear’s driver installed, the modem will be flashed with a firmware that makes it incompatible with Windows. This firmware flash is not reversible. You will need to return your modem to Clear to get a new Windows-compatible one. More details below.</p>
<p>I got connected with Clear Wireless in Portland 4 days ago. So far I’m very happy with the bandwidth. Connected to my laptop, I’m getting 3mbs down and 200kbps up speeds. For mobile, unlimited internet, this is fantastic. Even better, I’m getting 100-160ms packet latencies, which is about one-third of what I was getting on my cellular wireless modem.</p>
<p><a href="http://erudition.radianttiger.com/wp-content/uploads/2009/10/photo2.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="photo(2)" border="0" alt="photo(2)" src="http://erudition.radianttiger.com/wp-content/uploads/2009/10/photo2_thumb.jpg" width="141" height="244" /></a> </p>
<p>I also purchased the Clear Spot WiFi/WWAN router. This little device is really cool, letting me share my WIMAX connection with other computers, my iPhone, or whatever. Even better, it lets me use the WIMAX modem without installing drivers. This is great because the drivers for WWAN modems are terrible….and Clear doesn’t have average quality drivers.</p>
<p><a href="http://erudition.radianttiger.com/wp-content/uploads/2009/10/photo.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="photo" border="0" alt="photo" src="http://erudition.radianttiger.com/wp-content/uploads/2009/10/photo_thumb.jpg" width="244" height="224" /></a></p>
<h2></h2>
<h2>Windows 7 Drivers</h2>
<p>Ok. So there aren’t Windows 7 drivers. Yet. The folks at Clear have told me I can expect to see them on Thursday, when the official launch date happens. In the meantime, install the connection manager from your CD or Driver Thumb Drive(in the box), and do a little googling for instructions on installing the older version of the drivers. Scott Hanselman <a href="http://www.hanselman.com/blog/ReviewTryingClearFromClearwireMobileBroadbandService.aspx">wrote up</a> something on this. You can also <a href="http://erudition.s3.amazonaws.com/Vista64.zip?AWSAccessKeyId=0R1668FQJS2V95SCZZG2&amp;Expires=1264713943&amp;Signature=zQZrL/NO7/FXY2hPYbhesS/44gY%3D">download the 64-bit driver</a> from here for a couple months.</p>
<p>Also, be sure not to unplug the Modem before using the ‘Safely Eject’ feature of Windows….I get a BSOD every time.</p>
<p>The Win7 drivers work. They aren’t shiny or easy to install, but they work. That’s much better than the…</p>
<h2>Mac OS X Drivers</h2>
<p>When Clear says they support Mac OS X, they are…well…reaching. Their driver is marked ‘Beta’ and it shows. After the install, the Connection Manager will spend 5 minutes or so just sitting there. No status message, and a red light on the modem. Is it working? Is it doing something? Who knows. After that, it will connect, and you’re set to go. Same good service.</p>
<p>Unless.</p>
<p>If you are running Snow Leopard (Mac OS X 10.6) you get nothing. No error message. No indication of failure. No connection. It just doesn’t work. Saying Windows 7 isn’t released yet is <em>technically</em> true, and I understand why those drivers aren’t out. OS X 10.6 has been out since August 28th. It seems foolish that an early-adopter service like Clear doesn’t support an early-adopter OS. That’s how it is, though. Clear people have told me unofficially that we should see a 10.6 driver ‘by the end of the month’. We’ll see.</p>
<h2>You can’t go back again</h2>
<p>The reason for the 5 minute wait when you install your Mac drivers is apparently that the drivers are installing a fresh firmware on your modem. As I stated at the top, this firmware isn’t compatible with the Windows drivers. Nor does Clear have a flash utility available that can downgrade it. You have to return your modem for a replacement. Clear has told me that this should be free, since it’s “Their Fault”. Be nice when you call, and they should hook you up.</p>
<h2>WiFi to the rescue</h2>
<p>Luckily, the Clear Spot can still connect to the modem with it’s new, corrupted, Mac OS (10.5 or earlier)-only firmware. I really like the driver-less mobile internet experience. No need for the hassle of incomplete, incompatible drivers or connection managers. Just Windows 7’s shiny new WiFi connection tool and fast internets.</p>
<p>The Clear Spot (Cradlepoint PHS-300) is a great router, works with non-Clear broadband modems, and is $50 cheaper when you get it from Clear. The battery seems to last a bit more than 3 hours with the network in use. You can get extra batteries and a car charger from Clear, but I think an external <a href="http://3gstore.com/index.php?main_page=product_info&amp;products_id=1571&amp;cPath=238&amp;m1track=googlebase#googlebase">Tekkeon battery</a> is probably a better idea. When you get it from 3Gstore, it comes with a USB cable that I’m hoping will let me charge my Clear Spot from my laptop. One less wall wart in my kit bag.</p>
<p>There is a slight glitch. Most of the pictures you’ll see of the Clear Spot will show it with the modem plugged right into it. It turns out this is a bad idea. WiFi and WiMax radios seem to <a href="http://www.cradlepoint.com/files/uploads/ReleaseNotesCTR_2_4_5.pdf">interfere</a>. Make sure you leave the router on Channel 1. I also didn’t get anything approaching full speeds until I used a USB extension cable to put some space between the two devices. Once I did that, speeds were right up there.</p>
<h2></h2>
</p>
<h2>Good support experience</h2>
<p>Clear’s service is definitely in early-adopter mode, but I had a really excellent experience both with the store staff, and with the folks at technical support. It took me 20 minutes on the phone to figure out my Mac/PC Firmware problem, but the rep was patient and eager to help, and that is an excellent experience these days.</p>
<p>I like my Clear service and I recommend it if you want some better mobile bandwidth.</p>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=87</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding MvcContrib SubControllers to your ASP.NET MVC Project</title>
		<link>http://erudition.radianttiger.com/?p=55</link>
		<comments>http://erudition.radianttiger.com/?p=55#comments</comments>
		<pubDate>Tue, 04 Aug 2009 06:07:28 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/PermaLink,guid,615d7ba1-babe-4813-98d4-e6f713e7ebf3.aspx</guid>
		<description><![CDATA[After a little bit of work with MVC, you get infected with the spirit of clean code and begin to desire even more ways of eliminating repetition. You’ve got partials and html helpers. Still you are hungry. SubControllers are the dish that will fill you up. Why SubControllers? There’s a design decision here. The question [...]]]></description>
			<content:encoded><![CDATA[<p>
After a little bit of work with MVC, you get infected with the spirit of clean code<br />
and begin to desire even more ways of eliminating repetition. You’ve got partials<br />
and html helpers. Still you are hungry. SubControllers are the dish that will fill<br />
you up.
</p>
<h2>Why SubControllers?<br />
</h2>
<p>
There’s a design decision here. The question is why are we designing with subcontrollers?<br />
To understand the rationale, let’s look at the qualities of the various sub-view options.
</p>
<ul>
<li>
Partial Views – partial views are probably the most useful method for re-using view<br />
output. They are very easy to set up, and are very versatile. However, they don’t<br />
contain logic. They are intended entirely as a slave to the Action Controller. They<br />
get their model from the controller and simply render it. This means that the controller<br />
needs to know and provide everything the partial view needs. Not good for something<br />
like a login status control, which is an separate concern from most controllers.</li>
<li>
HTML Helpers – HTML helpers get used a lot, and they are very helpful for creating<br />
your own ‘controls’ to use in your pages. They do not, however, support using a view<br />
template. This means you’ve got to create them and test them with tests for emitted<br />
markup. This adds a lot of complexity if you are trying to do something more than<br />
create a html rendering function. Not a good place to insert complex view logic, like<br />
a shopping cart status widget, or anything with a table or list. The HTML helper also<br />
still gets it’s data from the master view/controller, so it fails at separating concerns.</li>
<li>
Html.RenderAction() – RenderAction is the once and future solution to a number of<br />
problems. Or so I hear. I have trouble getting excited about using it right now. Currently,<br />
it is not baked into MVC, but rather is in the separate ‘MVC Futures’ assembly, where<br />
it is unsupported. Rumor is it is buggy and unsecure. In the future it may be changed<br />
or dropped or renamed or anything. ScottGu has promised in a blog comment that it<br />
is due for inclusion in MVC 2. However, I don’t program to unreleased Microsoft products.<br />
Maybe later, but for now…</li>
<li>
MvcContrib SubController – Jeff Palermo implemented subcontrollers for MvcContrib<br />
to give us a working solution—now—for reusable view/controller code. Subcontrollers<br />
have their own model, ViewData, are nestable, and can use view templates for their<br />
output. If you have a job that goes beyond a partial view, or a html helper, SubControllers<br />
are a peach.</li>
</ul>
<h2>Setting Up Your Project<br />
</h2>
<p>
1) Add a reference to MvcContrib.
</p>
<p>
2) Create a class called StructureMapSubControllerBinder. This is only required if<br />
you’re using StructureMap to do your IOC for you. You can use the base SubControllerBinder<br />
from MvcContrib, or create your own version for your IOC tool.
</p>
<ol>
</ol>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> StructureMapSubControllerBinder
: SubControllerBinder
{
<span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">object</span> CreateSubController(Type
destinationType)
{
<span style="color: #0000ff">object</span> instance = ObjectFactory.GetInstance(destinationType);
<span style="color: #0000ff">if</span> (instance == <span style="color: #0000ff">null</span>)
{
<span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> InvalidOperationException(destinationType
+ <span style="color: #006080">&quot; not registered with StructureMap&quot;</span>);
}

<span style="color: #0000ff">return</span> instance;
}
}</pre>
<p>
</div>
<p>
&#160;
</p>
<p>
3) Make the SubControllerBinder your default binder.
</p>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">ModelBinders.Binders.DefaultBinder = <span style="color: #0000ff">new</span> StructureMapSubControllerBinder();
</pre>
</div>
<div>4) Add a reference to the MvcContrib namespace to the Pages section of Web.Config.<br />
This will save you putting a lot of namespace tags in your views.
</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;add <span style="color: #0000ff">namespace</span>=<span style="color: #006080">&quot;MvcContrib&quot;</span>/&gt;
</pre>
</div>
<div>

</div>
<h2>Creating a SubController<br />
</h2>
<p>
1) Create a ~/Controllers/SubControllers folder. This is completely optional. If you<br />
have a bigger project you might want to make multiple subcontrollers folders for different<br />
areas.
</p>
<p>
2) Create a SubController class. The action needs to have the ‘same’ name as the class.<br />
It also subclasses from SubController.
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> System.Web.Mvc;
<span style="color: #0000ff">using</span> MvcContrib;

<span style="color: #0000ff">namespace</span> NWIS.Business.Web.Controllers.SubControllers
{
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> DemoSubController
: SubController
{
<span style="color: #0000ff">public</span> ViewResult Demo()
{
<span style="color: #0000ff">return</span> View();
}
}
}</pre>
<p>
</div>
<p>
3) Create a View subfolder. Using the ‘Add View’ context menu from the controller<br />
won’t work because the ‘sub’ in the class name. Just create the folder yourself. ~/Views/Demo.
</p>
<p>
4) Create a View. Right click on the ~/Views/Demo folder. Select Add-&gt;View. Name<br />
the view ‘Demo’. Make it a partial view (.ascx). Go ahead an add some markup to the<br />
view. Whatever you like.
</p>
<h2>Using the SubController in your View<br />
</h2>
<p>
1) Add an attribute to your Controller class.
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[SubControllerActionToViewDataAttribute]
</pre>
<p>
</div>
</p>
</p>
</p>
</p>
<p>
2) Add the subcontroller as a parameter to the action you want to use it in.
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> ViewResult
Index(DemoSubController mySubCont)
</pre>
<p>
</div>
<p>
3) Place the subcontroller output into your view.
</p>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">&lt;% ViewData.Get&lt;Action&gt;(<span style="color: #006080">&quot;mySubCont&quot;</span>).Invoke();
%&gt;
</pre>
</div>
<div>The name you use here is the name of the parameter to the controller action.
</div>
<div>&#160;
</div>
<div>That should be it. You subcontroller can output into your view, and you can use<br />
it in many, many controllers and actions. You can add dependencies directly to the<br />
subcontroller in it’s constructor. You can also pass information from the action to<br />
the subcontroller using properties.<br />

</div>
<h2>Resources<br />
</h2>
<ul>
<li>
<a href="http://mhinze.com/subcontrollers-in-aspnet-mvc/">SubControllers In ASP.NET<br />
MVC</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=55</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Best of Code Syndication</title>
		<link>http://erudition.radianttiger.com/?p=56</link>
		<comments>http://erudition.radianttiger.com/?p=56#comments</comments>
		<pubDate>Mon, 03 Aug 2009 02:42:55 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/PermaLink,guid,0a999b05-e4d2-44ca-af4e-18d658f64c63.aspx</guid>
		<description><![CDATA[I was recently asked about who I learn from, so I threw together this list of good places to get new ideas. Most of these are the RSS Links, not the web sites. I use Google Reader to make sure I keep up. Top 3 Ayende Rahien Uncle Bob Martin Martin Fowler .NET Scott Hanselman [...]]]></description>
			<content:encoded><![CDATA[<p>
I was recently asked about who I learn from, so I threw together this list of good<br />
places to get new ideas. Most of these are the RSS Links, not the web sites. I use<br />
Google Reader to make sure I keep up.
</p>
<h2>Top 3<br />
</h2>
<ul>
<li>
<a href="http://feeds.feedburner.com/AyendeRahien">Ayende Rahien</a>
</li>
<li>
<a href="http://blog.objectmentor.com/xml/rss20/feed.xml">Uncle Bob Martin</a>
</li>
<li>
<a href="http://martinfowler.com/bliki/bliki.atom">Martin Fowler</a>
</li>
</ul>
<h2>.NET<br />
</h2>
<ul>
<li>
<a href="http://feeds.feedburner.com/ScottHanselman">Scott Hanselman</a>
</li>
<li>
<a href="http://feeds.jeffreypalermo.com/jeffreypalermo">Jeffrey Palermo</a>
</li>
<li>
<a href="http://feeds.feedburner.com/davybrion   ">Davy Brion</a>
</li>
<li>
<a href="http://feeds.feedburner.com/UdiDahan-TheSoftwareSimplist">Udi Dahan</a>
</li>
<li>
<a href="http://feeds2.feedburner.com/FransBouma">Frans Bouma</a>
</li>
<li>
<a href="http://feeds.feedburner.com/CodeBetter">Code Better</a>
</li>
</ul>
<h2>General<br />
</h2>
<ul>
<li>
<a href="http://www.joelonsoftware.com/rss.xml">Joel Spolsky</a>
</li>
<li>
<a href="http://feeds.feedburner.com/codinghorror    ">Jeff Atwood</a>
</li>
</ul>
<h2>Security<br />
</h2>
<ul>
<li>
<a href="http://www.schneier.com/blog/index.rdf    ">Schneier on Security</a>
</li>
</ul>
<h2>Funny<br />
</h2>
<ul>
<li>
<a href="http://xkcd.com/rss.xml        ">XKCD</a>
</li>
</ul>
<h2>Podcasts<br />
</h2>
<ul>
<li>
<a href="http://www.altnetpodcast.com/ ">ALT.NET</a>
</li>
<li>
<a href="http://elegantcode.com/category/codecast/ ">Elegant Code</a>
</li>
<li>
<a href="http://www.hanselminutes.com/ ">HanselMinutes</a>
</li>
<li>
<a href="http://herdingcode.com/ ">Herding Code</a>&#160;</li>
<li>
<a href="http://www.dotnetrocks.com/">.NET Rocks</a>&#160;&#160;
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=56</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using StructureMap to Build Your MVC Controllers</title>
		<link>http://erudition.radianttiger.com/?p=57</link>
		<comments>http://erudition.radianttiger.com/?p=57#comments</comments>
		<pubDate>Sun, 26 Jul 2009 23:03:31 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/PermaLink,guid,2370a2f8-f0fe-42c4-836e-a342540e2994.aspx</guid>
		<description><![CDATA[The simplest things seem to be the hardest to find the up-to-date documentation on. Adding a ControllerFactory to MVC is very simple, and making it work with StructureMap is pretty quick, but do you really want to write any of that code? Of course not. Somebody else can do it. The MVC Contrib project has [...]]]></description>
			<content:encoded><![CDATA[<p>
The simplest things seem to be the hardest to find the up-to-date documentation on.<br />
Adding a ControllerFactory to MVC is very simple, and making it work with StructureMap<br />
is pretty quick, but do you really want to write any of that code? Of course not.<br />
Somebody else can do it.
</p>
<p>
The MVC Contrib project has built all of the code you need to make a number of the<br />
popular IoC frameworks work in your project. Unfortunately IoC frameworks update a<br />
lot, and the MvcContrib project was finding it pretty hard to keep up with the latest<br />
versions when they compiled their builds. So that code is deprecated. Don’t use it.
</p>
<p>
Here’s how you add StructureMap to build controllers in your MVC project:
</p>
<p>
<strong>Create a StructureMapControllerFactory Class</strong>
</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Web.Mvc;
<span style="color: #0000ff">using</span> System.Web.Routing;
<span style="color: #0000ff">using</span> StructureMap;

<span style="color: #0000ff">namespace</span> MvcContrib.StructureMap
{
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> StructureMapControllerFactory
: DefaultControllerFactory
{
<span style="color: #0000ff">public</span> <span style="color: #0000ff">override</span> IController
CreateController(RequestContext context, <span style="color: #0000ff">string</span> controllerName)
{
Type controllerType = <span style="color: #0000ff">base</span>.GetControllerType(controllerName);
<span style="color: #0000ff">return</span> ObjectFactory.GetInstance(controllerType) <span style="color: #0000ff">as</span> IController;
}
}
}</pre>
<p>
</div>
</p>
<p>
<strong>Add a Method to Global.asax</strong>
</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> ConfigureIoC()
{
ControllerBuilder.Current.SetControllerFactory(<span style="color: #0000ff">new</span> StructureMapControllerFactory());
}</pre>
<p>
</div>
</p>
<p>
<strong>Add a call to that method in Application_Start</strong>
</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">ConfigureIoC();
</pre>
<p>
</div>
<p>
….and now we can go out for steak and exotic dancers. Your controllers will have their<br />
dependencies injected all nice and purty.</p>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=57</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StructureMap: IRepository and Test Data Injection</title>
		<link>http://erudition.radianttiger.com/?p=58</link>
		<comments>http://erudition.radianttiger.com/?p=58#comments</comments>
		<pubDate>Sun, 26 Jul 2009 21:07:28 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Editorial]]></category>
		<category><![CDATA[StructureMap]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/PermaLink,guid,7a54b461-e7b1-49df-acef-f0c14068bd03.aspx</guid>
		<description><![CDATA[I Love StructureMap! It’s wonderful. What a way to compose your code together easily, precisely, and consolidatedly (!!). When I put a sentence like that together, I wonder if I even know what I’m talking about. The problem with StructureMap, IoC, and dependency injection really seems to be that the jargon for the patterns is [...]]]></description>
			<content:encoded><![CDATA[<p>
I Love StructureMap! It’s wonderful. What a way to compose your code together easily,<br />
precisely, and consolidatedly (!!). When I put a sentence like that together, I wonder<br />
if I even know what I’m talking about. The problem with StructureMap, IoC, and dependency<br />
injection really seems to be that the jargon for the patterns is <strong>so manifestly<br />
true</strong> that once you learn what the hell you are doing, you are completely<br />
unable to stop talking about it in shorthand. And that shorthand makes absolutely<br />
no sense to someone who hasn’t absorbed the patterns. Keep plugging, people. Once<br />
you do it, you’ll get it. Then you’ll be <strong>there</strong> and not be able to<br />
explain to other people why you’re so right. It’s like being Tom Cruise and needing<br />
to explain scientology.
</p>
<p>
Anyways.
</p>
<p>
I learned two things today. The first is how to hook all of my concrete generic repository<br />
types together with their interfaces. I had been adding a line of configuration for<br />
each repository. Now my test code looks like this:
</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">ForRequestedType(<span style="color: #0000ff">typeof</span>(IRepository&lt;&gt;)).TheDefaultIsConcreteType(<span style="color: #0000ff">typeof</span>(ListRepository&lt;&gt;));
</pre>
<p>
</div>
<p>
And my production code:
</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">ForRequestedType(<span style="color: #0000ff">typeof</span>(IRepository&lt;&gt;)).TheDefaultIsConcreteType(<span style="color: #0000ff">typeof</span>(LlblRepository&lt;&gt;));
</pre>
<p>
</div>
</p>
<p>
That’s <em>easy!</em>
</p>
<p>
The other thing I learned is that I can happily and easily inject data into my object<br />
registry for testing purposes. I have an in-memory repository implementation built.<br />
All it needs is data.
</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> MemoryDataSource
{
<span style="color: #0000ff">private</span> Dictionary&lt;Type, IQueryable&gt; data;

<span style="color: #0000ff">public</span> MemoryDataSource(Dictionary&lt;Type, IQueryable&gt;
data)
{
<span style="color: #0000ff">this</span>.data = data;
}

<span style="color: #0000ff">public</span> IQueryable GetQueryable(Type type)
{
<span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.data[type];
}
}
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ListRepository&lt;T&gt;
: IRepository&lt;T&gt;
{
<span style="color: #0000ff">private</span> MemoryDataSource source;

<span style="color: #0000ff">public</span> ListRepository(MemoryDataSource source)
{
<span style="color: #0000ff">this</span>.source = source;
}

<span style="color: #0000ff">public</span> IQueryable&lt;T&gt; GetSource()
{
<span style="color: #0000ff">return</span> ((IQueryable&lt;T&gt;)source.GetQueryable(<span style="color: #0000ff">typeof</span>(T)));
}

<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> SaveEntity(T
entity)
{
<span style="color: #0000ff">return</span>;
}
}</pre>
<p>
</div>
<p>
Now all I need to do is build a Dictionary&lt;&gt; keyed on the entity object type<br />
and fill it up with data. Once I’ve done that, I just pass it into the StructureMap<br />
registry like this:
</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">ObjectFactory.Inject&lt;Dictionary&lt;Type, IQueryable&gt;&gt;(dataSource);
</pre>
<p>
</div>
<p>
Now I can have ObjectFactory construct my object under test and it’s got just the<br />
data I need it to have.</p>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=58</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding MVC to an existing ASP.NET Application</title>
		<link>http://erudition.radianttiger.com/?p=59</link>
		<comments>http://erudition.radianttiger.com/?p=59#comments</comments>
		<pubDate>Sun, 19 Jul 2009 11:26:00 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/PermaLink,guid,5e9e01d4-6ffc-4b21-af5f-14389a17c84b.aspx</guid>
		<description><![CDATA[ASP.NET MVC Has added a very useful new programming model to developing websites in .NET. There is hype and debate all throughout the interwebs on how great MVC is. And it all can be yours, with nothing but a ‘File-&#62;New’ in Visual Studio….unless you already have an ASP.NET application. In which case, you need to [...]]]></description>
			<content:encoded><![CDATA[<p>
ASP.NET MVC Has added a very useful new programming model to developing websites in<br />
.NET. There is hype and debate all throughout the interwebs on how great MVC is. And<br />
it all can be yours, with nothing but a ‘File-&gt;New’ in Visual Studio….unless you<br />
already have an ASP.NET application. In which case, you need to do a bit more work.
</p>
<ol>
<li>
Add project references to:<br />
<br />
System.Web.Abstractions<br />
<br />
System.Web.Mvc<br />
<br />
System.Web.Routing<br />
<br />
<a href="http://erudition.radianttiger.com/content/binary/RecursiveErudition_F94C/AddingMVCtoanexistingASP.NETApplication_12C47/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://erudition.radianttiger.com/content/binary/RecursiveErudition_F94C/AddingMVCtoanexistingASP.NETApplication_12C47/image_thumb.png" width="468" height="386" /></a>
</li>
<li>
Create /Controllers, /Views, and /Views/Shared folders in your project<br />
<br />
<a href="http://erudition.radianttiger.com/content/binary/RecursiveErudition_F94C/AddingMVCtoanexistingASP.NETApplication_12C47/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://erudition.radianttiger.com/content/binary/RecursiveErudition_F94C/AddingMVCtoanexistingASP.NETApplication_12C47/image_thumb_3.png" width="373" height="345" /></a>
</li>
<li>
Update web.config<br />
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">=&quot;1.0&quot;</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">=&quot;utf-8&quot;</span> ?<span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">system.web</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">pages</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">namespaces</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">namespace</span><span style="color: #0000ff">=&quot;System.Web.Mvc&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">namespace</span><span style="color: #0000ff">=&quot;System.Web.Mvc.Ajax&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">namespace</span><span style="color: #0000ff">=&quot;System.Web.Mvc.Html&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">namespace</span><span style="color: #0000ff">=&quot;System.Web.Routing&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">namespace</span><span style="color: #0000ff">=&quot;System.Linq&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">namespace</span><span style="color: #0000ff">=&quot;System.Collections.Generic&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">namespaces</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">pages</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">compilation</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">assemblies</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">assembly</span><span style="color: #0000ff">=&quot;System.Core,
Version=3.5.0.0,
Culture=neutral,
PublicKeyToken=B77A5C561934E089&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">assembly</span><span style="color: #0000ff">=&quot;System.Web.Mvc,
Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">assembly</span><span style="color: #0000ff">=&quot;System.Web.Abstractions,
Version=3.5.0.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">assembly</span><span style="color: #0000ff">=&quot;System.Web.Routing,
Version=3.5.0.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">assemblies</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">compilation</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">httpModules</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;UrlRoutingModule&quot;</span>

<span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;System.Web.Routing.UrlRoutingModule,
System.Web.Routing,
Version=3.5.0.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">httpModules</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">system.web</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">system.webServer</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">validation</span> <span style="color: #ff0000">validateIntegratedModeConfiguration</span><span style="color: #0000ff">=&quot;false&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">modules</span> <span style="color: #ff0000">runAllManagedModulesForAllRequests</span><span style="color: #0000ff">=&quot;true&quot;</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">remove</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ScriptModule&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">remove</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;UrlRoutingModule&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ScriptModule&quot;</span> <span style="color: #ff0000">preCondition</span><span style="color: #0000ff">=&quot;managedHandler&quot;</span>

<span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;System.Web.Handlers.ScriptModule,

System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

PublicKeyToken=31BF3856AD364E35&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;UrlRoutingModule&quot;</span>

<span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;System.Web.Routing.UrlRoutingModule,
System.Web.Routing,

Version=3.5.0.0, Culture=neutral,

PublicKeyToken=31BF3856AD364E35&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">modules</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">handlers</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">remove</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;WebServiceHandlerFactory-Integrated&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">remove</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ScriptHandlerFactory&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">remove</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ScriptHandlerFactoryAppServices&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">remove</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ScriptResource&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">remove</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;MvcHttpHandler&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">remove</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;UrlRoutingHandler&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ScriptHandlerFactory&quot;</span> <span style="color: #ff0000">verb</span><span style="color: #0000ff">=&quot;*&quot;</span> <span style="color: #ff0000">path</span><span style="color: #0000ff">=&quot;*.asmx&quot;</span>

<span style="color: #ff0000">preCondition</span><span style="color: #0000ff">=&quot;integratedMode&quot;</span>

<span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;System.Web.Script.Services.ScriptHandlerFactory,

System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

PublicKeyToken=31BF3856AD364E35&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ScriptHandlerFactoryAppServices&quot;</span> <span style="color: #ff0000">verb</span><span style="color: #0000ff">=&quot;*&quot;</span>

<span style="color: #ff0000">path</span><span style="color: #0000ff">=&quot;*_AppService.axd&quot;</span> <span style="color: #ff0000">preCondition</span><span style="color: #0000ff">=&quot;integratedMode&quot;</span>

<span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;System.Web.Script.Services.ScriptHandlerFactory,

System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

PublicKeyToken=31BF3856AD364E35&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;ScriptResource&quot;</span> <span style="color: #ff0000">preCondition</span><span style="color: #0000ff">=&quot;integratedMode&quot;</span>

<span style="color: #ff0000">verb</span><span style="color: #0000ff">=&quot;GET,HEAD&quot;</span> <span style="color: #ff0000">path</span><span style="color: #0000ff">=&quot;ScriptResource.axd&quot;</span>

<span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;System.Web.Handlers.ScriptResourceHandler,

System.Web.Extensions, Version=3.5.0.0, Culture=neutral,

PublicKeyToken=31BF3856AD364E35&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;MvcHttpHandler&quot;</span> <span style="color: #ff0000">preCondition</span><span style="color: #0000ff">=&quot;integratedMode&quot;</span>

<span style="color: #ff0000">verb</span><span style="color: #0000ff">=&quot;*&quot;</span> <span style="color: #ff0000">path</span><span style="color: #0000ff">=&quot;*.mvc&quot;</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;System.Web.Mvc.MvcHttpHandler,

System.Web.Mvc, Version=1.0.0.0, Culture=neutral,

PublicKeyToken=31BF3856AD364E35&quot;</span><span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;UrlRoutingHandler&quot;</span>

<span style="color: #ff0000">preCondition</span><span style="color: #0000ff">=&quot;integratedMode&quot;</span> <span style="color: #ff0000">verb</span><span style="color: #0000ff">=&quot;*&quot;</span> <span style="color: #ff0000">path</span><span style="color: #0000ff">=&quot;UrlRouting.axd&quot;</span>

<span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;System.Web.HttpForbiddenHandler,
System.Web,

Version=2.0.0.0, Culture=neutral,

PublicKeyToken=b03f5f7f11d50a3a&quot;</span> <span style="color: #0000ff">/&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">handlers</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">system.webServer</span><span style="color: #0000ff">&gt;</span>

<span style="color: #0000ff">&lt;/</span><span style="color: #800000">configuration</span><span style="color: #0000ff">&gt;</span></pre>
</div>
</li>
<li>
Add the following to Global.asax.cs (create a Global.asax if you don’t already have<br />
one)<br />
</p>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> RegisterRoutes(RouteCollection
routes)
{
routes.IgnoreRoute(<span style="color: #006080">&quot;{resource}.axd/{*pathInfo}&quot;</span>);
routes.IgnoreRoute(<span style="color: #006080">&quot;{resource}.aspx/{*pathInfo}&quot;</span>);

routes.MapRoute(
<span style="color: #006080">&quot;Default&quot;</span>, <span style="color: #008000">//
Route name</span>

<span style="color: #006080">&quot;{controller}/{action}/{id}&quot;</span>, <span style="color: #008000">//
URL with parameters</span>

<span style="color: #0000ff">new</span> { controller = <span style="color: #006080">&quot;Home&quot;</span>,
action = <span style="color: #006080">&quot;Index&quot;</span>, id = <span style="color: #006080">&quot;&quot;</span> } <span style="color: #008000">//
Parameter defaults</span>

);

}

<span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
</pre>
<p>
The above is the “standard” routing for a MVC site. It will work, but it might cause<br />
you trouble if you want the root of your website to still go to a ‘default.aspx’.<br />
Try this line instead:<br />

</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">routes.MapRoute(
<span style="color: #006080">&quot;Default&quot;</span>,

<span style="color: #006080">&quot;MVC/{controller}/{action}/{id}&quot;</span>,

<span style="color: #0000ff">new</span> { controller = <span style="color: #006080">&quot;Home&quot;</span>,
action = <span style="color: #006080">&quot;Index&quot;</span>, id = <span style="color: #006080">&quot;&quot;</span> } </pre>
</div>
</li>
<li>
Edit your .csproj file by hand </p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">&lt;</span><span style="color: #800000">ProjectTypeGuids</span><span style="color: #0000ff">&gt;</span>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">ProjectTypeGuids</span><span style="color: #0000ff">&gt;</span>

</pre>
<p>
</div>
<div>This will tell Visual Studio to act like this is an MVC project. You will get<br />
the context menu items for MVC in your Controllers and Views directories.<br />
<br />
<strong>Note:</strong> I’ve had trouble at this point with some Visual Studio installs.<br />
If you’re having trouble with “The project type is not supported by this installation.”<br />
messages here, it may be time for a clean install in a fresh VM.
</div>
</li>
<li>
<div>Set Up IIS. If you’re using IIS7, the System.Webserver settings in your Web.Config<br />
file should have taken care of this step. If you’re going to need to map the wildcard<br />
URL to aspnet_isapi.dll in order to get all of the MVC routing magic to work.<br />
<br />
<a href="http://erudition.radianttiger.com/content/binary/RecursiveErudition_F94C/AddingMVCtoanexistingASP.NETApplication_12C47/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://erudition.radianttiger.com/content/binary/RecursiveErudition_F94C/AddingMVCtoanexistingASP.NETApplication_12C47/image_thumb_4.png" width="504" height="294" /></a>
</div>
</li>
<li>
<div>You might want to copy of the /Views/web.config file from an existing MVC project<br />
to prevent your views from being viewed directly, rather than through their controllers.
</div>
</li>
<li>
<div>You might also wish to create a /Scripts folder and copy over the contents of<br />
the /Scripts folder from native MVC project. It has the jquery and MS AJAX javascripts<br />
that you may be looking for if you’re following a MVC book or tutorial.
</div>
</li>
</ol>
<p>
Boy howdy. That was a good chunk of work. But now you have the infinite pleasure of<br />
developing in MVC, and your old web site should continue to work under you. Delicious<br />
incremental development goodness.
</p>
<h3>Resources<br />
</h3>
<ul>
<li>
Phil Haack on <a href="http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx">Setting<br />
up MVC in IIS6</a>.
</li>
<li>
StackOverflow <a href="http://stackoverflow.com/questions/546377/hybrid-webforms-asp-net-mvc/994159#994159">Hybrid<br />
Web Forms / MVC</a>.
</li>
<li>
<a href="http://blogs.imeta.co.uk/MGodfrey/archive/2009/03/31/663.aspx">Integrating<br />
ASP.Net MVC Into an Existing ASP.Net Web Applcation</a>
</li>
<li>
<a href="http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc">Mixing<br />
ASP.NET Webforms and ASP.NET MVC</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=59</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Incorporating Growl For Windows into my Application</title>
		<link>http://erudition.radianttiger.com/?p=60</link>
		<comments>http://erudition.radianttiger.com/?p=60#comments</comments>
		<pubDate>Wed, 24 Jun 2009 01:00:36 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/PermaLink,guid,fb7a2e52-2d83-40be-9445-d4a506effbac.aspx</guid>
		<description><![CDATA[I’m a big believer in re-use. Code I don’t aihave to write is code I don’t have to debug or maintain. When I discovered that I’d really like some notification toast in my Windows Forms enterprise application, I immediately started looking for libraries. The definitive toast solution for Mac OS is Growl. Growl is a [...]]]></description>
			<content:encoded><![CDATA[<p>
I’m a big believer in re-use. Code I don’t aihave to write is code I don’t have to<br />
debug or maintain. When I discovered that I’d really like some <a href="http://en.wikipedia.org/wiki/Toast_(computing)">notification<br />
toast</a> in my Windows Forms enterprise application, I immediately started looking<br />
for libraries.
</p>
<p>
The definitive toast solution for Mac OS is <a href="http://growl.info/">Growl</a>.<br />
Growl is a separate application/control panel that runs on your system and manages<br />
notifications from all subscribing services on your system. No more overlapping toast.<br />
It also provides a lot of filtering, control, and plugin-based extensibility. Did<br />
you want your ‘new mail’ notifications to show up on your cell phone as SMS rather<br />
than on your desktop? Just do it. Want the toilet to flush when the build fails? Get<br />
an <a href="http://www.arduino.cc/">Arduino</a> and script it up!
</p>
<p>
Needless to say I was really chuffed to find the <a href="http://www.growlforwindows.com/">Growl<br />
for Windows</a> project. Their application is still in beta, but the developers are<br />
very responsive, and they are checking code fixes in within hours of getting bug reports<br />
when they can. GfW can provide you notifications for your GMail, Outlook, Visual Studio<br />
Builds, and the current song playing in Pandora.
</p>
<h2>Installing Growl With My Application<br />
</h2>
<p>
My application installs with <a href="http://nsis.sourceforge.net/">NSIS</a>. Adding<br />
automatic installation of the Growl client to my installer was very quick. I grabbed<br />
the .msi file from the Growl download, and put it within my build tree. Then I added<br />
the following snippet to my NSIS script:
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">Section <span style="color: #006080">&quot;Growl
Install&quot;</span> SEC01
File <span style="color: #006080">&quot;Growl\Windows Deployment.msi&quot;</span>

ExecWait <span style="color: #006080">'MSIEXEC.EXE /I &quot;$INSTDIR\Windows Deployment.msi&quot;
/QB- ALLUSERS=1'</span>

SectionEnd</pre>
<p>
</div>
</p>
<p>
That’s it for the install. However, I wanted it to uninstall cleanly as well, so I<br />
added the following line to the uninstall section:
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">ExecWait <span style="color: #006080">'MSIEXEC.EXE
/x &quot;$INSTDIR\Windows Deployment.msi&quot; /qn'</span>

</pre>
<p>
</div>
</p>
<p>
Two caveats:
</p>
<ol>
<li>
You may not want to uninstall Growl automatically for the user, in case they had installed<br />
it on their own and want to uninstall your app, but keep Growl. This isn’t an issue<br />
in my business deployment, but it may be one for a public application.
</li>
<li>
There may be some issues with UAC installs, and I haven’t tested this yet. I think<br />
I can just run my NSIS exe ‘As Administrator’ and have it work, but there may be issues<br />
with msiexec and UAC.
</li>
</ol>
<h2>
</h2>
<h2>Code to Send Notifications<br />
</h2>
<p>
First things first, lets establish some interfaces to program to, that way we can<br />
swap out implementations for testing and if our needs change.
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> INotificationMessage
{
<span style="color: #0000ff">string</span> MessageType { get; }
<span style="color: #0000ff">string</span> MessageDescription { get; }
<span style="color: #0000ff">string</span> MessageId { get; }
<span style="color: #0000ff">string</span> MessageText { get; set; }
Image MessageIcon { get; }
Action AcceptMessageCallback { get; set; }
Action DeclineMessageCallback { get; set; }
}
<span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> INotificationSender
{
<span style="color: #0000ff">void</span> SendMessage(INotificationMessage message);
}</pre>
<p>
</div>
<p>
Next, we’ll implement a specific Notification Message type. Each Notification Message<br />
type can be instantiated of a specific type so that it’s very easy to add new types<br />
as well as very easy to use them. Each type can have an icon of it’s own.
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ApplicationErrorNotificationMessage
: INotificationMessage
{
<span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> MessageType
{ get; <span style="color: #0000ff">private</span> set; }
<span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> MessageDescription
{ get; <span style="color: #0000ff">private</span> set; }
<span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> MessageId
{ get; <span style="color: #0000ff">private</span> set; }
<span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> MessageText
{ get; set; }
<span style="color: #0000ff">public</span> Image MessageIcon { get; <span style="color: #0000ff">private</span> set;
}
<span style="color: #0000ff">public</span> Action AcceptMessageCallback { get; set;
}
<span style="color: #0000ff">public</span> Action DeclineMessageCallback { get; set;
}

<span style="color: #0000ff">public</span> ApplicationErrorNotificationMessage()
{
<span style="color: #0000ff">this</span>.MessageType = <span style="color: #006080">&quot;APPLICATION_ERROR&quot;</span>;
<span style="color: #0000ff">this</span>.MessageDescription = <span style="color: #006080">&quot;Application
Error&quot;</span>;
<span style="color: #0000ff">this</span>.MessageId = Guid.NewGuid().ToString();
<span style="color: #0000ff">this</span>.MessageIcon = Application.Properties.Resources.AppIcon;
}
}</pre>
<p>
</div>
<p>
It appears that growl caches the message icons, so you might need to restart the Growl<br />
process if you go changing your Notification icons.
</p>
<p>
Finally we have our implementation of INotificationSender which registers with Growl,<br />
ensures that it is installed, and ensures that it is running.
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> GrowlNotificationSender
: INotificationSender
{
<span style="color: #0000ff">private</span> GrowlConnector connector;
<span style="color: #0000ff">private</span> Image applicationIcon;
<span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> applicationName;
<span style="color: #0000ff">private</span> INotificationMessage[] messageTypes;
<span style="color: #0000ff">private</span> Dictionary&lt;<span style="color: #0000ff">string</span>,
INotificationMessage&gt; sentMessages;

<span style="color: #0000ff">public</span> GrowlNotificationSender(INotificationMessage[]
messageTypes,
Image applicationIcon,
<span style="color: #0000ff">string</span> applicationName)
{
<span style="color: #0000ff">this</span>.connector = <span style="color: #0000ff">new</span> GrowlConnector();
<span style="color: #0000ff">this</span>.messageTypes = messageTypes;
<span style="color: #0000ff">this</span>.applicationIcon = applicationIcon;
<span style="color: #0000ff">this</span>.applicationName = applicationName;
<span style="color: #0000ff">this</span>.sentMessages = <span style="color: #0000ff">new</span> Dictionary&lt;<span style="color: #0000ff">string</span>,
INotificationMessage&gt;();

EnsureGrowlIsRunning();
RegisterWithGrowl();
}

<span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> RegisterWithGrowl()
{
Application thisApplication = <span style="color: #0000ff">new</span> Application(applicationName);
thisApplication.Icon = applicationIcon;
List&lt;NotificationType&gt; notificationTypes = <span style="color: #0000ff">new</span> List&lt;NotificationType&gt;();
<span style="color: #0000ff">foreach</span> (var messageType <span style="color: #0000ff">in</span> messageTypes)
{
NotificationType notificationType =
<span style="color: #0000ff">new</span> NotificationType(messageType.MessageType,
messageType.MessageDescription);
notificationType.Icon = messageType.MessageIcon;
notificationTypes.Add(notificationType);
}
<span style="color: #0000ff">this</span>.connector.Register(thisApplication, notificationTypes.ToArray());
<span style="color: #0000ff">this</span>.connector.NotificationCallback += <span style="color: #0000ff">new</span> GrowlConnector.CallbackEventHandler(connector_NotificationCallback);
<span style="color: #0000ff">this</span>.connector.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText;
}

<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> EnsureGrowlIsRunning()
{
Process[] processlist = Process.GetProcesses();
<span style="color: #0000ff">foreach</span> (Process theprocess <span style="color: #0000ff">in</span> processlist)
{
<span style="color: #0000ff">if</span> (theprocess.ProcessName.Equals(<span style="color: #006080">&quot;Growl&quot;</span>))
{ <span style="color: #0000ff">return</span>; }
}

Detector detector = <span style="color: #0000ff">new</span> Growl.CoreLibrary.Detector();
<span style="color: #0000ff">if</span> (detector.IsAvailable)
{
System.Diagnostics.Process.Start(detector.InstallationFolder + <span style="color: #006080">@&quot;\Growl.exe&quot;</span>);
Thread.Sleep(1000);
<span style="color: #0000ff">return</span>;
}
<span style="color: #0000ff">else</span>

{
<span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> FileNotFoundException(<span style="color: #006080">&quot;Growl
not installed?&quot;</span>);
}
}

<span style="color: #0000ff">void</span> connector_NotificationCallback(Response response,
CallbackData callbackData)
{
<span style="color: #0000ff">if</span> (sentMessages[callbackData.Data] != <span style="color: #0000ff">null</span>)
{
<span style="color: #0000ff">if</span> (callbackData.Result == CallbackResult.CLICK)
{
<span style="color: #0000ff">if</span> (sentMessages[callbackData.Data].AcceptMessageCallback
!= <span style="color: #0000ff">null</span>)
{
sentMessages[callbackData.Data].AcceptMessageCallback.Invoke();
}
}
<span style="color: #0000ff">else</span>

{
<span style="color: #0000ff">if</span> (sentMessages[callbackData.Data].DeclineMessageCallback
!= <span style="color: #0000ff">null</span>)
{
sentMessages[callbackData.Data].DeclineMessageCallback.Invoke();
}
}
sentMessages.Remove(callbackData.Data);
}
}

<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> SendMessage(INotificationMessage
message)
{
<span style="color: #0000ff">this</span>.sentMessages.Add(message.MessageId, message);

CallbackContext callbackContext = <span style="color: #0000ff">new</span> CallbackContext();
callbackContext.Data = message.MessageId;
callbackContext.Type = message.MessageType;

Notification notification = <span style="color: #0000ff">new</span> Notification(<span style="color: #0000ff">this</span>.applicationName,
message.MessageType,
message.MessageId,
message.MessageDescription,
message.MessageText);

EnsureGrowlIsRunning();
<span style="color: #0000ff">this</span>.connector.Notify(notification, callbackContext);
}
}</pre>
<p>
</div>
<p>
This implementation keeps track of sent messages, and executes callbacks on them depending<br />
on the user’s response. If you don’t want to use one of the callbacks, just leave<br />
it undefined.
</p>
<p>
I haven’t found a way to get Growl to send the CLOSE message rather than the TIMEOUT,<br />
but that’s ok, since I treat them the same.
</p>
<h2>
</h2>
<h2>Using The Code<br />
</h2>
<p>
You’d probably want to wire this up with your IOC container, but here’s a manual usage.
</p>
</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">INotificationSender sender = <span style="color: #0000ff">new</span> GrowlNotificationSender(
<span style="color: #0000ff">new</span>[] { <span style="color: #0000ff">new</span> ApplicationErrorNotificationMessage()
},
Moneta.Properties.Resources.Crystal_128_package_network,
<span style="color: #006080">&quot;My Application&quot;</span>

);
Thread.Sleep(1000);
ApplicationErrorNotificationMessage message = <span style="color: #0000ff">new</span> ApplicationErrorNotificationMessage
{
MessageText = <span style="color: #006080">&quot;Hi There&quot;</span>,
AcceptMessageCallback = () =&gt; MessageBox.Show(<span style="color: #006080">&quot;You
clicked&quot;</span>),
DeclineMessageCallback = () =&gt; MessageBox.Show(<span style="color: #006080">&quot;Pay
Attention!&quot;</span>)
};
sender.SendMessage(message);</pre>
<p>
</div>
</p>
<p>
It’s worth noting that the first registration of your app may take a moment for Growl<br />
to process, and that’s why I have the Sleep() in there. If your app doesn’t intend<br />
to immediately send a message after it’s first registration, that’s unnecessary.
</p>
<h2>Resources<br />
</h2>
<ul>
<li>
<a href="http://groups.google.com/group/growl-for-windows">Growl For Windows Google<br />
Group</a>
</li>
<li>
<a href="http://nsis.sourceforge.net/Embedding_other_installers">Embedding Installers<br />
in NSIS</a>
</li>
<li>
<a href="http://nsis.sourceforge.net/UAC_plug-in">UAC Plug-In for NSIS</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=60</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Forms Eventing: Thread Synchronization</title>
		<link>http://erudition.radianttiger.com/?p=61</link>
		<comments>http://erudition.radianttiger.com/?p=61#comments</comments>
		<pubDate>Tue, 23 Jun 2009 20:26:24 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/PermaLink,guid,57ed2864-72c0-43f2-88c0-a21dd353ad54.aspx</guid>
		<description><![CDATA[So last time, we created this great event aggregator for our Windows Forms applications. Instead of having the code that sends messages directly connected to the code that receives messages, everybody just knows about the event aggregator. This works the same way you don’t need turn-by-turn directions to Fox News Headquarters to mail them a [...]]]></description>
			<content:encoded><![CDATA[<p>
So last time, we created this great event aggregator for our Windows Forms applications.<br />
Instead of having the code that sends messages directly connected to the code that<br />
receives messages, everybody just knows about the event aggregator. This works the<br />
same way you don’t need turn-by-turn directions to Fox News Headquarters to mail them<br />
a box of dirty diapers.
</p>
<p>
The catch is that the code so far only works if all the senders and receivers are<br />
on the same thread. If they are on different threads, who knows what may happen? (Not<br />
me. I failed out of Home-Ec. I don’t even know how you turn cotton flowers into threads,<br />
let alone how to make them fit together.)
</p>
<p>
There is a simple fix, however. The .NET 2.0 SynchronizationContext is used by Windows<br />
Forms and can provide an easy-to-use central choke point to manage all of our thread-to-thread<br />
communications.
</p>
<h2>Remember Your Singleton<br />
</h2>
<p>
When I was cutting and pasting together this code from the Intarnets, one big problem<br />
I had was forgetting to initialize my singleton correctly. It’s <strong><em>really</em> </strong>important<br />
that you initialize your singleton EventAggregator from SynchronizationContext.Current<br />
in the <em>Windows Forms Thread</em>. Setting the thing up right in StructureMap or<br />
your IOC Container of choice works just great. Just make sure it gets done. (My mistake<br />
also involved letting StructureMap use “new SynchronizationContext()” in initializing<br />
my singleton rather than “SynchronizationContext.Current”.) Get it right the first<br />
time and you won’t have to do multithread debugging.
</p>
<h2>EventAggregator Class<br />
</h2>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> EventAggregator
: IEventAggregator
{
<span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> SynchronizationContext
_context;
<span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> List&lt;<span style="color: #0000ff">object</span>&gt;
_listeners = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">object</span>&gt;();
<span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">object</span> _locker
= <span style="color: #0000ff">new</span> <span style="color: #0000ff">object</span>();

<span style="color: #0000ff">public</span> EventAggregator(SynchronizationContext
context)
{
_context = context;
}

<span style="color: #cc6633">#region</span> IEventAggregator Members
<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> SendMessage&lt;T&gt;(T
message)
{
sendAction(() =&gt; all().CallOnEach&lt;IListener&lt;T&gt;&gt;(x =&gt; { x.Handle(message);
}));
}

<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> AddListener(<span style="color: #0000ff">object</span> listener)
{
withinLock(() =&gt;
{
<span style="color: #0000ff">if</span> (_listeners.Contains(listener)) <span style="color: #0000ff">return</span>;
_listeners.Add(listener);
});
}

<span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> RemoveListener(<span style="color: #0000ff">object</span> listener)
{
withinLock(() =&gt; _listeners.Remove(listener));
}
<span style="color: #cc6633">#endregion</span>

<span style="color: #0000ff">private</span> <span style="color: #0000ff">object</span>[]
all()
{
<span style="color: #0000ff">lock</span> (_locker)
{
<span style="color: #0000ff">return</span> _listeners.ToArray();
}
}

<span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> withinLock(Action
action)
{
<span style="color: #0000ff">lock</span> (_locker)
{
action();
}
}

<span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> sendAction(Action
action)
{
_context.Send(state =&gt; { action(); }, <span style="color: #0000ff">null</span>);
}
}</pre>
<p>
</div>
<p>
Notice the locking. Notice the creation of a copy of the _listeners list into an array<br />
for Thread Safety. Most importantly, notice the use of _context.Send(). A few minor<br />
changes…but now the whole class is thread safe, and synchronous between threads. Hooray!
</p>
<h2>Next Time<br />
</h2>
<p>
I’ve still got lots to cover on this subject. How do you use the eventing in your<br />
application architecture. Using Weak References to protect your event system from<br />
memory leaks. Sending events to a specific target or set of targets. I’m going to<br />
be working on some other projects for a bit, so it may be a while before I write those<br />
posts, but hopefully what we’ve covered so far is useful on its own until then.
</p>
<h2>Resources<br />
</h2>
<ul>
<li>
<a href="http://msdn2.microsoft.com/en-us/library/system.threading.synchronizationcontext.aspx">MSDN<br />
SynchronizationContext</a>
</li>
<li>
<a href="http://blogs.msdn.com/jaredpar/archive/2008/02/24/synchronizationcontext-and-higher-order-functions.aspx">SynchronizationContext<br />
and Higher Order Functions</a>
</li>
<li>
<a href="http://wildermuth.com/2009/04/12/For_Now_Don_t_Use_SynchronizationContext_in_Silverlight_2_or_3">Willdermuth:<br />
Don&#8217;t Use SynchronizationContext</a>
</li>
<li>
<a href="http://stackoverflow.com/search?q=synchronizationcontext">StackOverflow:<br />
SynchronizationContext</a>
</li>
<li>
<a href="http://thevalerios.net/matt/2008/07/controlinvokerequired-delegatemarshaler-and-anonymous-methods/">Control.InvokeRequired,<br />
DelegateMarshaller and Anonymous Methods</a>
</li>
<li>
<a title="http://msdn.microsoft.com/en-us/library/system.weakreference.aspx" href="http://msdn.microsoft.com/en-us/library/system.weakreference.aspx">MSDN:<br />
Weak References</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=61</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Principles</title>
		<link>http://erudition.radianttiger.com/?p=62</link>
		<comments>http://erudition.radianttiger.com/?p=62#comments</comments>
		<pubDate>Tue, 23 Jun 2009 20:18:04 +0000</pubDate>
		<dc:creator>Josh Rivers</dc:creator>
				<category><![CDATA[NothingToSeeHere]]></category>

		<guid isPermaLink="false">http://erudition.radianttiger.com/PermaLink,guid,e1a89568-c4e6-46ce-b551-f2bde3457474.aspx</guid>
		<description><![CDATA[Digging out the Draft Bucket: This isn’t really a completed post, but rather than leave it in my Draft folder forever, I’m just going to post it. That way it’s infamy will live forever. There&#8217;s a massive summary of design principles in the ASP.NET MVC Forums project introduction. The actual code in the project is [...]]]></description>
			<content:encoded><![CDATA[<p>
<em>Digging out the Draft Bucket: This isn’t really a completed post, but rather than<br />
leave it in my Draft folder forever, I’m just going to post it. That way it’s infamy<br />
will live forever.</em>
</p>
<p>
There&#8217;s a massive summary of design principles in the <a href="http://weblogs.asp.net/stephenwalther/archive/2008/09/05/asp-net-mvc-application-building-forums-1-create-the-perfect-application.aspx">ASP.NET<br />
MVC Forums project introduction</a>. The actual code in the project is opaque to me.<br />
I&#8217;d need to learn the framework before I&#8217;d understand how he&#8217;s working on it.
</p>
<p>
<a href="http://forums.lhotka.net/forums/post/17914.aspx">Rocky on TDD</a>, with an<br />
explanation on how comprehensive testing means writing more test code than real code.<br />
&quot;No one actually does this.&quot; &quot;I once watched a TDD (and MVC/MVP) presentation.<br />
The speaker wrote several pages of code to build and test a presenter that did a bunch<br />
of work. Nice stuff, until you realized that all that could have been done in 1-3<br />
lines of code using data binding. I asked him why he did this rather than using data<br />
binding. The answer: you can&#8217;t test data binding. I&#8217;m afraid my jaw dropped. See,<br />
I have a wife and kids. I like to get home and spend time with them. If I can write<br />
3 lines of code, or write 3 pages of code that I need to test and debug, I&#8217;m going<br />
to pick the 3 lines of code every time&quot;
</p>
<p>
<a href="http://forums.lhotka.net/forums/post/17079.aspx">Authorization system in<br />
CSLA</a>.
</p>
<p>
<a href="http://www.polymorphicpodcast.com/shows/mv-patterns/">Polymorphic MV*</a>.
</p>
<p>
For when I need some new article materials: <a href="http://www.hanselman.com/blog/BackToBasicsAlgorithmsAndGoingBackToVirtualSchool.aspx">A<br />
Big Hanselman Article on Code Learning Online</a>.
</p>
<p>
<a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/09/21/let-s-go-back-to-the-basics-of-cohesion-and-coupling.aspx">Cohesion<br />
and Coupling</a>
</p>
<p>
Articles on SOLID:
</p>
<ol>
<li>
<a href="http://codebetter.com/blogs/david_laribee/archive/2008/09/09/why-solid-gimme-an-s.aspx">Single<br />
Responsibility Principle</a>
</li>
<li>
<a href="http://codebetter.com/blogs/david_laribee/archive/2008/09/11/why-solid-gimme-an-quot-o-quot.aspx">Open/Closed<br />
Principle</a>
</li>
<li>
<a href="http://codebetter.com/blogs/david_laribee/archive/2008/09/22/why-solid-gimme-an-l.aspx">Liskov<br />
Substitution Principle</a>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://erudition.radianttiger.com/?feed=rss2&amp;p=62</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
