Version checking - AquaticInformatics/aquarius-sdk-net GitHub Wiki

The AquariusServerVersion class includes the IsLessThan(AquariusServerVersion other) and Compare(AquariusServerVersion other) predicate methods to quickly compare version numbers correctly to determine if a specific version is older or newer.

If your integration needs to adapt its behaviour based on the server version, this class can sometimes help you work around release-specific quirks.

// Eg. Assume that AQTS 2017.3 introduced a new Foo operation on the Publish API
private static readonly AquariusServerVersion FooApiExistsVersion
                                              = AquariusServerVersion.Create("17.3");
...
if (client.ServerVersion.IsLessThan(FooApiExistsVersion))
{
    // We know we're talking to an older AQTS, which won't have the new API, so don't even try to send the request
    return;
}

// The request should be valid, so go ahead and issue it
var response = new client.Publish.Get(new FooRequest());

Version comparison rules

Version comparison is quite as simple as comparing version strings lexicographically. "3.5" needs to be considered earlier than "17.1.56".

var serverVersion = "3.5";
var myVersion = "17.1.56";

if (serverVersion< myVersion) // Wrong! String sort-order yields incorrect results
{
    Console.WriteLine("Old server version detected!");
}
else
{
    Console.WriteLine("New server version detected!");
}

The above code will do the wrong thing for many types of comparisons.

The AquariusServerVersion.Create(string apiVersion) method takes a dotted-version-string and populates some internal fields to enable efficient comparison:

  • Split the string on '.' boundaries into version components
  • Parse each component as an integer
  • Adjust the first component (the "major" version) to reflect the 20XX.Y.Z naming convention for new AQTS server releases

There is also a ToString() method which recomposes the parsed version into string form again.

Console.WriteLine($"{AquariusServerVersion.Create("17.1.56")}"); // Outputs: 2017.1.56

All of this logic is verified by the unit test class, so you can have confidence that the IsLessThan() and Compare() predicates behave as expected.