<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Mad Props!</title><link>http://madprops.org/</link><description>Omniscience is just a Google-search away.</description><generator>Graffiti CMS 1.2 (build 1.2.0.1451)</generator><lastBuildDate>Tue, 10 Nov 2009 04:39:18 GMT</lastBuildDate><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/mabster" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><title>foreach Over Multidimensional Arrays</title><link>http://feedproxy.google.com/~r/mabster/~3/MxhenSdc5H4/</link><pubDate>Tue, 10 Nov 2009 04:39:18 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/foreach-over-multidimensional-arrays/</guid><dc:creator>mabster</dc:creator><slash:comments>0</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;Think fast! What will this code print?&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;[,] nums = { { 1, 2 }, { 3, 4 }, { 5, 6 } };

&lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;num &lt;span style="color: blue"&gt;in &lt;/span&gt;nums)
{
    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(num);
}&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re like me, you probably thought you’d see this output:&lt;/p&gt;

&lt;pre&gt;System.Int32[]
System.Int32[]
System.Int32[]&lt;/pre&gt;

&lt;p&gt;That is, you figure that the “foreach” will iterate over the array of arrays, and try to print out each array.&lt;/p&gt;

&lt;p&gt;I can tell you now that that’s not the case. If you compile the code and run it, you’ll find it prints this:&lt;/p&gt;

&lt;pre&gt;1
2
3
4
5
6&lt;/pre&gt;

&lt;p&gt;WTF? Iterating over an array of arrays actually &lt;em&gt;flattened&lt;/em&gt; the array for me? Why yes, yes it did! Have a look at this article from the MSDN C# Programming Guide called &lt;a href="http://msdn.microsoft.com/en-au/library/2h3zzhdw.aspx"&gt;Using foreach with Arrays&lt;/a&gt;. When you iterate over a multidimensional array, you get each &lt;em&gt;element&lt;/em&gt; of the array rather than each “row”.&lt;/p&gt;

&lt;p&gt;I figured I’d try something else after discovering this, and wrote this piece of code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;[,] nums = { { 1, 2 }, { 3, 4 }, { 5, 6 } };

&lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;i = 0; i &amp;lt; nums.Length; i++)
{
    &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;j = 0; j &amp;lt; nums[i].Length; j++)
    {
        &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(nums[i, j]);
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Surely that’s reasonable? A nested “for” loop over my multidimensional array? Guess what? It &lt;em&gt;doesn’t even compile!&lt;/em&gt; You get this error on the “nums[i]” line:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Wrong number of indices inside []; expected '2'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So it turns out that &lt;em&gt;multidimensional&lt;/em&gt; arrays in C# are not the same as &lt;em&gt;arrays of arrays&lt;/em&gt; (also called &lt;em&gt;jagged arrays&lt;/em&gt; because each element of the array might be an array of any size). The compiler treats these two objects very differently:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;[,] array1;
&lt;span style="color: blue"&gt;int&lt;/span&gt;[][] arrays2;&lt;/pre&gt;

&lt;p&gt;I’d love to hear from a C# guru on this one. I guess I just don’t use arrays enough to have known this, preferring instead to use generic collections and the like.&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/foreach-over-multidimensional-arrays/</feedburner:origLink></item><item><title>Master of My Domain</title><link>http://feedproxy.google.com/~r/mabster/~3/EqnI6Ui2YKQ/</link><pubDate>Fri, 30 Oct 2009 04:39:47 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/master-of-my-domain/</guid><dc:creator>mabster</dc:creator><slash:comments>2</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;I just managed to pick up the &lt;a href="http://matthamilton.org"&gt;matthamilton.org&lt;/a&gt; domain!&lt;/p&gt;  &lt;p&gt;For now, I have simply pointed it to this site. I’m thinking that some time down the track I might end up re-branding Mad Props to my own name, but there’s so many incoming links out there that madprops.org will never truly disappear.&lt;/p&gt;  &lt;p&gt;Still, it’s great to have a true “vanity” domain name! I’ve set up matt –at- matthamilton.org too, so if you ever need to email me it shouldn’t be too hard to remember the address.&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/master-of-my-domain/</feedburner:origLink></item><item><title>Text Rendering in WPF 4</title><link>http://feedproxy.google.com/~r/mabster/~3/jIvg-O1KSWQ/</link><pubDate>Wed, 21 Oct 2009 08:13:16 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/text-rendering-in-wpf-4/</guid><dc:creator>mabster</dc:creator><slash:comments>1</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;For your viewing pleasure! You might have to copy the images and overlay them to see the difference, but I’ve taken the liberty of zooming in on a similar section in each image so you get a better look.&lt;/p&gt;  &lt;p&gt;This is a straight recompile of Comicster – I didn’t have to change any XAML markup at all. I think you’ll agree that the “after” screenshot has more readable text. It’s darker, somehow, particularly in the semi-transparent “subtitle” text under each issue name.&lt;/p&gt;  &lt;h5&gt;Before (.NET 3.5 SP1)&lt;/h5&gt;  &lt;p&gt;&lt;a href="http://www.madprops.org/files/media/image/WindowsLiveWriter/TextRenderinginWPF4_10E20/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title=".NET 3.5 SP1" border="0" alt=".NET 3.5 SP1" src="http://www.madprops.org/files/media/image/WindowsLiveWriter/TextRenderinginWPF4_10E20/image_thumb.png" width="484" height="324" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h5&gt;After (.NET 4.0 beta 2)&lt;/h5&gt;  &lt;p&gt;&lt;a href="http://www.madprops.org/files/media/image/WindowsLiveWriter/TextRenderinginWPF4_10E20/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title=".NET 4.0 beta 2" border="0" alt=".NET 4.0 beta 2" src="http://www.madprops.org/files/media/image/WindowsLiveWriter/TextRenderinginWPF4_10E20/image_thumb_1.png" width="484" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/text-rendering-in-wpf-4/</feedburner:origLink></item><item><title>Removing Replication Info from an Attached Database</title><link>http://feedproxy.google.com/~r/mabster/~3/wUEcJBtL_3E/</link><pubDate>Mon, 19 Oct 2009 21:54:45 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/removing-replication-info-from-an-attached-database/</guid><dc:creator>mabster</dc:creator><slash:comments>0</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;I often need to grab a copy of a production database so I can work with it on my local SQL Server instance (for testing purposes etc). Traditionally I’ve been doing this by taking the most recent full backup and restoring that. That’s time-consuming, though, and doesn’t necessarily mean you’ll have the latest data unless you also restore the logs.&lt;/p&gt;  &lt;p&gt;So late last week I tried a different approach. Our database is merge-replicated across a bunch of servers, one of which is a reporting server that isn’t used very often. I visited that server and took the database offline while I copied the .mdf file down to my local machine. Once that was done, I brought the database back online and attached the copied .mdf file to my local server. It was a &lt;em&gt;much&lt;/em&gt; quicker way to copy the database and I was online almost straight away.&lt;/p&gt;  &lt;p&gt;So for this particular job I needed to add a column to a table. I went ahead and ran my ALTER TABLE statement against the newly-attached database, and was met with this error:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Msg 21531, Level 16, State 1, Procedure sp_MSmerge_altertable, Line 361     &lt;br /&gt;The data definition language (DDL) command cannot be executed at the Subscriber. DDL commands can only be executed at the Publisher. In a republishing hierarchy, DDL commands can only be executed at the root Publisher, not at any of the republishing Subscribers.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Well, damn. The copy of the database has brought with it the replication information, which is telling my local server that this database is “subscribed” to a merge replication and can’t have its structure changed. The interesting thing is that this query:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;select &lt;/span&gt;&lt;span style="color: gray"&gt;* &lt;/span&gt;&lt;span style="color: blue"&gt;from master&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;sys&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: green"&gt;databases&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;… brought back a 0 for all the replication-related columns (“is_published”, “is_subscribed”, “is_merge_published”, “is_distributor” etc).&lt;/p&gt;

&lt;p&gt;In the end, I found a stored procedure that I’d never heard of before: &lt;a href="http://msdn.microsoft.com/en-us/library/ms188734.aspx"&gt;sp_removedbreplication&lt;/a&gt;. I executed it like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: maroon"&gt;sp_removedbreplication &lt;/span&gt;@dbname &lt;span style="color: gray"&gt;= &lt;/span&gt;&lt;span style="color: red"&gt;'pigfmcor'&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;And voilà! My database now allows DDL statements to be issued against it! Good to know, and handy enough that I thought it was worth blogging about.&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/removing-replication-info-from-an-attached-database/</feedburner:origLink></item><item><title>A Week of SQL and Corny Jokes</title><link>http://feedproxy.google.com/~r/mabster/~3/s31JUj8UpWw/</link><pubDate>Fri, 09 Oct 2009 22:13:00 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/a-week-of-sql-and-corny-jokes/</guid><dc:creator>mabster</dc:creator><slash:comments>0</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;My brain is full.&lt;/p&gt;
&lt;p&gt;This week at work we&amp;rsquo;ve been hosting a visit from &lt;a href="http://msmvps.com/blogs/robfarley/"&gt;Rob Farley&lt;/a&gt;, SQL Server MVP and proprietor of &lt;a href="http://lobsterpot.com.au/"&gt;LobsterPot Solutions&lt;/a&gt;. He&amp;rsquo;s been taking us through three solid days of SQL Server Analysis Services training.&lt;/p&gt;
&lt;p&gt;While I feel as if I&amp;rsquo;ve known Rob for years (we first started corresponding via blog comments about &lt;a href="http://www.madprops.org/blog/splitting-text-into-words-in-sql-revisited/#comments"&gt;three years ago&lt;/a&gt;, and have had Twitter conversations) this is the first chance I&amp;rsquo;ve had to meet him face to face. I was a little dismayed to learn that he&amp;rsquo;s actually more or less the same age as me (I typically assume that &amp;ldquo;experts&amp;rdquo; are older than me), but at least he isn&amp;rsquo;t some sort of &lt;a href="http://www.paulstovell.com"&gt;child prodigy barely out of puberty&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As well as three days of training, Rob volunteered to present at &lt;a href="http://awdnug.org"&gt;AWDNUG&lt;/a&gt; this month, and ran us through a fast-paced version of his Tech.Ed Australia talk &amp;ldquo;&lt;a href="http://www.sqlserver.org.au/events/ViewEvent.aspx?EventId=355"&gt;Improving Your SQL Arsenal&lt;/a&gt;&amp;rdquo;. This is a collection of tips and techniques to improve your SQL queries, and was well-received by the entire group.&lt;/p&gt;
&lt;p&gt;Right now I&amp;rsquo;m sitting in the auditorium at the &lt;a href="http://www.sqldownunder.com/SDUCodeCamp/tabid/100/Default.aspx"&gt;SQL Down Under Code Camp&lt;/a&gt;, watching a presentation called &amp;ldquo;&lt;a href="http://www.codecampsa.com/speakers/rob-farley"&gt;The Dangers of BEGIN and END&lt;/a&gt;&amp;rdquo; by &amp;hellip; you guessed it &amp;hellip; Rob Farley.&lt;/p&gt;
&lt;p&gt;The week has given us plenty to think about for our SQL-based solutions at work, and I can&amp;rsquo;t wait to try to put some of the techniques into practice. I imagine, too, that my colleagues at work are looking forward to returning to an environment in which the worst jokes are made by yours truly. Let&amp;rsquo;s face it, Rob: comedy is not your fort&amp;eacute;! ;-)&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/a-week-of-sql-and-corny-jokes/</feedburner:origLink></item><item><title>UI Evolution?</title><link>http://feedproxy.google.com/~r/mabster/~3/QNCVej7ih7o/</link><pubDate>Tue, 15 Sep 2009 04:51:45 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/ui-evolution/</guid><dc:creator>mabster</dc:creator><slash:comments>3</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;Eighteen glorious years of user-interface evolution!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.madprops.org/files/media/image/WindowsLiveWriter/UIEvolution_CD5E/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Windows 3.x Program Manager vs iPhone" border="0" alt="Windows 3.x Program Manager vs iPhone" src="http://www.madprops.org/files/media/image/WindowsLiveWriter/UIEvolution_CD5E/image_thumb_1.png" width="500" height="260" /&gt;&lt;/a&gt;&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/ui-evolution/</feedburner:origLink></item><item><title>Saving an Offline Copy of a SharePoint Document Library</title><link>http://feedproxy.google.com/~r/mabster/~3/uTLOB7w4qqw/</link><pubDate>Thu, 10 Sep 2009 23:59:28 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/saving-an-offline-copy-of-a-sharepoint-document-library/</guid><dc:creator>mabster</dc:creator><slash:comments>0</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;We had a requirement at work this week which had a few people bamboozled: How can we “archive” a SharePoint document library to CD so that auditors could take it off site? It only needs to be a read-only copy, but it needs to include not only the documents themselves, but any “metadata” custom columns that the site owner has added to the library.&lt;/p&gt;  &lt;p&gt;We tried a few different options, but nothing seemed to do what we wanted. A lot of people I asked suggested Groove, but after dicking around in Groove for a while, I couldn’t find how to access the “metadata” for any file that it had downloaded. In the end we settled on a fairly simple solution, which I will document here for future reference.&lt;/p&gt;  &lt;p&gt;Note: I’m blurring out the data in these screenshots. Not because it’s overly sensitive, but mostly because I want to focus on the “how” rather than the what. Also I couldn’t be bothered constructing a “fake” document library just for the purpose of this blog post. ;-)&lt;/p&gt;  &lt;p&gt;First, open the document library in a view that contains all the “metadata” columns you want to export and click Actions|Export to Spreadsheet:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.madprops.org/files/media/image/WindowsLiveWriter/SavinganOfflineCopyofaSharePointDocument_8745/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Actions|Export to Spreadsheet" border="0" alt="Actions|Export to Spreadsheet" src="http://www.madprops.org/files/media/image/WindowsLiveWriter/SavinganOfflineCopyofaSharePointDocument_8745/image_thumb_2.png" width="244" height="184" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Your list will open in Excel, and the first column will be a hyperlink back to the original document on your SharePoint server:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.madprops.org/files/media/image/WindowsLiveWriter/SavinganOfflineCopyofaSharePointDocument_8745/image_5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="The exported data in Excel" border="0" alt="The exported data in Excel" src="http://www.madprops.org/files/media/image/WindowsLiveWriter/SavinganOfflineCopyofaSharePointDocument_8745/image_thumb_1.png" width="244" height="77" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Add a new column (I like to make it the second column), and insert the formula into the first data cell:&lt;/p&gt;  &lt;pre&gt;=HYPERLINK(A2)&lt;/pre&gt;

