Microsoft of the Future is Now

Last weekend my friends from Three Red Cubes Inc. and I were at NBTC. A detailing of the event itself deserves a post, but this post is based on a conversation I had with the CEO of a pretty cool and successful Toronto-based start-up developing software as services using Java-based web-frameworks.

As most of my conversations do, the question came to, “Why do you, as a start-up, use .Net?”

In most people’s perspective, Microsoft’s technologies are confined to being used in the cubicles of high-rise corporate buildings. Images of Windows 98 and XP flash through their minds when you say Microsoft. If you identify yourself as a .Net developer, they look confused, wondering why you don’t look like a nerd or surprised that you are having a conversation, in-person. They probably think you should look a lot like this guy.

Not an image start-ups should associate with. Not one bit.

The new face of Microsoft is not represented by their past image, but it’s not determining the future. The future of Microsoft is being determined right now.

Embracing Open-Source

A few hours before I started writing this, it was announced that ASP.Net MVC 4 and several related technologies are being made available as open-source projects, accepting contributions from the community. That’s massive because ASP.Net MVC is Microsoft’s flagship web-framework of the future. If this is the attitude towards ASP.Net MVC, I can’t wait to see what’s in store.

This is not the first time of course, there has been many more initiatives from Microsoft which are all enumerated at Microsoft Openness. As this push continues, I believe we will see CodePlex and Nuget take centre stage. These are two amazing platforms where open-source is very alive.

Now, there are a lot of conspiracy theories around the reasons behind Microsoft’s push towards open-source. For me, as long as I have personally seen initiatives such as Web Not War in action and as long as the community is being nurtured, I’m good.

Unifying Experiences

Having heard it from Eric Gales at NBTC, I can say that Microsoft’s realization that all technology should be unified is comforting.

Technology-wise, everything is being brought under one umbrella, which is great! Specially as a young developer, I can learn everything I wish to on the .Net web-stack and then transfer these skills to say, game development. And this is not just theory, I am a web-developer by birth but with the guys at Three Red Cubes I’ve worked on more than one game. It’s made possibly by how well the entire collection of frameworks and tools are integrated. They say Visual Studio spoils you, it’s true.

For consumers, learning to use Word or Excel means having learnt to use Office365 or SkyDrive because they all provide an unified experience. This is the case for Windows Phone, XBox and the up-coming Windows 8. They all speak the same user-experience language so we’re always at home.

Engaging Students

From my experience as a student, there is no other company that I know of that puts in so much effort to reach students. Microsoft has teams of amazing people dedicated to running programs for us students. The Dreamspark program is just one of many programs that make software worth thousands of dollars available to us students.

This is to Microsoft’s advantage of course. Students are going to continue on to become developers, consumers and influence the course of  technology and businesses.

Inspiring the Future

Part of building a future is tackling the problems of the present. Imagine Cup is yet another way for Microsoft to encourage students to use their technologies. This time, to change the world and to solve problems experienced by thousands if not millions over the world. Big words? Not at all, this has been the culture of Imagine Cup, see for yourself.

To arrive at anything remotely close to its vision, a world interconnected via technology and the cloud, Microsoft has to work tremendously hard. Maybe five years is a tall order but with all that it is doing, Windows 8, Windows Azure, and .Net technologies, powering forward to a super sleek future is only but a matter of time.

As a start-up, the image we associate with is open-minded, community-involving, forward-thinking and technologically savvy. And this is the kind of future that seems to be in the making for Microsoft. Being as smart as we are, Three Red Cubes jumped on board pretty early. This can only end well.


Building Laaalallaaa Share

My tally for Windows Phone 7 applications isn’t too high. Not compared to some of my friends at Three Red Cubes. In my defense though, I’ve been working on several MVC projects that are pure fun to work with. But to close the gap, I got down and dirty and wrote Laaalallaaa Share (♫share).

