<?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>endjin blog &#187; Mike.Larah</title>
	<atom:link href="http://blogs.endjin.com/author/mike-larah/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.endjin.com</link>
	<description>work smarter</description>
	<lastBuildDate>Thu, 23 May 2013 10:08:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Introducing endjin composition framework 2.0 : Part 3 &#8211; Using the content factory</title>
		<link>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-3-using-the-content-factory/</link>
		<comments>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-3-using-the-content-factory/#comments</comments>
		<pubDate>Thu, 23 May 2013 07:00:34 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Samples]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Endjin Composition]]></category>

		<guid isPermaLink="false">http://blogs.endjin.com/?p=8272</guid>
		<description><![CDATA[As I explained in this post, the framework provides a set of installers for registering components against interfaces in the container. Another powerful tool in the composition framework is the ContentFactory. This provides methods for registering and getting content based on a contentType string. When getting content, if the contentType is not found in the [...]]]></description>
				<content:encoded><![CDATA[<p>As I explained in <a href="http://wp.me/p19Amb-1Zg">this post</a>, the framework provides a set of installers for registering components against interfaces in the container.</p>
<p>Another powerful tool in the composition framework is the <code>ContentFactory</code>. This provides methods for registering and getting content based on a <code>contentType</code> string. When getting content, if the <code>contentType</code> is not found in the container, it will try to fallback using substrings of <code>contentType</code> by progressively removing sections after a <code>.</code></p>
<p>As an example, we might have some serializers that inherit from <code>ISerializer</code>.</p>
<script src="https://gist.github.com/e2c0fa287e7f4524b2ee.js"></script><noscript><pre><code class="language-c# c#">public class FooSerializer : ISerializer
{
}

public class BarSerializer : ISerializer
{
}

public class FooBarSerializer : ISerializer
{
}</code></pre></noscript>
<p>We can create a new <code>SerializerFactory</code> that inherits from <code>ContentFactory</code>.</p>
<script src="https://gist.github.com/6151fa3b39fe121648f4.js"></script><noscript><pre><code class="language-c# c#">public class SerializerFactory : ContentFactory&lt;ISerializer&gt;, ISerializerFactory
{
    private const string Extension = &quot;+Serializer&quot;;

    public override void RegisterContentFor&lt;TInstance&gt;(string contentType)
    {
        base.RegisterContentFor&lt;TInstance&gt;(contentType + Extension);
    }

    public override ISerializer GetContentFor(string contentType)
    {
        return base.GetContentFor(contentType + Extension);
    }
}</code></pre></noscript>
<p>Then we use a custom installer to register the factory as a singleton, and also to register our default content (i.e. the serializers).</p>
<script src="https://gist.github.com/9a7a26abd167ef418ae4.js"></script><noscript><pre><code class="language-c# c#">public class SerializerFactoryInstaller : IInstaller
{
    public void Install(IContainer container)
    {
        var serializerFactory = new SerializerFactory();
              container.Register(Component.For&lt;ISerializerFactory&gt;).Instance(serializerFactory).LifeStyle.Singleton);

        RegisterDefaultContent(serializerFactory);
    }

    private static void RegisterDefaultContent(SerializerFactory serializerFactory)
    {
        serializerFactory.RegisterContentFor&lt;FooSerializer&gt;(&quot;Foo&quot;);
        serializerFactory.RegisterContentFor&lt;BarSerializer&gt;(&quot;Bar&quot;);
        serializerFactory.RegisterContentFor&lt;FooBarSerializer&gt;(&quot;Foo.Bar&quot;);
    }
}</code></pre></noscript>
<p>We are now able to use the <code>SerializerFactory.GetContentFor(string contentType)</code> method to retrieve our serializers by the name we registered them with:</p>
<ul>
<li><code>SerializerFactory.GetContentFor("Foo")</code> will return <code>FooSerializer</code></li>
<li><code>SerializerFactory.GetContentFor("Foo.Bar")</code> will return <code>FooBarSerializer</code></li>
<li><code>SerializerFactory.GetContentFor("Foo.Bar.Baz")</code> will fallback to contentType of &#8220;Foo.Bar&#8221; and return <code>FooBarSerializer</code></li>
</ul>
<p>In the next post I&#8217;ll show you how to get set up with endjin composition framework in an MVC4 / WebAPI application.</p>
<p><a href="http://twiiter.com/MikeLarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-3-using-the-content-factory/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing endjin composition framework 2.0 : Part 2 &#8211; Getting Started</title>
		<link>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-2-getting-started/</link>
		<comments>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-2-getting-started/#comments</comments>
		<pubDate>Thu, 16 May 2013 07:00:08 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Samples]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Endjin Composition]]></category>

		<guid isPermaLink="false">http://blogs.endjin.com/?p=7642</guid>
		<description><![CDATA[In the last post I introduced v2.0 of our open source, composition framework. In this post, I&#8217;m going to cover a quick example of how to get started with the basics of the endjin composition framework. Firstly, we define an interface for some type Then, we create a concrete type for our interface Now we can [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://wp.me/p19Amb-1V4">In the last post</a> I introduced<a href="https://github.com/endjin/Endjin.Core.Composition-V2" target="_blank"> v2.0 of our open source, composition framework</a>. In this post, I&#8217;m going to cover a quick example of how to get started with the basics of the endjin composition framework.</p>
<p>Firstly, we define an interface for some type</p>
<script src="https://gist.github.com/c8839ffbbd1fc6c74703.js"></script><noscript><pre><code class="language-c# c#">namespace Endjin.CompositionExample.Contracts
{
    public interface IRepository
    {
        string GetMessage();
    }
}</code></pre></noscript>
<p>Then, we create a concrete type for our interface</p>
<script src="https://gist.github.com/a5ee5494f75c335d477c.js"></script><noscript><pre><code class="language-c# c#">namespace Endjin.CompositionExample.Storage
{
    public class SampleRepository  : IRepository
    {
        public string GetMessage()
        {
            return &quot;Hello, world!&quot;;
        }
    }
}</code></pre></noscript>
<p>Now we can use one the composition framework&#8217;s convention based installers. For instance we could use the namespace installer, to install all types in a given namespace into the container.</p>
<script src="https://gist.github.com/5fa418ce4a5e6e58d0a8.js"></script><noscript><pre><code class="language-c# c#">namespace Endjin.CompositionExample.Installers
{
    using Endjin.Core.Installers;

    public class StorageInstaller : NamespaceInstallerBase&lt;StorageInstaller&gt;
    {
        public StorageInstaller() : base(&quot;Storage&quot;)
        {
        }
    }
}</code></pre></noscript>
<p>The namespace installer will register types against their Default interface &#8211; where the default interface is the interface that follows the naming convention <code>I</code> + [my specific name] + [service name] (e.g. the default interface for <code>class FooBarService : IFooService, IFooBarService</code> is <code>IFooBarService</code>)</p>
<p>Most of the convention-based installers will install the concrete type into the container as Transient by default, but we can explicit specify the lifestyle using <code>[Singleton]</code> and <code>[Transient]</code> attributes.</p>
<p>See the <a href="https://github.com/endjin/Endjin.Core.Composition-V2/wiki/Installers">Installers</a> page on the GitHub wiki for a complete list of all the installers included in the framework, and explanations of how they work.</p>
<p>Next step is to initialize the container within our application&#8217;s start-up code. This is done using the Bootstrapper appropriate for whichever framework we are using, which will locate the installers in our assemblies and install the types they find into the container.</p>
<p><strong>WP8</strong></p>
<script src="https://gist.github.com/2069915b8fef938ea8b8.js"></script><noscript><pre><code class="language-c# c#">public partial class App : Application
{
  ...

  private async void Application_Launching(object sender, LaunchingEventArgs e)
  {
      // Initialize container using WP8 Bootstrapper
      await ApplicationServiceLocator.InitializeAsync(new Container(), new Wp8Bootstrapper());
  }

  ...
}</code></pre></noscript>
<p><strong>WinRT</strong></p>
<script src="https://gist.github.com/50c25568f1c2812ac0d3.js"></script><noscript><pre><code class="language-c# c#">sealed partial class App : Application
{
  ...
  
    protected override async void OnLaunched(LaunchActivatedEventArgs args)
    {
        Frame rootFrame = Window.Current.Content as Frame;

        if (rootFrame == null)
        {
            // Initialize the container for the application using the WinRT Bootstrapper
            await ApplicationServiceLocator.InitializeAsync(
                 new Container(),
                 new WinRtBootstrapper());
            
            ...
        }

  ...
}</code></pre></noscript>
<p><strong>.NET 4.0/4.5</strong></p>
<script src="https://gist.github.com/65ba5ab998f3ec998ad3.js"></script><noscript><pre><code class="language-c# c#">private async void Initialize()
{
    ...

    await ApplicationServiceLocator.InitializeAsync(new Container(), new DesktopBootstrapper());

    ...
}</code></pre></noscript>
<p>You can now use the static <code>ApplicationServiceLocator.Container</code> for resolving your root types.</p>
<script src="https://gist.github.com/b5d51463a1bf162dfb6d.js"></script><noscript><pre><code class="language-c# c#">public class FooService
{
    private readonly IRepository repository;

    public FooService()
    {
        this.repository = ApplicationServiceLocator.Container.Resolve&lt;IRepository&gt;();
    }

    public void WriteMessage()
    {
        var message = this.repository.GetMessage();
        Console.WriteLine(message);
    }
}</code></pre></noscript>
<p>In the next post, I&#8217;ll go over how to use the ContentFactory for registering content with custom names.</p>
<p><a href="http://twiiter.com/MikeLarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-2-getting-started/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introducing endjin composition framework 2.0 : Part 1</title>
		<link>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-1/</link>
		<comments>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-1/#comments</comments>
		<pubDate>Thu, 09 May 2013 07:00:31 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Engineering Practices]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Endjin Composition]]></category>

		<guid isPermaLink="false">http://blogs.endjin.com/?p=7382</guid>
		<description><![CDATA[We’ve just pushed out version 2.0 of our open-source, component composition framework. This is the framework we use internally day-in, day-out for our dependency injection. The previous version had a dependency on Castle Windsor, but in this new version we have implemented our own container. There are a few reasons we decided to take this [...]]]></description>
				<content:encoded><![CDATA[<p>We’ve just pushed out version 2.0 of our open-source, component composition framework. This is the framework we use internally <a href="http://endjin.com/our-work" target="_blank">day-in, day-out</a> for our dependency injection. The <a href="http://blogs.endjin.com/2010/12/work-smarter-with-convention-over-configuration-and-the-endjin-composition-framework/">previous version</a> had a dependency on <a href="http://docs.castleproject.org/">Castle Windsor</a>, but in this new version we have implemented our own container.</p>
<p>There are a few reasons we decided to take this step. Mainly, we were developing some early Windows Phone 8 and Windows 8 applications last year, like our <a href="http://blogs.endjin.com/2013/04/prototyping-and-proof-of-concept-charting-and-data-visualization-on-the-microsoft-platforms/">cross-platform charting controls</a> and <a href="http://endjin.com/our-work/milliman">Milliman&#8217;s Azure Compute Dashboard</a>, and we couldn&#8217;t live without DI. At the time, none of the existing container frameworks supported all the main Microsoft platforms that we were working with, so we had to &#8220;roll our own&#8221;. I did attempt to build a Windows 8 Azure Dashboard app (see pic) without DI to begin with, but the barrier to maintainability meant when it got large enough I ended up pretty much going back to the start and reimplementing it using our new framework.</p>
<p><a href="http://blogs.endjin.com/wp-content/uploads/2013/05/AzureDashboard.png"><img class="alignnone  wp-image-8122" alt="AzureDashboard" src="http://blogs.endjin.com/wp-content/uploads/2013/05/AzureDashboard.png" width="1152" height="720" /></a></p>
<p>Other containers are also really expensive for a &#8216;miss&#8217; scenario (i.e. trying to resolve a component that isn&#8217;t registered in the container), because they use exceptions to implement this. We wanted to be really efficient for failing to find a match so we could implement an inexpensive &#8220;fallback mechanism&#8221; (e.g. looking in the container for handlers for specific content types, falling back to more general versions, if they were not found).</p>
<p>The other reason was, as much as we love Castle Windsor, it does a lot (much like the Spring Framework in the Java ecosystem). It suffers from a problem that many OSS projects do &#8211; it&#8217;s based on contributions from the community but rarely do people rationalise and prune the feature set. So with our container, we&#8217;ve stripped it back and included only the features we require. This means that there&#8217;s lots it doesn&#8217;t do, but in this series of blog posts, we&#8217;re going to cover many of the main usage scenarios.</p>
<p>Whatever the framework, component composition works the same way: you have contracts and concrete implementations and you need to map one against the other. The <a href="https://github.com/endjin/Endjin.Core.Composition-V2" target="_blank">Endjin Composition Framework</a> helps you work smarter, not harder by making component composition simple.</p>
<p>You can install the packages via <a href="http://nuget.org/packages/Endjin.Core.Composition/">NuGet</a> or the <a href="https://github.com/endjin/Endjin.Core.Composition-V2">source code</a> is available up on the <a href="http://www.github.com/endjin">endjin GitHub page</a>. There are packages for use with .NET 4.0, .NET 4.5, WinRT and Windows Phone 8 frameworks. Additionally there is an <a href="http://nuget.org/packages/Endjin.Core.Composition.Web/">Endjin.Core.Composition.Web</a> package with extensions for use in ASP.NET MVC 4 / WebAPI applications.</p>
<p>There are samples in the GitHub repo for how to use component composition for each of the supported frameworks, and in the next post I&#8217;ll go over how to get set up.</p>
<p><a href="http://twiiter.com/MikeLarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2013/05/introducing-endjin-composition-framework-2-0-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A step by step guide to building a Twilio voice app with Web API</title>
		<link>http://blogs.endjin.com/2013/01/a-step-by-step-guide-to-building-a-twilio-voice-app-with-web-api/</link>
		<comments>http://blogs.endjin.com/2013/01/a-step-by-step-guide-to-building-a-twilio-voice-app-with-web-api/#comments</comments>
		<pubDate>Thu, 24 Jan 2013 16:50:37 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Step by Step Guides]]></category>
		<category><![CDATA[Twilio]]></category>
		<category><![CDATA[Web API]]></category>

		<guid isPermaLink="false">http://endjinblog.azurewebsites.net/?p=636</guid>
		<description><![CDATA[Background Twilio is a cloud based voice and SMS service and this post will show you how easy it is to create your own inbound voice application using MVC 4 Web API. The basic premise of how it works is Twilio parses a form of XML called ‘TwiML&#8217;, which contains various verbs telling Twilio what [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Background</strong></p>
<p><a href="http://www.twilio.com">Twilio</a> is a cloud based voice and SMS service and this post will show you how easy it is to create your own inbound voice application using MVC 4 Web API.</p>
<p>The basic premise of how it works is Twilio parses a form of XML called ‘TwiML&#8217;, which contains various verbs telling Twilio what to do. For example, parsing the following TwiML would read out &#8220;Good morning. How do you do?&#8221; in a woman&#8217;s voice, pause for 5 seconds, then make a POST request to https://twiliowebapisample.endjin.com/api/Sample for the next section of TwiML :</p>
<script src="https://gist.github.com/b32a9881530742c2878e.js"></script><noscript><pre><code class="language-xml xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Response&gt;
    &lt;Say voice=&quot;woman&quot;&gt;Good morning. How do you do?&lt;/Say&gt;
    &lt;Pause length=&quot;5&quot;/&gt;
    &lt;Redirect method=&quot;POST&quot;&gt;https://twiliowebapisample.endjin.com/api/Sample&lt;/Redirect&gt;
&lt;/Response&gt;</code></pre></noscript>
<p>The full set of verbs and parameters you can use are detailed in <a href="http://www.twilio.com/docs/api/twiml">Twilio’s docs section</a>.</p>
<p>When someone dials into your service, Twilio will make a request to an action on one of your Web API controllers. Your controller may call on some back-end infrastructure and will then generate some TwiML to return to Twilio&#8217;s parser. This TwiML will need to contain instructions on where to make the next request, and so this will continue until the call is over.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2013/01/Twilio-Diagram-21.jpg"><img class="aligncenter" style="float: none;padding-top: 0px;padding-left: 0px;margin-left: auto;padding-right: 0px;margin-right: auto;border: 0px" title="Twilio-Diagram-2" alt="Twilio-Diagram-2" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2013/01/Twilio-Diagram-2_thumb1.jpg" width="878" height="249" border="0" /></a></p>
<p><strong>Setup</strong></p>
<p>To get started, firstly create a new ASP.NET MVC 4 app in Visual Studio and select Web API. Then pull in the Nuget package for <a href="https://github.com/twilio/twilio-csharp">Twilio.Mvc</a> which contains libaries for MVC helpers and REST API wrappers.</p>
<p>You will also have to <a href="https://www.twilio.com/try-twilio">sign up for a Twilio account</a> (there is a free trial for developers). You will be given a phone number on signing up that you can use for the service.</p>
<p><strong>Controllers</strong></p>
<p>Let’s start by making a controller for our Twilio service to call when someone rings in. Create a new ApiController with a Post method like so:</p>
<script src="https://gist.github.com/40de09a13a668151d816.js"></script><noscript><pre><code class="language-c# c#">public class WelcomeController : ApiController
{
    public HttpResponseMessage Post(VoiceRequest request)
    {
        // Method will go here
    }    
}</code></pre></noscript>
<p>By default, all request Twilio makes are POST but you can change these to GET if you wish. When Twilio makes a request it also passes a set of parameters, the same as the ones contained in the VoiceRequest class in the client library.</p>
<p>Use the TwilioResponse MVC helper to build up the TwiML for the response. It contains methods for generating the correct TwiML and stores it in the Element property. When you have built up your TwiML, simply return the Element property as an HTTP response and format as XML.</p>
<script src="https://gist.github.com/7c04f6cfeffa77082179.js"></script><noscript><pre><code class="language-c# c#">public HttpResponseMessage Post(VoiceRequest request)
{
    var response = new TwilioResponse();

    response.Say(&quot;Welcome to this Twilio demo app. Please enter your 5 digit ID.&quot;);
    response.Gather(new { numDigits = 5, action = string.Format(&quot;/api/Authenticate&quot;) });

    return this.Request.CreateResponse(
        HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter());
}</code></pre></noscript>
<p>If you use the gather verb in your TwiML, after the user has pressed a specified number of digits, Twilio sends a request to the URL you specify in the action parameter (you can specify relative or fully-qualified URLs). It also passes a Digits string as one of the request parameters, which contains the numbers that the user pressed on their telephone. Now you can use these digits in your controller method, for example if you wanted a user to enter in an ID number to login into a service.</p>
<script src="https://gist.github.com/240aad410392f54f13b0.js"></script><noscript><pre><code class="language-c# c#">public class AuthenticateController : ApiController
{
    public HttpResponseMessage Post(VoiceRequest request)
    {
        var response = new TwilioResponse();

        var validIds = new List&lt;string&gt; { &quot;12345&quot;, &quot;23456&quot;, &quot;34567&quot; };
        var userId = request.Digits;
        var authenticated = validIds.Contains(userId);

        // Rest of method
    }
}</code></pre></noscript>
<p>Now if you wanted to pass other parameters to your controllers (the ID number the user previously entered, for example) you can just format your action and redirect URLs to include query parameters</p>
<script src="https://gist.github.com/62b28d6cf8bd9adb17f1.js"></script><noscript><pre><code class="language-c# c#">if (!authenticated)
{
    response.Say(&quot;You entered an invalid ID. Goodbye.&quot;);
    response.Hangup();
}
else
{
    response.Say(&quot;ID is valid.&quot;);
    response.Redirect(string.Format(&quot;/api/Name?userId={0}&quot;, userId));
}</code></pre></noscript>
<p>Then add a extra parameter to the action of the relevant controller</p>
<script src="https://gist.github.com/65fdfa85c767760a89f3.js"></script><noscript><pre><code class="language-c# c#">public class NameController : ApiController
  {
      public HttpResponseMessage Post(VoiceRequest request, string userId)
      {
          var response = new TwilioResponse();

          var usernames = new Dictionary&lt;string, string&gt;
                              {
                                  { &quot;12345&quot;, &quot;Tom&quot; }, 
                                  { &quot;23456&quot;, &quot;Dick&quot; }, 
                                  { &quot;34567&quot;, &quot;Harry&quot; }
                              };

          var username = usernames[userId];

          response.Say(string.Format(&quot;Hello {0}&quot;, username));
          response.Pause(5);
          response.Hangup();

          return this.Request.CreateResponse(
            HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter());
      }
    }</code></pre></noscript>
<p>You can create a complex service with many functions in this way.</p>
<p><strong>Security</strong></p>
<p>If your controllers expose any sensitive data you may want to validate that your requests are coming from Twilio. Fortunately, if you are using SSL and configure Twilio to use HTTPS URLs then you can do just that.</p>
<p>Twilio will take the full request URL and any POST parameters, concatenate them into a string, sign the string using HMAC-SHA1 with your AuthToken as the key (you are given an AuthToken when you create an account), and send this signature as a header on the request called &#8216;X-Twilio-Signature&#8217;. Full details are given in <a href="https://www.twilio.com/docs/security">Twilio’s Security section</a>.</p>
<p>So to authenticate the request we need construct the signature in the same manner on our side and check the two signatures match. In the Twilio.Mvc client library there is an attribute that can be applied to controllers and actions called ValidateRequestAttribute that does this for you if you are using MVC. For Web API though we will need to change this method slightly.</p>
<p>Create your own attribute as follows:</p>
<script src="https://gist.github.com/16e3acf94fdb11b14a30.js"></script><noscript><pre><code class="language-c# c#">using System;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;

public class ValidateTwilioRequestAttribute : ActionFilterAttribute
{
    private readonly string authToken;
    private readonly string urlOverride;

    public ValidateTwilioRequestAttribute()
    {
        this.authToken = ConfigurationManager.AppSettings[&quot;TwilioAuthToken&quot;];
    }

    public ValidateTwilioRequestAttribute(string urlOverride)
    {
        this.authToken = ConfigurationManager.AppSettings[&quot;TwilioAuthToken&quot;];
        this.urlOverride = urlOverride;
    }

    public override void OnActionExecuting(HttpActionContext actionContext)
    {
        if (!IsValidRequest(actionContext, this.authToken, this.urlOverride))
        {
            var response = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.Forbidden
            };
            throw new HttpResponseException(response);
        }

        base.OnActionExecuting(actionContext);
    }

    private static bool IsValidRequest(
        HttpActionContext context, string authToken, string urlOverride = null)
    {
        var value = new StringBuilder();
        
        // Take the host URL from the request, or use the URL override if there is one
        var fullUrl = string.IsNullOrEmpty(urlOverride) 
                                ? context.Request.RequestUri.ToString() : urlOverride;

        value.Append(fullUrl);

        var request = HttpContext.Current.Request;

        // If POST request, concatenate the key-value pairs in the request
        if (context.Request.Method == HttpMethod.Post)
        {
            var sortedKeys = request.Form.AllKeys.OrderBy(k =&gt; k, StringComparer.Ordinal).ToList();
            foreach (var key in sortedKeys)
            {
                value.Append(key);
                value.Append(request.Form[key]);
            }
        }

        // Create signature using AuthToken as key
        var sha1 = new HMACSHA1(Encoding.UTF8.GetBytes(authToken));
        var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(value.ToString()));
        var encoded = Convert.ToBase64String(hash);

        var sig = request.Headers[&quot;X-Twilio-Signature&quot;];

        // Compare our signatures
        return sig == encoded;
    }
}</code></pre></noscript>
<p>You will want to store your AuthToken somewhere in your configuration. In my example I have stored it in the Web.config file and used the ConfigurationManager to retrieve it in the default constructor. You’ll also notice there is a constructor that takes a urlOverride – you may need this when testing (we’ll get to that soon).</p>
<p>You can see the IsValidRequest method mirrors Twilio’s process for constructing the signature and then does the comparison. The attribute throws an exception and returns a Forbidden code if the signatures do not match.</p>
<p>To use the validation, all you need to do is decorate your actions (or controllers) with the attribute.</p>
<script src="https://gist.github.com/52d952e475c5f8e0fb25.js"></script><noscript><pre><code class="language-c# c#">[ValidateTwilioRequest]
public class WelcomeController : ApiController
{
  // Some actions
}</code></pre></noscript>
<p><strong>Debugging</strong></p>
<p>To check if your controllers are returning the correct TwiML you could use a web debugging tool such as <a href="http://www.fiddler2.com/fiddler2/">Fiddler</a> to make requests to your controllers and look at the responses. But if you want to test your application actually running in Twilio then you will need to create an app in the <a href="https://www.twilio.com/user/account">Twilio dashboard</a>. To do this, sign in to your Twilio account and go to DEV TOOLS –&gt; TWIML APPS –&gt; CREATE APP.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2013/01/23-01-2013-10-44-29.png"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" title="23-01-2013 10-44-29" alt="23-01-2013 10-44-29" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2013/01/23-01-2013-10-44-29_thumb.png" width="690" height="323" border="0" /></a></p>
<p>Give it a friendly name and then you will see you have to supply the request URL as an endpoint for Twilio to make requests. Now unless your machine is publicly exposed to the internet, you will need to set up some tunnelling in order to debug your application whilst in development.</p>
<p>For tunnelling I used a service called <a href="https://forwardhq.com/">Forward</a> (it was the only service I could find to work on Windows). This takes a little bit of setup. Firstly you will have to install Ruby and RubyGems (<a href="http://rubyinstaller.org/">Ruby Installer for Windows</a> is an easy option for this). Then <a href="https://forwardhq.com/signup?plan=solo">sign up for an account at Forward</a> – they offer a free 30 day trial.  With Ruby installed, open up Command Prompt With Ruby and install Forward using</p>
<p><span style="font-family: consolas">gem install forward</span></p>
<p>Finally, in your Web API project&#8217;s properties pane in VS, in the Web section under servers, change the setting to ‘Use Visual Studio Development Server’ and set a specific port of your choice.</p>
<p>Now we’re ready to go. Back in your Twilio dashboard, set the the request URL for app as the domain you specified when signing up for Forward (e.g. <a href="https://example.fwd.wf">https://example.fwd.wf</a>). Start up your Web API app in debug mode, then in Command Prompt With Ruby type</p>
<p><span style="font-family: consolas">forward {port}</span></p>
<p>where {port} is the port you assigned in the app properties. The first time you do this you be asked for your Forward credentials.</p>
<p>With that done, you should now hopefully be able to call your service. If you navigate to your TwiML app in the Twilio dashboard, just press the Call button.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2013/01/23-01-2013-10-48-22.png"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" title="23-01-2013 10-48-22" alt="23-01-2013 10-48-22" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2013/01/23-01-2013-10-48-22_thumb.png" width="701" height="225" border="0" /></a></p>
<p>And now you can run through your service using the onscreen keypad and debug on your development machine. The Twilio debugger in the dashboard also provides useful information for when errors occur.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2013/01/23-01-2013-10-51-05.png"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border-width: 0px" title="23-01-2013 10-51-05" alt="23-01-2013 10-51-05" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2013/01/23-01-2013-10-51-05_thumb.png" width="378" height="246" border="0" /></a></p>
<p><em>NOTE</em> – if you are using the authentication attribute from above to do validation, you will need to specify a urlOverride parameter when testing, otherwise you will find that Twilio will use your Forward URL when constructing a signature, but your app will use a “https://localhost:{port}” URL and they won’t match.</p>
<script src="https://gist.github.com/387ba6d21617eb4d7200.js"></script><noscript><pre><code class="language-c# c#">[ValidateTwilioRequest(&quot;https://example.fwd.wf/api/welcome&quot;)]
public class WelcomeController : ApiController
{
  // Some method
}</code></pre></noscript>
<p><strong>Conclusion</strong></p>
<p>There is of course plenty more functionality to be found with Twilio and this just scratches the surface. I would recommend you check out their website for all the features. But following this guide you can get quickly and simply set up with building an inbound voice application using Web API.</p>
<p>For the full sample application, download it from the <a href="https://github.com/endjin/Samples">endjin samples GitHub repo</a>.</p>
<p>Finally, thanks to <a href="http://twitter.com/sydlawrence">@sydlawrence</a> and <a href="http://twitter.com/devinrader">@devinrader</a> for help getting me starting with my Twilio project.</p>
<p><a href="http://twitter.com/MikeLarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2013/01/a-step-by-step-guide-to-building-a-twilio-voice-app-with-web-api/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Integration testing with Web API</title>
		<link>http://blogs.endjin.com/2013/01/integration-testing-with-web-api/</link>
		<comments>http://blogs.endjin.com/2013/01/integration-testing-with-web-api/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 10:45:59 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Samples]]></category>
		<category><![CDATA[Step by Step Guides]]></category>
		<category><![CDATA[Integration Testing]]></category>
		<category><![CDATA[Web API]]></category>

		<guid isPermaLink="false">http://endjinblog.azurewebsites.net/?p=619</guid>
		<description><![CDATA[I recently had do a project where I wanted to run integration tests on some Web API controllers, so this post is to describe the method for doing so. The way to do it is to mock an HttpServer and HttpClient class, but first you have to change some of the config to get them [...]]]></description>
				<content:encoded><![CDATA[<p>I recently had do a project where I wanted to run integration tests on some Web API controllers, so this post is to describe the method for doing so.</p>
<p>The way to do it is to mock an <em>HttpServer</em> and <em>HttpClient</em> class, but first you have to change some of the config to get them working correctly.</p>
<p>In the <em>WebApiConfig</em> in App_Start, create two overloaded methods for mapping HTTP routes &#8211; one that takes a <em>RouteCollection</em> as a parameter<em> </em>(for when running in debug/production), and one that takes an <em>HttpRouteCollection </em>(for when running integration tests).</p>
<p>You will also have to define your own class for a <em>Route - </em>with <em>Name</em>, <em>Template</em> and <em>Defaults</em> properties.</p>
<script src="https://gist.github.com/4500747.js"></script><noscript><pre><code class="language-c# c#">public static void AddHttpRoutes(this HttpRouteCollection routeCollection)
{
    var routes = GetRoutes();
    routes.ForEach(route =&gt; routeCollection.MapHttpRoute(route.Name, route.Template, route.Defaults));
}

public static void AddHttpRoutes(this RouteCollection routeCollection)
{
    var routes = GetRoutes();
    routes.ForEach(route =&gt; routeCollection.MapHttpRoute(route.Name, route.Template, route.Defaults));
}

private static List&lt;Route&gt; GetRoutes()
{
    return new List&lt;Route&gt;
               {
                   new Route(
                       &quot;DefaultApi&quot;, 
                       &quot;api/{controller}/{id}&quot;, 
                       new { id = RouteParameter.Optional })
               };
}

private class Route
{
    public Route(string name, string template, object defaults)
    {
        this.Name = name;
        this.Template = template;
        this.Defaults = defaults;
    }

    public object Defaults { get; set; }

    public string Name { get; set; }

    public string Template { get; set; }
}</code></pre></noscript>
<p>Then call the <em>AddHttpRoutes</em> method during application startup (I placed it in the <em>RegisterRoutes </em>method of <em>RouteConfig</em>) to configure the routing on the Web API controllers.</p>
<script src="https://gist.github.com/4500808.js"></script><noscript><pre><code class="language-c# c#">RouteTable.Routes.AddHttpRoutes();</code></pre></noscript>
<p>So now we are ready to set up some integration tests &#8211; in my sample I am using NUnit.</p>
<p>In your test setup you will need to instantiate an <em>HttpClient</em> and pass a configured <em>HttpServer </em>as a parameter (using the overloaded <em>AppHttpRoutes</em> method to configure it).</p>
<script src="https://gist.github.com/4500839.js"></script><noscript><pre><code class="language-c# c#">private HttpClient client;

[SetUp]
public void HttpClientSetup()
{
    var config = new HttpConfiguration();

    config.Routes.AddHttpRoutes();
    config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

    var server = new HttpServer(config);
    this.client = new HttpClient(server);
    
}</code></pre></noscript>
<p>Now you can create an <em>HttpRequest </em>and use the <em>HttpClient</em> to send the request and hit your Web API controllers, then run your assertions on the <em>HttpResponse</em> that is returned.</p>
<script src="https://gist.github.com/4500903.js"></script><noscript><pre><code class="language-c# c#">[TestCase]
public void GetRecordTest()
{
    var url = &quot;http://WebApiTests.com/api/records/1&quot;;

    var request = new HttpRequestMessage { RequestUri = new Uri(url) };
    request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(&quot;application/json&quot;));
    request.Method = HttpMethod.Get;

    HttpResponseMessage response = this.client.SendAsync(request, new CancellationTokenSource().Token).Result;

    Assert.True(response.IsSuccessStatusCode);
    Assert.NotNull(response.Content);
}

[TestCase]
public void PostRecordTest()
{
    var url = &quot;http://WebApiTests.com/api/records&quot;;

    var record = new Record { Name = &quot;Mike&quot;, Content = &quot;Hello!&quot; };
    
    var request = new HttpRequestMessage { RequestUri = new Uri(url) };
    request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(&quot;application/json&quot;));
    request.Method = HttpMethod.Post;
    request.Content = new ObjectContent&lt;Record&gt;(record, new JsonMediaTypeFormatter());

    HttpResponseMessage response = this.client.SendAsync(request, new CancellationTokenSource().Token).Result;

    Assert.True(response.IsSuccessStatusCode);
    Assert.NotNull(response.Content);
}</code></pre></noscript>
<p>And that&#8217;s it. Now you can run integration tests against your Web API controllers &#8211; useful for checking if your routes are correctly configured.</p>
<p>Check out the full sample on the <a href="https://github.com/endjin/Samples">endjin samples GitHub repo</a>.</p>
<p>&nbsp;</p>
<p><a href="http://twitter.com/MikeLarah">@MikeLarah</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2013/01/integration-testing-with-web-api/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>DDD10 Conference</title>
		<link>http://blogs.endjin.com/2012/09/ddd10-conference/</link>
		<comments>http://blogs.endjin.com/2012/09/ddd10-conference/#comments</comments>
		<pubDate>Mon, 03 Sep 2012 14:55:26 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Apprenticeships]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Event Sourcing]]></category>
		<category><![CDATA[SignalR]]></category>
		<category><![CDATA[WebSockets]]></category>

		<guid isPermaLink="false">http://endjinblog.azurewebsites.net/?p=581</guid>
		<description><![CDATA[Saturday I attended the Developer Developer Developer DDD10 conference held at Microsoft HQ in Reading. There were some great talks throughout the day and I’ll highlight a couple of the ones I attended. DDD, CQRS and Event Sourcing – Neil Barnwell First talk of the day from a first time Developer Developer Developer speaker (although [...]]]></description>
				<content:encoded><![CDATA[<p>Saturday I attended the Developer Developer Developer DDD10 conference held at Microsoft HQ in Reading.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/09/IMAG0237.jpg"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/09/IMAG0237_thumb.jpg" alt="IMAG0237" width="647" height="364" border="0" /></a></p>
<p>There were some great talks throughout the day and I’ll highlight a couple of the ones I attended.</p>
<p><strong>DDD, CQRS and Event Sourcing – </strong><a href="http://www.neilbarnwell.co.uk/">Neil Barnwell</a></p>
<p>First talk of the day from a first time Developer Developer Developer speaker (although you would never have known). Neil used a series of examples based around his current line of work (warehouse management systems) to put forward his arguments. He went through the advantages of using Domain-Driven Design for any applications that require more logic than CRUD (Create, Read, Update, Delete). I’ve been informed that this <a href="http://www.amazon.co.uk/Domain-driven-Design-Tackling-Complexity-Software/dp/0321125215">book</a> by Eric Evans is good place to start for DDD and has been added to my reading list.</p>
<p>He went on to talk about how DDD lends itself to two other ideas: CQRS (Command Query Responsibility Separation) and Event Sourcing.  CQRS as I understand it is essentially a separation of commands (which mutate state) and queries (which do not). This leads onto the idea of Event Sourcing, where every command triggers an event and these event objects are stored in sequence. Then you can do interesting things like replaying the events to rebuild the application state, or looking at at the state at any given time in the past. Neil pointed out that this could be really useful when debugging as you can see the precise sequence of events that led to a bug.</p>
<p>I found <a href="http://martinfowler.com/bliki/CQRS.html">this link</a> and <a href="http://martinfowler.com/eaaDev/EventSourcing.html">this link</a> useful for better understanding the ideas.</p>
<p><strong>Developing real-time asynchronous web applications – </strong><a href="http://mirajavora.com/">Mira Javora</a></p>
<p>Mira showed a really interesting example of using <a href="http://signalr.net/">SignalR</a> to create real-time web applications. His example was a basic “Formula 1” web app that showed updates to race position, news etc.</p>
<p>He explained that instead of the client constantly querying the server to see if there is any new data, by implementing SignalR, the server establishes whether the client is capable of accepting real-time information and creates a persistent connection using WebSockets if possible (and if not it uses another real-time technique such as Long Polling).</p>
<p>From what Mira demonstrated, I feel there is a lot of potential in these type of applications and am looking forward to trying it out for myself.</p>
<p><strong>Designing for Mobile – </strong><a href="http://twitter.com/GeorgeAdamson">George Adamson</a></p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/09/IMAG0241.jpg"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/09/IMAG0241_thumb.jpg" alt="IMAG0241" width="657" height="370" border="0" /></a></p>
<p>A lively talk from George that made me a think. He spoke about how the instinct is to design “desktop” apps primarily, then make a “mobile” app to fit around that by some means, whether that be by linking to the desktop site for full features or just omitting features altogether.</p>
<p>But, to quote George himself, “Mobile traffic has/might-jolly-soon overtake desktop traffic”. We expect to be able to do the same things now whether we’re on our smartphones, tablets or laptops and all these devices can be classed as “mobile”. So almost every web application should be designed with this in mind and the solution he suggested is to place content as first priority and use <a href="http://en.wikipedia.org/wiki/Responsive_Web_Design">responsive web design</a>.</p>
<p>George then went on to explain various ways of implementing this and talked about good practices to bear in mind when designing for mobile.</p>
<p>&nbsp;</p>
<p>Overall I would say DDD10 was great success and I will definitely be attended more of their events in the future. The Doctor Who cupcakes helped too (not a fan of the show BTW, but they were delicious)</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/09/IMAG0242.jpg"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/09/IMAG0242_thumb.jpg" alt="IMAG0242" width="708" height="398" border="0" /></a></p>
<p><a href="http://twitter.com/MikeLarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2012/09/ddd10-conference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the endjin composition framework in an MVC application</title>
		<link>http://blogs.endjin.com/2012/08/using-the-endjin-composition-framework-in-an-mvc-application/</link>
		<comments>http://blogs.endjin.com/2012/08/using-the-endjin-composition-framework-in-an-mvc-application/#comments</comments>
		<pubDate>Thu, 23 Aug 2012 09:53:53 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Apprenticeships]]></category>
		<category><![CDATA[Castle Windsor]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Gist]]></category>

		<guid isPermaLink="false">http://endjinblog.azurewebsites.net/?p=541</guid>
		<description><![CDATA[As I was setting up the framework for my apprenticeship portal MVC 4 web application, I used part of endjin’s core composition framework for the dependency injection, which utilises Castle Windsor. (Here is a link to some useful videos on dependency injection and Castle Windsor that helped me to understand why they are used). Part of the framework [...]]]></description>
				<content:encoded><![CDATA[<p>As I was setting up the framework for my apprenticeship portal MVC 4 web application, I used part of <a href="https://github.com/endjin/Endjin.Core.Composition">endjin’s core composition framework</a> for the dependency injection, which utilises <a href="http://docs.castleproject.org/Windsor.MainPage.ashx">Castle Windsor</a>.</p>
<p>(Here is a <a href="http://dimecasts.net/Casts/ByTag/Windsor%20Castle">link</a> to some useful videos on dependency injection and Castle Windsor that helped me to understand why they are used).</p>
<p>Part of the framework uses a class called WindsorContainerBootstrapper which calls a GetInstallers method which looks through all referenced assemblies and finds and returns a list of the Windsor Installers that are contained within them.</p>
<script src="https://gist.github.com/3448834.js"></script><noscript><pre><code class="language-c# c#">public class WindsorContainerBootstrapper : IContainerBootstrapper
  {
    public IWindsorInstaller[] GetInstallers()
    {
      return new IWindsorInstaller[1]
      {
        FromAssembly.InDirectory(new AssemblyFilter(&quot;./&quot;, (string) null))
      };
    }
  }</code></pre></noscript>
<p>This was designed for console applications though. To make this work, I made a change so that it uses the HttpRuntime.BinDirectory method to correctly locate the bin folder where the assemblies are stored in a web application.</p>
<script src="https://gist.github.com/3448882.js"></script><noscript><pre><code class="language- ">public class WindsorContainerWebBootstrapper : IContainerBootstrapper
    {
        public IWindsorInstaller[] GetInstallers()
        {
            return new[] { FromAssembly.InDirectory(new AssemblyFilter(HttpRuntime.BinDirectory, &quot;*.dll&quot;)) };
        }
    }</code></pre></noscript>
<p>This extra class could not be added to Endjin.Core.Composition though as HttpRuntime is dependent on System.Web, and Endjin.Core.Composition uses the .NET 4 Client Profile which does not support this.</p>
<p>So I added a new WindsorContainerWebBootstrapper class to the project and called it in the dependency injection configuration to initialise a new Windsor Container.</p>
<script src="https://gist.github.com/3448828.js"></script><noscript><pre><code class="language-c# c#">  public class ContainerConfig
    {
        public static void InitialiseContainer()
        {
            ApplicationServiceLocator.Initialize(new WindsorContainer(), new WindsorContainerWebBootstrapper());
            var container = ApplicationServiceLocator.Container;
            
            // MVC
            DependencyResolver.SetResolver(
               x =&gt; container.Kernel.HasComponent(x) ? container.Resolve(x) : null,
               x =&gt; container.Kernel.HasComponent(x) ? container.ResolveAll(x).Cast&lt;object&gt;() : new object[0]);
        }
    }</code></pre></noscript>
<p>This means I can now resolve my types dynamically.</p>
<p>(As a side note, we now have a <a href="https://gist.github.com/">GitHub Gist</a> <a href="http://wordpress.org/extend/plugins/embed-github-gist/">plugin</a> installed for the blog so all the pasted code looks pretty)</p>
<p><a href="http://twitter.com/mikelarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2012/08/using-the-endjin-composition-framework-in-an-mvc-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 8 Development Camp</title>
		<link>http://blogs.endjin.com/2012/08/windows-8-development-camp/</link>
		<comments>http://blogs.endjin.com/2012/08/windows-8-development-camp/#comments</comments>
		<pubDate>Thu, 23 Aug 2012 09:21:26 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Apprenticeships]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://endjinblog.azurewebsites.net/?p=515</guid>
		<description><![CDATA[I spent yesterday at Microsoft’s London offices for talks on how to develop new Metro – uh, “Windows Store” – apps for Windows 8. The day kicked off with Mike Taulty going over all the features of Windows 8 and explaining how to use the new touch based controls and also how to do everything [...]]]></description>
				<content:encoded><![CDATA[<p>I spent yesterday at Microsoft’s London offices for talks on how to develop new Metro – uh, “Windows Store” – apps for Windows 8.</p>
<p>The day kicked off with <a href="http://mtaulty.com/communityserver/blogs/mike_taultys_blog/default.aspx">Mike Taulty</a> going over all the features of Windows 8 and explaining how to use the new touch based controls and also how to do everything with whilst using traditional keyboard and mouse. I must say, even after having used Windows 8 for 3 weeks now, I found it becomes much easier to use as a desktop OS once you learn all the keyboard shortcuts ( Windows + q for search, Windows + . to “snap” an app, Windows + c for the charms menu, etc.) and the split desktop/tablet experience isn’t as jarring as I first found it.</p>
<p>Then a great talk from <a href="http://twitter.com/andspo">Andrew Spooner</a> about the UX/UI considerations when developing Metro apps. It appears Microsoft have taken a big step towards making the user’s experience seamless between apps, by encouraging developers to do things like only using fonts of 3 specified sizes (depending on heading/subtitle/text) from a select group of typefaces and considering how the app’s views for <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465319.aspx">semantic zoom</a>.</p>
<p>Back to Mike Taulty again for a more in-depth talk about the new Windows APIs specifically for Metro apps like sharing, searching, notifications and app lifecycle management.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/IMAG0222-21.jpg"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/IMAG0222-2_thumb1.jpg" alt="IMAG0222 (2)" width="730" height="410" border="0" /></a></p>
<p>In afternoon we got to see these APIs in action as we put together a Metro app through a series of tutorials, building the ‘Contoso Cookbook’ app (and getting my first, slightly daunting, experience with using XAML).</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image9.png"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image_thumb8.png" alt="image" width="737" height="415" border="0" /></a></p>
<p>I could talk about any and all of the new features in detail but I think one of my favourite parts was how easy it is to set up an app to share content and also how easy it is to set up another app to consume that content.</p>
<p>When hitting the share charm whilst on a page in the app, a DataRequested event is triggered. All that needs to be done in the app is write a handler on that page to respond to the event. So for example, for the single item page (in this case a recipe) like this,</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image10.png"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image_thumb9.png" alt="image" width="737" height="464" border="0" /></a></p>
<p>the method needed to share the image and text is:</p>
<pre><script src="https://gist.github.com/3450711.js"></script><noscript><pre><code class="language-c# c#">void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
    var request = args.Request;
    var item = (RecipeDataItem)this.flipView.SelectedItem;
    request.Data.Properties.Title = item.Title;
    request.Data.Properties.Description = &quot;Recipe ingredients and directions&quot;;
    
    // Share recipe text
    var recipe = &quot;\r\nINGREDIENTS\r\n&quot;;
    recipe += String.Join(&quot;\r\n&quot;, item.Ingredients);
    recipe += (&quot;\r\n\r\nDIRECTIONS\r\n&quot; + item.Directions);
    request.Data.SetText(recipe);
    
    // Share recipe image
    var reference = RandomAccessStreamReference.CreateFromUri(new Uri(item.ImagePath.AbsoluteUri));
    request.Data.Properties.Thumbnail = reference;
    request.Data.SetBitmap(reference);
}
</code></pre></noscript></pre>
<p><span style="font-family: Verdana">Then when hitting the share charm, Windows filters through your apps to determine which ones are capable of handling the file types you have shared.</span></p>
<pre><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image11.png"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image_thumb10.png" alt="image" width="240" height="237" border="0" /></a></pre>
<p><span style="font-family: Verdana">Using the Share Target sample from the Windows 8 SDK we can see that the image and text content were both shared.</span></p>
<pre><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image12.png"><img style="padding-top: 0px;padding-left: 0px;padding-right: 0px;border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image_thumb11.png" alt="image" width="714" height="402" border="0" /></a></pre>
<p>So, all in all an interesting day at Microsoft and I think it’s going to be quite fun doing some Windows 8 development.</p>
<p><a href="http://twitter.com/MikeLarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2012/08/windows-8-development-camp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apprenticeship Week 2</title>
		<link>http://blogs.endjin.com/2012/08/apprenticeship-week-2/</link>
		<comments>http://blogs.endjin.com/2012/08/apprenticeship-week-2/#comments</comments>
		<pubDate>Sat, 18 Aug 2012 12:01:08 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Apprenticeships]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Balsamiq]]></category>
		<category><![CDATA[Functional testing]]></category>
		<category><![CDATA[XMind]]></category>

		<guid isPermaLink="false">http://endjinblog.azurewebsites.net/?p=496</guid>
		<description><![CDATA[I started my second week of the apprenticeship by looking at some functional testing. Specifically I was beginning to put together a ‘regression’ test pack for a client, identifying key success scenarios in their product and service that can be tested against before future releases are deployed to ensure the software does not ‘regress’. Ideally, once this [...]]]></description>
				<content:encoded><![CDATA[<p>I started my second week of the apprenticeship by looking at some functional testing. Specifically I was beginning to put together a ‘regression’ test pack for a client, identifying key success scenarios in their product and service that can be tested against before future releases are deployed to ensure the software does not ‘regress’. Ideally, once this test pack has been compiled, it would be best to write scripts to automate what would be long manual testing process.</p>
<p>The other part of my week has been spent preparing to write a web application to assist in logging my (and future apprentices’) progress. The idea is to create a system where it is easy to log activities that have been completed and represent the logged data in useful ways. Other features will be to provide a way to give feedback for continuous assessment throughout the apprenticeship, and a library for sharing useful articles/tutorials/tools. To get prepared for this, I have been studying <a href="http://www.pluralsight.com/training">Pluralsight</a> courses on <a href="http://www.asp.net/mvc">ASP.NET MVC</a> and <a href="http://www.asp.net/web-api">Web API</a>.</p>
<p>To begin designing the structure of the site, I have been creating a mindmap (using <a href="http://www.xmind.net/">XMind</a>) and using a great, simple tool called <a href="http://www.balsamiq.com/products/mockups">Balsamiq Mockups</a> to create wireframes like the one below.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/courselog.png"><img style="border: 0px" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/courselog_thumb.png" alt="course log" width="647" height="454" border="0" /></a></p>
<p>These are both great ways to start thinking about the features for the site and the architecture that will be required to build it.</p>
<p>Finally, I have also this week attended the Microsoft <a href="http://www.microsoft.com/belux/techdays/2012/Home.aspx">TechDays</a> Windows Azure Developer Camp (taken by cloud evangelist <a href="http://blogs.msdn.com/b/plankytronixx/">Steve Plank</a>), where I was shown an introduction to cloud computing and how to do things like deploy an application to Azure, and create and utilise cloud storage and databases.</p>
<p><a href="http://twiiter.com/mikelarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2012/08/apprenticeship-week-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>End of the first week</title>
		<link>http://blogs.endjin.com/2012/08/end-of-the-first-week/</link>
		<comments>http://blogs.endjin.com/2012/08/end-of-the-first-week/#comments</comments>
		<pubDate>Thu, 09 Aug 2012 15:49:57 +0000</pubDate>
		<dc:creator>Mike.Larah</dc:creator>
				<category><![CDATA[Apprenticeships]]></category>
		<category><![CDATA[Musings]]></category>

		<guid isPermaLink="false">http://endjinblog.azurewebsites.net/?p=480</guid>
		<description><![CDATA[As thought, by modifying our YouTrackSharp CreateUser method to use PUT instead of POST (and creating the Put method), this fixed the password issue and is now fully functioning. So one down! Next up was to try TeamCity and straight to C# and VS 2012 for this one as the REST API looked similar to [...]]]></description>
				<content:encoded><![CDATA[<p>As thought, by modifying our YouTrackSharp CreateUser method to use PUT instead of POST (and creating the Put method), this fixed the password issue and is now fully functioning.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image7.png"><img style="border: 0px;" alt="image" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image7_thumb.png" width="921" height="326" border="0" /></a></p>
<p>So one down! Next up was to try <a href="http://www.jetbrains.com/teamcity/">TeamCity</a> and straight to C# and VS 2012 for this one as the REST API looked similar to YouTrack. For this we used the <a href="https://github.com/stack72/TeamCitySharp">TeamCitySharp</a> NuGet package (by <a href="http://paulstack.co.uk/blog/">Paul Stack</a>).</p>
<p>Although similar, it was not exactly the same and I found that it required a XML object passed, not just a string. We ended up using <a href="http://www.fiddler2.com/fiddler2/">Fiddler</a> to determine the structure of the required request body to create a new user and tested by using POST request in Fiddler itself (below). This turned out to be successful, except there was an issue (again) with the password.</p>
<p><a href="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image3.png"><img style="border: 0px;" alt="image" src="http://endjinblog.azurewebsites.net/wp-content/uploads/2012/08/image_thumb3.png" width="917" height="307" border="0" /></a></p>
<p>After contacting the TeamCity team, it seems like there is a issue in the XML deserialization which ignores the password and they suggested a workaround by using a separate PUT request for the password. Using this fix, I got the CreateUser method fully working in TeamCitySharp and so have now successfully got two of the five accounts for new employees to automate new users. Next step will be to wrap them up in PowerShell script.</p>
<p>So to sum up this first week at endjin: I’ve had a play around with PowerShell and C#, learnt to use various debugging tools like Fiddler and IDE debuggers, learnt how to use BDD and testing frameworks, used Git to save and share projects, learnt how to configure virtual machines, toyed around with various tools to increase productivity and attended a client meeting about developing a communication plan. Been kept busy but that’s not a bad thing!</p>
<p>Next week I’ll be off at a client to run some testing, spending a day at Microsoft to attend a course on Azure, and starting to develop a web and mobile app to log apprentice activities and development.</p>
<p><a href="http://twitter.com/MikeLarah">@MikeLarah</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.endjin.com/2012/08/end-of-the-first-week/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
