Tech in the 603, The Granite State Hacker

Intro to Uno Platform

Uno’s free.  Uno is open-source.  Uno could seriously be the next significant disruption in mobile development.

Apologies that I neglected to hit on the conference call for the introductions.  We did get the bulk of the presentation recorded.

On the call:  Jerome Laban, Architect, and Francois Tanguay, CEO of nventive of Montreal, Quebec, Canada. Participants of the Windows Platform App Devs (including myself) were in the audience, asking questions.

To make up for the intro missed in the call, let me begin with the elephant in the room…

What’s “wrong” with Xamarin?

The relatively well known Microsoft tool set called Xamarin enables developers to write a dialect of C# and Xaml to target a variety of platforms including Windows, Windows Mobile, iOS, Android, MacOS and others.

For that reason, Xamarin’s currently a top choice for mobile developers around the world. Xamarin enables developers to target billions of devices.

The problem Xamarin presents is that Xamarin has become its own distinct dialect of .NET-based development.  Xamarin has its own distinct presentation layer called Xamarin Forms. Xamarin Forms as an employee skill set is not the same as a classic Windows developer set.  It’s not exactly the same as a Windows 10 developer skill set.  It’s a different platform, and requires developers that understand it.

Uno Platform reduces the skillset burden in this problem by converging the main skill set on Windows 10 development. Developers with an appreciation for the future of Windows development will definitely appreciate Uno Platform.

Windows Universal Platform (UWP) targets ALL flavors of Windows 10, including some unexpected ones, like Xbox One, and IoT devices running Windows 10 IoT Core.

Uno bridges UWP to iOS, Android, Web Assembly (Wasm), on top of Windows 10. This targets a huge and rapidly growing range of devices… (currently approaching around 3 BILLION… and that might be a low estimate.)

I’d embed the video, but Blogger’s giving me a hard time with the iframe-based embed code… please click this

Link to the video:

Intro to Uno Platform Skype conference recording.

The meetup:
Granite State Windows Platform App Devs
https://www.meetup.com/Granite-State-NH-WPDev/events/251284215/

Uno Platform’s site:
http://platform.uno

Tech in the 603, The Granite State Hacker

Locking Resources in C# for Read/Write Concurrency

In a previous project, I became a big fan of System.Threading.ReaderWriterLockSlim.  It was an excellent way to guard a resource against concurrency in a relatively flexible manner.  

C# has a lock(object) {} syntax for simple concurrency locks, but what if you have a resource that can sometimes be used concurrently, and other times, exclusively?

Enter System.Threading.ReaderWriterLockSlim.  This has a few handy methods on it for guarding code on a non-exclusive (Read) and exclusive (Write) mode, with an upgradeable lock, as well, so you don’t have to release a read lock in order to upgrade it.

This source works just as well in .NET as UWP.

I commented the code enough to try to make it so that someone familiar with ReaderWriterLockSlim and using(IDisposable){} would understand the rest, so without further ado…

https://gist.github.com/GraniteStateHacker/e608eecce2cb3dba0dbf4363b00e941f.js

Tech in the 603, The Granite State Hacker

Windows 10 IoT Core, C# & Azure IoT Hub for New England Microsoft Developers 12/7/2017

Just wanted to say thanks for inviting me to reprise my Boston Code Camp 28 presentation for the group last night (12/7).   I enjoy talking about development anywhere in the Microsoft stack, and I love that Windows 10 IoT Core + Azure IoT Hub spans a good range of it.  I have a bunch of other topics I’d be happy to share, especially in the Windows 10 domain. Check through this blog, I have a post for each that shares slides, but I know the presentation’s a big part of the value of them.

