tag:blogger.com,1999:blog-38225557993291980302024-03-08T14:04:05.600+00:00Naeem KhedarunNeither completely public nor strictly private, coding related thoughts with varying degrees of usefulness...Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.comBlogger42125tag:blogger.com,1999:blog-3822555799329198030.post-39169802389388623342010-04-14T20:34:00.001+01:002010-04-14T20:34:47.716+01:00Moving Blog (Again)<p>I don’t particularly like the idea of switching blog (again), however I’ve decided to join a few of my close colleagues (whom I respect a great deal) in a blog conglomeration of sorts. You can find my personal posts here:</p> <p><a href="http://sharpfellows.com/author/naeemkhedarun.aspx">http://sharpfellows.com/author/naeemkhedarun.aspx</a></p> <p>And everyone’s posts here:</p> <p><a href="http://sharpfellows.com/">http://sharpfellows.com/</a></p> <p>I did initially want to cross post but decided it was additional blogging overhead that I didn’t want, I’m lazy enough as it is :-)</p> <p>If you are reading this, thanks a great deal for subscribing and I do hope you find the sharp fellows posts just as useful!</p> <p>Nym.</p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-83263903108563397812010-03-26T16:36:00.001+00:002010-03-27T14:05:30.057+00:00Slower than Reflection: Take Two<p>This is a hugely belated reply to: <a href="http://kozmic.pl/archive/2008/10/13/slower-than-reflection-meet-stacktrace.aspx">http://kozmic.pl/archive/2008/10/13/slower-than-reflection-meet-stacktrace.aspx</a></p> <p>I’m looking to perform some instrumentation on some already compiled code, and part of that involves getting a handle to a previous method. I wondered how slow accessing this through the StackTrace would actually be, and it turns out to be too slow according to that article.</p> <p>I was hoping that Kozmic’s approach to getting the entire stack trace before filtering was causing the massive performance hit, so I did some benchmarks of my own…</p> <pre class="brush: csharp;">Profile(() => new System.Diagnostics.StackTrace(false).GetFrame(1).GetMethod(), "Unfiltered StackFrame");<br /><br />Profile(() => new StackFrame(1, false).GetMethod(), "Filtered StackFrame");</pre>
<p>The unfiltered version is comparable to Kozmic’s example, and the filtered example is supposed to be more performant as we don’t need the entire stack trace. But the question is, “Is it faster?”. Let’s see:</p>
<p><a href="http://lh3.ggpht.com/_LKkDi4IUVKo/S6zidOIqvxI/AAAAAAAAAJ4/4xO40YWcZ9w/s1600-h/image%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_LKkDi4IUVKo/S6zieEcAyFI/AAAAAAAAAJ8/p7GeuNeNFfI/image_thumb.png?imgmax=800" width="244" height="79" /></a> </p>
<p>(Results in milliseconds)</p>
<p>Yes it is!  However, quite unfortunately it is still not performant enough for my purposes. If you want to try out your own benchmarks the code is: <a href="http://bitbucket.org/naeem.khedarun/stacktrace.experiments/">http://bitbucket.org/naeem.khedarun/stacktrace.experiments/</a></p>
<p>Cross posted to: <a href="http://sharpfellows.com/post/Slower-than-Reflection-Take-Two.aspx">#Fellows</a></p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-75346171776273782422010-03-24T23:46:00.001+00:002010-03-24T23:46:25.713+00:00Session downloader for MIX 2010<p>I’ve rehashed the session downloader to be able to download the Mix 2010 sessions just gone by.</p> <p>Thanks to <a href="http://sharpfellows.com/author/marcinkaluza.aspx">Marcin Kaluza</a> for helping out and giving the application some much needed design love.</p> <p><a href="http://lh3.ggpht.com/_LKkDi4IUVKo/S6qkSsFek8I/AAAAAAAAAJw/s1AgsKmZ74I/s1600-h/image%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_LKkDi4IUVKo/S6qkUHAyMAI/AAAAAAAAAJ0/XhFDrusDYpo/image_thumb.png?imgmax=800" width="244" height="196" /></a> </p> <p>As usual you can pick up the source at bitbucket: <a href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/">http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/</a></p> <p>And the download is now available via click-once: <a href="http://sharpfellows.com/SessionDownloader/publish.htm">http://sharpfellows.com/SessionDownloader/publish.htm</a></p> <p>Please let me know if you have any trouble with the application!</p> <p>Cross posted to: <a href="http://sharpfellows.com/post/Session-downloader-for-mix.aspx">#Fellows</a></p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-63151647826665945152009-12-11T14:29:00.001+00:002009-12-17T17:37:40.237+00:00Setting up and using KDiff in Visual Studio<p>One of the things that really sucks when using TFS is the integrated Diff and Merge tool which it ships with. I’ve tried out a few merge tools, and the one I was using previously was pretty good (I didn’t think a merge tool could get any better), and if you decide you don’t like KDiff then I would recommend giving it a try.</p> <p><a href="http://www.sourcegear.com/diffmerge/">http://www.sourcegear.com/diffmerge/</a></p> <p>Anyhow, a work mate recommended KDiff, initially I didn’t like the look of it. The user interface isn’t very inviting, if anything its rather intimidating. However once you get past its initial complexity its actually very simple and easy to use. Not to mention its quite powerful, and its three way merge algorithm is even more clever than TFS (its not hard tbh).</p> <p>First download and install KDiff: <a href="http://kdiff3.sourceforge.net/">http://kdiff3.sourceforge.net/</a></p> <p>Next let’s set up visual studio to use it instead of the built in one, for both diffing and merging.</p> <p><strong>Go to tools and options.</strong></p> <p><a href="http://lh6.ggpht.com/_LKkDi4IUVKo/SyJXOekSTSI/AAAAAAAAAJQ/e6uGonTD_rs/s1600-h/image%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_LKkDi4IUVKo/SyJXO0AteBI/AAAAAAAAAJU/uG7oGTw1jTM/image_thumb.png?imgmax=800" width="244" height="78" /></a> </p> <p><strong>Then select Source Control in the left pane, followed by the Visual Studio Foundation Server child item.</strong></p> <p><a href="http://lh3.ggpht.com/_LKkDi4IUVKo/SyJXPCa80mI/AAAAAAAAAJY/LiBAXiaFDlM/s1600-h/image%5B5%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_LKkDi4IUVKo/SyJXP2P4H2I/AAAAAAAAAJc/8fCAyfCOk3k/image_thumb%5B1%5D.png?imgmax=800" width="244" height="165" /></a> </p> <p><strong>Hit the configure User Tools button.</strong></p> <p><a href="http://lh5.ggpht.com/_LKkDi4IUVKo/SyJXQAFqWwI/AAAAAAAAAJg/Xz1gLCXZo-Q/s1600-h/image%5B8%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_LKkDi4IUVKo/SyJXQocKiPI/AAAAAAAAAJk/iejtDI7hFPY/image_thumb%5B2%5D.png?imgmax=800" width="244" height="80" /></a> </p> <p><strong>Hit the Add button, and setup your comparison tool with the following data:</strong></p> <p>Extension: .* <br />Operation: Compare <br />Command: <location>\kdiff3.exe <br />Arguments: %1 --fname %6 %2 --fname %7</p> <p><strong>Next setup your merging tool with the following data:</strong></p> Extension: .* <br />Operation: Merge <br />Command: <location>\kdiff3.exe <br />Arguments: %3 --fname %8 %2 --fname %7 %1 --fname %6 -o %4 <p><strong>Nice, you’ve setup KDiff as your default tool! The next post will outline some useful shortcuts and features.</strong></p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com2tag:blogger.com,1999:blog-3822555799329198030.post-71870479767376806862009-12-09T15:13:00.001+00:002009-12-10T13:22:01.032+00:00Finding the root of all evil<p>Recently I was trying to fix a bug on a project I’m currently on, however in trying to fix it I found another 2-3 issues which I deemed more critical so I was slightly side tracked.</p> <p>After fixing the other problems I returned to the bug I initially <i>wanted</i> to fix, only to find its already been fixed, great! Well it should have been.</p> <p>The bug in question is when clicking a button on one of our wpf screens. A <b>NullReferenceException </b>was being thrown when attempting to load a dialog. The mischievous piece of code was this:</p> <pre class="brush: csharp;">var startData = new ProductCodesDialog.StartData(hierarchicalCodeType)<br />{<br /> DefaultSearch = productCodes.Trim().FinderSplit()<br />};</pre>
<p>The problem? <b>productCodes </b>which is a string was null. This is fine and there’s probably nothing wrong with binding to null string values. But this piece of code was relying on the string being empty instead.</p>
<p>So the fix that I found nicely patched into place was the following:</p>
<pre class="brush: csharp;">if(string.IsNullOrEmpty(productCodes))<br />{<br /> productCodes = string.Empty;<br />}</pre>
<p>If something’s Null and we don’t want it to be null, then we just initialise it right? There was another piece of code in the actual textbox control which had something to say about that...</p>
<pre class="brush: csharp;">/*<br /> * This fix below is for a strange issue whereby deleting all<br /> * text in the textbox is not updating the source.<br /> */<br />if(Text != null && Text.Trim().Length == 0)<br /> Text = null;</pre>
<p>So this value is being constantly set to different values because dependant code is scared of throwing exceptions. Let’s take a look at what the value is initialised to so we have a starting point.</p>
<pre class="brush: csharp;">private String _value = String.Empty;</pre>
<p>So whoever created the base type <b>StringWithMatchType</b> designed it with String.Empty being the starting value, IMO we should probably respect that as a heap of functionality has been built on top of this.</p>
<p>So why is it being set to null in the control? Apparently the bound object is not getting updated when someone selects all the text and deletes it. So let’s see if it’s the case... *<b>a few minutes happened here</b>* and to cut a long story short it does appear to be the case. So the new question becomes:</p>
<p>Why doesn’t my binding update to string.Empty when the textbox text is deleted? After a bit of Googling I found this:</p>
<p><a href="http://jeffhandley.com/archive/2008/07/09/binding-to-nullable-values-in-xaml.aspx">http://jeffhandley.com/archive/2008/07/09/binding-to-nullable-values-in-xaml.aspx</a></p>
<p>So WPF is being carful not to null a bound property, not the ideal behaviour in this case. Ideally we want a string.Empty but perhaps WPF can’t be sure of what to do. Never-the-less luckily we are using .NET 3.5 SP1, and with that comes a handy binding property by the name of TargetNullValue</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.targetnullvalue.aspx">http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.targetnullvalue.aspx</a></p>
<p>So while this issue doesn’t affect the code above, as it’s binding to a string and does correctly propagate a string.Empty, it does affect some other places we are using the same custom textbox control. Wherever we are binding to Nullable<T> values seems to be affected, whether WPF doesn’t update the bound object when the textbox is emptied. I can only assume it was for this case the Text property on the custom control was being nulled. Using the TargetNullValue we are able to get around this:</p>
<pre class="brush: xml;">WPFControls:TextBoxWatermark Text="{Binding Path=Value,TargetNullValue={x:Static System:String.Empty},UpdateSourceTrigger=PropertyChanged}"</pre>
<p>And when retesting this the Nullable property is correctly being set to null when the textbox is emptied.</p>
<p>A dash of curiosity coupled with an inquisitive nature and a distaste for quick hacks seems to have got this problem resolved in quite a satisfactory manner!</p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-56930174782964208942009-12-08T11:41:00.001+00:002009-12-08T16:45:27.423+00:00Regex.IsMatch always returning true?<p>The following code was failing:</p> <pre class="brush: csharp;">[TestMethod]<br />public void ShouldNotMatchInvalidCharacters()<br />{<br /> Regex regex = null;<br /> string invalidString = null;<br /> bool result = false;<br /><br /> Story.WithScenario("matching invalid characters")<br /> .Given("a regex expression",<br /> () => regex = new Regex(@"[0-9]*\.{0,1}[0-9]*"))<br /> .And("an invalid string",<br /> ()=> invalidString = "a")<br /> .When("we check whether we have a match",<br /> () => result = regex.IsMatch(invalidString))<br /> .Then("the match should fail",<br /> () => Assert.IsFalse(result));<br />}</pre>
<p>It turns out it was matching on the empty string. I couldn’t think why on earth it was doing this. A bit of googling and the correct way to match on an entire string is to specify the start and end of the string in the regex.</p>
<p><font color="#ff0000">^</font>[0-9]*\.{0,1}[0-9]*<font color="#ff0000">$</font></p>
<p><font color="#000000">The test now goes green!</font></p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-30955985085359840102009-12-07T11:16:00.001+00:002009-12-07T11:16:18.919+00:00PDC Downloader FileNotFoundException – Update 6<p>Big thanks to Sam for diagnosing and suggesting how to fix this one. It turns out System.Threading (Parallel Tasks Library) was not being copied in as a referenced assembly, I thought it was.</p> <p>Anyhow – in the usual fashion, there's a new version:</p> <p><a title="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_6.zip" href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_6.zip">download</a></p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-80882517463638168652009-12-04T11:49:00.001+00:002009-12-04T11:49:03.773+00:00Getting things right the first time round<p>After releasing the PDC downloader application I have learned quite a few things the hard way. Releasing <strong>any</strong> software, be it open source, free or with a limited target audience comes with the same strings attached as any software.</p> <p>For this tool I wanted the code base to be nice, feature set to be just enough, to be well tested and to learn a few things on the way. In this way it turned out to be a great success, but in trying to keep things lightweight and push versions out early I made some critical errors.</p> <ol> <li>Do not underestimate the usefulness of automatic updates. No matter how small the application, you always want to keep your user base up to date. Even if the updates are tiny and incremental, reaching everyone that has already downloaded a previous version is <u>vital</u>. There will come a time when something show stopping happens, and its a pain for your users to have to manually get an up to date version. In this respect, I really wish I employed the use of something like <a href="http://msdn.microsoft.com/en-us/library/t71a733d(VS.80).aspx">ClickOnce</a> from the start!</li> <li>When I hacked the UI together, I wanted it to be functional so I didn’t mind having a basic UI. But to be honest the UI was too basic, which actually made it less functional than I intended. A few hours in blend would have easily rectified this which is another thing I wish I did from the start.</li> <li>And finally error reporting. It’s fine to set up a log file so all exceptions are logged <em>somewhere</em>. But this isn’t much use to users who just want to download something and have it work. Something simple like making it easier for users to email an exception is something which should have been there from the very beginning.</li> </ol> <p>I really hope I won’t make these mistakes in the future.</p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-19857798903741571042009-12-04T11:20:00.001+00:002009-12-04T11:50:00.457+00:00Putting it together series – Part 2: IoC Container (Castle.Windsor and Fluent Castle)<p><strong>Introduction</strong></p> <p>Whenever I need to put even a simple application together there’s always a whole bunch of infrastructure I need to put in place. For a WPF application this <em>can</em> include:</p> <ul> <li>IoC Container </li> <li>Testing Framework </li> <li>MVP / MVVM Framework </li> <li>Logging </li> <li>ORM </li> </ul> <p>This was recently the case when putting together the PDC downloader.  So I’m going to put a quick post around each of these areas. Besides the UI Framework everything else should convert over to ASP.NET without too much difficulty.</p> <p>There is going no be no real example as I don’t want to complicate the solutions. Each solution will contain the minimum code to get the relevant area up and running, with the smallest example I can give. Once you have things going, Google will provide more advanced help.</p> <p><strong>Part 2: IoC Container</strong></p> <p>So we have our testing framework in place, the next step is to put in our IoC Container so we can dependency inject domain services in our business objects, or UI services into our UI objects. If you want to know more about what <a href="http://en.wikipedia.org/wiki/Inversion_of_control">IoC</a> and <a href="http://en.wikipedia.org/wiki/Dependency_injection">DI</a> is there is a host of information explaining the technology and how to use it. This guide will be around setting up one of my preferred containers and integrating it with the tests we already have.</p> <p>The container in question is <a href="http://www.castleproject.org/container/index.html">Castle.Windsor</a> which IMO is one of the more powerful and configurable containers available. It has good performance and is easily extensible offering some powerful extension points. It is also one of the more popular containers offering great documentation (both on the official site and by 3rd party bloggers), as well as lots of adaptors to plug it into various other frameworks.</p> <p>So let’s get started, we really want to use the latest code and the easiest place to get it is here:</p> <p><a href="http://hornget.net/">http://hornget.net/</a></p> <p>Clicking on IoC gives us access to the latest build of the Castle.Windsor trunk, exactly what we need! We’ll need to set up the following referenced assemblies in our solution:</p> <p><a href="http://lh4.ggpht.com/_LKkDi4IUVKo/Sxjwb6DcxjI/AAAAAAAAAJI/fTuDJGmV620/s1600-h/image%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_LKkDi4IUVKo/SxjwccnVY3I/AAAAAAAAAJM/5LIL0bDbWzM/image_thumb.png?imgmax=800" width="208" height="98" /></a> </p> <p>Now we already have an entity from the last example called SillyPoco, and a service which its dependent on called ISillyService. So what we want to do is create a concrete SillyServiceImpl and inject that into our SillyPoco object.</p> <p>We’ll start with a test:</p> <pre class="brush: csharp;">[TestMethod]<br />public void ShouldInjectSillyServiceIntoMyObject()<br />{<br /> SillyPoco sillyPOCO = null;<br /> bool result = false;<br /><br /> Story.WithScenario("a plain old nbehave spec")<br /> .Given("an object we are going to test",<br /> () => sillyPOCO = FrameworkHelper.New<SillyPoco>())<br /> .When("we call a method on the object",<br /> () => result = sillyPOCO.TalkToService())<br /> .Then("the service should have been called",<br /> () => Assert.IsTrue(result));<br />}</pre>
<p>So we’ve made the service contract return a boolean, and we are checking that it should return true. We’ve also got a static helped method called FrameworkHelper.New<T> which will create our object that needs to have dependencies injected. Here’s how it looks:</p>
<pre class="brush: csharp;">public static T New<T>()<br />{<br /> return Container.Resolve<T>();<br />}</pre>
<p>That looks good, this is how we will ask the container for instances of our dependency injected objects. This is a simple implementation of the ServiceLocator, for something more advanced I would recommend: <a href="http://commonservicelocator.codeplex.com/">CommonServiceLocator</a> which Castle.Windsor is compatible with.</p>
<p>So we have a method to get our objects, let’s setup the container. Since we are in a test project we should probably refactor the setup into a test base class to be shared throughout the tests.</p>
<p></p>
<pre class="brush: csharp;">protected override void Establish_context()<br />{<br /> base.Establish_context();<br /><br /> WindsorContainer windsorContainer = new WindsorContainer();<br /> windsorContainer.Register(<br /> Component.For<ISillyService>().ImplementedBy<SillyService>(),<br /> Component.For<SillyPoco>().ImplementedBy<SillyPoco>());<br /><br /> FrameworkHelper.Initialize(windsorContainer);<br />}</pre>
<p>We've now set up our container. Essentially what we’ve told it is:</p>
<ul>
<li>If anyone asks you for a ISillyService, return a new instance of SillyService </li>
<li>If anyone asks you for a SillyPoco, return a new SillyPoco and insert a new instance of ISillyService into it. </li>
</ul>
<p>So now when we run our test it goes green! Now we have our container set up, it will start getting much easier to put our application together!</p>
<p>You can find the code for the examples at the bitbucket repo:</p>
<p><a href="http://bitbucket.org/naeem.khedarun/projectpit/overview/">http://bitbucket.org/naeem.khedarun/projectpit/overview/</a></p>
<p>The samples for this part are under a tag called <strong>parttwo. </strong>Simply get the repository and update to that tag.</p> Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-10957491830483283382009-12-02T15:46:00.002+00:002009-12-03T09:58:40.400+00:00PDC Downloader – Major Bug Fix<p>Unfortunately the PDC Sessions file the application was using had some corrupted session codes, which meant these sessions could not actually be downloaded. A work mate of mine (Robin Prosch) luckily brought it to my attention (Thanks!). </p><p><a href="http://lh4.ggpht.com/_LKkDi4IUVKo/SxaL0LilCHI/AAAAAAAAAJA/OJ1SYnXi2HQ/s1600-h/image%5B5%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_LKkDi4IUVKo/SxaL0m1ETII/AAAAAAAAAJE/rXLLWJq9SiQ/image_thumb%5B1%5D.png?imgmax=800" width="244" height="18" /></a> </p><p>In order to side step this, the application goes to <a href="http://micrsoftpdc.com/videos">http://micrsoftpdc.com/videos</a> to get the available sessions and the downloads should now work correctly. I highly recommend getting this update if you want to download any of the affected sessions (there are quite a few!).</p><p>The application start up time has taken a couple of seconds hit but its well worth it for getting an up to date list of sessions (and correct!), although I don’t think its likely to change at this point.</p><p>Sincere apologies for this one, I wish I’d spotted it sooner!</p><p><a title="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_5.zip" href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_5.zip">download</a></p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com5tag:blogger.com,1999:blog-3822555799329198030.post-42344726214032361262009-11-30T10:21:00.002+00:002009-12-03T09:58:27.038+00:00Putting it together series – Part 1: Testing Framework (NBehave, Rhino.Mocks)<p><strong>Introduction</strong></p><p>Whenever I need to put even a simple application together there’s always a whole bunch of infrastructure I need to put in place. For a WPF application this <em>can</em> include:</p><ul><li>IoC Container </li>
<li>Testing Framework </li>
<li>MVP / MVVM Framework </li>
<li>Logging </li>
<li>ORM </li>
</ul><p>This was recently the case when putting together the PDC downloader.  So I’m going to put a quick post around each of these areas. Besides the UI Framework everything else should convert over to ASP.NET without too much difficulty.</p><p>There is going no be no real example as I don’t want to complicate the solutions. Each solution will contain the minimum code to get the relevant area up and running, with the smallest example I can give. Once you have things going, Google will provide more advanced help.</p><p><strong>Part 1: Testing Framework</strong></p><p>The first think I end up needing in any solution is a testing framework, and currently my framework of choice is NBehave, a superb framework for writing any tests be it TDD or BDD.</p><p><a href="http://nbehave.org/">http://nbehave.org/</a></p><p>In my case I’m using MSTest; I prefer Gallio/MBUnit but they current don’t work so well in VS2010. In any case, after creating a new C# project your referenced assemblies should look something like this:</p><p><a href="http://lh6.ggpht.com/_LKkDi4IUVKo/SxOcl9PPRQI/AAAAAAAAAII/UFN3LjqVlsY/s1600-h/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_LKkDi4IUVKo/SxOcmnM3TBI/AAAAAAAAAIM/N6WDl5qBAWw/image_thumb.png?imgmax=800" width="244" height="147" /></a> </p><p>So we are ready to put together our first spec! The example will contain a little bit of rhino mocks to show the integration NBehave has put around it.</p><p>So let’s write our first BDD Story.</p><pre class="brush: csharp;">protected override void Establish_context()
{
this.Story = new Story("writing our first nbehave spec");
this.Story
.AsA("person new to nbehave")
.IWant("a simple example")
.SoThat("I can better understand how to use it");
}</pre><p>This story doesn’t actually do anything, however if we ran the NBehave tool we would have that output together with the scenarios. This way when a test fails, you know exactly which business functionality has been affected.</p><pre class="brush: csharp;">[TestMethod]
public void APlainOldNBehaveSpec()
{
SillyPOCO sillyPOCO = null;
string junglegon = "Junglegon";
Story.WithScenario("a plain old nbehave spec")
.Given("an object we are going to test",
()=> sillyPOCO = new SillyPOCO())
.When("we set a property on that object",
()=> sillyPOCO.Name = junglegon)
.Then("we should have changed that object",
()=> Assert.AreEqual(junglegon, sillyPOCO.Name));
}</pre><p>There’s our first NBehave specification. It’s pretty straightforward, and I particularly like how easy it is to read when the Given, When and Then clauses are accompanied by a well written scenario. You might ask whether or not this why of testing scales when testing complicated business functionality or frameworks, and I can say it does. Even better than just working, it forces you to improve the quality of your test code to make it more readable and less bulky which is what my workmates and myself experienced on our current project.</p><p>Anyhow, let’s take a look at testing with rhino mocks, we are going to add some pointless dependacy properties to out silly object to test the interactions using mocks.</p><pre class="brush: csharp;">[TestMethod]
public void AnNBehaveSpecWithMocking()
{
SillyPOCO sillyPOCO = null;
Story.WithScenario("a plain old nbehave spec")
.Given("an object we are going to test",
() => sillyPOCO = new SillyPOCO())
.And("the object has a silly service",
()=> sillyPOCO.SillyService = CreateDependency<ISillyService>())
.When("we call a method on the object",
()=> sillyPOCO.TalkToService())
.Then("the service should have been called",
()=> sillyPOCO.SillyService.AssertWasCalled(service => service.Chatter()));
}</pre><p>NBehave provides a CreateDependency method as a wrapper for creating a mocks. When making your expects and asserts, you can use the rhino mocks extension methods as a simple of way checking things happened the way you expected.</p><p>You can find the code for the examples at the bitbucket repo:</p><p><a href="http://bitbucket.org/naeem.khedarun/projectpit/overview/">http://bitbucket.org/naeem.khedarun/projectpit/overview/</a></p><p>The samples for this part are under a tag called <strong>partone</strong>. Simply get the repository and update to that tag.</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-453305616310184672009-11-27T15:02:00.002+00:002009-12-03T09:57:57.392+00:00New balloon tip notifications for PDC Downloader<p><a href="http://lh4.ggpht.com/_LKkDi4IUVKo/Sw_qCW1PmvI/AAAAAAAAAIA/A4pp9D4dgSA/s1600-h/image%5B2%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_LKkDi4IUVKo/Sw_qCjdH36I/AAAAAAAAAIE/rgJNBk8prys/image_thumb.png?imgmax=800" width="244" height="90" /></a> </p><p>There are balloon tips for starting and finishing downloads. There is also one if the download errors for whatever reason, in which case mail me the log file!</p><p><a title="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_4.zip" href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_4.zip">download</a></p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-7374761492299508422009-11-27T14:08:00.002+00:002009-12-03T09:57:44.165+00:00New version of PDC Downloader<p>Incremental improvements this time based on requests.</p><ul><li>Now logs all exceptions to a log file in Logs/<date-time>.log. If you have any problems just email this log to me and I’ll take a look and push out a new version with fixes.</li>
<li>Removes failed downloads from the download queue so you can try and re-download.</li>
</ul><p><a title="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_3.zip" href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_3.zip">download</a></p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-18649804717854488472009-11-25T20:10:00.002+00:002009-12-03T09:57:32.087+00:00PDC Session Downloader Resuming is now fixed…<p><a title="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_2.zip" href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_2.zip">download</a></p><p>I hope so anyway…</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-77288869602814512512009-11-25T19:57:00.002+00:002009-12-03T09:57:21.204+00:00PDC Session Downloader resume functionality<p>Seems to be broken… I’ll try and have it fixed by tomorrow.</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-13831115788550296122009-11-25T19:44:00.002+00:002009-12-03T09:57:07.995+00:00Update to PDC Session Downloader<p>Based on some requests I’ve updated the application. </p><p>Changes:</p><ul><li>Updated application to work with full sessions list so you can download all available sessions</li>
<li>Added ability to resume broken downloads. </li>
<li>Added ability to download sessions with strange characters in the description.</li>
</ul><p>The repository has been updated with the changes, and a new download link.</p><p><a title="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_1.zip" href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_1.zip">download</a></p><p>Enjoy!</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-17497871645122515952009-11-25T15:07:00.002+00:002009-12-03T09:56:58.419+00:00Doh! PDC Downloader<p>It looks like frank has updated his XML file (which my application uses) with some new sessions. Luckily the XML structure is abstracted away using a stylesheet tranform. I’ll update the application with the new file this evening.</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com1tag:blogger.com,1999:blog-3822555799329198030.post-6554913068085083672009-11-25T14:52:00.003+00:002009-12-03T09:56:49.090+00:00PDC 2009 Session Downloader<p>So PDC 2009 is all wrapped up and for those of us not lucky enough to attend, we still have the sessions which are available on the PDC site <a href="http://microsoftpdc.com/">http://microsoftpdc.com/</a>.</p><p>This would have normally been enough for me, however Frank (<a href="http://www.franksworld.com/">http://www.franksworld.com/</a>) was nice enough to provide a small utility to automatically download the sessions. The utility does work, but it did leave something to be desired (A non blocking UI, ability to choose sessions, etc…) so my OCD kicked in and I just had to do something.</p><p>I’ve built a little application which let’s you choose which sessions you want to download, and provide a way to see each downloads progress.</p><p><a href="http://lh6.ggpht.com/_LKkDi4IUVKo/Sw1EWYEbDsI/AAAAAAAAAHw/cLwLNQx6SL8/s1600-h/image%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_LKkDi4IUVKo/Sw1EXNZu3kI/AAAAAAAAAH0/ursRXSZqngc/image_thumb.png?imgmax=800" width="244" height="209" /></a> </p><p><a href="http://lh3.ggpht.com/_LKkDi4IUVKo/Sw1EXsYPIxI/AAAAAAAAAH4/YuzWtOKwuCU/s1600-h/image%5B5%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_LKkDi4IUVKo/Sw1EYTRgKzI/AAAAAAAAAH8/TUoSpTotNdU/image_thumb%5B1%5D.png?imgmax=800" width="244" height="209" /></a> </p><p></p><p>It wasn’t bad for a few hours work, however there’s some nice technology backing it and it’s a fun little solution to try new things inside.</p><p>You can find the full source code on bitbucket: <a href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/overview/">http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/overview/</a></p><p>It’s built using Visual Studio 2010 (Beta 2), and you’ll find inside some examples of using:</p><ul><li>Parallel task library </li>
<li>WPF </li>
<li>NBehave (BDD) Specifications </li>
<li>Caliburn / Prism </li>
<li>Windsor IoC with Fluent Configuration </li>
<li>Xslt Transforms / DataContract serialising </li>
</ul><p>There’s a few more things I plan to add, but so far I’ve got it downloading my sessions and that’s keeping me happy for now. If you do make any modifications feel to fork it on bitbucket and I’ll merge the changes in.</p><p>* Update new version*</p><p><a title="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_2.zip" href="http://bitbucket.org/naeem.khedarun/fancypcddownloader2009/downloads/FancyPDCDownloader2009Binaries_update_2.zip">download</a></p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com2tag:blogger.com,1999:blog-3822555799329198030.post-5984068750135198132009-11-11T13:14:00.002+00:002009-12-03T09:56:09.921+00:00Building a package management framework<p>One of the open source projects I’m currently working on is PiXI which you can learn more about <a href="http://pixidev.blogspot.com/2009/11/pixi-project-resources.html">here</a>.</p><p>The project is essentially a framework which allows plug-ins to be added using MEF and MAF loaded out of a few plug-in directories. So writing a new plug-in for the framework is incredibly easy (I think…), however pushing plug-ins to users is still a real pain.</p><p>The current process would be:</p><ol><li>Create a WiX installer for your plug-in which deploys everything into the appropriate directories.</li>
<li>Upload the plug-in somewhere.</li>
<li>User downloads the plug-in from somewhere</li>
<li>User installs it via the installer (which normally contains prompts and isn’t a background operation).</li>
</ol><p>This is less than idea, in both distribution and developer effort, so moving to a new model is a good idea. And since MEF is really kicking off now a framework to more easily facilitate this process wouldn’t go amiss.</p><p>I would like this to follow a more unix like approach using the idea of packages. This is all available in Linux on more recently on smart phones however windows is greatly lagging behind in this respect. My current thinking for this process is split into three main areas:</p><p><a href="http://lh6.ggpht.com/_LKkDi4IUVKo/Svq4vz0g0GI/AAAAAAAAAHo/h1WKRZ_QzDY/s1600-h/image%5B2%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_LKkDi4IUVKo/Svq4wWl8AAI/AAAAAAAAAHs/97VESVMe_As/image_thumb.png?imgmax=800" width="211" height="244" /></a> </p><p>The NPackageManager suite is a combination of tools, API’s and applications to allow for some flexibility in this process. </p><ul><li>BUILD – This is aimed towards plug-in developers who need an easy means of packaging and deploying plug-ins. Currently NPackageManager contains a command line tool to package up a solution together with a package definition, similar to many Linux repo systems.</li>
<li>INSTALL – This is targeted towards the target application which needs to consume the plug-ins. Target applications need an easy way to setup the ability to consume generated packages and register associations in the registry. For all intents and purposed discovery of new plug-ins is left to the actual technology employed, for example MEF will take care of the integration aspect.</li>
<li>UNINSTALL – Again targeted towards the target application, a simple API to uninstall from a list of installed plug-ins should be provided (not there yet). This means an application can expose the functionality to the user without having to hand crank the un-installation code which should normally be similar between projects.</li>
</ul><p>I’ve made a start on this (basically enough to move my own project forward) and will be blogging about improvements to this as time goes on.</p><p><a href="http://bitbucket.org/naeem.khedarun/npackagemanager/">http://bitbucket.org/naeem.khedarun/npackagemanager/</a></p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-76486379206979260942009-11-11T12:58:00.002+00:002009-12-03T09:55:46.292+00:00Using the configuration section designer<p>There’s an awesome tool which one of my work mates showed me called the Configuration Section Designer. It’s an open source project and be found on Codeplex <a href="http://www.codeplex.com/csd">here</a>. </p><p>It really beats hand cranking a custom configuration and generates a nice API for using your new configuration section.</p><p>After installing it, it’s simple to add a new configuration.</p><p><a href="http://lh6.ggpht.com/_LKkDi4IUVKo/Svq06BvjGWI/AAAAAAAAAGw/FC4Ezo80X3k/s1600-h/image%5B2%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_LKkDi4IUVKo/Svq06oT6NuI/AAAAAAAAAG0/7ZUeq49cRWo/image_thumb.png?imgmax=800" width="244" height="156" /></a> </p><p>This will split out a bunch of generated files, in my case:</p><p><a href="http://lh3.ggpht.com/_LKkDi4IUVKo/Svq07Aes9oI/AAAAAAAAAG4/mn-TwtoeFZ0/s1600-h/image%5B5%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_LKkDi4IUVKo/Svq07hWAWnI/AAAAAAAAAG8/D1qXDemwZNg/image_thumb%5B1%5D.png?imgmax=800" width="244" height="132" /></a> </p><p>The one we are interested in is the .csd file, which is where we go to edit the configuration section using the designer. So let’s open that one up, and we get a nice designer with some logical toolbox items:</p><p><a href="http://lh4.ggpht.com/_LKkDi4IUVKo/Svq08NdZrII/AAAAAAAAAHA/nEQfikEg15Y/s1600-h/image%5B8%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_LKkDi4IUVKo/Svq083fNqDI/AAAAAAAAAHE/ykubDBkWyYg/image_thumb%5B2%5D.png?imgmax=800" width="244" height="214" /></a> </p><p>I’ve created my custom configuration section with a single attribute called installationRoot:</p><p><a href="http://lh4.ggpht.com/_LKkDi4IUVKo/Svq09BhpzqI/AAAAAAAAAHI/O0nVuqvqO7g/s1600-h/image%5B11%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_LKkDi4IUVKo/Svq09iJPPBI/AAAAAAAAAHM/atXdSTtZ_QQ/image_thumb%5B3%5D.png?imgmax=800" width="244" height="143" /></a> </p><p>When you try and save, the CSD attempts to validate your configuration section, and errors will appear in the usual visual studio error box:</p><p><a href="http://lh4.ggpht.com/_LKkDi4IUVKo/Svq0-E5puMI/AAAAAAAAAHQ/sKA_XM2Mxnk/s1600-h/image%5B14%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_LKkDi4IUVKo/Svq0-mHwxjI/AAAAAAAAAHU/eKMtOaluQ1M/image_thumb%5B4%5D.png?imgmax=800" width="244" height="77" /></a> </p><p>It will want you to give the namespaces for where you want the generated files to go, in my case I used their physical location in the solution so everything matches. You can edit namespaces and xml namespaces as well as types for the attributes and everything else in the properties box.</p><p><a href="http://lh4.ggpht.com/_LKkDi4IUVKo/Svq0_OOhCPI/AAAAAAAAAHY/_tjf8CgWTC8/s1600-h/image%5B17%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_LKkDi4IUVKo/Svq0_vEpkII/AAAAAAAAAHc/Scfz2dl8kdc/image_thumb%5B5%5D.png?imgmax=800" width="244" height="111" /></a> </p><p>It’s all quite logical and straightforward to use. It really comes in handy when you start putting together complex configuration sections and realise you have <strong>no</strong> code to write:</p><p><a href="http://lh5.ggpht.com/_LKkDi4IUVKo/Svq1AVe9vRI/AAAAAAAAAHg/SPChlvPoKqQ/s1600-h/image%5B20%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_LKkDi4IUVKo/Svq1A_ZBeYI/AAAAAAAAAHk/ufhLtyqBqvI/image_thumb%5B6%5D.png?imgmax=800" width="244" height="163" /></a> </p><p>Consuming the generated API is also very straightforward:</p><pre class="brush: csharp;">[Test]
public void Create_WithValidConfiguration_HydratesStructureConfigurationObject()
{
Structure structure = NPkgConfiguration.Instance.structure;
Assert.AreEqual("package", structure.packageRoot, "Failed to hydrate correctly.");
Assert.AreEqual("installation", structure.installationRoot, "Failed to hydrate correctly.");
Assert.AreEqual("source", structure.sourceRoot, "Failed to hydrate correctly.");
Assert.AreEqual("document", structure.documentRoot, "Failed to hydrate correctly.");
}</pre><p>Hope you enjoy using it!</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-42780721430956818962009-10-01T21:54:00.002+01:002009-12-03T09:55:23.766+00:00Using Mercurial with TFS – Read Only files<p>After having used mercurial on a project, going back to TFS was slightly depressing. However I did stumble upon this <a href="http://www.stereoplex.com/two-voices/tfs-and-mercurial">post</a> which shows how you can use mercurial to fill in some of the TFS gaps around working offline.</p><p>If you working on a particularly large piece and don’t want to go through the pain of a TFS branch, being able to commit to a local repository frequently and take advantage of mercurials merge algorithms when committing to older revisions is incredibly useful – anyway I digress.</p><p>The post outlined above seems to have omitted the way TFS tracks changes against files using the read-only file system flag. So when you attempt to update you ‘tracking’ workspace with a bunch of new changes mercurial will be unable to update the read-only files.</p><p>If you attempt to make all the project files writable, TFS will pick up changes against files even when they have no differences with the workspace version.</p><p>Luckily there is a handy mercurial extension called MakeWritableExtension which will make read-only files writable if it tries to make changes to them.</p><p><a href="http://mercurial.selenic.com/wiki/MakewritableExtension">http://mercurial.selenic.com/wiki/MakewritableExtension</a></p><p>If like me your using TortoiseHg, either update the Mercurial.ini in the TortoiseHg folder or in your local user folder. I added the following lines to C:\Program Files\TortoiseHg\Mercurial.ini</p><pre>[extensions]
makewritable = C:/makewritable.py</pre><p>And then copied the python file in the link above in my C drive (because I’m lazy). Whenever mercurial tries to update a read-only file you will get:</p><pre><a href="http://lh6.ggpht.com/_LKkDi4IUVKo/SsUXGdIzKUI/AAAAAAAAADQ/G-qq1Kekxps/s1600-h/image%5B2%5D.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_LKkDi4IUVKo/SsUXG-vqNzI/AAAAAAAAADU/BENsSBfD_YM/image_thumb.png?imgmax=800" width="244" height="34" /></a> </pre><p>Now it will automatically set the edited files to writable thus doing a TFS checkout and making life a *lot* easier.</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com3tag:blogger.com,1999:blog-3822555799329198030.post-21703250851508880332009-09-24T17:20:00.002+01:002009-12-03T09:54:56.842+00:00An invalid or incomplete configuration was used while creating a SessionFactory<p>If like me your also getting this error when using the lastest FluentNHibernate binaries you might want to try building the lastest code from source.</p><p><a href="http://code.google.com/p/fluent-nhibernate/source/checkout">http://code.google.com/p/fluent-nhibernate/source/checkout</a></p><p>Using the lastest cut of the code has resolved this issue for me…</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-47627234401352741892009-09-08T10:41:00.002+01:002009-12-03T09:54:38.779+00:00Clearing Visual Studio Memory Consumption With A Macro<p>Recently one of my work mates sent an email round the development community saying that:</p><p><em>If your visual studio is taking up too much memory then you can run an empty visual studio macro to reduce its foot print.</em></p><p>Some evidence was provided via task manager which showed VS taking over 1gb of memory before the macro was run, and only a few megabytes afterwards.</p><p>You may call me a sceptic but I immediately called foul, thinking it was impossible. I decided to try it myself just to see if it was a complete lie.</p><p>Before</p><p><a href="http://lh5.ggpht.com/_LKkDi4IUVKo/SqYmymCk6zI/AAAAAAAAADA/ESuRkcaCDUQ/s1600-h/before%5B2%5D.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="before" border="0" alt="before" src="http://lh6.ggpht.com/_LKkDi4IUVKo/SqYmy7uoePI/AAAAAAAAADE/k_Gb3B1-lDk/before_thumb.jpg?imgmax=800" width="244" height="167" /></a></p><p>After</p><p><a href="http://lh6.ggpht.com/_LKkDi4IUVKo/SqYmzYm6oJI/AAAAAAAAADI/GfLvR5-yyQw/s1600-h/after%5B2%5D.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="after" border="0" alt="after" src="http://lh3.ggpht.com/_LKkDi4IUVKo/SqYmzupCahI/AAAAAAAAADM/ZLK5APSX_xs/after_thumb.jpg?imgmax=800" width="244" height="167" /></a> </p><p>Wow, devenv.exe has had its private memory (which is the value reported by Task Manager) reduced from 1.3gb to a mere 26mb. So my workmate wasn’t completely wrong. But taking a look at some of the other values shows the results are less promising. So I wanted to know what exactly each of those memory columns mean. Stack Overflow had an answer, the below is copied from <a href="http://stackoverflow.com/questions/1170654/how-to-interpret-windows-task-manager/1170741#1170741">here</a>:</p><p><a href="http://blogs.msdn.com/salvapatuel/archive/2007/10/13/memory-working-set-explored.aspx">Working set</a>:</p><blockquote><p>Working set is the subset of virtual pages that are resident in physical memory only; this will be a partial amount of pages from that process.</p></blockquote><p><a href="http://cybernetnews.com/cybernotes-windows-memory-usage-explained/">Private working set</a>:</p><blockquote><p>The private working set is the amount of memory used by a process that cannot be shared among other processes</p></blockquote><p><a href="http://windowshelp.microsoft.com/Windows/en-us/help/d119bbe6-f604-4eb1-9c75-bbbc45cce1da1033.mspx">Commit size</a>:</p><blockquote><p>Amount of <a href="http://windowshelp.microsoft.com/Windows/en-US/Help/fd3e9104-1076-4600-9f9d-8739849387ec1033.mspx">virtual memory</a> that is reserved for use by a process.</p></blockquote><p>And at <a href="http://windowshelp.microsoft.com/Windows/en-us/help/d119bbe6-f604-4eb1-9c75-bbbc45cce1da1033.mspx">microsoft.com</a> you can find more details about other memory types.</p><p>So it looks like the working set and private set have been cleared down, but all of VSs process data is still in the virtual memory. So its my understanding that you are probably making VS slower since when VS needs some of that data, there is a higher chance of it hitting the pagefile. If your low on memory and need to use other applications then this would have been a good idea had it not been for the fact windows will probably automatically do this for you anyway.</p><p>Is this a myth busted or have I misunderstood something?</p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com2tag:blogger.com,1999:blog-3822555799329198030.post-83739546907790822332009-05-27T11:57:00.008+01:002009-12-03T09:54:02.549+00:00An exception was thrown while exploring tests. Gallio.I was getting the below exception constantly while trying to run some unit tests in our solution. <br />
<pre class="brush:csharp">[error] An exception was thrown while exploring tests.
Location: C:\x\Solutions\x.Web.Controllers\bin\Debug\x.Web.Controllers.DLL
Reference: x.Web.Controllers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark)
at System.Reflection.Assembly.GetTypes()
at Gallio.Reflection.Impl.NativeAssemblyWrapper.GetTypes() in c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Reflection\Impl\NativeAssemblyWrapper.cs:line 72
at Gallio.Framework.Pattern.TestAssemblyPatternAttribute.PopulateChildrenImmediately(PatternEvaluationScope assemblyScope, IAssemblyInfo assembly) in c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\TestAssemblyPatternAttribute.cs:line 122
at Gallio.Framework.Pattern.TestAssemblyPatternAttribute.Consume(PatternEvaluationScope containingScope, ICodeElementInfo codeElement, Boolean skipChildren) in c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\TestAssemblyPatternAttribute.cs:line 70
at Gallio.Framework.Pattern.PatternEvaluator.Consume(PatternEvaluationScope containingScope, ICodeElementInfo codeElement, Boolean skipChildren, IPattern defaultPrimaryPattern) in c:\RelEng\Projects\MbUnit v3\Work\src\Gallio\Gallio\Framework\Pattern\PatternEvaluator.cs:line 196
</pre><p>Our tests rely on the gallio unit testing framework, which is pretty cool but thats for another post. This exception was driving me mad, until I noticed our solution had a bunch of referenced assemblies with CopyLocal set to False. This is great for build performance, but gallio didn't seem to like it. </p><p>Since referenced assemblies don't usually change much its nice to have copy local set to false, I didn't plan on changing this for gallio. </p><p>Writing a script to one-off copy the referenced assemblies into the unit test projects is the solution in this regard. Just a heads up incase you get caught in this trap. </p><p>Edit: Here a nice post about the subjects from one of my workmates. [<a href="http://blogs.conchango.com/howardvanrooijen/archive/2009/05/09/speeding-up-your-desktop-build-part-1.aspx">+</a>] </p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0tag:blogger.com,1999:blog-3822555799329198030.post-53313129774021834372009-05-25T01:20:00.000+01:002009-05-26T20:26:50.496+01:00Pretty printing code in Blogger<p>If like me you need to paste in chunks of code into your blog, then it's nice to have it looking similar to how it looks in your code editor. Theres a project called SyntaxHighlighter which does just that. It's a bunch of css, javascript and image files which apply the code formatting on the clientside. Previously on my self hosted wordpress blog it was quite easy to upload the required files and change the site template. Unfortunately this isn't possible with a hosted account, however luckily its still easy enough to get this working in Blogger.</p><p>This trick involves linking directly to the javascript files on the projects webpage. The idea came from urenjoy, which at first I was thoroughly reluctant to do, which was linking to the files in the google code trunk. However that was for v1.5, with version 2.x we are a little luckier:</p><p><a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter:Hosting">we_have_permission_from_the_author_for_direct_linking</a></p><p>A big thumbs up to alex for allowing us to do this!</p><p>Instructions:</p><ol><li>Go to the Layout tab, and select Edit HTML.</li><li>Paste the contents of shCore.css and shThemeDefault.css straight into the skin section of the template.</li><li>Add the script code shCore.js shBrushPlain.js and the brushes you will want into the head section.</li><li>Add the necessary syntax highlighter configuration javascript into the body section.</li></ol><p>Here's a rough example of how it should look:</p><pre class="brush:xml">
<head>
<b:include data='blog' name='all-head-content' />
<title><data:blog.pageTitle/></title>
<b:skin><![CDATA[
/* Theres probably a bunch of code for your theme here, leave it as-is */
[paste the contents of http://alexgorbatchev.com/pub/sh/2.0.320/styles/shCore.css here]
[paste the contents of http://alexgorbatchev.com/pub/sh/2.0.320/styles/shThemeDefault.css here]
]]></b:skin>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushPlain.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushCSharp.js' type='text/javascript'/>
/* You can add more brushes from http://alexgorbatchev.com/pub/sh/2.0.320/scripts/ */
</head>
<body>
/* You can paste the below right after the body tag. */
<script language='javascript'>
SyntaxHighlighter.config.clipboardSwf = &#39;http://alexgorbatchev.com/pub/sh/2.0.278/scripts/clipboard.swf&#39;
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.gutter = false;
SyntaxHighlighter.all();
</script>
</body></pre><p>You will need to avoid messing with your blog theme within the template. I would recommend copying the template into an editor, adding the changes, then copying it all back to save. I hope that makes things easier for you.</p><p>Oh and as mentioned in the below posts, you will need to HTML encode the code you wish to embed or any angle brackets will screw up the site template etc...!</p><p>To actually prettify some code you will need to wrap it in pre tags whilst specifying which brush (code style) to use. You can get a full list of brushes <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter:Brushes">here</a>.</p><pre class="brush:xml">
<pre class="brush:xml">
... code here
</pre></pre><p>Here a couple of links which aided me in my quest, although I wrote this post to bring the information up to date with SyntaxHighlighter 2.0 and hopefully slightly easier to follow. Good luck.</p><p><a href="http://developertips.blogspot.com/2007/08/syntaxhighlighter-on-blogger.html" style="text-decoration: none;">http://developertips.blogspot.com/2007/08/syntaxhighlighter-on-blogger.html</a>
<a href="http://urenjoy.blogspot.com/2008/10/publish-source-code-in-blogger.html">http://urenjoy.blogspot.com/2008/10/publish-source-code-in-blogger.html</a></p>Naeem Khedarunhttp://www.blogger.com/profile/02485654918123584789noreply@blogger.com0