Azure Event Hub REST API

imageI was recently worked on a project where I had to use a mobile device, specifically Window 8.1 phone/tablet, as a hub for an external sensor. The mobile device then needed to pass the data to an Azure Event Hubs endpoint. The data was then going to be sent through Azure Stream Analytics to various storage solutions. Normally you would fire up a project, go to NuGet package manager, install ‘Microsoft Azure  Service Bus’ SDK, set your endpoint URL and send key, and be off and running. There is one slight problem with that in my architecture. One of the SDK dependencies is not compiled against WinRT so you are out of luck there.

Luckily Azure Event Hubs exposes a REST API that is fairly straight forward except for one thing. How do I assure the service I have the appropriate authorization to send messages. The REST endpoint expects a Shared Access Signature in the header of the request. Here is some sample code for creating that token:


Basically it is a string containing the base URL a hash of the base URL and expiration (using the send key as the hash key) and the key rule name.  You can go to the MSDN documentation for more information on Shared Access Signatures.

I created a little proxy class that encapsulates the generation of this token and handles sending the message:


My Event Hub expects all messages to be formatted as JSON. My proxy method takes the serialized object and packages it up as the content of the HTTP request. It also sets the SharedAccessSignature header value.

UPDATE: I recently got asked what [PATH TO MESSAGE ENDPOINT] is,  So here is a little explaintion. In the EventHubProxy you have [BASE SERVICEBUS URL] which should look something like this:, where xxxxxxxxxx is the name of your services bus namespace. On the portal website you should see you EventHub Url which looks something like this, where zzzzzzz is the EventHub name.  So  [PATH TO MESSAGE ENDPOINT] is ‘zzzzzzz/messages’. I hope this clears it up.

Sending and event to the hub is as easy as:


One thing to note in this architecture is that mobile devices tend to be on metered connections. So be aware that sending loads of data will count against the devices data plan. You may want to restrict sending data only when the device is not on a metered connection.  You can get the code and play with it.  I put TODO statements where you have to provide you environment specific values.

Posted in Architecture, Azure, Cloud, IoT | Tagged , , | Leave a comment

My Visual Studio 2015 Review


Recently I was asked by SDTimes to write a review of Visual Studio 2015.  I had been using it since early previews so I was more than happy to give my two cents.  Check out the article Visual Studio 2015: An insider’s review and tell me what you think.

Posted in Uncategorized | Leave a comment

A Universal Example

In my last post What Does It Mean to Be Universal, I talked about Microsoft’s new Universal Application Platform (name may be changing to Universal Windows Platform), coming in Windows 10. This new application platform allows you to build one application and run it on different platforms.  In that post I told you how Microsoft was doing that. In this post I want to look at an example of what a single app running everywhere, might look like.



Let’s say you were building an application for manufacturing company. They want to deploy IoT sensors running Windows 10.  These sensors would gather telemetry data from the machines on the factory floor.  This data would be transmitted to the cloud where it would be analyzed and reported through machine learning (out of scope for this post).  The data then can be accessed on Windows PC, Tablets and Phones. They also want to take advantage of augmented reality technology to give their plant manager real time access to the data while they are walking around the plant.

The Old

imageIn the past you would probably create a project that looks something like this. You would have multiple projects for each head you want to support. Plus you would have some libraries for code that you want to share across each of the heads. After compiling, you end up with an application for each head. Although not too complex, there is the potential for major code duplication. This is especially true when it comes to the interface and platform specific code (where API differ). There was less of an opportunity for reuse.

The New

imageUnder the system you can create one project, compile into one application, and have it run on all the devices. The APIs are pretty much the same.  When they do differ for a device, Microsoft has a way for that code to still live in the same project (see my last post for a sample). There may be times when you want to separate out code. For instance code that can be reused in projects that are not part of the new platform, server code comes to mind.  That should still be possible.  I say should because we don’t know for sure. We will have to see what comes out at Build next week. Hopefully we will have more clarity on this.


So one project or many projects?  This universal platform is going to make us rethink how we architect our solutions going forward.  Does it make sense to have everything in one project or do you want to keep things separated? I can definitely see creating utility projects that get reused between different solutions but does it make sense to have a .dll for Services or Models?  You used to be able to replace those components just by swapping out dll’s but now everything gets wrapped up into an apex package that is signed.  Swapping out dll’s would invalidate the package so a new build is needed. I am interested in hearing what people have to say about the new universal platform.

Posted in IoT, Software Architecture, Universal App Platform, Windows 10 | Leave a comment

What Does It Mean To Be Universal

So what does it mean to be universal when it comes to Windows 10?  A new way of building applications is coming in Windows 10. The past few years Microsoft has been on this path of converging all of their operating systems to run on a common core.  Windows 10 is the culmination of this journey. One of the benefits of having a common core is the ability to create an API that will allow apps to run across all the devices that use this core.  So Microsoft introduced the Universal Application Platform (UAP).  Gallo blog 1 v2


The UAP will allow developers to build applications that will run across the One Windows Platform. There are many challenges to achieve this goal of write once and run on all these devices. There are all kinds of devices that these apps can run on from phones with 4” screens, to running on Xbox with 52” screens, to devices with no screens at all. These different device have different capabilities. So how do you address these needs.

How Did We Get Here

Back in the day Microsoft’s “cross” platform solution was to create a portable class library. These libraries were restricted to the least common denominator of frameworks you want to address. This created a dll that could be referenced by the reference frameworks. This was great except that you were restricted on which API’s you had access to plus you ended up with multiple applications.

With Windows 8.1, Microsoft introduced a universal application template that helped developers build phone and modern Windows 8.1 apps. A “minor” convergence of the API happened, bringing the phone and the tablet closer together. The converged API allow for more code reuse and minimal device specific code. It did this by creating a shared project that injected the common files into each project (Windows and Phone). So you could share a lot of code but in the end you still have two applications. And the code you write for these universal apps was specific for the phone and modern applications (formally known as Metro).

Moving Forward

In Windows 10, Microsoft is taking the concept of universal apps from Windows 8.1 and expanding on it to cover a wider array of devices. The common core operating system was the first step. At the base of the Universal Application Platform is this thing call the Universal Device Family. This is the set of APIs that are guaranteed to be available to all applications written with UAP.  Once an UAP app is compiled there is one app package that can run on all these different device families.

Device families

From the diagram above you can see that there are many device families that your application can target (one, some, or all). Does that mean there will be Xboxs API installed on my desktop? There has to be if I expect my code to compile, right? Also how do I take advantage of device specific functionality, like the hardware back button on my phone? Hey some of those IoT devices are pretty small to be having all these APIs installed, remember we are creating one package to rule them all.

Microsoft handles this through Extensions. When you need to target specific functionality tied to one of these device families, you add a reference to the extension for that device family. Those extensions are just metadata files with the available API’s for that device family. When the application compiles it does so against these metadata files.  The actual API’s will be installed on those specific device families.


Now that I have those references I can start writing code for the phone back button and expect that code to run just fine on the Xbox right? Well not quite. You don’t want to try to call an API that is not implemented on you specific device family where your app is running.  You will get all kinds of run time errors. How do you handle these API calls?

In the past when we had shared code, we would isolate device specific code in #IF statements. But wait you said there would be one app package and #IF suggest multiple since it is a compiler directive. In Windows 10, you do not want to query for device types. Device types will be added all the time and your #IF statements could get out of control. Instead, Microsoft, has provided a means to query for capabilities/API.  They have introduced the ApiInformation class. 

The ApiInformation class allows you to test for the presence of the API you want to call. Here is an example checking to see if there are phone hardware buttons present.


On thing to notice is the use of Magic Strings.  Those are bad. I hope that Microsoft comes up with a better way to do that. Maybe have a constants file that contains the most common types users are going to query for and the leave it up to the user to handle the exotic cases. Either way there is a good chance that you will fat finger a fully qualified name. It is an early release of the SDK so things can and most likely will change.

By querying for specific capabilities, line 39 will only run if there are hardware buttons present.

The …

The beauty of the UAP approach is that it is extensible.  Did you notice “…” in the diagram above.  They are leaving it open for new platforms in the future, say for instance HoloLens. Or even devices that don’t exist today.  If you install the preview SDK you will see that there are only 2 extensions present, one for the desktop device family and one for the phone device family. Expect more to come in future releases.

Final Thoughts

The direction that Microsoft is going is exciting. It will be interesting to see how they follow through on this One Windows Platform vision. It will also be interesting to see if someone like Xamarin can take advantage of the UAP and extend it to iOS and Android.  Hopefully we will get more insight at Build this year.

Posted in IoT, Modern Application, Software Architecture, Windows 10, WinRT | 1 Comment

Layout Awareness in Windows 10 UAP

There have been lots of changes with Windows of the past few years. A while back, Microsoft radically changed the way Windows worked with Windows 8. The goal was to start to converge the different operating systems into a single core. Windows 10 is the culmination of that convergence which started out as “Three Screens and a Cloud” and now includes many more screens. 


The road to convergence is a difference story. Here I want to talk about the user experience. While all this was going on there was a revolution in the experiences that users expected. No longer are battleship gray user interfaces acceptable.  Neither are shrunk down versions of these interfaces acceptable on mobile devices.  As a developer you need to design and build you applications for the form factors that you are targeting. Here is where we pick up that journey on the Microsoft stack.

The Past

