I recently teamed up with Ryan Carson, Keir Whitaker and Mike Kus from Carsonified to write an application called 'Hello', with the catchy tagline "Turn to your neighbour and say...", geddit?! The motivation behind the project was to write something within a tight timescale that used a complete Microsoft stack, capped by ASP.NET MVC, and I thought that some of my experiences might be interesting to other people. This post will be the first in a series that will hopefully cover the techy side as well as the 'managerial' / logistical aspects. I'll give an initial overview of the project and its component parts, with some code thrown in to whet your appetite.
Overview
Hello helps you to meet interesting people at FOWA London. You can say where you're sitting, earn points, badges and post messages to the whole audience.
As the description on Hello's front page says. The basic idea is that it is an app to encourage social interaction at events, namely FOWA London. Unusually, all input in to the app comes from Twitter, so the architecture looks something like this:

The arrows show the flow of information - the arrow from the User to Twitter represents the flow of information from the user to Twitter by means of tweeting (unsurprisingly). To give you an example of how this works, if you wanted to join in with this Hello thing you could send a tweet that looked something like:
@HelloApp hello !dev #csharp #aspnetmvc #jquery
This would sign you up for Hello with a category of Developer, and then the hashtags that describe you. Hello gets really interesting on Conference Day when you're able to tweet messages saying where you're sitting, who you've met, tokens you've found or been given, and so on. And why would you want to do all these things? To win points of course - each action has an associated number of points. And why do you want points? Well because the more points you have then, clearly, the cooler you are. Not only do you look cool though, but you can then also tweet your own personal message and get it seen on the conference home page. A perfect opportunity to let people know you're hiring, or advertise your latest startup. Now that we know the users categories, hashtags and where they're sitting, you can then browse the seating chart and see who is sitting around you, what their interests are, and whether you have anything in common. You can also search the audience for specific names or skillsets (php, designer, CSS3, etc). Simple, but fun.
But how does all this work?
The Bot - Getting tweets from twitter
There are a couple of APIs out there for accessing Twitter from .NET code; I went with TweetSharp, which has a fluent API; the code for grabbing all the mentions of a particular username looks like this:
var tweets = FluentTwitter
.CreateRequest()
.AuthenticateAs(
Settings.TwitterBotUsername,
Settings.TwitterBotPassword)
.Statuses()
.Mentions()
.Request()
.AsStatuses();
Pretty straight forward.
Those tweets are then queued and processed, using the repo for storage...
The Repo - LINQ to SQL
We used LINQ to SQL for the backend, I love it for its simplicity and ease of use. We knew from the outset that we weren't going to have a hugely complex schema, so some of the weaknesses of LINQ to SQL wouldn't be a problem. After creating the database in SSMS, I switched over to Visual Studio and dragged the tables from the Server Explorer on to the Object Relational Designer. This generated all the domain objects for my application. The real highlight for me is that I don't have to mess around with SqlCommands or SqlDataReaders anymore. I love what you get, pretty much, for free, for example:
var messages = _repo
.Messages
.Where(m => !m.Offensive
&& m.User.Points.Sum(p => p.Amount) > Settings.Thresholds.Silver)
.OrderBy(m => (m.User.Created.Millisecond * randomOffset) % 1000)
.Take(Settings.MaxMessages);
Sweet, huh?!
The Web App - Intro to ASP.NET MVC
For the web portion of the project we used the latest iteration of Microsoft's web framework, ASP.NET MVC. For anyone keen to know more, there are lots of introductions to ASP.NET MVC out there on the web. To get up and running we used the Web Platform Installer, which makes the install process real easy. Mike, the designer working on the project, put together some awesome designs for the main pages of the site; the front page, search, and the conference day page. They looked something like this:

I then translated these to view pages, and MVC makes this really simple as you don't have to fight against the HTML produced server controls. Although the responsibility of writing more HTML by hand can be a higher initial overhead, the long term gain of tight control over your markup is well worth it. Specifically, this is what goes in:
<% foreach (var message in (IQueryable<Message>)ViewData["Messages"]) { %>
<div class="message">
<blockquote><p>"<%= message.Text %>"</p></blockquote>
<p class="author">
By @<a href="http://twitter.com/<%= message.Username %>">
<%= message.Username %></a>
</p>
</div><!-- /.message -->
<% } %>
And the output...
<div class="message">
<blockquote><p>"Ben's message is cool!"</p></blockquote>
<p class="author">
By @<a href="http://twitter.com/benadderson">
benadderson</a>
</p>
</div><!-- /.message -->
<div class="message">
<blockquote><p>"Business is booming and we're hiring. Whoop whoop!"
</p></blockquote>
<p class="author">
By @<a href="http://twitter.com/thatismatt">
thatismatt</a>
</p>
</div><!-- /.message -->
Lovely, clean HTML that exactly matches what I was given by Mike. Gone are the days when you have to convince your designer that he can't use a div with that class there because you're using an ASP GridPanel.
The added flexibility in the View code does give you more power and, as we all know, "With great power comes great responsibility". But seriously, you do have to watch that you don't tie yourself in knots with too much code in your view.
Wrap up
I found the project really interesting, and working with ASP.NET MVC is such a joy coming from Web Forms, and has pacified my framework envy of such creations as Django and Rails. The Twitter integration was also challenging, and taught me a lot about writing applications with dependencies on external services. And the fact that the project was all written on such a tight schedule meant it had such a different feel to the line-of-business projects I'm normally on. I’ll pull out a bit more detail on a few of these topics in the next few posts, but leave a comment if there’s anything specific you’re interested in.