<?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:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Codeharder</title>
    <description />
    <link>http://codeharder.com/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 2.0.0.36</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://codeharder.com/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://codeharder.com/syndication.axd</blogChannel:blink>
    <dc:creator>Joe Kaiser</dc:creator>
    <dc:title>Codeharder</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Codeharder" /><feedburner:info uri="codeharder" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>Registering your WP7 app with Bing Search Extras</title>
      <description>&lt;p&gt;A handy new feature coming in the Mango update for WP7 devices is the Search Extras. Essentially it allows a developer to deeply integrate his application with the phones experience. The video below will give you a quick overview of how to do it, but they skip over some relevant information.&lt;/p&gt;
&lt;p&gt;
&lt;video poster="http://media.ch9.ms/ch9/86b9/6c0860e9-b7ca-4063-a299-9ef000d986b9/IWPMangoExtras_512_ch9.jpg" controls&gt;&lt;source src="http://media.ch9.ms/ch9/86b9/6c0860e9-b7ca-4063-a299-9ef000d986b9/IWPMangoExtras_low_ch9.mp4" /&gt;&lt;object type="application/x-silverlight-2" data="data:application/x-silverlight-2," width="512" height="288"&gt;&lt;param name="minRuntimeVersion" value="4.0.50401.0"/&gt;&lt;param name="source" value="http://channel9.msdn.com/scripts/Channel9.xap?v=1.5"/&gt;&lt;param name="initParams" value="mediaurl=http://smooth.ch9.ms/ch9/86b9/6c0860e9-b7ca-4063-a299-9ef000d986b9/IWPMangoExtras.ism/manifest,thumbnail=http://media.ch9.ms/ch9/86b9/6c0860e9-b7ca-4063-a299-9ef000d986b9/IWPMangoExtras_512_ch9.jpg,deliverymethod=adaptivestreaming,autoplay=false,entryid=6c0860e9b7ca4063a2999ef000d986b9"/&gt;&lt;/object&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Lets assume that you want to integrate a Craigslist applition in with the search results. From a high level you need to put which extensions you support in you WMAppManifest.xml, add an Extras.xml file with more metadata, and set up URI Mapping in your app. I feel like it is more work than I should have to do, but the tools are still beta, and they could change. Either way it is still pretty easy.&lt;/p&gt;
&lt;h2&gt;WMAppManifest.xml&lt;/h2&gt;
&lt;p&gt;There are four kinds of extensions you can subscribe to, and many differnet categories in each kind. Listing them all here would take too much room, so I'll just &lt;a href="http://msdn.microsoft.com/en-us/library/hh202958(v=VS.92).aspx" target="_blank"&gt;point you to the page&lt;/a&gt;. Keep in mind each set has different launch parameters, and you cannot change them. I'll get to that later.&lt;/p&gt;
&lt;p&gt;Once you know what extensions you are going to subscribe to, you need to add them into your WMAppManifest. There is a new Extensions element you can add to the Deployment/App node. Each extension you support gets it own entry.&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;&amp;lt;Extensions&amp;gt;
  &amp;lt;Extension
    ExtensionName="Products"
    ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5661}"
    TaskID="_default"
    ExtraFile="Extensions\\Extras.xml" /&amp;gt;
  &amp;lt;Extension
    ExtensionName="Bing_Products_Movies"
    ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5661}"
    TaskID="_default"
    ExtraFile="Extensions\\Extras.xml" /&amp;gt;
&amp;lt;/Extensions&amp;gt;&lt;/pre&gt;
&lt;p&gt;Here is the first thing I think needs changed. The&amp;nbsp;&lt;em&gt;ConsumerID&lt;/em&gt;&amp;nbsp;node &lt;strong&gt;needs to be that exact guid&lt;/strong&gt;, and the &lt;em&gt;ExtraFile&amp;nbsp;&lt;strong&gt;need to be in that location.&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;I feel like we could omit those two nodes, and have the device infer the information. It doesn't make sense to me to have to tell it when you don't have an option to change it.&lt;/p&gt;
&lt;h2&gt;Extras.xml&lt;/h2&gt;
&lt;p&gt;Now create a folder at the root of your project called Extensions, and add an xml file called Extras.xml to it. this file contains the metadata for what your app will display when shown as a search extra. You specify what caption you want displayed next to your app for each extension.&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;

&amp;lt;ExtrasInfo&amp;gt;
  &amp;lt;AppTitle&amp;gt;
    &amp;lt;default&amp;gt;Craigslist Search&amp;lt;/default&amp;gt;
    &amp;lt;fr-FR&amp;gt;Craigslist recherche&amp;lt;/fr-FR&amp;gt;
  &amp;lt;/AppTitle&amp;gt;

  &amp;lt;Consumer ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5661}"&amp;gt;     
    &amp;lt;ExtensionInfo&amp;gt;
      &amp;lt;Extensions&amp;gt;
        &amp;lt;ExtensionName&amp;gt;Bing_Products_Movies&amp;lt;/ExtensionName&amp;gt;
        &amp;lt;ExtensionName&amp;gt;Bing_Products_Software&amp;lt;/ExtensionName&amp;gt;
      &amp;lt;/Extensions&amp;gt;
      &amp;lt;CaptionString&amp;gt;
        &amp;lt;default&amp;gt;Look for cheap movies and software on Craigslist&amp;lt;/default&amp;gt;
        &amp;lt;fr-FR&amp;gt;Recherchez les films bon march&amp;eacute;s et logiciels Craigslist&amp;lt;/fr-FR&amp;gt;
      &amp;lt;/CaptionString&amp;gt;
    &amp;lt;/ExtensionInfo&amp;gt;

    &amp;lt;ExtensionInfo&amp;gt;
      &amp;lt;Extensions&amp;gt;
        &amp;lt;ExtensionName&amp;gt;Bing_Products_Video_Games&amp;lt;/ExtensionName&amp;gt;
        &amp;lt;ExtensionName&amp;gt;Bing_Products_Toys&amp;lt;/ExtensionName&amp;gt;
      &amp;lt;/Extensions&amp;gt;
      &amp;lt;CaptionString&amp;gt;
        &amp;lt;default&amp;gt;Look for pre-owned games on Craigslist&amp;lt;/default&amp;gt;
        &amp;lt;fr-FR&amp;gt;Recherchez les jeux neufsm Craigslist&amp;lt;/fr-FR&amp;gt;
      &amp;lt;/CaptionString&amp;gt;
    &amp;lt;/ExtensionInfo&amp;gt;

    &amp;lt;ExtensionInfo&amp;gt;
      &amp;lt;Extensions&amp;gt;
        &amp;lt;ExtensionName&amp;gt;Products&amp;lt;/ExtensionName&amp;gt;
      &amp;lt;/Extensions&amp;gt;
      &amp;lt;CaptionString&amp;gt;
        &amp;lt;default&amp;gt;Look for stuff on Craigslist&amp;lt;/default&amp;gt;
      &amp;lt;/CaptionString&amp;gt;
    &amp;lt;/ExtensionInfo&amp;gt;
  &amp;lt;/Consumer&amp;gt;