These slides are really only a tweak of the BOSCC28 slides with the NEMD group title. [office src=”https://onedrive.live.com/embed?cid=90A564D76FC99F8F&resid=90A564D76FC99F8F%211283616&authkey=AH0Ai1kfUL_6WKE&em=2&wdAr=1.7777777777777776″]

Tech in the 603, The Granite State Hacker

MVP IoT with Windows 10, C#, Raspberry Pi and Azure IoT Hub

Boston Code Camp 28 is in the books as one of the greatest community events of recent times in my book.  Attendance was fantastic, we had amazing sponsors, and a ton of great speakers, but the thing that really made things hop was attendance.  I’m personally convinced it was the best attended Code Camp I’ve ever participated in.
As a presenter, I don’t often get to attend as many of the amazing presentations as I’d like, but yesterday I found myself especially regretting that… there was just so much great content from so many great presenters. I did manage to get into more sessions than I usually do… how could I not?

Sure, you get a few “look at this cool stuff I can do” presentations.  These are great for folks looking for inspiration on the tough challenges.  I love the spirit of “look at this cool stuff you can do (if you apply your skills in a modestly different direction)”.
This is why I do this MVP IoT presentation.  This presentation is about taking skills you already know and love (namely C# development) and applying them to what’s classically though of as “embedded” development.  Yes, there’s overhead in this approach…  you might have to use hardware that’s slightly better equipped to handle Windows 10 IoT Core such as the Raspberry Pi 2b & 3b… but the difference is mute at small scale, and masked at large scale by not having to have a separate team with different skills. 

IoT apps on the Windows 10 IoT Core platform ARE Windows 10 apps.


The point I always try to drive home is IoT apps on the Windows 10 IoT Core platform ARE Windows 10 apps.  The very same exe you compile for your embedded device runs just as well on laptop, desktop, server, Windows 10 phone, et al.

I do regret the couple snags I had during my demos.  Still, someone approached me after the presentation with the idea that I should pre-record portions of my presentation in order to avoid these kinds of things.  I like to run live for several real reasons.  1)  I’m a coder, not a professional presenter… I don’t often have time to polish my presentations to that level.  2)  Glossing over rough edges hides what development is.  Development is tough.  You have to have backup plans and contingencies.  My Raspberry Pi didn’t want to connect to the guest WiFi, so I fell back to plan B, and moved on.  It’s a real world scenario;  you hit a snag, but keep pressing on.

IoT is already about the last mile of the Sci-fi story, bringing Internet omnipotence to the fringes of reality, enabling the “Computer” of Star Trek (or the Cortana of the modern desktop) to reach it’s potential (hopefully without becoming Skynet).

It’s the stuff of science fiction… but it’s not fiction.

Visual Studio 2017’s ability to debug into a remote embedded device and make hot changes to a running executable is beyond top notch; it’s the stuff of science fiction… but it’s not fiction.

