<feed xmlns:dc="http://purl.org/dc/elements/1.1/" 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="http://www.w3.org/2005/Atom" xml:lang="en-GB">
    <title>X</title>
    <link rel="self" type="application/xml" href="http://geekswithblogs.net/cskardon/Atom.aspx" />
    <subtitle type="html">Coder, not artist.</subtitle>
    <id>http://geekswithblogs.net/cskardon/Default.aspx</id>
    <author>
        <name>Chris Skardon</name>
        <uri>http://geekswithblogs.net/cskardon/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 0.0.0.0">Subtext</generator>
    <updated>2013-03-27T01:14:39Z</updated>
    <entry>
        <title>Gotcha Got with AzureReader2 and ImageResizer</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2013/03/27/gotcha-got-with-azurereader2-and-imageresizer.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2013/03/27/gotcha-got-with-azurereader2-and-imageresizer.aspx</id>
        <published>2013-03-27T01:14:39-12:00:00</published>
        <updated>2013-03-27T01:14:39Z</updated>
        <content type="html">&lt;p&gt;After my &lt;a href="http://geekswithblogs.net/cskardon/archive/2013/02/26/imageresizer-azurereader2-and-wellhellip-azure-duh.aspx" target="_blank"&gt;previous post&lt;/a&gt; on getting AzureReader2 up and running with &lt;a title="Image Resizer" href="http://imageresizing.net/" target="_blank"&gt;ImageResizer&lt;/a&gt; – I ran into a problem – I had a page with a foreach on it, where I had a link to each fullsize image. It was all working fine, except for a couple which just wouldn’t work.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="/cloud/blah-1/example.jpg"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;img&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="/cloud/blah-1/example.jpg?maxwidth=70&amp;amp;amp;maxheight=80"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="/cloud/blah-2/hello%20world.jpg"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;img&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="/cloud/blah-2/Hello%20World.jpg?maxwidth=70&amp;amp;amp;maxheight=80"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Ending up with something like the above…&lt;/p&gt;

&lt;p&gt;Notice the ‘hello world’ link is in lower case, FOR SOME REASON.&lt;/p&gt;

&lt;p&gt;So the image shows on the page, but when you click on it, you get a 404 error – no image can be found. It’s the case, it needs to match the case in the Azure Blob…&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;GRRRRRRRRRRRRRRR&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/152534.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/152534.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/152534.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/152534.aspx</trackback:ping>
    </entry>
    <entry>
        <title>ImageResizer, AzureReader2 and well&amp;hellip; Azure (duh!)</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2013/02/26/imageresizer-azurereader2-and-wellhellip-azure-duh.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2013/02/26/imageresizer-azurereader2-and-wellhellip-azure-duh.aspx</id>
        <published>2013-02-26T00:36:26-12:00:00</published>
        <updated>2013-02-26T00:39:11Z</updated>
        <content type="html">&lt;p&gt;So, as part of my on-going project I’ve recently made the decision to shift all my images (uploaded by ME and my USERS) to Azure Blob Storage, instead of the quite frankly ridiculous ‘unique folder system’ ™ that I had been using.&lt;/p&gt;  &lt;p&gt;Now, originally I’d been using &lt;a title="Image Resizer" href="http://imageresizing.net/" target="_blank"&gt;ImageResizer&lt;/a&gt; which was working well, buut, it didn’t work (the way I was using it) with Azure Blobs (at least not in an efficient way).&lt;/p&gt;  &lt;p&gt;So. &lt;/p&gt;  &lt;p&gt;I do the standard of searching for ‘&lt;a title="ImageResizer Azure on Google" href="https://www.google.co.uk/search?q=imageresizer+azure" target="_blank"&gt;ImageResizer Azure&lt;/a&gt;’ on google, and first on the list: &lt;a href="http://imageresizing.net/plugins/azurereader" target="_blank"&gt;AzureReader plugin&lt;/a&gt;, which being me, before I’ve actually clicked on the link I’ve switched to Visual Studio and added the AzureReader nuget package to my site (which is MVC4, using Azure SDK 2 by-the-by). Whilst that installs, I switch back to the browser, and read this: &lt;a href="http://imageresizing.net/plugins/azurereader2"&gt;See AzureReader2 if you're using the Azure SDK 2.0&lt;/a&gt;. ah.&lt;/p&gt;  &lt;p&gt;Uninstall the AzureReader package, install AzureReader2 package. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Bump&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;That’s the sound of me hitting a wall. The documentation for both the AzureReader and AzureReader2 plugins are – well – minimalist, sure, they explain about the config settings (and the AzureReader page even explains how to add to azure) but not really on how you would use it. LUCKILY it’s pretty simple, so here goes, this is how to setup AzureReader2 with ImageResizer on an MVC4 Website.&lt;/p&gt;  &lt;h3&gt;1. Create a new Mvc4 site &lt;/h3&gt;  &lt;p&gt;(obviously if you have a site already, you can skip this bit) I’m going with an Empty site in my one (with no test project – basically because I’m lazy).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_6.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_thumb_2.png" width="244" height="136" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;2. Add the nuget packages you need&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font color="#0000ff"&gt;Windows Azure Storage (&amp;gt;= 2.0.4.0)&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font color="#0000ff"&gt;ImageResizer Web.Config Installation for MVC&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;ImageResizer Web.Config Installation &lt;/li&gt;    &lt;li&gt;&lt;font color="#0000ff"&gt;ImageResizer.Mvc – MVC-friendly utilities&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;ImageResizer &lt;/li&gt;    &lt;li&gt;&lt;font color="#0000ff"&gt;ImageResizer.Plugins.AzureReader2 – Process images from the Azure blobstore&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font color="#0000ff"&gt;Image Resizer Fluent Extensions for ASP.NET MVC&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;Image Resizer Fluent Extensions &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;(if you search for and install the ones in &lt;font color="#0000ff"&gt;blue&lt;/font&gt;, you will get the others installed)&lt;/p&gt;  &lt;h3&gt;3. Start the Storage Emulator&lt;/h3&gt;  &lt;p&gt;(Yes – I have made a &lt;strong&gt;big&lt;/strong&gt; assumption here that you have the Azure SDK installed – if you don’t – now would be a good time to install it, then come straight back here)&lt;/p&gt;  &lt;h3&gt;4. Create a container on the development storage&lt;/h3&gt;  &lt;p&gt; Easiest way to do this (for me) was to use Visual Studio’s Server Explorer:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_8.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_thumb_3.png" width="244" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Give it any name you want, I’ve gone with: &lt;em&gt;imageresizer-example&lt;/em&gt;&lt;/p&gt;  &lt;h3&gt;5. Upload an image to your blob container&lt;/h3&gt;  &lt;p&gt;Double click on the container, and click on the Upload Blob button:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_10.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_thumb_4.png" width="244" height="34" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then select a biggish image, and whack it in…&lt;/p&gt;  &lt;p&gt;So now you should have something like: &lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_12.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_thumb_5.png" width="244" height="22" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;6. Web.Config Edits&lt;/h3&gt;  &lt;p&gt;They gotta be done, and this is where the meat is, if we go down to the bottom of our Web.Config file, we should see a ‘resizer’ element, which will look something like:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;resizer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;plugins&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="MvcRoutingShim"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;plugins&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;resizer&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;We need to add our AzureReader2 plugin:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="AzureReader2"&lt;/span&gt; &lt;span class="attr"&gt;connectionString&lt;/span&gt;&lt;span class="kwrd"&gt;="UseDevelopmentStorage=true"&lt;/span&gt; &lt;span class="attr"&gt;endpoint&lt;/span&gt;&lt;span class="kwrd"&gt;="http://127.0.0.1:10000/devstoreaccount1/"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;This is the &lt;em&gt;minimum&lt;/em&gt; you need to get working.&lt;/p&gt;

