<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss version="2.0"><channel><title>bradygaster.com</title><link>http://bradygaster.com:80/</link><description>bradygaster.com</description><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/brady-gaster" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="brady-gaster" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>WebMatrix on Web Camps TV</title><link>http://bradygaster.com:80/webmatrix-on-web-camps-tv</link><description>&lt;p&gt;This week I had the absolute privelege of hosting the Channel 9 Web Camps TV show. The show featured &lt;a href="http://www.microsoft.com/web/webmatrix/next/" target="_blank"&gt;WebMatrix&lt;/a&gt;, and our guest was &lt;a href="https://twitter.com/#!/vishalrjoshi" target="_blank"&gt;Vishal Joshi&lt;/a&gt;, Lead Program Manager for the product. Vishal highlights some of the great new features available in the new version of WebMatrix, which you can download for free in under 2 minutes. The product is impressive and offers just about every single thing a web developer would need. From database edits to code completion across C#, CSS, HTML, and &lt;strong&gt;even PHP code completion&lt;/strong&gt;, WebMatrix has you covered. Take a few minutes and check out the new features you can get for free on &lt;a href="http://channel9.msdn.com/Shows/Web+Camps+TV/Web-Camps-TV-12-Vishal-Joshi-talks-about-WebMatrix-v2" target="_blank"&gt;Web Camps TV&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;</description><pubDate>Thu, 26 Jan 2012 05:58:48 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/webmatrix-on-web-camps-tv</guid></item><item><title>Codemash SignalR Talk</title><link>http://bradygaster.com:80/codemash-signalr-talk</link><description>&lt;p&gt;If you attended my SignalR talk at Codemash, thank you so much for your time. I had a blast at Codemash, and really enjoyed the talk. It was a great audience with some good conversations in the hallway afterward. If you attended the session and want to get your hands on the deck and code, this is the place.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygasterblobs.blob.core.windows.net/talks/Codemash.zip"&gt;The deck and code are here&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;Safe travels home, everyone! I look forward to next year's Codemash!&lt;/p&gt;</description><pubDate>Tue, 17 Jan 2012 16:32:57 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/codemash-signalr-talk</guid></item><item><title>The Azure Service Bus Simplifier</title><link>http://bradygaster.com:80/service-bus-simplifier</link><description>&lt;p&gt;One of the things that makes enterprise service development of any type difficult is the requirement to learn that ESB’s programming model. The Windows Azure has a very simple programming model already, but for those developers getting started with Azure Service Bus programming for the first time who mainly want a simple publish/subscribe-style bus architecture limited to a few types of custom messages, I’ve created a NuGet package called the &lt;em&gt;ServiceBusSimplifier. &lt;/em&gt;&lt;/p&gt; &lt;p&gt;If all you need from the Azure service bus is a simple implementation of the pub/sub model there’s no longer a need to learn all the plumbing and deeper detail work. Of course, there’s nothing&lt;em&gt; wrong &lt;/em&gt;with learning the plumbing and doing so is encouraged, but for those just getting started with Azure’s Topic-based messaging, the &lt;em&gt;ServiceBusSimplifier &lt;/em&gt;package might be just the answer. It provides extremely basic access to publishing and subscribing custom messages through the Azure service bus. The video below demonstrates how to use the package, and there is some detailed usage instruction below the video.&lt;/p&gt;&lt;iframe height="315" src="http://www.youtube.com/embed/E_XBHxgxDnE" frameborder="0" width="420" allowfullscreen&gt;&lt;/iframe&gt; &lt;h2&gt;Usage and Source Code&lt;/h2&gt; &lt;p&gt;If you’re just trying to use the package to simplify your entry into using Azure’s service bus, just pull down the &lt;a title="The ServiceBusSimplifier NuGet Package Home Page" href="https://nuget.org/packages/ServiceBusSimplifier" target="_blank"&gt;package from NuGet&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_thumb_2.png" width="927" height="91"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;If you’d like to peruse the source code, which the remaining sections of this post will take a slightly deeper dive into an element at a time or you’d like to add functionality to it, the code is available as a &lt;a title="The ServiceBusSimplifier GitHub Repository" href="https://github.com/bradygaster/ServiceBusSimplifier" target="_blank"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt; &lt;h2&gt;Setting up the Connection&lt;/h2&gt; &lt;p&gt;To set up the service bus connection, call the &lt;em&gt;Setup &lt;/em&gt;method, passing it an instance of the class the package uses to supply authentication and connectivity information to the service bus, the &lt;em&gt;&lt;a title="The code for the request class in GitHub" href="https://github.com/bradygaster/ServiceBusSimplifier/blob/master/ServiceBusSimplifier/InitializationRequest.cs" target="_blank"&gt;InitializationRequest&lt;/a&gt; &lt;/em&gt;class. The &lt;em&gt;ServiceBus&lt;/em&gt; abstraction class offers a Fluent interface, so the methods could be chained together if need be. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_thumb_3.png" width="816" height="309"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h2&gt;Subscribing&lt;/h2&gt; &lt;p&gt;As mentioned earlier, the &lt;em&gt;ServiceBus&lt;/em&gt; abstraction offers very simple usage via self-documenting methods. The code below has been augmented to subscribe to an instance of a custom class. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_thumb_4.png" width="816" height="344"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Note, there are no special requirements or inheritance chain necessary for a class to be passed around within this implementation. The class below is the one being used in this example, and in the GitHub repository. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_thumb_5.png" width="816" height="221"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Finally, here’s the &lt;em&gt;HandleSimpleMessage &lt;/em&gt;method from the program class. Note, this could have been passed as an anonymous method rather than a pointer to a class member or static member. The video demonstration above shows such a usage, but it’s important to note that either a static, instance, or anonymous method would be appropriate being passed to the &lt;em&gt;Subscribe&lt;/em&gt; method. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_thumb_6.png" width="816" height="222"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h2&gt;Publishing&lt;/h2&gt; &lt;p&gt;The final piece of this demonstration involves publishing messages into the Azure service bus. The code below shows how to publish a message to the bus, using the self-explanatory &lt;em&gt;Publish &lt;/em&gt;method&lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Azure-Service-Bus-Simplifier_A39C/image_thumb_7.png" width="816" height="315"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Hopefully, the &lt;em&gt;ServiceBusSimplifier &lt;/em&gt;package will ease your development experience with the Azure service bus. Even though the Azure service bus is dirt-simple to use, this handy utility library will give your code 1-line access to efficient publish/subscribe mechanisms built into the cloud. Happy coding!&lt;/p&gt;</description><pubDate>Thu, 29 Dec 2011 22:03:00 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/service-bus-simplifier</guid></item><item><title>Blob Storage of Kinectonitor Images</title><link>http://bradygaster.com:80/blob-storage-of-kinectonitor-images</link><description>&lt;p&gt;The Kinectonitor has received a lot of commentary and I’ve received some great ideas and suggestions on how it could be improved. There are a few architectural aspects about it that gave me some heartburn. One of those areas is in that, I failed to make use of any of Azure’s storage functionality to store the images. This post sums up how Blob Storage was added to the Kinectonitor’s architecture so that images could be stored in the cloud, not on the individual observer site’s web servers. &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font color="#434343"&gt;So we’re taking all these pictures with our Kinect device. Where are we storing the images? Are they protected by disaster recovery procedures? What if I need to look at historical evidence to see photos of intruders from months or years ago? Where will all of this be stored? Do I have to worry about buying a new hard drive for all those images?&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;A legitimate concern that can be solved by storing the photographs taken by the Kinect into the Azure cloud. The video below shows a test harness I use in place of the Kinect device. This tiny application allows me to select an image from my hard drive. The image content is then sent along the same path as the images that would be captured and sent into the cloud by the Kinect. This video demonstrates the code running at debug time. Using &lt;a href="http://clumsyleaf.com/products/cloudxplorer" target="_blank"&gt;ClumsyLeaf’s CloudXplorer&lt;/a&gt; client I then show the files as they’ve been stored in the local development storage account’s Blob storage container. &lt;/p&gt;&lt;iframe height="315" src="http://www.youtube.com/embed/XYwdbn0D5Fk" frameborder="0" width="560" allowfullscreen&gt;&lt;/iframe&gt; &lt;p&gt;Now we’ll take a slightly deeper dive into the changes that have been made in this update of the Kinectonitor source code. If you’d like to grab that code it is &lt;a title="The Kinectonitor Source on GitHub" href="https://github.com/bradygaster/Kinectonitor" target="_blank"&gt;available on GitHub&lt;/a&gt;.&lt;/p&gt; &lt;h2&gt;The Kinectonitor Worker Role&lt;/h2&gt; &lt;p&gt;This new project basically serves the purpose of listening for &lt;em&gt;ImageMessage&lt;/em&gt; instances. There’s not a whole lot of code in the worker role. We’ll examine its purpose and functionality in more detail in a moment. For now, take a look at the role’s code in the Object Browser to get a quick understanding of what functions the role will provide the overall Kinectonitor architecture. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_thumb_1.png" width="644" height="416"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;In the previous release of the code, &lt;em&gt;ImageMessage &lt;/em&gt;instances were the only things being used to pass information from the Kinect monitoring client, to the Azure Service Bus, and then back down to the ASP.NET MVC client site. This release of the code simplifies things somewhat, especially around the service bus area. The previous code actually shipped the binary data into &lt;em&gt;and &lt;/em&gt;out of the Azure Service bus; obviously this sort of arrangement would make for huge transfer rates. Before, the communication was required because the images were being stored in the ASP.NET MVC site structure as image files. Now, the image data will be stored in Azure Blob Storage, so all the ASP.NET MVC client sites will need is the URL of the image to be shown to the user in the SignalR-powered HTML observation client. &lt;/p&gt;  &lt;p&gt;If you haven’t yet taken in some of the great resources on the Microsoft Windows Azure site, now would be a great time. The &lt;a title="How to use the Blob Storage Service" href="http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/" target="_blank"&gt;introductory how-to on Blob Storage&lt;/a&gt; was quite helpful in my understanding of how to do some of the Blob Storage-related functionality. It goes a good deal deeper into the details of how Blob Storage works, so I’ll refer you to that article for a little background.&lt;/p&gt; &lt;p&gt;The worker role does very little handiwork with the Blob Storage. Basically, a container is created in which the images will be saved, and that container’s accessibility is set to public. Obviously the images in the container will be served up in a web browser, so they’ll need to be publicly viewable. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_thumb_2.png" width="644" height="336"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The &lt;em&gt;SaveImageToBlobStorage&lt;/em&gt; method, shown below, does the work of building a stream to use to pass the binary data into the Blob Storage account, where it is saved permanently (or until a user deletes it). &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_thumb_3.png" width="644" height="373"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Note how the &lt;em&gt;&lt;a title="MSDN Documentation on the CloudBlob.Uri Property" href="http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storageclient.cloudblob.uri.aspx" target="_blank"&gt;CloudBlob.Uri&lt;/a&gt; &lt;/em&gt;property exposes the URL where the blob can be accessed. In the case of images, this is quite convenient – all we need to be able to display an image is its URL and we’ve got that as soon as the image is saved to the cloud. &lt;/p&gt; &lt;h2&gt;Simplifying the Service Bus Usage&lt;/h2&gt; &lt;p&gt;As previously mentioned, the image data had been getting sent not only &lt;em&gt;to &lt;/em&gt;the cloud, but out of the cloud and then stored in the folder tree of an ASP.NET MVC web site. Not exactly optimal for archival, definitely not for long-term storage. We’ve solved the storage problem by adding in the Blob Storage service, so the next step is to clean up the service bus communication. The sole message type that had been used between all components of the Kinectonitor architecture in the first release was the &lt;em&gt;ImageMessage &lt;/em&gt;class, shown below. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_thumb_4.png" width="651" height="353"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Since the &lt;em&gt;ImageMessage&lt;/em&gt; class is really only needed when the need exists to pass the binary content of the image, a second class has been added to the messaging architecture. The &lt;em&gt;ImageStoredMessage&lt;/em&gt; class, shown below, now serves the purpose of information the SignalR-driven web observation client that new images have been taken and saved into the cloud. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_thumb_5.png" width="651" height="353"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;With the added event concept of images being stored and the client needing to only know the URL of the last image that’s shown automatically in the browser, the message bus usage is in need of rework. When the worker role spins up, the service bus subscription is established, as was being done directly from within the MVC site previously. The worker role listens for messages that come from the Kinect monitor.&lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_thumb_6.png" width="644" height="455"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;When those messages are received, the worker role saves them to Blob Storage using the &lt;em&gt;PublishBlobStoredImageUrl&lt;/em&gt; method that was highlighted earlier. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_thumb_7.png" width="644" height="296"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Finally, one last change that will surely be augmented in a later revision is within the SignalR hub area. Previously, Hubs were wired up through a middle object, a service that wasn’t too thoroughly implemented. That service has been removed, and the Hubs are wired directly to the service bus subscription. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_18.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Improving-the-Kinectonitor-using-Blob-St_D1B1/image_thumb_8.png" width="644" height="289"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Obviously, this results in all clients seeing all updates. Not very secure, not very &lt;em&gt;serviceable &lt;/em&gt;in terms of simplicity and customer separation. The next post in this series will add some additional features around customer segmentation and subscription, as well as potential authentication via the bolted-on Kinect identification code. &lt;/p&gt;</description><pubDate>Wed, 28 Dec 2011 21:39:34 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/blob-storage-of-kinectonitor-images</guid></item><item><title>The Kinectonitor</title><link>http://bradygaster.com:80/the-kinectonitor</link><description>&lt;p&gt;Suppose you had a some scary-looking hoodlum walking around your house when you were out? You&amp;rsquo;d want to know about it, wouldn&amp;rsquo;t you? Take one Kinect, mix in a little Windows Azure Service Bus, sprinkle in some SignalR, and mix it all together with some elbow grease, and you could watch in near-real-time as sinewy folks romp through your living room. Here&amp;rsquo;s how.&lt;/p&gt;
&lt;p&gt;You might not be there (or want to be there) when some maniac breaks in, but it&amp;rsquo;d be great to have a series of photographs with the dude&amp;rsquo;s face to aid the authorities in their search for your home stereo equipment. The video below is a demonstration of the code this post will dive into in more detail. I figured it&amp;rsquo;d give some context to the problem this article will be trying to solve.&lt;/p&gt;
&lt;p&gt;&lt;iframe height="315" src="http://www.youtube.com/embed/UfGOR1Eg_qQ" frameborder="0" width="560" allowfullscreen=""&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I&amp;rsquo;d really like to have a web page where I could go to see what&amp;rsquo;s going on in my living room when I&amp;rsquo;m not there. I know that fancy Kinect I picked up my kids for their XBox can do that sort of thing and I know how to code some .NET. Is it possible to make something at home that&amp;rsquo;d give me this sort of thing?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Good news! It isn&amp;rsquo;t that difficult. To start with, take a look at the Kinectonitor Visual Studio solution below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_4.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_1.png" width="293" height="175" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;At a high level it&amp;rsquo;ll provide the following high-level functions. The monitor application will watch over a room. When a skeleton is detected in the viewing range, a photograph will be taken using the Kinect camera. The image will be published to the Windows Azure Service Bus, using a Topic publish/subscribe approach. An MVC web site will subscribe to the Windows Azure Service Bus topic, and whenever the subscriber receives a ping from the service bus with a new image taken by the Kinect, it will use a SignalR hub to update an HTML client with the new photo. Here's a high-level architectural diagram of how the whole thing works, end-to-end.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="/Media/Default/Misc/SignalR-Kinect-Azure-Security-System-Diagram.png" alt="" width="788" height="370" /&gt;&lt;/p&gt;
&lt;h2&gt;The Kinectonitor Core Project&lt;/h2&gt;
&lt;p&gt;Within the core project will exist a few common areas of functionality. The idea behind the core project is to provide a domain structure, functional abstraction, and initial implementation of the image publication concept. For all intents and purposes, the Kinect will be publishing messages containing image data to the Azure Service Bus, and allow subscribers (which we&amp;rsquo;ll get to in a moment) their own autonomy. The &lt;em&gt;ImageMessage&lt;/em&gt; class below illustrates the message that&amp;rsquo;ll be transmitted through the Azure Service Bus.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_6.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_2.png" width="320" height="97" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A high-level abstraction will be needed to represent consumption of image messages coming from the Azure cloud. The purpose of the &lt;em&gt;IImageMessageProcessor &lt;/em&gt;service is to receive messages from the cloud and to then notify it&amp;rsquo;s own listeners that an image has been received.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_8.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_3.png" width="526" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A simple implementation is needed to receive image messages and to notify observers when they&amp;rsquo;re received. This implementation will allow the SignalR hub, which we&amp;rsquo;ll look at next, to get updates from the service bus; this abstraction and implementation are the custom glue that binds the service bus subscriber to the web site.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_10.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_4.png" width="571" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next up is the MVC web site, in which the SignalR hub is hosted and served up to users in an HTML client.&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;Wiring Up a SignalR Hub&lt;/h2&gt;
&lt;p&gt;Just before we dive into the MVC code itself, take a quick look at the solution again and note the &lt;em&gt;ServiceBusSimplifier &lt;/em&gt;project. This is a super na&amp;iuml;ve, demo-class wrapper around the Windows Azure Service Bus that was inspired by the &lt;a href="https://github.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus" target="_blank"&gt;far-more-complete implementation Joe Feser shares on GitHub&lt;/a&gt;. I used Joe&amp;rsquo;s library to get started with Azure Service Bus and really liked some of his hooks, but his implementation was overkill for my needs so I borrowed some of his ideas in a tinier implementation. If you&amp;rsquo;re deep into Azure Service Bus, though, you should totally look into Joe&amp;rsquo;s code.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_12.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_5.png" width="214" height="107" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Within the &lt;em&gt;ServiceBusSimplifier &lt;/em&gt;project is a class that provides a Fluent wrapper abstraction around the most basic Windows Azure Service Bus publish/subscribe concepts. The &lt;em&gt;ServiceBus &lt;/em&gt;class (which could probably stand be renamed) is below, but collapsed. The idea is &lt;em&gt;just to get the idea &lt;/em&gt;of how this abstraction is going to simplify things from here on out. I&amp;rsquo;ll post a link to download the source code for this article in a later section. For now, just understand that the projects will be using this abstraction to streamline development and form a convention around the Azure Service Bus usage.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_14.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_6.png" width="644" height="429" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A few calls are going to be made in calls to the &lt;em&gt;ServiceBus.Setup &lt;/em&gt;method, specifically to provide Azure Service Bus authentication details. The classes that represent this sort of thing are below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_16.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_7.png" width="523" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now that we&amp;rsquo;ve covered the shared code that the MVC site and WPF/Kinect app will use to communicate via the Azure Service Bus, let&amp;rsquo;s keep rolling and see how the MVC site is connected to the cloud using this library.&lt;/p&gt;
&lt;p&gt;In this prototype code, the Global.asax.cs file is edited. A property is added to the web application to expose an instance of the &lt;em&gt;MockImageMessageProcessor&lt;/em&gt;, (a more complete implementation would probably make use of an IoC container to store an instance of the service) for use later on in the SignalR Hub. Once the service instance is created, the Azure Service Bus wrapper is created and the &lt;em&gt;ImageMessage&lt;/em&gt; messages are subscribed to by the site &lt;em&gt;MessageProcessor &lt;/em&gt;instance&amp;rsquo;s &lt;em&gt;Process &lt;/em&gt;method.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_18.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_8.png" width="465" height="246" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When the application starts up, the instance is created and shared with the web site&amp;rsquo;s server-side code. The SignalR Hub, then, can make use of that service implementation. The SignalR Hub listens for &lt;em&gt;ImageReceived &lt;/em&gt;events coming from the service. Whenever the Hub handles the event, it turns around and notifies the clients connected to it that a new photo has arrived.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_20.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_9.png" width="585" height="417" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;With the Hub created, a simple Index view (and controller action) will provide the user-facing side of the Kinectonitor. The HTML/JQuery code below demonstrates how the client responds when messages arrive. There isn&amp;rsquo;t much to this part, really. The code just changes the &lt;em&gt;src &lt;/em&gt;attribute of an &lt;em&gt;img &lt;/em&gt;element in the HTML document, then fades the image in using JQuery sugar.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_22.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_10.png" width="644" height="482" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now that the web client code has been created, we&amp;rsquo;ll take a quick look at the Kinect code that captures the images and transmits them to the service bus.&lt;/p&gt;
&lt;h2&gt;The Kinectonitor Monitor WPF Client&lt;/h2&gt;
&lt;p&gt;Most of the Kinect-interfacing code comes straight from the samples available with the &lt;a href="http://kinectforwindows.org/" target="_blank"&gt;Kinect SDK download&lt;/a&gt;. The main points to be looked at in the examination of the WPF client is to see how it publishes the image messages into the Azure cloud.&lt;/p&gt;
&lt;p&gt;The XAML code for the main form of the WPF app is about as dirt-simple as you could get. It just needs a way to display the image being taken by the Kinect and the skeletal diagram (the code available from the Kinect SDK samples). The XAML for this sample client app is below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_24.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_11.png" width="484" height="180" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When the WPF client opens, the first step is, of course, to connect to the Kinect device and the Windows Azure Service Bus. The &lt;em&gt;OnLoad &lt;/em&gt;event handler below is how this work is done. Note that this code also instantiates a &lt;em&gt;Timer&lt;/em&gt; instance. That timer will be used to control the delay between photographs, and will be looked at in a moment.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_28.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_13.png" width="644" height="234" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Whenever image data is collected from the camera it&amp;rsquo;ll be displayed in the WPF Image control shown earlier. The &lt;em&gt;OnKinectVideoReady &lt;/em&gt;handler method below is where the image processing/display takes place. Take note of the highlighted area; this code sets an instance of a &lt;em&gt;BitmapSource &lt;/em&gt;object, which will be used to persist the image data to disk later.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_30.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_14.png" width="644" height="397" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Each time the Kinect video image is processed a new &lt;em&gt;BitmapSource &lt;/em&gt;instance is created. Remember the &lt;em&gt;Timer &lt;/em&gt;instance from the class earlier? That timer&amp;rsquo;s handler method is where the image data is saved to disk and transmitted to the cloud. Note the check being performed on the &lt;em&gt;AreSkeletonsBeingTracked &lt;/em&gt;property. That&amp;rsquo;s the last thing that&amp;rsquo;ll be looked at next, that&amp;rsquo;ll tie the WPF functionality together.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_32.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_15.png" width="492" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If the Kinectonitor WPF client just continually took snapshots and sent them into the Azure cloud the eventual price would probably be prohibitive. The idea behind a monitor like this, really, though, is to show only when people enter during unexpected times. So, the WPF client will watch for skeletons using the built-in Kinect skeleton tracking functionality (and code from the Kinect SDK samples). If a skeleton is being tracked, we know someone&amp;rsquo;s in the room and that a photo should be taken. Given that the skeleton might be continually tracked for a few seconds (or minutes, or longer), the Kinect will continue to photograph while a skeleton is being tracked. As soon as the tracking stops, a final photo is taken, too. The code that sets the &lt;em&gt;AreSkeletonsBeingTracked &lt;/em&gt;property value during the skeleton-ready event handler is below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_34.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_16.png" width="617" height="195" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Some logic occurs during the setter of the &lt;em&gt;AreSkeletonsBeingTracked &lt;/em&gt;method, just to sound the alarms whenever a skeleton is tracked, without having to wait the typical few seconds until the next timer tick.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_36.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/image_thumb_17.png" width="560" height="194" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s it for the code! One more note &amp;ndash; it helps if the Kinect is up high or in front of a room (or both). During development of this article I just placed mine on top of the fridge, which is next to the kitchen bar where I do a lot of work. It could see the whole room pretty well and picked up skeletons rather quickly. Just a note for your environment testing phase.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/IMAG0356_2.jpg"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="IMAG0356" border="0" alt="IMAG0356" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/The-Kinecto_13AA2/IMAG0356_thumb.jpg" width="644" height="387" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;This article took a few of the more recent techniques and tools to be released to .NET developers. With a little creativity and some time, it&amp;rsquo;s not difficult to use those components to make something pretty neat at home in the physical computing world. Pairing these disciplines up to create something new (or something old someway different) is great fodder for larger projects using the same technologies later.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/bradygaster/Kinectonitor" target="_blank"&gt;If you&amp;rsquo;d like to view the Kinectonitor GitHub source code, it&amp;rsquo;s right here.&lt;/a&gt;&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:36 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/the-kinectonitor</guid></item><item><title>The Red Pill</title><link>http://bradygaster.com:80/the-red-pill</link><description>&lt;p&gt;You may have noticed I’ve been getting into Azure recently. You could say my head’s going to be even more in the cloud than usual, because I’ve accepted a position with Microsoft as an Azure Technical Evangelist. &lt;/p&gt; &lt;p&gt;Admittedly, I was relatively late to the Azure party. I’ve been seeing so many colleagues do amazing things with it - &lt;a href="http://www.structuretoobig.com/" target="_blank"&gt;Brian Hitney&lt;/a&gt; with &lt;a href="http://www.rockpaperazure.com/" target="_blank"&gt;Rock, Paper, Azure&lt;/a&gt;, &lt;a href="https://twitter.com/#!/mlinnen" target="_blank"&gt;Mike Linnen&lt;/a&gt; with his &lt;a href="http://www.protosystem.net/post/2011/08/21/Lawn-Sprinkler-the-Demo-Part-2.aspx" target="_blank"&gt;Netduino/Service Bus/WP7 solution&lt;/a&gt;, and &lt;a href="http://blogs.captechconsulting.com/blog/author/Mike%20Diiorio" target="_blank"&gt;Mike Diiorio’s&lt;/a&gt; presentation at the &lt;a href="http://richmondcodecamp.org/" target="_blank"&gt;Richmond Code Camp&lt;/a&gt;. Once I dove in, I couldn’t look back, and now, I’ll be finding just how far the cloud goes. &lt;/p&gt; &lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/db815ceed93b_89C6/IMAG0326_2.jpg" target="_blank"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top: 0px; border-right: 0px; padding-top: 0px" title="Building 24, where I will be working soon" border="0" alt="Building 24" align="left" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/db815ceed93b_89C6/IMAG0326_thumb.jpg" width="244" height="148"&gt;&lt;/a&gt;My team is amazing and I’m honored to be a part of it. I’ll be working with/for &lt;a href="http://www.wadewegner.com/" target="_blank"&gt;Wade Wegner&lt;/a&gt;, &lt;a href="http://ntotten.com/" target="_blank"&gt;Nathan Totten&lt;/a&gt;, &lt;a href="http://jamesconard.com/" target="_blank"&gt;James Conard&lt;/a&gt;, &lt;a href="http://drewby.com/" target="_blank"&gt;Drew Robbins&lt;/a&gt;, and a lot of other bright, talented folks in Building 24. I’m not sure what specific Azure areas I’ll focus on out of the gate, but API’s and SOA’s are areas of interest to me and I hope to focus in those areas. Right now, I’m just thankful to have the opportunity and look forward to getting started. &lt;/p&gt; &lt;p&gt;The next few months will be interesting, to say the least. The position is based out of Redmond, so after years of wanting to near Seattle (my favorite city so far), my family will finally have the opportunity. We’ve started investigating our options and preparing ourselves, and we have been overwhelmed at how hospitable and helpful Microsoft is being to help in the transition.&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:36 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/the-red-pill</guid></item><item><title>Testing SignalR Connections with NUnit</title><link>http://bradygaster.com:80/testing-signalr-connections-with-nunit</link><description>&lt;p&gt;The &lt;a title="SignalR GitHub" href="https://github.com/SignalR/SignalR" target="_blank"&gt; SignalR GitHub&lt;/a&gt; site has an example wherein a SignalR &lt;em&gt;&lt;a title="The source code for the PersistentConnection class" href="https://github.com/SignalR/SignalR/blob/master/SignalR/PersistentConnection.cs" target="_blank"&gt;PersistentConnection&lt;/a&gt;&lt;/em&gt; instance is used from a non-HTML client. The idea of being able to use SignalR connections in applications other than those that run in a web browser raises some interesting challenges. Likewise, there aren&amp;rsquo;t too many examples on how to use SignalR connections. This post will demonstrate asynchronously testing a SignalR connection in an end-to-end scenario using NUnit.&lt;/p&gt;
&lt;h2&gt;Creating Custom SignalR Connections&lt;/h2&gt;
&lt;p&gt;The first step is to create a custom SignalR connection. For the purposes of this example a simple connection implementation will do just fine. Borrowing from the example on the SignalR GitHub site is the &lt;em&gt;EchoConnection &lt;/em&gt;class below.&lt;/p&gt;
&lt;p&gt;The implementation of the &lt;em&gt;EchoConnection &lt;/em&gt;should be relatively self-explanatory. Whenever the connection receives a message from a client, it turns around and sends that message out to all the connected clients using the &lt;em&gt;Broadcast &lt;/em&gt;method.&lt;/p&gt;
&lt;p&gt;&lt;img border="0" alt="image" src="/Media/Default/SignalRConnectionNUnitTest/1.png" width="568" height="189" /&gt;&lt;/p&gt;
&lt;p&gt;Unlike SignalR Hubs, which are automatically wired up and routed, SignalR Connection classes aren&amp;rsquo;t (at least, I don&amp;rsquo;t know that they are). There&amp;rsquo;s an additional step with SignalR connections; they must be routed similarly to how MVC routes or &lt;a title="WCF Web API home page" href="http://wcf.codeplex.com/wikipage?title=WCF%20HTTP" target="_blank"&gt;WCF Web API&lt;/a&gt; routes are set up. The code below is from an MVC 3.0 application&amp;rsquo;s &lt;em&gt;Global.asax.cs &lt;/em&gt;file, but you could accomplish the same sort of thing using a custom module.&lt;/p&gt;
&lt;p&gt;&lt;img border="0" src="/Media/Default/SignalRConnectionNUnitTest/2.png" width="533" height="301" /&gt;&lt;/p&gt;
&lt;p&gt;The point here is to define a route that will provide HTTP access to this connection class. Next, the client code needs to be written. That&amp;rsquo;ll be accomplished using an &lt;a title="NUnit is my favorite unit testing framework" href="http://nunit.org/" target="_blank"&gt;NUnit&lt;/a&gt; test (it&amp;rsquo;s really an integration test, but that&amp;rsquo;s semantic sugar).&lt;/p&gt;
&lt;h2&gt;Using the SignalR.Client NuGet Package&lt;/h2&gt;
&lt;p&gt;The example source code contains a simple class library project. This project references the &lt;a title="SignalR.Client NuGet project page" href="http://nuget.org/List/Packages/SignalR.Client" target="_blank"&gt;SignalR.Client&lt;/a&gt; NuGet package to provide .NET client communication functionality to an application written in managed code. You can use the SignalR.Client project in your desktop applications or in back-end services or Azure Worker Roles. The class library project is shown below, so you can get an idea of the minimal dependencies necessary to support .NET client SignalR support.&lt;/p&gt;
&lt;p&gt;&lt;img border="0" src="/Media/Default/SignalRConnectionNUnitTest/3.png" width="298" height="308" /&gt;&lt;/p&gt;
&lt;p&gt;SignalR.Client makes use of &lt;a title="Newtonsoft.JSON NuGet project page" href="http://nuget.org/List/Packages/Newtonsoft.JSON" target="_blank"&gt;Newtonsoft.JSON&lt;/a&gt;, so that project gets pulled in automatically when you update your NuGet package references. &lt;strong&gt;Caveat/Gotcha:&lt;/strong&gt; I had to explicitly redirect this class library project&amp;rsquo;s &lt;em&gt;App.config &lt;/em&gt; file to the newest version of the Newtonsoft.JSON assembly. You might not need to do that, but just in case, here&amp;rsquo;s how.&lt;/p&gt;
&lt;p&gt;&lt;img border="0" src="/Media/Default/SignalRConnectionNUnitTest/4.png" width="526" height="258" /&gt;&lt;/p&gt;
&lt;h2&gt;Writing the Test&lt;/h2&gt;
&lt;p&gt;At this point, the project is properly set up and everything should be ready for setting up the unit (or integration, depending on your stance) test to communicate with the SignalR connection.&lt;/p&gt;
&lt;p&gt;It is important to point out that this test makes use of the &lt;em&gt;AutoResetEvent &lt;/em&gt;class to wait for the asynchronous process to complete. This is done because SignalR&amp;rsquo;s communication via either the connection or hub approach implies that the communication is asynchronous.&lt;/p&gt;
&lt;p&gt;&lt;img border="0" src="/Media/Default/SignalRConnectionNUnitTest/5.png" width="518" height="385" /&gt;&lt;/p&gt;
&lt;p&gt;If this test is run when the web server is turned off, it will obviously fail, as the test output below from NUnit demonstrates.&lt;/p&gt;
&lt;p&gt;&lt;a href="/Media/Default/SignalRConnectionNUnitTest/6.png" target="_blank"&gt; &lt;img title="Click for larger view" border="0" alt="Failing!!!" src="/Media/Default/SignalRConnectionNUnitTest/6.png" width="644" height="421" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once the web server is started and the test re-run, the client receives a message almost as soon as it finishes sending it, and the test passes.&lt;/p&gt;
&lt;p&gt;&lt;a href="/Media/Default/SignalRConnectionNUnitTest/7.png"&gt; &lt;img title="Click for larger view" border="0" alt="Passing!!!" src="/Media/Default/SignalRConnectionNUnitTest/7.png" width="644" height="422" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;SignalR is an asynchronous messaging library designed to provide push-like functionality and continuous connectivity for web clients. However, it isn&amp;rsquo;t &lt;em&gt;just &lt;/em&gt; for the web; SignalR connections can be used from within .NET code to provide instant communication and constant connectivity between multiple clients.&lt;/p&gt;
&lt;p&gt;Happy coding!&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:35 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/testing-signalr-connections-with-nunit</guid></item><item><title>JSON-based WCF in Azure</title><link>http://bradygaster.com:80/json-based-wcf-in-azure</link><description>&lt;p&gt;Developers need to grok Windows Azure, especially developers who want to distribute consumption of an application in a web-based API. A great use for Microsoft Azure, obviously, is to use it to host an application&amp;rsquo;s web service API layer. This post will demonstrate how to host WCF services in an Azure worker role in a manner that will offer REST-like JSON API support.&lt;/p&gt;
&lt;h2&gt;WCF Can do JSON, and it isn&amp;rsquo;t Difficult&lt;/h2&gt;
&lt;p&gt;I promise. Most of the examples you&amp;rsquo;ll see cover possibly &lt;em&gt;too much &lt;/em&gt;of the configuration specifics and focus on how Visual Studio can generate proxies for you. Though that&amp;rsquo;s a great facet of the IDE, there are some natural limitations to comprehending the moving parts within WCF if you always let the IDE take care of the plumbing. Once you get into implementing JSON services in WCF, the IDE generation can actually make things more difficult. If you'd like to follow along in the Visual Studio solution you can &lt;a href="http://dl.dropbox.com/u/3597725/JSON-WCF-Azure.zip" title="Download the code for this article"&gt;download it here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To start with, here&amp;rsquo;s a snap shot of the Visual Studio solution. Each project should be relatively self-explanatory in purpose. Each will be examined in a moment.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_3.png" width="242" height="224" /&gt;&lt;/p&gt;
&lt;p&gt;At this point, a closer examination of each project is in order. Don&amp;rsquo;t worry, there&amp;rsquo;s not a lot to each project. This won&amp;rsquo;t take long. You&amp;rsquo;ll be amazed how easy it could&amp;rsquo;ve been the whole time and even more amazed how easy it is to get your JSON API&amp;rsquo;s into Windows Azure.&lt;/p&gt;
&lt;h2&gt;Service Contract and Implementation&lt;/h2&gt;
&lt;p&gt;This example will be a simple and familiar one; the service layer will expose calculator functionality. Hopefully, a later blog post will go into more detail on complex messaging, but for now, a calculator serves the explanation well.&lt;/p&gt;
&lt;p&gt;The screen shot below demonstrates the &lt;em&gt;ICalculator &lt;/em&gt;service interface. Note it has been decorated with the typical service model attributes, as well as the &lt;em&gt;WebInvoke &lt;/em&gt;attribute. Within the &lt;em&gt;WebInvoke&lt;/em&gt; attribute&amp;rsquo;s constructor, JSON is being used as a request and response style.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_7.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_2.png" width="644" height="379" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This attribute code simply says &amp;ldquo;when the application hosts this service, use JSON as the serialization syntax.&amp;rdquo; It&amp;rsquo;ll be important that those attributes are on the interface later on in this post. For now, just take a look at the implementation in the screen shot below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_11.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_4.png" width="644" height="379" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you&amp;rsquo;ve seen, the service contract interface is not only where the abstraction is defined, but how the service is used from within WCF. The next piece of the puzzle is how the service will be hosted within a Windows Azure worker role process.&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;Hosting WCF JSON Services in Windows Azure&lt;/h2&gt;
&lt;p&gt;There are a number of great resources on StackOverflow or CodeProject on the details of hosting a WCF service in Azure, so this article won&amp;rsquo;t dive too deeply into the intricacies. Rather, this next section will dive right in and get things done.&lt;/p&gt;
&lt;p&gt;WCF Services can be hosted in numerous ways. A few options are available via Windows Azure, from hosting in a typical web application environment to being hosted and configured manually in a Worker Role. The code below demonstrates the second option via a worker role class.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_13.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_5.png" width="624" height="390" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The important method, &lt;em&gt;HostService&amp;lt;TService, TImplementation&amp;gt;&lt;/em&gt; is closed in the screen shot above, as it&amp;rsquo;ll be examined in somewhat more detail below. The &lt;em&gt;HostService &lt;/em&gt;method does just what it says &amp;ndash; it hosts a WCF service implementation as represented by a decorated WCF interface in the Windows Azure worker role.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_17.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_7.png" width="670" height="468" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This method just declares a new &lt;em&gt;ServiceHost &lt;/em&gt;instance, then sets that instance up on the &lt;em&gt;WebHttp &lt;/em&gt;binding so that JSON communication can take place. In particular, the code requires one step of configuration take place. The code that looks at the Worker Role environment&amp;rsquo;s end points collection is shown below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_19.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_8.png" width="560" height="145" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This stipulates a convention. That each service endpoint will be named in the endpoints configuration according to it&amp;rsquo;s type&amp;rsquo;s name. In this example case, the &lt;em&gt;Calculator &lt;/em&gt;class is the one that&amp;rsquo;ll actually be placed on the WCF binding. The screen shot below demonstrate how and in which file this can be set using Visual Studio 2010.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_21.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_9.png" width="644" height="398" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;At this point, the worker role should be configured and ready to run. If the project is run in debug mode at this point the computer emulator will open and the trace output is visible. The screen shot below shows the compute emulator running. The highlighted sections are the custom trace messages the code writes at run-time.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_23.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_10.png" width="644" height="336" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The final step is to write a client to consume the service while it is being hosted in Windows Azure.&lt;/p&gt;
&lt;h2&gt;Calling via a Unit Test&lt;/h2&gt;
&lt;p&gt;This service only exposes one small unit of functionality, so it stands to reason a unit test could be a good method of testing the service. Sure, it&amp;rsquo;s test-after, but that argument is for another time! For now, let&amp;rsquo;s finish this example up by calling the WCF service being hosted in Windows Azure. Just to prove there are no smoke and mirrors, here&amp;rsquo;s what the URL from the compute emulator will expose when suffixed with the &lt;em&gt;UrlTemplate &lt;/em&gt;format from the &lt;em&gt;ICalculator &lt;/em&gt;service definition from earlier.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_25.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_11.png" width="381" height="96" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To know about the service, the unit test project will have a reference set to the contracts project. So that the unit test will know how to call the service in the cloud, the unit test project will need a tiny bit of configuration added to it&amp;rsquo;s &lt;em&gt;app.config&lt;/em&gt; file. The screen shot below demonstrates both of these steps.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_27.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_12.png" width="644" height="391" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I mentioned early on that this post would demonstrate proxy formation without the use of the service references functionality of Visual Studio. The class below demonstrates how this can be achieved. By inheriting from the &lt;em&gt;ClientBase&amp;lt;T&amp;gt; &lt;/em&gt;class and the interface being exposed by the service, you can create a custom proxy class in a minimal amount of work.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_29.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_13.png" width="494" height="165" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Finally, the unit test can be authored.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_31.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_14.png" width="561" height="225" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When executed, provided the calculator service is being hosted in Azure, the results should be immediate. The test passes, the result of the calculation yielding a correct result.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_33.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_15.png" width="482" height="194" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Looking back at the compute emulator that was running when the unit test client was executed, the evidence the service is handling requests is apparent. The screen shot below highlights a pair of executions from when the test was executed.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_37.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/JSON-based-WCF-in-Azure_40F/image_thumb_17.png" width="560" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;/h2&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;This article took a no-nonsense approach to demonstrating how simple it is to host JSON-serialized WCF services in Windows Azure. Azure is an amazing resource for developers who want to expose aspects of their application in open web API&amp;rsquo;s. Hopefully, this example has demonstrated how easy it is to get started doing just that. Soon, you&amp;rsquo;ll be RESTing in the Cloud, with your very own WCF JSON API&amp;rsquo;s.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://dl.dropbox.com/u/3597725/JSON-WCF-Azure.zip" title="Download the code for this article"&gt;Download the Visual Studio.NET solution for this article.&lt;/a&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:35 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/json-based-wcf-in-azure</guid></item><item><title>The Robot Factory Kata</title><link>http://bradygaster.com:80/the-robot-factory-kata</link><description>&lt;p&gt;On the drive home from my last Behavior Driven Development talk, I began thinking about the idea of &lt;a href="http://codekata.pragprog.com/2007/01/code_kata_backg.html" title="Great introduction to coding katas" target="_blank"&gt;Code Katas&lt;/a&gt; and how one might be appropriate in my future disucssions of Behavior Driven Development. Given that BDD tries to solve things in as simple and direct a path as possible, and given that BDD takes some of the lessons learned via TDD and applies them in slightly more business-centric language, a Kata would demonstrate well the effectiveness of BDD when applied to a problem domain.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, I took the example problem domain of a robotic assembly line that I've been using since I was training full-time under the guidance of &lt;a href="http://weblogs.asp.net/palermo4/" title="my mentoring mentor" target="_blank"&gt;J. Michael Palermo IV&lt;/a&gt;&amp;nbsp;and implemented it using &lt;a href="http://specflow.org/" title="the SpecFlow project page" target="_blank"&gt;SpecFlow&lt;/a&gt; and &lt;a href="http://code.google.com/p/moq/" title="Moq is my favorite mocking library for .NET" target="_blank"&gt;Moq&lt;/a&gt;. So far, the Robot Factory Kata video series has two videos.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The first of these demonstrates the project setup and configuration, and starts solving the problem using SpecFlow specifications and NUnit tests.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;iframe width="560" height="315" src="http://www.youtube.com/embed/PAeIuqt2Nf0" frameborder="0" allowfullscreen=""&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;The second part helps demonstrate how mocking method verification using callback expectations to demonstrate testing interaction between two objects. Sure, this is getting into integration testing, but the idea is to demonstrate BDD using a legitimate problem domain that's slightly more interesting than the construction of a calculator. Not that there's anything wrong with that, but you know, it helps to have variety.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;iframe width="560" height="315" src="http://www.youtube.com/embed/CZl9Ic3R4_E" frameborder="0" allowfullscreen=""&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;Hope you enjoy these video demonstrations and that they motivate you to start BDD'ing today.&amp;nbsp;&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:34 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/the-robot-factory-kata</guid></item><item><title>From the Cloud to the Client</title><link>http://bradygaster.com:80/from-the-cloud-to-the-client</link><description>&lt;p&gt;That title sums up what this blog post will summarize and explain; how to get data instantly from the cloud &amp;ndash; in this case, the Azure cloud platform &amp;ndash; all the way down to an HTML 5.0 browser. The point of this exercise is to take a slightly deeper dive into using SignalR. Secondary to the SignalR deep dive, this article will explain how to use the Azure Service Bus.&lt;/p&gt;
&lt;p&gt;Azure and AppFabric can seem like huge, daunting problems. I was shocked how simple both were to use and admit that, like many technologies, the problem isn&amp;rsquo;t in their difficulty but in my willfulness to just learn how it works. Once I dove in I had a queue up and working in about 5 minutes on the first try. &lt;a title="Mike Diiorio" href="http://blogs.captechconsulting.com/blog/author/Mike%20Diiorio" target="_blank"&gt;Mike Diiorio&lt;/a&gt; gave a great introduction into how AppFabric works at the &lt;a title="Richmond Code Camp" href="http://richmondcodecamp.org/" target="_blank"&gt;Richmond Code Camp&lt;/a&gt;. Some of the code in this blog was inspired by the code he presented there. He really made the Azure service bus seem quite easy and made my adoption of it a lot more rapid. I&amp;rsquo;d highly recommend you check out his talk if the opportunity arises.&lt;/p&gt;
&lt;h2&gt;Service Bus Namespace Authentication&lt;/h2&gt;
&lt;p&gt;To make authentication seamless from both the publication and subscription ends of the Azure Service Bus conversation, one class will be used to persist the authentication information. The &lt;em&gt;CredentialDetail &lt;/em&gt;class below serves to represent the service bus and the namespace under which it resides in the Azure cloud.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_b37dfbf2-838e-4b0e-98f9-e1638b903077.png" width="505" height="390" /&gt;&lt;/p&gt;
&lt;p&gt;To give this some context, the corresponding service bus is shown below in the Azure management site. Note the red boxes; that string matches the string property &lt;em&gt;Namespace &lt;/em&gt;in the credential class we&amp;rsquo;ll be sharing for all clients of this service bus. The &lt;em&gt;IssuedKey &lt;/em&gt;and &lt;em&gt;Issuer&lt;/em&gt; properties can be obtained from clicking the &lt;em&gt;View &lt;/em&gt;button in the Azure management site.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_3.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_thumb.png" width="644" height="275" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Sending Messages to Azure&lt;/h2&gt;
&lt;p&gt;This application is a regular, boring old Console application, but you could send messages into Azure Service Bus from pretty much anything &lt;em&gt;or &lt;/em&gt;you could host a WCF service or MVC site in Azure to publish messages to it from the Internet. Whatever the case may be, message transmission into Azure isn&amp;rsquo;t verify difficult; if you&amp;rsquo;ve done any message-based coding in the past it should appear relatively familiar in structure. The application first makes a connection to the Azure service bus using the data stored in the &lt;em&gt;CredentialDetail &lt;/em&gt;class from earlier in this article.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_e6b6dae6-cacf-41cf-a43f-6ca5763615e4.png" width="442" height="255" /&gt;&lt;/p&gt;
&lt;p&gt;Next, the &lt;em&gt;Sender &lt;/em&gt;class connects to the Azure namespace. Then it either connects to or creates an Azure queue.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_bc6fb7b3-2fa0-43d1-abea-1388df6e4454.png" width="625" height="234" /&gt;&lt;/p&gt;
&lt;p&gt;Next, the &lt;em&gt;Sender &lt;/em&gt;class gets user input at the console and transmits that data into Azure via the queue client.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_6699f283-b266-40be-b1fb-f8cee49c6782.png" width="560" height="275" /&gt;&lt;/p&gt;
&lt;p&gt;When the sender application runs, the output should be relatively obvious and simple. It just lets us enter some messages and send them into the Azure queue, then confirms the transmission was completed.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_73f7711f-a0e3-42e9-af6b-bdf03365a404.png" width="681" height="346" /&gt;&lt;/p&gt;
&lt;h2&gt;A Service Bus-Aware SignalR Hub&lt;/h2&gt;
&lt;p&gt;From the title it should be obvious we&amp;rsquo;re not going to stop by just being able to send messages into the queue. This sample will receive messages from the queue, too, and then notify all connected HTML 5.0 clients &lt;em&gt;instantaneously &lt;/em&gt;when messages are pulled from the Azure service bus and processed.&lt;/p&gt;
&lt;p&gt;The first step in completing this is a service that will listen for messages. The interface contract for the &lt;em&gt;IQueueReceiver &lt;/em&gt;interface is below.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_ac4fe75b-97d1-41d5-983f-70bcd9f4ec98.png" width="349" height="255" /&gt;&lt;/p&gt;
&lt;p&gt;The first implementation for the &lt;em&gt;IQueueReceiver &lt;/em&gt;interface will be expecting to get a string message. The &lt;em&gt;StringQueueReceiver &lt;/em&gt;service watches the Azure service bus and, when messages arrive, it fires the &lt;em&gt;Received&lt;/em&gt; event to notify any of its observers that it has a message for them.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_9d566e3b-a1e6-4c6d-8a35-1b43553d2817.png" width="664" height="443" /&gt;&lt;/p&gt;
&lt;p&gt;The observer, in this case, is going to be a SignalR Hub. Since SignalR Hubs do the heavy lifting of pushing data from the server to the client browser, a custom Hub is a perfect candidate; the Hub will receive the data coming from the Azure bus, then hand it off to all the HTML clients. The &lt;em&gt;ServiceBusListenerHub&lt;/em&gt; will depend on the &lt;em&gt;StringQueueReceiver &lt;/em&gt;so it&amp;rsquo;ll be passed in via constructor injection.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_f53fbf08-f890-49c4-b7ad-cf3cc24c565a.png" width="492" height="166" /&gt;&lt;/p&gt;
&lt;p&gt;This is where a deeper dive into how SignalR can use your favorite IoC container comes into play. Since Hubs are transient, and the nature of listening to a queue indefinitely is a more permanent type of thing, we&amp;rsquo;re going to inject the listener service into our SignalR Hub. My favorite IoC container is Unity, so I&amp;rsquo;ve rolled my very own Unity startup implementation per the specs from the SignalR team and using the &lt;a title="Helps customize resources available during IIS application startup" href="http://nuget.org/List/Packages/WebActivator" target="_blank"&gt;WebActivator&lt;/a&gt; NuGet package.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_fb93874c-03c1-4d3f-b34c-97d9758655f1.png" width="605" height="488" /&gt;&lt;/p&gt;
&lt;p&gt;Once the Unity container is set up, the service can be added.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_c679c31c-e556-4023-9ad8-422f8ce44432.png" width="539" height="103" /&gt;&lt;/p&gt;
&lt;p&gt;The Hub will have one method, &lt;em&gt;Initialize, &lt;/em&gt;that HTML clients will call at page ready. This call clears any previously bound event handlers on the &lt;em&gt;IQueueReceiver.Received &lt;/em&gt;event, then binds to it to make sure that incoming messages are then passed to the HTML clients.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_a57a0d87-ad01-4dbb-ad7f-6b387a016e28.png" width="591" height="214" /&gt;&lt;/p&gt;
&lt;h2&gt;Client Code&lt;/h2&gt;
&lt;p&gt;The client code is quite simplistic. Just a few lines of JavaScript files to set SignalR and to get everything wired up.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_483b5b78-c088-42ee-bfa2-03955cea9d2d.png" width="657" height="183" /&gt;&lt;/p&gt;
&lt;p&gt;Then a few more lines to initiate communication with the Hub.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_812e2775-dd7e-4672-9b61-1d0c0e8651e2.png" width="560" height="343" /&gt;&lt;/p&gt;
&lt;p&gt;Once that&amp;rsquo;s finished the client should start to receive messages as they&amp;rsquo;re being sent in from the service bus.&lt;/p&gt;
&lt;p&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/From-the-Cloud-to-the-Client_2EB/image_be115fe4-e485-4a94-afee-39e47e0abfa1.png" width="329" height="221" /&gt;&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;This article introduced the idea of creating an Azure Service Bus implementation (which was what I&amp;rsquo;d planned on learning through the exercise, so I met my personal goal). The messages are taken from the bus, thrown into a SignalR Hub, which then transmits those messages directly to HTML 5 browser clients. Hopefully this will inspire you to create a few Azure bus or SignalR toys yourself. The possibilities are pretty staggering!&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:34 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/from-the-cloud-to-the-client</guid></item><item><title>Doing BDD with SignalR and Jasmine</title><link>http://bradygaster.com:80/doing-bdd-with-signalr-and-jasmine</link><description>&lt;p&gt;SignalR is one of the latest (and sexiest) elements in the .NET stack. Expect to hear more about SignalR if you haven’t already, because it delivers on the promise of push technology without the requirement of a fat client. If you’ve not yet read much about SignalR, &lt;a title="SignalR was originally developed within Microsoft, is hosted on GitHub, and is completely and totally open source." href="https://github.com/SignalR/SignalR" target="_blank"&gt;clone the source code from GitHub&lt;/a&gt; or read &lt;a title="I mean, come on. You gotta trust this guy." href="http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx" target="_blank"&gt;Scott Hanselman’s post on SignalR&lt;/a&gt; for an introduction. The scope and inner-workings of SignalR are somewhat out of scope here, so I’ll just assume you’ve at least heard &lt;em&gt;something &lt;/em&gt;about SignalR and that you’re interested in it but have a few questions. I mean, if you’re into BDD/TDD, you should definitely be wondering:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;font color="#212121"&gt;So how testable is SignalR? If the magic of it is based in some form of maintained connection, the implication of how one has to code asynchronously against it makes testing p-r-e-t-t-y difficult. Testing in JavaScript is pretty difficult to begin with, so now what?&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;There’s this amazing TDD/BDD micro-framework called &lt;a title="Jasmine is a behavior-driven development framework for testing your JavaScript code" href="http://pivotal.github.com/jasmine/" target="_blank"&gt;Jasmine&lt;/a&gt; that lends itself extremely well to all sorts of different JavaScript problem domains. I learned about Jasmine from some colleagues in the Ruby community, then found some &lt;a title="Pragmatic JavaScript Testing with Jasmine" href="http://blog.carbonfive.com/2011/07/06/pragmatic-javascript-testing-with-jasmine/" target="_blank"&gt;pretty&lt;/a&gt; &lt;a title="Testing Your JavaScript with Jasmine" href="http://net.tutsplus.com/tutorials/javascript-ajax/testing-your-javascript-with-jasmine/" target="_blank"&gt;awesome&lt;/a&gt; &lt;a title="How do I verify jQuery AJAX events with Jasmine?" href="http://stackoverflow.com/questions/4662641/how-do-i-verify-jquery-ajax-events-with-jasmine" target="_blank"&gt;resources&lt;/a&gt; on Jasmine, and have been waiting for an opportunity to try it out. This seemed like a perfect opportunity, so I dove in.&lt;/p&gt; &lt;h2&gt;&lt;/h2&gt; &lt;h2&gt;The Calculator SignalR Hub&lt;/h2&gt; &lt;p&gt;This example will offer a solution to the simple problem of providing basic numeric calculations. Obviously, the first operation most users will need is some addition functionality.&lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_67.png" width="372" height="219"&gt;&lt;/p&gt; &lt;p&gt;The implementation of this method might look a little strange if you’re new to SignalR. It’ll make sense in just a moment when you see the corresponding JavaScript code. Think about it this way; the Clients property of any Hub is &lt;em&gt;dynamic&lt;/em&gt; object that will represent a corresponding JavaScript method on each of the clients connected to the Hub. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_68.png" width="375" height="210"&gt;&lt;/p&gt; &lt;p&gt;The controller action for the client has no special glue or magic in it. It’s basically a shell to adhere to the requirement of having an action for the views. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_69.png" width="242" height="79"&gt;&lt;/p&gt; &lt;p&gt;On the client, there will be a few script references to make sure SignalR works properly. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_70.png" width="709" height="145"&gt;&lt;/p&gt; &lt;p&gt;This is the part where the dynamic client thing should make sense. The JavaScript code below demonstrates how to call this dirt-simple SignalR Hub and to generate some action on the client. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_71.png" width="368" height="301"&gt;&lt;/p&gt; &lt;p&gt;The call earlier, within the implementation of the Hub, is basically a way of the server telling the client, &lt;em&gt;would you please run this method and pass it this data? &lt;/em&gt;It isn’t a really sexy example when you see it execute, of course, but it drives the point home. &lt;em&gt;SignalR makes push ridiculously simple. &lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_72.png" width="427" height="242"&gt;&lt;/p&gt; &lt;h2&gt;Bring on the BDD!&lt;/h2&gt; &lt;p&gt;As if SignalR isn’t nifty enough, Jasmine gives us the ability to set up specifications and unit tests to make sure things are working properly and to guide development. Now, we get to put them together to answer the problem of &lt;em&gt;how to test the client. &lt;/em&gt;(I’m not knocking other methods, like WaTiN or other automated testing implementations, here, this is just another way of skinning the same kitty.)&lt;/p&gt;   &lt;p&gt;We’ll need to include the basic script references and CSS file to make Jasmine light up. You can download those from the &lt;a title="Jasmine standalone downloads" href="http://pivotal.github.com/jasmine/download.html" target="_blank"&gt;Jasmine site&lt;/a&gt;, or they’re included in the &lt;a title="My GitHub SignalR.Demo repository." href="https://github.com/bradygaster/SignalR.Demo" target="_blank"&gt;GitHub repository&lt;/a&gt; I’ve created for the purpose of my continued tinkering in SignalR. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_73.png" width="709" height="208"&gt;&lt;/p&gt; &lt;p&gt;Once the Jasmine files are in place, it doesn’t hurt to create a pulse-check specification to make sure the glue’s dry. The JavaScript object shell below will be a roadmap for how we’ll solve this problem. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_74.png" width="355" height="337"&gt;&lt;/p&gt; &lt;p&gt;Once the specifications have been written up, Jasmine’s environment is created and the tests are executed. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_75.png" width="496" height="233"&gt;&lt;/p&gt; &lt;p&gt;If you’ve pinned the tail on the donkey to this point, the results should be quite self-explanatory when you view the calculator page again. If you don’t see the tests, check the &lt;em&gt;passed &lt;/em&gt;checkbox and the passing test will appear. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_76.png" width="593" height="306"&gt;&lt;/p&gt; &lt;p&gt;At this point, to test that the SignalR &lt;em&gt;CalculatorHub&lt;/em&gt; is communicating with the client properly all that’s &lt;em&gt;really &lt;/em&gt;needed is a way to call the &lt;em&gt;Add &lt;/em&gt;method from in a unit test and to verify that the JavaScript code’s &lt;em&gt;showSum &lt;/em&gt;method executed with a parameter of 4. &lt;/p&gt; &lt;p&gt;The first step in getting this working is to modify the test fixture class so it can be supplied any dependencies it might have. In this case, we plan on testing the calculator hub, so it’ll be passed into the fixture in it’s constructor. Also added is the &lt;em&gt;addCallback &lt;/em&gt;field. At this point it’ll be set to &lt;em&gt;false, &lt;/em&gt;but the plan is, to set this variable to the callback method that will be called when the calculation is completed by the hub.&lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_77.png" width="324" height="107"&gt;&lt;/p&gt; &lt;p&gt;Since the constructor’s changed it’d be wise to change the calling code, our jQuery &lt;em&gt;ready &lt;/em&gt;method. This time, we’ll go ahead and create an instance of the SignalR &lt;em&gt;CalculatorHub &lt;/em&gt;and it’ll be provided as a construction argument. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_78.png" width="397" height="98"&gt;&lt;/p&gt; &lt;p&gt;Next, a new specification is added to the &lt;em&gt;init &lt;/em&gt;method. This specification is the unit test that will demonstrate the calculator’s being called properly from the client JavaScript. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_79.png" width="458" height="338"&gt;&lt;/p&gt; &lt;p&gt;It’d help at this point to take a &lt;a title="The Matchers section is really the important part here. You don't need to KNOW this, just have an idea of it and a reference bookmark." href="https://github.com/pivotal/jasmine/wiki/Spies" target="_blank"&gt;peek at the Jasmine Wiki article on Spies&lt;/a&gt; to get an idea of how this sort of verification can be accomplished. Jasmine’s Fluent syntax makes it pretty self-explanatory (and including vsdoc files to provide Intellisense in Visual Studio brings in the Jasmine methods). Jasmine, like Moq and other mocking frameworks, offers unit tests the capability of checking to see if methods have been executed properly.&lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_80.png" width="384" height="180"&gt;&lt;/p&gt; &lt;p&gt;If your Jasmine tests are executed at this point, you’ll see some &lt;em&gt;p-r-e-t-t-y&lt;/em&gt; interesting results. For about 5 seconds the browser will let you know something’s happening by making the current test’s background color yellow. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_81.png" width="700" height="437"&gt;&lt;/p&gt; &lt;p&gt;Then the test will complete execution and fail. Jasmine is assuming via those calls earlier assume they should wait for an asynchronous response and if it doesn’t arrive, the tests will fail. They fail because the callback methods are never executed, &lt;em&gt;and the tests expect them to be&lt;/em&gt;. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_82.png" width="700" height="437"&gt;&lt;/p&gt; &lt;p&gt;That &lt;em&gt;addCallback &lt;/em&gt;field that was added to the test fixture is how this can be accomplished. The client’s &lt;em&gt;showSum &lt;/em&gt;method is the one thing that’s been omitted from the JavaScript code. That’s the method that the SignalR hub will try to call on each client whenever it needs to do so.&lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_83.png" width="388" height="261"&gt;&lt;/p&gt; &lt;p&gt;Within the test fixture resides the &lt;em&gt;onAdd &lt;/em&gt;method. It just executes the fixture’s &lt;em&gt;addCallback &lt;/em&gt;method and feeds it the results from the SignalR &lt;em&gt;CalculatorHub &lt;/em&gt;call. &lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_84.png" width="317" height="187"&gt;&lt;/p&gt; &lt;p&gt;Once that’s all wired up, the test should pass!&lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_85.png" width="683" height="417"&gt;&lt;/p&gt; &lt;p&gt;If you’re obsessive about verifying, just change the expected value to be something wrong and re-run the test. Obviously, if the math fails, so should the test. Otherwise it’d be a pretty useless calculator!&lt;/p&gt; &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/814b0f5cf49c_1109F/image_86.png" width="683" height="417"&gt;&lt;/p&gt; &lt;h2&gt;Recap&lt;/h2&gt; &lt;p&gt;SignalR and Jasmine work quite nicely together. If you apply a little OO elbow grease and take the time to wire things up with callbacks and to verify the execution of those callbacks, SignalR can be tested rather effectively. All it takes is to properly stage, and then verify, that the Hub’s method is called and that, when the Hub fires the client callback, that the callback is executed as your code expects it to be executed. &lt;/p&gt; &lt;p&gt;Thanks for taking the time to stop by. Happy Coding!&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:33 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/doing-bdd-with-signalr-and-jasmine</guid></item><item><title>Richmond Code Camp</title><link>http://bradygaster.com:80/richmond-code-camp-2011</link><description>&lt;p&gt;The Richmond Code Camp was great. NDecision attracted a lot of participants and enthusiasm and motivated me to keep plugging away at it. There was some excellent audience pariticipation and Twitter-reviews from which I got much encouragement. Both sessions I presented were loaded with enthusiasm that Microsoft is, from all public observation, maturing in its attitude and adoption of OSS contribution. That was uplifting, but not my favorite observation from the weekend.&lt;/p&gt;
&lt;p&gt;My favorite observation from the weekend is that it seems like the Microsoft community is finally beginning to realize how much work Microsoft is doing for it and either appreciates, or finally admits in public that it appreciates the contributions Microsoft has been making. There were a few participants and discussions I heard in hallways that were inspiring. I heard a few discussions between OSS enthusiasts who were speaking favorably, rather than with fear and loathing, about a few different .NET projects produced both within Microsoft and independent. That's inspiring, considering that just a few years ago the public opinion of Microsoft's support of OSS a joke, and I heard more snickers and doubt than I did appreciation. That's motivation for myself, those out there who are ISV'ing themselves, and those who want to utilize open-source contributions to ease their own development pains.&lt;/p&gt;
&lt;p&gt;What's frustrating about that is that projects like SignalR might go un-noticed by participants who lack the time or knowledge to maintain a very active level of involvement. Yes, SignalR is new and I'm probably being impatient in wanting the community to get on it yesterday, as is a lot of other technologies within and outside of the .NET stack that need discovering. I fear that, after years of bickering about how Microsoft fails to support the open-source&amp;nbsp;community, that once Microsoft does openly begin supporting the open-source&amp;nbsp;community&amp;nbsp;and the open-source community begins to admit to itself that Microsoft really is supporting it (that was the hard part IMO), that Microsoft misses a few golden opportunities because it fails to market its own efforts effectively. I think we need to do our best to keep researching these young micro-frameworks and pushing the envelope of what's possible in our development framework. That shared contribution thing... it really works!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I didn't get to spend a lot of time with my out-of-state colleagues this weekend, but it was nice to see everyone for the brief conversations and dinner last night. Looking forward to seeing everyone at the next event!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:33 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/richmond-code-camp-2011</guid></item><item><title>MyNuGets - An Orchard Module for NuGet Fans</title><link>http://bradygaster.com:80/mynugets---an-orchard-module-for-nuget-fans</link><description>&lt;p&gt;If you enjoy using NuGet to obtain and distribute your open source work and you maintain a blog or a site using Orchard, this post's for you. I've written a widget that will allow you to enter your author name. Then, the widget will hit the NuGet OData API and find any packages published with that author name. From that, the HTML is build up through the Orchard pipeline and what you get is a nice list of NuGet projects. Check it out for yourself on the &lt;a href="http://www.bradygaster.com/mynugets"&gt;MyNuGets project page&lt;/a&gt; or in the &lt;a target="_blank" href="http://orchardproject.net/gallery/List/Modules/Orchard.Module.MyNuGets"&gt;Orchard Gallery&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:32 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/mynugets---an-orchard-module-for-nuget-fans</guid></item><item><title>Custom Authentication with MVC 3.0</title><link>http://bradygaster.com:80/custom-authentication-with-mvc-3.0</link><description>&lt;p&gt;During a friendly code review discussion a week or so ago I realized I&amp;rsquo;d forgotten my favorite lore of custom authentication/authorization functionality in lieu of ASP.NET P&amp;amp;M. Though I definitely prefer P&amp;amp;M to rolling my own from scratch to the extent that I&amp;rsquo;ve gone as far as to use it as a pass-through there are some times when P&amp;amp;M is too much &amp;ndash; or too little &amp;ndash; so custom schemes must be developed. The thing that surprises me each time I observe a custom scheme is the lack of usage of the IPrincipal/IIdentity interfaces. With MVC 3.0 as my major weapon of choice in web development and my recent adoption of P&amp;amp;M, it became obvious that an opportunity had popped up for mixing my favorite old-school .NET trick into my favorite new-school paradigm.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Here&amp;rsquo;s the thing. If you don&amp;rsquo;t use the IIdentity and IPrincipal interfaces when you create a custom authentication/authorization solution you&amp;rsquo;ve completely missed the boat and I guarantee you you will write 100 times more code, that will be more brittle, than you would have ever written had you just used them in the first place.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img style="border-width: 0px;" src="/Media/Default/Windows-Live-Writer/Custom-Authentication-with-MVC-3.0_12B49/IPrincipal-IIdentity_6.png" alt="image" border="0" title="image" /&gt;&lt;/p&gt;
&lt;p&gt;A quick look into what these two interfaces offer is in order. The graphic above sums it up visually. You&amp;rsquo;ll see that the IIdentity interface is typically considered a requirement for the IPrincipal to exist; obviously this model fits in rather well with MVC&amp;rsquo;s favoritism to IoC/DI practices.&amp;nbsp; The principal wraps around the identity, supplying access to a user&amp;rsquo;s roles. So long as your classes implement the requirements, they can be bound to the HTTP Context, the current thread, basically attached the process so that all the niceties like use of the [Authorize] attribute and role-based location security via the web.config file are possible without tons of rework.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The first class needed in any custom implementation is the identity class. The main purpose of this implementation is to represent the user&amp;rsquo;s name, really, as well as how the user was authenticated and if they &lt;em&gt;are &lt;/em&gt;authenticated. Should the &lt;em&gt;IsAuthenticated &lt;/em&gt;property be set to false at run-time, code later on assumes the user is an anonymous user.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bradygaster.com/Media/Default/Windows-Live-Writer/Custom-Authentication-with-MVC-3.0_12B49/image_2.png"&gt;&lt;img height="402" width="455" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Custom-Authentication-with-MVC-3.0_12B49/image_thumb.png" alt="image" border="0" title="image" style="border-width: 0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next will be the &lt;em&gt;CustomPrincipal &lt;/em&gt;class. Since this class implements &lt;em&gt;IPrincipal, &lt;/em&gt;it can be used to bind itself directly to a thread (or an HTTP Context). Since it can be used in that manner, all the functionality and support offered via web.config-based authorization, use of the [Authorization] attribute, all of that &amp;ndash; it will be maintained and you won&amp;rsquo;t have to write it (or support it, or debug it, and so on). Note how the constructor&amp;rsquo;s argument is highlighted to illustrate the connection between the two classes.&lt;/p&gt;
&lt;p&gt;&lt;img height="329" width="422" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Custom-Authentication-with-MVC-3.0_12B49/image_5.png" alt="image" border="0" title="image" style="border: 0px;" /&gt;&lt;/p&gt;
&lt;p&gt;To wrap these classes up via a native event handler or inherited method we&amp;rsquo;ll create a &lt;em&gt;BaseController&lt;/em&gt;. It could &amp;ndash; and probably should &amp;ndash; be done via an injected service, obviously, but I&amp;rsquo;m honoring the KISS principle [you &lt;em&gt;say principle, I say principal&lt;/em&gt;] for the purposes of this walk-thru. The base controller is shown below and its main purpose in existing &amp;ndash; to authorize the active user account prior to allowing execution of the controller action.&lt;/p&gt;
&lt;p&gt;&lt;img height="277" width="602" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Custom-Authentication-with-MVC-3.0_12B49/image_10.png" alt="image" border="0" title="image" style="border: 0px;" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Caveat: This next part isn&amp;rsquo;t a recommendation, it&amp;rsquo;s only used for the purposes of keeping this explanation simple. Forgive me. &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now that we&amp;rsquo;ve satisfied the authorization part we&amp;rsquo;ve got to authenticate the user and store their login information somewhere for the life of their&amp;hellip; yeah, you guess it, &lt;em&gt;for the life of their session. &lt;/em&gt;We&amp;rsquo;re going to use &lt;em&gt;Session &lt;/em&gt;here, okay, but just for the demo. It isn&amp;rsquo;t a recommendation. Please turn &lt;em&gt;off &lt;/em&gt;the tape recorder.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;SimpleSessionPersister&lt;/em&gt; class below persists the user&amp;rsquo;s name into a session variable [ducks under flying tomato]. The login controller action below the utility class just validates that the user provided &lt;em&gt;something &lt;/em&gt;for their username and password and, if so, the user&amp;rsquo;s username is persisted to session for use &amp;ndash; by the &lt;em&gt;BaseController, &lt;/em&gt;specifically &amp;ndash; later during the HTTP request.&lt;/p&gt;
&lt;p&gt;&lt;img height="696" width="783" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Custom-Authentication-with-MVC-3.0_12B49/image_13.png" alt="image" border="0" title="image" style="border: 0px;" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;You can relax now, that part&amp;rsquo;s over. &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Now that the user has been authenticated we can assume that each controller we create (provided it inherit from our custom base) will authorize each individual request per the best-practice role-base security means. Take the following controller action below, which requires the user be authenticated via the [Authorize] attribute and the web.config, also below, which indicates the login page URL as our Login controller action.&lt;/p&gt;
&lt;p&gt;&lt;img height="519" width="682" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Custom-Authentication-with-MVC-3.0_12B49/image_25.png" alt="image" border="0" title="image" style="border: 0px;" /&gt;&lt;/p&gt;
&lt;p&gt;Should a user try to hit the non-anonymous page they&amp;rsquo;d be redirected to the login page (see the URL highlighted below).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img height="266" width="458" src="http://bradygaster.com/Media/Default/Windows-Live-Writer/Custom-Authentication-with-MVC-3.0_12B49/image_22.png" alt="image" border="0" title="image" style="border: 0px;" /&gt;&lt;/p&gt;
&lt;p&gt;To review the process we went through to accomplish our very own custom-made end-to-end security paradigm that still allows usage of the .NET built-in role-based security resources, here&amp;rsquo;s what we had to do:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Implement the IIdentity interface in a custom class&lt;/li&gt;
&lt;li&gt;Inherit from the IPrincipal interface in a custom class&lt;/li&gt;
&lt;li&gt;Create a way to authenticate the user&lt;/li&gt;
&lt;li&gt;Create a way to persist the authentication information [a.k.a. &lt;em&gt;username&lt;/em&gt; in this example]&lt;/li&gt;
&lt;li&gt;Override the &lt;em&gt;OnAuthorization &lt;/em&gt;method in a base controller and then use that base controller in future controllers&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Happy Coding! If you&amp;rsquo;d like to take a peek at the code for this demo and debug it for better observation as to how it all works together &lt;a target="_blank" href="http://dl.dropbox.com/u/3597725/MVCCustomAuthSample.zip"&gt;you can download the code from my DropBox account&lt;/a&gt;.&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:32 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/custom-authentication-with-mvc-3.0</guid></item><item><title>NHQS NuGet Package</title><link>http://bradygaster.com:80/nhqs-nuget-package</link><description>&lt;p&gt;This evening I was finally able to get the NHQS library up on NuGet. As always, you can use either the NuGet package explorer or the command-line tool to grab yourself NHQS.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img height="96" width="767" src="/Media/Default/CodeScreenShots/install-nhqs.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;I'll be maintaining most of the general information about NHQS on the &lt;a href="http://bradygaster.com/nhqs"&gt;main NHQS page here on my site&lt;/a&gt;, which you can see in the navigation bar above. Hope NHQS makes your life with NHibernate a little easier!&lt;/p&gt;
&lt;p&gt;Happy coding!&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:31 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/nhqs-nuget-package</guid></item><item><title>Announcing the Release of NDecision</title><link>http://bradygaster.com:80/announcing-the-ndecision-1.0-release</link><description>&lt;p&gt;A pet project of mine for a few months, NDecision is finally going to be allowed to see the light of day. You can get it as a &lt;a target="_blank" href="http://nuget.org/List/Packages/NDecision"&gt;NuGet package&lt;/a&gt; right now.&lt;/p&gt;
&lt;p&gt;&lt;img height="86" width="762" alt="NDecision NuGet Install" src="/Media/Default/CodeScreenShots/ndecision-install.png" /&gt;&lt;/p&gt;
&lt;p&gt;If you'd like to see a video of NDecision being installed and used in a brand new project, there's a video below. Finally, click the NDecision link in the navigation bar above if you'd like to read more about NDecision. There's not a lot to it, but that's kind of the point.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;iframe width="425" height="349" src="http://www.youtube.com/embed/Nq39YLw5DB8" frameborder="0"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;Keep watching this blog and the NDecision page, though, I've got some more stuff related to NDecision I'll be talking about in a few days. For now, grab it and start using the BDD decisioning goodness that NDecision offers!&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:30 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/announcing-the-ndecision-1.0-release</guid></item><item><title>Introducing NDecision.Aspects</title><link>http://bradygaster.com:80/ndecision-with-aop</link><description>&lt;p&gt;If you've not gotten up to speed with the core functionality provided via NDecision it might be good to take a look at the release announcement, &lt;a href="http://bradygaster.com/announcing-the-ndecision-1.0-release" title="NDecision Release Announcement" target="_blank"&gt;which you can find here.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you're into Aspect-Oriented Programming or you like things to be a little more dynamic and automatic, a second option exists that you might find interesting. The NDecision.Aspects package makes use of the amazing AOP product &lt;a href="http://www.sharpcrafters.com/postsharp" title="PostSharp, the best AOP framework for .NET" target="_blank"&gt;PostSharp&lt;/a&gt;, by &lt;a href="http://www.sharpcrafters.com/" title="SharpCrafters, makers of PostSharp" target="_blank"&gt;SharpCrafters&lt;/a&gt;, to enable logic execution automatically at run-time. Rather than write your logical specifications inline, you implement the IHasSpec&amp;lt;T&amp;gt; interface. This interface's single method, GetSpec(), allows you the freedom of wiring up your logic in one place (or in many places, if you prefer to have your specifications split into individual classes based on your own need or preferences).&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Refactoring the Example for NDecision.Aspects&lt;/h2&gt;
&lt;p&gt;I'll build on the &lt;a target="_blank" title="The original NDecision example" href="http://bradygaster.com/announcing-the-ndecision-1.0-release"&gt;previous example&lt;/a&gt; and refactor the code to use the NDecision.Aspects package and to provide some insight into the difference. First of all, the logic from the original code has been moved into an implementation of the IHasSpec&amp;lt;BugsBunny&amp;gt; interface.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="/Media/Default/CodeScreenShots/bunny_spec_implementation.png" alt="Implementing the rules for an object in an IHasSpec implementation" width="532" height="524" /&gt;&lt;/p&gt;
&lt;p&gt;Once your IHasSpec&amp;lt;T&amp;gt; implementation has been written, the majority of the work is complete. To use the specifications outlined in the IHasSpec&amp;lt;T&amp;gt; implementation, the ApplySpecsBeforeExecution (or ApplySpecsAfterExecution) attribute class can be used to decorate the methods whenever the specifications need to be applied. The screen shot below demonstrates how, using the ApplySpecsBeforeExecution attribute, the rules will automatically be applied prior to the method's logic being executed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img height="353" width="480" alt="Method with a parameter decorated for automatic specification application" src="/Media/Default/CodeScreenShots/decorated_method_with_target.png" /&gt;&lt;/p&gt;
&lt;p&gt;If a second parameter for which there existed IHasSpec&amp;lt;T&amp;gt; implementations were placed on this method, specifications for that parameter would be picked up too. In this way, AOP takes over - for any parameter added to this method for which there exists an IHasSpec&amp;lt;T&amp;gt; implementation, the specifications will be dynamically found and executed on the parameter instance at run-time.&lt;/p&gt;
&lt;p&gt;Your rules, in a sense, are automatically applied whenever you want them to be applied.&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;NDecision with AOP, Option Two - Self-Awareness&lt;/h2&gt;
&lt;p&gt;Now, there may exist a circumstance where your object instances - in this case our favorite childhood cartoon character - should be allowed to do their own work based on the specifications and how they should be applied. In these cases it would be more optimal to have the capability of applying the ApplySpecsBeforeExecution or ApplySpecsAfterExecution attributes to the target class itself (or specifically, to methods of the target class). The code from above has been refactored with this idea in mind. Specifically, we've given Bugs his own method, also decorated with the ApplySpecsBeforeExecution attribute.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img height="286" width="521" alt="Self-driven functionality" src="/Media/Default/CodeScreenShots/decorated_self_driven_method.png" /&gt;&lt;/p&gt;
&lt;p&gt;Likewise, the program code will need to be changed so that it allows Bugs his autonomy.&lt;/p&gt;
&lt;p&gt;&lt;img src="/Media/Default/CodeScreenShots/main_method_with_self_driven_changes.png" alt="Allowing the target class to drive itself" width="450" height="240" /&gt;&lt;/p&gt;
&lt;p&gt;Both methods result with the following obvious output - a console window showing the directions Bugs takes on his journey, in the order they were taken.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="/Media/Default/CodeScreenShots/ndecision_demo_output.png" alt="Output of the demonstration code" width="479" height="138" /&gt;&lt;/p&gt;
&lt;p&gt;Just like the NDecision core project, &lt;a target="_blank" title="NDecision.Aspects on NuGet" href="http://nuget.org/List/Packages/NDecision.Aspects"&gt;NDecision.Aspects is available for free via NuGet&lt;/a&gt;. Don't worry about the dependencies or having to install both packages; simply installing NDecision.Aspects will bring down everything you need, including the PostSharp assembly, as SharpCrafters so generously offer it up as a NuGet package too.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img height="86" width="762" alt="NDecision.Aspects NuGet install " src="/Media/Default/CodeScreenShots/ndecision-aspects-install.png" /&gt;&lt;/p&gt;
&lt;p&gt;Happy coding! I hope you give NDecision a spin. If you do take the time to play with it, please let me know how it works out for you via the comments form. Or, you can find me on &lt;a target="_blank" href="http://twitter.com/#!/bradygaster"&gt;Twitter at @bradygaster.&lt;/a&gt;&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:30 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/ndecision-with-aop</guid></item><item><title>Developers Guild AOP and PostSharp Presentation</title><link>http://bradygaster.com:80/developers-guild-aop-and-postsharp-presentation</link><description>&lt;p&gt;Last night I presented &lt;a href="http://www.sharpcrafters.com/" target="_blank"&gt;PostSharp&lt;/a&gt; and AOP at the &lt;a href="http://www.developersguild.org/" target="_blank"&gt;Charlotte Enterprise Developer's Guild&lt;/a&gt;. I had a great &amp;nbsp;time and the audience seemed to enjoy the topic.&lt;/p&gt;
&lt;p&gt;I've put the code samples and presentation deck in my public Dropbox so feel free to download it and should you have any feedback it is welcome. In fact, I've set up a SurveyMonkey survey for the participants, so if you have a moment and you attended the presentation I'd appreciate you taking 1-2 minutes and completing the survey. Every little bit of feedback helps me improve these sessions, so anything you can provide would be helpful. Below you'll find links to the code and the evaluation, as well as links to some of the resources I mentioned in the presentation.&amp;nbsp;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://dl.dropbox.com/u/3597725/AOP_PostSharp_Guild_07262011.zip"&gt;Session Examples and Slide Deck&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.surveymonkey.com/s/JMVLZQQ" target="_blank"&gt;Session Evaluation Survey&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.sharpcrafters.com/blog/author/Matthew-Groves.aspx" target="_blank"&gt;Matthew Groves' excellent SOLID series&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/SOLID" target="_blank"&gt;Wikipedia page on SOLID&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.sharpcrafters.com/solutions/notifypropertychanged" target="_blank"&gt;The INotifyPropertyChanged documentation article I failed to find during the session&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for attending the session if you were there, thanks to the Guild organizers, and thanks to my boss Dan who let me remote into my laptop from his when the mini DVI jack failed for a second time (at least now we think we know what it is, though).&amp;nbsp;&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:29 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/developers-guild-aop-and-postsharp-presentation</guid></item><item><title>Netduino Controlled by Kinect</title><link>http://bradygaster.com:80/netduino-controlled-by-kinect</link><description>&lt;p&gt;&lt;strong&gt;Update: &lt;/strong&gt;I've uploaded the code I wrote for this demonstration project to GitHub into my &lt;a target="_blank" href="https://github.com/bradygaster/KinectControlledNetduino"&gt;KinectControlledNetduino&lt;/a&gt; public repository. I also forgot to mention that the Kinect code makes use of the &lt;em&gt;excellent &lt;/em&gt;gesturing engine created by David Catuhe, which you can &lt;a target="_blank" href="http://blogs.msdn.com/b/eternalcoding/archive/2011/07/04/gestures-and-tools-for-kinect.aspx"&gt;read about on his blog&lt;/a&gt; or &lt;a target="_blank" href="http://kinecttoolkit.codeplex.com/"&gt;download from CodePlex&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I'll put the code up here tomorrow once time and energy permit, but for the time being the title says it all. There's a Kinect, it controls a WPF app, that app sends messages to an HTTP server running on a Netduino, which is connected to a servo.&lt;/p&gt;
&lt;p&gt;Using hand gestures like "SwipeRight" or "SwipeLeft," a user can literally wave to the Kinect to tell it how to tell the Netduino server how to angle the servo. Pretty neat, and quite easier than I'd expected. I'll post the code ASAP but for now here's a video demonstrating how it works.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;iframe frameborder="0" src="http://www.youtube.com/embed/QWiRGT58BoQ" height="349" width="425"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:29 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/netduino-controlled-by-kinect</guid></item><item><title>Introducing the NHibernate QuickStart (NHQS, Part 1)</title><link>http://bradygaster.com:80/nhqs-part-1-introducing-the-nhibernate-quickstart</link><description>&lt;p&gt;If you’ve worked with me over the past year or you’ve seen one of my alt group meetings, chances are I’ve mentioned, demonstrated, or maybe stuffed down your throat, the NHQS thingamabob. With the improvements in NHibernate following .NET 4.0 and the experiences I learned in a few projects in the previous release I’ve decided to rewrite NHQS for NHibernate 3.xx. I like the improvements in NHibernate and with those and a slightly renewed focus on my goal for NHQS I felt it might be worthwhile to introduce it on its own into the wild. This post will introduce the world to NHQS and provide a guideline for its usage.&lt;/p&gt; &lt;p&gt;As usual the project is only as effective as is the goal it intends to serve so let’s get that out of the way.&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;span style="color: #373737" color="#373737"&gt;A lot of developers want to use NHiibernate, or Fluent NHibernate, or some flavor therein, but don’t want to learn the layers and layers of how-and-why it works just to get up and running. NHQS should mitigate this confusion and ease the transition into usage of NHibernate. A secondary goal of NHQS is to make it easy for a developer to have access to any and all persistent storage mechanisms supported by NHibernate in a fluent and domain-centric manner. At the highest level, a developer facilitating object persistence via NHQS should neither need to know nor be exposed to the underlying persistence mechanism. &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;To accomplish that goal we’re going to walk through the steps of setting up and using NHQS to access multiple databases via the almost-too-simple-to-be-legit fluent/generic interfaces exposed almost solely via extension methods. I’m sure I’ll get burned at the stake for failing to follow &lt;em&gt;someone’s &lt;/em&gt;NHibernate Best Practice 101 list, so I’ll apologize up front. With that, here’s the synopsis of the blog series, which I aim to complete by the end of this week.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;a href="http://bradygaster.com/nhqs-part-1-introducing-the-nhibernate-quickstart"&gt;Introduction (this post) &lt;/a&gt; &lt;li&gt;&lt;a href="http://bradygaster.com/nhqs-part-2-sessionfactory-creation-and-containment"&gt;Session Factory Creation and Containment &lt;/a&gt; &lt;li&gt;&lt;a href="http://bradygaster.com/nhqs-part-3-session-fluency-extensions"&gt;Session Fluency Extensions &lt;/a&gt; &lt;li&gt;&lt;a href="http://bradygaster.com/nhqs-part-4-multiple-database-connectivity-and-transaction-management" target="_blank"&gt;Transactions and Multiple Database Support&lt;/a&gt; &lt;/li&gt;&lt;/ol&gt; &lt;h2&gt;NHQS in 30 Seconds&lt;/h2&gt; &lt;p&gt;There are a few steps one must follow to get their persistence mechanism accessible via NHQS. Here they are:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Implement the &lt;em&gt;ISessionFactoryCreator&lt;/em&gt; interface via a class of your own (we’ll cover this in a moment)  &lt;li&gt;Add code to the startup of the calling application (or in your &lt;em&gt;TestFixtureSetup&lt;/em&gt; method) that calls the &lt;em&gt;Create&lt;/em&gt; method of that class to create an NHibernate &lt;em&gt;ISessionFactory&lt;/em&gt; object instance  &lt;li&gt;Take the resultant &lt;em&gt;ISessionFactory &lt;/em&gt;and store it using the &lt;em&gt;SessionFactoryContainer&lt;/em&gt; class  &lt;li&gt;Write DDD-like code to get objects from databases and perform CRUD operations via an arsenal of extension methods attached to areas of NHibernate &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The second post in this series will begin the process of using NHQS in a real-world situation by simplifying the art of creating &lt;em&gt;ISessionFactories &lt;/em&gt;and storing them in a container, so check back soon.&lt;/p&gt; &lt;p&gt;If you’d like to skip the blogs and look at the source, feel free, I keep the &lt;a href="https://github.com/bradygaster/NHibernate-QuickStart" target="_blank"&gt;NHQS source in Github&lt;/a&gt;.&lt;/p&gt;</description><pubDate>Mon, 12 Dec 2011 13:02:28 GMT</pubDate><guid isPermaLink="true">http://bradygaster.com:80/nhqs-part-1-introducing-the-nhibernate-quickstart</guid></item></channel></rss>