[office src=”https://onedrive.live.com/embed?cid=90A564D76FC99F8F&resid=90A564D76FC99F8F%211283217&authkey=AKQG9LbQcNcUSkk&em=2&wdAr=1.7777777777777776″]

If you look through my post history, you’ll see how this presentation has evolved over the past decade.  It’s been an interesting evolution…  starting with connecting Windows Phone 7 to SharePoint.  Then Windows Phone 8 and SharePoint online (and the story got really muddy for a bit there).  Then CSOM hit and smoothed out the SharePoint side of things.  I changed the story to Field Enablement using Xamarin for iOS, Android, and Windows Phone with SharePoint as a back end for a bit. (It’s a surprisingly compelling story, even if it’s only academic).  Eventually I started focusing on UWP for Windows 10, and my love of small form factor development drew me back to Raspberry Pi. 
Finally, I’ved bridged off of SharePoint and started talking about Azure IoT Hub, which is the modern accepted best practice in the domain of this development stack.  This change happened so relatively quickly that if you notice, the synopsis for the session didn’t mention it.  (  https://www.bostoncodecamp.com/CC28/sessions/details/16540 )

One can explore the code I developed for the demo at git hub, here:
That leads me to my final bit:  I am sorry I ran out of time in my presentation.  I was so psyched to show how to send telemetry back to Azure IoT Hub, and while I got to step through the code that sends updated reports, I did not get to explore any of what that looks like in the Azure IoT Hub portal, and didn’t get to explore the event-driven API on the embedded side that allows you to send code with Device Twin down to a the device.
Here’s the event that commits the post:

        private async void iotHubButton_Click(object sender, RoutedEventArgs e)

{

try

{

using (var client = DeviceClient.CreateFromConnectionString(

$"HostName=BOSCC-IOTHub.azure-devices.net;DeviceId=GraniteStHacker;SharedAccessKey={Credentials.LuisAccessKeyFromAzurePortal}",

TransportType.Mqtt))

{

var twinProperties = new TwinCollection();

twinProperties["MeasuredTemperature"] = manager.MeasuredTemperature;

twinProperties["HeaterPowerOn"] = manager.HeaterPowerOn;

twinProperties["ACPowerOn"] = manager.ACPowerOn;

twinProperties["Device_BOSCC"] = DateTime.Now.ToString();

await client.UpdateReportedPropertiesAsync(twinProperties);

Console.WriteLine("Done");

}

}

catch(Exception ex)

{

Console.WriteLine(ex);

}

}

}


Click the image below to see the device I was using for the demo in Azure IoT Hub’s Device Twin view.

Here’s the resulting Device Twin JSON:
{
  “deviceId”: “GraniteStHacker”,
  “etag”: “AAAAAAAAAAE=”,
  “version”: 8,
  “status”: “enabled”,
  “statusUpdateTime”: “0001-01-01T00:00:00”,
  “connectionState”: “Disconnected”,
  “lastActivityTime”: “0001-01-01T00:00:00”,
  “cloudToDeviceMessageCount”: 0,
  “authenticationType”: “sas”,
  “x509Thumbprint”: {
    “primaryThumbprint”: null,
    “secondaryThumbprint”: null
  },
  “properties”: {
    “desired”: {
      “$metadata”: {
        “$lastUpdated”: “2017-11-14T01:48:45.8322179Z”
      },
      “$version”: 1
    },
    “reported”: {
      “MeasuredTemperature”: 74,
      “HeaterPowerOn”: true,
      “ACPowerOn”: false,
      “Device_BOSCC”: “11/18/2017 8:34:08 AM”,
      “$metadata”: {
        “$lastUpdated”: “2017-11-18T16:34:20.1258514Z”,
        “MeasuredTemperature”: {
          “$lastUpdated”: “2017-11-18T16:34:20.1258514Z”
        },
        “HeaterPowerOn”: {
          “$lastUpdated”: “2017-11-18T16:34:20.1258514Z”
        },
        “ACPowerOn”: {
          “$lastUpdated”: “2017-11-18T16:34:20.1258514Z”
        },
        “Device_BOSCC”: {
          “$lastUpdated”: “2017-11-18T16:34:20.1258514Z”
        }
      },
      “$version”: 7
    }
  }
}

Tech in the 603, The Granite State Hacker

Intro to Natural Language Processing with LUIS

Here’s the slides for the presentation I’m doing 11/16/2017 at the Granite State Windows Platform Developers (@WPDevNH) meeting in Salem, NH (at the Microsoft Store)

The group is primarily about Windows 10 app development (implying Universal Windows Platform, UWP).  That said, the group’s been begging for sessions on AI and related services for some time.

Since I’ve been helping a client navigate LUIS lately, I figured an into to the LUIS service would be a nice way to break into this very useful service.

I reserve the right to tweak these slides up until I present them on Thursday, November 16th, 2017.

[office src=”https://onedrive.live.com/embed?cid=90A564D76FC99F8F&resid=90A564D76FC99F8F%211282855&authkey=APp8wuFX2hkqevw&em=2″ width=”402″ height=”327″]Please Join Us! RSVP HERE:
https://www.meetup.com/Granite-State-NH-WPDev/events/243099117/

Tech in the 603, The Granite State Hacker

UWP Equivalent for HttpUtility.ParseQueryString

Getting ready for my LUIS presentation at the Granite State Windows 10 Platform Devs Users Group (@WPDevNH), it made sense to demo LUIS using UWP rather than .NET classic.  (Join us, 11/16 at the Microsoft Store in Salem, NH…  https://www.meetup.com/Granite-State-NH-WPDev/events/243099117/ )

For a demo related to LUIS querying, I needed an alternative to System.Web.HttpUtility.ParseQueryString.  (based on this demo:  https://docs.microsoft.com/en-us/azure/cognitive-services/LUIS/luis-get-started-cs-get-intent )

I did a simple decorator of a Dictionary, adding a constructor to parse using WwwFormUrlDecoder, and overriding the ToString() to put it back together…

I whipped one up relatively quickly, but decided this would be a decent quick post.  Here’s my alt code:

usingSystem.Collections;
usingSystem.Collections.Generic;
using System.Net;
using System.Text;
usingWindows.Foundation;
namespaceLUIS_Examples
{
    public class ParseQueryString : IDictionary<string, string>
    {
        private IDictionary<string, string> _internalDictionary = new Dictionary<string, string>();
        public ParseQueryString(string queryString) :
            base()
        {
            var decoder = new WwwFormUrlDecoder(queryString);
            foreach (var item in decoder)
            {
                _internalDictionary.Add(item.Name, item.Value);
            }
        }
        public override string ToString()
        {
            var sb = new StringBuilder();
            foreach (var aPair in _internalDictionary)
            {
                sb.AppendFormat(“{0}={1}”, WebUtility.UrlEncode(aPair.Key), WebUtility.UrlEncode(aPair.Value));
            }
            return sb.ToString();
        }
        public string this[string key] { get => _internalDictionary[key]; set { _internalDictionary[key] = value; } }
        public ICollection<string> Keys => _internalDictionary.Keys;
        public ICollection<string> Values => _internalDictionary.Values;
        public int Count => _internalDictionary.Count;
        public bool IsReadOnly => _internalDictionary.IsReadOnly;
        public void Add(string key, string value)
        {
            _internalDictionary.Add(key, value);
        }
        public void Add(KeyValuePair<string, string> item)
        {
            _internalDictionary.Add(item);
        }
        public void Clear()
        {
            _internalDictionary.Clear();
        }
        public bool Contains(KeyValuePair<string, string> item)
        {
            return _internalDictionary.Contains(item);
        }
        public bool ContainsKey(string key)
        {
            return _internalDictionary.ContainsKey(key);
        }
        public void CopyTo(KeyValuePair<string, string>[] array, int arrayIndex)
        {
            _internalDictionary.CopyTo(array, arrayIndex);
        }
        public IEnumeratorstring, string>> GetEnumerator()
        {
            return _internalDictionary.GetEnumerator();
        }
        public bool Remove(string key)
        {
            return _internalDictionary.Remove(key);
        }
        public bool Remove(KeyValuePair<string, string> item)
        {
            return _internalDictionary.Remove(item);
        }
        public bool TryGetValue(string key, out string value)
        {
            return _internalDictionary.TryGetValue(key, out value);
        }
        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)_internalDictionary).GetEnumerator();
        }
    }
}

Tech in the 603, The Granite State Hacker

UWP App Samples

I realized as I was presenting a guided tour of UWP App Samples that I’d come full circle on a set of presentations around my experience building Windows 10 UWP apps.   The overall process was kicked off in three decisions. 

1)  pick a framework (we settled on Prism + Unity),   

