<?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:media="http://search.yahoo.com/mrss"
	>

<channel>
	<title>Karl On WPF - .Net</title>
	<atom:link href="http://karlshifflett.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://karlshifflett.wordpress.com</link>
	<description>The Home of Mole and Karl's BLOG on WPF &#38; VB.NET.  (Karl speaks VB, learning C#)</description>
	<pubDate>Fri, 09 May 2008 20:35:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>Metadata - a Voice Crying in the Wilderness, Hey! I&#8217;m Over Here</title>
		<link>http://karlshifflett.wordpress.com/2008/05/08/metadata-a-voice-crying-in-the-wilderness-hey-im-over-here/</link>
		<comments>http://karlshifflett.wordpress.com/2008/05/08/metadata-a-voice-crying-in-the-wilderness-hey-im-over-here/#comments</comments>
		<pubDate>Thu, 08 May 2008 21:54:48 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Code Generation]]></category>

		<category><![CDATA[Visual Studio 2008]]></category>

		<category><![CDATA[WPF General]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/05/08/metadata-a-voice-crying-in-the-wilderness-hey-im-over-here/</guid>
		<description><![CDATA[Welcome to Metadata Island.&#160; It&#8217;s a beautiful place.&#160; Rich in resources that represent the hard work of application designers, business analysts and their customers.&#160; Those very long specification meetings.&#160; Countless missed meals typing up specifications.&#160; Yes we have all contributed to the paradise repository called, Metadata Island.&#160; Not to mention this vast metadata resource that [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Welcome to Metadata Island.&nbsp; It&#8217;s a beautiful place.&nbsp; Rich in resources that represent the hard work of application designers, business analysts and their customers.&nbsp; Those very long specification meetings.&nbsp; Countless missed meals typing up specifications.&nbsp; Yes we have all contributed to the paradise repository called, Metadata Island.&nbsp; Not to mention this vast metadata resource that sits dormant which companies paid tens of thousands of dollars to create.&nbsp; If you were to get in your boat, the lone guy managing the metadata can be heard on the beaches waving his arms and crying out, &#8220;Hey!! I&#8217;m over here!&#8221;</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/05/metadataisland.jpg"><img style="border-width:0;" height="319" alt="104004A.TIF" src="http://karlshifflett.files.wordpress.com/2008/05/metadataisland-thumb.jpg?w=404&h=319" width="404" border="0"></a></p>
<h3>The Problem</h3>
<p>Bottom line; the once thought out and complete metadata never gets off the island after it arrives.&nbsp; Current development tools are not set up to take advantage of developer metadata during the form or code generation processes.&nbsp; Anyone ever used Microsoft Access?&nbsp; Since Access 1.0, the program utilizes the developers metadata stored in the table object.&nbsp; The form and report designers expose this metadata in a ComboBox allow the developer to drag a field to the design surface and Access will create the control and corresponding label.&nbsp; It also has Mr. Wizard that creates forms and reports for you.</p>
<p>Why should our developers have to retype ToolTip text into form property grids?&nbsp; Why should developers spend time entering data into property grids at all, especially the same data that is sitting on Metadata Island?&nbsp; Beside being error prone, software companies are having to pay another person to enter this same data into yet another interface.</p>
<h3>Why Did I Write This?</h3>
<p>Before I get much further I must explain the context of this blog post.&nbsp; First and foremost, I&#8217;m not a Microsoft finger pointer, not by a long shot.&nbsp; We have fantastic tools and outstanding developers that I have deep respect for standing behind them.</p>
<p>I have been to two recent Microsoft events, MIX08 and the 2008 Microsoft MVP Summit.&nbsp; I didn&#8217;t hear anything in any keynote, presentation or off-line conversation about any plans for Visual Studio or Visual Studio related tools to consume developer metadata.&nbsp; I feel so strongly about this, so I wrote this blog post to raise the awareness of this need and to demonstrate how simple this is to accomplish.</p>
<p>I like Visual Studio 2008 and Expression Blend 2 and 2.5.&nbsp; I like that I can open a designer and the tool creates classes for me.&nbsp; Someone worked real hard to deliver that tool.&nbsp; Where I get disappointed is when I have a great tool that I can&#8217;t use because it can&#8217;t consume my metadata.</p>
<p>For example the LINQ to SQL and SQLMetal tools don&#8217;t currently add XML comments to my classes or add my attributes to my properties.&nbsp; But this would be easy to accomplish.</p>
<p>Currently there is no way to use the tools and have them populate a control&#8217;s properties based on my metadata as the control is being dragged to the design surface.&nbsp; But this would be easy to accomplish.</p>
<h3>Video Demonstrations</h3>
<p>Please watch the two below videos.&nbsp; The first one demonstrates a program I wrote that uses metadata to generate WPF forms in milliseconds.&nbsp; It can also generate individual controls&nbsp; The second is a short video on the program and how simple it was to write.</p>
<p>When I made the videos, this was using the Alpha One version.&nbsp; Since then I have updated it after getting suggestions.&nbsp; The version in the video works great but has been updated and now looks like the version at the bottom of this post.</p>
<p><img alt="Silverlight Icon" src="http://karlshifflett.files.wordpress.com/2008/01/silverlight_logo_small1.gif"></p>
<p>The video links require Microsoft Silverlight 1.0. If you do not have it, you will be prompted to install it when you click one of the links. After the short installation is completed, close the browser window that you did the install in and re-click the video you want to watch. You can also download it <a href="http://www.microsoft.com/silverlight/" target="_blank">here</a>. Windows XP or Vista required.</p>
<p><img height="19" alt="" src="http://karlshifflett.files.wordpress.com/2008/01/movie1.gif" width="19"> <a href="http://silverlight.services.live.com/invoke/48184/MetadataFormGeneration/iframe.html" target="_blank">Metadata Form Generation Video</a></p>
<p><img height="19" alt="" src="http://karlshifflett.files.wordpress.com/2008/01/movie1.gif" width="19"> <a href="http://silverlight.services.live.com/invoke/48184/MetadataFormGenerationHowIDidIt/iframe.html" target="_blank">Metadata Form Generation How I Did It Video</a></p>
<h3>The Solution</h3>
<p>We need bridges from our tools to Metadata Island.&nbsp; Bridges is such a friendly and happy word.&nbsp; The phrase, &#8220;bridge building or building bridges&#8221; is normally used in the context of good, of creating relationships or joining separate objects.</p>
<p>After watching the first video, no one can now say, WPF is not RAD capable.&nbsp; In fact this simple tool is way faster than the great Winforms designer.&nbsp; I spent a days time thinking the tool out, writing and testing it.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/05/metadataislandbridges.jpg"><img style="border-width:0;" height="454" alt="metadataislandbridges" src="http://karlshifflett.files.wordpress.com/2008/05/metadataislandbridges-thumb.jpg" width="604" border="0"></a></p>
<p>I have been thinking about metadata and code generation since I wrote the <a href="http://karlshifflett.wordpress.com/2008/03/02/visual-studio-2008-designers-and-code-generators-you-have-overlooked/" target="_blank">Visual Studio 2008 Designers and Code Generators; You Have Overlooked (…)</a> blog entry.</p>
<p>I have come up with two bridge building methods I think would work.&nbsp; Of course there are much smarter architects and developers working on tools than me, so maybe they would have a better solution that what I&#8217;m proposing here.&nbsp; I&#8217;m just praying the ball gets rolling in time for the next release of Visual Studio or possibly a service pack to Visual Studio 2008.</p>
<h3>Solution A:&nbsp; Bridge Provider Model</h3>
<p>This would be the simplest solution to implement and one that completely decouples the tools from the developers.</p>
<p>In each Visual Studio Solution the developer would place a .dll in the MetadataProvider directory of the solution that was decorated with the required attributes.</p>
<p>When Visual Studio opens the solution, it looks for it, similar to the way it currently does for Visualizer .dlls.</p>
<p>Here is the workflow.&nbsp; When LINQ to SQL or SQLMetal needs to write a class or property object they pass the class name and property name and the MetadataProvider either returns a string or nothing.&nbsp; If nothing, then the tool simply uses its default implementation like it does today.&nbsp; If a string is returned, then that string is used for that object.&nbsp; This would allow developers to create the property with XML comments, attributes and property getter and setter code that they want to use.&nbsp; This way the code the the LINQ to SQL designer generates now looks exactly like code I would have hand coded.&nbsp; Now everyone is happy, very happy.&nbsp; How easy would this be to code into the current tools?</p>
<p>If the developer wanted to generate a form, they would select a business object class that would be used to populate a Data Grid like my program and then generate the code.&nbsp; So in this case, Visual Studio would be interacting with the .dll in the MetadataProvider directory twice.&nbsp; Once to fill up the grid and once when each object is created.&nbsp; Again, very simple workflow and almost zero impact on the current tools.</p>
<h5>Advantages</h5>
<p>The major advantage to this solution is that it completely decouples the tools from the solution.&nbsp; The tools do not have to be concerned about metadata management.&nbsp; Just call the provider and use what it returns.</p>
<h3>Solution B:&nbsp; Metadata Model</h3>
<p>This solution would require that a metadata model be established and then developers could populate.&nbsp; This model would be consumed by the tools during object construction.</p>
<p>This model would require that the solution expose templates that could be modified so that the constructed classes, properties and controls be generated exactly if a developer had hand coded them.</p>
<h3>Program</h3>
<p>I have receieved a few emails about the program so I&#8217;ll give the overview.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/05/metadataislandnewcompressed.jpg"><img style="border-width:0;" height="574" alt="metadataislandnewcompressed" src="http://karlshifflett.files.wordpress.com/2008/05/metadataislandnewcompressed-thumb.jpg" width="704" border="0"></a> </p>
<p>I used the <a href="http://www.infragistics.com/dotnet/netadvantage/wpf/xamdatagrid.aspx#Overview" target="_blank">Infragistics xamDataGrid</a> in the above application for very easy editing of the individual metadata objects.&nbsp; </p>
<p>Most of the columns are editable.&nbsp; The control type column is a ComboBox and the two button columns allow the creation of the control by clicking the button to copy the control to the clipboard as in the demo video or allow the control to be created by dragging the button to a Visual Studio or Blend XAML editor and the control is created there.</p>
<p>You can see I&#8217;ve also have put my Code Generator here also.&nbsp; I&#8217;ll post some more videos soon on this entire application and demonstrate how RAD WPF development can be.</p>
<h3>Close</h3>
<p>My program is not a templated solution.&nbsp; It&#8217;s coded to generate code they way I would write it.&nbsp; This makes my program very useful to me and anyone that subscribes to my methods and Core library that I have written.&nbsp; We also have a super clean metadata store for our applicaiton generation.</p>
<p>Until the tools catch up, I hope this encourages you to start mining your own rich metadata stores and bringing that well thought out data into your development cycles.</p>
<p>Have a great day and thank you!</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/474/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/474/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/474/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/474/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/474/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/474/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/474/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/474/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/474/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/474/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/474/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/474/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=474&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/05/08/metadata-a-voice-crying-in-the-wilderness-hey-im-over-here/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/05/metadataisland-thumb.jpg" medium="image">
			<media:title type="html">104004A.TIF</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/01/silverlight_logo_small1.gif" medium="image">
			<media:title type="html">Silverlight Icon</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/01/movie1.gif" medium="image" />

		<media:content url="http://karlshifflett.files.wordpress.com/2008/01/movie1.gif" medium="image" />

		<media:content url="http://karlshifflett.files.wordpress.com/2008/05/metadataislandbridges-thumb.jpg" medium="image">
			<media:title type="html">metadataislandbridges</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/05/metadataislandnewcompressed-thumb.jpg" medium="image">
			<media:title type="html">metadataislandnewcompressed</media:title>
		</media:content>
	</item>
		<item>
		<title>Needed Features In Visual Studio 2008 Server Explorer</title>
		<link>http://karlshifflett.wordpress.com/2008/05/02/needed-features-in-visual-studio-2008-server-explorer/</link>
		<comments>http://karlshifflett.wordpress.com/2008/05/02/needed-features-in-visual-studio-2008-server-explorer/#comments</comments>
		<pubDate>Fri, 02 May 2008 20:54:43 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/05/02/needed-features-in-visual-studio-2008-server-explorer/</guid>
		<description><![CDATA[I&#8217;ve been trying to utilize the Server Explorer in Visual Studio 2008 for my SQL Server programming tasks like table maintenance and stored procedure authoring.  However this new workflow is not as productive as using SQL Server Management Studio.
Viewing Columns
A quick glance at the below images shows that Visual Studio 2008 does not display the [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been trying to utilize the Server Explorer in Visual Studio 2008 for my SQL Server programming tasks like table maintenance and stored procedure authoring.  However this new workflow is not as productive as using SQL Server Management Studio.</p>
<h3>Viewing Columns</h3>
<p>A quick glance at the below images shows that Visual Studio 2008 does not display the same MUCH needed column information.  Yes, when you click on a column, the Visual Studio 2008 Properties Window displays this and more data.  However, when you click back to the code window or anywhere else, the Properties Window data changes.  Also, having to click on a column to see its information slows the developers workflow down.  Please display at least the same information that SSMS does for a column.</p>
<table border="0" cellspacing="5" cellpadding="2" width="600">
<tbody>
<tr>
<td width="300" valign="top"><strong>SQL Server Management Studio</strong></td>
<td width="300" valign="top"><strong>Visual Studio 2008</strong></td>
</tr>
<tr>
<td width="300" valign="top"><a href="http://karlshifflett.files.wordpress.com/2008/05/visualstudioone1.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/05/visualstudioone-thumb.jpg?w=296&h=279" border="0" alt="visualstudioone" width="296" height="279" /></a></td>
<td width="300" valign="top"><a href="http://karlshifflett.files.wordpress.com/2008/05/visualstudiothree1.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/05/visualstudiothree-thumb.jpg?w=200&h=275" border="0" alt="visualstudiothree" width="200" height="275" /></a></td>
</tr>
</tbody>
</table>
<h3>Copying Column Name(s)</h3>
<p>Another very missed piece of functionality is the ability to copy one or more column names from the above displayed list into either a stored procedure or code window.</p>
<p>In SSMS the developer can drag the Columns folder into a code window and all column names are copied into the code window separated by commas.  Visual Studio 2008 does not have this.</p>
<p>In SSMS the developer can drag the column name into a code window and the column name is copied into the code window.  Visual Studio 2008 does not have this.</p>
<p>This is an invaluable time saver and ensures accurate copying of column names into code or stored procedures.</p>
<h3>Viewing Stored Procedure Declarations</h3>
<p>A look at the two below images shows that Visual Studio 2008 does not display the same MUCH needed parameter information.  This functions that same way and has the same limitations at the above table columns.</p>
<table border="0" cellspacing="5" cellpadding="2" width="600">
<tbody>
<tr>
<td valign="top"><strong>SQL Server Management Studio</strong></td>
<td valign="top"><strong>Visual Studio 2008</strong></td>
</tr>
<tr>
<td valign="top"><a href="http://karlshifflett.files.wordpress.com/2008/05/visualstudiotwo1.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/05/visualstudiotwo-thumb.jpg?w=346&h=116" border="0" alt="visualstudiotwo" width="346" height="116" /></a></td>
<td valign="top"><a href="http://karlshifflett.files.wordpress.com/2008/05/visualstudiofour1.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/05/visualstudiofour-thumb.jpg?w=210&h=102" border="0" alt="visualstudiofour" width="210" height="102" /></a></td>
</tr>
</tbody>
</table>
<h3>Help Get This Fixed</h3>
<p>I have posted this problem on Microsoft Connect here: <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=341791" target="_blank">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=341791</a>. </p>
<p>Please rate this issue on Microsoft Connect so that it will get corrected. </p>
<p>VS2005 had the same issue and I wish I would have known how to report problems like this long ago.</p>
<h3>Close</h3>
<p>I was going to write this up on the Visual Studio 2008 forums, but you can&#8217;t post images (which is a very good feature) so I wrote it up here where I could post the images and wrote a text only version that you can read here: <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3281961&amp;SiteID=1" target="_blank">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3281961&amp;SiteID=1</a>.</p>
<p>I do like the fact that many features have been moved into Visual Studio (STRONGLY wish SSMS could debug stored procedures) but if I&#8217;m being asked to alter my workflow, then I should at least have the same features that the other tool does.</p>
<p>Microsoft, please update Visual Studio 2008 with these features.</p>
<p>Have a great day and thank you!</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/469/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/469/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/469/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=469&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/05/02/needed-features-in-visual-studio-2008-server-explorer/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/05/visualstudioone-thumb.jpg" medium="image">
			<media:title type="html">visualstudioone</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/05/visualstudiothree-thumb.jpg" medium="image">
			<media:title type="html">visualstudiothree</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/05/visualstudiotwo-thumb.jpg" medium="image">
			<media:title type="html">visualstudiotwo</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/05/visualstudiofour-thumb.jpg" medium="image">
			<media:title type="html">visualstudiofour</media:title>
		</media:content>
	</item>
		<item>
		<title>Registration Now Open for Enterprise Developers Guild Code Camp on 17 May 2008</title>
		<link>http://karlshifflett.wordpress.com/2008/05/01/registration-now-open-for-enterprise-developers-guild-code-camp-on-17-may-2008/</link>
		<comments>http://karlshifflett.wordpress.com/2008/05/01/registration-now-open-for-enterprise-developers-guild-code-camp-on-17-may-2008/#comments</comments>
		<pubDate>Thu, 01 May 2008 10:18:46 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Code Camp]]></category>

		<category><![CDATA[Demonstrations]]></category>

		<category><![CDATA[Presentations]]></category>

		<category><![CDATA[WPF Business Application Series]]></category>

		<category><![CDATA[WPF General]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/?p=456</guid>
		<description><![CDATA[On Saturday 17 May 2008, the Enterprise Developers Guild will have their spring Code Camp at the CPCC Central Campus located in Charlotte, NC.
Directions and registration is posted here: http://www.developersguild.org/Default.aspx?alias=www.developersguild.org/codecamp/2008/spring
Code Camps are very informative, free and fun.
Code Camp Tracks

WPF Multi-Tier Business Application Track
VS 2008 / SQL 2008 Labs Track
Agile Track
Presentation Track

I have updated the information [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>On Saturday 17 May 2008, the <a href="http://www.developersguild.org/" target="_blank"><span style="color:#800080;">Enterprise Developers Guild</span></a> will have their spring Code Camp at the <a href="http://maps.live.com/default.aspx?v=2&amp;cp=35.215561~-80.82889&amp;style=r&amp;lvl=15&amp;tilt=-90&amp;dir=0&amp;alt=-1000&amp;where1=Elizabeth%20Ave%20at%20E%20Independence%20Blvd%2C%20Charlotte%2C%20NC&amp;encType=1"><span style="color:#0066cc;">CPCC Central Campus</span></a> located in Charlotte, NC.</p>
<p>Directions and registration is posted here: <a href="http://www.developersguild.org/Default.aspx?alias=www.developersguild.org/codecamp/2008/spring">http://www.developersguild.org/Default.aspx?alias=www.developersguild.org/codecamp/2008/spring</a></p>
<p>Code Camps are very informative, free and fun.</p>
<h3>Code Camp Tracks</h3>
<ul>
<li class="normal">WPF Multi-Tier Business Application Track</li>
<li class="normal">VS 2008 / SQL 2008 Labs Track</li>
<li class="normal">Agile Track</li>
<li class="normal">Presentation Track</li>
</ul>
<p>I have updated the information on the WPF Multi-Tier Business Application Track that you can read here: <a href="http://karlshifflett.wordpress.com/2008/04/06/may2008codecamp/">http://karlshifflett.wordpress.com/2008/04/06/may2008codecamp/</a></p>
<h3>See You At Code Camp!</h3>
<p>Have a great day!</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/456/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/456/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/456/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=456&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/05/01/registration-now-open-for-enterprise-developers-guild-code-camp-on-17-may-2008/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>
	</item>
		<item>
		<title>Reconciling Initial Use of LINQ to SQL DataContext</title>
		<link>http://karlshifflett.wordpress.com/2008/04/30/reconciling-initial-use-of-linq-to-sql-datacontext/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/30/reconciling-initial-use-of-linq-to-sql-datacontext/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 12:28:02 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Performance]]></category>

		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/04/30/reconciling-initial-use-of-linq-to-sql-datacontext/</guid>
		<description><![CDATA[A few days ago in my blog post, Sample Series - Bench Marking Object Loading I showed bench mark times for several different methods of loading Business Entity Objects from a SQL Server database.&#160; LINQ to SQL turned in the slowest times.&#160; 
I received comments and emails so I went back and wrote a real [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A few days ago in my blog post, <a title="Sample Series - Bench Marking Object&nbsp;Loading" href="http://karlshifflett.wordpress.com/2008/04/27/sample-series-bench-marking-object-loading/" rel="bookmark">Sample Series - Bench Marking Object Loading</a> I showed bench mark times for several different methods of loading Business Entity Objects from a SQL Server database.&nbsp; LINQ to SQL turned in the slowest times.&nbsp; </p>
<p>I received comments and emails so I went back and wrote a real world application that did more than one test that is posted here, <a title="Permanent Link to Sample Series - Bench Marking Object Loading Application&nbsp;II" href="http://karlshifflett.wordpress.com/2008/04/28/sample-series-bench-marking-object-loading-application-ii/" rel="bookmark">Sample Series - Bench Marking Object Loading Application II</a>.&nbsp; This application showed that LINQ to SQL is as faster or faster than other methods used to load objects.</p>
<p>However, I still needed to reconcile the results from the first bench mark test.&nbsp; These numbers were not going to go away.</p>
<p><a href="http://joshsmithonwpf.wordpress.com/ On" target="_blank">Josh Smith</a> and I will be teaching the <a title="Permanent Link to WPF Multi-Tier Business Application Track at the Enterprise Developers Guild Code Camp on 17 May&nbsp;2008" href="http://karlshifflett.wordpress.com/2008/04/06/may2008codecamp/" rel="bookmark">WPF Multi-Tier Business Application Track at the Enterprise Developers Guild Code Camp on 17 May 2008</a> and one of the sessions is on WPF Tools &amp; Performance Testing.</p>
<p><a href="http://marlongrech.wordpress.com/" target="_blank">Marlon Grech</a> and I were emailing back and forth about how to find the hold up and he told me he uses <a href="http://www.red-gate.com/products/Ants_Profiler/index.htm" target="_blank">Red Gate Software&#8217;s Ants Profiler</a>.&nbsp; So, yesterday I purchase Ants Profiler and got to work.</p>
<h3>The Profiling</h3>
<p>Using Ants Profiler, I ran two profile tests.&nbsp; The first test I only ran the LoadLINQ method once.&nbsp; This would give me a base line to compare the running of LoadLINQ multiple times.</p>
<p>The times are in seconds.&nbsp; The longer run time in seconds is because the Ants Profiler is doing a lot of work to gather the information from the application and CLR classes that the application calls.</p>
<p>While the number of seconds to run the program under the profiler is longer than the one second run times we got in the initial blog post, the results are relative with respect to method run times.&nbsp; The red bar graph indicates a relative run time of the method compared to other methods.</p>
<p>In the next two images, notice that LoadLINQ runs much faster on the second run.&nbsp; Ants Profiler will enable us to find out why. </p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/ants1.jpg"><img style="border-width:0;" height="97" alt="Ants1" src="http://karlshifflett.files.wordpress.com/2008/04/ants1-thumb.jpg?w=442&h=97" width="442" border="0"></a> </p>
<p>&nbsp;<a href="http://karlshifflett.files.wordpress.com/2008/04/ants3.jpg"><img style="border-width:0;" height="84" alt="Ants3" src="http://karlshifflett.files.wordpress.com/2008/04/ants3-thumb.jpg?w=345&h=84" width="345" border="0"></a></p>
<p>In the below two images the longer running code is easily found.&nbsp; Look at the top line of code in each image.&nbsp; This is the constructor for the DataContext.&nbsp; </p>
<p>We can see that the very first time this is called it took 2.66.&nbsp; When I profiled the application the second time, notice that the time to call the constructor twice was only 2.67.</p>
<p>Ants Profiler has shown us exactly which line of code was the initial bottleneck.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/ants2.jpg"><img style="border-width:0;" height="91" alt="Ants2" src="http://karlshifflett.files.wordpress.com/2008/04/ants2-thumb.jpg?w=638&h=91" width="638" border="0"></a>&nbsp;&nbsp; </p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/ants4.jpg"><img style="border-width:0;" height="73" alt="Ants4" src="http://karlshifflett.files.wordpress.com/2008/04/ants4-thumb.jpg?w=643&h=73" width="643" border="0"></a> </p>
<p>I used another feature of Ants Profiler to view the CLR method calls and execution times to determine what was happening within the constructor of the DataContext.&nbsp; </p>
<p>The below image shows the method calls inside the DataContext constructor and that the DataContext.Init method was taking up almost all of the time.&nbsp; Ants Profiler allows you to &#8220;drill into&#8221; that method and see what is going on under the covers.&nbsp; Karl really likes this drilling business;&nbsp; both Ants Profiler and <a href="http://karlshifflett.wordpress.com/mole-for-visual-studio/" target="_blank">Mole</a> share this common feature of allowing developers to drill around very easily and inspect under the hood.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/ants5.jpg"><img style="border-width:0;" height="113" alt="Ants5" src="http://karlshifflett.files.wordpress.com/2008/04/ants5-thumb.jpg?w=599&h=113" width="599" border="0"></a> </p>
<p>The below image is a profile of the DataContext.Init method.&nbsp; (the reason for the time differences is that I captured these images on different runs of the profiler.)</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/ants6.jpg"><img style="border-width:0;" height="273" alt="Ants6" src="http://karlshifflett.files.wordpress.com/2008/04/ants6-thumb.jpg?w=597&h=273" width="597" border="0"></a> </p>
<h3>Close</h3>
<p>In case you&#8217;re wondering, I&#8217;m not a sales person or employee of Red Gate, I just love their products and support.&nbsp; I&#8217;ve been a long time SQL Compare customer.&nbsp; </p>
<p>Now I have Ants Profiler in my toolbox and love the fact that I can look under the hood and see what is going on in my applications.</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
<p><font color="#c0943f"></font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/453/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/453/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/453/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/453/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/453/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=453&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/30/reconciling-initial-use-of-linq-to-sql-datacontext/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/ants1-thumb.jpg" medium="image">
			<media:title type="html">Ants1</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/ants3-thumb.jpg" medium="image">
			<media:title type="html">Ants3</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/ants2-thumb.jpg" medium="image">
			<media:title type="html">Ants2</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/ants4-thumb.jpg" medium="image">
			<media:title type="html">Ants4</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/ants5-thumb.jpg" medium="image">
			<media:title type="html">Ants5</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/ants6-thumb.jpg" medium="image">
			<media:title type="html">Ants6</media:title>
		</media:content>
	</item>
		<item>
		<title>Sample Series - Bench Marking Object Loading Application II</title>
		<link>http://karlshifflett.wordpress.com/2008/04/28/sample-series-bench-marking-object-loading-application-ii/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/28/sample-series-bench-marking-object-loading-application-ii/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 00:56:56 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Performance]]></category>

		<category><![CDATA[Samples]]></category>

		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/04/28/sample-series-bench-marking-object-loading-application-ii/</guid>
		<description><![CDATA[This is the next sample in the Sample Applications Series. The purpose of the Sample Series is to provide concise code solutions for specific programming tasks. This sample provides a brief description of the problem, the solution and full source code.
After last nights blog post Sample Series - Bench Marking Object Loading I received a [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This is the next sample in the Sample Applications Series. The purpose of the Sample Series is to provide concise code solutions for specific programming tasks. This sample provides a brief description of the problem, the solution and full source code.</p>
<p>After last nights blog post <a href="http://karlshifflett.wordpress.com/2008/04/27/sample-series-bench-marking-object-loading/" target="_blank">Sample Series - Bench Marking Object Loading</a> I received a good number of questions on a <a href="http://groups.google.com/group/wpf-disciples" target="_blank">WPF Disciples Google Group Discussion Thread</a>.&nbsp; If you didn&#8217;t get a chance to read that blog post, please look at it now as I won&#8217;t be repeating the background information.</p>
<p>I thought about all the comments, suggestions and possible &#8220;one time&#8221; object initiation that various software technologies pay the first time they are used.</p>
<p>I really want to get to the bottom for the initial delay that me and others got when using LINQ to build object collections.&nbsp; Additionally I wanted to see what the bench mark would look like in a typical application.</p>
<p>When I was researching the loading of business entity objects from a database I ran across an awesome article on Code Project entitled, <a href="http://www.codeproject.com/KB/database/DynamicMethod_ILGenerator.aspx" target="_blank"><font color="#800080">Dynamic Method IL Generator</font></a> written by Code Project author <a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=1715766" target="_blank"><font color="#800080">Herb Randson</font></a>.&nbsp; I used the code from his article and translated into VB.NET and made just a few very minor adjustments and added a LINQ test to the mix for comparison.</p>
<h3></h3>
<h3>New Bench Mark Test</h3>
<p>Let me introduce you to the players in this bench mark.</p>
<h5>NEW SQL Server Express Database</h5>
<p>Included in the download is a NEW BenchMarkData SQL Server Express 2005 Database.&nbsp; If you downloaded and set up the database from the previous sample, please remove that database and attached the new database supplied with the source download below.&nbsp; </p>
<p>To run the tests in the sample download, you will need to have either SQL Server 2005 or SQL Server 2005 Express installed on your computer.&nbsp; Attach the included database to either server and edit the app.config file and changed the connection string to match your system.&nbsp; This database is ultra simple with one table at has 19,972 rows that I imported from the AdventureWorks database Person.Contacts table.&nbsp; </p>
<p>This new database has an additional field and stored procedures for all CRUD operations.</p>
<h5>NEW Bench Mark Loading Objects Sample Application</h5>
<p>This new application is a Windows forms application that runs all the tests and displays the results in a DataGridView.&nbsp; There are four sets of tests.&nbsp; Each set of tests has 5 tests, except for the LINQ set which has 6 tests.&nbsp; All CRUD operations are performed using stored procedures and concurrency checks are made using the SQL Server timestamp column in each row.&nbsp; Each test has been optimized and correctly handles DBNull coming from the database and correctly set Nullable(Of Type) properties.</p>
<p>The below list describes the four sets of tests.&nbsp; </p>
<ul>
<li>Manual - method loads the business objects by iterating a SQLDataReader and manually constructing the classes with optimized code.&nbsp; In a real world application, this would require that a method be written for each business entity to load it.
<li>Reflection - method loads the business objects by iterating a SQLDataReader and using a cached listing of the target objects properties.&nbsp; In a real world application, this requires only this code be called and a List of business objects will be returned.&nbsp; What is more realistic is that a method will be created that wraps this code as I have done in this application.
<li>Dynamic - method loads the business objects by iterating a SQLDataReader and using some of the most wicked code I&#8217;ve seen a long time.&nbsp; In his Code Project article <a href="http://www.codeproject.com/KB/database/DynamicMethod_ILGenerator.aspx" target="_blank"><font color="#800080">Dynamic Method IL Generator</font></a> the author lays out how to generate IL code at runtime and then call that code.&nbsp; This method results in insanely fast loading of business objects.&nbsp; In a real world application, this requires only this code be called and a List of business objects will be returned.&nbsp; What is more realistic is that a method will be created that wraps this code as I have done in this application.
<li>LINQ - method utilizes code generated by Visual Studio 2008 and takes advantage of the stored procedures for CRUD operations.</li>
</ul>
<p>The below list describes each of the five tests performed by the four above methods.</p>
<ul>
<li>Read - Update One Record Single Connection - this test simulates the retrieval of a single record, the changing of the record by a process and the updating of the record over a single connection to the database.&nbsp; NOTE:&nbsp; This is also the very first test in the set and you will notice that it records a longer execution duration than the next test.
<li>Read - Update One Record Two Connections - this test simulates a user loading a form with a single record, editing of the record and then updating the record over two separate connections to the database.
<li>Read 911 records - this test reads all records in the database where the last name starts with &#8220;a.&#8221;&nbsp; 911 is the total number of records returned.
<li>Read Insert and Delete - this test inserters a record, rereads that record and deletes that same record.
<li>Read and Update 19,972 records using same connection - this test simulates business processing with complex business layer calculations being applied to a set of data.&nbsp; All the records are loaded into business objects, that collection of objects is iterated and each object has a field updated using a calculation and each individual record is updated back to the database.&nbsp; The same database connection is used to retrieve the records and to write them back to the database.
<li>Read and Update 19,972 records using SUBMIT CHANGES same connection - this test is only performed by LINQ and is TestNumber 6.&nbsp; I did this to show the difference between using a stored procedure and LINQ to update a large number of records in a batch.</li>
</ul>
<h3>Test Results</h3>
<p>All of these tests were run against a production SQL Server in the middle of the day.&nbsp; The client was a 2 Core Dual 2.4GHz with 2GB memory running Vista x32.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/resulttwoii.jpg"><img style="border-width:0;" height="481" alt="ResultTwoII" src="http://karlshifflett.files.wordpress.com/2008/04/resulttwoii-thumb.jpg?w=644&h=481" width="644" border="0"></a> </p>
<p>This test clearly shows that LINQ to SQL is just as fast or faster than other techniques for building business entity objects from a database query.</p>
<p>It is only in the Update department that LINQ to SQL turns in slower times.&nbsp; The average time to retrieve 19,972 records, iterate through them and write individual updates back to the database was 16 seconds.&nbsp; Pretty impressive.&nbsp; LINQ using stored procedures took 24 seconds.&nbsp; Not back either.&nbsp; However, when I used the LINQ SubmitChanges command it took 1:28 seconds. </p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/resultoneii.jpg"><img style="border-width:0;" height="495" alt="ResultOneII" src="http://karlshifflett.files.wordpress.com/2008/04/resultoneii-thumb.jpg?w=660&h=495" width="660" border="0"></a> </p>
<h3>Comments</h3>
<p>After showing this to others at my work, they looked at me and said, what is the conclusion?&nbsp; Which technique should we go with?&nbsp; We can generate all of the code for any of the techniques.&nbsp; The leanest method is the ManualBuilder method.&nbsp; It consistently turns in the second fastest time and does not require any caching of precompiled queries, IL execution code or reflection property lists.&nbsp; So for my next few projects, I&#8217;m sticking with &#8220;old school&#8221; DataReaders and optimized .NET object loading.</p>
<p>Choosing the ManualBuilder does not prevent me from using LINQ within the application once the object are loaded.&nbsp; For object loading, I prefer simpler business objects with less overhead and less dependencies. </p>
<h3>Close</h3>
<p>Your application requirements and development resources will dictate your choices.&nbsp; Making an informed decision that meets your needs is what this post is about.</p>
<p>I hope this sample gets you to investigate the various options you have for loading business entity objects from a database.</p>
<p><strong>Source Code:</strong> After downloading the source code you MUST change the file extension from .zip.DOC to .zip. This is a requirement of WordPress.com.</p>
<p>The source includes a Visual Studio 2008 solution and SQL Server 2005 database for testing.&nbsp; At your option, you could very easily download the code and point it to any of your current databases and run tests against them. </p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/benchmarkobjectloadingsampletwozip.doc" target="_blank">Download Source and SQL Database 779KB</a></p>
<p>Hope you can learn just a little bit more about .NET from this article and the Sample Series.</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/440/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/440/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/440/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/440/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/440/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/440/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/440/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/440/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/440/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/440/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/440/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/440/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=440&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/28/sample-series-bench-marking-object-loading-application-ii/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/resulttwoii-thumb.jpg" medium="image">
			<media:title type="html">ResultTwoII</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/resultoneii-thumb.jpg" medium="image">
			<media:title type="html">ResultOneII</media:title>
		</media:content>
	</item>
		<item>
		<title>Sample Series - Bench Marking Object Loading</title>
		<link>http://karlshifflett.wordpress.com/2008/04/27/sample-series-bench-marking-object-loading/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/27/sample-series-bench-marking-object-loading/#comments</comments>
		<pubDate>Sun, 27 Apr 2008 23:33:04 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Performance]]></category>

		<category><![CDATA[Samples]]></category>

		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/04/27/sample-series-bench-marking-object-loading/</guid>
		<description><![CDATA[ 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Time to create 19,972 business objects
This is the next sample in the Sample Applications Series. The purpose of the Sample Series is to provide concise code solutions for specific programming tasks. This sample provides a brief description of the problem, the solution and full source code.
Josh Smith and I are very busy preparing [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultsconsole.jpg"><img style="border-width:0;" height="253" alt="BenchMarkResultsConsole" src="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultsconsole-thumb.jpg?w=313&h=253" width="313" border="0"></a> </p>
<p><em><font face="Arial" size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time to create 19,972 business objects</font></em></p>
<p>This is the next sample in the Sample Applications Series. The purpose of the Sample Series is to provide concise code solutions for specific programming tasks. This sample provides a brief description of the problem, the solution and full source code.</p>
<p><a href="http://joshsmithonwpf.wordpress.com/" target="_blank">Josh Smith</a> and I are very busy preparing for the <a href="http://www.developersguild.org/Default.aspx?alias=www.developersguild.org/codecamp/2008/spring" target="_blank">Charlotte, NC May 17th Code Camp</a> as we will be teaching the <a href="http://karlshifflett.wordpress.com/2008/04/06/may2008codecamp/" target="_blank">WPF Multi-Tier Business Application Track</a>.&nbsp; This will be a very exciting day for WPF and LOB and hope to see you there!&nbsp; </p>
<p>I am also writing the 4th installment of the WPF Business Application Series and hope to deliver the entire application soon and then continue to write articles against it.</p>
<p>During this preparation the topic of loading Business Entity Objects from the database keesp coming up.&nbsp; Each time I reflect on that topic these questions immediately come to mind:</p>
<ul>
<li>Should I stick with the time tested and super fast SQLDataReader?
<li>Should I move to LINQ to SQL?
<li>Should I load objects using reflection?
<li>Should I write object loader code for each object?
<li>When I add Silverlight into the mix will that effect my above choice?</li>
</ul>
<p>I did a good bit of research and will present the results.&nbsp; </p>
<p>When researching I ran across an awesome article on Code Project entitled, <a href="http://www.codeproject.com/KB/database/DynamicMethod_ILGenerator.aspx" target="_blank">Dynamic Method IL Generator</a> written by Code Project author <a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=1715766" target="_blank">Herb Randson</a>.&nbsp; I used the code from his article and translated into VB.NET and made just a few very minor adjustments and added a LINQ test to the mix for comparison.</p>
<p>I hope this blog post encourages you to perform your own testing before choosing Door #1 or Door #2.</p>
<h3>Introduction</h3>
<p>I wanted the test to simulate a real world database request that involved selecting almost 20,000 rows and building a generic collection of objects to process.&nbsp; Not that any of us would be selecting all our customers and stuffing them into a ComboBox, but that the test would simulate building 20,000 instances of a business object class that would be processed and the results written back to the database.&nbsp; For this bench mark, I&#8217;m not writing results back to the database.&nbsp; Business applications I write can easily generate this type and volume of traffic when performing business processing so I elected to use this as my test.&nbsp; This type of request is also commonly used to preprocess data for a report.</p>
<p>Users could care less about bench marks.&nbsp; They judge our applications based on how it appears to run on their desktop in their unique environment.&nbsp; How long does a form take to appear?&nbsp; When the customer form opens and the users clicks on the History tab, is there a delay before the 500 records appear in the grid?&nbsp; When the user runs a report that requires preprocessing, how long does it take?&nbsp; How long does batch processing take?&nbsp; Is the UI frozen while processing?</p>
<p>When I design applications my first priority is delivering documented, maintainable code, my second priority is performance.</p>
<p>As architects we are not only concerned with how responsive and quick our UI&#8217;s are, but must take into consideration processing time on our servers.&nbsp; If we have clients that are connected over the web, almost all processing will take place on the web or application server.&nbsp; It is imperative that server deployed code runs as fast and efficient as possible.&nbsp; </p>
<h3>Bench Mark Testing</h3>
<p>Let me introduce you to the players in this bench mark.</p>
<h5>SQL Server Express Database</h5>
<p>Included in the download is the BenchMarkData SQL Server Express 2005 Database.&nbsp; To run the tests in the sample download, you will need to have either SQL Server 2005 or SQL Server 2005 Express installed on your computer.&nbsp; Attach the included database to either server and edit the app.config file and changed the connection string to match your system.&nbsp; This database is ultra simple with one table at has 19,972 rows that I imported from the AdventureWorks database Person.Contacts table.</p>
<h5>SQL Server Profiler</h5>
<p>I used the SQL Server Profiler to record bench marks from the SQL Server during processing and have included the results below.</p>
<h5>Bench Mark Loading Objects Sample Application</h5>
<p>This is a very simple console application that demonstrates four different methods of loading business objects.&nbsp; I tried to make each test as far as possible.&nbsp; Each test will open and close the connection to the database.&nbsp; Each test has been optimized and correctly handles DBNull coming from the database and correctly set Nullable(Of Type) properties.</p>
<p>Below is the list of the four methods.&nbsp; Each method will build a generic List(Of Contact) or List(Of ConactEntity).&nbsp; LINQ builds the Contact class and the other methods build the ConactEntity class.&nbsp; I did this so that each technique would build a class like it would in a real world application.</p>
<ul>
<li>Manual - the LoadManual method loads the business objects by iterating a SQLDataReader and manually constructing the classes with optimized code.&nbsp; In a real world application, this would require that a method be written for each business entity to load it.
<li>Reflection - the LoadReflection method loads the business objects by iterating a SQLDataReader and using a cached listing of the target objects properties.&nbsp; In a real world application, this requires only this code be called and a List of business objects will be returned.&nbsp; What is more realistic is that a method will be created that wraps this code.
<li>Dynamic - the LoadDynamic method loads the business objects by iterating a SQLDataReader and using some of the most wicked code I&#8217;ve seen a long time.&nbsp; In his Code Project article <a href="http://www.codeproject.com/KB/database/DynamicMethod_ILGenerator.aspx" target="_blank">Dynamic Method IL Generator</a> the author lays out how to generate IL code at runtime and then call that code.&nbsp; This method results in insanely fast loading of business objects.&nbsp; This code reminds me of the old ADO GetRows method we used on early ASP web sites.&nbsp; This too was insanely fast compared to any other method of reading data from SQL Server.
<li>LINQ - the LoadLINQ method utilizes code generated by Visual Studio 2008, creates a DataContext and with a single line of code, transforms the query results into a List(Of Contact).</li>
</ul>
<h3>Test Results</h3>
<p>This test was run on my home system, an Intel Core2 Quad 2.4 GHz with 4 GB main memory, 4 MB L2 cache and a single hardware RAID 1 SATA disk array.&nbsp; This configuration would be common among server class machines except large servers would have more memory and dual SCSI RAID arrays.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultsconsole1.jpg"><img style="border-width:0;" height="253" alt="BenchMarkResultsConsole" src="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultsconsole-thumb1.jpg?w=313&h=253" width="313" border="0"></a> </p>
<p>From the above image, the stats that stick out are the low and high results (lower time is better).&nbsp; The LINQ loader took just over one second.&nbsp; The Dynamic loader to .063 seconds which is insanely fast.&nbsp; The other two were longer but still much faster than the LINQ solution.&nbsp; In a UI, time is perception.&nbsp; Add in any other latencies, and the user is now waiting.</p>
<p>In the below image, we can see how each of the above techniques interacted with the SQL Server while iterating the SQLDataReader.&nbsp; The duration is measured in microseconds.</p>
<p>All of the techniques are very efficient in terms of working with the SQL Server.&nbsp; Each time I ran this, I got different results with respect to CPU, but he Reads and Duration columns remained the same.&nbsp; To be honest, I do not know why the Reflection method Duration was so long compared to the others or why the LINQ to SQL method was 2.5 times slower than the Manual of Dynamic methods.&nbsp; The SQL queries were the same except for the way the LINQ query used fully qualified column names.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultssqlprofiler.png"><img style="border-width:0;" height="356" alt="BenchMarkResultsSQLProfiler" src="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultssqlprofiler-thumb.png?w=601&h=356" width="601" border="0"></a> </p>
<h3>Real World Development</h3>
<p>I strongly recommend that you read Herb&#8217;s article and the comments other developers posted.&nbsp; Herb&#8217;s article is about &#8220;how&#8221; something can be accomplished and he presents several solutions for the accomplishing the same programming task.&nbsp; I simply added a LINQ to SQL solution to the mix and presented these here for your inspection and review.</p>
<p>I don&#8217;t know about you, but I like to adopt new technologies slowly.&nbsp; Give myself and others around me time to prove them from a security, development, performance, reliability, scalability, toolset availability, toolset maturity and maintenance perspectives.</p>
<p>From a code generation standpoint, all four solutions can be code generated.&nbsp; I don&#8217;t recommend using the Visual Studio ORM Designer or SQLMetal tools at this time because they do not provide any ability for developers to place either XML comments or attributes on their class properties.&nbsp; You can use the XML Map Files to make this happen but have to pay additional performance hits for this ability.&nbsp; The lack of support for the developers meta data in the ORM tools has caused me to write all my own code generation tools.&nbsp; I hope this will be corrected in future releases of the ORM or other Visual Studio RAD tool offerings.&nbsp; While at the April 2008 MVP Summit I did speak with several teams at Microsoft about this current limitation of meta data awareness.</p>
<p>I have a blog post that raises some questions on ORM tools consuming meta data that you can read <a href="http://karlshifflett.wordpress.com/2008/03/02/visual-studio-2008-designers-and-code-generators-you-have-overlooked/" target="_blank">here.</a></p>
<p>The time tested Manual technique is super fast but requires the most code.&nbsp; If this code is generated then this becomes a non-issue.&nbsp; The Reflection and Dynamic methods offer very simple and small footprint for great functionality and performance.&nbsp; The Dynamic method has a draw back in that you can&#8217;t debug the generate IL code using the standard debugging techniques most developers are comfortable with.</p>
<p>I don&#8217;t think I&#8217;m ready to jump on the LINQ to SQL bandwagon for business object loading just yet.&nbsp; However, that does not mean that I can&#8217;t load my objects using the other techniques and then use LINQ to work with them.</p>
<h3>Close</h3>
<p>Your application requirements and development resources will dictate your choices.&nbsp; Making an informed decision that meets your needs is what this post is about.</p>
<p>I hope this sample gets you to investigate the various options you have for loading business entity objects from a database.</p>
<p><strong>Source Code:</strong> After downloading the source code you MUST change the file extension from .zip.DOC to .zip. This is a requirement of WordPress.com.</p>
<p>The source includes a Visual Studio 2008 solution and SQL Server 2005 database for testing.&nbsp; At your option, you could very easily download the code and point it to any of your current databases and run tests against them.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/benchmarkloadingobjectssamplezip.doc" target="_blank">Download Source 951 KB</a></p>
<p>Hope you can learn just a little bit more about .NET from this article and the Sample Series.</p>
<p><font color="#c0943f">Just a grain of sand on the worlds beaches.</font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/434/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/434/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/434/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=434&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/27/sample-series-bench-marking-object-loading/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultsconsole-thumb.jpg" medium="image">
			<media:title type="html">BenchMarkResultsConsole</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultsconsole-thumb1.jpg" medium="image">
			<media:title type="html">BenchMarkResultsConsole</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/benchmarkresultssqlprofiler-thumb.png" medium="image">
			<media:title type="html">BenchMarkResultsSQLProfiler</media:title>
		</media:content>
	</item>
		<item>
		<title>Mole geekSpeak Posted Online</title>
		<link>http://karlshifflett.wordpress.com/2008/04/25/mole-geekspeak-posted-online/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/25/mole-geekspeak-posted-online/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 11:16:07 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Demonstrations]]></category>

		<category><![CDATA[Mole]]></category>

		<category><![CDATA[Videos]]></category>

		<category><![CDATA[Visualizer]]></category>

		<category><![CDATA[WPF General]]></category>

		<category><![CDATA[geekSpeak]]></category>

		<category><![CDATA[video]]></category>

		<category><![CDATA[webcast]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/?p=426</guid>
		<description><![CDATA[Glen Gordon has posted the MSDN webcast geekSpeak we did on Mole.
You can view the webcast and links to resources mentioned in the webcast here: Mole geekSpeak.
Enjoy Mole!
Just a grain of sand on the worlds beaches.
       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://blogs.msdn.com/glengordon/" target="_blank">Glen Gordon</a> has posted the MSDN webcast geekSpeak we did on <a href="http://karlshifflett.wordpress.com/mole-for-visual-studio/">Mole</a>.</p>
<p>You can view the webcast and links to resources mentioned in the webcast here: <a href="http://blogs.msdn.com/geekspeak/archive/2008/04/24/resources-for-geekspeak-the-mole-visualizer-with-karl-shifflett.aspx">Mole geekSpeak</a>.</p>
<p>Enjoy Mole!</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/426/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/426/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/426/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/426/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/426/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=426&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/25/mole-geekspeak-posted-online/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Mole to View ASP.NET ViewState</title>
		<link>http://karlshifflett.wordpress.com/2008/04/23/using-mole-to-view-aspnet-viewstate/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/23/using-mole-to-view-aspnet-viewstate/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 02:11:21 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Mole]]></category>

		<category><![CDATA[Videos]]></category>

		<category><![CDATA[Visualizer]]></category>

		<category><![CDATA[WPF General]]></category>

		<category><![CDATA[geekSpeak]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/04/23/using-mole-to-view-aspnet-viewstate/</guid>
		<description><![CDATA[On April 23rd 2008 I did a MSDN geekSpeak web cast with Microsoft Developer Evangelists Glen Gordon and Brian Hitney.&#160; The great thing about geekSpeaks is that the attendees can ask questions during the web cast and get the answers they need.&#160; My great friend and Microsoft MVP Chris Love asked if Mole could be [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>On April 23rd 2008 I did a <a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032374735&amp;Culture=en-US" target="_blank">MSDN geekSpeak</a> web cast with Microsoft Developer Evangelists <a href="http://blogs.msdn.com/glengordon/default.aspx" target="_blank">Glen Gordon</a> and <a href="http://www.structuretoobig.com/home/" target="_blank">Brian Hitney</a>.&nbsp; The great thing about geekSpeaks is that the attendees can ask questions during the web cast and get the answers they need.&nbsp; My great friend and Microsoft MVP <a href="http://professionalaspnet.com/" target="_blank">Chris Love</a> asked if <a href="http://karlshifflett.wordpress.com/mole-for-visual-studio/">Mole</a> could be used to view ViewState.&nbsp; We were getting short on time so Glen suggested we take this question offline.</p>
<p>I have put together a short video that covers using Mole to view ViewState.&nbsp; Currently Mole does not decrypt the __VIEWSTATE object.&nbsp; I might do this for Mole v5 if some ASP.NET developers need this.&nbsp; Please leave a comment and let me know if you would like this feature.</p>
<p>For now, Mole does provide access to each individual control&#8217;s ViewState which includes the StateBag for the page.&nbsp; The below video demonstrates using Mole in each of these scenarios.</p>
<p><img alt="Silverlight Icon" src="http://karlshifflett.files.wordpress.com/2008/01/silverlight_logo_small1.gif"></p>
<p>The video links require Microsoft Silverlight 1.0. If you do not have it, you will be prompted to install it when you click one of the links. After the short installation is completed, close the browser window that you did the install in and re-click the video you want to watch. You can also download it <a href="http://www.microsoft.com/silverlight/" target="_blank">here</a>. Windows XP or Vista required.</p>
<p><img height="19" alt="" src="http://karlshifflett.files.wordpress.com/2008/01/movie1.gif" width="19"> <a title="This video is an introduction to Mole v4.  Recommended for all users of Mole." href="http://silverlight.services.live.com/invoke/48184/MoleViewingViewState/iframe.html" target="_blank">Mole v4 Viewing ASP.NET ViewState</a> </p>
<p>Enjoy Mole!</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/425/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/425/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/425/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=425&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/23/using-mole-to-view-aspnet-viewstate/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/01/silverlight_logo_small1.gif" medium="image">
			<media:title type="html">Silverlight Icon</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/01/movie1.gif" medium="image" />
	</item>
		<item>
		<title>WPF Sample Series - EventManager RegisterClassHandler</title>
		<link>http://karlshifflett.wordpress.com/2008/04/22/wpf-sample-series-eventmanagerregisterclasshandler/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/22/wpf-sample-series-eventmanagerregisterclasshandler/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 20:57:52 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Did You Know]]></category>

		<category><![CDATA[Samples]]></category>

		<category><![CDATA[WPF General]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/04/22/wpf-sample-series-eventmanagerregisterclasshandler/</guid>
		<description><![CDATA[This is the next sample in the WPF Sample Applications Series. The purpose of the Sample Series is to provide concise code solutions for specific programming tasks. This sample provides a brief description of the problem, the solution and full source code.
I have been working on several WPF applications in parallel for some time now.  [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This is the next sample in the WPF Sample Applications Series. The purpose of the Sample Series is to provide concise code solutions for specific programming tasks. This sample provides a brief description of the problem, the solution and full source code.</p>
<p>I have been working on several WPF applications in parallel for some time now.  All of my business applications have one main window.  These applications also have the ability to display a modal dialog box when required.  For example displaying the About Dialog Box or to allow the user to interact with the currently displayed task in some modal way, like looking up a value in a related table or editing values in related tables.  Very common tasks in a business application.</p>
<p>As I was testing my application I noticed a very strange behavior in the application for the first time.  Code was running in the main window, but the modal window was the window raising the RoutedEvent.  I had always read and been taught that RoutedEvents tunnel and bubble in the current window and not other windows.  <em>That is true, except when the RoutedEventHandler is set up using EventManager.RegisterClassHandler.</em> </p>
<p>If WPF RoutedEvents are new to you or you feel you need a short review, please check out the <a href="http://karlshifflett.wordpress.com/2007/11/07/routed-event-viewer/">RoutedEvent Viewer</a> on my blog.  It provides an interactive Routed Event Viewer application for understanding WPF Routed Events.  An understanding of RoutedEvents and the concept of events being handled is important for this short demonstration.  Additionally I recommend reading the <a href="http://msdn2.microsoft.com/en-us/library/ms742806.aspx" target="_blank">Routed Events Overview</a> in the MSDN documentation.</p>
<p>Let&#8217;s get into this.</p>
<h3>Test Bench UI</h3>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/sample1.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/04/sample1-thumb.jpg?w=432&h=308" border="0" alt="sample1" width="432" height="308" /></a> </p>
<p>The UI is very straightforward.  In the above image, I have opened the included sample program and clicked the Click Me button. </p>
<p>When the two buttons are clicked, the code handlers respond by displaying a message.  In the case of the New Window button being clicked, a new instance of Window2 will be created and displayed.  The CheckBox when Checked, will mark any events handled by Class Handler as Handled.</p>
<p>The Message: #, provides a simple way of viewing the order in which the event handlers were called by WPF.  As you use this Test Bench UI, keep track of the Message #&#8217;s to understand what is going on.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/sample2.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/04/sample2-thumb.jpg?w=640&h=268" border="0" alt="sample2" width="640" height="268" /></a> </p>
<p>In the above image, the New Window button was clicked.  You can see the order in which the handlers were called and a new instance of Window2 was created and displayed.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/sample3.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/04/sample3-thumb.jpg?w=640&h=266" border="0" alt="sample3" width="640" height="266" /></a></p>
<p>Now things get VERY interesting.  The Window 2 Button Clicked button, was clicked and handled in Window1.  Notice Message 6.  This is what caught me off guard and the purpose of this blog post.  The Class handler is assigned to handle all ClickEvents owned by the Button class.  Have a look at the below code EventManager.RegisterClassHandler line.  This line of code allows the Window1 class to monitor Button.ClickEvents in its own window and other windows in the application.  This is a great feature, unless you don&#8217;t expect it to work this way.</p>
<div class="code">
<pre><span style="color:#0000ff;">Private Sub </span>Window1_Loaded(<span style="color:#0000ff;">ByVal </span>sender <span style="color:#0000ff;">As Object</span>, _
            <span style="color:#0000ff;">ByVal </span>e <span style="color:#0000ff;">As </span>System.Windows.RoutedEventArgs) <span style="color:#0000ff;">Handles Me</span>.Loaded

    <span style="color:#008000;">&#8216;best fully understand WPF when using this
    </span>EventManager.RegisterClassHandler(<span style="color:#0000ff;">GetType</span>(Button), _
        Button.ClickEvent, <span style="color:#0000ff;">New </span>RoutedEventHandler(<span style="color:#0000ff;">AddressOf </span>WatchOutHandler))

    <span style="color:#008000;">&#8216;notice that the CheckBox&#8217;s Click event will be captured with
    &#8216;this event handler because the CheckBox gets its ClickEvent
    &#8216;from ButtonBase and not the CheckBox class.
    </span><span style="color:#0000ff;">Me</span>.AddHandler(Button.ClickEvent, _
        <span style="color:#0000ff;">New </span>RoutedEventHandler(<span style="color:#0000ff;">AddressOf </span>WindowSafeHandler))

<span style="color:#0000ff;">End Sub</span></pre>
</div>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/sample4.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/04/sample4-thumb.jpg?w=498&h=307" border="0" alt="sample4" width="498" height="307" /></a></p>
<p>The above Me.AddHandler statement goes along with the above image.  The comments above the Me.AddHandler statement give the big picture.  Notice that after clicking the CheckBox, Message 7 is displayed for the Window Handler, but not the Class Handler.  Many WPF programmers like to handler RoutedEvents at a parent container level since it just makes sense to do this.  This little application teaches us, to be on the look out for other controls that derive from the same base class that can raise the event we are watching for.  So as programmers, we should not just assume that if we are listening for a Button.ClickEvent that a real button control actually raised the event.  In the above case, it was a CheckBox control that actually raised the event.</p>
<p> <a href="http://karlshifflett.files.wordpress.com/2008/04/sample5.jpg"><img style="border-width:0;" src="http://karlshifflett.files.wordpress.com/2008/04/sample5-thumb.jpg?w=496&h=311" border="0" alt="sample5" width="496" height="311" /></a></p>
<p>In the above image the Click Me button was clicked, but only the Class Handler actually handled the event since it was marked as handled and the other event handlers down stream were not set up to handle, previously handled events.  This is where the <a href="http://karlshifflett.wordpress.com/2007/11/07/routed-event-viewer/">Routed Event Viewer</a> application really shines by allowing you to experiment and fully understand the concept of Handled RoutedEvents.</p>
<h3>Window1 XAML</h3>
<div class="code">
<pre><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">Window
    </span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Class</span><span style="color:#0000ff;">=&#8221;Window1&#8243;
    </span><span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;
    </span><span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;
    </span><span style="color:#ff0000;">Title</span><span style="color:#0000ff;">=&#8221;Window1&#8243; </span><span style="color:#ff0000;">Height</span><span style="color:#0000ff;">=&#8221;300&#8243; </span><span style="color:#ff0000;">Width</span><span style="color:#0000ff;">=&#8221;500&#8243;&gt;
    &lt;</span><span style="color:#a31515;">StackPanel </span><span style="color:#ff0000;">Orientation</span><span style="color:#0000ff;">=&#8221;Vertical&#8221;&gt;
        &lt;</span><span style="color:#a31515;">Button </span><span style="color:#ff0000;">Margin</span><span style="color:#0000ff;">=&#8221;10&#8243; </span><span style="color:#ff0000;">Content</span><span style="color:#0000ff;">=&#8221;Click Me&#8221;
                </span><span style="color:#ff0000;">ToolTip</span><span style="color:#0000ff;">=&#8221;Click to display message below&#8221;
                </span><span style="color:#ff0000;">VerticalAlignment</span><span style="color:#0000ff;">=&#8221;Top&#8221;
                </span><span style="color:#ff0000;">Click</span><span style="color:#0000ff;">=&#8221;Button_Click_1&#8243;/&gt;

        &lt;</span><span style="color:#a31515;">Button </span><span style="color:#ff0000;">Margin</span><span style="color:#0000ff;">=&#8221;10&#8243; </span><span style="color:#ff0000;">Content</span><span style="color:#0000ff;">=&#8221;New Window&#8221;
                </span><span style="color:#ff0000;">ToolTip</span><span style="color:#0000ff;">=&#8221;Click to display a new window&#8221;
                </span><span style="color:#ff0000;">VerticalAlignment</span><span style="color:#0000ff;">=&#8221;Top&#8221;
                </span><span style="color:#ff0000;">Click</span><span style="color:#0000ff;">=&#8221;Button_Click&#8221; /&gt;

        &lt;</span><span style="color:#a31515;">CheckBox </span><span style="color:#ff0000;">Margin</span><span style="color:#0000ff;">=&#8221;10&#8243;
                  </span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&#8221;chkHandleWatchOutEvents&#8221;
                  </span><span style="color:#ff0000;">VerticalAlignment</span><span style="color:#0000ff;">=&#8221;Top&#8221;
                  </span><span style="color:#ff0000;">Content</span><span style="color:#0000ff;">=&#8221;Handle Watch Out Event&#8221; /&gt;

        &lt;</span><span style="color:#a31515;">TextBlock </span><span style="color:#ff0000;">Margin</span><span style="color:#0000ff;">=&#8221;10&#8243; </span><span style="color:#ff0000;">VerticalAlignment</span><span style="color:#0000ff;">=&#8221;Top&#8221;
                   </span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&#8221;tbWatchOutMessages&#8221; /&gt;

        &lt;</span><span style="color:#a31515;">TextBlock </span><span style="color:#ff0000;">Margin</span><span style="color:#0000ff;">=&#8221;10&#8243; </span><span style="color:#ff0000;">VerticalAlignment</span><span style="color:#0000ff;">=&#8221;Top&#8221;
                   </span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&#8221;tbSafeMessages&#8221; /&gt;

        &lt;</span><span style="color:#a31515;">TextBlock </span><span style="color:#ff0000;">Margin</span><span style="color:#0000ff;">=&#8221;10&#8243; </span><span style="color:#ff0000;">VerticalAlignment</span><span style="color:#0000ff;">=&#8221;Top&#8221;
                   </span><span style="color:#ff0000;">x</span><span style="color:#0000ff;">:</span><span style="color:#ff0000;">Name</span><span style="color:#0000ff;">=&#8221;tbHandlerMessages&#8221; /&gt;

    &lt;/</span><span style="color:#a31515;">StackPanel</span><span style="color:#0000ff;">&gt;
&lt;/</span><span style="color:#a31515;">Window</span><span style="color:#0000ff;">&gt;
</span></pre>
</div>
<h3>Window1 XAML VB</h3>
<div class="code">
<pre><span style="color:#0000ff;">Class </span>Window1

    <span style="color:#0000ff;">Private </span>_intMessageNumber <span style="color:#0000ff;">As Integer

    Private Sub </span>WatchOutHandler(<span style="color:#0000ff;">ByVal </span>sender <span style="color:#0000ff;">As Object</span>, <span style="color:#0000ff;">ByVal </span>e <span style="color:#0000ff;">As </span>RoutedEventArgs)

        _intMessageNumber += 1
        <span style="color:#0000ff;">If TypeOf </span>e.OriginalSource <span style="color:#0000ff;">Is </span>CheckBox <span style="color:#0000ff;">Then
            </span><span style="color:#008000;">&#8216;this line of code will never run, but here to prove the point
            </span><span style="color:#0000ff;">Me</span>.tbSafeMessages.Text = <span style="color:#0000ff;">String</span>.Format( _
              <span style="color:#a31515;">&#8220;Class Handler: CheckBox clicked at {0}, Message: {1}&#8221;</span>, _
              Now.ToLongTimeString, _intMessageNumber.ToString)
        <span style="color:#0000ff;">Else
            Me</span>.tbWatchOutMessages.Text = <span style="color:#0000ff;">String</span>.Format( _
              <span style="color:#a31515;">&#8220;Class Handler: {0} was clicked at {1}, Message: {2}&#8221;</span>, _
              <span style="color:#0000ff;">CType</span>(e.OriginalSource, Button).Content.ToString, _
              Now.ToLongTimeString, _intMessageNumber.ToString)
        <span style="color:#0000ff;">End If

        </span>e.Handled = <span style="color:#0000ff;">Me</span>.chkHandleWatchOutEvents.IsChecked.Value

    <span style="color:#0000ff;">End Sub

    Private Sub </span>WindowSafeHandler(<span style="color:#0000ff;">ByVal </span>sender <span style="color:#0000ff;">As Object</span>, <span style="color:#0000ff;">ByVal </span>e <span style="color:#0000ff;">As </span>RoutedEventArgs)

        _intMessageNumber += 1
        <span style="color:#0000ff;">If TypeOf </span>e.OriginalSource <span style="color:#0000ff;">Is </span>CheckBox <span style="color:#0000ff;">Then
            Me</span>.tbSafeMessages.Text = <span style="color:#0000ff;">String</span>.Format( _
              <span style="color:#a31515;">&#8220;Window Handler: CheckBox clicked at {0}, Message: {1}&#8221;</span>, _
              Now.ToLongTimeString, _intMessageNumber.ToString)
        <span style="color:#0000ff;">Else
            Me</span>.tbSafeMessages.Text = <span style="color:#0000ff;">String</span>.Format( _
              <span style="color:#a31515;">&#8220;Window Handler: {0} was clicked at {1}, Message: {2}&#8221;</span>, _
              <span style="color:#0000ff;">CType</span>(e.OriginalSource, Button).Content.ToString, _
              Now.ToLongTimeString, _intMessageNumber.ToString)
        <span style="color:#0000ff;">End If

    End Sub

    Private Sub </span>Window1_Loaded(<span style="color:#0000ff;">ByVal </span>sender <span style="color:#0000ff;">As Object</span>, _
                <span style="color:#0000ff;">ByVal </span>e <span style="color:#0000ff;">As </span>System.Windows.RoutedEventArgs) <span style="color:#0000ff;">Handles Me</span>.Loaded

        <span style="color:#008000;">&#8216;best fully understand WPF when using this
        </span>EventManager.RegisterClassHandler(<span style="color:#0000ff;">GetType</span>(Button), _
            Button.ClickEvent, <span style="color:#0000ff;">New </span>RoutedEventHandler(<span style="color:#0000ff;">AddressOf </span>WatchOutHandler))

        <span style="color:#008000;">&#8216;notice that the CheckBox&#8217;s Click event will be captured with
        &#8216;this event handler because the CheckBox gets its ClickEvent
        &#8216;from ButtonBase and not the CheckBox class.
        </span><span style="color:#0000ff;">Me</span>.AddHandler(Button.ClickEvent, _
            <span style="color:#0000ff;">New </span>RoutedEventHandler(<span style="color:#0000ff;">AddressOf </span>WindowSafeHandler))

    <span style="color:#0000ff;">End Sub

    Private Sub </span>Button_Click(<span style="color:#0000ff;">ByVal </span>sender <span style="color:#0000ff;">As </span>System.Object, _
                <span style="color:#0000ff;">ByVal </span>e <span style="color:#0000ff;">As </span>System.Windows.RoutedEventArgs)

        <span style="color:#0000ff;">Dim </span>obj <span style="color:#0000ff;">As New </span>Window2
        obj.Show()

    <span style="color:#0000ff;">End Sub

    Private Sub </span>Button_Click_1(<span style="color:#0000ff;">ByVal </span>sender <span style="color:#0000ff;">As </span>System.Object, _
                <span style="color:#0000ff;">ByVal </span>e <span style="color:#0000ff;">As </span>System.Windows.RoutedEventArgs)

        _intMessageNumber += 1
        <span style="color:#0000ff;">Me</span>.tbHandlerMessages.Text = <span style="color:#0000ff;">String</span>.Format( _
          <span style="color:#a31515;">&#8220;Button Handler: {0} was clicked at {1}, Message: {2}&#8221;</span>, _
          <span style="color:#0000ff;">CType</span>(e.OriginalSource, Button).Content.ToString, Now.ToLongTimeString, _
          _intMessageNumber.ToString)

    <span style="color:#0000ff;">End Sub
End Class
</span></pre>
</div>
<h3>Close</h3>
<p>As WPF developers we have 4 ways of adding RoutedEvent Handlers to our applications and each was demonstrated in this Test Bench Sample.</p>
<ol>
<li>In XAML</li>
<li>At the class level</li>
<li>At the container level</li>
<li>At the control level</li>
</ol>
<p>Understanding how and when each event handler will be called is vital to writing a WPF application. WPF provides the flexibility we as developers require. However, it&#8217;s incumbent upon developers to understand and harness that intrinsic power so that we can deliver stable, super cool applications.</p>
<p><strong>Source Code: </strong>After downloading the source code you MUST change the file extension from .zip.DOC to .zip. This is a requirement of WordPress.com.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/eventmanagersamplezip.doc">Download Source Code 17KB</a></p>
<p>Hope you can learn just a little bit more about WPF from this article and the Sample Series.</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/424/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/424/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/424/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=424&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/22/wpf-sample-series-eventmanagerregisterclasshandler/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/sample1-thumb.jpg" medium="image">
			<media:title type="html">sample1</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/sample2-thumb.jpg" medium="image">
			<media:title type="html">sample2</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/sample3-thumb.jpg" medium="image">
			<media:title type="html">sample3</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/sample4-thumb.jpg" medium="image">
			<media:title type="html">sample4</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/sample5-thumb.jpg" medium="image">
			<media:title type="html">sample5</media:title>
		</media:content>
	</item>
		<item>
		<title>Wednesday 23 April MSDN Webcast: geekSpeak: The Mole Visualizer for WPF</title>
		<link>http://karlshifflett.wordpress.com/2008/04/22/wednesday-23-april-tomorrow-msdn-webcast-geekspeak-the-mole-visualizer-for-wpf/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/22/wednesday-23-april-tomorrow-msdn-webcast-geekspeak-the-mole-visualizer-for-wpf/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 14:49:56 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Mole]]></category>

		<category><![CDATA[Presentations]]></category>

		<category><![CDATA[Visualizer]]></category>

		<category><![CDATA[geekSpeak]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/?p=412</guid>
		<description><![CDATA[Back in January 2008, I was asked by Glen Gordon, our fantastic Microsoft Developer Evangelist for the Southeast if I would like to be a guest on geekSpeak and do a MSDN Webcast about Mole.
My reaction; honored and thrilled.
Wednesday 23 April 2008 at 3:00pm EST, Mole will be live on geekSpeak! 
You can register for the [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Back in January 2008, I was asked by <a href="http://blogs.msdn.com/glengordon/default.aspx">Glen Gordon</a>, our fantastic Microsoft Developer Evangelist for the Southeast if I would like to be a guest on <a href="http://blogs.msdn.com/geekSpeak/">geekSpeak</a> and do a MSDN Webcast about <a href="http://karlshifflett.wordpress.com/mole-for-visual-studio/">Mole</a>.</p>
<p>My reaction; honored and thrilled.</p>
<p>Wednesday 23 April 2008 at 3:00pm EST, Mole will be live on geekSpeak! </p>
<p>You can register for the Mole geekSpeak Webcast here: <a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032374735&amp;Culture=en-US"><span style="color:#0000ff;">http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032374735&amp;Culture=en-US</span></a>.</p>
<p>geekSpeaks are free Webcasts conducted over Microsoft LiveMeeting, which provides the attendee&#8217;s the ability to ask questions and get them answered during the Webcast.</p>
<p>I have bookmarked several upcoming geekSpeaks myself. You can view all upcoming geekSpeak Webcasts here: <a href="http://www.microsoft.com/events/series/geekspeak.aspx?tab=webcasts&amp;id=liveall">http://www.microsoft.com/events/series/geekspeak.aspx?tab=webcasts&amp;id=liveall</a>.</p>
<p>Looking forward to your questions about Mole on geekSpeak!</p>
<p>Have a great day!</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/412/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/412/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/412/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/412/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=412&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/22/wednesday-23-april-tomorrow-msdn-webcast-geekspeak-the-mole-visualizer-for-wpf/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>
	</item>
		<item>
		<title>Fort Knox Business Objects ( yes / no )</title>
		<link>http://karlshifflett.wordpress.com/2008/04/20/fort-knox-business-objects-yes-no/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/20/fort-knox-business-objects-yes-no/#comments</comments>
		<pubDate>Sun, 20 Apr 2008 18:29:47 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Data Binding]]></category>

		<category><![CDATA[Did You Know]]></category>

		<category><![CDATA[Exceptions]]></category>

		<category><![CDATA[Rant]]></category>

		<category><![CDATA[Thoughts]]></category>

		<category><![CDATA[WPF General]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/?p=411</guid>
		<description><![CDATA[I&#8217;ve spent the last week at the Microsoft 2008 MVP Summit.&#160; It was a fantastic learning and sharing experience.&#160; Microsoft took excellent care of us the entire week.&#160; Spending time with other MVP&#8217;s and meeting my friends from all over the globe was priceless.
I also spent a good deal of time out of the classroom [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve spent the last week at the Microsoft 2008 MVP Summit.&nbsp; It was a fantastic learning and sharing experience.&nbsp; Microsoft took excellent care of us the entire week.&nbsp; Spending time with other MVP&#8217;s and meeting my friends from all over the globe was priceless.</p>
<p>I also spent a good deal of time out of the classroom with members from four different teams.&nbsp; It was during these times that we had some very healthy,&nbsp; animated discussions on topics that we are both passionate about.&nbsp; In the end, we shook hands and parted with deep respect looking forward to our next discussion.</p>
<p>I don&#8217;t know about the readers of my blog, but I like passionate discussions.&nbsp; I like to listen to other developers explain their approaches to problem solving and their solutions.&nbsp; After the flamethrowers are put back in the armory, I then like time to think about why the other side was presenting their point of view.&nbsp; Many times the &#8220;why&#8221; never comes out in the dialog.&nbsp; That developers life experience normally does not get presented as part of a discussion on the .NET Framework.&nbsp; So I like to marinade on the facts and work backwards to try to get inside the other persons world to understand why they want to adopt this solution.&nbsp; This is known as inductive study.&nbsp; By asking questions of the facts presented, you can many times determine context and then come to an understanding or appreciation of the process that lead to their solution.</p>
<h3>The Scenario</h3>
<p>I spent several hours talking about the concept of business objects throwing exceptions in the property setters if the value did not pass the validation rules for that property.&nbsp; If you have read my latest article, <a href="http://www.codeproject.com/KB/WPF/WPFBusinessAppsPartThree.aspx" target="_blank">WPF Business Application Series Part Three</a> you know that I strongly favor using the IDataErrorInfo interface for business object validation broken rule notification as opposed to throwing exceptions from property setters.</p>
<p>I thought long and hard about the discussions and came to this conclusion, you either favor the Fort Knox or Shopping Cart approach to business object validation.&nbsp; One is a controlling paradigm the other a trusting relationship.&nbsp; One takes a very granular approach the other a holistic approach to business object validation.</p>
<p>In discussions, business object validation is normally centered around UI binding scenarios.&nbsp; This is only one scenario and I would strongly argue that more validation takes place in the business layer processing of objects than direct UI binding.&nbsp; So proponents of throwing exceptions as a form of broken validation rule notification, must take a step back and look at this notificaiton business from a much higher perspective than just a UI binding scenario.</p>
<p>I realize that there are two schools of thought here.&nbsp; One states, an object should never be in a invalid state.&nbsp; The other, allows for temporary broken rules, but verifies object state prior to any actual use of the invalid object.&nbsp; This notion of absolute control or pure objects is an illusion that does not play well with real world business objects and today&#8217;s computer users.&nbsp; Of course application scope and requirements must dictate how and when business rules are enforced.&nbsp; As an architect I don&#8217;t want the platform to force me to write objects in a certain way just to utilize it, especially when there is no payback and only complicates development and code maintenance.&nbsp; Framework developers are not responsible for my data, me and my developers are.</p>
<p>WPF is one example of permitting developers to choose a broken validation rule notification technique that suits their application.&nbsp; It allows developers to use exceptions or IDataErrorInfo for broken validation rule notification to the class binding to it.</p>
<table cellspacing="10" cellpadding="0" width="95%" border="0">
<tbody>
<tr>
<td valign="top" align="middle"><strong>Fort Knox</strong> </td>
<td valign="top" align="middle"><strong>Shopping Cart</strong> </td>
</tr>
<tr>
<td valign="top" align="middle" width="50%"><a href="http://karlshifflett.files.wordpress.com/2008/04/fort-knox.jpg"><img style="border-width:0;" height="132" alt="fort-knox" src="http://karlshifflett.files.wordpress.com/2008/04/fort-knox-thumb.jpg?w=240&h=132" width="240" border="0"></a> </td>
<td valign="top" align="middle" width="50%"><a href="http://karlshifflett.files.wordpress.com/2008/04/ethical-shopping-cart-vob.jpg"><img style="border-width:0;" height="174" alt="ethical_shopping_cart-vob" src="http://karlshifflett.files.wordpress.com/2008/04/ethical-shopping-cart-vob-thumb.jpg?w=240&h=174" width="240" border="0"></a> </td>
</tr>
<tr>
<td valign="top">
<ul>
<li>Throws exceptions when a validation rule is violated in a property setter.&nbsp; Guards each property setter with a machine gun, sounding general quarters any time a value does not pass all the rules.&nbsp;
<li>The Fort Knox approach to shopping, would have the store manager walking with you.&nbsp; Each time you add an item to the cart, the manager would be running your credit card and possibly forcing you to submit to a polygraph.&nbsp; Your every movement would be recorded on video and watched real time by a security guard, waiting like a cat ready to pounce on its prey at the first sign of weakness.
<li>This approach makes validation rules that are dependent on two or more properties, very difficult to implement since the order that the property must be set can now become a factor when trying to avoid an exception being thrown. </li>
</ul>
</td>
<td valign="top">
<ul>
<li>Follows a passive validation model that maintains a listing of each broken rule in the object and provides a means to query an individual property or the entire object for its validation status.&nbsp;&nbsp;&nbsp;
<li>The Shopping Cart approach to object validation allows the user to shop the store, place items in the cart and then check out.&nbsp; In the above example the shopper can get feedback on items and their total as they shop, but are not prevented from adding the item to the cart.
<li>This approach only cares about the checkout process and not the act of placing an item in the cart as opposed to the Fort Knox approach that won&#8217;t let you place a second item in the cart until the first item is paid for.&nbsp; </li>
</ul>
</td>
</tr>
</tbody>
</table>
<h3>Fort Knox Business Layer Problem</h3>
<p>The Fort Knox approach can kill business layer code like LINQ queries that attempt to populate that object and the data is invalid for one reason or another.&nbsp; I&#8217;ll use two examples to illustrate this problem.</p>
<p>If you have validation rules that are dependent on one or more property values, developers will now have to write code to set property values in a certain order to avoid an exception being thrown.&nbsp; This is a crazy requirement and is contrary all .NET class design documentation.&nbsp; Can you imaging having to wrap EVERY piece of code that sets a property with a try catch block.&nbsp; Again, what about LINQ queries that are tying to populate objects and unnecessary exceptions are being thrown by property setters.&nbsp; This makes writing maintainable code MUCH harder and with ZERO payback.&nbsp; When code is changed over time, a field added, we have to factor in usless exception handling and be cognasent of the order in which property setters are called or change.</p>
<p>I was speaking to one of the team PM&#8217;s on Friday.&nbsp; When I asked him about a certain issue his response was, &#8220;stuff happens.&#8221;&nbsp; I agree with him, stuff does happen.&nbsp; The Fort Knox approach does not allow for (actually tries to prevent) temporary invalid object state.&nbsp; This all comes full circle to the Fort Knox developers that some how get this false sense of security from exceptions being thrown, as opposed to developers checking an object&#8217;s Error property or other properties that expose object state and collections of broken validation rules.&nbsp; Any developer can read and learn this programming pattern from <a href="http://www.lhotka.net/Default.aspx" target="_blank">Rockford Lhotka&#8217;s CSLA</a>, <a href="http://msdn2.microsoft.com/en-us/library/bb410105.aspx" target="_blank">Microsoft&#8217;s Validation Application Block</a> or <a href="http://www.codeproject.com/KB/WPF/WPFBusinessAppsPartThree.aspx" target="_blank">Karl Shifflett&#8217;s Lightweight Business Object Declarative Programming</a>.</p>
<p>Using the Fort Knox approach does not guarentee a valid object either.&nbsp; The developer could go through the pains of catching exceptions, but the object is still invalid if it does not pass all the validation rules.</p>
<p>In reality both approaches do allow for tracking broken rules since the developer is free to write any code in each setter and then throw the required exception.&nbsp; My biggest problem is having to code around what should be a reporting problem.&nbsp; However, this still means that all business layer processing code would have to be on the look out for a broken validation rule exception each time a setter was accessed as opposed to business layer code checking the object validation state as a whole, prior to persisting or moving an object to another tier.</p>
<h3>Close</h3>
<p>I welcome your feedback on this topic.&nbsp; Please comment on your approach to business object broken validation rule notification.&nbsp; Good discussions lead to better programming techniques and educate all who participate.</p>
<p>Have a great day!</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/411/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/411/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/411/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=411&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/20/fort-knox-business-objects-yes-no/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/fort-knox-thumb.jpg" medium="image">
			<media:title type="html">fort-knox</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/04/ethical-shopping-cart-vob-thumb.jpg" medium="image">
			<media:title type="html">ethical_shopping_cart-vob</media:title>
		</media:content>
	</item>
		<item>
		<title>Silverlight 2 LostFocus and Data Binding Bugs</title>
		<link>http://karlshifflett.wordpress.com/2008/04/12/silverlight-2-lostfocus-and-data-binding-bugs/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/12/silverlight-2-lostfocus-and-data-binding-bugs/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 06:47:20 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Bugs]]></category>

		<category><![CDATA[Silverlight]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[databinding]]></category>

		<category><![CDATA[lostfocus]]></category>

		<category><![CDATA[silverlight 2]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/04/12/silverlight-2-lostfocus-and-data-binding-bugs/</guid>
		<description><![CDATA[I have been working on a cool Silverlight application and started to run into strange behaviors.&#160; So I stopped and wrote a demo application to show the issues I found.&#160; A small demo also makes it very easy to demonstrate the problems.
Below are two videos that clearly demonstrate the issues.&#160; Please watch the videos to [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have been working on a cool Silverlight application and started to run into strange behaviors.&nbsp; So I stopped and wrote a demo application to show the issues I found.&nbsp; A small demo also makes it very easy to demonstrate the problems.</p>
<p>Below are two videos that clearly demonstrate the issues.&nbsp; Please watch the videos to fully understand the problem and the implication of these issues.</p>
<h3>Bug Demonstration Videos</h3>
<p><img style="margin:0 10px 0 0;" height="56" alt="silverlight_logo_small.gif" src="http://karlshifflett.files.wordpress.com/2008/01/silverlight_logo_small.gif?w=154&amp;h=56&h=56" width="154" align="left"></p>
<p>The video link require Microsoft Silverlight 1.0. If you do not have it, you will be prompted to install it when you click one of the links. After the short installation is completed, close the browser window that you did the install in and re-click the video you want to watch. You can also download Silverlight <a href="http://www.microsoft.com/silverlight/" target="_blank"><font color="#0066cc">here</font></a>. Windows XP or Vista required.</p>
<p><img style="border-width:0;" height="19" src="http://karlshifflett.files.wordpress.com/2008/01/movie3-thumb2.gif?w=19&amp;h=19&h=19" width="19" border="0"> <a href="http://silverlight.services.live.com/invoke/48184/SilverlightFocusBugs/iframe.html" target="_blank"><font color="#0066cc">Silverlight 2 LostFocus Bugs Video</font></a>&nbsp; </p>
<p><img style="border-width:0;" height="19" src="http://karlshifflett.files.wordpress.com/2008/01/movie3-thumb2.gif?w=19&amp;h=19&h=19" width="19" border="0"> <font color="#0066cc"><a href="http://silverlight.services.live.com/invoke/48184/SilverlightDataBindingBugs/iframe.html" target="_blank">Silverlight 2 Data Binding Bugs Video</a></font>&nbsp; </p>
<h3>LostFocus Bugs </h3>
<p>The above video covers the LostFocus bugs in great detail. (please watch it)</p>
<ul>
<li>Bug:&nbsp; Wrong control reported in LostFocus RoutedEvent Source when event handler is declared in XAML or by using AddHandler <em>control, delegate </em>( ex: AddHandler txtName.LostFocus, AddressOf TextBox_LostFocus ).
<li>Works:&nbsp; Correct control reported in LostFocus RoutedEvent Source when event handler is declare in code using the Handles syntax.&nbsp; ( Ex: Handles txtName.LostFocus )
<li>Bug:&nbsp; Button control does not honor the IsTabStop property when set to False.&nbsp; Button will still receive focus even though the Button property IsTabStop=False.
<li>Works:&nbsp; GotFocus RoutedEvent Source is correct regardless of where the event handler is set up.&nbsp; Event handler can be set using Handles, Addhandler, XAML on the control or XAML in a parent container.</li>
</ul>
<h3>Data Binding Bugs</h3>
<p>The above video covers the Data Binding bugs in great detail. (please watch it)</p>
<ul>
<li>Bug:&nbsp; First time the TextBoxes are tabbed through in a form and their values are not null, the INotifyPropertyChanged event is raised, even if no changes are made to the TextBox.&nbsp; On the second and subsequent passes through the form, the event is not raised unless the property is actually changed by the user changing the TextBox.&nbsp; This does not happen in WPF.
<li>Bug:&nbsp; TextBox controls are not updated even if a converter is used in the binding statement.&nbsp; In WPF, if a converter is used in a binding statement, the convert is run after the data binding takes place and the UI is updated.&nbsp; This does not happen in Silverlight but should.
<li>Bug:&nbsp; If a System.FormatException is thrown when the data binding pipeline attempts to set a property, the exception is caught (but never reported) and then the data binding pipeline sets the property to its default value.&nbsp; This should not happen.&nbsp; If a System.FormatException occurs, that should stop all further process and the exception should be reported like WPF.&nbsp; </li>
</ul>
<h3>Demo Application</h3>
<p><strong>Source Code:&nbsp; </strong>After downloading the source code you MUST change the file extension from .zip.DOC to .zip. This is a requirement of WordPress.com.</p>
<p><a href="http://karlshifflett.files.wordpress.com/2008/04/silverlightdatabindingbugzip.doc">Download Source Code 612 KB</a></p>
<h3>Close</h3>
<p>I have reported the above issues in the Silverlight.net forum: <a href="http://silverlight.net/forums/p/14035/45963.aspx#45963" target="_blank">http://silverlight.net/forums/p/14035/45963.aspx#45963</a></p>
<p>I really love Silverlight so far.&nbsp; I have moved the Declarative Programming I did in Part 3 of the Business Application Series into Silverlight with almost no changes and no loss of functionality.&nbsp; Full business object validation and case correcting in Silverlight without code just like in WPF.&nbsp; Great stuff.</p>
<p>Have a great day!</p>
<p><span style="color:#c0943f;">Just a grain of sand on the worlds beaches.</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/karlshifflett.wordpress.com/406/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/karlshifflett.wordpress.com/406/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/karlshifflett.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/karlshifflett.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/karlshifflett.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/karlshifflett.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/karlshifflett.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/karlshifflett.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/karlshifflett.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/karlshifflett.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/karlshifflett.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/karlshifflett.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=karlshifflett.wordpress.com&blog=1204518&post=406&subd=karlshifflett&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://karlshifflett.wordpress.com/2008/04/12/silverlight-2-lostfocus-and-data-binding-bugs/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/karlshifflett-128.jpg" medium="image">
			<media:title type="html">Karl Shifflett</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/01/silverlight_logo_small.gif?w=154&#38;h=56" medium="image">
			<media:title type="html">silverlight_logo_small.gif</media:title>
		</media:content>

		<media:content url="http://karlshifflett.files.wordpress.com/2008/01/movie3-thumb2.gif?w=19&#38;h=19" medium="image" />

		<media:content url="http://karlshifflett.files.wordpress.com/2008/01/movie3-thumb2.gif?w=19&#38;h=19" medium="image" />
	</item>
		<item>
		<title>WPF Sample Series - WPF MDI Task Switching</title>
		<link>http://karlshifflett.wordpress.com/2008/04/10/wpf-sample-series-wpf-mdi-task-switching/</link>
		<comments>http://karlshifflett.wordpress.com/2008/04/10/wpf-sample-series-wpf-mdi-task-switching/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 10:12:34 +0000</pubDate>
		<dc:creator>Karl Shifflett</dc:creator>
		
		<category><![CDATA[Data Binding]]></category>

		<category><![CDATA[Samples]]></category>

		<category><![CDATA[WPF Controls]]></category>

		<category><![CDATA[WPF General]]></category>

		<guid isPermaLink="false">http://karlshifflett.wordpress.com/2008/04/10/wpf-sample-series-wpf-mdi-task-switching/</guid>
		<description><![CDATA[ 
This is the next sample in the WPF Sample Applications Series. The purpose of the Sample Series is to provide concise code solutions for specific programming tasks. This sample provides a brief description of the problem, the solution and full source code.
I&#8217;ve been working on the WPF Business Application Series and wanted to add [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://karlshifflett.files.wordpress.com/2008/04/wpfmditaskswitching2.jpg"><img style="border-width:0;" height="610" alt="WPFMDITaskSwitching" src="http://karlshifflett.files.wordpress.com/2008/04/wpfmditaskswitching-thumb2.jpg?w=690&h=610" width="690" border="0"></a> </p>
<p>This is the next sample in the WPF Sample Applications Series. The purpose of the Sample Series is to provide concise code solutions for specific programming tasks. This sample provides a brief description of the problem, the solution and full source code.</p>
<p>I&#8217;ve been working on the WPF Business Application Series and wanted to add Windows style task switching to my MDI applications.&nbsp; Task switching is familiar to Windows users and can help them find a window when they have several open at once.&nbsp; Also this type of feature &#8220;shows&#8221; well in demonstrations.</p>
<p>From the above image, you can see that three MDI forms were opened up and then the user opened the task switching dialog by pressing CTRL+TAB.&nbsp; The user can then continue to cycle through the open forms by pressing CTRL+TAB.&nbsp; The user can also select a form by clicking the name of the form with the mouse.</p>
<p>Once a form is opened, you can RIGHT CLICK&nbsp; on the form and select Close Tab from the context menu to close the form. </p>
<h3>UI Demonstration Video</h3>
<p><img style="margin:0 10px 0 0;" height="56" alt="silverlight_logo_small.gif" src="http://karlshifflett.files.wordpress.com/2008/01/silverlight_logo_small.gif?w=154&amp;h=56&h=56" width="154" align="left"></p>
<p>The video link require Microsoft Silverlight 1.0. If you do not have it, you will be prompted to install it when you click one of the links. After the short installation is completed, close the browser window that you did the install in and re-click the video you want to watch. You can also download Silverlight <a href="http://www.microsoft.com/silverlight/" target="_blank"><font color="#0066cc">here</font></a>. Windows XP or Vista required.</p>
<p><img style="border-width:0;" height="19" src="http://karlshifflett.files.wordpress.com/2008/01/movie3-thumb2.gif?w=19&amp;h=19&h=19" width="19" border="0"> <font color="#0066cc"><a href="http://silverlight.services.live.com/invoke/48184/WPFMDITaskSwitching/iframe.html" target="_blank">WPF MDI Task Switching Video</a></font>&nbsp;</p>
<h3>Program Flow</h3>
<p>When the application is started up, the menu is loaded from data.&nbsp; In this demo application, it is loaded from strings.&nbsp; In a real world application, the menu data will come from a database, with menu options selected based on the users security content.</p>
<p>When a menu item is clicked, the window OnPetMenuClick event handler dynamically loads the required UserControl into a TabItem that is then loaded into the TabControl and displayed to the user.</p>
<p>The user then decides to use the task switching feature and presses the CTRL+TAB keystroke combination.&nbsp; This is trapped by the window PreviewKeyDown event handler and the task switching UserControl is brought into view.&nbsp; When this happens, focus is also moved to the task switching UserControl and is trapped within the control until it closes.&nbsp; The user can use CTRL+TAB to cycle through their forms, find the one they want and select it.&nbsp; After selecting the form, the task switcher closes and they are brought to the form they selected.</p>
<h3>Program Code</h3>
<div class="code">
<pre><span style="color:blue;">&lt;</span><span style="color:#a31515;">DockPanel</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">Border </span><span style="color:red;">DockPanel.Dock</span><span style="color:blue;">=&#8221;Top&#8221;&gt;
        &lt;</span><span style="color:#a31515;">Grid</span><span style="color:blue;">&gt;

            &lt;</span><span style="color:#a31515;">TabControl </span><span style="color:red;">x</span><span style="color:blue;">:</span><span style="color:red;">Name</span><span style="color:blue;">=&#8221;tcOpenForms&#8221; </span><span style="color:red;">SelectedIndex</span><span style="color:blue;">=&#8221;0&#8243;
                </span><span style="color:red;">TabStripPlacement</span><span style="color:blue;">=&#8221;Bottom&#8221; /&gt;

            &lt;</span><span style="color:#a31515;">local</span><span style="color:blue;">:</span><span style="color:#a31515;">TaskSwitcherControl </span><span style="color:red;">x</span><span style="color:blue;">:</span><span style="color:red;">Name</span><span style="color:blue;">=&#8221;ucTaskSwitcherControl&#8221;
                </span><span style="color:red;">HorizontalAlignment</span><span style="color:blue;">=&#8221;Center&#8221; </span><span style="color:red;">VerticalAlignment</span><span style="color:blue;">=&#8221;Center&#8221;
                </span><span style="color:red;">Visibility</span><span style="color:blue;">=&#8221;Collapsed&#8221;&gt;

                &lt;</span><span style="color:#a31515;">local</span><span style="color:blue;">:</span><span style="color:#a31515;">TaskSwitcherControl.BitmapEffect</span><span style="color:blue;">&gt;
                    &lt;</span><span style="color:#a31515;">OuterGlowBitmapEffect </span><span style="color:red;">GlowSize</span><span style="color:blue;">=&#8221;8&#8243; </span><spa