The application is really simple but it uses a very interesting .Net namespace Microsoft.Xna.Framework.Media and some classes from Microsoft.Phone.Tasks.

MediaPlayer

This static class exposes a number of methods and properties to access the media player (duh!) and the library.

For example I used the properties in MediaPlayer.Queue.ActiveSong to find the details of the current song being played. MediaPlayer.State holds the status of the media player, use it to find the state of the player.

This class also exposes a number of events such as ActiveSongChanged or MediaStateChanged that lets the application know if the current song has changed or if the song has stopped/started playing. Handy stuff.

MediaPlayerLauncher

Launchers and Choosers in the Windows Phone world give us developers access to a number of operating system and user functionalities.

The MediaPlayerLauncher is used to “start the media player and play the media file you specify.” But you don’t necessarily have to play a file, you can just take the user to the music player, like I did. Read more about this class.

ShareStatusTask

As of Windows Phone 7 Mango (Windows Phone OS 7.1), this class exists in the Microsoft.Phone.Tasks namespace. This class launches “a dialog that enables the user to share a status message on the social networks of their choice.”

By setting the Status property and calling Show you could get to the People Hub’s “Post a Message” page and let the user post away. Read more about how to use this task.

There you are, three nifty little classes that do really cool things that I hope you’ll use in your next application. Say… when you sign up for The Developer Movement and win a bunch of expensive cool gadets or Imagine Cup and win a lot of money!


ASP.Net MVC Walkthrough – Gears of Web

There so many great resources for learning ASP.Net MVC out there, especially on Scott Guthrie’s blog. I found that the approach taken by most bloggers in their tutorials involves writing a project, while it is a great way to get the some hands-on experience, it can be overwhelming to first understand the context of the project and then how the MVC framework handles the project.

In this walkthrough series, I will go through the beautiful ASP.Net MVC framework and attempt to explain its many cogs that interact to build powerful web applications. I won’t be going in to any projects that involve restaurants or nerds.

First let’s get the gears of war err… web.

Visual Studio 2010

You might have heard of it, it’s this amazing IDE we .Net-ers use. VS2010, like its predecessors comes in many editions. The VS2010 Express Edition is free and pretty sweet. Also, if you’re a student, don’t read any further and head over to DreamSpark and get yourself a fresh VS2010 Professional Edition. Yeah, pretty sweeter!

Web Platform Installer

This is something you might not have heard of. Using Web Platform Installer Microsoft distributes all its web components to us developers. It’s got everything. Get it. Now.

Nuget

I have nothing else to say to you if you have not installed Nuget. It’s the one tool that every .Net developer needs besides Visual Studio. With it, you’ll be able to download from a plethora of community powered tools and projects that will make life and working with MVC a breeze.

Everything else

From here on, installing ASP.Net MVC 3 and updates for Visual Studio should be an easy exploration. Hint: Web PI. In my next post, I’ll write about all the basics and background to MVC. Stay tuned!

This post also appeared on the Go DevMENTAL blog.


ASP.Net MVC Walkthrough Series

In this walkthrough series, I go through the beautiful ASP.Net MVC framework and attempt to explain its many cogs that interact to build powerful web applications without going in to any projects that involve restaurants or nerds.

1. Gears of Web


Care Presentation at DevCamp Recap

DevCamp Toronto was a lot of fun with awesome speakers. Looking forward to more events from Make Web Not War, it’s a great place for open source and community talks. Loads to learn and enjoy!

To prepare for the presentation I had written up the gist of my presentation… and here it is with the slides!

Slides

Transcript

Slide 1

I’m going to talk about Care, a cloud powered
application to help empower patients to take
an active role in their healthcare. I am also
going to talk about why and how we took Care
to the cloud. And of course I’ll talk about the technologies
involved.

Slide 2

Every idea spawns from some needs and the need for our application was brought into attention at Code Your Art Out in the summer. Now what are the needs?