&lt;h3&gt;7. Run&lt;/h3&gt;

&lt;p&gt;Press CTRL+F5 and ignore any errors you see – there’s no page to display in an empty solution – but that’s of no concern to us. My one started up on port 4598, so replace 4598 with whatever your port is.&lt;/p&gt;

&lt;p&gt;In the browser you have open – navigate to: http://localhost:&amp;lt;PORT&amp;gt;/azure/&amp;lt;container&amp;gt;/&amp;lt;file&amp;gt;, so in my case I’m going to: &lt;em&gt;http://localhost:4598/azure/imageresizer-example/example.jpg&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Did you get a 404 error? This is because the container we created earlier doesn’t have public permissions. To change this, we’re going to make it public at the blob level, (you can go container if you really want to).&lt;/p&gt;

&lt;h3&gt;8. Change public access&lt;/h3&gt;

&lt;p&gt;Right click on the container in the server explorer within visual studio, and go to the ‘Properties’ page. Here, set the PublicAccess property to ‘Blob’:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_13.png" rel="lightbox"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_thumb.png" width="244" height="128" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go back to your browser and refresh the page&lt;/p&gt;

&lt;p&gt;One thing to note is that the URL &lt;em&gt;despite&lt;/em&gt; what you typed in, now points to the Azure Blob url directly:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_15.png" rel="lightbox"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_thumb_1.png" width="244" height="72" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is because we’re not doing any modifications to the picture, so ImageResizer has just forwarded us directly to the blob, which is nice. But lets get ImageResizer doing a resize:&lt;/p&gt;

&lt;h3&gt;9. Resizing&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Very VERY simple&lt;/strong&gt;. Just add ?width=200 to the end of your url (obviously if the picture you are pulling isn’t at least 200 pixels wide this will have no effect). So:&lt;/p&gt;

&lt;p&gt;http://localhost:&amp;lt;PORT&amp;gt;/azure/&amp;lt;container&amp;gt;/&amp;lt;file&amp;gt;?width=200, &lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_17.png" rel="lightbox"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/ImageResizer-AzureReader2-and-well-Azure_F1F8/image_thumb_6.png" width="244" height="79" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aceness!&lt;/p&gt;

&lt;p&gt;Now – yes – I’m using Azure (now), but personally I’d rather hide that fact so if I decide to go S3, I don’t have to update all my URLs, luckily – this is all in the config, so last thing:&lt;/p&gt;

&lt;h3&gt;10. Web.Config changes (again)&lt;/h3&gt;

&lt;p&gt;Let’s edit our plugin line and add the ‘prefix’ attribute.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="AzureReader2"&lt;/span&gt; &lt;strong&gt;&lt;span class="attr"&gt;prefix&lt;/span&gt;&lt;span class="kwrd"&gt;="~/cloud/"&lt;/span&gt;&lt;/strong&gt; &lt;span class="attr"&gt;connectionString&lt;/span&gt;&lt;span class="kwrd"&gt;="UseDevelopmentStorage=true"&lt;/span&gt; &lt;span class="attr"&gt;endpoint&lt;/span&gt;&lt;span class="kwrd"&gt;="http://127.0.0.1:10000/devstoreaccount1/"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;now all the links will look like:&lt;/p&gt;

&lt;p&gt;http://localhost:&amp;lt;PORT&amp;gt;/&lt;strong&gt;cloud&lt;/strong&gt;/&amp;lt;container&amp;gt;/&amp;lt;file&amp;gt;?width=200&lt;/p&gt;

&lt;p&gt;which is pretty cool.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;ImageResizer is – well, Awesome. I’m personally going to be getting a license soon (I’ve not used this in production yet), but I can’t see any reason why I wouldn’t.&lt;/p&gt;

&lt;p&gt;If you need ImageResizing I have yet to find a better alternative – and it’s really not that expensive (by the by – full disclosure – I have &lt;strong&gt;not received anything&lt;/strong&gt; to influence me. This is all from personal research)&lt;/p&gt;

&lt;p&gt;I’ve put my files here: &lt;a title="http://sdrv.ms/V4DSnV" href="http://sdrv.ms/V4DSnV"&gt;http://sdrv.ms/V4DSnV&lt;/a&gt; but you’ll still need to create the azure container yourself. 7Zip appears to do a weird unzip and doesn’t create the empty folders as folders, so if it doesn’t load with a ‘missing app_data’ folder error – that’s why.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;Addendum&lt;/h3&gt;

&lt;p&gt;I believe – if you &lt;em&gt;are&lt;/em&gt; looking for a connection config element for a production system you want something like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="AzureReader2"&lt;/span&gt; &lt;span class="attr"&gt;connectionString&lt;/span&gt;&lt;span class="kwrd"&gt;="DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY"&lt;/span&gt; &lt;span class="attr"&gt;endpoint&lt;/span&gt;&lt;span class="kwrd"&gt;="http://NAME.blob.core.windows.net/"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Though – this is speculation – I can’t confirm the results as I’m not running this against a production server at the moment. I’ll let you know if it’s NOT that.&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/152233.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/152233.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/152233.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/152233.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Extending Expression Blend 4 &amp;amp; Blend for Visual Studio 2012</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2012/10/24/extending-expression-blend-4-amp-blend-for-visual-studio-2012.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2012/10/24/extending-expression-blend-4-amp-blend-for-visual-studio-2012.aspx</id>
        <published>2012-10-24T06:52:04-12:00:00</published>
        <updated>2012-10-24T06:52:04Z</updated>
        <content type="html">&lt;p&gt;Just getting this off the bat, I &lt;em&gt;presume&lt;/em&gt; this will also work for Blend 5, but I can’t confirm it…&lt;/p&gt;  &lt;p&gt;Anyhews, I imagine you’re here because you want to know how to create an addin for Blend, so let’s jump right in there!&lt;/p&gt;  &lt;p&gt;First, and foremost, we’re going to need to ensure our development environment has the right setup, so the checklist:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Visual Studio 2012&lt;/li&gt;    &lt;li&gt;Blend for Visual Studio 2012&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;OK, let’s create a new project (class library, .NET 4.5):&lt;/p&gt;  &lt;p&gt;Hello.Extension&lt;/p&gt;  &lt;p&gt;The ‘.Extension’ bit is &lt;strong&gt;very very&lt;/strong&gt; important. The addin will &lt;em&gt;not&lt;/em&gt; work unless it is named in this way. You can put whatever you want at the front, but it &lt;em&gt;has&lt;/em&gt; to have the extension bit.&lt;/p&gt;  &lt;p&gt;OK, so now we have a solution with one project. To this project we need to add references to the following things:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Microsoft.Expression.Extensibility (from c:\program files\Microsoft Visual Studio 11.0\Blend\   -- x86 folder if you are on an x64 windows install)&lt;/li&gt;    &lt;li&gt;Microsoft.Expression.Framework (same location as above)&lt;/li&gt;    &lt;li&gt;PresentationCore&lt;/li&gt;    &lt;li&gt;PresentationFramework&lt;/li&gt;    &lt;li&gt;WindowsBase&lt;/li&gt;    &lt;li&gt;System.ComponentModel.Composition&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Got them? ACE.&lt;/p&gt;  &lt;p&gt;Let’s now add a project to contain our control, so, create a new WPF Application project, cunningly named something like ‘Hello.Control’… (I’m creating a WPF application here, because I’m too lazy to dig up the correct references, and this will add all the ones I need &lt;img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Smile" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Extending-Expression-Blend-4--Blend-for-_10688/wlEmoticon-smile_2.png" /&gt;) &lt;/p&gt;  &lt;p&gt;Once that is created, delete the App.xaml and MainWindow.xaml files, we won’t be needing them. You will also need to change the properties of the project itself, so it is only a class library.&lt;/p&gt;  &lt;p&gt;Once that is done, let’s add a new UserControl, which will be this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="Hello.Control.HelloControl"&lt;/span&gt;
             &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
             &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
             &lt;span class="attr"&gt;xmlns:mc&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.openxmlformats.org/markup-compatibility/2006"&lt;/span&gt; 
             &lt;span class="attr"&gt;xmlns:d&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/expression/blend/2008"&lt;/span&gt; 
             &lt;span class="attr"&gt;mc:Ignorable&lt;/span&gt;&lt;span class="kwrd"&gt;="d"&lt;/span&gt; 
             &lt;span class="attr"&gt;d:DesignHeight&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt; &lt;span class="attr"&gt;d:DesignWidth&lt;/span&gt;&lt;span class="kwrd"&gt;="300"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;TextBlock&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="HELLO!!!"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grid&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;UserControl&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Impressive eh? &lt;/p&gt;

&lt;p&gt;Now, let’s reference the WPF project from the Extension library. All that’s left now is to code up our extension… &lt;/p&gt;