2) pick a control library (we went with the UWP Community Toolkit (which is since released 2.0 by the way, updated for 1710, Fall Creators Update… there may be another presentation in the works here)).

Finally,
3) we consulted the UWP App Samples.   ( https://github.com/Microsoft/Windows-universal-samples )

When it comes down to it, our goal was very ambitious, and we couldn’t have accomplished what we did without these three key pieces.   I’ve presented each of them over the past several months at the Granite State Windows Platform App Devs meetup. ( https://www.meetup.com/Granite-State-NH-WPDev/ )

At the time of the presentation, the categories in the Open Sourced UWP App Samples project were these:

  • App Settings,
  • Audio/Video/Camera,
  • Communications,
  • Contacts and Calendar,
  • Controls/Layout/Text,
  • Custom User Interactions,
  • Data,
  • Deep links and app-to-app Communication,
  • Devices and Sensors,
  • Files/Folders/Libraries,
  • Gaming, Globalization and Localization,
  • Graphics and Animation,
  • Holographic,
  • Identity/Security/Encryption,
  • Launching/background tasks,
  • Maps/Location, Navigation,
  • Networking/Web Services,
  • Platform Architecture,
  • Speech/Cortana,
  • Threading,
  • Tiles/Toasts/Notifications

If your app will do anything remotely associated with any of the above functionality, you need to consult the related sample projects before beginning.  They aren’t production-ready samples, but they are good samples, nonetheless.

These slides don’t do any justice at all to the UWP Sample Apps project, it was really just something to throw on the big screen while folks gathered.

[office src=”https://onedrive.live.com/embed?cid=90A564D76FC99F8F&resid=90A564D76FC99F8F%211281880&authkey=&em=2&wdAr=1.7777777777777776″]

Tech in the 603, The Granite State Hacker

UWP Community Toolkit in the Wild

On August 17th, I reviewed use of the UWP Community Toolkit in practical application, used in several privately published apps. These apps were commissioned by Hewlett Packard to illustrate commercial uses of the HP Elite X3 Windows 10 Mobile phone. We checked out the code behind these apps with permission from HP.

The apps themselves focus on three core verticals:
1) Public Safety – apps to support officers in the field
2) Field Service – supporting a cable field service technician
3) Home Health – supporting a visiting care provider.

