EDITING BOARD
RO
EN
×
▼ BROWSE ISSUES ▼
Issue 44

Creating a Microsoft Band Tile to push build status notifications

Radu Vunvulea
Solution Architect
@iQuest



PROGRAMMING

Last year Microsoft had launched Microsoft Band 2. From the hardware configuration, it's very powerful with a lot of sensors and a battery autonomy that offers me two days of power.

Overview

But, the thing that impress me is the software part and how easily you can develop a tile (a custom app) for it. You don't need to learn C#, you can create a tile easily directly from browser.

Yes, you heard me, from a browser

This will allow you to get content from the fat web and push it to your tile. In this way you can easily integrate your application with the band - fast and easy

Another great thing is how you deploy and share tiles. You don't need to push to the store, validate it and so on. No, you are free to share the tile with anybody. Just upload it to a specific location and share the URL with your friends via email or web. The phone can detect automatically the tile and open it using Microsoft Band application.

Information is the power

For consumers, the most important thing is the content that you display in the tile. Try to focus on the content that you want to display. You need to identify the content that can improve the life of the band owner.

Because the number of tiles that you can install on the band is limited, you should keep in mind that the consumer will keep only the most important tiles that bring on his device information that he really needs. Otherwise, your tile will be just another tile, that nobody use or keep more than 5 minutes.

Any developer can create a tile and push content to Microsoft Band, in only 2 or 3 minutes. But only great ideas and useful content will end up on consumers devices.

Our team

Each developer from the team that I'm part of received last year a Microsoft Band 2. We started to make jokes, that we increased the number of Microsoft Bands in Cluj-Napoca with 800-1000%. The team is not so big, but in that moment in time in Cluj-Napoca I knew only a person with a band.

The IDEA

I started to think about what we can do with the band, how we can improve our life. I end up with a simple solution, that I will describe end to end in the next part of the article.

Push build status change notification to our band

The idea is simple. We are keeping our source code on TFS Online (Visual Studio Online) and TFS 2015 on-premises. We have different builds agents on Azure and in our company private network (on-premises) that build our solution, run unit tests, extract different metrics and deploys automatically the application on different environments. The main scope is to notify as soon as possible the development team that the build is down.  

Blockers and architecture overview

The main scope is to push a notification to the band in the moment when build fails. The idea is simple, but we need to find a solution to be able to send the notification to the band without having to store TFS User Credentials.

There is no way to store credentials on the band and query the source control server.

A possible solution is to develop a phone app that would push these notifications. But, wait… we are not mobile developers and each of us has different types of phones - iPhones, Windows Phone and Android. It might work, but the development effort is too expensive. It is possible to write a cross platform mobile app., but until you push it to the store you will lose the interest and the current opportunity.

RSS Feed

A more simple solution is to expose a RSS feed with build status change notifications. Each time when the build status change, new content will be available on the RSS Server. The tile that is running on the band will detect the new content and will notify the user.

In this moment we resolved only a part of the problem. We have a web endpoint that can be used by the tile to access the RSS feed. The RSS feed channel can be used by the band to get build status change notifications.

Push Notifications

Now, we need to find a way we can push the build status change from CI server to our web application. This is a little trickier and, please, ignore any kind of security issues that will be only mentioned, but not covered.

For Visual Studio Team Services, the problem can be solved easily. Because the CI is public available we need to store in our web app a valid username and password that can be used to query the build status for changes. 

But for our on-premises CI server we might have a problem. The on-premises CI server is not public available. This means that we cannot query our server to check the build status from the internet.

Let's use our imagination. 

What is the default action that is done by a CI server when a build fails, except the color change (big smile)?

The most common action is to send an email to one or more users. This is our key to be able to access a build status change notification.

The CI machine will send a notification to our mail server. Normally, a Mail Server is public accessible from internet. Our RSS web app will need to store the email credentials.

Even if the solution works and can be used with success, we need to keep in mind that:

All these points need to be mitigated with the security group of your company. You should never implement such a solution without their approval. 

Implementation

TFS Email notification

The solution is applicable for older version of TFS also. The below steps and samples are for Visual Studio Online and TFS 2015. 

You will need to define an alert that sends an email notification in the moment when the build quality changes. Based on your needs you can use the same account to send notifications for different builds. 

Check for new emails

There are different libraries that can help you to access your email server. You should decide what kind of library you want to use based on the email server type. If you are using Outlook or Exchange Server, then you might want to use EWS library. For Gmail account you might need a POP3 client and a MIME purser like OpenPOP.NET.

In the below sample, you can see how you can get a message using OpenPOP.NET library. 

POPClient client = new POPClient();
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("radu.vunvulea.sample@gmail.com", "Hahaha");
var count = client.GetMessageCount();
Message message = client.GetMessage(count);

The subject can be accessed in the following way 'message.Headers.Subject'.

Expose notifications as RSS feed 

The next step is to expose as RSS feed the new notifications. This can be done in 10 minutes if we are using ApiController. Wait, we don't need to implement a RSS feed and serialize the content.

This is supported by ASP.NET MVC. There is even a special ActionResult that is created for this purpose - RssActionResult. To the RssActionResult, we need to set the 'Feed' property that is of type 'SyndicationFeed'.

public ActionResult BuildStatusRSS()
{
    IEnumerable buildStatus = BuildStatusManager.GetAllByDate(8);
    SyndicationFeed buildFeed =
        new SyndicationFeed(„Build Status”,
            new Uri(„http://www.raduvunvulea.com/buildStatus/RSS”),
            Guid.NewGuid().ToString(),
            DateTime.Now);

    List buildStatusList = new List();
    foreach (BuildStatus bs in posts)
    {
        string postUrl = string.Format(„build\\build-entry-{0}”, bs.Id);
        SyndicationItem buildStatus =
            new SyndicationItem(bs.Title,
                bs.Description,
                new Uri(postUrl),
                bs.Id,
                bs.Date);
        buildStatusList.Add(buildStatus);
    }

    buildFeed.Items = buildStatusList;

    return new RssActionResult {Feed = buildFeed};
}

In the above example we are generating a RSS with build status. The BuildStatus class is a custom class where information related to a specific build is stored. This class is populated based on the emails that are send by the TFS when a build status changes.

Hosting our Web App

We can host our web application as a Web App in Azure. The free tier will be enough to play around.

My web application url will be http://rvbuilstatus.azurewebsite.com. The build status is mapped to http://rvbuilstatus.azurewebsite.com/build/rss.

Creating the Tile

This is the last step that we need to do. We need to create the Microsoft Band Tile. This will be done directly from browser.

The next steps are pretty simple, you need to specify colors, icon and things like that. Once we′ve done this, we can download the tile on our local computer.

Publish the tile

The most simple solution to publish the tile is to upload on a file sharing system like OneDrive and create a share link.

... the end...

And we are done. Once we will access the tile link from your phone, the Microsoft Band application will open and you will be able to push the tile.

Conclusion

In this post we saw an end to end solution on how we can push builds notification to our Microsoft Band without developing a phone application. From the tile perspective, creating and publishing a tile is easy.

The most complex thing is to create the feed with the right information. Not because of technical problems, it is about what content to push (display). We should remember that 'Information is the power'

Conference TSM

VIDEO: ISSUE 109 LAUNCH EVENT

Sponsors

  • Accenture
  • BT Code Crafters
  • Accesa
  • Bosch
  • Betfair
  • MHP
  • BoatyardX
  • .msg systems
  • P3 group
  • Ing Hubs
  • Cognizant Softvision
  • Colors in projects

VIDEO: ISSUE 109 LAUNCH EVENT