<?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/"
     xmlns:georss="http://www.georss.org/georss" 
     xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" 
     xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Nathan Totten's Blog</title>
    <description>Thoughts and Experiences with Software Development.</description>
    <atom:link href="http://http://ntotten.com/feed/" rel="self" type="application/rss+xml" />
    <link>http://ntotten.com</link>
    <lastBuildDate>Sat, 25 May 2013 14:43:35 -0700</lastBuildDate>
    <language>en</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <image>
      <url>http://0.gravatar.com/blavatar/4467e37d91705aa956f90e6c2e16e118?s=96</url>
      <title>Nathan Totten's Blog</title>
      <link>http://ntotten.com</link>
    </image>
    <atom:link href="http://ntotten.com/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>Windows Azure SDK for Node.js and CLI updated for Node.js 0.10.x</title>
        
        <description><![CDATA[The Windows Azure SDK for Node.js and CLI has been updated for compatibility with Node.js 0.10.x. You can now use the latests and greatest version of Node with Windows Azure.]]></description>
        
        <pubDate>Sun, 14 Apr 2013 00:00:00 -0700</pubDate>
        <link>http://ntotten.com/2013/04/14/windows-azure-sdk-for-nodejs-and-cli-updated-for-nodejs-010x/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/04/14/windows-azure-sdk-for-nodejs-and-cli-updated-for-nodejs-010x/</guid>
        <content:encoded><![CDATA[<p>Good news! The <a href="https://github.com/WindowsAzure/azure-sdk-tools-xplat">Windows Azure Cross Platform CLI</a> and the <a href="https://github.com/WindowsAzure/azure-sdk-for-node/">Windows Azure SDK for Node.js</a> has been updated to support Node.js version 0.10.3 and above. You can now update your installation of node and Windows Azure tools to the latest and greatest.</p>

<blockquote><p><strong>Note</strong>: Make sure you are using 0.10.3 or greater. <a href="https://twitter.com/guayan/">Guang Yang</a>, who is a PM on the team that writes the SDK <a href="https://twitter.com/guayan/status/323549326687219712">pointed out</a> that there is a bug in earlier versions that can cause issues in the SDK.</p></blockquote>

<p>To upgrade Node.js head over to <a href="http://nodejs.org">nodejs.org</a> and click the install button. In order to upgrade the Windows Azure CLI tools simply use npm as show below.</p>

<pre><code>npm install azure-cli -g
</code></pre>

<blockquote><p><strong>Note</strong>: On OS X you will need to run this command as sudo to install globally.</p></blockquote>

<p>To install the latest version of the Windows Azure SDK for Node.js in your project you can use npm as well.</p>

<pre><code>npm install azure
</code></pre>

<p>An alternative option is to use our one-click installers to install the SDK and tools together. You can find the <a href="http://www.windowsazure.com/en-us/downloads/">Node.js installer here</a>.</p>
]]></content:encoded>
      </item>
    
      <item>
        <title>Using Node.js with Jekyll to Optimize Static Content</title>
        
        <description><![CDATA[Learn how to use Node.js to script common tasks for optimizing static content in a Jekyll page.]]></description>
        
        <pubDate>Wed, 10 Apr 2013 00:00:00 -0700</pubDate>
        <link>http://ntotten.com/2013/04/10/using-nodejs-with-jekyll-to-optimize-static-content/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/04/10/using-nodejs-with-jekyll-to-optimize-static-content/</guid>
        <content:encoded><![CDATA[<p>I recently migrated my blog to <a href="https://github.com/mojombo/jekyll">Jekyll</a> hosted on Github Pages. I did this primarily because I was sick of dealing with the web editor in Wordpress. Wordpress is a great blogging platform for many people, but I just wanted something simpler and more flexible. I have <a href="http://ntotten.com/2012/03/02/github-pages-with-jekyll-local-development-on-windows/">written about</a> how to configure Jekyll on Windows in the past. This post is about optimizing the content of a Jekyll page using Node.js.</p>

<p>The reason, I am using Node.js is primarily because of cross-platform issues with many Ruby gems. I played around with Jekyll Asset Pipeline and it seemed like a great tool for combining and minifying static content, but it seems to have issues running on Windows. I use many different computers including several PCs (I love my Surface Pro) and a Macbook Air so cross-platform support is critical. I blog on both devices so my blog platform must work on each OS. Node.js is an obvious choice for this as it runs flawlessly on both platforms.</p>

<p>The second reason I chose to use Node.js rather than Ruby gems is because I am hosting this site on Github Pages to use their automatic Jekyll deployment. Unfortunately, Github Pages doesn't support Jekyll plugins so anything that does this level of customization must be done on my local machine anyway. This means it didn't really matter which tools I used.</p>

<p>Now, that you know why I am doing this. Lets talk about how. First, I decided to use <a href="https://github.com/srod/node-minify">node-minify</a> to handle the actual combining and minifying of files. This node module works well, it is simple, and it works with several minification libraries like UglyJS, YUI Compressor, and Google Closure Complier. Since I avoid Java like the plague I am just using UglyJS. The optimization isn't quite as good as the other two, but it is enough for me.</p>

<p>Below you can see how node-minify can be used to combine and minify js and css files.</p>

<pre><code>// Using UglifyJS for JS
new compressor.minify({
  type: 'uglifyjs',
  fileIn: ['assets/js/prettify.js', 'assets/js/app.js'],
  fileOut: 'assets/' + config.version + '.js',
  callback: function(err){
    if (err) {
      console.log(err);
    }
  }
});

// Using Sqwish for CSS
new compressor.minify({
  type: 'sqwish',
  fileIn: ['assets/css/bootstrap.min.css', 'assets/css/style.css'],
  fileOut: 'assets/' + config.version + '.css',
  callback: function(err){
    if (err) {
      console.log(err);
    }
  }
});
</code></pre>

<p>In addition to node-minify I also wanted something that would help me automate the various tasks of building the site. For this I chose <a href="https://github.com/mde/jake">Jake</a>. Jake is a great tool that I have used on many other projects for creating build scripts.</p>

<p>I setup my jakefile.js with a few simple tasks.</p>

<pre><code>task('default', ['minify', 'build'])

task('minify', function() {
  // Clean up old files
  var files = fs.readdirSync('./assets/');
  for (var i = files.length - 1; i &gt;= 0; i--) {
    var file = files[i];
    if (path.extname(file) == '.js' || path.extname(file) == '.css') {
      fs.unlinkSync('./assets/' + file);
    }
  };

  // Combine and minify code here
  ...
});

task('build', function() {
  setConfigValue('version', config.version);
});
</code></pre>

<p>On thing you will notice is that my static content is being created with a uuid version number. This way each time I publish my site I get a new version. Eventually, I am going to change this code to only perform the minification if the css or js files change. The issue with using a random name is that I need to somehow tell Jekyll which files to use. For this, I set a configuration value in the _config.yml file that Jekyll uses. You can see that file below. The version number gets updated every time I build my static content.</p>

<pre><code>markdown: rdiscount
pygments: false
permalink: /:year/:month/:day/:title/
paginate: 5
version: 63301a88-ec4f-4f35-b9a7-7533810aec30
name: Nathan Tottes&amp;#39;s Blog
description: Thoughts and Experiences with Software Development.
url: http://ntotten.com
</code></pre>

<p>Finally, I need to reference this version number in my Jekyll layouts. This is easy and can be seen below.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt;
    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
    &lt;link href='http://fonts.googleapis.com/css?family=Droid+Sans' 
      rel='stylesheet' type='text/css'&gt;
    &lt;link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' 
      rel='stylesheet' type='text/css'&gt;
    &lt;link href='/assets/{{ site.version }}.css' 
      rel='stylesheet' type='text/css'&gt;
</code></pre>

<p>Now when I publish the site to Github pages, Jekyll will use the version number to setup the static content path and my site will be served with the smaller and optimized js and css files. You can see the full <a href="https://github.com/ntotten/ntotten.github.com/blob/master/jakefile.js">jakefile.js</a> in my website's <a href="https://github.com/ntotten/ntotten.github.com/">Github repositoryy</a>.</p>
]]></content:encoded>
      </item>
    
      <item>
        <title>Scaling Out Socket.IO with Windows Azure Service Bus</title>
        
        <description><![CDATA[Build large scale real-time applications with Socket.IO and Windows Azure Services Bus using the Service Bus Store.]]></description>
        
        <pubDate>Fri, 05 Apr 2013 11:41:54 -0700</pubDate>
        <link>http://ntotten.com/2013/04/05/scaling-out-socket-io-with-windows-azure-service-bus/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/04/05/scaling-out-socket-io-with-windows-azure-service-bus/</guid>
        <content:encoded><![CDATA[<p><a href="http://socket.io">Socket.IO</a> is a handy tool that makes it easy to build real-time communication into your application. If you haven't used Socket.IO before, I recommend reading the <a href="http://www.windowsazure.com/en-us/develop/nodejs/tutorials/app-using-socketio/">tutorial over on WindowsAzure.com</a>. This post shows how you can scale out Socket.IO to multiple servers in order to handle many simultaneous connections by using Windows Azure Service Bus as a backing store.</p>

<p>The get started, you will need to create a service bus namespace and subscription. You can do this in the portal by clicking the "New" button and following the steps shown below.</p>

<p><a href="/images/2013/04/createtopic.jpg"><img src="/images/2013/04/createtopic.jpg" alt="createtopic" /></a></p>

<p>After your topic is created, install the socket.io-servicebus module by running npm as shown below.</p>

<pre><code>npm install https://github.com/ntotten/socket.io-servicebus/archive/master.tar.gz
</code></pre>

<blockquote><p><strong>Note</strong>: I am installing <a href="https://github.com/ntotten/socket.io-servicebus">my fork</a> of the <a href="https://github.com/WindowsAzure/socket.io-servicebus">socket.io-servicebus</a> module. The module is also available on npm, but there are updates to this fork for automatically managing subscriptions. These updates will be in the main version shortly. You can see the pull request for my updates <a href="https://github.com/WindowsAzure/socket.io-servicebus/pull/47">here</a>.</p></blockquote>

<p>With the module installed, open up your application. For this demo, I am using an express web app, but you can use whatever frameworks you would like. Configure the service bus store for Socket.IO as shown below.</p>

<pre><code>// Setup the Service Bus store for Socket.IO
var sbstore = require('socket.io-servicebus');
io.configure(function () {
  io.set("transports", ["xhr-polling"]); 
  io.set("polling duration", 30); 
  io.set('store', new sbstore({
    topic: nconf.get("SERVICE_BUS_TOPIC"),
    connectionString: nconf.get("CUSTOMCONNSTR_SERVICEBUS"),
    logger: io.get('logger')
  }));
});
</code></pre>

<p>After you have configured the service bus store you are now ready to scale your application to use as many servers as required. You can download the <a href="https://github.com/WindowsAzure-Samples/node-messageme-servicebus">full source</a> of my sample application on <a href="https://github.com/WindowsAzure-Samples/node-messageme-servicebus">Github</a>.</p>
]]></content:encoded>
      </item>
    
      <item>
        <title>Password Caching when Publishing with Git to Windows Azure Web Sites</title>
        
        <description><![CDATA[If you have setup git publishing on a Windows Azure Web Site you have noticed that our git endpoints use HTTPS rather than SSH. This means that you can't use an SSH key to authenticate and thus you will need to enter your password every time you publish to Windows Azure Web Sites via a git push. The good news is that Github has created a tool that allows credential caching of HTTPS git endpoints. This tool is compatible with both OS X and Windows and is very easy to setup. You can see how to setup Github's...]]></description>
        
        <pubDate>Thu, 04 Apr 2013 11:49:52 -0700</pubDate>
        <link>http://ntotten.com/2013/04/04/password-caching-when-publishing-with-git-to-windows-azure-web-sites/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/04/04/password-caching-when-publishing-with-git-to-windows-azure-web-sites/</guid>
        <content:encoded><![CDATA[<p>If you have <a href="http://www.windowsazure.com/en-us/develop/net/common-tasks/publishing-with-git/">setup git publishing</a> on a <a href="http://www.windowsazure.com/en-us/home/scenarios/web-sites/">Windows Azure Web Site</a> you have noticed that our git endpoints use HTTPS rather than SSH. This means that you can't use an SSH key to authenticate and thus you will need to enter your password every time you publish to Windows Azure Web Sites via a git push. The good news is that Github has created a tool that allows credential caching of HTTPS git endpoints. This tool is compatible with both OS X and Windows and is very easy to setup.</p>

<p>You can see how to setup Github's password caching tool on their <a href="https://help.github.com/articles/set-up-git#password-caching">help documentation here</a>. As their documentation mentions, you do need to ensure you are running Git version 1.7.0 or above.</p>

<p>You can see that after the password helper is setup we are prompted for credentials on the first commit, but on subsequent commits our cached credentials are used automatically.</p>

<p><strong>First Push</strong>
<a href="/images/2013/04/push1.png"><img src="/images/2013/04/push1.png" alt="push1" /></a></p>

<p><strong>Second Push</strong>
<a href="/images/2013/04/push2.png"><img src="/images/2013/04/push2.png" alt="push2" /></a></p>

<p>Hopefully that helps save a little time when developing on Windows Azure.</p>
]]></content:encoded>
      </item>
    
      <item>
        <title>Sample Code for Node.js and MongoDB Task List App on Windows Azure</title>
        
        <description><![CDATA[Sample Code for Node.js and MongoDB Task List App on Windows Azure

You can now find the source for the "Create a Node.js Application on Windows Azure with MongoDB" tutorial on Github. This application is a simple task list app written in Node.js that uses Mongoose to store data in MongoDB.
]]></description>
        
        <pubDate>Tue, 02 Apr 2013 13:42:54 -0700</pubDate>
        <link>http://ntotten.com/2013/04/02/sample-code-for-node-js-and-mongodb-task-list-app-on-windows-azure/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/04/02/sample-code-for-node-js-and-mongodb-task-list-app-on-windows-azure/</guid>
        <content:encoded><![CDATA[<p><a href="https://github.com/WindowsAzure-Samples/node-websites-tasklist-mongodb">Sample Code for Node.js and MongoDB Task List App on Windows Azure</a></p>

<p>You can now find the source for the "<a href="http://www.windowsazure.com/en-us/develop/nodejs/tutorials/website-with-mongodb-mongolab/">Create a Node.js Application on Windows Azure with MongoDB</a>" tutorial on Github. This application is a simple task list app written in Node.js that uses Mongoose to store data in MongoDB.</p>
]]></content:encoded>
      </item>
    
      <item>
        <title>Rebuild "Open With" Menu on OS X</title>
        
        <description><![CDATA[I often find the "Open With" menu on OS X gets cluttered with old apps and duplicates of existing apps like Sublime Text. This command will rebuild the menu items.

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user;killall Finder;

]]></description>
        
        <pubDate>Wed, 20 Mar 2013 20:46:38 -0700</pubDate>
        <link>http://ntotten.com/2013/03/20/rebuild-open-with-menu-on-os-x/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/03/20/rebuild-open-with-menu-on-os-x/</guid>
        <content:encoded><![CDATA[<p>I often find the "Open With" menu on OS X gets cluttered with old apps and duplicates of existing apps like Sublime Text. This command will rebuild the menu items.</p>

<pre><code>/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user;killall Finder;
</code></pre>
]]></content:encoded>
      </item>
    
      <item>
        <title>Using Windows Azure Mobile Services with the Facebook SDK for Windows Phone</title>
        
        <description><![CDATA[As you may have seen, Windows Azure Mobile Services makes it super easy to add a cloud backend to your mobile apps. Mobile Services also supports authentication with OAuth providers like Facebook, Microsoft, and Twitter. I have had people ask me if it is possible to use Mobile Services with the Facebook SDK for .NET (formally named the Facebook C# SDK). In short, yes. Authenticating with Facebook Since our app is going to be authentication with Facebook we will likely want to ask the user for additional Facebook permissions such as posting to a wall or reading additional friend...]]></description>
        
        <pubDate>Thu, 14 Mar 2013 14:10:19 -0700</pubDate>
        <link>http://ntotten.com/2013/03/14/using-windows-azure-mobile-services-with-the-facebook-sdk-for-windows-phone/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/03/14/using-windows-azure-mobile-services-with-the-facebook-sdk-for-windows-phone/</guid>
        <content:encoded><![CDATA[<p>As you may have seen, <a href="http://www.windowsazure.com/en-us/home/scenarios/mobile-services/">Windows Azure Mobile Services</a> makes it super easy to add a cloud backend to your mobile apps. Mobile Services also supports authentication with OAuth providers like Facebook, Microsoft, and Twitter. I have had people ask me if it is possible to use Mobile Services with the <a href="https://github.com/facebook-csharp-sdk/facebook-csharp-sdk">Facebook SDK for .NET</a> (formally named the Facebook C# SDK). In short, yes.</p>

<h1>Authenticating with Facebook</h1>

<p>Since our app is going to be authentication with Facebook we will likely want to ask the user for additional Facebook permissions such as posting to a wall or reading additional friend data. This currently isn't supported in the Mobile Services SDK. So the first thing we need to do is change how the initial authentication is performed. To this we are going to use the <a href="https://github.com/facebook-csharp-sdk/facebook-winclient-sdk">Facebook SDK for Windows Phone</a>. The Facebook SDK for Windows Phone is a layer on top of the <a href="https://github.com/facebook-csharp-sdk/facebook-csharp-sdk">Facebook SDK for .NET</a> that helps with authentication and other phone specific scenarios.****</p>

<blockquote><p><strong>Warning:</strong> The Facebook SDK for Windows Phone is currently in alpha so things will change and break as we move toward version 1.0.0.</p></blockquote>

<p>Starting with our default Mobile Services implementation of authentication as show in <a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-users-dotnet/">this tutorial</a> we need to make a few minor changes.</p>

<p>First, we need to install the Facebook SDK for Windows Phone. To do this use NuGet. Since the package is pre-release you will need to use the Nuget console.</p>

<pre><code>Install-Package Facebook.Client -pre
</code></pre>

<p>Next, add a static property for <a href="https://github.com/facebook-csharp-sdk/facebook-winclient-sdk/blob/master/Source/Facebook.Client/FacebookSessionClient.cs">FacebookSessionClient</a> to the App.xaml.cs file. You can add this property right above the MobileServiceClient property.</p>

<pre><code>public static FacebookSessionClient FacebookSessionClient = 
    new FacebookSessionClient("[facebookAppId]");
public static MobileServiceClient MobileService = new MobileServiceClient(
    "https://[namespace].azure-mobile.net/",
    "[applicationKey]"
    );
</code></pre>

<p>Next, we will make a few changes to our authentication method in MainPage.xaml.cs as shown below.</p>

<pre><code>private FacebookSession fbSession;
private MobileServiceUser user;
private async System.Threading.Tasks.Task Authenticate()
{
    while (fbSession == null)
    {
        string message;
        try
        {
            fbSession = await App.FacebookSessionClient
                .LoginAsync("email,publish_stream,friends_about_me");
            var client = new FacebookClient(fbSession.AccessToken);
            var token = JObject.FromObject(new
            {
                access_token = fbSession.AccessToken,
            });
            user = await App.MobileService
                .LoginAsync(MobileServiceAuthenticationProvider.Facebook, token);
            message =
                string.Format("You are now logged in - {0}", user.UserId);
        }
        catch (InvalidOperationException)
        {
            message = "You must log in. Login Required";
        }


        MessageBox.Show(message);
    }
}
</code></pre>

<p>As you can see, we are now using the FacebookSessionClient to perform the OAuth with Facebook. After the user authorizes the app with Facebook we then create a JToken object containing the Facebook Access Token and pass it to the MobileServiceClient's LogingAsync method. Mobile Services then makes a request to the Mobile Services REST API. On the server a new user is created and a Mobile Services authentication token is created. This token is returned to the client. Now the client is authenticated with both Facebook and Mobile Services.</p>

<p>Also, notice that the FacebookSessionClient's LoginAsync method allows us to pass in a string of permissions to request. In this case we are requesting the email, publish_stream, and friends_about_me permissions. You can change this list accordingly based on the needs of your app.</p>

<h1>Using the Facebook Graph API</h1>

<p>Now that we are authenticated and have a Facebook access token we can perform requests on the Facebook Graph API using the Facebook SDK for Windows Phone. In this case I am going to request a list of friends including their "About Me" details as we have the "friends_about_me" permission.</p>

<p>To get the Facebook access token simply access the AccessToken property on the FacebookSession object which we have in our app at fbSession. You can see below how you can make this Graph API request using the <a href="https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/blob/master/Source/Facebook/FacebookClient.cs">FacebookClient</a> object.</p>

<pre><code>private async Task GraphRequest()
{
    var client = new FacebookClient(fbSession.AccessToken);
    dynamic friends = await client.GetTaskAsync("me/friends");
    foreach (dynamic friend in friends.data)
    {
        string about = friend.about;
    }
}
</code></pre>

<p>Now you are free to interact with both the Facebook Graph API and the Mobile Services API as an authenticated user. You could also use the Facebook SDK for Windows Phone to request additional permissions if your application requires them.</p>
]]></content:encoded>
      </item>
    
      <item>
        <title>Building Amazing Apps with the ASP.NET EmberJS Template</title>
        
        <description><![CDATA[I have been using EmberJS for a while so I was pretty excited to work on the new EmberJS template for ASP.NET. If you are not familiar with EmberJS, I highly recommend reading through their documentation. In short though, ember is a framework for building client-side browser apps. Ember solves the same sort of problems as frameworks like BackboneJS and KnockoutJS. Personally, I prefer ember over these other frameworks as I have felt more productive with ember. Ember is very convention based, and once you learn those conventions you will find yourself able to build a...]]></description>
        
        <pubDate>Tue, 19 Feb 2013 09:57:14 -0800</pubDate>
        <link>http://ntotten.com/2013/02/19/building-amazing-apps-with-the-asp-net-emberjs-template/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/02/19/building-amazing-apps-with-the-asp-net-emberjs-template/</guid>
        <content:encoded><![CDATA[<p>I have been using <a href="http://emberjs.com">EmberJS</a> for a while so I was pretty excited to work on the <a href="http://www.asp.net/single-page-application/overview/templates/emberjs-template">new EmberJS template for ASP.NET</a>. If you are not familiar with EmberJS, I highly recommend reading through their <a href="http://emberjs.com/guides/">documentation</a>. In short though, ember is a framework for building client-side browser apps. Ember solves the same sort of problems as frameworks like <a href="http://backbonejs.org/">BackboneJS</a> and <a href="http://knockoutjs.com/">KnockoutJS</a>. Personally, I prefer ember over these other frameworks as I have felt more productive with ember. Ember is very convention based, and once you learn those conventions you will find yourself able to build a lot of software very quickly.</p>

<p>If you are interested in more in depth look at this template, I definitely recommend reading <a href="http://www.asp.net/single-page-application/overview/templates/emberjs-template">the article</a> written by Xinyang Qui who is the lead developer for this template. His article explains the components of the template, how the client-side app interacts with WebAPIs, and more. For this post, I want to show you some of the cool features of the template and how it can help you build amazing web apps.</p>

<h1>Super Fast and Fluid</h1>

<p>Ember makes it easy to build apps that are extremely responsive and will provide your users with a great experience. Head over to the <a href="http://ember.azurewebsites.net">deployed version</a> of this template and click between the different views on the site. You will notice how fast the views load. This is because nearly everything  used to render the views is loaded on the first page load. Subsequent interactions with the app are fast and fluid.</p>

<p><a href="/images/2013/02/clicks.gif"><img src="/images/2013/02/clicks.gif" alt="clicks" /></a></p>

<h1>Bundles and Minification for Performance</h1>

<p>This template uses ASP.NET bundling and minification to decrease the file size and number of requests required to load your application. This is important for any web app, but even more so with a client-side app as you are likely to have hundreds of individual Javascript files as part of your completed project.</p>

<pre><code>bundles.Add(new ScriptBundle("~/bundles/app").Include(
      "~/Scripts/app/app.js",
      "~/Scripts/app/router.js",
      "~/Scripts/app/helpers.js")
      .IncludeDirectory("~/Scripts/app/routes", "*.js")
      .IncludeDirectory("~/Scripts/app/models", "*.js")
      .IncludeDirectory("~/Scripts/app/views", "*.js")
      .IncludeDirectory("~/Scripts/app/controllers", "*.js"));
</code></pre>

<h1>Packaging of Templates</h1>

<p>Managing EmberJS templates can be tricky. Your production site should include all of the templates  in a single file or with the html page to decrease the number of requests you app makes. There are a number of strategies for packaging your templates, but we have made this process super simple with the Ember template. The template includes a helper method that renders all templates that are included in the templates folder. This means you don't need to worry about a build process that combines these files. Additionally, when you are writing your templates Visual Studio also now includes syntax highlighting for the Mustache syntax so your code looks great even inside script tags.</p>

<p><a href="/images/2013/02/template.jpg"><img src="/images/2013/02/template.jpg" alt="template" /></a></p>

<h1>Adding a New View</h1>

<p>Now that we have seen some of the cool features from the EmberJS template lets look at customizing this template. The first thing we will do is add a new view to the app. You will see how EmberJS makes this process extremely easy.</p>

<p>First, create a new template file called firstTemplate.html. You can use the code below for the body of the view.</p>

<pre><code>&lt;script type="text/x-handlebars" data-template-name="first"&gt;
    &lt;h1&gt;My First Template&lt;/h1&gt;
&lt;/script&gt;
</code></pre>

<p>Now to wire this up the only change you need to make is to add the route. Open the router.js file in the /Scripts/app folder. Add a new route as shown below.</p>

<pre><code>App.Router.map(function () {
    this.route("index", { path: "/" });
    this.route("about");
    this.route("todoList", { path: "/todo" });
    this.route("first"); // New Route
});
</code></pre>

<p>That is everything required to create a new view. Navigate to <a href="http://localhost:PORT/#/first">http://localhost:PORT/#/first</a> and you will see your view. Its that simple!</p>

<h1>Linking to a View</h1>

<p>Now that we have added a new view to the application we need to link to it. This is done using a special mustache helper that is part of Ember. Open the applicationTemplate.html file in the templates folder. You will see the existing links in the <nav> element. Add a new link to the first view as shown below.</p>

<pre><code>&lt;nav&gt;
  {{#linkTo "index"}}Home{{/linkTo}}
  {{#linkTo "about"}}About{{/linkTo}}
  {{#linkTo "todoList"}}Todo{{/linkTo}}
  {{#linkTo "first"}}First{{/linkTo}} &lt;!-- New Link --&gt;
&lt;/nav&gt;
</code></pre>

<h1>Handling Events</h1>

<p>The final thing I want to show in this post is how you can handle an event from an ember view. For our app lets just add a simple sub-view that handles the click event. To do this add the code shown below to the firstTemplate.html that you created earlier.</p>

<pre><code>&lt;script type="text/x-handlebars" data-template-name="first"&gt;
    &lt;h1&gt;My First Template&lt;/h1&gt;
    {{#view App.ClickableView}}
        This is a clickable area!
    {{/view}}
&lt;/script&gt;
</code></pre>

<p>Now we need a view object to actually handle this event. Create a file called FirstView.js in the Scripts/app/views folder. Because we are using bundles, this script file will be automatically referenced in our App.cshtml page. Add the following code to the FirstView.js file.</p>

<pre><code>App.ClickableView = Ember.View.extend({
  click: function(evt) {
    alert("ClickableView was clicked!");
  }
});
</code></pre>

<p>That's all there is to handling events.</p>

<h1>Conclusion</h1>

<p>Hopefully this post showed you a few of the reasons why EmberJS and the new ASP.NET SPA template are so cool. I will be blogging more about ember in the coming weeks so stay tuned. Additionally, this release of the template is just our first so <a href="http://twitter.com/ntotten">let me know</a> if you have any feedback or suggestions. We definitely want to keep improving the template.</p>
]]></content:encoded>
      </item>
    
      <item>
        <title>Useful Error Messages for Node.js Apps on Windows Azure Web Sites</title>
        
        <description><![CDATA[I deployed a simple node.js app to Windows Azure Web Sites today and noticed something new (or at least that I haven't payed attention to before). If there is an error starting your Node.js app the last 64k of the output generated by the node.exe process to stderr is shown on the error page. This makes discovering little things like forgetting to add a module to the package.json file much easier. You can see my error below.


]]></description>
        
        <pubDate>Sun, 10 Feb 2013 11:41:51 -0800</pubDate>
        <link>http://ntotten.com/2013/02/10/useful-error-messages-for-node-js-apps-on-windows-azure-web-sites/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/02/10/useful-error-messages-for-node-js-apps-on-windows-azure-web-sites/</guid>
        <content:encoded><![CDATA[<p>I deployed a simple node.js app to Windows Azure Web Sites today and noticed something new (or at least that I haven't payed attention to before). If there is an error starting your Node.js app the last 64k of the output generated by the node.exe process to stderr is shown on the error page. This makes discovering little things like forgetting to add a module to the package.json file much easier. You can see my error below.</p>

<p><a href="/images/2013/02/screen-shot-2013-02-10-at-2-39-03-pm.png"><img src="/images/2013/02/screen-shot-2013-02-10-at-2-39-03-pm.png" alt="IIS Node Error" /></a></p>
]]></content:encoded>
      </item>
    
      <item>
        <title>Implementing a Simple Registration Code Check in ASP.NET MVC</title>
        
        <description><![CDATA[I was building a simple web app a few days ago and needed a way to control who could register to use the site. I didn't really want to build a fancy invitation system nor did I want to add all of the user accounts manually. I solved this problem by creating a very simple registration code mechanism that would check if a user provided the valid code when registering either the traditional way (username and password) or when logging in with their Facebook or other OAuth account. The result is a simple check that lets...]]></description>
        
        <pubDate>Thu, 24 Jan 2013 13:37:41 -0800</pubDate>
        <link>http://ntotten.com/2013/01/24/implementing-a-simple-registration-code-check-in-asp-net-mvc/</link>
        <guid isPermaLink="true">http://ntotten.com/2013/01/24/implementing-a-simple-registration-code-check-in-asp-net-mvc/</guid>
        <content:encoded><![CDATA[<p>I was building a simple web app a few days ago and needed a way to control who could register to use the site. I didn't really want to build a fancy invitation system nor did I want to add all of the user accounts manually. I solved this problem by creating a very simple registration code mechanism that would check if a user provided the valid code when registering either the traditional way (username and password) or when logging in with their Facebook or other OAuth account.</p>

<p><a href="/images/2013/01/registrationcode1.png"><img src="/images/2013/01/registrationcode1.png" alt="registrationcode" /></a>The result is a simple check that lets me control who is allowed to register to use my site. Obviously this isn't foolproof and I have to trust my friends not to share the registration code, but this is a good enough solution for what I am building.</p>

<p>Below you will see how to add this simple check to your application with just a few lines of code.</p>

<p>To handle the actual validation I am going to use <a href="http://www.asp.net/mvc/tutorials/older-versions/models-(data">data annotations</a>/validation-with-the-data-annotation-validators-cs). This way, the places in my application that already check for a valid state will continue to operate without modification. This simply adds another check. This means I can implement this without touching a line of code in my AccountController. The first thing we need to do is create our validator. This simple validator will check the registration code that is provided with a registration code stored in my AppSettings.</p>

<pre><code>public class ValidRegistrationCodeAttribute : ValidationAttribute
{

    public ValidRegistrationCodeAttribute()
    {
        this.ErrorMessage = "Invalid registration code.";
    }

    public override bool IsValid(object value)
    {
        if (value == null) return false;
        // In this example, I am storing my registration code in the web.conf file. 
        // You can store the code however you like including web.config or a database.
        var validCode = ConfigurationManager.AppSettings["RegistrationCode"];
        return validCode.Equals(value.ToString());
    }

}
</code></pre>

<p>Next, add the RegistrationCode property to the RegisterExternalLoginModel and RegisterModel classes found in Models/AccountModels.cs. Include the ValidRegistratoinCode and other attributes as well.</p>

<p>RegisterModel.cs:</p>

<pre><code>public class RegisterModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [ValidRegistrationCode]
    [Display(Name = "Registration Code")]
    public string RegistrationCode { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}
</code></pre>

<p>RegisterExternalLoginModel.cs:</p>

<pre><code>public class RegisterExternalLoginModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [ValidRegistrationCode]
    [Display(Name = "Registration Code")]
    public string RegistrationCode { get; set; }

    public string ExternalLoginData { get; set; }
}
</code></pre>

<p>This is everything that needs to be done from a code prospective. The last changes are just to add the registration code field to our registration views. You will need to modify two views. The first is the Account/Register.cshtml view. Add the lines for the RegistrationCode directly below the Username code as show below.</p>

<pre><code>&lt;li&gt;
    @Html.LabelFor(m =&gt; m.UserName)
    @Html.TextBoxFor(m =&gt; m.UserName)
&lt;/li&gt;
&lt;li&gt;
    @Html.LabelFor(m =&gt; m.RegistrationCode)
    @Html.TextBoxFor(m =&gt; m.RegistrationCode)
&lt;/li&gt;
&lt;li&gt;
    @Html.LabelFor(m =&gt; m.Password)
    @Html.PasswordFor(m =&gt; m.Password)
&lt;/li&gt;
</code></pre>

<p>Next, add the lines for the RegistrationCode directly below the Username code in the Account/ExternalLoginConfirmation.cshtml view as shown.</p>

<pre><code>&lt;li class="name"&gt;
    @Html.LabelFor(m =&gt; m.UserName)
    @Html.TextBoxFor(m =&gt; m.UserName)
    @Html.ValidationMessageFor(m =&gt; m.UserName)
&lt;/li&gt;
&lt;li class="name"&gt;
    @Html.LabelFor(m =&gt; m.RegistrationCode)
    @Html.TextBoxFor(m =&gt; m.RegistrationCode)
    @Html.ValidationMessageFor(m =&gt; m.RegistrationCode)
&lt;/li&gt;
</code></pre>

<p>That's it. Now anyone trying to register on the site will be required to provide the registration code.</p>
]]></content:encoded>
      </item>
    
  </channel>
</rss>