All show off Windows 10 UWP as a versatile platform, capable of easily adapting to phone, tablet, or desktop, as well as the HP Elite X3’s additional ability to support various hardware expansion jackets and docking options.

The UWP Community Toolkit is an open source project designed to make Windows 10 the easiest platform to build great apps for. More information can be found here:

http://www.uwpcommunitytoolkit.com/

The official UWP CTK demo app is here:
http://aka.ms/uwptoolkitapp

The presentation itself was all demos, digging in on the CTK toolkit sample app, looking at it in a locally cloned git repo, and showing how we used the same controls in the X3 demo apps.

The UWP CTK is a great set of tools to jumpstart Windows 10 Dev with.  

Our next meeting on September 21st, (2017) we’ll take a look at another great “Hit the ground running” UWP resource, the App Samples.

Tech in the 603, The Granite State Hacker

Rise of the Smart App

Microsoft didn’t talk much about the Windows Phone at Build 2016.  If you think that’s news, you’re missing the point.

As Microsoft re-defines “Mobile First, Cloud First” they declare shenanigans on the idea that the tech world revolves around phone and tablet.  Yes, tablet and smartphone are mature, first-class citizens, now, but they’re not above laptops, PCs, or other computing devices, as Apple (and perhaps even Samsung) might have you believe.

There’s no denying that Microsoft lost the battle for smartphone market share.  RIM’s Blackberry, considered a relic of the primordial smartphone market, is all but forgotten. Microsoft was pushing Windows Phone as significant competitor, yet, with about the same market share as Blackberry, no one really took their smartphone offering seriously. 

Until Windows Phone’s recent convergence with the PC on the universal Windows 10 OS, Windows Phone had no more competitive edge than Blackberry, either.  Sadly, this new competitive edge comes too little, too late. Or has it?

Several years ago, in a very sly move, Apple narrowed and laser-focused the global technology mindset on a much smaller battle… one that it was well positioned in. Apple then equated the battle to the war… They made it all about the smartphone/tablet market.  (I don’t think Apple counted on Android, but it didn’t matter… in terms of market share, Android won, but in terms of profitability, Apple won.)  Billions of dollars can’t be wrong, so Microsoft tried to position itself in Apple’s vision, and let itself get dragged around for years… 