&lt;p&gt;So, add a class to the Extension project (name wise doesn’t matter), and make it implement the IPackage interface from the Microsoft.Expression.Extensibility library:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HelloExtension : IPackage { &lt;span class="rem"&gt;/**/&lt;/span&gt; }&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;We’ll implement the two methods we need to:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HelloExtension : IPackage
{
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Load(IServices services) { }
     &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Unload() { }
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;We’re only really concerned about the Load method in this case, as let’s face it, the extension we have doesn’t need to do a lot to bog off. The interesting thing about the Load method is that it receives an IServices instance. This allows us to get access to all the services that Expression provides, in this case we’re interested in one in particular, the ‘IWindowService’&lt;/p&gt;

&lt;p&gt;So, let’s get that bad boy…&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; IWindowService _windowService;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Load(IServices services)
{
    _windowService = services.GetService&amp;lt;IWindowService&amp;gt;();
}&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Nailed it… But why? The WindowService allows us to register our UserControl with Blend, which in turn allows people to activate and see it, which is a big plus point. So, let’s do that…&lt;/p&gt;

&lt;p&gt;We’ll create an ‘Initialize’ method to create our new control, and add it to the WindowService:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; HelloControl _helloControl;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize()
{
    _helloControl = &lt;span class="kwrd"&gt;new&lt;/span&gt; HelloControl();
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (_windowService.PaletteRegistry[&lt;span class="str"&gt;"HelloPanel"&lt;/span&gt;] == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        _windowService.RegisterPalette(&lt;span class="str"&gt;"HelloPanel"&lt;/span&gt;, _helloControl, &lt;span class="str"&gt;"Hello Window"&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;First we check that we’re not already registered, and if we’re not we register, the first argument is the identifier used by the service to, well, identify your extension. The second argument is the actual control, the third argument is the name that people will see in the ‘Windows’ menu of Blend itself (so important note here – don’t put anything embarrassing or (need I say it?) sweary…)&lt;/p&gt;

&lt;p&gt;There are only two things to do now - &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Call ‘Initialize()’ from our Load method, and &lt;/li&gt;

  &lt;li&gt;Export the class&lt;/li&gt;

  &lt;ol&gt;
    &lt;li&gt;This is easy money – add [Export(typeof(IPackage))] to the top of our class…&lt;/li&gt;
  &lt;/ol&gt;
&lt;/ol&gt;

&lt;p&gt;The full code will (should) look like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;[Export(&lt;span class="kwrd"&gt;typeof&lt;/span&gt; (IPackage))]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HelloExtension : IPackage
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; HelloControl _helloControl;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; IWindowService _windowService;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Load(IServices services)
    {
        _windowService = services.GetService&amp;lt;IWindowService&amp;gt;();
        Initialize();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Unload()
    {
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize()
    {
        _helloControl = &lt;span class="kwrd"&gt;new&lt;/span&gt; HelloControl();
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (_windowService.PaletteRegistry[&lt;span class="str"&gt;"HelloControl"&lt;/span&gt;] == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            _windowService.RegisterPalette(&lt;span class="str"&gt;"HelloControl"&lt;/span&gt;, _helloControl, &lt;span class="str"&gt;"Hello Window"&lt;/span&gt;);
    }
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;If you build this and copy it to your ‘Extensions’ folder in Blend (c:\program files\microsoft visual studio 11.0\blend\) and start Blend, you should see ‘Hello Window’ listed in the Window menu:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Extending-Expression-Blend-4--Blend-for-_10688/image_2.png" rel="lightbox"&gt;&lt;img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Extending-Expression-Blend-4--Blend-for-_10688/image_thumb.png" width="244" height="161" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That as they say is it!&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/151059.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/151059.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/151059.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/151059.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Neo4J and Azure and VS2012 and Windows 8</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2012/08/24/neo4j-and-azure-and-vs2012-and-windows-8.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2012/08/24/neo4j-and-azure-and-vs2012-and-windows-8.aspx</id>
        <published>2012-08-24T04:13:29-12:00:00</published>
        <updated>2012-08-24T04:13:29Z</updated>
        <content type="html">&lt;p&gt;Now, I know that this has been written about, but both of the main places (&lt;a href="http://www.richard-banks.org/2011/02/running-neo4j-on-azure.html"&gt;http://www.richard-banks.org/2011/02/running-neo4j-on-azure.html&lt;/a&gt; and &lt;a href="http://blog.neo4j.org/2011/02/announcing-neo4j-on-windows-azure.html"&gt;http://blog.neo4j.org/2011/02/announcing-neo4j-on-windows-azure.html&lt;/a&gt;) utilise VS2010, and well, I’m on VS2012 and Windows 8. Not that I think Win 8 had anything to do with it really, anyhews!&lt;/p&gt;  &lt;p&gt;I’m going to begin from the beginning, this is my first foray into running something on Azure, so it’s been a bit of a learning curve. But luckily the &lt;a title="Neo4j Homepage" href="http://neo4j.org/"&gt;Neo4J&lt;/a&gt; guys have got us started, so let’s download the VS2010 solution: &lt;a title="http://neo4j.org/get?file=Neo4j.Azure.Server.zip" href="http://neo4j.org/get?file=Neo4j.Azure.Server.zip"&gt;http://neo4j.org/get?file=Neo4j.Azure.Server.zip&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;OK, the other thing we’ll need is the VS2012 Azure SDK, so let’s get that as well: &lt;a href="http://www.windowsazure.com/en-us/develop/downloads/"&gt;http://www.windowsazure.com/en-us/develop/downloads/&lt;/a&gt; (I just did the full install).&lt;/p&gt;  &lt;p&gt;Now, unzip the VS2010 solution and let’s open it in VS2012:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;your location&amp;gt;\Neo4j.Azure.Server\Neo4j.Azure.Server.sln&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;One-way-upgrade? Yer! Ignore the migration report – we don’t care!&lt;/p&gt;  &lt;p&gt;Let’s build that sucker… Ahhh &lt;strong&gt;14 &lt;/strong&gt;errors… &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;WindowsAzure does not exist in the namespace ‘Microsoft’&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Not a problem right? We’ve installed the SDK, just need to update the references:&lt;/p&gt;  &lt;p&gt;We can ignore the Test projects, they don’t use Azure, we’re interested in the other projects, so what we’ll do is remove the broken references, and add the correct ones, so expand the references bit of each project:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_4.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_1.png" width="244" height="112" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;hunt out those yellow exclamation marks, and delete them! You’ll need to add the right ones back in (listed below), when you go to the ‘Add Reference’ dialog&lt;/p&gt;  &lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_6.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_2.png" width="244" height="68" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;make sure you have ‘Assemblies’ and ‘Framework’ selected before you seach (and search for ‘microsoft.win’ to narrow it down)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_2.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb.png" width="244" height="172" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So the references you need for each project are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font face="Courier New"&gt;&lt;strong&gt;CollectDiagnosticsData&lt;/strong&gt;&lt;/font&gt;       &lt;ul&gt;       &lt;li&gt;&lt;font face="Courier New"&gt;Microsoft.WindowsAzure.Diagnostics&lt;/font&gt; &lt;/li&gt;        &lt;li&gt;&lt;font face="Courier New"&gt;Microsoft.WindowsAzure.StorageClient&lt;/font&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;font face="Courier New"&gt;&lt;strong&gt;Diversify.WindowsAzure.ServiceRuntime&lt;/strong&gt;&lt;/font&gt;       &lt;ul&gt;       &lt;li&gt;&lt;font face="Courier New"&gt;Microsoft.WindowsAzure.CloudDrive&lt;/font&gt; &lt;/li&gt;        &lt;li&gt;&lt;font face="Courier New"&gt;Microsoft.WindowsAzure.ServiceRuntime&lt;/font&gt; &lt;/li&gt;        &lt;li&gt;&lt;font face="Courier New"&gt;Microsoft.WindowsAzure.StorageClient&lt;/font&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Right, so let’s build again… Sweet! No errors.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Now we need to setup our Blobs, I’m assuming you are using the most up-to-date Java you happened to have downloaded :) in my case that’s JRE7, and that is located in:&lt;/p&gt;  &lt;p&gt;C:\Program Files (x86)\Java\jre7&lt;/p&gt;  &lt;p&gt;So, zip up that folder into whatever you want to call it, I went with jre7.zip, and stuck it in a temp folder for now. In that same temp folder I also copied the neo4j zip I was using: neo4j-community-1.7.2-windows.zip&lt;/p&gt;  &lt;p&gt;OK, now, we need to get these into our Blob storage, this is where a lot of stuff becomes unstuck - I didn’t find any applications that helped me use the blob storage, one would crash (because my internet speed is so slow) and the other just didn’t work – sure it &lt;em&gt;looked&lt;/em&gt; like it had worked, but when push came to shove it didn’t. &lt;/p&gt;  &lt;p&gt;So this is how I got my files into Blob (local first):&lt;/p&gt;  &lt;p&gt;1. Run the ‘Storage Emulator’ (just search for that in the start menu)&lt;/p&gt;  &lt;p&gt;2. That takes a little while to start up so fire up another instance of Visual Studio in the mean time, and create a new Console Application.&lt;/p&gt;  &lt;p&gt;3. Manage Nuget Packages for that solution and add ‘Windows Azure Storage’&lt;/p&gt;  &lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_10.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_4.png" width="244" height="35" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now you’re set up to add the code:&lt;/p&gt;  &lt;blockquote&gt;   &lt;div class="csharpcode"&gt;     &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()&lt;/pre&gt;

    &lt;pre&gt;{&lt;/pre&gt;

    &lt;pre class="alt"&gt;    CloudStorageAccount cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;&lt;/pre&gt;

    &lt;pre&gt;    CloudBlobClient client = cloudStorageAccount.CreateCloudBlobClient();&lt;/pre&gt;

    &lt;pre class="alt"&gt;    client.Timeout = TimeSpan.FromMinutes(30);&lt;/pre&gt;

    &lt;pre&gt;    CloudBlobContainer container = client.GetContainerReference(&lt;span class="str"&gt;"neo4j"&lt;/span&gt;); &lt;span class="rem"&gt;//This will create it as well&lt;/span&gt;&lt;/pre&gt;

    &lt;pre class="alt"&gt; &lt;/pre&gt;

    &lt;pre&gt;    UploadBlob(container, &lt;span class="str"&gt;"jre7.zip"&lt;/span&gt;, &lt;span class="str"&gt;"c:\\temp\\jre7.zip"&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre class="alt"&gt;    UploadBlob(container, &lt;span class="str"&gt;"neo4j-community-1.7.2-windows.zip"&lt;/span&gt;, &lt;span class="str"&gt;"c:\\temp\\neo4j-community-1.7.2-windows.zip"&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre&gt;}&lt;/pre&gt;

    &lt;pre class="alt"&gt; &lt;/pre&gt;

    &lt;pre&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UploadBlob(CloudBlobContainer container, &lt;span class="kwrd"&gt;string&lt;/span&gt; blobName, &lt;span class="kwrd"&gt;string&lt;/span&gt; filename)&lt;/pre&gt;

    &lt;pre class="alt"&gt;{&lt;/pre&gt;

    &lt;pre&gt;    CloudBlob blob = container.GetBlobReference(blobName);&lt;/pre&gt;

    &lt;pre class="alt"&gt; &lt;/pre&gt;

    &lt;pre&gt;    &lt;span class="kwrd"&gt;using&lt;/span&gt; (FileStream fileStream = File.OpenRead(filename))&lt;/pre&gt;

    &lt;pre class="alt"&gt;        blob.UploadFromStream(fileStream);&lt;/pre&gt;

    &lt;pre&gt;}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;This will upload the files to your local storage account (&lt;em&gt;to switch to an Azure one, you’ll need to create a storage account, and use those credentials when you make your CloudStorageAccount above&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;To test you’ve got them uploaded correctly, go to: &lt;/p&gt;

&lt;p&gt;&lt;a href="http://localhost:10000/devstoreaccount1/neo4j/jre7.zip"&gt;&lt;font face="Courier New"&gt;http://localhost:10000/devstoreaccount1/neo4j/jre7.zip&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and you will hopefully download the zip file you just uploaded.&lt;/p&gt;

&lt;p&gt;Now that those files are there, we are ready for some final configuration…&lt;/p&gt;

&lt;p&gt;Right click on the Neo4jServerHost role in the Neo4j.Azure.Server cloud project:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_12.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_5.png" width="244" height="145" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the ‘Settings’ tab and we’ll need to do some changes – by default, the 1.7.2 edition of neo4J unzips to:&lt;/p&gt;

&lt;p&gt;&lt;font face="Courier New"&gt;neo4j-community-1.7.2&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;So, we need to update all the ‘neo4j-1.3.M02’ directories to be ‘neo4j-community-1.7.2’, we also need to update the Java runtime location, so we start with this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_14.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_6.png" width="244" height="201" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and end with this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_16.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_7.png" width="244" height="200" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, I also changed the Endpoints settings, to be HTTP (from TCP) and to have a port of 7410 (mainly because that’s straight down on the numpad)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_18.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_8.png" width="244" height="24" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last ‘gotcha’ is some hard coded consts, which had me looking for ages, they are in the ‘ConfigSettings’ class of the ‘Neo4jServerHost’ project, and the ones we’re interested in are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Neo4jFileName &lt;/li&gt;

  &lt;li&gt;JavaZipFileName &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Change those both to what that should be.&lt;/p&gt;

&lt;p&gt;OK&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nearly there (I promise)!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the ‘Compute Emulator’ (same deal with the Start menu), in your system tray you should have an Azure icon, when the compute emulator is up and running, right click on the icon and select ‘Show Compute Emulator UI’&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_20.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_9.png" width="244" height="143" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The last steps!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make sure the ‘Neo4j.Azure.Server’ cloud project is set up as the start project and let’s hit &lt;/p&gt;

&lt;p align="center"&gt;&lt;font size="7"&gt;F5&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;tension mounts, the build takes place (you need to accept the UAC warning) and VS does it’s stuff. If you look at the Compute Emulator UI you’ll see some log stuff (which you’ll need if this goes awry – but it won’t don’t worry!)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_22.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_10.png" width="244" height="97" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a bit, the console and a Java window will pop up:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_24.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_11.png" width="244" height="42" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then the console will bog off, leaving just the Java one, and if we switch back to the Compute Emulator UI and scroll up we should be able to see a line telling us the port number we’ve been assigned (in my case 7411):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_26.png" rel="lightbox"&gt;&lt;img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://gwb.blob.core.windows.net/cskardon/Windows-Live-Writer/Neo4J-and-Azure_E0B2/image_thumb_12.png" width="244" height="13" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(If you can’t see it, don’t worry.. press CTRL+A on the emulator, then CTRL+C, copy all the text and paste it into something like Notepad, then just do a Find for ‘port’ you’ll soon see it)&lt;/p&gt;

&lt;p&gt;Go to your favourite browser, and head to: &lt;a href="http://localhost:YOURPORT/"&gt;http://localhost:YOURPORT/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and you should see the &lt;strong&gt;WebAdmin&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;See you on the cloud side hopefully!&lt;/p&gt;

&lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author"&gt;Chris&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PS Other gotchas!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;OK, I’ve been caught out a couple of times:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;I had an instance of Neo4J running as a service on my machine, the Azure instance wanted to run the https version of the server on the same port as the Service was running on, and so Java would complain that the port was already in use.. &lt;/li&gt;

  &lt;li&gt;The first time I converted the project, it didn’t update the version of the Azure library to load, in the App.Config of the Neo4jServerHost project, and VS would throw an exception saying it couldn’t find the Azure dll version 1.0.0.0. &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/150530.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/150530.aspx</wfw:comment>
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/150530.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/150530.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Mocking ITable&amp;lt;T&amp;gt;</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2012/02/06/mocking-itablelttgt.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2012/02/06/mocking-itablelttgt.aspx</id>
        <published>2012-02-06T21:12:20-12:00:00</published>
        <updated>2012-02-06T21:12:20Z</updated>
        <content type="html">&lt;p&gt;I have to do some mocking of an &lt;a title="ITable on MSDN" href="http://msdn.microsoft.com/en-us/library/system.data.linq.itable.aspx" target="_blank"&gt;ITable&lt;/a&gt; to be able to test some of my code, as you may imagine this is the point where we’re crossing the data boundary… Now, ITable is a total bugger to mock, I’ve tried on (at least) 3 separate occasions to get it mocked, and have only now, finally achieved an 80% solution.&lt;/p&gt;  &lt;p&gt;(Nothing is ever 100%)&lt;/p&gt;  &lt;p&gt;I’m not using any mock framework, they just take too long to setup (&lt;em&gt;in this case&lt;/em&gt;) and instead have a concrete class that implements ITable and uses an &lt;a href="http://msdn.microsoft.com/en-us/library/5y536ey6.aspx" target="_blank"&gt;IList&lt;/a&gt; as it’s base.&lt;/p&gt;  &lt;p&gt;Without further ado:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq.Expressions;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MockTable&amp;lt;T&amp;gt; : ITable&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IList&amp;lt;T&amp;gt; _entities;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; MockTable(IList&amp;lt;T&amp;gt; entities)
    {
        _entities = entities;
    }

    &lt;span class="preproc"&gt;#region&lt;/span&gt; ITable&amp;lt;T&amp;gt; Members

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerator&amp;lt;T&amp;gt; GetEnumerator()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; _entities.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; GetEnumerator();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Expression Expression 
    { 
        get 
        { 
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _entities.AsQueryable().Expression; 
        } 
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Type ElementType 
    { 
        get 
        { 
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _entities.AsQueryable().ElementType; 
        } 
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IQueryProvider Provider 
    { 
        get 
        { 
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _entities.AsQueryable().Provider; 
        } 
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InsertOnSubmit(T entity)
    {
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Attach(T entity)
    {
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DeleteOnSubmit(T entity)
    {
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
    }
    &lt;span class="preproc"&gt;#endregion&lt;/span&gt; ITable&amp;lt;T&amp;gt; Members
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;To use, in your test, let’s say you have an IDataContext (and why not) looking like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IDataContext
{
    ITable&amp;lt;Person&amp;gt; People { get; set; }
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;You can then mock this interface like so:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;[TestMethod]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Something_DoesSomething_WhenSomething()
{
    &lt;span class="rem"&gt;//Create seed list&lt;/span&gt;
    var people = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Person&amp;gt;{ &lt;span class="kwrd"&gt;new&lt;/span&gt; Person{Name = &lt;span class="str"&gt;"Chris Skardon"&lt;/span&gt;} };
    
    &lt;span class="rem"&gt;//Create new Mock&lt;/span&gt;
    var dataContextMock = &lt;span class="kwrd"&gt;new&lt;/span&gt; Mock&amp;lt;IDataContext&amp;gt;();
    
    &lt;span class="rem"&gt;//Setup the People ITable property&lt;/span&gt;
    dataContextMock
        .Setup(dc =&amp;gt; dc.People)
        .Returns(&lt;span class="kwrd"&gt;new&lt;/span&gt; MockTable&amp;lt;Person&amp;gt;(people));
    
    &lt;span class="rem"&gt;/* Asserts etc */&lt;/span&gt;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;It’s obviously not perfect, I haven’t bothered with several methods, but I’ll get to them later…&lt;/p&gt;

&lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/148621.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/148621.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/148621.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/148621.aspx</trackback:ping>
    </entry>
    <entry>
        <title>CSharpCodeDomClientCodeGenerator encountered a fatal exception</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2012/01/23/csharpcodedomclientcodegenerator-encountered-a-fatal-exception.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2012/01/23/csharpcodedomclientcodegenerator-encountered-a-fatal-exception.aspx</id>
        <published>2012-01-23T22:00:14-12:00:00</published>
        <updated>2012-01-23T22:00:14Z</updated>
        <content type="html">&lt;p&gt;I’ve been battling this now for an hour or so, and as all the reponses I’ve seen online haven’t really helped, I thought I’d whack this up..&lt;/p&gt;  &lt;p&gt;The error I got was:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The code generator 'Microsoft.ServiceModel.DomainServices.Tools.CSharpCodeDomClientCodeGenerator' encountered a fatal exception and could not generate code for project 'TheProject.csproj':     &lt;br /&gt;Exception has been thrown by the target of an invocation.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now, searching online comes up with loads of things, but the most important one I found was on &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/details/662780/exception-thrown-by-the-target-of-an-invocation-in-microsoft-ria-client-targets" target="_blank"&gt;Microsoft Connect&lt;/a&gt;. It’s actually a comment from ArielBH, which says:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;From my exprience it is connected to the DataAnnotions attributes when it is looking for types in the resx.     &lt;br /&gt;When I tried to manipulate the Buisness Applocation template and move Ria Services link and files to other assembly I had the same issue. When I removed all references to those resx files this issue disappered.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I indeed have a class using DataAnnotations linking to a resx file… So, I removed all the attributes linking to the resx files, (i.e. removing all the validation…) and did another compile…&lt;/p&gt;  &lt;p&gt;At this point RIA decides to actually give the correct error, that a method was missing… &lt;/p&gt;  &lt;p&gt;So, point of note is that the DataAnnotations will mask the actual error, but once you’ve fixed the error, putting the DataAnnotations back will be fine…&lt;/p&gt;  &lt;p&gt;Grrrr&lt;/p&gt; &lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author" alt="Google+"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/148458.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/148458.aspx</wfw:comment>
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/148458.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/148458.aspx</trackback:ping>
    </entry>
    <entry>
        <title>InitParams in Silverlight &amp;ndash; passed via MVC</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2012/01/06/initparams-in-silverlight-ndash-passed-via-mvc.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2012/01/06/initparams-in-silverlight-ndash-passed-via-mvc.aspx</id>
        <published>2012-01-06T00:40:53-12:00:00</published>
        <updated>2012-01-06T00:40:53Z</updated>
        <content type="html">&lt;p&gt;The old skool way of passing InitParams in aspx is well documented, adding a:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="initParams"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="&amp;lt;%=InitParams%&amp;gt;"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;which is accessing the public ‘InitParams’ &lt;em&gt;member&lt;/em&gt; in the code-behind file, which is inevitably set up via the ‘Page_Init’ handler.&lt;/p&gt;

&lt;p&gt;All well and good, but not practical in MVC, so… how to do this?&lt;/p&gt;

&lt;p&gt;(NB. This is just how I’ve done it, it’s not the only solution)&lt;/p&gt;

&lt;p&gt;There are a few things to change:&lt;/p&gt;

&lt;h2&gt;1. The Model&lt;/h2&gt;

&lt;p&gt;I’ve created a SilverlightHostModel, it only has one property in it (at the moment), to hold the InitParams:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Webby.Models
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SilverlightHostModel
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; InitParams { get; set; }
    }
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;h2&gt;2. The Controller&lt;/h2&gt;

&lt;p&gt;The controller is going to create the model and pass it to the view..&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ViewResult Ria()
{
    SilverlightHostModel host = &lt;span class="kwrd"&gt;new&lt;/span&gt; SilverlightHostModel();
    host.InitParams = &lt;span class="str"&gt;"IpAddress="&lt;/span&gt; + System.Web.HttpContext.Current.Request.ServerVariables[&lt;span class="str"&gt;"REMOTE_ADDR"&lt;/span&gt;];

    &lt;span class="kwrd"&gt;return&lt;/span&gt; View(host);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;h2&gt;3. The View&lt;/h2&gt;

&lt;p&gt;The view needs to be strongly-typed to the Model, so we add this to the top of the new view:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;@model Webby.Models.SilverlightHostModel&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;and where we’re hosting the &lt;a href="http://www.silverlight.net"&gt;Silverlight&lt;/a&gt; control itself, we change the param to read:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="initParams"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="@Model.InitParams"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;h2&gt;4. The App.xaml.cs Application_Startup&lt;/h2&gt;

&lt;p&gt;You (I presume) already have this done, but you would get your new parameter like so&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Application_Startup(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, StartupEvents e)
{
    &lt;span class="rem"&gt;//Get the ip address from InitParams&lt;/span&gt;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; ip = e.InitParams[&lt;span class="str"&gt;"IpAddress"&lt;/span&gt;];

    &lt;span class="kwrd"&gt;this&lt;/span&gt;.RootVisual = &lt;span class="kwrd"&gt;new&lt;/span&gt; MainPage();
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Done!&lt;/p&gt;

&lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author" alt="Google+"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/148259.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/148259.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/148259.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/148259.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Ajaxy</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/11/10/ajaxy.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/11/10/ajaxy.aspx</id>
        <published>2011-11-10T08:16:05-12:00:00</published>
        <updated>2011-11-10T08:16:05Z</updated>
        <content type="html">&lt;p&gt;Today is the big day, the day I attempt to use Ajax in the app… &lt;/p&gt;  &lt;p&gt;I’ve never done this (well, tell a lie, I’ve done it in a ‘tutorial’ site, but that was a while ago now), so it’s going to be interesting.. &lt;/p&gt;  &lt;p&gt;OK, basics first, let’s start with the @Ajax.ActionLink&lt;/p&gt;  &lt;p&gt;Right, first stab:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;@Ajax.ActionLink(&lt;span class="str"&gt;"Click to get latest"&lt;/span&gt;,
                 &lt;span class="str"&gt;"LatestEntry"&lt;/span&gt;,
                 &lt;span class="kwrd"&gt;new&lt;/span&gt; AjaxOptions
                   {
                      UpdateTargetId = &lt;span class="str"&gt;"ajaxEntrant"&lt;/span&gt;,
                      InsertionMode = InsertionMode.Replace,
                      HttpMethod = &lt;span class="str"&gt;"GET"&lt;/span&gt;
                   })&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;As far as I’m aware, I’m asking to get the ‘LatestEntry’ from the current controller, and in doing so, I will replace the #ajaxEntrant DOM bit with the result. So. I guess I’d better get the result working…&lt;/p&gt;

&lt;p&gt;To the controller!&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; PartialResult LatestEntry()
{
    var entrant =_db.Entrants.OrderByDescending(e =&amp;gt; e.Id).Single();
    &lt;span class="kwrd"&gt;return&lt;/span&gt; PartialView(&lt;span class="str"&gt;"_Entrant"&lt;/span&gt;, entrant);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Pretty simple, just returns the last entry in a PartialView… but! I have yet to make my partial view, so onto that!&lt;/p&gt;

&lt;pre class="csharpcode"&gt;@model Webby.Entrant

&amp;lt;div &lt;span class="kwrd"&gt;class&lt;/span&gt;=&lt;span class="str"&gt;"entrant"&lt;/span&gt;&amp;gt;
    &amp;lt;h4&amp;gt;@Model.Name&amp;lt;/h4&amp;gt;
&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Again, super simple, (I’m really just testing at this point)…&lt;/p&gt;

&lt;p&gt;All the code is now there (&lt;em&gt;as far as I know&lt;/em&gt;), so F5 and in… &lt;/p&gt;

&lt;p&gt;And once again, in the traditionally disappointing way of the norm, it doesn’t work, sure… it &lt;em&gt;opens&lt;/em&gt; the right view, but it doesn’t replace the #ajaxEntry DOM element, rather it replaces the whole page… The source code (again, as far as I know) looks ok:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;data-ajax&lt;/span&gt;&lt;span class="kwrd"&gt;="true"&lt;/span&gt; &lt;span class="attr"&gt;data-ajax-method&lt;/span&gt;&lt;span class="kwrd"&gt;="GET"&lt;/span&gt; &lt;span class="attr"&gt;data-ajax-mode&lt;/span&gt;&lt;span class="kwrd"&gt;="replace"&lt;/span&gt; &lt;span class="attr"&gt;data-ajax-update&lt;/span&gt;&lt;span class="kwrd"&gt;="#ajaxEntrants"&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="/Entrants/LatestEntrant"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Click to get latest&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Changing the InsertionMode to any of the other modes has the same effect..&lt;/p&gt;

&lt;p&gt;It’s not the DOM name either, changing that has the same effect.. i.e. none.&lt;/p&gt;

&lt;p&gt;It’s not the partial view either, just making that a &amp;lt;p&amp;gt; has (&lt;em&gt;again&lt;/em&gt;) no effect…&lt;/p&gt;

&lt;p&gt;Ahhhhh --- what a schoolboy error… I had neglected (ahem) to actually put the script bit into the calling page (another save from &lt;a href="http://stackoverflow.com/questions/4557021/mvc-3-ajax-load-partial-view-into-div"&gt;stackoverflow&lt;/a&gt;):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="@Url.Content("&lt;/span&gt;~/&lt;span class="attr"&gt;Scripts&lt;/span&gt;/&lt;span class="attr"&gt;jquery&lt;/span&gt;.&lt;span class="attr"&gt;unobtrusive-ajax&lt;/span&gt;.&lt;span class="attr"&gt;js&lt;/span&gt;&lt;span class="kwrd"&gt;")"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;I’ve now stuck that into the _Layout.cshtml view &lt;em&gt;temporarily&lt;/em&gt; to aid the development process… :) &lt;/p&gt;

&lt;p&gt;Onwards and upwards!&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author" alt="Google+"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/147649.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/147649.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/147649.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/147649.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Comprehensive redesigns</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/11/09/comprehensive-redesigns.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/11/09/comprehensive-redesigns.aspx</id>
        <published>2011-11-09T07:23:06-12:00:00</published>
        <updated>2011-11-09T07:23:06Z</updated>
        <content type="html">&lt;p&gt;So, last night I realised that I’d made some bad decisions with the database, structure and naming, so… I’ve now refactored it all, and I’m feeling… hmmm… meh about it. I suspect I will redo it all later, but for now it will do….&lt;/p&gt;  &lt;p&gt;I’ve also come to the conclusion that I was maybe trying too much for the initial release, so as a consequence I have removed one part of the project… (which, by-the-by, I intend to have published in a month or so – and yes Andy, that is one month longer than I mentioned to you in that email :)) &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;@Html.DisplayFor()&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I find myself using DisplayFor a lot at the moment, is this correct? I mean – it works, but is that really only for forms? Do I need to use it? &lt;em&gt;Should&lt;/em&gt; I use it?&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/147635.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/147635.aspx</wfw:comment>
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/147635.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/147635.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Registering&amp;hellip;</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/10/26/registeringhellip.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/10/26/registeringhellip.aspx</id>
        <published>2011-10-26T08:50:53-12:00:00</published>
        <updated>2011-10-27T20:02:39Z</updated>
        <content type="html">&lt;p&gt;So, I want potential clients to have to enter the least amount of info possible to get an account, to that end, I really don’t see the benefit of a username &lt;em&gt;and&lt;/em&gt; email address, I’d rather just use the email address.&lt;/p&gt;
&lt;p&gt;Pretty easy, edit the Register.cshtml to remove all traces of a ‘username’ field…&lt;/p&gt;
&lt;p&gt;Edit the controller so that it now reads:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;
   model.UserName = model.Email;
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (ModelState.IsValid) { &lt;span class="rem"&gt;/*...*/&lt;/span&gt; }&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;F5 and … no&lt;/p&gt;
&lt;p&gt;Hmmm, turns out the ModelState isn’t valid, and that’s down to the fact that I’ve left in the ‘Required’ bit on the UserName property in the AccountModels RegisterModel class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;
    &lt;span class="rem"&gt;//[Required]&lt;/span&gt;
    [Display(Name = &lt;span class="str"&gt;"User name"&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; UserName { get; set; }&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;Conceivably, I don’t really need that property at all, and can probably just do away with it later, but for now it can remain… Bigger fish to fry and all that…&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;a title="Chris Skardon is on Google+" alt="Google+" rel="author" href="http://plus.google.com/101339052790440625852/about"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/147468.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/147468.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/147468.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/147468.aspx</trackback:ping>
    </entry>
</feed>