&amp;lt;/ExtrasInfo&amp;gt;&lt;/pre&gt;
&lt;p&gt;Once again, the ConsumerID needs to be that value. It feels odds having to include it in a second place, but that's how it goes. A few other things to note:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you can have more than one ExtensionName per ExtensionInfo. In the sample above you will see &lt;em&gt;Look for cheap movies and software on Craigslist&lt;/em&gt; when movies and software are displayed, but &lt;em&gt;Look for pre-owned games on Craigslist&lt;/em&gt; is displayed when games and toys are displayed. Notice you can also specify what to show be other languages. The default one is required, but the language specific ones are optional.&lt;/li&gt;
&lt;li&gt;You can specify up to 50 captions in Extras.xml, for a maximum of 50 ExtensionInfo elements. Each ExtensionInfo element can contain up to 50 different ExtensionName elements.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;URI Mapping&lt;/h2&gt;
&lt;p&gt;When an extra is launched from a search, it targets a specific page, and paramers. You cannot change them, but you can re-route them. In the case of a product search it will target&amp;nbsp;&lt;em&gt;/SearchExtras?ProductName=&amp;lt;product_name&amp;gt;&amp;amp;Category=&amp;lt;extension_names&amp;gt;&lt;/em&gt;&amp;nbsp;where SearchExtras is the page, ProductName is the name of the product the selected, and Category is the category it is in.&amp;nbsp;But lets say your app uses SearchResults.xaml, not SearchExtras.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;step 1: &lt;/strong&gt;Open &lt;em&gt;App.xaml&lt;/em&gt;&amp;nbsp;and add&amp;nbsp;&lt;em&gt;&amp;nbsp;xmlns:nav="clr-namespace:System.Windows.Navigation;assembly=Microsoft.Phone"&lt;/em&gt;&amp;nbsp;as a namespace directive&lt;/p&gt;
&lt;pre class="brush: xml; highlight: 7;"&gt;&amp;lt;Application 
    x:Class="WindowsPhoneApplication1.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:nav="clr-namespace:System.Windows.Navigation;assembly=Microsoft.Phone"&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;step 2:&lt;/strong&gt; Add a UIRMapping resource in App.xaml. Notice the line highlighted. You need to change YourPage.xaml.&lt;/p&gt;
&lt;pre class="brush: xml; highlight: 7;"&gt;&amp;lt;!--Application Resources--&amp;gt;
    &amp;lt;Application.Resources&amp;gt;
     
        &amp;lt;!-- Map Search Extras deep links to Item page --&amp;gt;
        &amp;lt;nav:UriMapper x:Key="UriMapper"&amp;gt;
            &amp;lt;nav:UriMapper.UriMappings&amp;gt;
                &amp;lt;nav:UriMapping Uri="/SearchExtras" MappedUri="/YourPage.xaml"/&amp;gt;
            &amp;lt;/nav:UriMapper.UriMappings&amp;gt;
        &amp;lt;/nav:UriMapper&amp;gt;
        
    &amp;lt;/Application.Resources&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;step 3:&lt;/strong&gt; Load it in the App.cs constructor.&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;public App()
{
    RootFrame.UriMapper = Resources["UriMapper"] as UriMapper;
}&lt;/pre&gt;
&lt;p&gt;If you have done all of that correctly, all you have to do is configure your page to look for the given parameters. I chose to do this in the Page_Loaded event.&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    string query;
    if (NavigationContext.QueryString.Keys.Contains("ProductName"))
    {
        query = NavigationContext.QueryString["ProductName"];
        SearchCraigsList(query);
    }
}&lt;/pre&gt;
&lt;p&gt;There you go. You should now see your app in the Extras section when you are looking at a category you subscribed to. I do have two more things to&amp;nbsp;note.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Right now there are Beta extensions, and Production extensions. A beta extension is broad (Product) and Production are specific (Bing_Product_Toys). As of now, I can't get the Production extensions to work, only the Beta. Also, submitting your app with Beta extensions enabled will cause it to fail certifiction. Make sure your remove it.&lt;/li&gt;
&lt;li&gt;The Visual Studio debugger will detach when a new instance of the app is launched. In order to debug this experience you need to trick your app into thinking it was lauched from Search Extras. In WMAppManifest.xml there is a task name _default. comment this line out and add another like&amp;nbsp;the one below. This will simulate the app being launched from Search Extras.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="brush: xml;"&gt;&amp;lt;Tasks&amp;gt;
  &amp;lt;!--&amp;lt;DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/&amp;gt;--&amp;gt;
  &amp;lt;DefaultTask Name="_default" NavigationPage="SearchExtras?ProductName=XBox 360&amp;amp;Category=Bing_Products_Electronics" /&amp;gt;