Almost 80% of Ontarians over the age of 45 have a chronic condition but the time of healthcare professionals is limited so many have to manage their own conditions. The time between appointments for patients is usually long causing lack of communication and miscommunication of patients’ symptoms.

The adoptation of technologies is slow, in the healthcare industry at least, and it’s understandable, typical healthcare applications will cost about $30,000 in infrustructure and IT. Especially if you are focusing on non-profits, as we are, it is so expensive for them, deploying applications to solve problems become an impossible task for them.

Slide 3

To tackles these needs Care exists. Unlike most healthcare applications its aim is to solve a small and realistic problem.
In its core, it is a personal symptom management tool. It provides guided forms to record symptoms and create reports out of them. It’s a powerful yet simple way of involving patients in their care, also of providing healthcare professionals more accurate information about their patients and their symptoms. And how we involve our partners is by making
Care a family and group focused application so that patients can share this information with the people helping them through their conditions.

Slide 4

That just solves one part of the problem, connecting patients to their professionals. To solve the problem of lacking infrustructure we picked the cloud. By hosting applications on the cloud we’ll be saving thousands on infrustructure, IT and utilities. It provides for a secure hosting environment with amazing fault tolerance. As developers we have access to utility style software services with greater performance and features, something we can provide to our partners. And as
developers we get greater control over our software features and versions preventing fragmentations and giving us access in case some nasty bugs creep in.

Slide 5

Now what are the tools we used to build Care and how are the feasible for our non-profit partners?
Microsoft Windows Azure with its utility style platform, it’s cost effective for us to develop
using the technologies we want. We mainly a .Net firm so we love using ASP.Net MVC, it you’re
familiar with the MVC architecture, you’ll know that it’s a beautiful framework to work with.
For our ORM we use Entity Framework Code First which plays nicely with both MSSQL and MySql so we
can deploy which ever suits our partners’ needs. For the UI we leverage open source frameworks Blueprint, jQuery UI, Mobile. All of this is served through Nuget, my personal favorite to explore and find open source tools
to use.

Slide 6

Care wouldn’t be what it is without the support of its partners in Colorectal Cancer Association of Canada
and Hope and Cope working out of Montreal. We also need you to partner with us to
bring Care to patients who need it. We are also would love to connect with you and
hear about your ideas and experiences. You’ll find our company and myself on these Twitter handles.


1Transit for them All (Exclusively for WP7)

A few days ago we released 1Transit. Softly. It is an exclusive Windows Phone 7 transit application that is a bundle of simple but robust and hopefully useful features.

Features Like

The application serves data for over 20 transit agencies across North America. Yes, built for travel.

We wanted you to be able to find things fast. Thus, the searching is fast. Something we like to showoff to our friends.

No your eyes do not fool you. Those are live updates that you can receive for transit stops around you. We implemented a bookmarking (aka pinning in the Windows world) feature too, so that you can get these updates with only a touch.

Not impressed? Try it for yourself and maybe you will be. Fingers crossed.

Coming Soon

We have put much weight behind this application and we’ll be building on the current version. In the coming updates we are looking to,

  • Utilize location to enrich the experience,
  • Provide schedules and maps of routes,
  • Implement live updates of vehicle locations,
  • Add support for more agencies.

Coming Sooner

Yes, 1Transit is exclusive for WP7 but we have been working on a version for our fellow smartphone users on Android and iOS. Stay tuned for that.


Say Hello to Project jQMvc

After my previous post about jQuery Mobile and ASP.Net MVC, I found myself using jQM in a project. Now, it would be a shame if I didn’t share the goodies I built for MVC with jQM.

So, I give you Project jQMvc. Really, it’s a collection of HTMLHelper extensions that build on jQM. With jQMvc you’ll be able to build full HTML5 compatible and mobile ready views but with the lovely MVC behind it at all times. Let me show you some of the things it can do.

Lists, a lot of them

In the project there a several types of lists, with and without searching. Thanks to jQM, it’s a treat! And really useful.