Until now.

By connecting Mobility with Portability, Microsoft is driving the scope of technology mindshare again, and are driving it back out to a scale Apple will have to struggle to position itself in. Apple made good smartphones.  Cool beans.

With its converged “Universal” Windows 10 platform, Xamarin portability, and mature cloud offerings replete with machine learning, Microsoft is targeting a much broader “smart app” market… Smart Apps are apps that make any device (keyboard, mouse, display/touchscreen, microphone, pen, scanner, camera, video recorder/editor, audio mixer, cell phone, media player, whiteboard, virtual/augmented reality, what have you) into a smart device.  (Notice anything missing here?  perhaps cars…  but it’s hard to imagine that won’t change in the next few years…  after all, cars (e.g. BMW) did get mentioned at Build.) 

The smartphone isn’t irrelevant, it’s just not the whole pie. The reality is that Microsoft is not going to exclude phones from Windows 10 now or any time soon. 

Smartphone prominence is not innovation superiority.

So, how does this make you feel?

Tech in the 603, The Granite State Hacker

Mobile First, Cloud First as Redefined in Build 2016

There were a number of very cool announcements made at Microsoft Build’s 2016 kickoff today, Wednesday, March 30th.  On first brush, one might not notice the common theme across the announcements, however.

These things may seem disconnected, but if you look again, they’re not… nor are the other less obviously connected major announcements such as:

Microsoft has been promising Mobile First, Cloud First for a long time. Until today, there’s been a consensus that Mobile First meant Tablet and Phone…  as in those hardware form factors get updates and features before classic alternatives.  Today Satya Nadella, CEO of Microsoft, addressed the developer crowd and clarified (or perhaps more accurately “redefined”) what “Mobile First” really means.

Mobile First, Cloud First has morphed to mean something more like “Portable First, Cloud First”, with portable referring directly to the Universal Windows Platform…  write your code once, and the user can take it to any device (desktop, laptop, phone, IoT) and use it as naturally as possible with the whatever human interface device is available (keyboard, mouse, touch, ink, voice, text, etc)…

And there is, indeed, how all the announcements fit together. 

All of the announcements made today talk about how Microsoft is diversifying the human interface, yet keeping the context of all your work and play available across all devices.  Your apps are there, and they work just as naturally with voice commands as they do with ink. 

Note that keyboard and mouse are relatively unnatural compromises in human interface paradigm, and their use will be diminished in the future. 

If pen and paper is the natural choice, Ink will replace it. 

If voice makes sense, it will be available.

If an intelligent actor might assist you, Cortana and your trusted “Network of Experts” (Apps and BotFX bots) are there. If a virtual or augmented reality makes sense, your apps will join you on Hololens. 

If an Xbox controller is the right choice, no problem. 

All of these things can be enhanced significantly with DirectX 12, even for non-games.

And the Cloud will interlink them naturally so that you can flip from tablet to Hololens without skipping a beat. (in some ways, live process migration is really becoming a reality;  when the apps are the same across every deployed device, the only thing that needs to transfer from device to device is user data, and that’s happening via cloud.)

One segment that didn’t see much love today:  the Web.  Or did it?  Bash for Windows 10 is a bit of a stretch to connect to the coming shift, but really, it is meant to make it easier for developers to deliver web-based, cloud-hosted solutions using Visual Studio to non-Windows hosts.  Indirectly this will aid in the creation of services that might support Bots made with the BotFX, for example.  All of this is based predominantly on JSON over REST / HTTP.

Some would point out that Windows 10 Mobile (formerly Windows Phone) didn’t get any stage time, either, but the reality is that Microsoft no longer sees the smartphone edition of Windows to be a separate thing.   Windows 10 is converging on “The Best Windows Ever”, Windows 10… smartphone or not.