&amp;lt;/Tasks&amp;gt;&lt;/pre&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/jMO5t7D_R_I/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Registering-your-WP7-app-with-Bing-Search-Extras.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=5ff91026-d657-452c-93ad-509b913ef244</guid>
      <pubDate>Thu, 09 Jun 2011 08:00:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=5ff91026-d657-452c-93ad-509b913ef244</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=5ff91026-d657-452c-93ad-509b913ef244</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Registering-your-WP7-app-with-Bing-Search-Extras.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=5ff91026-d657-452c-93ad-509b913ef244</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=5ff91026-d657-452c-93ad-509b913ef244</feedburner:origLink></item>
    <item>
      <title>Enhanced Pathfinding</title>
      <description>&lt;p&gt;In a previous post - &lt;a title="Mobile games are different" href="http://codeharder.com/post/Mobile-games-are-different.aspx"&gt;Mobile games are different&lt;/a&gt; - I mentioned that I made it so the player would walk to the location on the map you touched. Obviously, I had to implement some kind of pathfinding so the player would walk through solid objects. I chose to go with the &lt;a href="http://en.wikipedia.org/wiki/A*"&gt;A* algorithm&lt;/a&gt;. From what I read, it was fast, and I found a guy who &lt;a href="http://roy-t.nl/index.php/2010/06/27/more-a-improvements/"&gt;did most of the leg work&lt;/a&gt; for me.&lt;/p&gt;
&lt;p&gt;It was great, except the movement was not real. The player walked pretty jagged, and it turns out that is a pretty common thing. With a bit of digging I found an &lt;a href="http://www.gamasutra.com/view/feature/3096/toward_more_realistic_pathfinding.php"&gt;article&lt;/a&gt; that gave many ways to improve the algorithm. I only implemented the stright line movement improvements as I wasn't worried about the turns, but it looks great now.&amp;nbsp;&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/t-K3uU8N_xM/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Enhanced-Pathfinding.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=015548fc-7e9e-44fe-9474-8ff9ffe0cfa3</guid>
      <pubDate>Tue, 31 May 2011 08:11:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=015548fc-7e9e-44fe-9474-8ff9ffe0cfa3</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=015548fc-7e9e-44fe-9474-8ff9ffe0cfa3</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Enhanced-Pathfinding.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=015548fc-7e9e-44fe-9474-8ff9ffe0cfa3</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=015548fc-7e9e-44fe-9474-8ff9ffe0cfa3</feedburner:origLink></item>
    <item>
      <title>Updated WP7 tools for Mango</title>
      <description>&lt;p&gt;In case you missed it, the &lt;a href="http://create.msdn.com/en-US/news/WPDT_7.1_Beta"&gt;WP7 dev tools were updated&lt;/a&gt; for the upcoming "Mango" release. Over 500 features are being added to the platform, which means a lot more API's! If you want to get a head start, get the tools and &lt;a href="http://msdn.microsoft.com/en-us/library/ff637516(v=VS.92).aspx"&gt;check out the docs&lt;/a&gt;. Below is a list of the APIs I plan on playing with as soon as my laptop is fixed.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh202946(v=VS.92).aspx"&gt;Scheduled Actions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff402528(v=VS.92).aspx"&gt;Silverlight and XNA combined&lt;/a&gt;&amp;nbsp;- I am really interested in having the silverlight navigation framework in an XNA game&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh202934(v=VS.92).aspx"&gt;Windows Phone Profiler&lt;/a&gt; - I have been waiting for this since Scott Gu showed it off at PDC10&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh202860(v=VS.92).aspx"&gt;Local Database&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff769548(v=VS.92).aspx"&gt;Scheduled Tile Updates&lt;/a&gt;&amp;nbsp;- I already have ideas for great apps :)&lt;/li&gt;
&lt;/ul&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/MOmr1U_dcv4/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Updated-WP7-tools-for-Mango.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=8d30e7ff-c1e3-454d-b1dd-0067c86d6e8b</guid>
      <pubDate>Tue, 24 May 2011 10:49:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=8d30e7ff-c1e3-454d-b1dd-0067c86d6e8b</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=8d30e7ff-c1e3-454d-b1dd-0067c86d6e8b</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Updated-WP7-tools-for-Mango.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=8d30e7ff-c1e3-454d-b1dd-0067c86d6e8b</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=8d30e7ff-c1e3-454d-b1dd-0067c86d6e8b</feedburner:origLink></item>
    <item>
      <title>Mobile games are different</title>
      <description>&lt;p&gt;I don't have much time to devote to gaming anymore, and becuase of that I have been enjoying mobile games more than console games lately. Mainly because most of the time I only have 20 minutes, and there seem to be more mobile games that I can do short plays on over console games.&lt;/p&gt;
