<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DEV SCRUM .NET</title>
	<atom:link href="http://blog.devscrum.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.devscrum.net</link>
	<description>agile development with the .NET framework</description>
	<lastBuildDate>Wed, 31 Oct 2012 19:06:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Querying data from the WadLogsTable in Windows Azure</title>
		<link>http://blog.devscrum.net/2012/10/querying-data-from-the-wadlogstable-in-windows-azure/</link>
		<comments>http://blog.devscrum.net/2012/10/querying-data-from-the-wadlogstable-in-windows-azure/#comments</comments>
		<pubDate>Wed, 31 Oct 2012 18:47:48 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Repository]]></category>
		<category><![CDATA[WadLogsTable]]></category>
		<category><![CDATA[Windows Azure]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=731</guid>
		<description><![CDATA[<p>When writing any application, particularly an application built for Azure, it is vital to have a good logging strategy in place. How many times have you heard someone in the office say &#8220;hey the system has just gone down, but &#8230; <a href="http://blog.devscrum.net/2012/10/querying-data-from-the-wadlogstable-in-windows-azure/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/10/querying-data-from-the-wadlogstable-in-windows-azure/">Querying data from the WadLogsTable in Windows Azure</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>When writing any application, particularly an application built for Azure, it is vital to have a good logging strategy in place.  How many times have you heard someone in the office say &#8220;hey the system has just gone down, but we don&#8217;t know why?&#8221; It is important to log anything that can help diagnose a issue raised in production to assist towards a quick resolution of the fault.  </p>
<p>Windows Azure has some pretty cool diagnostic features built into the SDK, which allows you to write to a log store held within table storage.  Typically to activate logging it is as simple as adding the following startup code within a cloud service, whether it be a web or worker role, which will initialise your service to write to the Azure logs table.</p>
<pre class="brush: csharp">
private DiagnosticMonitorConfiguration DiagnosticMonitorConfiguration()
{
    var diagnosticMonitorConfiguration = DiagnosticMonitor.GetDefaultInitialConfiguration(); 
    diagnosticMonitorConfiguration.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
    diagnosticMonitorConfiguration.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
    return diagnosticMonitorConfiguration;
}

DiagnosticMonitor.Start(&quot;Microsoft.WindowsAzure .Plugins.Diagnostics.ConnectionString&quot;, diagnosticMonitorConfiguration);
</pre>
<p>You can then use the trace classes to write to the log.  The below shows writing to the log with the log level set to exception.</p>
<pre class="brush: csharp">
Trace.TraceError(&quot;An exception has occured for UserId {0}, exception is {1}, userId, ex.ToString());
</pre>
<p>The diagnostic support allows you to configure things such as the log level and the frequency to batch write your logging to table storage.  It can also be used to configure performance counters, which includes being able to specify what performance counters to monitor on a service, as well as a few other things.</p>
<p>Within Azure commonly you would have a storage account which is used only for logging, monitoring etc.  For logging Azure creates an entity in table storage which is called the WadLogsTable.  This entity will include any logging message, the logging level, which role the logging was from etc.   </p>
<p>A requirement I recently had was to be able to query this table and return anything logged with a logging level of Exception or above.  The idea was to take this data from table storage and move it into a SQL database, where the data can be collated and be able to run a number of Reporting services reports over the data, to provide stats on the frequency of types of errors over the course of a day etc.</p>
<p>Within the Azure SDK, there is no built in TableServiceEntity which represents the WadLogsTable, therefore you have to role your own.  The class below is an example of this.  I have created a class which inherits from TableServiceEntity and includes all the properties with the same name and data type as per the WadLogsTable within table storage.  The TableServiceEntity is the base class for any entity that is stored within table storage.</p>
<pre class="brush: csharp">
namespace AzureDiagnosticsService.Domain
{
    public class WadLogsTable : TableServiceEntity
    {
        public string Role { get; set; }
        public string RoleInstance { get; set; }
        public int Level { get; set; }
        public string Message { get; set; }
        public int Pid { get; set; }
        public int Tid { get; set; }
        public int EventId { get; set; }
        public DateTime EventDateTime
        {
            get
            {
                return new DateTime(long.Parse(PartitionKey.Substring(1)));
            }
        }
    }
}
</pre>
<p>To query table storage, I need a class which inherits from TableServiceContext, as per the Repository class shown below.  You can think of the TableServiceContext as the equivalent of the DbContext, which is used within the Entity framework.</p>
<p>Unlike the Entity framework where you can use the same DbContext against multiple entities defined within the context, an instance of the TableServiceContext can only be used against a single table storage entity type.  This may seem a little odd at first but it actually makes perfect sense for the reason that table storage is a completely different beast to a standard relational database such as SQL server.  In table storage there are no relationships, each table is independent from any other.</p>
<p>The code below shows a generic repository, where T is a TableServiceEntity.  The repository would be used to perform CRUD operations against entities stored within Table storage in Azure.  For the sake of simplicity this example only shows a generic LoadBy method, operations such as Add, Update and Delete are omitted.  </p>
<p>The results returned from the query are automatically mapped to the WadLogsTable TableServiceEntity, as the property name and data types match.  No need for Automapper here.</p>
<pre class="brush: csharp">
public class Repository&lt;T&gt; : TableServiceContext, IRepository&lt;T&gt; where T : TableServiceEntity
{
    private readonly string entitySetName;

    public Repository(string baseAddress, StorageCredentials credentials) : base(baseAddress, credentials)
    {
        entitySetName = typeof (T).Name;
    }

    public List&lt;T&gt; LoadBy(Func&lt;T, bool&gt; expression)
    {
        var result = CreateQuery&lt;T&gt;(entitySetName);
        return result.Where(expression).ToList();
    }
}
</pre>
<p>The LoadBy method within the repository above takes a Func with the following signature Func&lt;T, bool&gt;, where T is the WadLogsTable in this example.  The idea of inserting a Func expression into the the LoadBy method allows this method within the repository to be completely generic, by being able to pass in any expression to be performed against this entity or any other for that matter.  Let me show you an example of the expression below.</p>
<pre class="brush: csharp">
public class WadLogsQueryObject : IWadLogsQueryObject
{
    public Func&lt;WadLogsTable, bool&gt; ByLastMinutes(int minutes)
    {
        Func&lt;WadLogsTable, bool&gt; expression = x =&gt; x.PartitionKey.CompareTo(&quot;0&quot; + DateTime.UtcNow.AddMinutes(minutes).Ticks) &gt;= 0;
        return expression;
    }
}
</pre>
<p>The above expression which I am going to refer to as the query object, is the lambda that I am going to use as my filter.  The query object allows me to pass in a parameter in this case the last number of minutes I want to retrieve WadLogsTable entries for.  Within these QueryObject classes I can store together all the operations I would want to run against a particular entity.  Storing these queries in a separate class and passing them into the repository also helps make the whole thing testable when using Mocks.</p>
<p>In most cases you would probably want to query the WadLogsTable by the timestamp to retrieve for example all the logs for the last hour lets say.  An entity within table storage always has two keys, the PartitionKey and the RowKey.  These are the only two columns which are indexed and therefore optimised for running queries against.  With the WadLogsTable the convenient thing is the PartitionKey is actually the timestamp, with an additional zero appended to the beginning.  This means that I can run a query against the table using the ParitionKey substituting the leading zero as is shown above in the Func expression.</p>
<p>Having loaded this data into my object, I could then do what I liked with it, using Linq to objects if I wanted to filter the results any further and persist it to anywhere of my choosing if necessary.  The same trick can be used for not only the WadLogsTable but it can also be used for the WadPerformanceCountersTable and WadWindowsEventLogTable.</p>
<p>I hope this post shows you how to access logging data from Azure and also has shown you a few nice tips and tricks towards the start of a nice reusable repository for table storage. </p>
<p>The post <a href="http://blog.devscrum.net/2012/10/querying-data-from-the-wadlogstable-in-windows-azure/">Querying data from the WadLogsTable in Windows Azure</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/10/querying-data-from-the-wadlogstable-in-windows-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running a Load Test Rig in Windows Azure</title>
		<link>http://blog.devscrum.net/2012/10/running-a-load-test-rig-in-windows-azure/</link>
		<comments>http://blog.devscrum.net/2012/10/running-a-load-test-rig-in-windows-azure/#comments</comments>
		<pubDate>Sat, 27 Oct 2012 12:58:19 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Load Testing]]></category>
		<category><![CDATA[Azure Performance Testing]]></category>
		<category><![CDATA[Load Test Rig]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Windows Azure Connect]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=672</guid>
		<description><![CDATA[<p>One of the main benefits of Windows Azure is being able to easily scale an application out where by you can add additional role instances in matter of minutes to meet demand. As well as being a great platform for &#8230; <a href="http://blog.devscrum.net/2012/10/running-a-load-test-rig-in-windows-azure/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/10/running-a-load-test-rig-in-windows-azure/">Running a Load Test Rig in Windows Azure</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>One of the main benefits of Windows Azure is being able to easily scale an application out where by you can add additional role instances in matter of minutes to meet demand.  As well as being a great platform for hosting and running your applications, it is also ideal for using it to host a load test rig, giving you all the great scaling benefits of Azure, by being able to spin up any number of instances to run load test agents upon and then just as easily scale back down when your test is complete.</p>
<p>I recently set up a load test rig in Azure to run load tests against cloud services also hosted within Azure.  This post does not talk through how to create the rig, there is a great set of articles on the Windows Azure developer site which does exactly that. You can read them here <a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh674491.aspx" title="http://msdn.microsoft.com/en-us/library/windowsazure/hh674491.aspx" target="_blank">Setting up a Load Test Rig in Windows Azure</a></p>
<p>The intention of this post is to discuss the components that make up a test rig in Azure and talk through some of the lessons I learned from setting up the rig, hopefully so you don&#8217;t have to feel all the pain I had setting it up for the first time.</p>
<p>The below diagram shows the architecture of the Load Test Rig.  </p>
<div id="attachment_677" class="wp-caption alignnone" style="width: 860px"><a href="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Load-Test-Rig.png"><img src="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Load-Test-Rig.png" alt="Windows Azure Load Test Rig Architecture" title="Windows Azure Load Test Rig" width="850" height="684" class="size-full wp-image-677" /></a><p class="wp-caption-text">Windows Azure Load Test Rig Architecture</p></div>
<p><strong>Local Machine</strong><br />
This is simply the machine that kicks off the test, such as the developers or testers machine.  A load test can be started from within Visual Studio Ultimate.  However before you start a test to run against a controller hosted remotely inside Azure, you need to configure the test controller settings. </p>
<p>The first think todo is to add a testsettings file to the solution that contains the load tests.  The testsettings file allows you to specify settings that are applied when you execute your tests in Visual Studio.  To run a test against Azure you need to set the test execution method as &#8220;Remote&#8221; and include the name of the controller.  This is shown below</p>
<div id="attachment_692" class="wp-caption alignnone" style="width: 1039px"><a href="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Test-Settings.png"><img src="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Test-Settings.png" alt="" title="Windows Azure Test Settings" width="1029" height="714" class="size-full wp-image-692" /></a><p class="wp-caption-text">Visual Studio Test Settings File Configuration</p></div>
<p><em>Full details of configuring testsettings can be read here.</em> <a href="http://msdn.microsoft.com/en-us/library/ee256991.aspx" title="http://msdn.microsoft.com/en-us/library/ee256991.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ee256991.aspx</a></p>
<p>You also need to set the controller and the database the test results will be stored in on the &#8220;Manage Test Controllers&#8221; option found under the &#8220;Test&#8221; menu in Visual Studio.</p>
<div id="attachment_706" class="wp-caption alignnone" style="width: 667px"><a href="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Manage-Test-Controller.png"><img src="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Manage-Test-Controller.png" alt="" title="Windows Azure Manage Test Controller" width="657" height="656" class="size-full wp-image-706" /></a><p class="wp-caption-text">Windows Azure Manage Test Controller</p></div>
<p><strong>Visual Studio Test Controller</strong><br />
The controller is responsible for starting a test run.  When a load test is executed from the local machine the assemblies required to run the test are copied to the controller.  The files are copied to a directory on the controller in the following location D:\Users\[USER]\AppData\Local\VSEQT\QTController.  Each deployment will have a further directory named with a unique GUID where the files are copied.</p>
<p>Once the files have been deployed the controller is responsible for sending the load test and deployed assemblies to all the agents that are configured to run the test.  The controller polls the agents to see when they are ready.  When all agents are initialised the controller then sends a message to all the agents to start the test.</p>
<p>The controller machine is also responsible for collating all the results from the test run.  The results are stored within a SQL Server database.  The database is called loadTest2010 and is created when the test controller is installed on the instance.  To be able to connect to the SQL database from the local machine you have to add a firewall rule to allow TCP traffic on port 1433.</p>
<p>You can think of the controller as a service broker.</p>
<p><strong>Visual Studio Test Agent(s)</strong><br />
The agents are effectively the clients that execute the tests.  The more agents you have the more load you can thrust upon your system, this is where Azure comes in great for the ease of spinning up additional agent instances.  All the agents are running a service that listens from requests from the controller.  </p>
<p>There is no limit to the number of agents that can be created.  Each agent will run the same load test in a test run.  Agents can be given a weighting, which can be seen as the proportion of the overall load that each agent runs.</p>
<p><strong>System under Test</strong><br />
The system under test is your system, made up of web and worker roles that you want to test.  Performance counters can be collected from any Azure instance as long as they are part of the same Windows Azure Connect group as the local machine, test controller and test agents.</p>
<p><strong>Windows Azure Connect Group Setup</strong><br />
In order to create a load test rig in Azure and run the performance tests against services hosted in Azure, all components must be part of the same Windows Azure Connect Group.   To add all the machines into a virtual network every machine must have the same user account, must have the Windows Azure Connect endpoint installed with the same activation token and must be must be added to the same virtual network group from within the Windows Azure Portal.</p>
<ul>
<li><em>Configure User Account</em><br />
The same user account with administrative privileges must be created on all nodes that form part of the virtual network.  This comprises of the local machine, test controller, test agents and every instance for which you want to retrieve performance counters for within the system under test.</p>
<p>The easiest way to add an user account to all role instances in Azure is to use the remote access account, which can be configured in the service configuration file. </p>
<p><code>
<pre lang="xml">
&lt;Setting name=&quot;Microsoft.WindowsAzure.Plugins.RemoteAccess.Enabled&quot; value=&quot;true&quot; /&gt;
&lt;Setting name=&quot;Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername&quot; value=&quot;[USERNAME]&quot; /&gt;
&lt;Setting name=&quot;Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword&quot; value=&quot;[PASSWORD]&quot; /&gt;
</pre>
<p></code></p>
<p>These service configuration settings are populated when you choose to “Configure remote desktop” settings, which can be accessed on the right click menu of the Cloud project within Visual Studio.</p>
<p>You will need to create an account on the local machine which has the same username and password as to the account created on each role instance in Azure.  It is this account that you need to be logged into when you start a load test run.</li>
<li><em>Install Windows Azure Connect</em><br />
The Windows Azure Connect endpoint needs to be installed on the local machine and all role instances including the test controller, all the test agents as well as all role instances for the system under test.  This needs to be installed with the same activation token.  </p>
<p>The activation token can be accessed by going to the Virtual Network tab within the Windows Azure Portal and clicking on the “Get Activation Token” option within the ribbon.</p>
<p><a href="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Get-Activation-Token-Option.png"><img src="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Get-Activation-Token-Option.png" alt="Windows Azure Get Activation Token Option" title="Windows Azure Get Activation Token Option" width="363" height="151" class="alignnone size-full wp-image-678" /></a></p>
<p>The easiest way I have found to install the endpoint on each role instance with the given activation token is to run a custom bat file to install Windows Azure Connect and run the script as a  startup task which can be configured within the service definition file of the cloud project.  The following post covers how this can be achieved.  <a href="http://blog.devscrum.net/2012/10/installing-windows-azure-connect-with-a-start-up-task/" title="Installing Windows Azure Connect as a start-up Task" target="_blank">Installing Windows Azure Connect as a Start-up Task</a></li>
<li><em>Enabling Firewall Rules</em><br />
In order to retrieve performance counters from any instance within the system under test, you need to allow a couple inbound firewall rules on each Azure instance.  These firewall rules are the &#8220;File and Printer Sharing&#8221; and &#8220;Performance Logs and Alerts&#8221;.  These can be added manually on each instance from wf.msc and can be found under the predefined option, or you can use netsh advfirewall from the command line to automate the task.   The following post covers how this can be achieved.  <a href="http://blog.devscrum.net/2012/10/installing-windows-azure-connect-with-a-start-up-task/" title="Installing Windows Azure Connect as a start-up Task" target="_blank">Installing Windows Azure Connect as a Start-up Task</a><br/><br/></li>
<li><em>Configuring the Windows Azure Connect Group in the Windows Azure Portal</em><br />
This requires creating a group under the Virtual Network option in the Windows Azure Portal and adding the machine instances to this group to allow all machines to function as if they are on the same network.</p>
<p><div id="attachment_718" class="wp-caption alignnone" style="width: 664px"><a href="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Connect-Group.png"><img src="http://blog.devscrum.net/wp-content/uploads/2012/10/Windows-Azure-Connect-Group.png" alt="" title="Windows Azure Connect Group" width="654" height="526" class="size-full wp-image-718" /></a><p class="wp-caption-text">Windows Azure Connect Group</p></div></li>
<p>As Windows Azure Connect is installed computers will appear at the bottom of the list.  Simply edit the group and add each computer.  As long as you don&#8217;t delete your services from either staging or production before you deploy, the machine names will always be the same, so once all machines have been added to the group from both staging and production you should not need to make any more changes to the Windows Azure Connnect group.</p>
</ul>
<p>Using Windows Azure to host a load test rig is definitely a good idea.  Once the initial setup is complete you have a reliable test rig which can be easily scaled up and down as required, so you don&#8217;t need to make any big investment in hardware to purchase machines to run the test controller and multiple test agents. </p>
<p>I hope this post provides some use to those seeking to setup a test rig within Windows Azure.  I would love to hear any experiences others had had also setting up a rig within Azure.  </p>
<p>The post <a href="http://blog.devscrum.net/2012/10/running-a-load-test-rig-in-windows-azure/">Running a Load Test Rig in Windows Azure</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/10/running-a-load-test-rig-in-windows-azure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Windows Azure Connect with a start-up Task</title>
		<link>http://blog.devscrum.net/2012/10/installing-windows-azure-connect-with-a-start-up-task/</link>
		<comments>http://blog.devscrum.net/2012/10/installing-windows-azure-connect-with-a-start-up-task/#comments</comments>
		<pubDate>Sat, 27 Oct 2012 11:21:56 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Startup Tasks]]></category>
		<category><![CDATA[Virtual Network]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Windows Azure Connect]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=649</guid>
		<description><![CDATA[<p>I recently had the requirement to set up a virtual network within Azure to enable my local development machine to connect to role instances running within Windows Azure and for a number of role instances within Azure to be able &#8230; <a href="http://blog.devscrum.net/2012/10/installing-windows-azure-connect-with-a-start-up-task/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/10/installing-windows-azure-connect-with-a-start-up-task/">Installing Windows Azure Connect with a start-up Task</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>I recently had the requirement to set up a virtual network within Azure to enable my local development machine to connect to role instances running within Windows Azure and for a number of role instances within Azure to be able to communicate directly with each other.  I undertook this task as part of setting up a Visual Studio Load test rig running in azure.  Not only did I need to be able to connect to the test controller and test agents hosted within Azure I also wanted to be able to retrieve performance counters from my web and worker role instances which were also hosted within Azure.</p>
<p>From within the Windows Azure Portal under the Virtual Network setting you can download and install a Windows Azure Connect endpoint, which is required on every machine that will form part of your virtual network.  In addition to this they must all be installed with the same activation token, which can be accessed for a particular subscription under the Virtual network tab and then by clicking on the Get Activation Token button.</p>
<p>The challenge was to be able to automate the installation of the Windows Azure Connect endpoint to all the instances every time I do a deployment, but only to certain subscriptions and also to ensure that when the Windows Azure Connect endpoint is installed that it uses the right activation token for that subscription.  To accomplish this I used a parameterised start-up task.</p>
<p>Within the ServiceDefinition.csdef file within the Cloud project in Visual Studio, you can add custom tasks that are run on startup when a role is installed on Azure.  This can be applied to a web or worker role using the Task configuration element located under the Startup element.  This is shown below.</p>
<p><code>
<pre>
&lt;WorkerRole name=&quot;MyService&quot; vmsize=&quot;Small&quot;&gt;
    &lt;ConfigurationSettings&gt;
        &lt;Setting name=&quot;IsPerformanceTestRig&quot;/&gt;
        &lt;Setting name=&quot;WindowsAzureConnectActivationToken&quot;/&gt;
    &lt;/ConfigurationSettings&gt;
    &lt;Startup&gt;
        &lt;Task commandLine=&quot;deployment\startup\InstallWindowsAzureConnect.cmd &gt;&gt; deployment\startup\installWindowsAzureConnect.log&quot; executionContext=&quot;elevated&quot; taskType=&quot;simple&quot;&gt;
            &lt;Environment&gt;
                &lt;Variable name=&quot;IS_PERFORMANCE_TEST_RIG&quot;&gt;
                    &lt;RoleInstanceValue xpath=&quot;/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='IsPerformanceTestRig']/@value&quot; /&gt;
                &lt;/Variable&gt;
                &lt;Variable name=&quot;WINDOWS_AZURE_CONNECT_ACTIVATION_TOKEN&quot;&gt;
                    &lt;RoleInstanceValue xpath=&quot;/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='WindowsAzureConnectActivationToken']/@value&quot; /&gt;
                &lt;/Variable&gt;
            &lt;/Environment&gt;
        &lt;/Task&gt;
    &lt;/Startup&gt;
  &lt;/WorkerRole&gt;
</pre>
<p></code></p>
<p>The task runs a bat file called InstallWindowsAzureConnect.cmd.  The &gt;&gt; deployment\Startup\installWindowsAzureConnect.log creates a log file which outputs the execution of the bat file.</p>
<p>You can parameterise a task by adding Variables which is shown above.  There are a number of ways to obtain a value to set as the variable.  </p>
<p><code>
<pre>
&lt;Variable name=&quot;WINDOWS_AZURE_CONNECT_ACTIVATION_TOKEN&quot;&gt;
    &lt;RoleInstanceValue xpath=&quot;/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='WindowsAzureConnectActivationToken']/@value&quot; /&gt;