The below code,

@using jQM
@model IEnumerable

@{
    ViewBag.Title = "Unordered List With Search";
}

@Html.UnorderedListWithSearchFilter(Model)

And a little bit of sauce from the controller will give you,

jQMvc List with Search Preview

Buttons, all sorts of them

@using jQM

@{
    ViewBag.Title = "Buttons";
}

@Html.ActionButton("Hi. I am a simple button.", "Index", "Home")

@Html.ActionButton("Hey! Look, I am a settings kind'a button.", "Index", "Home", ButtonIcon.gear)

@Html.ActionButton("Unlike others, I have route values.", "Router", "Home", new { id = "value" })

The code above will create a neat little stack of different kinds of button.

So that’s it for now. As the project grows, I will be sure to update with the neat things that will go into jQMvc.


Implementation of a Generic Repository Beauty, with Ninject the Beast

I really should be studying. But why study when I can blog right? Well, I have been meaning to write this post for a while now, and here it is.

The Repository Pattern is invaluable when working with the data, particularly in MVC. It encapsulates a lot of redundant and hopefully generic operations, I use it to encapsulate operations on the Entity Framework Code First ORM. My implementation doesn’t use Unit of Work which tracks changes and updates the database accordingly. Instead, I let myself decide. It’s not that bad.

The Context

Firstly, there is the context interface. It can expose methods, but I didn’t need to. Let’s imagine this context is for a shop.
This interface is important because it’ll be used by Ninject to wire everything up.

public interface IShopContext
{
}

The concrete implementation of the context might look like this.

public class CareContext: DbContext, IShopContext
{
    public DbSet<Fruit> Fruits { get; set; }

    public ShopContext()
    {
    }
}

The Entities

Fruit above is an entity and there can be many more. The entities derive from an abstract Identity class. What it is, is pretty obvious.

public abstract class Identity
{
    public Guid ID { get; set; }
}

Now let’s look at the example Fruit.

public class Fruit: Identity
{
    public string Name { get; set; }
    public int AmountInShop { get; set; }
}

The Repository

public interface IRepository<TEntity> where TEntity : Identity
{
    TEntity Add(TEntity model, bool persist = false);
    TEntity Get(Guid id);
    IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> predicate);
    IEnumerable<TEntity> GetAll();

    TEntity Update(TEntity model, bool persist = false);

    void Remove(Guid id, bool persist = false);
    void Remove(TEntity model, bool persist = false);

    void Save();
}

So these are some of the operations that the repository will perform. As you can see, I take care of the persistence using the optional parameter persist.

And now… the concrete implementation of the repository.

public class Repository<TEntity> : IRepository<TEntity> where TEntity : Identity
{
    private DbContext Context;
    private DbSet<TEntity> DBSet;

    public Repository(IShopContext context)
    {
        Context = context as DbContext;
        DBSet = Context.Set<TEntity>();
    }

    public TEntity Get(Guid id)
    {
        TEntity model = DBSet.Find(id);
        return model;
    }

    public IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> predicate)
    {
        return DBSet.Where(predicate).AsEnumerable();
    }

    public IEnumerable<TEntity> GetAll()
    {
        return DBSet.AsEnumerable<TEntity>();
    }

    public TEntity Add(TEntity model, bool persist = false)
    {
        model.ID = Guid.NewGuid();
        DBSet.Add(model);
        Save(persist);

        return model;
    }

    public TEntity Update(TEntity model, bool persist = false)
    {
        Context.Entry(model).State = EntityState.Modified;
        Save(persist);

        return model;
    }

    public void Remove(Guid id, bool persist = false)
    {
        TEntity model = DBSet.Find(id);
        Remove(model, persist);
    }

    public void Remove(TEntity model, bool persist = false)
    {
        if (model != null)
        {
            Context.Entry<TEntity>(model).State = EntityState.Deleted;
            Save(persist);
        }
    }

    public void Save()
    {
        Save(true);
    }

    private void Save(bool persist)
    {
        if (persist)
        {
            Context.SaveChanges();
        }
    }
}

There you have it. It’s very simple to read really. It just spells out the methods defined in the interface and also provides logic for persistence when you want it.

The Ninject

Now all of this is pretty useless without Ninject. You’ll have noticed I used Inversion of Control while implementing the repository. Ninject is available on Nuget.

While registering the services on Ninject, I can tell it to provide a ShopContext when a IShopContext is required. The repository is bound to an interface, this context can be a development or deployment context, depending. Also, since I want to use the same context always, I bind it using ToConstant.

As for when a repository operating on a certain entity is requested, Ninject finds its type and provides accordingly.

private static void RegisterServices(IKernel kernel)
{
    IShopContext shopContext = new ShopContext();
    kernel.Bind(typeof(IShopContext)).ToConstant(shopContext);
    kernel.Bind(typeof(IRepository<>)).To(typeof(Repository<>));
}

Hope that wasn’t too long a post, it probably is my longest so far. Till next time, then.


MVC Now Stands for Mobile Views Conquered

Say hello to my little friend. Always wanted to say that. But seriously, say hello to jQuery Mobile. It’s pretty obvious what its all about so I’ll get straight to it. Here’s a little look at how pages of ASP.Net MVC applications can be hosted to work with mobile devices et with amazing interfaces.

Link ‘em.

We’ll need to link the resources either from the CDN that’s mentioned on jQMobile’s download page. Or you can… download them. As I have.

    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.mobile-1.0a4.1.min.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/jqmobile/jquery.mobile-1.0a4.1.min.css")" rel="stylesheet" type="text/css" />

Give it structure.

I gave this MVC3 project’s _Layout.cshtml the following layout so that I can use it throughout my other views and modify those as required.

<div data-role="page">
   <div data-role="header">
       <h1>@ViewBag.Title</h1>
   </div>
   <div data-role="content">@RenderBody()</div>
   <div data-role="footer">
       <h4>Footer here</h4>
   </div>
</div>

Using the data-role attribute, we can specify different parts of the page as we like. And as you might guess RenderBody() will be the mode of transaction for all your data. Data transactions can also happen through the jQMobile framework itself (using JavaScript that is). As you might imagine, each page can have be strongly typed to a model.

From there on it’s just good old MVC with jQMobile doing all the neat work, preparing the application for mobile platforms.


MVC3 Docking on AppHarbor and Entity Framework Code First

So, I spent last few hours figuring this out. AppHarbor is pretty nice. AppHarbor is free for one application, one database and it does work with SQL Server CE. I just deployed a stripped down version of one of my MVC projects there and it’s pretty smooth. So, here’s a run down of how it’s done, so that someone else might not need hours.

Stripping the project down was a breeze, you’ve got to love Object Oriented design, it’s beautiful. Deploying the project was a no-brainer too, if you’ve had some experience with Git. But testing, as ever brought out the issues.

I was using Entity Framework Code First (EFCF) as my ORM and it likes to drop databases. I didn’t realize it since it’s natural for EFCF to. And for good reason too, for when you change your models. On AppHarbor, you don’t get permissions to create databases. Thus the problem.

But no fear, NuGet to the rescue. Again. Actually, community to the rescue. There’s a workaround for EFCF’s DropCreateDatabases it’s DontDropDbJustCreateTables. You can find here on NuGet. It plugs in beautifully to your application and all you need to do is enter your context name. Also, you will have to get a new database from AppHarbor since already EFCF dropped it.

Also the connection string should include a providerName otherwise, exceptions!

<connectionStrings>
    <add name="connection string name"
         connectionString="Server=db003.appharbor.net;Database=dbXXXX;User ID=dbXXXX;Password=YourPassword;"
         providerName="System.Data.SqlClient" />
</connectionStrings>


Follow

Get every new post delivered to your Inbox.