&lt;p&gt;&lt;img style="float: left;" src="http://codeharder.com/image.axd?picture=2011%2f5%2fmobilegames.png" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;The only thing I miss about console games are the controllers. no matter how hard you try, a phone just doesn't have the same "input feel" as a controller. Some people have tried using virtual analog sticks and buttons, but those always bothered me. Maybe I am just different, but I often find my fingers have drifted from the "button" at a crucial point in the game play. What bothers me is the enitre phone is an input device. Why limit the input to a few virtual buttons on the screen?&amp;nbsp;In a recent game me and a good friend are working on, I really didnt want to have to use the virtual button approach. Our game (a 2d, top down, rpg -like game) was going to be better.&lt;/p&gt;
&lt;p&gt;If a player want to walk to a certain place on the screen, he could just tap on it, and the player would walk there. It felt great, but it was missing a few things. The viewport was small, and if you wanted to walk across the current map, it took several taps. So I added the ability to "pinch zoom". It was an immediate improvement, but still not good enough as you are limited as to how far you can zoom out and still have the game playable. The next logical thing was panning. Swipe you finger across the screen, and the camera moves that direction.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Great, the person was able to quickly locate, move to the position, and it felt natural. Well, natural until it was a bigger play area. I found myslef looking for my player after I had panned away. Easy enough, when you told the player to move to a location, the camera quickly panned back down to where the player was on the map. Much better! I even added a little icon to the HUD that let you know if the camera was following the player, or if it was in "free range" mode. When in free range mode, touching the icon would snap back to the players location.&lt;/p&gt;
&lt;p&gt;I guess what I am trying to get at is, think about a phone's input differently than a traditional gaming device. Try a few approaches until you find something that feels good to use. Now I know that not every game will benefit from the approach I took, but that is the point. Games/generes all require something different. Don't settle for what you think is traditional. Branch out and try something else.&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/gLHT4LJgwsk/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Mobile-games-are-different.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=267fda7a-1ce0-4a6b-9679-4ffb1657bfa4</guid>
      <pubDate>Mon, 23 May 2011 10:35:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=267fda7a-1ce0-4a6b-9679-4ffb1657bfa4</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=267fda7a-1ce0-4a6b-9679-4ffb1657bfa4</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Mobile-games-are-different.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=267fda7a-1ce0-4a6b-9679-4ffb1657bfa4</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=267fda7a-1ce0-4a6b-9679-4ffb1657bfa4</feedburner:origLink></item>
    <item>
      <title>Smush Your Images</title>
      <description>&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 10px; display: inline; border-top: 0px; border-right: 0px" title="smushit" src="http://codeharder.com/image.axd?picture=smushit.jpg" border="0" alt="smushit" width="244" height="130" align="right" /&gt;Optimizing images is something you should always do for websites. No&amp;nbsp; excuses! If you aren&amp;rsquo;t doing it, start now. Seriously, it saves bandwidth for you AND your readers. Yahoo even provides a service (&lt;a rel="nofollow" href="http://smushit.com"&gt;Smush.it&lt;/a&gt;) to make it simple.&lt;/p&gt;
&lt;p&gt;That being said, my wife loves pictures. Every Wednesday she chooses the best from the previous week and shares them on her blog. She uses Windows Live Writer to compiler the post, and likes to add effects to the images before they go out. This makes optimizing them really annoying because I had to go do it after the post was complete.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I started to look around to see if there was a plugin for Live Writer that would send all images through Smush.it before uploading the post, but nothing seemed to be there. I figure I would buckle down and knock one out in a night. After an hour or so of hacking, I present to you Smushy.&lt;/p&gt;
&lt;p&gt;It is really quite simple. When you are creating a new post (sorry, it doesn&amp;rsquo;t work for updating because I didn&amp;rsquo;t want to have to worry about sending already smushed images through their service again) it pulls all image tags out of the HTML, runs them through the service, and overwrites the one on disk with the optimized one.&lt;/p&gt;
&lt;p&gt;It should be fine, but as always, use at your own risk. Please leave feedback below, and let me know if there are any bugs.&lt;/p&gt;
&lt;p&gt;One last thing, the more images you have in the post the longer it is going to take. It currently send them off one at a time.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codeharder.com/file.axd?file=2010%2f10%2fSmushy.cs"&gt;Smushy.cs (3.31 kb)&lt;/a&gt;&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/hO3479oMclE/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Smush-Your-Images.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=6a8183b6-82ff-4e4e-b685-26870f2dfe44</guid>
      <pubDate>Fri, 08 Oct 2010 16:25:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=6a8183b6-82ff-4e4e-b685-26870f2dfe44</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=6a8183b6-82ff-4e4e-b685-26870f2dfe44</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Smush-Your-Images.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=6a8183b6-82ff-4e4e-b685-26870f2dfe44</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=6a8183b6-82ff-4e4e-b685-26870f2dfe44</feedburner:origLink></item>
    <item>
      <title>Creating packages and repositories for NuPack</title>
      <description>&lt;h2&gt;Overview&lt;/h2&gt;
&lt;p&gt;&lt;span style="color: #004000;"&gt;Disclaimer: the information below is based off of CTP1&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Earlier today Microsoft announced a new tool called &lt;a href="http://nupack.codeplex.com" target="_blank"&gt;NuPack&lt;/a&gt; for managing dependencies. Before I was even done reading announcement, I wanted to know how to create my own package, and host a repository.&lt;/p&gt;
&lt;p&gt;There is some &lt;a href="http://nupack.codeplex.com/wikipage?title=Creating%20a%20Package" target="_blank"&gt;documentation&lt;/a&gt; on how to build a package at the codeplex site, but I feel like a few things are missing, or not explained well. Granted, the project was only announced a few hours ago so I guess I can cut them some slack :)&lt;/p&gt;
&lt;p&gt;Before you create a package, &lt;a href="http://nupack.codeplex.com/releases/view/52016" target="_blank"&gt;go and get nupack.exe&lt;/a&gt;. It is a simple&amp;nbsp; wrapper around PackageWrapper API, so technically you don&amp;rsquo;t need it; however, it did make things easier (for me at least). &lt;span style="text-decoration: line-through;"&gt;As of the time of this writing the tool isn&amp;rsquo;t distributed as a binary. You have to &lt;a href="http://nupack.codeplex.com/SourceControl/changeset/view/06de9eb70fc4" target="_blank"&gt;download the source&lt;/a&gt; and build it yourself.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now that you have the tool you need to create a a spec to describe your package.&amp;nbsp; The spec is posted &lt;a href="http://nupack.codeplex.com/documentation?title=Nuspec%20Format" target="_blank"&gt;here&lt;/a&gt;, but it a nutshell, it is an xml file with a &lt;em&gt;.nuspec &lt;/em&gt;extension, and are really quite simple.&lt;/p&gt;
&lt;pre class="brush: xml; gutter: false;"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;package&amp;gt;
  &amp;lt;metadata&amp;gt;
    &amp;lt;id&amp;gt;xunit&amp;lt;/id&amp;gt;
    &amp;lt;version&amp;gt;1.6.1&amp;lt;/version&amp;gt;
    &amp;lt;authors&amp;gt;
      &amp;lt;author&amp;gt;Brad Wilson&amp;lt;/author&amp;gt;
      &amp;lt;author&amp;gt;Jim Newkirk&amp;lt;/author&amp;gt; 
    &amp;lt;/authors&amp;gt;
    &amp;lt;description&amp;gt;xUnit.net is a developer testing framework, built to support Test Driven Development &amp;lt;/description&amp;gt;
    &amp;lt;language&amp;gt;en-US&amp;lt;/language&amp;gt;
  &amp;lt;/metadata&amp;gt;