&lt;/Variable&gt;
</pre>
<p></code></p>
<p>The example above gets the value of a configuration setting which will be set in the ServiceConfiguration.cscfg file with its name set to WindowsAzureConnectActivationToken, and will set the WINDOWS_AZURE_CONNECT_ACTIVATION_TOKEN variable which can then be used in the bat file.</p>
<p>The following article lists the different options you have for setting a variable value. <a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh404006.aspx" title="http://msdn.microsoft.com/en-us/library/windowsazure/hh404006.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/windowsazure/hh404006.aspx</a></p>
<p>The following is the InstallWindowsAzureConnect.cmd file contents</p>
<p><code>
<pre>
@ECHO OFF

echo Installing Windows Azure Connect &amp;amp;amp;amp;amp; Enabling Firewall

IF &quot;%IS_PERFORMANCE_TEST_RIG%&quot; == &quot;false&quot; goto END
deployment\startup\Wacendpointpackage.exe /i /s /m en-us /token %WINDOWS_AZURE_CONNECT_ACTIVATION_TOKEN%

IF %ERRORLEVEL% neq 0 goto ERROR_INSTALL
echo Windows Azure Connect Install succeeded

Echo Add Firewall Rules
netsh advfirewall firewall add rule name=&quot;File and Printer Sharing (Echo Request - ICMPv4-In)&quot; dir=in service=&quot;File and Printer Sharing&quot; action=allow protocol=ICMPv4 enable=yes
netsh advfirewall firewall add rule name=&quot;File and Printer Sharing (Echo Request - ICMPv6-In)&quot; dir=in action=allow protocol=ICMPv6 enable=yes
netsh advfirewall firewall add rule name=&quot;Performance Logs and Alerts (DCOM-In)&quot; dir=in action=allow program=&quot;%systemroot%\system32\svchost.exe&quot; protocol=TCP localport=135 enable=yes
netsh advfirewall firewall add rule name=&quot;Performance Logs and Alerts (TCP-In)&quot; dir=in action=allow program=&quot;%systemroot%\system32\plasrv.exe&quot; enable=yes	

