Introducing the Entile Notification Framework

Update 2011-01-13: A first preview is now available. You can get it here!

This post is an introduction to the (not yet publicly released) Entile Notification Framework for Windows Phone 7 (wow, I should work for marketing at Microsoft…). If you like what you see and would like to give it a go yourself, follow and ping @entile_fx on Twitter or add a comment to this post and I’ll send you teh codez! Eventually, Entile will be released under an OSS license, but there is a bit of polishing left to do…

The past couple of weeks I’ve been playing around a bit with Windows Phone 7 development. My first attempt was a very simple app that displays the current week number (why not download it and give it a review?). Actually doing the main part of the app was incredibly simple, but I did run into a bit of trouble when I decided that it also needed a Live Tile (so that you can see the current week number if you pin the app to your home screen). It turns out that doing push notifications and live tile updates is not as straight-forward as one would like it to be.

There are plenty of articles out there that explain how to do it, and they all look more or less the same; it’s a bunch of web request, a few magic http headers, plenty of asynchronous methods and events. A mess.

So, I decided to try to clean the process up a little – and the Entile Notification Framework was born. The framework in its current state is likely not for everyone, but at least if you have reasonably simple requirements it may already be of use to you.

Essentially, Entile consists of two parts; a client assembly for your Windows Phone 7 app and a server-side assembly that can be hosted in an IIS web application or in an Azure Web Role.

Client

But let’s begin in your Windows Phone 7 client application, and let’s keep it simple. After adding a refernce to the Entile.dll assembly, you need to do three things:

  • Create an EntileClient
  • Make sure the Enable property can be set
  • Add some configuration in App.xaml

Even though you should be able to use Entile without the MVVM-pattern, I’m going to assume that you’ve already seen the light. So you need a ViewModel that exposes an instance of the EntileClient class.

public class MainViewModel : INotifyPropertyChanged
{
    public MainViewModel()
    {
        Entile = new EntileClient("YourChannelName");
    }

    private EntileClient _entile;
    public EntileClient Entile
    {
        get { return _entile; }
        set
        {
            if (_entile != value)
            {
                _entile = value;
                NotifyPropertyChanged("Entile");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

EntileClient has a boolean property called Enable that when set to true will start the process of opening a channel and registering it on the server side. The simplest way of doing this is of course to data bind against it. I’ve been using the SilverlightToolkit ToggleSwitch control for this. To give the user some feedback you should probably also bind to the Busy-property and indicate that we are working.

<toolkit:ToggleSwitch Content="Notifications" IsChecked="{Binding Entile.Enable, Mode=TwoWay}"/>
<ProgressBar IsIndeterminate="{Binding Entile.Busy}"/>

Finally, we need to tell the client where to find the server, and also (potentially) from where any Live Tile images might be coming. All configuration settings are handled as static resources, so why not just put them in App.xaml:

<Application.Resources>
  <sys:String x:Key="RegistrationServiceUri">http://your-server.com/YourModule/Registration</sys:String>
  <sys:String x:Key="AllowedTileUris">http://your-server.com</sys:String>
  <sys:String x:Key="RequestLiveTiles">true</sys:String>
  <sys:String x:Key="RequestToasts">true</sys:String>
</Application.Resources>

Also notice that this is where you decide the types of notifications your app will support.

And that was it on the client. There are several things you can do to further customize things on the client, most importantly you can decide to add more data to the registration, but as promised we’ll keep it simple for now.

Server

As mentioned above, Entile relies on IIS (and .NET Framework 4.0) for the server side. One host can actually cater for several different apps, each one with its own Module

A module consists of two things; a class that implements IEntileModule, and a WCF Http service. When a module is initialized, it is passed an instance to the IRegistrator (which provides information about any registered clients) and the INotifier (which can be used to actually send toasts and live tiles to a client). A module can also expose a Remote Live Tile Uri that will be used by the client to regulary (once every hour) poll for a new tile instead of relying on it being pushed out.

To set everything up, you only need to initialize the EntileHost and register all modules. You do that in Global.asax.cs

protected void Application_Start(object sender, EventArgs e)
{
    EntileHost.Initialize();
    EntileHost.RegisterModule(new MyModule("http://your-server.com"), new MyCustomRegistrationStore());
}

This will register your own service at http://your-server.com/{NameOfTheModule} and will also setup the Registration service for your module at http://your-server.com/{NameOfTheModule}/Registrations

As you may have noted, RegisterModule also takes an IRegistrationStore as a parameter. By default, all registrations are stored in a very simple XML-file – but that is clearly not a viable path for an app that expects to see any kind of usage.. The IRegistrationStore interface allows you to make sure that the registrations are stored using your favorite persistance layer – be it a flat file, SQL Server, Azure Table storage or why not RavenDB.

Get the bits

Ok. If you’ve actually read this far, I’m guessing you may be interested in giving Entile a go? I’m still trying to put some finishing touches on the code before feeling confident enough to put it in a public repository (also, I need to learn how to Git..). That said, if you would like to get a zip-file with what I’ve currently got, do contact me via the blog, or send out a tweet to @entile_fx!



9 responses to “Introducing the Entile Notification Framework”

  1. I am interested. Can you share via email.
    thanks!

    Like

  2. […] This post was mentioned on Twitter by Anders Ljusberg. Anders Ljusberg said: RT @entile_fx: Introducing Entile Notification Framework for Windows Phone 7 http://ande.rs/fzs7jo #wp7 #wp7dev […]

    Like

  3. I m also interested 🙂
    Nice job by the way

    Like

  4. Thanks for the interest! I’ll try to send you some bits tomorrow!

    Like

  5. […] Entile Notification Framework « Introducing the Entile Notification Framework […]

    Like

  6. Good job, I am interested 🙂

    Like

  7. I am interested as well. Looks like a useful solution.

    Like

  8. I just downloaded the files and it works good 🙂 Framework is excellent. Thanks @Anders

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

About Me

Consultant, Solution Architect, Developer.

Do note that this blog is very, very old. Please consider that before you follow any of the advice in here!

Newsletter

%d bloggers like this: