<?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>Barry Jones &#187; Quick Route Debugging in MVC.NET &#8211; Barry Jones</title>
	<atom:link href="http://www.barryjones.me.uk/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barryjones.me.uk</link>
	<description>General Ramblings</description>
	<lastBuildDate>Mon, 06 Sep 2010 10:05:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Quick Route Debugging in MVC.NET</title>
		<link>http://www.barryjones.me.uk/2009/10/quick-route-debugging-in-mvc-net/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quick-route-debugging-in-mvc-net</link>
		<comments>http://www.barryjones.me.uk/2009/10/quick-route-debugging-in-mvc-net/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 10:26:43 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.barryjones.me.uk/?p=141</guid>
		<description><![CDATA[Here is a quick way of getting detailed information about which route has been accepted and why in MVC.NET. The code below should be placed in your Application_EndRequest event handler in global.asax. By placing a break point in the code directly after evaluation you can see a collection of all the routes, if it matched [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick way of getting detailed information about which route has been accepted and why in MVC.NET.</p>
<p>The code below should be placed in your Application_EndRequest event handler in global.asax. By placing a break point in the code directly after evaluation you can see a collection of all the routes, if it matched the request and a reference to the RouteData to see more detailed information.</p>
<p>This code works by re-evaluating each of the Routes defined in your application against the current request. The first match in the collection is the match that MVC will have used to handle your request.<span id="more-141"></span></p>
<pre class="code">List&lt;object&gt; routes = new List&lt;object&gt;();
foreach (System.Web.Routing.Route current in System.Web.Routing.RouteTable.Routes) {
	System.Web.Routing.RouteData data = current.GetRouteData(
		new HttpContextWrapper(HttpContext.Current)
		);
	bool matches = data != null;
	routes.Add(new { Match=matches, Url=current.Url.ToString(), Data=data});
}</pre>
<p>For a better long term implementation try using <a title="Phil Haack's ASP.NET Routing Debugger" href="http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx" target="_blank">Phil Haack&#8217;s</a> debugging implementation or get the route debugging code from the <a title="ASP.NET MVC Unleased" href="http://www.informit.com/store/product.aspx?isbn=9780672329982" target="_blank">ASP.NET MVC Unleashed</a> book.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2009/10/quick-route-debugging-in-mvc-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Current Work: Live Documenter</title>
		<link>http://www.barryjones.me.uk/2009/10/current-work-live-documenter/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=current-work-live-documenter</link>
		<comments>http://www.barryjones.me.uk/2009/10/current-work-live-documenter/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 21:43:47 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[My Projects]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[XML Comments]]></category>

		<guid isPermaLink="false">http://www.barryjones.me.uk/?p=48</guid>
		<description><![CDATA[I had nothing else to talk about so I thought I would give a little ramble on my current project. It has been &#8216;code named&#8217; Live Documenter, which will probably end up being its final name as well &#8211; if only I was more creative. OK, onward! Basically since NDoc curled up and died a [...]]]></description>
			<content:encoded><![CDATA[<p>I had nothing else to talk about so I thought I would give a little ramble on my current project. It has been &#8216;code named&#8217; Live Documenter, which will probably end up being its final name as well &#8211; if only I was more creative. OK, onward!</p>
<p>Basically since <a title="NDoc stagnating since 2005" href="http://ndoc.sourceforge.net/" target="_blank">NDoc</a> curled up and died a long time ago I have really wanted a nice xml comment documenter to read all those lovely comments I have been painstakingly hand crafting since , well, as long as I can remember. This has been curled up at the back of mind for ages. And a little while ago I decided I would start faffing around with the .NET meta-data and just try to learn a little more about how the <acronym title="Common Language Runtime">CLR</acronym> holds it&#8217;s data in <acronym title="Portable Executable">PE</acronym> files, what kind of data and well.. OK I can&#8217;t justify it really. Anyway; two thoughts collided and the rest is unwritten history.<span id="more-48"></span></p>
<h2>What it Does</h2>
<p>This documentor takes a solution, project or library and churns through all the internal gubbins of the built libraries for the <acronym title="Visual Studio">VS</acronym> files or itself for the DLL. It then locates the lovely XML comment files, mingles them together and spits out some nice legible information. I haven&#8217;t painted that in the most beautiful light but I am British so it remains understated.</p>
<ul>
<li>Reads VS Solution, Project and Library files</li>
<li>Parses XML comments (supports the basic <a href="http://msdn.microsoft.com/en-us/library/5ast78ax(VS.80).aspx" target="_blank">Microsoft set</a>) to produce documentation</li>
<li>Updates live the changes you make to the your source code</li>
<li>Allows searching of types, properties and methods</li>
<li>Supports code comments for generic types and methods</li>
<li>Provides syntax in C# or Visual Basic</li>
</ul>
<p>It was a real struggle getting information about the internal workings of PE files, the Internet is a little sparse in this regard, so I had to get the aid of two books <a title=".NET IL Assembler" href="http://www.amazon.co.uk/Inside-NET-IL-Assembler-Lidin/dp/0735615470/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1255037193&amp;sr=8-2" target="_blank">.NET IL Assembler</a> and <a title="Reversing - The secrets of reverse engineering" href="http://www.amazon.co.uk/Reversing-Secrets-Engineering-Eldad-Eilam/dp/0764574817/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1255037247&amp;sr=1-1" target="_blank">Reversing</a> to help me on the way. Whilst I was reinventing the wheel Microsoft released an open source reflection library (which I can no longer find a link to) which seems to do everything, ah well. However, I think I will in future posts, describe in a little more detail what I did and learnt while making this app.</p>
<h2>Appearances can be Deceiving</h2>
<p>This doesn&#8217;t look the best at the moment, but it&#8217;s still in development so bear with me! I really need to polish the front end up and apply some UX magic; so with that in mind lets have a look at some screenies.</p>
<div id="attachment_105" class="wp-caption alignleft" style="width: 160px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/type-view.png" rel="lightbox[48]"><img class="size-thumbnail wp-image-105" title="Live Documentor - Type Page" src="http://www.barryjones.me.uk/wp-content/uploads/2009/10/type-view-150x102.png" alt="Live Documentor - Type Page" width="150" height="102" /></a><p class="wp-caption-text">View of a Class</p></div>
<div id="attachment_111" class="wp-caption alignright" style="width: 160px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/namespace-view.png" rel="lightbox[48]"><img class="size-thumbnail wp-image-111" title="namespace view" src="http://www.barryjones.me.uk/wp-content/uploads/2009/10/namespace-view-150x102.png" alt="namespace view" width="150" height="102" /></a><p class="wp-caption-text">View of a Namespace</p></div>
<p>The class view has all of the information you would expect. Full namespace declaration, deceleration syntax, all your lovely comments, inheritance tree and by the powers of WPF lots of control over how you view the page. All of the param references, type references, exception information (for methods) is linked up from the comments. The UI currently allows you to view easily which libraries have comments and which don&#8217;t.</p>
<p>As you can see by the method view below, it supports generic types and methods. Type, method, property etc signatures are generated and can be changed to multiple languages; although I have only written code to support VB and C# at the moment.</p>
<div id="attachment_113" class="wp-caption alignleft" style="width: 160px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/method-view-generic.gif" rel="lightbox[48]"><img class="size-thumbnail wp-image-113" title="Live Documentor - View of Generic Method" src="http://www.barryjones.me.uk/wp-content/uploads/2009/10/method-view-generic-150x107.gif" alt="View of a Method" width="150" height="107" /></a><p class="wp-caption-text">View of a Method</p></div>
<p>I all in all am pretty excited about where this is going at the moment and for the ideas I have about where it will be going on a more long term basis. One little thing I &#8211; in the long term &#8211; am hoping to get in there is dynamically creating <a title="Unified Modelling Language" href="http://en.wikipedia.org/wiki/Unified_Modeling_Language" target="_blank">UML</a> diagrams. The idea of being able to see a methods full sequence diagram, cant be anything but a help for people working on new projects or revisiting old ones!</p>
<p>Finally, the main idea behind this application is that it is used more like a live reference, an open book; which you would have open at the same time as a project. Because of this the application will continually update itself based on changes you make to your solutions, projects, code and comments. I thought that was a little different from your normal wait for application to generate static pages, currently event with a large 20 project solution this still opens quickly and is extremely usable. I hope that has made you interested and I will speak up again when I have something that I can throw out there.</p>
<p>This application will be made available from my company, <a href="http://www.theboxsoftware.com">The Box Software</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2009/10/current-work-live-documenter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Populate DTOs</title>
		<link>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatically-populate-dtos</link>
		<comments>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 20:07:09 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[DTO]]></category>
		<category><![CDATA[Pattern]]></category>

		<guid isPermaLink="false">http://carl.barryjones.me.uk/?p=15</guid>
		<description><![CDATA[The lowly DTO, a pattern described by Martin Fowler that enables you to reduce the number of API calls you make across a remote boundary; it allows this by grouping all the data in to a new data type and returning that instead. I have however found that this pattern can cause you to write [...]]]></description>
			<content:encoded><![CDATA[<p>The lowly <a title="DTO Pattern" href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"><acronym title="Data Transfer Object">DTO</acronym></a>, a pattern described by <a title="Martin Fowler" href="http://martinfowler.com/" target="_blank">Martin Fowler</a> that enables you to reduce the number of API calls you make across a remote boundary; it allows this by grouping all the data in to a new data type and returning that instead. I have however found that this pattern can cause you to write a lot of code that is nothing more than property setting. The code provided in this post (<a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">here</a>) allows you to automate the population of these <acronym title="Data Transfer Object">DTO</acronym>s saving you time, so you can get on with something more important like drinking coffee.<span id="more-15"></span></p>
<h2>Automating DTO Population</h2>
<p>First of all grab yourself a copy of the <a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">source</a> code. A general overview of the process is; you specify — using attributes — the mappings between your business objects and your data transfer objects. These attributes can describe simple properties, complex properties and collections. After that is done, throw the object at the converter and Bob&#8217;s your uncle!</p>
<h3>Mapping DTO Properties with Attributes</h3>
<p>There are two attributes DTOSimpleMapper and DTOCollectionMapper; the basic signature of the attributes is shown below.</p>
<pre class="code">[DTOSimpleMapper(params string[] fields)]
[DTOCollectionMapper(Type ofType, string fromField)]</pre>
<pre class="code">[DTOSimpleMapper("FromProperty.Child.Identifier")]
public int ConvertedProperty;</pre>
<p>The ‘fields’ and ‘fromField’ parameters describe the property on the origin object that is to be converted. The destination for the conversion is always the property the attribute is decorating. The fields are represented as a string where the field is a child property the ‘.’ notation can be used to indicate this. I.e. &#8220;Parent.Child.Child&#8221;.<br />
The params string[] parameters on both attributes can be used to describe more complex conversions, when the converting types have multiple properties the conversion can be described by passing in an array of strings which define the from and to properties. I.e:</p>
<pre class="code">[DTOSimpleMapper("Prop1.Prop2=Identifier", "Prop2.Prop1=Name")]</pre>
<p>The first parameter on the DTOCollectionMapper tells the converter what the destination array elements are:</p>
<pre class="code">[DTOCollectionMapper(typeof(string), "FromProperty"]
public string[] ConvertedCollection;</pre>
<p>The converter will work with any collection that implements IEnumerable. As with the simple mapper, the property name can describe more complex conversions. This is useful where you have a generic <acronym title="Data Transfer Object">DTO</acronym> that is used to describe many elements:</p>
<pre class="code">[DTOCollectionMapper(typeof(IdentifiedElement), "FromPoperty", "Identifier=Identifier",
"Child.Name=Name")]
public List Children;</pre>
<p>Finally where the conversions are more complex the type for the property can describe its own conversion:</p>
<pre class="code">Public class RelatedChildDTO {
     [DTOSimpleMapper("Identifier")] public int Identifier;
     [DTOSimpleMapper("Name")] public string Name;
}
Public class ParentDTO {
     [DTOSimpleMapper("Child")]
     public RelatedChildDTO Child;
}</pre>
<p>With the above example the converter will check the type of instance it is creating and use the attributes described on that type to perform the conversion.</p>
<h2>Conditional Population</h2>
<p>Both of the attributes allow for Type conditional conversions as well, both are overloaded with a type property that is checked in the conversion process and only performed when the origin type is the same:</p>
<pre class="code">[DTOSimpleMapper(typeof(ConditionalBusinessObject), "FromProperty")]
public string ConvertedProperty;</pre>
<h2>Automatic Conversion</h2>
<p>Now you have described the way objects are converted we are left with actual conversion, the library has a Converter class with a simple static method called Convert. This method takes an instance of an origin object and a type for the destination object.</p>
<pre class="code">BusinessObject bus = new BusinessObject();
// set business properties
DTO dto = (DTO)Convertor.Convert(bus, typeof(DTO));</pre>
<p>The result of this method call is that the <acronym title="Data Transfer Object">DTO</acronym> is created and populated using the attributes, the conversion is done!<br />
Here is the <a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">source code</a>, it contains test classes which should give you a better idea of how it all works, enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