In Windows 8 there were two environments, a desktop environment, and a tablet environment and with the tablet environment they introduced a new programing language WinRT.  Those tablet apps, sometimes referred to as “Metro” apps, could be running in one of four states; Filled, Full, Snap and Portrait. There was a neat little enum that helped support these states.  One of the mantras was good design. Your app should look good and respond well/do the right thing in any of those states.  To assist developers, the Visual Studio template for those projects included a LayoutAwarePage that assisted in handling the transition between states.  I wrote a blog about it What is This ‘LayoutAwarePage’ You Speak Of.

Along comes Windows 8.1, that enum goes away and so does your LayoutAwarePage. In 8.1, apps could be resized horizontally independent of those defined states. There was another wrench thrown into the mix, the phone.  With this release WinRT apps can be developed for the phone. The templates changed to include a new Universal App template.  There was guidance from Microsoft that you should target both table and phone but no tool build in the framework to help. At Build 2014 there was a pretty good session on how to target screens of any size: From 4 to 40 inches: Developing Windows Applications across Multiple Form Factors.  During this session Peter Torr, showed the science of view items on different size screens, he also showed a potential solution to the lack of built in tooling. Since I wrote about the LayoutAwarePage in 8 I figured I better write a post about where in went in 8.1: What Happened to My LayoutAwarePage?.

The Now

In Windows 10, Microsoft wants to target a larger array of device, including some that don’t even have screens. From the image bellow there are a plethora of platforms that your apps can run on.  The convergence allows you to write code that runs on all these devices but does that mean I have to write a separate UI for all these devices?

The answer is no. Taking a page from web design, the new guidance is to build adaptive interfaces.  Keeping in mind that the experience should be tailored for each specific form factor.  Recently a preview of the SDK for Windows 1o was released along with a Microsoft Virtual Academy training course. Module 9 caught my attention because it talks about building adaptive UI and it looks very similar to the solution that Peter Torr came up with for 8.1. In Windows 10 you can truly build one app (one app package) that will run on any Windows 10 device. There is some neat magic behind the sense that allows this to happen and if you are interested in that you should watch the other modules in the course. To support writing a single Xaml file that runs across devices, Microsoft has revamped Visual State Manager to assist with building adaptive UI.  I highly recommend that you take a look at that module if you are interested in the story.

I am sure that more details will come during Build 2015 (April 28-May 1) so keep an eye out for what coming down the pike. Keep in mind that everything is in preview right now so things may change between now and release but this looks promising. 

Posted in Mobile, Modern Application, Universal App Platform, Windows 10 | Leave a comment

Virtual Reality vs. Augmented Reality vs. Holograms

hololensOn January 21, 2015 Microsoft Announce that the science fiction of holograms has become science fact.  They announced a new product, based on Windows 10, called HoloLens.  The first self contained, wearable computer that can create holograms.  This announcement has generated a buzz. If you haven’t seen the video Microsoft put out, take a minute, follow the link above and watch it, I’ll wait….. You’re back.  Were you blown away? I was. My mind was immediately racing to what problems I could solve if this truly pans out. More on that in a bit.

Virtual Reality

“Virtual Reality (VR), sometimes referred to as immersive multimedia, is a computer-simulated environment that can simulate physical presence in places in the real world or imagined worlds. Virtual reality can recreate sensory experiences, which include virtual taste, sight, smell, sound, touch, etc.” Wikipedia

When Microsoft announced HoloLens some people mistakenly called it virtual reality. Although Microsoft showed immersive experiences, the fact that you can still see the world around you makes precludes it from being virtual reality.  A prime example of virtual reality is the Oculus Rift

Augmented Reality

“Augmented reality (AR) is a live direct or indirect view of a physical, real-world environment whose elements are augmented (or supplemented) by computer-generated sensory input such as sound, video, graphics or GPS data.” Wikipedia

HaloLense is really just augmented reality plus much more. I will go into what I mean in a bit. Augmented reality is not really new.  There are phone app, Yelp for instance, uses the phone’s camera to display the world around it while superimposing restaurant information based on the direction the phone is pointed.  Or how about the translator app for Windows phone that superimposes translated text over written text. You can go from one language to another.

Another recent example is Google Glass (though they have suspended the program).  Google Glass is a pair of glasses that puts a heads up display on the lens, providing information to the wearer. That information is in a static location, no matter which direction the users is facing.


“Holography is a technique which enables three-dimensional images (holograms) to be made. It involves the use of a laser, interference, diffraction, light intensity recording and suitable illumination of the recording. The image changes as the position and orientation of the viewing system changes in exactly the same way as if the object were still present, thus making the image appear three-dimensional.” Wikipedia

The HoloLens can created realistic three-dimensional images and place those images in the world around you.  So I would say that HoloLens is a combination of all three. It may not be truly creating holograms they seem to be real enough to the wearer.


