Refresh of MTConnect Client SDK

Last week I had a call with a couple guys looking to implement an MTConnect Client into their system.  I decided to take that as an opportunity to revisit some MTConnect SDK code I wrote a few years back and apply at least a little modernity to the code base.

So what I did was:

The source code on Github contains a sample Client application that lets you quickly view, graph and store MTConnect data.  This is what it looks like when graphing X and Y axis positions from the public, sample MTConnect Agent.

mtconnect_client

Unit Testing REST Clients

I frequently seem to end up writing code that calls REST services – on pretty much every project I work on anymore.  Since I seem to be often writing the same code over and over, I’m working on a library (well a couple libraries) to simplify things and consolidate all that I typically come across.

A challenge in writing a REST client is how to easily unit test it.  I don’t want to have to stand up a server somewhere just to run simple tests, especially if the server needs to return valid and invalid data that needs to change with the test.

So I create a really simple, yet really useful class I’m calling SimpleServer and it’s available as a gist.  It basically allows you to define a URI and then set callback methods for the common HTTP verbs (GET, PUT, POST and DELETE).

Let’s say you want to test out a GET operation.  In the example below the RestConnector encapsulates the goo required to make the HTTP call, but the cool part is how it uses the SimpleServer to test an expected response to a GET at the API root.

        [TestMethod]
        public void GetNoCreds()
        {
            var uri = "http://localhost:8080/";
            var response = "Hello!";

            using (var svr = new SimpleServer(uri, (request) =>
            {
                return response;
            })
            )
            {
                svr.Start();

                using (var rc = new RestConnector(uri))
                {
                    Assert.IsNotNull(rc);
                    var result = rc.GetString("/");

                    Assert.AreEqual(response, result);
                }
            }
        }

Here I’m using the default handler parameter for a GET, but you can individually pass in Func’s for GET, PUT, POST and DELETE which makes testing even fairly complex scenarios both quick and really, really easy.

New MQTT library

I don’t know if the development world needs another .NET MQTT library, but I wrote one a few years ago and finally decided to dust it off and publish it in source form and as a NuGet package.  I considered doing a PCL version, but then I looked at the source and was reminded that the library heavily uses sockets and threads and figured that’s a bit more work than I feel like putting into it right now.

It’s fully functional and pretty solid. I used it in a production app, so it’s not just an experimental library.

Source code is on GitHub.

Package is in NuGet [id: opennetcf-mqtt]

NuGet Updates across the board

As I mentioned a couple weeks ago, I was in the process of unraveling a load of projects that were tied together, trying to get them all into separate code repositories.  I finally got that done and got them all published to NuGet (well not the CF versions of those that support the CF – patience).

And so you now have available:

 

New Open Source Projects

I’m working on a new application that’s going to be open source.  Once it’s a bit further along I’ll provide more details, but essentially it’s a paperless forms solution that encompasses a WPF desktop app, a self-hosted ASP.NET WebAPI service and a Xamarin Forms mobile app all working together.

In the process of getting the foundation up and running, I’m moving a lot of stuff over to Github, but more importantly I’m updating, extending, and creating whole new libraries that can be used for other stuff.  These, too, are open source.

What’s being updated?

  • OpenNETCF.ORM
    I’m primamrily working with SQLite, but I’ve already uncovered and fixed some issues around one-to-many entity relationships
  • OpenNETCF.IoC
    Work and updates to make it more Xamarin/PCL friendly
  • OpenNETCF Extensions
    This thing has been stable and in heavy production use for years.  Support continues for it with some minor changes and improvements in the Validation namespace so far.

What’s New?

  • OpenNETCF.Xamarin.Forms
    Adding things that I’m finding missing or hard in Xamarin’s BCL.  Things like “hey, scale this label to the right size depending on my screen resolution, on any platform”.  Thanks go out to Peter Foot for pointing me in the right direction there.
  • OpenNETCF.MVVM
    No idea why Xamarin didn’t provide a basic navigation framework.  I created one.  Is it awesome?  I don’t know – but it works for my use case (plus 3 other apps I’ve done with it).
  • OpenNETCF.Google.Analytics (moving to it’s own repo soon)
    Again, seems like low-hanging fruit here.  Why isn’t it in the box?  I don’t know, but there’s now a simple, open source library for it.

One note – these are all in active development, so don’t expect a NuGet package updates on them for at least a little while (end of May?).  I’d like to get features in and stable before rolling them out.

Feedback welcome. Testers wanted.  Enjoy.

ORM Migration to Github

With the announced mothballing of Codeplex, I’m working to migrate at least some of the open source projects I have to Github.

It turns out I own 29 projects over on Codeplex. Some of them, like the barcode decoding library, were simply learning exercises.  Some of them were idea that I never found time to actually work on.  Many are for technologies that are now dead (I’m looking at you Compact Framework!). But some are actually useful and I still use quite regularly.

As I pull them into Github, I’m also taking the time to merge in local forks I have from doing other projects as well as doing NuGet releases.  Turns out that this is a fairly large undertaking, but it’s forcing me to do some cleanup that’s long overdue.

So yesterday I pulled over the OpenNETCF ORM.  For those who don’t know, it’s a lightweight ORM (way, way, way lighter than Entity Framework) that supports code first, data first *and* I don’t know my data structure until run time, which no other ORM I’ve seen supports.  It has support for MySQL, SQLite, SQL Server, SQL Compact, Oracle, Azure Table Service and Dream Factory out of the box.  Adding new implementations, especially anything that had an ADO provider already, is really easy.

So, if you’re a current ORM user, or looking for a simple ORM for a .NET project, take a look.

OpenNETCF.Google.Analytics improvements

My original plan when building up the OpenNETCF Google Analytics library (which provides GA support to Xamarin Forms apps) was to make it 100% PCL.  A fine goal, but it turns out that it was unrealistic for a single reason: the User Agent string.  My original implementation had a “user agent generator” that successfully would tell GA whether you were using an Android or iOS device, but getting any finer grained was really not a simple task.  I considered – very, very briefly – keeping a long list of user agent strings and trying to figure out which one to use based on the platform, but that sounded like an unmaintainable nightmare.  Instead, I had to create a simple native piece for each platform for something that seems pretty basic.

In iOS, this was all that was needed:

using (var webView = new UIWebView(CGRect.Empty))
{
    m_userAgent = webView.EvaluateJavascript("navigator.userAgent");
}

In Android it was even less:

m_userAgent = Java.Lang.JavaSystem.GetProperty("http.agent")

But it had to be done native.

I’ve updated the library in NuGet, and now GA will show you exactly what type of device was connected and tracking, which I feel was more than worth the added complexity.