&lt;p&gt;You’ll now have a second column of hyperlinks, but the links won’t go anywhere because they only link to a filename, rather than a full path:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.madprops.org/files/media/image/WindowsLiveWriter/SavinganOfflineCopyofaSharePointDocument_8745/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.madprops.org/files/media/image/WindowsLiveWriter/SavinganOfflineCopyofaSharePointDocument_8745/image_thumb_3.png" width="244" height="69" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Because there is no path on the hyperlinks in the second column, Excel will look for the linked file in the same folder as the spreadsheet itself. So now all you need to do is save that spreadsheet to a folder, and also save all the files out of the document library itself into that same folder! I like to call the spreadsheet “index.xlsx” so it’s clear that this is the index for all the documents.&lt;/p&gt;

&lt;p&gt;Do you have an easier way to save an offline, archived copy of a document library? If so, I’d love to hear it! Leave me a comment!&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/saving-an-offline-copy-of-a-sharepoint-document-library/</feedburner:origLink></item><item><title>Get Reactive with Rx in .NET 4.0</title><link>http://feedproxy.google.com/~r/mabster/~3/o3bIxYdHwEk/</link><pubDate>Thu, 06 Aug 2009 23:43:54 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/get-reactive-with-rx-in-net-4-0/</guid><dc:creator>mabster</dc:creator><slash:comments>0</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;Over at Channel9 they’ve recently uploaded a couple of videos on a new feature of .NET 4.0 called the Reactive Framework:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Brian-Beckman-and-Erik-Meijer-Inside-the-NET-Reactive-Framework-Rx/"&gt;Expert to Expert: Brian Beckman and Erik Meijer - Inside the .NET Reactive Framework (Rx)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://channel9.msdn.com/shows/Going+Deep/Kim-Hamilton-and-Wes-Dyer-Inside-NET-Rx-and-IObservableIObserver-in-the-BCL-VS-2010/"&gt;Kim Hamilton and Wes Dyer: Inside .NET Rx and IObservable/IObserver in the BCL (VS 2010)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;What is the Reactive Framework? I’ll try to explain it briefly, but if you want to skip to the end of this post, I’ll add some links to other blogs that you should check out.&lt;/p&gt;  &lt;p&gt;The .NET framework right now provides a pair of classes that can be used to iterate over a collection of objects: &lt;a href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/78dfe2yb.aspx"&gt;IEnumerator&amp;lt;T&amp;gt;&lt;/a&gt;. Enumerable objects provide the actual list, while enumerators do the “heavy lifting” of asking for the current item and moving forward through the list. When you think about it, this is a “pull” operation – the enumerator is “pulling” the data from the enumerable.&lt;/p&gt;  &lt;p&gt;The Reactive Framework (Rx) introduces a new pair of classes: IObservable&amp;lt;T&amp;gt; and IObserver&amp;lt;T&amp;gt;. Observable objects provide a way to “subscribe” to events, and observers (which do the subscribing) are notified when those events happen. In a way it’s a bit like traditional events in the framework, but with a game-changing addition: It’s queryable from LINQ.&lt;/p&gt;  &lt;p&gt;What does this mean? It means you can do ridiculous LINQ queries like this one, which sets up an observer that only reacts when the user presses the a, b and c keys successively:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;IObservable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Unit&lt;/span&gt;&amp;gt; abcPressed =
   &lt;span style="color: blue"&gt;from &lt;/span&gt;firstKeyPressEvent &lt;span style="color: blue"&gt;in &lt;/span&gt;pressedIs(&lt;span style="color: #2b91af"&gt;Key&lt;/span&gt;.A)
   &lt;span style="color: blue"&gt;from &lt;/span&gt;secondKeyPressEvent &lt;span style="color: blue"&gt;in &lt;/span&gt;pressedIs(&lt;span style="color: #2b91af"&gt;Key&lt;/span&gt;.B).Take(1).Until(pressedIsNot(&lt;span style="color: #2b91af"&gt;Key&lt;/span&gt;.B))
   &lt;span style="color: blue"&gt;from &lt;/span&gt;thirdKeyPressEvent &lt;span style="color: blue"&gt;in &lt;/span&gt;pressedIs(&lt;span style="color: #2b91af"&gt;Key&lt;/span&gt;.C).Take(1).Until(pressedIsNot(&lt;span style="color: #2b91af"&gt;Key&lt;/span&gt;.C))
   &lt;span style="color: blue"&gt;select new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Unit&lt;/span&gt;();