&amp;lt;/package&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have found that it is easier to just put the metadata in the spec, and rely on a directory structure to build the package. The folders should be relative to the location of the .nuspec you have created.&lt;/p&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;tools - The tools folder of a package will be added to $env:Path (PATH) when the package is installed&amp;nbsp; &lt;/li&gt;
&lt;li&gt;content - These files will be copied to the site root on install &lt;/li&gt;
&lt;li&gt;lib - dlls under this folder will become assembly references on install &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Once all that is setup you just run nupack.exe, give it the .nuspec file, and it will generate a package that you can host, or submit to an existing repository.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;A *very* simple package&lt;/h2&gt;
&lt;p&gt;I created a simple object pool library (Opool.dll&lt;em&gt;)&lt;/em&gt;, that recycles objects for later use. My spec file is:&lt;/p&gt;
&lt;pre class="brush: xml; gutter: false;"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;package&amp;gt;
  &amp;lt;metadata&amp;gt;
    &amp;lt;id&amp;gt;Opool&amp;lt;/id&amp;gt;
    &amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;
    &amp;lt;authors&amp;gt;
      &amp;lt;author&amp;gt;Joe Kaiser&amp;lt;/author&amp;gt;
    &amp;lt;/authors&amp;gt;
    &amp;lt;description&amp;gt;Opool is a generic object pool that lets you recycle objects instead of throwing them away&amp;lt;/description&amp;gt;
    &amp;lt;language&amp;gt;en-US&amp;lt;/language&amp;gt;
  &amp;lt;/metadata&amp;gt;
&amp;lt;/package&amp;gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My directory structure is such that I just wanted the end user to reference my assembly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;+ OpoolPackge&lt;/strong&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Opool.nuspec     &lt;br /&gt;&amp;nbsp; &lt;strong&gt;&amp;nbsp; + lib&lt;/strong&gt; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Opool.dll     &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Opool.pdb&lt;/p&gt;
&lt;p&gt;and I generated the package: &lt;em&gt;d:\tools\nupack.exe d:\packages\OpoolPackage\Opool.nuspec&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;And a *very* simple repository&lt;/h2&gt;
&lt;p&gt;If you want to host a package in the simplest way possible you can just share them out. Any one wanting to use it just adds your share as a source.&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;Tools&amp;gt;Options&amp;gt;Package Manager &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img style="display: inline; border-width: 0px;" src="http://codeharder.com/image.axd?picture=Capture_1.jpg" border="0" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;Now when you go to add a package reference it should show up in the list, and you can install it into your project.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img style="display: inline; border-width: 0px;" src="http://codeharder.com/image.axd?picture=ref_1.jpg" border="0" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img style="display: inline; border-width: 0px;" src="http://codeharder.com/image.axd?picture=pool.jpg" border="0" alt="" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I really, really like where Microsoft has been going lately. They have been listening to what developers want, and not only have they been delivering it, but making it open source as well. NuPack is just yet another tool that is making me wonder how I have gone so long without it.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx" target="_blank"&gt;&amp;nbsp;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks to the dev team for helping me figure some of this out :)&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/nCEGktFn97E/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Creating-packages-and-repositories-for-NuPack.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=fd3a01d9-d017-448b-a3bc-987d2615e0da</guid>
      <pubDate>Wed, 06 Oct 2010 07:44:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=fd3a01d9-d017-448b-a3bc-987d2615e0da</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=fd3a01d9-d017-448b-a3bc-987d2615e0da</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Creating-packages-and-repositories-for-NuPack.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=fd3a01d9-d017-448b-a3bc-987d2615e0da</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=fd3a01d9-d017-448b-a3bc-987d2615e0da</feedburner:origLink></item>
    <item>
      <title>Bookmark Mashup 7.30.10</title>
      <description>&lt;p&gt;As everyone else does, I run into several interesting articles, and tools throughout the week. I figured that every so often I would share the best of them. Without further ado&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel="nofollow" href="http://cdhrdr.com/aWww8U "&gt;Clean Code&lt;/a&gt; &amp;ndash; It never hurts to have a reminder&lt;/li&gt;
