<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<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/"
	>

<channel>
	<title>Dylan Marks on Web Application Development</title>
	<link>http://www.dioramadesign.net/blog</link>
	<description>Notes on web application design using .NET and XHTML</description>
	<pubDate>Tue, 01 May 2007 15:40:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>optimizing XSL in .NET 2.0</title>
		<link>http://www.dioramadesign.net/blog/optimizing-xsl-in-net-20/</link>
		<comments>http://www.dioramadesign.net/blog/optimizing-xsl-in-net-20/#comments</comments>
		<pubDate>Tue, 01 May 2007 15:39:27 +0000</pubDate>
		<dc:creator>dmarks</dc:creator>
		
		<category><![CDATA[General Tech]]></category>

		<guid isPermaLink="false">http://www.dioramadesign.net/blog/optimizing-xsl-in-net-20/</guid>
		<description><![CDATA[This week I spent some time with the excellent Jet Brains dotTrace Profiler, which allows you to see exactly how many milliseconds every method of your code is taking.&#160;I found the performance profiling quite easy to use, and within a few minutes I had already isolated a few problem areas in our application.&#160; 
One of [...]]]></description>
			<content:encoded><![CDATA[<p>This week I spent some time with the excellent <a title="Profile performance and memory in .NET" href="http://www.jetbrains.com/profiler/">Jet Brains dotTrace Profiler</a>, which allows you to see exactly how many milliseconds every method of your code is taking.&nbsp;I found the performance profiling quite easy to use, and within a few minutes I had already isolated a few problem areas in our application.&nbsp; </p>
<p>One of the main trouble spots I came across was with the <em><a title="MSDN docs on XsltCompiledTransform class" href="http://msdn2.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx">XslCompiledTransform</a> </em>class, which replaces the new obsolete <em><a title="MSDN article on migrating to XslCompiledTransform" href="http://msdn2.microsoft.com/en-us/library/66f54faw.aspx">XsltTransform</a></em> class.&nbsp; This class, new to .net 2.0,&nbsp;performs way faster because it actually loads and compiles the xslt into <abbr title="Microsoft Intermediate Language - all .net languages are converted into this when compiled">MSIL</abbr>.&nbsp; We rely heavily on xslts in our applications, with almost all html being defined in xslts instead of embedded inside app code.&nbsp;I&#8217;ll go into detail on this in a future post.</p>
<p>Using the profiler, I was noticing that loading xslt into <em>XslCompiledTransform</em> was taking a good 30-35% of the processing time for a page, since it is actually compiling the xslt on the fly. The solution? Either use caching, or <a title="optimize xsltcompiledtransform by making it static" href="http://www.cornetdesign.com/2006/12/improving-performance-of.html">make the compiled transform static</a>, so that it reuses the same one instead of constantly recompiling it. </p>
<p>You may find my <a href="http://www.dioramadesign.net/blog/some-notes-on-httpcontextcache/">notes on httpcontext.cache</a>&nbsp;helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dioramadesign.net/blog/optimizing-xsl-in-net-20/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rejoice Midi Software</title>
		<link>http://www.dioramadesign.net/blog/rejoice-midi-software/</link>
		<comments>http://www.dioramadesign.net/blog/rejoice-midi-software/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 17:02:06 +0000</pubDate>
		<dc:creator>dmarks</dc:creator>
		
		<category><![CDATA[General Tech]]></category>

		<guid isPermaLink="false">http://www.dioramadesign.net/blog/rejoice-midi-software/</guid>
		<description><![CDATA[In an earlier post, I mentioned how I use a piece of software called Rejoice to map events from a usb joystick/gamepad to midi notes.  This is so I can use a cheap usb video game joystick as a controller for audio software, for example changing pitch or tone by pushing the joystick a certain [...]]]></description>
			<content:encoded><![CDATA[<p>In an earlier post, I <a title="Wii-mote as a percussion instrument" href="http://www.dioramadesign.net/blog/using-the-wiimote-as-a-percussion-instrument/">mentioned</a> how I use a piece of software called Rejoice to map events from a usb joystick/gamepad to midi notes.  This is so I can use a cheap usb video game joystick as <a title="rejoice with ableton live" href="http://www.ableton.com/forum/viewtopic.php?t=55664&#038;highlight=rejoice">a controller for audio software</a>, for example changing pitch or tone by pushing the joystick a certain direction, or firing off loops with buttons.  Anyhow, someone pointed out to me that the site for Rejoice is currently down, so I thought I&#8217;d upload the installer for it here, in case anyone is looking for it.</p>
<p>Rejoice will convert your Joystick or P5 Glove into a MIDI controller. Up to 1000 Button/Axis/POV actions on your joystick can be mapped to MIDI controllers. <a title="Rejoice Installer" href="http://www.dioramadesign.net/blog/wp-content/uploads/2007/03/rejoice-installer.exe">Download the installer here</a>.  Please note that I&#8217;m only hosting this freeware software as a mirror. Although I&#8217;ve personally used it, I don&#8217;t know much at all about its internal workings. Unfortunately I don&#8217;t have access to the documentation that was also on the <a title="Rejoice Midi Website" href="http://www.fireballtrailers.com/rejoice/">now defunct original site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dioramadesign.net/blog/rejoice-midi-software/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Some Notes on HttpContext.Cache</title>
		<link>http://www.dioramadesign.net/blog/some-notes-on-httpcontextcache/</link>
		<comments>http://www.dioramadesign.net/blog/some-notes-on-httpcontextcache/#comments</comments>
		<pubDate>Thu, 14 Dec 2006 19:40:55 +0000</pubDate>
		<dc:creator>dmarks</dc:creator>
		
		<category><![CDATA[General Tech]]></category>

		<guid isPermaLink="false">http://www.dioramadesign.net/blog/some-notes-on-httpcontextcache/</guid>
		<description><![CDATA[In order to really push the efficiency of your ASP.NET application, I recommend using the HttpContext.Cache object for data that rarely changes. One thing I was experiencing with a high volume site was seemingly random errors to do with accessing cached objects. Consider the following simple example:
if (HttpContext.Current.Cache[&#8220;myObject&#8221;] != null)
    Control ctrl [...]]]></description>
			<content:encoded><![CDATA[<p>In order to really push the efficiency of your ASP.NET application, I recommend using the HttpContext.Cache object for data that rarely changes. One thing I was experiencing with a high volume site was seemingly random errors to do with accessing cached objects. Consider the following simple example:</p>
<pre class="code"><span style="color: rgb(0,0,255)">if</span> (<span style="color: rgb(0,128,128)">HttpContext</span>.Current.Cache[<span style="color: rgb(128,0,0)">&#8220;myObject&#8221;</span>] != <span style="color: rgb(0,0,255)">null</span>)
    <span style="color: rgb(0,128,128)">Control</span> ctrl = (<span style="color: rgb(0,128,128)">Control</span>) <span style="color: rgb(0,128,128)">HttpContext</span>.Current.Cache[<span style="color: rgb(128,0,0)">&#8220;myObject&#8221;</span>];</pre>
<p>This seems foolproof: first you check if the object is in the cache, and only retrieve it if it is.&nbsp;The problem is that the Cache is accessed in a multi-threaded environment, and so there could be potentially&nbsp;thousands of separate web requests happening at once for this object, with some of them perhaps clearing the cache and re-adding a new copy.&nbsp;It&#8217;s entirely possible for the cache to become null in the microsecond between checking for existence and actually retrieving from it.&nbsp; To make this matter worse, it&#8217;s a bug that will likely not be caught until on production with heavy traffic, and is very hard to duplicate effectively.&nbsp; So the simple way to handle this (without messing with locks) would be to first retrieve into an object, check that <em>object</em>&nbsp;for null, and then cast it:</p>
<pre class="code"><span style="color: rgb(0,0,255)">object</span> cachedCtrl = <span style="color: rgb(0,128,128)">HttpContext</span>.Current.Cache[<span style="color: rgb(128,0,0)">&#8220;myObject&#8221;</span>];
<span style="color: rgb(0,0,255)">if</span> (cachedCtrl != <span style="color: rgb(0,0,255)">null</span>)
    <span style="color: rgb(0,128,128)">Control</span> ctrl = (<span style="color: rgb(0,128,128)">Control</span>) cachedCtrl;</pre>
<h4>Always Set an Expiration on a Cache</h4>
<p>In order to avoid the dreaded OutofMemoryException, you should make sure you are not loading too much into the cache. One way of doing this is to place a rolling timeout on your cached object. That way if it&#8217;s not being used frequently it will automatically be discarded to free up memory for other activities:</p>
<pre class="code"><span style="color: rgb(0,128,128)">HttpContext</span>.Current.Cache.Insert(<span style="color: rgb(128,0,0)">&#8220;MyObject&#8221;</span>, myObject, <span style="color: rgb(0,0,255)">null</span>,
                            System.Web.Caching.<span style="color: rgb(0,128,128)">Cache</span>.NoAbsoluteExpiration,
                            <span style="color: rgb(0,128,128)">TimeSpan</span>.FromHours(1));</pre>
<p>If you are experiencing OutOfMemoryExceptions because of this sort of situation, a quick fix would be to clear the Application Pool for that application in IIS. You can then configure the app pool to automatically recycle the working process after it has consumed too much memory.&nbsp; Open up IIS Manager and right click the associated Application Pool:</p>
<p class="MsoNormal"><a href="http://www.dioramadesign.net/blog/wp-content/uploads/2006/12/WindowsLiveWriter/NotesonHttpContext.Cache_A927/RecycleAppPool%5B6%5D1.gif" atomicselection="true"><img height="348" alt="change the maximum virtual memory in the recycling tab" src="http://www.dioramadesign.net/blog/wp-content/uploads/2006/12/WindowsLiveWriter/NotesonHttpContext.Cache_A927/RecycleAppPool_thumb%5B4%5D1.gif" width="429"></a> </p>
<p class="MsoNormal">Obviously this should be considered a temporary fix until you are able to test and push out a new version of code with more long term fixes.</p>
<h4>On HttpContext and NUnit</h4>
<p>Working directly with HttpContext makes writing Unit Tests difficult.&nbsp;When NUnit runs, it doesn&#8217;t have the same ASP.NET HttpContext to work with, and thus will throw an error when you try to access it in your code.&nbsp; Instead of accessing HttpContext directly, lately I&#8217;ve used a facade-type object that mimics the interface of HttpContext.&nbsp; If the context is available, it returns that, and if not, it returns simple collections for storing cache etc.&nbsp;I just found an excellent implementation by Phillip J Haack that does this better than my code, so I will direct you there instead of posting my version:&nbsp;&nbsp;<a title="HttpContext and Unit Testing" href="http://haacked.com/archive/2005/06/11/Simulating_HttpContext.aspx">Simulating Http Context For Unit Tests Without Using Cassinni nor IIS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dioramadesign.net/blog/some-notes-on-httpcontextcache/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The WiiMote as a Percussion Instrument</title>
		<link>http://www.dioramadesign.net/blog/using-the-wiimote-as-a-percussion-instrument/</link>
		<comments>http://www.dioramadesign.net/blog/using-the-wiimote-as-a-percussion-instrument/#comments</comments>
		<pubDate>Wed, 13 Dec 2006 18:36:36 +0000</pubDate>
		<dc:creator>dmarks</dc:creator>
		
		<category><![CDATA[General Tech]]></category>

		<guid isPermaLink="false">http://www.dioramadesign.net/blog/using-the-wiimote-as-a-percussion-instrument/</guid>
		<description><![CDATA[This is somewhat off my regular topic of .net programming, but still damn geeky: using the Nintendo Wii&#8217;s remote as a virtual percussion instrument.&#160; I&#8217;m not talking about banging it around as a drum stick! Read on and I&#8217;ll explain.. 
I was one of the lucky ones to score a new Nintendo Wii a week [...]]]></description>
			<content:encoded><![CDATA[<p>This is somewhat off my regular topic of .net programming, but still damn geeky: using the Nintendo Wii&#8217;s remote as a virtual percussion instrument.&nbsp; I&#8217;m not talking about banging it around as a drum stick! Read on and I&#8217;ll explain.. </p>
<p>I was one of the lucky ones to score a new Nintendo Wii a week after it came out, and have been currently wasting too many evenings on <a title="I disagree with their motion control issues" href="http://www.gamespot.com/wii/driving/needforspeedcarbon/review.html">Need For Speed Carbon</a> of late (wii-mote as steering wheel rocks).&nbsp;The wii-mote is truly a lovely piece of hardware that demands to be assimilated to&nbsp;other uses.&nbsp;Hacker-bees over at <a title="Linux for the Wii. Before WiiLi comes WiiLi Live, a Live CD that turns standard PCs into a media and gaming center designed around the Wii Remote." href="http://www.wiili.org/">wiili.org</a> are working away on this as we speak.&nbsp;Since it uses standard bluetooth to communicate, it&#8217;s entirely possible to use it on windows as an&nbsp;<a title="WiiMote mouse control" href="http://www.wiili.org/index.php/WiiMote_Mouse_Control_%28IR%21%29">infrared mouse pointer</a>, as a <a title="tranfer mii to online site with windows" href="http://wiihacks.blogspot.com/2006/12/howto-transfer-mii-from-your-wii-using.html">system to transfer your miis,</a> or as a <a title="video of someone using wiimote as ableton live controller" href="http://www.youtube.com/watch?v=8FftLxuYzRA&amp;eurl="><strong>midi drum machine</strong>.</a></p>
<p>I&#8217;m particularly interested in the idea of the wiimote as a controller for audio software, much like the link for the midi drum machine above.&nbsp;In my &#8217;spare&#8217; time (hah), I&#8217;ve been playing around with <a title="live audio sampling software" href="http://www.ableton.com/">Ableton Live</a>, audio software that allows you to do live sampling and looping. My end goal here is to supplement my band&#8217;s live performances with some tasteful instrument looping and ambient samples.&nbsp;I run my bass and a microphone through this software and can build up whole compositions in real time using loops (or at least that&#8217;s what I&#8217;m working towards mastering). </p>
<p>At some point I&#8217;d like to be able to use my wiimotes in this sort of live music performance venue. One problem with looping percussion instruments on stage is that the mic picks up background noise and degrades the quality.&nbsp;Using the wiimote as a shaker or virtual drumstick would allow you to avoid that ambient noise buildup, and still have the performance quality that crouching over your laptop on stage doesn&#8217;t convey. </p>
<p>The link for the wii drum machine above isn&#8217;t quite there: he&#8217;s just mapping buttons to certain drum samples, but he isn&#8217;t taking into account the velocity of the movement of the wiimote.&nbsp;Midi is not only an on/off signal, but also allows for &#8216;velocity&#8217;.&nbsp;That&#8217;s how an expensive electric piano will respond with different volume depending on how hard you strike the keys.&nbsp;Without taking into account the velocity of movement, you aren&#8217;t going to be able to duplicate realistic percussion.</p>
<p>Check out this video of someone actually <a title="wiimote ableton live controller" href="http://vids.myspace.com/index.cfm?fuseaction=vids.individual&amp;videoID=1550180797">using his wiimote as a controller for Ableton live</a>.&nbsp; This is really close to what I&#8217;m talking about, although he doesn&#8217;t provide any information on his approach. Note how by twisting and tilting&nbsp;the wiimote, he is shifting around the settings on an audio effect filter to make that modulation sound. </p>
<p>I actually have a usb gamepad hooked up to my laptop and have been using it as a controller for Ableton Live already.&nbsp;It works great, and running at $35 it is both way cheaper than dedicated midi controllers and has bonus novelty effect. I&#8217;m using a combination of&nbsp;<a title="Rejoice turns your Joystick or P5 Glove into a MIDI controller." href="http://www.fireballtrailers.com/rejoice/">Rejoice</a> and <a title="MIDI Yoke displays incoming MIDI streams, and passes the data to a MIDI output driver or the MIDI Mapper." href="http://www.midiox.com/">MIDI Yoke</a> for this (let me know if you would like more information on how that is done).&nbsp;</p>
<p>Unfortunately, it&#8217;s going to take some more time for me to get my Wiimote working: first I need to get a bluetooth adapter for my laptop! I&#8217;m sure by the time I do that, those wiili hacker-bees will have figured it all out.</p>
<p>On a related topic, someone has also done a great job making the <a title="Nintendo DS as midi controller" href="http://www.engadget.com/2006/11/27/nintendo-ds-doubles-as-wireless-midi-keyboard-controller/">Nintendo DS into a wireless midi controller</a>, although it requires some hard-to-find hardware to hack homebrew on to it.&nbsp;Check out the video on that page where he uses&nbsp;it as a&nbsp;virtual keyboard, and how he can &#8216;bend&#8217; notes like a guitar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dioramadesign.net/blog/using-the-wiimote-as-a-percussion-instrument/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MSBuild and Solution Files</title>
		<link>http://www.dioramadesign.net/blog/msbuild-and-solution-files/</link>
		<comments>http://www.dioramadesign.net/blog/msbuild-and-solution-files/#comments</comments>
		<pubDate>Thu, 30 Nov 2006 17:42:54 +0000</pubDate>
		<dc:creator>dmarks</dc:creator>
		
		<category><![CDATA[General Tech]]></category>

		<guid isPermaLink="false">http://www.dioramadesign.net/blog/msbuild-and-solution-files/</guid>
		<description><![CDATA[I find the vast majority of documentation on using MSBuild to compile Visual Studio solutions is way too complicated.&#160; MSBuild is very powerful, in that you can customize a lot of what is going on in the build process.&#160; However, sometimes you just want to do a simple compile of a visual studio solution in [...]]]></description>
			<content:encoded><![CDATA[<p>I find the vast majority of documentation on using MSBuild to compile Visual Studio solutions is way too complicated.&nbsp; MSBuild is very powerful, in that you can customize a lot of what is going on in the build process.&nbsp; However, sometimes you just want to do a simple compile of a visual studio solution in your msbuild script, without having to worry about reconstructing references and other such nonsense.&nbsp; It&#8217;s a one-liner task:</p>
<pre class="code"><span style="color: rgb(0,0,255)">    &lt;</span><span style="color: rgb(128,0,0)">MSBuild</span><span style="color: rgb(0,0,255)"> </span><span style="color: rgb(255,0,0)">Projects</span><span style="color: rgb(0,0,255)">=</span>&#8220;<span style="color: rgb(0,0,255)">MySolution.sln</span>&#8221;
<span style="color: rgb(0,0,255)">           </span><span style="color: rgb(255,0,0)">Properties</span><span style="color: rgb(0,0,255)">=</span>&#8220;<span style="color: rgb(0,0,255)">Configuration=Debug</span>&#8220;<span style="color: rgb(0,0,255)"> </span><span style="color: rgb(255,0,0)">ContinueOnError</span><span style="color: rgb(0,0,255)">=</span>&#8220;<span style="color: rgb(0,0,255)">false</span>&#8220;<span style="color: rgb(0,0,255)"> /&gt;</span></pre>
<pre class="code">&nbsp;</pre>
<p>I did a lot of research on MSBuild in the last month, and it was amazing just how long it took me to realise that MSBuild will parse .sln files for you.&nbsp; I guess it was just too obvious (in other words, it says it right there if you go <em>msbuild /? </em>). </p>
<p>You could do this from the command line as well instead of using devenv.exe:&nbsp; <br /><em><strong>msbuild mysolution.sln /p:Configuration=Release</strong></em></p>
<p>Solution files are not proper MSBuild scripts (unlike&nbsp;vbproj and csproj files), but MSBuild can still work with them.&nbsp;I recommend this <a title="Exporting .proj from solution files with msbuild" href="http://www.sedodream.com/PermaLink,guid,2a926fd2-70ce-4b95-a489-2d6aa24bc7da.aspx">excellent article by Sayed Ibrahim Hashimi</a> if you want to go a bit deeper into using the solution file in MSBuild.&nbsp; He talks about generating a proper .proj file from a solution file with a custom task, and then working with that for any other customization you require in your build process.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dioramadesign.net/blog/msbuild-and-solution-files/feed/</wfw:commentRss>
		</item>
		<item>
		<title>fun with the Firebug Extension</title>
		<link>http://www.dioramadesign.net/blog/fun-with-the-firebug-extension/</link>
		<comments>http://www.dioramadesign.net/blog/fun-with-the-firebug-extension/#comments</comments>
		<pubDate>Thu, 09 Nov 2006 21:05:04 +0000</pubDate>
		<dc:creator>dmarks</dc:creator>
		
		<category><![CDATA[General Tech]]></category>

		<guid isPermaLink="false">http://www.dioramadesign.net/blog/fun-with-the-firebug-extension/</guid>
		<description><![CDATA[The other day I came across an article called Hacking Web 2.0 Applications with Firefox. This is a fantastic article for two reasons: 

It emphasizes just how little you should be trusting any client-side validation for ensuring the security of your web application. In other words, don&#8217;t be trusting anything that is submitted to your [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I came across an article called <a title="This article looks at some of the methods, tools and tricks to dissect web 2.0 applications" href="http://www.securityfocus.com/infocus/1879/1">Hacking Web 2.0 Applications with Firefox</a>. This is a fantastic article for two reasons: </p>
<ol>
<li>It emphasizes just how little you should be trusting any client-side validation for ensuring the security of your web application. In other words, don&#8217;t be trusting anything that is submitted to your server-side&nbsp;just because you are doing it in a hidden ajax method or something.
<li>It highlights what I consider to be pretty much the most important tool in my web application toolbox: the <a title="firefox extension: web debugging evolved" href="http://www.joehewitt.com/software/firebug/">Firebug Extension for Firefox</a>. </li>
</ol>
<p>This tool is not only a debugger for javascript; it also allows you to completely dissect a page&#8217;s html structure, css and javascript in seconds.&nbsp; No more combing through <em>View Source</em> in order to figure out how a page is laid out, or trying to find what css is acting on what. Just hit F12 in firefox to open the Firebug panel and click the Inspect button.&nbsp; </p>
<p>There&#8217;s a <em>tonne</em> of things you can do with this extension, but go install it and come back here and I&#8217;ll show you a fun little trick.</p>
<p>Are you back?&nbsp; Ok, try this: click F12 to open the firebug panel and hit the inspect button.&nbsp; With this you can see the shape of all the DOM elements on this page. Actually click on an element and you can do things like browse through the html tree, view any css styles acting on it etc etc.</p>
<p><a href="http://www.dioramadesign.net/blog/wp-content/uploads/2006/11/WindowsLiveWriter/funwiththeFirebugExtension_C5FD/firebug_inspect%5B9%5D1.gif" atomicselection="true"><img height="233" alt="using firebug inspector" src="http://www.dioramadesign.net/blog/wp-content/uploads/2006/11/WindowsLiveWriter/funwiththeFirebugExtension_C5FD/firebug_inspect_thumb%5B5%5D1.gif" width="479"></a></p>
<p>Now you know what the html structure of the page looks like.&nbsp;Note the id for the top header of this page is called &#8216;header&#8217;.&nbsp;&nbsp;Now we&#8217;ll take advantage of the fact that this blog&nbsp;uses the <a title="it's about the user interface, baby!" href="http://script.aculo.us/">scriptaculous library</a>&nbsp;in order to make the header on this page disappear right in front of you.&nbsp; Click the Console tab in Firebug.&nbsp; At the bottom, you can enter in arbitrary javascript and it will run in the c