abcPressed.Subscribe(() =&amp;gt; &lt;span style="color: #2b91af"&gt;Debug&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;ABC was pressed.&amp;quot;&lt;/span&gt;));&lt;/pre&gt;

&lt;p&gt;Weird? Yeah, today it’s weird. I have a feeling that, a year or two from now, this sort of “querying events” code will be a very natural way to code.&lt;/p&gt;

&lt;p&gt;For more information on the Reactive Framework, a good place to start is Jafar Husain’s blog “unfold”, specifically this post:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://themechanicalbride.blogspot.com/2009/07/introducing-rx-linq-to-events.html"&gt;Introducing Rx (Linq to Events)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should also check out Paul Baturn’s series of posts entitled “Reacting to the Reactive Framework”. Start with part one here:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.paulbatum.com/2009/05/reacting-to-reactive-framework-part-1.html"&gt;Reacting to the Reactive Framework: Part 1&lt;/a&gt;&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/get-reactive-with-rx-in-net-4-0/</feedburner:origLink></item><item><title>Good News and Bad News</title><link>http://feedproxy.google.com/~r/mabster/~3/DrZ-BsO75Jc/</link><pubDate>Thu, 30 Jul 2009 23:26:42 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/good-news-and-bad-news/</guid><dc:creator>mabster</dc:creator><slash:comments>0</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;About a month ago I received a call at work from Sal. This is a pretty rare occurrence, but it didn’t worry me at the time. When I asked what was up, she replied, “I have good news and bad news.”&lt;/p&gt;  &lt;p&gt;The bad news was that her work was shutting down. I’m sure the “global financial crisis” hasn’t helped, but the company she worked for had been running things very close to the bone for a few years and I guess they reached the tipping point this year and had no choice but to close up shop. So Sal was going to be out of work.&lt;/p&gt;  &lt;p&gt;The good news, however, was that since Sal was a full time employee she was getting a redundancy package. The amount, at the time, was almost &lt;em&gt;exactly&lt;/em&gt; what was left owing on our mortgage! So we knew that when Sal’s work finished up &lt;strong&gt;we’d essentially be debt free&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;That day comes today.&lt;/p&gt;  &lt;p&gt;Well, that’s not strictly true. Sal finishes work today and she’ll probably get the redundancy package today, but of course there are hoops to jump through to pay off the mortgage and waiting periods while money moves around. Anyway, the crux of it is that for all intents and purposes we own our house now.&lt;/p&gt;  &lt;p&gt;For those playing at home, that’s &lt;a href="http://www.madprops.org/blog/418/"&gt;this house that I blogged about seven years ago&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.madprops.org/mabster/pics/news/house.jpg"&gt;&lt;img title="Our home being built" alt="Our home being built" src="http://www.madprops.org/mabster/pics/news/house.jpg" width="240" height="158" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Seven years is a pretty good time period in which to pay off a mortgage. Since I was putting about two thirds of my salary into the home loan, the fact that we’ve paid it off means I’m essentially getting &lt;em&gt;triple my take-home pay&lt;/em&gt; each week from now on. What will we do with it? Well, I’m gonna start by picking up a few niceties that I’ve gone without for a while, like a new PC. Then we’re going to plan a European holiday. After that, we’ll settle back down and perhaps look at buying an investment property.&lt;/p&gt;  &lt;p&gt;Sal, of course, is going to look for another job. It’s fortuitous timing because she was starting to get a bit restless where she was. I know times are tough for job-seekers right now, but I have every confidence that she’ll find something that she loves before too long.&lt;/p&gt;  &lt;p&gt;Sorry if this comes across as a bit self-promotional, but it’s a big milestone in our lives and I wanted to get it “out there” if only so we can look back at this post in another seven years with fond memories.&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/good-news-and-bad-news/</feedburner:origLink></item><item><title>Name this [Anti-]Pattern</title><link>http://feedproxy.google.com/~r/mabster/~3/wjzSQxBoaNQ/</link><pubDate>Tue, 09 Jun 2009 00:35:00 GMT</pubDate><guid isPermaLink="false">http://madprops.org/blog/name-this-anti-pattern/</guid><dc:creator>mabster</dc:creator><slash:comments>2</slash:comments><category domain="http://madprops.org/blog/">Blog</category><description>&lt;p&gt;Over the long weekend I managed to do a little bit more work on the next version of &lt;a href="http://comicster.net/"&gt;Comicster&lt;/a&gt;. I don&amp;rsquo;t know when this version will ever see the light of day because I seem to be spending as much time ripping code out and rewriting it as I do adding new features! Still, it&amp;rsquo;s a fun and educational way to pass the time.&lt;/p&gt;
&lt;p&gt;In this latest batch of work I have been trying to extract the &amp;ldquo;online database&amp;rdquo; functionality out of the core executable and turn it into a &lt;a href="http://mef.codeplex.com/"&gt;MEF extension&lt;/a&gt;. That way I can introduce other online databases (such as the new &lt;a href="http://www.madprops.org/blog/comicster-comicvine-wcf-and-rest-apis/"&gt;ComicVine API&lt;/a&gt;) by copying a DLL into a known folder. In doing so, I&amp;rsquo;ve employed a pattern (or possibly an anti-pattern) which is working quite well. If you know what its name is, please tell me!&lt;/p&gt;
&lt;p&gt;I start by defining an interface which will be the contract that any online database extensions will have to fulfil:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IServiceExtension
&lt;/span&gt;{
    &lt;span style="color: #2b91af"&gt;Character&lt;/span&gt; GetCharacter(&lt;span style="color: blue"&gt;string &lt;/span&gt;id);
    &lt;span style="color: #2b91af"&gt;Creator&lt;/span&gt; GetCreator(&lt;span style="color: blue"&gt;string &lt;/span&gt;id);
    &lt;span style="color: #2b91af"&gt;Publisher&lt;/span&gt; GetPublisher(&lt;span style="color: blue"&gt;string &lt;/span&gt;id);
    &lt;span style="color: #2b91af"&gt;Trade&lt;/span&gt; GetTrade(&lt;span style="color: blue"&gt;string &lt;/span&gt;id);
    &lt;span style="color: #2b91af"&gt;Title&lt;/span&gt; GetTitle(&lt;span style="color: blue"&gt;string &lt;/span&gt;id);
    &lt;span style="color: #2b91af"&gt;Issue&lt;/span&gt; GetIssue(&lt;span style="color: blue"&gt;string &lt;/span&gt;id);
}&lt;/pre&gt;
&lt;p&gt;That&amp;rsquo;s not the complete interface, but this snippet at least gives us the ability to download the details for all the items that Comicster can track online.&lt;/p&gt;
&lt;p&gt;However, to use this interface in a program would be quite clunky. I&amp;rsquo;d have to do a switch on the currently-selected item&amp;rsquo;s type, calling the appropriate &amp;ldquo;Get*&amp;rdquo; method on the interface. Something like:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(SelectedItem &lt;span style="color: blue"&gt;is &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Issue&lt;/span&gt;)
{
    onlineItem = GetIssue(((&lt;span style="color: #2b91af"&gt;Issue&lt;/span&gt;)SelectedItem).Id);
}
&lt;span style="color: blue"&gt;else if &lt;/span&gt;(SelectedItem &lt;span style="color: blue"&gt;is &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Title&lt;/span&gt;) ...&lt;/pre&gt;
&lt;p&gt;That&amp;rsquo;s &lt;em&gt;ugly&lt;/em&gt; code, and I know it must be possible to refactor it to take advantage of the fact that all the known types in Comicster derive from a common class (Comicster.Item). So I plan to add a new abstract method to Comicster.Item, like this (I&amp;rsquo;ll think of a better name eventually):&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;abstract class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Item&lt;/span&gt;
{
    &lt;span style="color: blue"&gt;abstract &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Item&lt;/span&gt; GetById(&lt;span style="color: #2b91af"&gt;IServiceExtension&lt;/span&gt; service);
}&lt;/pre&gt;
&lt;p&gt;This method, then, would have overrides in classes that descend from Item, like this:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Issue&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;Item&lt;/span&gt;
{
    &lt;span style="color: blue"&gt;override &lt;/span&gt;Item GetById(&lt;span style="color: #2b91af"&gt;IServiceExtension&lt;/span&gt; service)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;service.GetIssue(&lt;span style="color: blue"&gt;this&lt;/span&gt;.Id);
    }
}

&lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Title&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;Item&lt;/span&gt;
{
    &lt;span style="color: blue"&gt;override &lt;/span&gt;Item GetById(&lt;span style="color: #2b91af"&gt;IServiceExtension&lt;/span&gt; service)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;service.GetTitle(&lt;span style="color: blue"&gt;this&lt;/span&gt;.Id);
    }
}&lt;/pre&gt;
&lt;p&gt;So each class knows which method to call on IServiceExtension to get a copy of its own &amp;ldquo;online&amp;rdquo; version. The program code to download the online item becomes much simpler now:&lt;/p&gt;
&lt;pre class="code"&gt;
onlineItem = SelectedItem.GetById(service);&lt;/pre&gt;
&lt;p&gt;This means that no matter what type the selected item is, it will &amp;ldquo;know&amp;rdquo; how to download a copy of itself from the online database service. It&amp;rsquo;s a little bit like the Strategy Pattern, I suppose, except that each derived class knows how to use the given service in its own way. Is there a name for this pattern? Or is it an anti-pattern? Will it work? What do you think?&lt;/p&gt;</description><feedburner:origLink>http://madprops.org/blog/name-this-anti-pattern/</feedburner:origLink></item></channel></rss>