IF %ERRORLEVEL% neq 0 goto ERROR_INSTALL
echo Firewall Rules Added
goto END

:ERROR_INSTALL
echo Error Installing Windows Azure Connect.  Return code is %ERRORLEVEL% 
goto END

:END
exit /b 0
</pre>
<p></code></p>
<p>This file runs a executable called “Wacendpointpackage.exe” (which needs to be also deployed with the .cmd file).  This is an exe created by Microsoft to allow you to install Windows Azure Connect from the command line.</p>
<p><code>Wacendpointpackage.exe /i /s /m en-us /token %WINDOWS_AZURE_CONNECT_ACTIVATION_TOKEN%</code></p>
<p>The /i switch is to install, /s is to run silently, /m sets the language and /token sets the activation token.  This here utilises the %WINDOWS_AZURE_CONNECT_ACTIVATION_TOKEN% variable.</p>
<p>The script also allows some firewall rules on each role instance which are required to be able to access the performance counters on each Azure instance.</p>
<p>The only step left once deployment is complete is to go into the Windows Azure Portal and under the Virtual Network tab create a new group and add all instances to that group.  It is important to remember that every role instance within Azure and any on premise machines must all have the same local user that is part of the administrator group.</p>
<p>The post <a href="http://blog.devscrum.net/2012/10/installing-windows-azure-connect-with-a-start-up-task/">Installing Windows Azure Connect with a start-up Task</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/10/installing-windows-azure-connect-with-a-start-up-task/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharing your living documentation with everyone with Pickles</title>
		<link>http://blog.devscrum.net/2012/06/making-your-living-documentation-available-to-everyone-with-pickles/</link>
		<comments>http://blog.devscrum.net/2012/06/making-your-living-documentation-available-to-everyone-with-pickles/#comments</comments>
		<pubDate>Fri, 29 Jun 2012 17:26:21 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Scrum]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=611</guid>
		<description><![CDATA[<p>BDD is a great way to collaboratively define features within your system and understand there intent by writing scenarios using the gherkin language (given, when, then). Another bonus to writing scenarios in such a style is it is easy to &#8230; <a href="http://blog.devscrum.net/2012/06/making-your-living-documentation-available-to-everyone-with-pickles/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/06/making-your-living-documentation-available-to-everyone-with-pickles/">Sharing your living documentation with everyone with Pickles</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>BDD is a great way to collaboratively define features within your system and understand there intent by writing scenarios using the gherkin language (given, when, then).  Another bonus to writing scenarios in such a style is it is easy to take scenarios written in plain English and turn them into automated tests.  Frameworks such as SpecFlow and Cucumber are but two such options.  With that, scenarios will generally live within the code base and for example with SpecFlow can only be accessed easily through Visual Studio and to ensure you have the latest version you will need access to the source code repository.  Effectively you need a dev setup!  In any software project the code base is always the only truth you can rely on, therefore it is correct to house the scenarios within the code base.  But then problems arise in that now you need a development IDE to view them.  You definitely don&#8217;t want everyone having to install and use the IDE to view the files but you also don&#8217;t want to be sending around copies of features files, which could become soon out of date.  Roll up Pickles!</p>
<p>Pickles is an open source living documentation generator that works on feature files written in the Gherkin language and supports frameworks such as SpecFlow and Cucumber.  Pickles is simple enough to use, you tell it where to find the features files, and then you tell it where to put the results.  You can output the results in a number of formats including JSON, Word and the default option HTML.</p>
<p>You can get Pickles via NuGet with the following command</p>
<blockquote><p>Install-Package Pickles</p></blockquote>
<p>Pickles has a number of options to how you can invoke the generation of the documentation.  This can be as a Nant task, an MSI task or even a PowerShell command.  With these options it is very simple to add the generation of the documentation as part of your continuous integration process.  Lets take the PowerShell example</p>
<pre class="brush: csharp">
Import-Module &#039;C:\Pickle\Pickles.PowerShell.dll&#039;

Pickle-Features -FeatureDirectory &#039;C:\MyFeatures&#039; -OutputDirectory &#039;C:\MyOutput&#039;

</pre>
<p>A simple two liner.  The Pickles NuGet package includes a PowerShell module, which you will first need to import.  This module contains a single CmdLet called Pickle-Features.  -FeatureDirectory tells pickles where to find your feature files.  Pickles will search for feature files in this directory and also any sub directories.  -OutputDirectory tells Pickles where to write the results too.  </p>
<p>So a typical scenario like the one below found in SpecFlow.</p>
<p><img src="http://blog.devscrum.net/wp-content/uploads/2012/06/Pickle-Scenario.png" alt="Gherkin Style Scenario" title="Gherkin Style Scenario" width="472" height="213"  /></p>
<p>Can be viewed as HTML through a web browser by running Pickle over the feature file.</p>
<p><img src="http://blog.devscrum.net/wp-content/uploads/2012/06/Pickle-Scenario-Formatted (1).png" alt="Pickle Output" title="Pickle Output" width="528" height="231"  /></p>
<p>We use TeamCity for our continuous integration.  We have added a step to the build process to run Pickles from PowerShell to generate the documentation files.  Then we have added an extra tab on the build results screen. so that it can always be viewed for every checkin.  In addition to this we copy the files over to a virtual directory folder so they can always be accessed, directly in a browser without the need to also have to go to TeamCity.  This now means that anyone in the office can view the feature files at any time with the same URL they can be sure they are always viewing the latest version.</p>
<p>The post <a href="http://blog.devscrum.net/2012/06/making-your-living-documentation-available-to-everyone-with-pickles/">Sharing your living documentation with everyone with Pickles</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/06/making-your-living-documentation-available-to-everyone-with-pickles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Five Laws of Software Development</title>
		<link>http://blog.devscrum.net/2012/06/the-five-laws-of-software-development/</link>
		<comments>http://blog.devscrum.net/2012/06/the-five-laws-of-software-development/#comments</comments>
		<pubDate>Thu, 28 Jun 2012 18:58:54 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Keep it simple]]></category>
		<category><![CDATA[KISS]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=591</guid>
		<description><![CDATA[<p>It has always been a challenge on a software project to write applications that do exactly what they are supposed to and are easy to maintain but are flexible enough for tomorrow. But is tomorrow something we should be coding &#8230; <a href="http://blog.devscrum.net/2012/06/the-five-laws-of-software-development/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/06/the-five-laws-of-software-development/">The Five Laws of Software Development</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>It has always been a challenge on a software project to write applications that do exactly what they are supposed to and are easy to maintain but are flexible enough for tomorrow.   But is tomorrow something we should be coding for?  The following list of five laws are nothing ground breaking but are five principles you should take onto every software project and they should be at the forefront of your mind as you develop new features.</p>
<p><strong>1. Simplicity</strong><br />
If there is any doubt, there is no doubt! Keep it simple, don&#8217;t over engineer your code, don&#8217;t write your code so it can support that piece of functionality that you &#8220;might&#8221; want in six months but probably never will, don&#8217;t write your own frameworks when there are commercial or open source libraries out there that specially built to solve a particular problem.  Code bases I have worked on that follow the &#8220;Keep it simple&#8221; principle are not only far quicker to write but are also ten times easier to maintain.  The rule I like to follow is that the code should do precisely want it is meant too and nothing more, don&#8217;t plan for tomorrow as it may never happen or if it does the requirements you know today will likely change as well. If you follow good design principle such as SOLID, refactoring down the road will be much easier.</p>
<p><strong>2. Consistency</strong><br />
The rule I like to follow is that if I look at any piece of code in an application, I will not be able to tell which developer wrote it.   This would be because all code is styled and laid out the same, following the same conventions through out the application.  It&#8217;s not hard to come up with a consistent approach to follow.  Sit with your team and come up with it together, its fine to introduce new ideas during the project, but run it past your team first and get agreement on it.  Introduce some patterns to follow across the system for everyone to follow.  A few examples might be if I have a variable to represent an object called Customer call it customer, this way when I look at the code I know straight away what the variable is.</p>
<p><strong>3. No Attachment</strong><br />
Developers can get quite attached to a piece of code they have written on a project.  The rule is that any code is subject to change at anytime.  This is particularly relevant on agile projects.  As hard as you might try, you will not write all your code perfectly first time.  Code changes, code should change, it is healthy for a code base to be refactored to continuously improve the code, hopefully with the backing of a good set of tests to give you the confidence to do so. The willingness to learn and adapt to new ideas and new ways of working should be an important trait of any developer.</p>
<p><strong>4. Share</strong><br />
Not everyone can be an expert on everything but everyone should at least know something about everything.  It is commonly the case that silo&#8217;s are born within a development team, in fact suddenly you can find yourself in a situation where you are completely stuck if that person takes a holiday or gets hit by a bus.  A good consistent style, well structured self descriptive code and a good descriptive set of tests can ease this pain.  Development practices such as pairing or even code reviews can also help.  But also get the dev&#8217;s together and review each others code as a group.  </p>
<p><strong>5. Have Fun!</strong><br />
What I love most about being a developer is that there is always something new to learn.  But I also love the collaborative aspect delivering solutions as a team.  Keeping it simple does not mean development becomes boring! It can give you the opportunity to explore new patterns as a team to deliver a consistent approach</p>
<p>There is a trade off, that although today you will only write the minimum amount of code that you need, there will be times that tomorrow you might have to apply large refactors to your code to support new features. But this is not a bad thing.  When you come to make the change you will have a much better understanding of the new feature you will need to support and you will also have learnt lessons from how you wrote the code to support the original requirement.  The end result will be that you have a far cleaner code base that always does only what it is meant too.</p>
<p>My best advice to you is to plan for tomorrow on paper but deliver what you need today in your code base. Keep it simple, keep it consistent and involve the whole dev team.  </p>
<p>If anyone can thing of a sixth law to follow, please share</p>
<p>The post <a href="http://blog.devscrum.net/2012/06/the-five-laws-of-software-development/">The Five Laws of Software Development</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/06/the-five-laws-of-software-development/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Writing maintainable unit tests</title>
		<link>http://blog.devscrum.net/2012/03/writing-maintainable-unit-tests/</link>
		<comments>http://blog.devscrum.net/2012/03/writing-maintainable-unit-tests/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 17:01:08 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[FluentAssertions]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=448</guid>
		<description><![CDATA[<p>The project I am currently working on has about seven-hundered unit tests. On previous projects I have worked on, there have been as many as two-thousand tests. Unit tests are definitely not just for Christmas, they are for the lifetime &#8230; <a href="http://blog.devscrum.net/2012/03/writing-maintainable-unit-tests/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/03/writing-maintainable-unit-tests/">Writing maintainable unit tests</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>The project I am currently working on has about seven-hundered unit tests.  On previous projects I have worked on, there have been as many as two-thousand tests. Unit tests are definitely not just for Christmas, they are for the lifetime of the code base! They have a purpose and that is to minmise bugs being checked into source control.  Unit tests are also meant to act as documentation of the code.  I have a rule that if I cannot understand what a particular unit test is trying to do in thirty seconds, then it needs to be refactored!  Generally the tests that I cannot make sense of are due to noise around the test and the test class itself.</p>
<p>This blog post aims to introduce three guidelines to help improve the maintainability and readability of your unit tests, by </p>
<ol>
<li>altering the layout of your test classes</li>
<li>reducing common noise</li>
<li>and improving readability</li>
</ol>
<p>I have introduced these three guidelines recently into my team and have found that the quality and understanding of each test has greatly improved, in particular when refactoring or fixing bugs in existing classes.<br />
<br/><br />
1) <b>Structuring Unit Tests</b><br />
When unit testing properly, most public methods within an application will have multiple unit tests associated to it. These tests should cover the different outputs to a method based usually on a different set of input data.  Given a class under test with a lot of public methods, the test class can quite often become quite overloaded and quite difficult without close inspection to see what each test method is actually testing, i.e. the method it is testing and the scenarios for which it is under test.  </p>
<p>With this in mind I recently read a post by <a href="http://haacked.com/archive/2012/01/02/structuring-unit-tests.aspx" target="_blank">Phil Haack</a> detailing a solution he had come across to improve the readability of what each test class is actually doing.  The solution is simple.  For each public method you are testing, in your unit test class, create a nested class to encapsulate all the test methods for a given method.  This is effectively grouping together tests by public method.  This may seem like overkill at first, but to avoid repetition, you can define the setup and teardown methods in the base class.  This means all the nested classes can inherit the base to reuse anything that should be shared. </p>
<p>The following example below shows the basic structure of a test class, which tests two public methods, the first called Get, the second Post.</p>
<pre class="brush: csharp">

    [TestClass]
    public class BlogPostTaskTests
    {
        protected Mock&lt;IBlogPostRepository&gt; blogPostRepository;

        [TestInitialize]
        public void Setup()
        {
            //shared setup, generally just initialising mocks
        }

        [TestClass]
        public class TheGetMethod : BlogPostTaskTests
        {
            [TestMethod]
            public void HappyPath()
            {
                //arrange
                //act
                //assert
            }

            [TestMethod]
            public void UnhappyPath()
            {
                //arrange
                //act
                //assert
            }
        }

        [TestClass]
        public class ThePostMethod : BlogPostTaskTests
        {
            [TestMethod]
            public void HappyPath()
            {
                //arrange
                //act
                //assert
            }

            //Additional Tests for the Post method here
        }

        [TestCleanup]
        public void Cleanup()
        {
        }
    }

</pre>
<p><br/><br />
2) <b>Use the Test Data Builder Pattern for test data</b><br />
Most unit tests require some input data for a method to test, and some output data to assert.  I have found it too commonly the case that developers will duplicate instances of objects across multiple test classes, and initialise the object with hard coded test values. All this set up code within a test class adds a lot of noise to test classes which can make it difficult to understand what the test is doing.</p>
<p>Given the following class:</p>
<pre class="brush: csharp">
public class BlogPost
{
    public int Id { get; set; }

    public string Title { get; set; }

    public string Content { get; set; }
}
</pre>
<p>All to commonly you will find scattered across many test classes an instance of this class being initialised with test values to be used in a test. </p>
<pre class="brush: csharp">
var blogPost = new BlogPost
{
    Id = 1,
    Title = &quot;My Title&quot;,
    Content = &quot;My Content&quot;
};
</pre>
<p>Following the DRY (Don&#8217;t Repeat Yourself) principle, I would recommend having a look at the test data builder pattern.  The code below is an example of this for the BlogPost class.  The class follows a number of conventions for consistency</p>
<ul>
<li>Create a class for each domain object.  The name of the class follows [DomainName]Builder</li>
<li>A private member variable for each property on the underlining class is added.  This variable is assigned a default value.</li>
<li>To allow you to override a default value, provide a method with the name With[PropertyName].  This method follows a fluent style to allow you to chain methods together.  Only add the With methods when you need them.  95% of the time the default value will probably suffice, there is no value in adding code that is not ever executed.</li>
<li>Add a Build method.  This method will create and return a new instance of the object with either the default or overrided values.</li>
</ul>
<pre class="brush: csharp">
public class BlogPostBuilder
{
    private int id = new Random().Next(1000);
    private string title = &quot;My Title&quot;;
    private string content = &quot;My Content&quot;;

    public BlogPostBuilder WithTitle(string title)
    {
        this.title = title;
        return this;
    }

    public BlogPost Build()
    {
        return new BlogPost
        {
            Id = id,
            Title = title,
            Content = content
        };
    }
}
</pre>
<p>An example of using the builder class</p>
<pre class="brush: csharp">
 var blogPost = new BlogPostBuilder()
                                    .WithTitle(&quot;Another Title&quot;)
                                    .Build();
</pre>
<p>Each unit test method should be responsible for initializing its own test data opposed to initializing the test data within the test setup.  This makes it clear what data each unit test it utilising.<br />
<br/><br />
3) <b>Use unit testing extension plugins to improve readability</b><br />
I have recently been looking a very useful library called Fluent Assertions which provide extensions on top of unit testing frameworks such, with the aim of improving readability by following a more natural language, and reducing the amount of code that is required.  </p>
<p>Fluent Assertions is effectively a set of extension methods on top of commonly used unit testing frameworks  such as NUnit and MSTest.  </p>
<p>As a simple example you could take the following Assert statement:</p>
<pre class="brush: csharp">
Assert.IsTrue(actualOutcome &gt; 5);
</pre>
<p>and rewrite it as the follows:</p>
<pre class="brush: csharp">
actualOutcome .Should().BeGreaterOrEqualTo(5);
</pre>
<p>This is a simple example, but Fluent Assertions provides a wealth of extensions.  </p>
<p>You can download Fluent Assertions via NuGet with the following command from the package manager console within Visual Studio.</p>
<blockquote><p>
INSTALL-PACKAGE FluentAssertions
</p></blockquote>
<p>and you can read about it <a href="http://fluentassertions.codeplex.com/" target="_blank">here</a><br />
<br/s><br />
I would recommend next time you write some tests, try following the three guideline above, I guarentee it will improve the maintainability and readability of your tests. </p>
<p>I would be very interested to hear any guidelines you follow to improve your unit tests.  Thanks for reading.</p>
<p>The post <a href="http://blog.devscrum.net/2012/03/writing-maintainable-unit-tests/">Writing maintainable unit tests</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/03/writing-maintainable-unit-tests/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Learning from mistakes with BDD</title>
		<link>http://blog.devscrum.net/2012/03/learning-from-mistakes-with-bdd/</link>
		<comments>http://blog.devscrum.net/2012/03/learning-from-mistakes-with-bdd/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 12:23:33 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Scrum]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[Learning BDD]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=485</guid>
		<description><![CDATA[<p>BDD (Behaviour Driven Design) is a great agile technique that adds value towards the three main steps of software development, defining, coding and testing. This hit list hopefully should provide some guidance for introducing or just improving BDD in your &#8230; <a href="http://blog.devscrum.net/2012/03/learning-from-mistakes-with-bdd/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/03/learning-from-mistakes-with-bdd/">Learning from mistakes with BDD</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>BDD (Behaviour Driven Design) is a great agile technique that adds value towards the three main steps of software development, defining, coding and testing.  </p>
<p>This hit list hopefully should provide some guidance for introducing or just improving BDD in your organisation.  The list is spawned from my own experience introducing BDD as a new concept to my team over the last few months.  It is in no particular order.</p>
<ol>
<li><b>Don&#8217;t rush into automation.</b><br />
Undoubtably one of key outputs of BDD is an automated set of tests covering the scenarios raised against a story.  However it is very easy to jump straight into the deep end.  It&#8217;s not all about the tool and automated tests can be a maintenance nightmare.  Get a proper framework in place,  use the right patterns, such as the page object pattern, particularly if you&#8217;re writing your tests from the UI layer.  Trust me this will save you a lot of rework.</li>
<li><b>Don&#8217;t spend hours arguing about the correct language to use.</b> Try and land a few ground rules early, decide on terms to refer to elements of your system by and stick to it.  Consult your domain experts.  It is important to follow a ubiquitous language, so everyone is on the same page.  Make sure everyone understands that the given, sets the context, when is an event and the then is an observable result.</li>
<li><b>See what others are doing.</b>  You didn&#8217;t invent BDD, Dan North did! Do some reading, there are many different people with many different views on the internet, read other peoples opinion and cut out and stick it in your scrap book, what you see as the points that will work for you and your team.</li>
<li><b>Write scenarios as a team.</b> Don&#8217;t get one person to write them it&#8217;s not about one persons view, include the BA&#8217;s, testers and dev&#8217;s.  Scenario writing is a team sport.</li>
<li><b>Have the conversation.</b> the best thing about writing or even discussing scenarios is that it gets you thinking off the happy path track.  Get the whole scrum team in a room and just talk through the requirements.  As you start discussing a story in more detail, you&#8217;ll continuously hear the question raised, ah but what if I do this&#8230; or what if I do that.  Ensure that this is also not just on the first day of the sprint.  Put meetings in the calendar for regular review meetings.</li>
<li><b>Don&#8217;t add implementation details in scenarios.</b> Avoid tying scenarios to the UI by referencing page elements or controls.  Avoid tying scenarios to the architecture or technologies used under the cover.  Everything that occurs under the UI cover is up to the architect and developers to design.</li>
<li><b>Add tests to continuous integration process as early as possible.</b> When you do automate, get the tests running as part of the build as soon as possible, this keeps the test alive.  The key to automated tests is maintenance.  Making them part of the build process means you will know when they fail fast. </li>
<li><b>Use your scenarios.</b> You&#8217;ve put the time in to write the scenarios, use them!  Make sure they are held centrally under source control.  Use them to develop against and particularly use them as test cases. Testers should be adding additional scenarios during the course of a sprint.</li>
<li><b>Include the SME (Subject Matter Expert), domain expert and customer</b> Even if just to replay the scenarios against.  These guys understand the problem domain more than anyone.  In particular the customer is the one who will use the software.</li>
<li><b>Keep scenarios precise</b> It has often been the case I have seen very long winded scenarios that have tried to capture multiple scenarios in one.  No one wants to read an 20-30 line scenario.  Keep them small and precise.  Each scenario should cover a single case.  Include examples for clarity.</li>
<li><b>Use examples to reinforce the scenario</b> Examples bring scenarios to life! They make them dynamic and they provide test data to verify that the scenario meets it&#8217;s goal.  Adding scenarios means that not only have you written your test cases upfront, you&#8217;ve also included the data by which to test it with.</li>
<li><b>Every scenario is negotiable</b> and is subject to change at anytime.  With the information available on one day a scenario might seem to be capturing the requirement.  However additional information or even the realisation that the scenario do not cover all cases may lead to you and your team to revisit the scenarios and add, edit or even delete scenarios.  If you do not change a suite of scenarios for a given story after they are first conceived, you are almost certainly doing something wrong.  These changes may well also mean that acceptance criteria or even stories are subject to change too.</li>
<li><b>Your scenarios are your living documentation</b> Make this available to the whole business, it&#8217;s also a great resource for your support team. If you do use tools like spec flow, the tools more often than not provides the ability to generate reports.  Get these executed as part of your build and make accessible for everyone.</li>
<li><b>Make things visual.</b> Using techniques such as story maps and including wireframes are a great way to visualise the requirements, and can be a great driver for conversation.  Stick them on a wall so everyone can see them. </li>
<li><b>Sign off scenarios.</b>  A story can only be considered complete when all your scenarios have been implemented.  At the end of sprint review meeting, when demoing whats been implemented in the sprint, replay the functionality to the team through the scenarios </li>
</ol>
<p>For me agile is about making the invisible visible.  What I mean by this is that agile is all about working as a team to deliver software.  The key point to this is that the software is built collaboratively as a unit, with input from the business, customers, dev&#8217;s, BA&#8217;s testers.  It&#8217;s about having the conversation, constantly reviewing, quick feedback and sharing the knowledge.  It&#8217;s always worth remembering the agile manifesto, which gets this bang on in four simple steps! </p>
<ul>
<li>Individuals and interactions over processes and tools</li>
<li>Working software over comprehensive documentation</li>
<li>Customer collaboration over contract negotiation</li>
<li>Responding to change over following a plan</li>
</ul>
<p>I would love to hear any comments from your own experiences implementing BDD within your organisation.  Thanks for reading.</p>
<p>The post <a href="http://blog.devscrum.net/2012/03/learning-from-mistakes-with-bdd/">Learning from mistakes with BDD</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/03/learning-from-mistakes-with-bdd/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>agile techniques &#8211; Dev Box Testing</title>
		<link>http://blog.devscrum.net/2012/03/dev-box-testing/</link>
		<comments>http://blog.devscrum.net/2012/03/dev-box-testing/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 08:45:47 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[Scrum]]></category>
		<category><![CDATA[scrum testing]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=451</guid>
		<description><![CDATA[<p>Dev box testing is a practice all teams should be doing. The idea is simple. When a developer writes a piece of code, which may have been to fix a bug, or implement a task within a story, just before &#8230; <a href="http://blog.devscrum.net/2012/03/dev-box-testing/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/03/dev-box-testing/">agile techniques &#8211; Dev Box Testing</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>Dev box testing is a practice all teams should be doing.  The idea is simple.  When a developer writes a piece of code, which may have been to fix a bug, or implement a task within a story, just before the code is committed to the source control repository, the developer should ask the assigned tester and BA to come and sit at the developer&#8217;s machine to demo the changes that have been made. Hence the name dev box testing.</p>
<p>The steps involved in dev box testing can be summed up with the following:</p>
<ul>
<li>The developer should demonstrate what he/she has done and run through the changes to the application that has been made.</li>
<li>The developer should let the BA or tester run the application and perform at minimum happy path testing.</li>
<li>This provides an opportunity for the BA to ensure that what has been produced meets the requirement.</li>
<li>This allows the testers to understand what has been developed.  The developer should share with the tester information about how to test the code change by means other than just the UI, i.e. any database changes, service calls etc.</li>
<li>If any issues are found, the developer will fix them, and get them retested before anything is checked in.</li>
<ul>
<p>Dev box testing commonly should not take any more than 10 minutes. It&#8217;s real value is that it allows for code to fail fast, which although that may seem a bit dramatic, is actually a really good thing! For example, even if you have a fantastically slick continuous integration process in place, the code still needs to be committed to source control, unit tests run and then deployed to a test environment before a tester and the BA can access the code change.  This means there is always a delay in the code change being available to test, once it has been checked in.  If a defect is found,  such as a bug, a piece of functionality is implemented incorrectly or not at all, a vicious cycle begins.  This is outlined in the diagram below. </p>
<p style="text-align:center">
<img src="http://blog.devscrum.net/wp-content/uploads/2012/03/devboxtesting1.png" alt="typcial flow before dev box testing" title="typcial flow before dev box testing" width="202" height="414" class="alignnone size-full wp-image-289" />
</p>
<p>Dev box testing helps by minimising the feedback cycle in terms of time. This is because code is tested before it is checked in.  Any defects or requirements not implemented can be picked up and dealt with immediately.  This also greatly improves the sharing of knowledge held by the developer with the testers.  This knowledge sharing allows the tester to truly understand how the changes were implemented and understand how the application can be tested under the covers, away from just UI testing.  Sharing this knowledge whilst it&#8217;s still hot, fresh in the developers mind is essential.</p>
<p>The diagram below outlines a typical dev box testing flow.  The key point to understand is that after the developer initially writes the code, the flow moves into an iterative cycle, between having the code dev box tested and the developer on the back of that coding any changes.  This cycle repeats until the BA and tester are happy with the change made and the code can be committed to source control.</p>
<p style="text-align:center">
<img src="http://blog.devscrum.net/wp-content/uploads/2012/03/devboxtesting2.png" alt="dev box testing flow" title="dev box testing flow" width="276" height="353" class="alignnone size-full wp-image-289" />
</p>
<p>Dev box testing strongly encourages collaboration between the BA, developer and tester because it forces conversation, which is key to the success of successful software projects.  It is important to point out that dev box testing is not about performing a full regression test, but more of a sanity check to ensure no obvious errors get deployed. </p>
<p>Dev box testing is a great tool in the agile armoury that every team should employ. Any technique that aims to reduce bugs that are committed into source control, and actively encourages collaboration between team members has to be a good thing.  There is no reason why you can&#8217;t start today!</p>
<p>The post <a href="http://blog.devscrum.net/2012/03/dev-box-testing/">agile techniques &#8211; Dev Box Testing</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/03/dev-box-testing/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Running a Retrospective</title>
		<link>http://blog.devscrum.net/2012/01/running-a-retrospective/</link>
		<comments>http://blog.devscrum.net/2012/01/running-a-retrospective/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 19:10:58 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[Scrum]]></category>
		<category><![CDATA[Retrospective]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=397</guid>
		<description><![CDATA[<p>A retrospective is one of the key practices that any agile team should employ. A retrospective provides an opportunity to bring a team together and collaboratively look back at events that have already taken place. This provides a forum to &#8230; <a href="http://blog.devscrum.net/2012/01/running-a-retrospective/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2012/01/running-a-retrospective/">Running a Retrospective</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>A retrospective is one of the key practices that any agile team should employ.  A retrospective provides an opportunity to bring a team together and collaboratively look back at events that have already taken place.  This provides a forum to review events and learn from the experience with the goal of improving the way we work as individuals and a team.</p>
<p>The remainder of this post offers a guideline for how to run a retrospective within your own team.</p>
<p><strong>What do you need</strong></p>
<ul>
<li>Someone to act as an mediator to facilitate the session</li>
<li>The whole scrum team</li>
<li>Many post its and a pen each</li>
<li>A strong drink, (I mean coffee!)</li>
</ul>
<p><strong>Step 1:  Prime Directive</strong><br />
Now this step may seem daft, but it is important to ensure that a retrospective is a team sport.  It is not about highlighting a mistake an individual has made, but more mistakes a team has made.  At the start of each retrospective the mediator should read out the following text.</p>
<blockquote><p>
&#8220;Regardless of what we discover today, we understand and truly believe that everyone did the best job they could, given what they knew at the time, their skills and abilities, the resources available and the situation at hand.&#8221;
</p></blockquote>
<p>The mediator should ask everyone if they agree to the above statement.  If anyone says no you should not continue.</p>
<p><strong>Step 2: Brainstorming</strong><br />
This is the core part of any retrospective.  Start by creating three separate sections on a wall, which I am going to refer to as swim lanes.  Take three post it notes and write the one of the following three headers on each one.  </p>
<ul>
<li>What went well</li>
<li>What didn&#8217;t go well</li>
<li>What you would like more of and could be improved</li>
</ul>
<p>Stick this as the heading of each swim lane.  </p>
<p>Now lets get everyone involved. the idea is simple, give everyone in the room some post it notes, and ask everyone to write down as many things they can think of it that are of importance to them, for each of the headers we just created.  Give everyone about five minutes to write down there ideas and add to the wall. </p>
<p><strong>Step 3: Identifying Common Themes</strong><br />
At the end of step 2, you will have a lot of post it notes within each swim lane.  It is almost certain that more than one individual will have raised the same point.  In order to make sense of the results, it is best to identify common themes raised within the post it notes by performin the following: </p>
<ul>
<li>Within each swim lane, group together all post its that are similar, i.e. you have more than one relating to training.</li>
<li>Give each group a name, which categorises the post its within.</li>
</ul>
<p>By performing this step you will suddenly have surfaced clear visibility of the common themes raised by the team.</p>
<p><strong>Step 4: Voting</strong><br />
Having identified a number of groups, it is time to identify the priority to which the team view them.  Give each person within the retrospective a number of votes, lets use five votes as a guideline.  Then ask all participants to vote on which category they believe is the most important to be raised for further discussion so that it can improved.  Votes are not constrained to a single category, in fact votes can be distributed across categories anyway they like.  For example all five votes can be used on a single category, or two votes can be used on one category and the remaining three votes could be spread across another three categories.</p>
<p>At the end of the voting step, add the votes together for each category.  You now have a priority order of which categories need to be addressed first.</p>
<p><strong>Step 5: Time boxed discussion</strong><br />
Typically within a retrospective I would pick the five categories with the most votes.  Then I would allocate a time to spend talking about each one, for example, 12 minutes.  This is the real meat of the retrospective, I would typically start by rereading all the post its under the category and then open it up to the floor to discuss as a group.  The mediator role here is to ensure the conversation remains on topic and ensures that the time allocated to each category does not overrun.</p>
<p><strong>Step 6: Assign owner to each group to action</strong><br />
The whole point of the retrospective is to address the issues that are of most concern.  At the end of each timeboxed discussion, an action should be agreed of how to take the issue forward, whether it be a follow up meeting, or a chat to the CEO, etc Typically I would assign each category an owner.  The owner is responsible for taking the action away to address.  The same owner can be assigned more than one category.</p>
<p><strong>Step 7: Retrospective Summary</strong><br />
After the retrospective, the mediator is responsible for creating a quick summary, commonly in the form of an email highlighting the top categories that were raised, and the actions that was agreed to take forward.</p>
<p><strong>Conclusion</strong><br />
Retrospectives should occur at the end of every sprint within a scrum project.  For any team that wants to continually improve and learn from mistakes a retrospective is an invaluable weapon within an agile armory.</p>
<p>The post <a href="http://blog.devscrum.net/2012/01/running-a-retrospective/">Running a Retrospective</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2012/01/running-a-retrospective/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting started with SignalR in ASP.NET MVC</title>
		<link>http://blog.devscrum.net/2011/12/getting-started-with-signalr-in-asp-net-mvc/</link>
		<comments>http://blog.devscrum.net/2011/12/getting-started-with-signalr-in-asp-net-mvc/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 14:20:28 +0000</pubDate>
		<dc:creator>Andrew Jutton</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Knockout]]></category>
		<category><![CDATA[SignalR]]></category>

		<guid isPermaLink="false">http://blog.devscrum.net/?p=334</guid>
		<description><![CDATA[<p>The publish / subscription pattern is a messaging pattern where messages are broadcast by a publisher and are pushed to a variable number of subscribers who have subscribed to the service. The pattern provides loose coupling by disconnecting the publishers &#8230; <a href="http://blog.devscrum.net/2011/12/getting-started-with-signalr-in-asp-net-mvc/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://blog.devscrum.net/2011/12/getting-started-with-signalr-in-asp-net-mvc/">Getting started with SignalR in ASP.NET MVC</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>The publish / subscription pattern is a messaging pattern where messages are broadcast by a publisher and are pushed to a variable number of subscribers who have subscribed to the service. The pattern provides loose coupling by disconnecting the publishers from its subscribers commonly over the form of a queue.</p>
<p>SignalR is an asynchronous signalling library for ASP.NET which provides a framework for broadcasting messages to multiple clients when a given operation on the server is executed, providing a publish / subscription model with the subscribers being either a .NET client application or a web page.  SignalR can be used to keep a number of web clients in sync with each other at real time with data held on the server. SignalR achieves this by holding open both the client and server side connections, ensuring the connection always stays open.  When a message is sent from a client to the server the server side operation can broadcast a response to all clients by sending a callback to all the open client connections.</p>
<p>SignalR provides a far more efficient solution than simply making a client continuously poll the server on a set timer to check for any change to the state held on the the server and keep itself in sync.  SignalR provides an architecture for pushing messages to listening clients rather than having each client individually responsible for pulling messages from the server.  This can dramatically reduce the load on the server ensuring there are no needless requests repeatedly being sent from clients.</p>
<p>The real beauty of SignalR is in its simplicity.  Requests are sent direct from a web view using JavaScript to the server, and responses are received via a callback on an open connection.  This means that SignalR can be used with frameworks such as Knockout.js for easily keeping the UI refreshed with the latest data.</p>
<p>I am sure you can already think of a number of situations where this can be very useful. Such examples could include either an online chat application or a real time booking system.  However I found that SignalR was the answer to a problem I had been looking to solve for a while.  I am currently working on a large web based integration project for placing insurance quotes online.  For a single request that is submitted for a quote, that request can be sent to multiple third party endpoints for processing.  All requests are sent asynchronously from the client to the server.  Within the application I have a health check routine, which monitors the status of these endpoints.  I want to use SignalR to broadcast a message informing the user of the status of a given service within a footer on the application.  This will inform the customer who may be waiting on an insurance quote if a service ever goes offline.  This will also be very useful during development.</p>
<p>Lets walk through how this could be accomplished by creating a server side endpoint that will be responsible for receiving a request from a client, change a data object and then be responsible for issuing a response with that change to multiple clients.</p>
<p>First create a new ASP.NET MVC 3 web application. To add SignalR to this solution you can issue the following NuGet command in the package manager console within Visual Studio.</p>
<blockquote><p>Install-Package SignalR</p></blockquote>
<p>This will download and add the following scripts to your solution.</p>
<ul>
<li>Scripts/jquery-1.6.4.js</li>
<li>Scripts/jquery.signalR.js</li>
</ul>
<p>plus minimised versions of both scripts. </p>
<p>It will also add a assembly reference to SignalR.dll in your project </p>
<p>There are two options for implementing SignalR server-side.  Both options involve deriving a class from an object within the SignalR framework.  The two options are persistent connections and hubs.  So what is the difference I hear you ask?  Well let&#8217;s take a quick look at both.</p>
<p>A persistent connection endpoint is exposed as an IHttpHandler.  This allows the endpoint to be accessed over HTTP, however in order to do so you must add a custom route map into the route map collection within the web applications global.asax.  Deriving from a PersistentConnection enables the ability to override a number of set operations within the SignalR framework to receive client requests and broadcast responses.</p>
<p>The other option is to use a hub.  A hub provides the ability to send different types of messages between client and server.  There is no need to create a custom route map when using hubs.  All requests are routed through the /signalr/hubs route which is added by the SignalR framework to access the hubs.  Hubs allow you to add any operations you like.  In this example we are going to use Hubs. </p>
<p>The code below is a simple implementation of a hub, with two methods GetServiceState() and UpdateServiceState(), both of which are exposed over HTTP and can be called direct from JavaScript running in a browser.  The code includes a static member variable called messages.  This is a list of strings and it is static so that its state can be shared across all client instances. The intention of the first method GetServiceState is set the initial state on the client.  It is called when the client first opens a connection to the hub.  The single line of the method uses the Clients object, which is a dynamic object which represents all the connected clients.  As this object is dynamic you can  simply specify the name of the callback routine that the JavaScript clients will be listening on.  This single line allows you to push the messages collection to all connected clients.  The second method UpdateServiceState adds an item to the list and pushes it out to all clients.  In this example the current date and time is added to the list.</p>
<pre class="brush: csharp">
public class HealthCheck : Hub
{
    public static List&lt;string&gt; messages = new List&lt;string&gt;();

    public void GetServiceState()
    {
        Clients.updateMessages(messages);
    }

    public void UpdateServiceState()
    {
        messages.Add(DateTime.Now.ToString(&quot;dd/MM/yyyy HH:mm:ss&quot;));

        Clients.updateMessages(messages);
    }
}
</pre>
<p>So now to set up the client.  In the _Layout,cshtml within your MVC 3 project add a script reference to the SignalR JavaScript library that was downloaded and added to the scripts folder when SignalR was added to the solution with NuGet. Please note that SignalR requires jquery to also be enabled. Therefore you will need to add the following two references. </p>
<pre class="brush: csharp">
&lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.6.4.min.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.signalr.min.js&quot;)&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>In index.cshtml add the following code</p>
<pre class="brush: csharp">
&lt;script src=&quot;/signalr/hubs&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    $(function () {
        // creates a proxy to the health check hub
        var healthCheckHub = $.connection.healthCheck;

        // handles the callback sent from the server
        healthCheckHub.updateMessages = function (data) {
            $(&quot;li&quot;).remove();

            $.each(data, function () {
                $(&#039;#messages&#039;).append(&#039;&lt;li&gt;&#039; + this + &#039;&lt;/li&gt;&#039;);
            });
        };

        $(&quot;#trigger&quot;).click(function () {
            healthCheckHub.updateServiceState();
        });

        // Start the connection and request current state
        $.connection.hub.start(function () {
            healthCheckHub.getServiceState();
        });
    });
&lt;/script&gt;

&lt;ul id=&quot;messages&quot;&gt;&lt;/ul&gt;

&lt;button type=&quot;button&quot; id=&quot;trigger&quot;&gt;Send request&lt;/button&gt;
</pre>
<p>The code above creates a proxy reference to the health check hub, it registers a callback called updateMessages.  This callback is the one that the dynamic Clients object makes reference to and broadcast messages on. An event handler is added for the button.  This will call the UpdateServiceState method on the hub when the button is clicked. Finally a connection to the hub is made and the GetServiceState method is called to retrieve the initial server state when the page is first rendered.  </p>
<p>To test open two browser tabs and navigate to the view in both.  Now click on the Send request button in one of the tabs and you will find that the current date and time is displayed shortly afterwards.  Now flip to the other tab and you&#8217;ll see that the date and time displayed in the first tab is also displayed.  This is because when you clicked the button in the first tab, the hub was called, the current date and time was added to the messages collection and this collection was pushed out to all listening clients who have an open connection registered, in this case both of the tabs.</p>
<p>So this is pretty clever but not a very useful example, but none the less it shows demonstrates a lot of the required plumbing, as we have made a connection to the hub and have registered a callback so that when a message is added on the hub it can be picked up and displayed by any listening clients with an open connection.</p>
<p>As previously mentioned I have a server side process that periodically checks the status of a given set of services.  To broadcast the latest status I need to broadcast a message to the clients from outside the hub.</p>
<p>SignalR provides exactly this functionality by allowing you to retrieve the currently connected clients for a given hub by calling Hub.GetClients<T> where T is the hub you wish to retrieve the clients for.</p>
<pre class="brush: csharp">
public class HealthMonitor
{
    public void Check()
    {
        /*
         * code ommited for clarity, 
         * but some process running on say a timer
         * or scheduler returns the latest state of the 
         * services and updates the messages
         * property on the HealthCheck hub
         */

        dynamic clients = Hub.GetClients&lt;HealthCheck&gt;();
        clients.updateMessages(HealthCheck.Messages);
    }
}
</pre>
<p>The code above is a arbitrary piece of code which can be run on the server. It can however also broadcast a message to all the currently connected clients outside of the hub itself.  The other code change I made was to change the messages field variable to a property so I can keep the same list in sync whether it is updated from a client or server request.</p>
<pre class="brush: csharp">
public class HealthCheck : Hub
{
    private static List&lt;string&gt; messages;

    public static List&lt;String&gt; Messages 
    { 
        get
        {
            if (messages == null)
            {
                messages = new List&lt;string&gt;();
            }

            return messages;
        }
        set
        {
           messages = value;
        }
    }

//remaining code ommited
</pre>
<p>Each request that is received within the hub also includes the callers context.  This can be used to only broadcast a response to a specific client.  SignalR also provides the functionality to alternatively broadcast a response to a group of subscribers.   </p>
<p>It is worth pointing out that the client is not restricted to being an MVC view, it can also be a .NET client.  </p>
<p>SignalR is open source framework hosted on github.  I would strongly recommend having a look at the documentation on the <a href="https://github.com/SignalR/SignalR/wiki">github site</a>.</p>
<p>The post <a href="http://blog.devscrum.net/2011/12/getting-started-with-signalr-in-asp-net-mvc/">Getting started with SignalR in ASP.NET MVC</a> appeared first on <a href="http://blog.devscrum.net">DEV SCRUM .NET</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.devscrum.net/2011/12/getting-started-with-signalr-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