&lt;li&gt;&lt;a rel="nofollow" href="http://cdhrdr.com/aJ44yY "&gt;50 jQuery snippets&lt;/a&gt; that will help you become a better javascript developer&lt;/li&gt;
&lt;li&gt;&lt;a rel="nofollow" href="http://cdhrdr.com/cN3Jvg "&gt;JSEnhancements&lt;/a&gt; &amp;ndash; A VS10 extension that adds some nice editor support to javascript&lt;/li&gt;
&lt;li&gt;&lt;a rel="nofollow" href="http://cdhrdr.com/at5Trm"&gt;Test controller actions&lt;/a&gt; in ASP.NET MVC by using the Dynamic type&lt;/li&gt;
&lt;/ul&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/3pZxborH54o/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Bookmark-Mashup-73010.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=8d1c90a3-b87a-46c5-a92b-263096ffca06</guid>
      <pubDate>Fri, 30 Jul 2010 00:51:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=8d1c90a3-b87a-46c5-a92b-263096ffca06</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=8d1c90a3-b87a-46c5-a92b-263096ffca06</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Bookmark-Mashup-73010.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=8d1c90a3-b87a-46c5-a92b-263096ffca06</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=8d1c90a3-b87a-46c5-a92b-263096ffca06</feedburner:origLink></item>
    <item>
      <title>Custom (dynamic) configuration sections in .net</title>
      <description>&lt;p&gt;Creating a custom configuration section can be done in &lt;a href="http://haacked.com/archive/2007/03/12/custom-configuration-sections-in-3-easy-steps.aspx"&gt;3 easy steps&lt;/a&gt;. However, accessing section with a ConfigurationElementCollection can be tedious. Let me explain.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s pretend you have a section that looks like this:&lt;/p&gt;
&lt;pre class="brush: csharp; auto-links: false;"&gt;&amp;lt;namedUrlSection favoriteUrl="CodeHarder"&amp;gt;
  &amp;lt;namedUrls&amp;gt;
    &amp;lt;add name="Twitter" url="http://twitter.com"/&amp;gt;
    &amp;lt;add name="CodeHarder" url="http://codeharder.com"/&amp;gt;
    &amp;lt;add name="Stackoverflow" url="http://www.stackoverflow.com"/&amp;gt;
  &amp;lt;/namedUrls&amp;gt;
