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

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

[Post-Event] Codecamp Conference Cluj-Napoca - Nov 19, 2016

Last day I was invited to another Codecamp Conference, that took place in Cluj-Napoca. Like other Codecamp Conferences, the event was very big, with more than 1.000 participants and 70 sessions. There were 10 tracks in parallel, so it was pretty hard to decide at  what session you want to join.
It was great to join this conference and I hope that you discovered something new during the conference.
At this event I talked about Azure IoT Hub and how we can use it to connect devices from the field. I had a lot of demos using Raspberry PI 3 and Simplelink SensorTag. Most of the samples were written in C++ and Node.JS and people were impressed that even if we are using Microsoft technologies, we are not limited to C# and .NET. World and Microsoft are changing so fast. Just looking and Azure IoT Hub and new features that were launched and I'm pressed (Jobs, Methods, Device Twin).
On backend my demos covered Stream Analytics, Event Hub, Azure Object Storage and DocumentDB.

Title:
What abo…