Skip to main content

Creating a Microsoft Band Tile to push build status notifications

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 - https://developer.microsoftband.com/WebTile

This will allow you get content from the 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 brings 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 this 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 to 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 tiles 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 how we can push the build status change from CI server to our web application. This is a little more tricky 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 up will need to store the email credentials.
Even if the solution will work and can be used with success we need to keep in mind that:

  • Emails credentials will be stored by Web App
  • Confidential information (Build Status) will be public available on a web endpoint that can be used by anybody
  • Any person that has your tile will be able to see status change notification of your build(s)
All this points needs 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 notification 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 that 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 messages 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 access 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 using 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> buildStatus = BuildStatusManager.GetAllByDate(8);
    SyndicationFeed buildFeed =
        new SyndicationFeed("Build Status",
            new Uri("http://www.raduvunvulea.com/buildStatus/RSS"),
            Guid.NewGuid().ToString(),
            DateTime.Now);
            
    List<SyndicationItem> buildStatusList = new List<SyndicationItem>();
    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 are 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 (https://developer.microsoftband.com/WebTile).
The next steps are pretty simple, you need to specify colors, icon and things like that. Once we 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 easily.
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'

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

What to do when you hit the throughput limits of Azure Storage (Blobs)

In this post we will talk about how we can detect when we hit a throughput limit of Azure Storage and what we can do in that moment. Context If we take a look on Scalability Targets of Azure Storage ( https://azure.microsoft.com/en-us/documentation/articles/storage-scalability-targets/ ) we will observe that the limits are prety high. But, based on our business logic we can end up at this limits. If you create a system that is hitted by a high number of device, you can hit easily the total number of requests rate that can be done on a Storage Account. This limits on Azure is 20.000 IOPS (entities or messages per second) where (and this is very important) the size of the request is 1KB. Normally, if you make a load tests where 20.000 clients will hit different blobs storages from the same Azure Storage Account, this limits can be reached. How we can detect this problem? From client, we can detect that this limits was reached based on the HTTP error code that is returned by HTTP