&amp;lt;/namedUrlSection&amp;gt;&lt;/pre&gt;
&lt;p&gt;And the accompanying code to read it:&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class UrlConfigSection : ConfigurationSection
{
    public static UrlConfigSection ConfigSection = ConfigurationManager.GetSection("namedUrlSection") as UrlConfigSection;

    [ConfigurationProperty("favoriteUrl")]
    public string Favorite
    {
        get
        {
            return this["favoriteUrl"].ToString();
        }
    }

    [ConfigurationProperty("namedUrls")]
    public NamedUrlCollection Urls
    {
        get
        {
            return this["namedUrls"] as NamedUrlCollection;
        }
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you wanted to get the name of your favorite URL, it is very simple syntax.&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;string favUrlName = UrlConfigSection.ConfigSection.Favorite;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But, when you want to access one of the child namedUrl elements, it just doesn&amp;rsquo;t look very nice. Not ugly, just verbose. Wouldn&amp;rsquo;t you agree?&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;UrlConfigSection.ConfigSection.Urls["CodeHarder"].Url&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I always wished I could just flatten it out to something like .CodeHarder. I don&amp;rsquo;t know why I didn&amp;rsquo;t think of this before, but with the new &lt;a href="http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject.aspx"&gt;DynamicObject&lt;/a&gt; in .net4 I can! Creating a wrapper to give me that syntax is ~10 lines of code.&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;public class DynamicUrlConfig:DynamicObject
{
    public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
        result = null;
        NamedUrl url = UrlConfigSection.ConfigSection.Urls[binder.Name];
                    
        if (url != null)
        {
            result = url.Url;
            return true;
        }
        return false;
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now, when I want to get anything from the &lt;em&gt;namedUrls&lt;/em&gt; section, I can use the syntax I always wanted.&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;dynamic urlSection = new DynamicUrlConfig();
string favUrl = urlSection.CodeHarder;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I know this isn&amp;rsquo;t new, and a quick google would probably give me several people who have done it before, but I was quite pleased and thought I would share.&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/kP5Xm8kL0KU/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Custom-(dynamic)-configuration-sections-in-net.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=c3a16ace-b959-494b-95fc-c68a8910fb96</guid>
      <pubDate>Fri, 09 Jul 2010 02:14:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=c3a16ace-b959-494b-95fc-c68a8910fb96</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=c3a16ace-b959-494b-95fc-c68a8910fb96</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Custom-(dynamic)-configuration-sections-in-net.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=c3a16ace-b959-494b-95fc-c68a8910fb96</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=c3a16ace-b959-494b-95fc-c68a8910fb96</feedburner:origLink></item>
    <item>
      <title>Modifying a WCF operation at runtime – part 3</title>
      <description>&lt;p&gt;&lt;span style="color: #008000"&gt;part 1: &lt;a href="http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-part-1.aspx"&gt;The client setup&lt;/a&gt;       &lt;br /&gt;part 2: &lt;a href="http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-part-2.aspx"&gt;The code setup&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;While at work the other day I was talking to my boss, and the subject of spoofing data came up. He mentioned that for our current project, it would be nice to be able to spoof data on a per-request basis. I thought it would be a fun challenge to tackle, so I spent a few hours last Saturday and came up with a pretty elegant solution.&lt;/p&gt;  &lt;p&gt;Before I started, I had a few requirements:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It had to be completely config driven. The client and target WCF service were to have no idea what was going on. &lt;/li&gt;    &lt;li&gt;It was to be on a per-user/per-request basis. What this means is any dev could turn it on/off and it would only affect him. &lt;/li&gt;    &lt;li&gt;Extensible. If you didn’t like the data I mocked, or needed to be able to simulate slow network traffic, exceptions, large data, etc - you could. &lt;/li&gt;    &lt;li&gt;I only had 5 hours to come up with a solution. &lt;/li&gt; &lt;/ul&gt;  &lt;hr /&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In &lt;a href="http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-part-2.aspx"&gt;part 2&lt;/a&gt; I described how I structured our code so I could provide any &lt;em&gt;ITypeFactory&lt;/em&gt; we wanted. With that out of the way, I was able to get back to some more of the fun stuff. Armed with&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.aspx"&gt;IOperationBehavior&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.aspx"&gt;IEndpointBehavior&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.configuration.behaviorextensionelement.aspx"&gt;BehaviorExtensionElement&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.ioperationinvoker.aspx"&gt;IOperationInvoker&lt;/a&gt;, and &lt;a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationsection.aspx"&gt;ConfigurationSection&lt;/a&gt; I set out to finish this thing off.&lt;/p&gt;  &lt;p&gt;One of my main goals was to make the entire thing config driven. I knew that when I saw the &lt;em&gt;mockdata&lt;/em&gt; header I would want to grab what ITypeFactory to use from the config. I figured I would start there.&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public class ServiceMockerConfigSection:ConfigurationSection
{
    public static ServiceMockerConfigSection ConfigSection = ConfigurationManager.GetSection(&amp;quot;ServiceMockerConfigSection&amp;quot;) as ServiceMockerConfigSection;
    static ServiceMockerConfigSection() { }

    [ConfigurationProperty(&amp;quot;mockType&amp;quot;,IsRequired=true)]
    public string MockFactoryType
    {
        get
        {
            return this[&amp;quot;mockType&amp;quot;].ToString();
        }
    }
}&lt;/pre&gt;

&lt;p&gt;and the config:&lt;/p&gt;

&lt;pre class="brush: xml;"&gt;&amp;lt;configSections&amp;gt;
  &amp;lt;section name=&amp;quot;ServiceMockerConfigSection&amp;quot; type=&amp;quot;VT.Lenio.ServiceMocker.ServiceMockerConfigSection, VT.Lenio.ServiceMocker&amp;quot;/&amp;gt;
&amp;lt;/configSections&amp;gt;

&amp;lt;ServiceMockerConfigSection mockType=&amp;quot;ServicesMocks.SimpleMockFactory,ServicesMocks&amp;quot;/&amp;gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Next up was the custom &lt;em&gt;IOperationInvoker.&lt;/em&gt; This is the part that looks for the &lt;em&gt;mockdata&lt;/em&gt; header. When found it creates a type specified in the config (in the case above, a SimpleMockFactory), and injects it into the given service.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class MockServiceOperationInvoker : IOperationInvoker
{
    public object Invoke(object instance, object[] inputs, out object[] outputs)
    {
        try
        {
            var headers = OperationContext.Current.IncomingMessageHeaders;
            
            if (headers.Any(h =&amp;gt; h.Name == &amp;quot;mockdata&amp;quot;))
            {
                if (instance is ServiceBase)
                {
                    string mockTypeString = ServiceMockerConfigSection.ConfigSection.MockFactoryType;
                    Type mockType = Type.GetType(mockTypeString);
                    ITypeFactory mockFactory = Activator.CreateInstance(mockType) as ITypeFactory;
                    if (mockFactory != null)
                        ((ServiceBase)instance).TypeFactory = mockFactory;
                }
            }
        }
        catch
        {
            //swallow so we don't break anything
        }

        return Invoker.Invoke(instance, inputs, out outputs);
    }
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;The biggest problem I had with this entire process was getting this invoker attached to an operation. To make that happen you have to create an IOperationBehavior. When the behavior executes, you can add your invoker into the pipeline.&lt;/p&gt;

&lt;p&gt;Every example I found showed it being done via a custom attribute. Unfortunately, that broke my #1 rule. How could I easily add/remove the behavior if it was coded into the service? Even after searching MSDN I had to come to the conclusion that the only way suggested would be to use that attribute. I wasn’t going to let that stop me!&lt;/p&gt;

&lt;p&gt;Having &lt;a href="http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-e28093-part-1.aspx"&gt;already implemented&lt;/a&gt; a IEndpointBehavior, I had a hunch I could use it here as well. If so, it would allow me to add my IOperationBehavior to every operation in a given endpoint, and have it driven from the configuration.&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class MockOperationBehavior : BehaviorExtensionElement,  IOperationBehavior, IEndpointBehavior
{
    #region IOperationBehavior
    public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
    {
        dispatchOperation.Invoker = new MockServiceOperationInvoker() { Invoker = dispatchOperation.Invoker };
    }
    #endregion

    #region IEndpointBehavior
    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        foreach (var op in endpoint.Contract.Operations)
        {
            op.Behaviors.Add(this);
        }
    }
    #endregion

    public override Type BehaviorType
    {
        get {return typeof(MockOperationBehavior); }
    }

    protected override object CreateBehavior()
    {
        return new MockOperationBehavior();
    }
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Basically, when the IEndpointBehavior was executed it would loop through each operation in its contract and add itself as a behavior. (This works because &lt;em&gt;MockOperationBehavior&lt;/em&gt; implements both IEndpointBehavior, and IOperationBehavior.) When the IOperationBehavior runs it sets the dispatchInvoker the the &lt;em&gt;MockerOperationInvoker&lt;/em&gt; I created above.&lt;/p&gt;

&lt;p&gt;The last step was add the configuration to the service host, and it was complete! To tie it together nicely, I added two bookmarklets to my browser. One wrote the cookie, and one removed it. With the click of a button I am able to switch from live data to spoofed data, and neither the client or the service knows it is happening.&lt;/p&gt;

&lt;p&gt;What really excites me about this is not that I can spoof data anytime I want, but that WCF is really easy to extend. Go play around with it, I doubt you will regret it!&lt;/p&gt;

&lt;p&gt;&lt;span style="color: #008000; font-size: x-small"&gt;I tried to make this as clear as I could, but I could be taking some things for granted. If I confused you at all feel free to leave a comment, or contact me. I will try to make it more clear for you.&lt;/span&gt;&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/nqKADCniujM/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-–-part-3.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=9f44f757-e9f5-4a5d-b641-ba28d6db4fa6</guid>
      <pubDate>Tue, 06 Jul 2010 20:56:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=9f44f757-e9f5-4a5d-b641-ba28d6db4fa6</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=9f44f757-e9f5-4a5d-b641-ba28d6db4fa6</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-–-part-3.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=9f44f757-e9f5-4a5d-b641-ba28d6db4fa6</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=9f44f757-e9f5-4a5d-b641-ba28d6db4fa6</feedburner:origLink></item>
    <item>
      <title>Modifying a WCF operation at runtime – part 2</title>
      <description>&lt;p&gt;&lt;font color="#008000"&gt;Part 1: &lt;a href="http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-part-1.aspx"&gt;The client setup&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;While at work the other day I was talking to my boss, and the subject of spoofing data came up. He mentioned that for our current project, it would be nice to be able to spoof data on a per-request basis. I thought it would be a fun challenge to tackle, so I spent a few hours last Saturday and came up with a pretty elegant solution.&lt;/p&gt;  &lt;p&gt;Before I started, I had a few requirements:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It had to be completely config driven. The client and target WCF service were to have no idea what was going on. &lt;/li&gt;    &lt;li&gt;It was to be on a per-user/per-request basis. What this means is any dev could turn it on/off and it would only affect him. &lt;/li&gt;    &lt;li&gt;Extensible. If you didn’t like the data I mocked, or needed to be able to simulate slow network traffic, exceptions, large data, etc - you could. &lt;/li&gt;    &lt;li&gt;I only had 5 hours to come up with a solution. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font color="#008000"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;hr /&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In the &lt;a href="http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-part-1.aspx"&gt;previous post&lt;/a&gt;, I configured the client to write a header on any outgoing request if a specified cookie was found. I knew I could look for that header easily, but I had to find a way to change the behavior of a given operation.&lt;/p&gt;  &lt;p&gt;I spent a while searching around for something that would let me do this, but I couldn’t find anything that would let me inject new type over an existing on a per-call basis. It may be that something like &lt;a href="http://ninject.org/" rel="nofollow"&gt;Ninject&lt;/a&gt; would have done this, but from what I understand (having never used it) it would replace all instances of a given type with a new one, not targeted instances. If I am wrong, please let me know.&lt;/p&gt;  &lt;p&gt;Lucky for me, we had a nice little pattern going in our code. Each service was just a shell to call out into an appropriate controller, and the controller had all the meat and potatos. For example:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;public class MyService : IMySerivce
{
    public void DoSomeWork()
    {
        MyServiceController controller = new MyServiceController();
        controller.DoSomething();
    }
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;I extended this by creating a custom ServiceBase class that any WCF service we wanted to be mockable would inherit from. It provided a single item.&amp;#160; (There was also a base that all of our controllers were to inherit from.)&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class AppBaseService
{
    protected ITypeFactory typeFactory=new DefaultTypeFactory();

    public virtual ITypeFactory TypeFactory
    {
        get { return this.typeFactory; }
        set { this.typeFactory= value; }
    }

}

public class ControllerBase
{
    protected ITypeFactory typeFactory;

    public ControllerBase(ITypeFactory typeFactory)
    {
        this.typeFactory= typeFactory;
    }
}&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;Now is a good time to note that the DefaultTypeFactory just newed up whatever type you provided it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, with these changes any service that was to be mockable would look something like this:&lt;/p&gt;

&lt;pre class="brush: csharp;"&gt;public class MyService : ServiceBase, IMySerivce
{
    public void DoSomeWork()
    {
        MyServiceController controller = new MyServiceController(this.TypeFactory);
        controller.DoSomething();
    }
}

//and the inners of the controller looked like:
public class MyServiceController : ControllerBase
{
    public MyServiceController(ITypeFactory typeFactory)
    {
        this.typeFactory = typeFactory;
    }
    
    public void DoSomething()
    {
        IDataAccessClass dataAccess = this.typeFactory.CreateType(typeof(MyConcreteDataClass)) as IDataAccessClass
        dataAccess.ExecuteSomething();
    }
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This allowed me to set whatever ITypeFactory I want on a &lt;em&gt;per call basis&lt;/em&gt;. Like I said above, the default one would just new up whatever type you gave it, but I could easily create one that would return a new type based on whatever you asked for. So in the example above, instead of returning a new &lt;em&gt;MyConcreteDataClass&lt;/em&gt;, I could return a &lt;em&gt;MyMockedDataClass&lt;/em&gt; (assuming that implement &lt;em&gt;IDataAccessClass&lt;/em&gt;, of course!)&lt;/p&gt;

&lt;p&gt;With the grunt work out of the way, part 3 will be the WCF extensions that tied all this together.&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Codeharder/~3/r8fhQq0hric/post.aspx</link>
      <author>kaiser.jd@gmail.com</author>
      <comments>http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-–-part-2.aspx#comment</comments>
      <guid isPermaLink="false">http://codeharder.com/post.aspx?id=b743b65d-0009-4b3b-960a-d9ddff64b86f</guid>
      <pubDate>Mon, 05 Jul 2010 21:55:00 -0800</pubDate>
      <dc:publisher>jkaiser</dc:publisher>
      <pingback:server>http://codeharder.com/pingback.axd</pingback:server>
      <pingback:target>http://codeharder.com/post.aspx?id=b743b65d-0009-4b3b-960a-d9ddff64b86f</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://codeharder.com/trackback.axd?id=b743b65d-0009-4b3b-960a-d9ddff64b86f</trackback:ping>
      <wfw:comment>http://codeharder.com/post/Modifying-a-WCF-operation-at-runtime-–-part-2.aspx#comment</wfw:comment>
      <wfw:commentRss>http://codeharder.com/syndication.axd?post=b743b65d-0009-4b3b-960a-d9ddff64b86f</wfw:commentRss>
    <feedburner:origLink>http://codeharder.com/post.aspx?id=b743b65d-0009-4b3b-960a-d9ddff64b86f</feedburner:origLink></item>
  </channel>
</rss>