To be clear, I have not had an opportunity to try HoloLense.  I was not one of the chosen few who got to attend the event.  The reaction from those who did get to try the canned demo’s is overwhelmingly positive.  Until I get to try it I can only rely on what they have said. I am excited at the possibilities that this opens up.  I do have some questions as well. 

First is Microsoft targeting consumer or enterprise or both.  The thing that will really determine that is price. When the Xbox one first came out it was $499 and adoption was slow. When they dropped the price $350 this past holiday season, they sold like hotcakes. Granted there is no direct competitor to HoloLens (as of yet), if they price it too high it may be just out of reach for the average consumer.

The next question I have is with the form factor itself.  If this is intended to be worn for long periods of time it needs to be comfortable.  Google Glass was a pair of glass so they were easy to wear for long periods of time.  HoloLens will have way more functionality than Google Glass.  All that functionality requires some pretty heavy computing power. Microsoft packed all that computing power into a self-contained device, or donut as my coworker likes to call it. Is v1 going to be too big or too bulky?  With all that computing power what is the battery life going to be?

Finally can Microsoft truly deliver on the experience they showed in the videos?  That will be the true test to the success of the device. Judging from the reaction of the reporters at the event, they are pretty close. Microsoft has gotten a lot of people excited with this announcement, a lot of people that have all but written them off. If they mess this up they may drive those people away for good.

The Possibilities

A couple of years ago Microsoft released a vision video that captured my imagination.  They showed off a lot of “imagined” technologies. They showed how technology will blend into the environment around you and become ingrained in everyday life.  Most of the stuff they showed was not real but with HoloLens and Surface Hub, some of those use cases are now possible.

I am excited at the possibilities this opens up. Microsoft has said that HoloLens apps are just Universal Apps with some added APIs. Hopefully they will release an SDK during their Build conference.  If you weren’t able to get in or can’t attend they usually make the sessions available online soon after. 

The video that Microsoft released shows all kinds of use cases for HoloLens. I have a few of my own and I am excited to see what others come up with.


In recent years these press events had very few surprises. Look for instance at the last Apple launch there were nothing announced that had not previously leaked. Microsoft did a great job keeping this secret.  There were rumors of an Xbox gaming helmet but this is so much more.  You can see pieces of this technologies in various Microsoft research projects. It is great to see them finally capitalizing on some of that research.  Only time will tell if HoloLens will be a success but you have to admit living in a time where holograms can be real is pretty cool.

Posted in Computer Science, Contextual Computing, UX, Windows 10 | Tagged , , | Leave a comment

Do What You Love!

I love what I do.  Technology makes me happy. Solving problems, making lives better are all worthy goals. Recently in the news there have been talk about diversity in technology.  I am against diversity for diversity sake. People should want to do technology because they love it not to meet a quota. On the flip side I hate seeing barriers to diversity.  When developers attack other developers because they are new, female, some ethnicity other than yours or some other reason, they stifle innovation. They create an environment that makes the atypical developer not want to participate, stifling diversity.

A while back I started following Iris Classon on twitter.  She was new to development and was pretty much self taught. She devoted time to really learn her craft. She sought out mentors and worked hard to mentor new developers. She is a good role model for anyone who wants to get into technology.  I had the chance to meet her a Microsoft Build Conference a while.  You could feel the enthusiasm she had and she wasn’t afraid to share it.  She had (I say had, more on that in a minute) a blog that asked the “stupid” questions that new developers have and she sought to answer those questions.  She was an active member of the community.

Because she is different, when I met her she had bright pink hair (how many developers have pink hair), she drew attention to herself. A lot good but some bad.  The twitter trolls out there started harassing her.  “Experienced” developers, who forgot that they had to start somewhere, gave her a hard for the work that she did.  Remember I said that she wasn’t afraid to share and ask for help.  The community is great place to learn, to innovate and when it turns on one of its own it is sad. Because of these public stress and the stresses of everyday life (I am guessing), she has decided to withdraw from the community. Deleting her Facebook page, removing her blog and pretty soon her twitter feed will be silenced.  Very sad. I enjoy her contributions and now……

I am not really close to her, I only met her once and did not interact with that much (although her arm wrestling match at Build was enjoyable). I do feel that I should say something. So Iris, here is my advice to you (or anyone for that matter). First do what you love. Don’t let anyone discourage you from doing that. Next ignore the negative but not the constructive criticism (that is how you grow).  Take a step back from the community for a while. Rejuvenate yourself. If you feel you need to contribute in the future do (I would look forward to it). Remember Twitter Troll don’t define you and what you do, that is up to you to do. But above all else do give up!!!!!

The sad truth is that there will always be people, in the world, who discriminate. If you let them rule who you are then they win. If you can overcome, you win! Ignore the negative and strive for the positive. You will be missed!

Posted in Computer Science, Leadership, Rants | Leave a comment