.NET example
A simple .NET application that checks-out a single license
QuidLM discovers, validates, and parses licenses. To take advantage of that functionality in your application, you need to
-
Initialize QuidLM. This is done by creating an
Apiobject from theQlmnamespace. You can use this opportunity to provide the user's credentials. They come into play because licenses can be configured to be available only to a subset of users. You may set the user email and password tonullif you do not intend to use this functionality. If you initialize the license system without specifying the user's email and password, QuidLM will not provide those licenses to your application.string user_email = null, password = null; var api = new Qlm.Api(user_email, password); // can also omit the arguments - they are null by defaultIf initialization encounters an error, the
Qlm.LicenseInitErrorexception is thrown, and its.Messageproperty explains the issue. -
Grab the license. The
api.CheckoutLicensemethod takes two inputs - the license name and the version. The license name is typically just the name of your product. The license version, if provided, should be in themajor.minorformat. QuidLM treats this input as the minimum license version that your application is willing to accept. Typically, you pass your application’s current version for this parameter. This ensures that newer licenses enable older applications, but not vice versa — which is usually the desired behavior. If that is not what you want, you can hard‑code the version to "1.0" or another constant.string product_name = "MyProduct", min_version = "3.1"; Qlm.License license = api.CheckoutLicense(product_name, min_version);If the requested license is not available,
Qlm.LicenseCheckoutErrorexception is thrown, and your application may want to catch it to explain the error to the user and exit. Otherwise, theQlm.Licenseobject contains useful information about the license, such as its expiration date (license.expiry) and its custom parameters, available vialicense.properties, which holds aDictionaryof key-value pairs you can use to configure application behavior. For example, you can enable some features based on the presence of certain parameters: e.g.,trial-license=truemay prompt your application to display the "trial copy" badge. One other typical use of such a parameter is to limit the application performance, as inmax-threads=10.The license is released when the
licenseobject is destroyed or when itsDisposemethod is called.
The above are the required parts, but you can also take advantage of optional features, such as logging and
license revocation. These additional features are demonstrated in the sample applications shipped with QuidLM.
The dotnet_client application is a more fully featured example, which can also
be used for testing. It is a command line application that checks out the license specified
on the command line for the specified number of seconds and prints licensing information. The
comments in the source code explain standard functionality, such as initialization and license checkout,
and introduce logging. The example is cross-platform - QuidLM ships
with libqlm_client.so and qlm_client.dll libraries to support both Windows and UNIX systems.
/// Dotnet_client application: grab the specified license for
/// the specified length of time and print the licensing information.
using System;
using System.Threading; // for Thread.Sleep
namespace QlmExample
{
class LicenseClient
{
static int Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine(
"Expected some inputs on the command line.\n\n" +
" product_name: the product that you need the license for [required]\n" +
" min_version: the minimum version of the product, in the major.minor format [1.0]\n" +
" duration: exit application after this many seconds [2]\n");
return 1;
}
string product_name = args[0];
string minimum_product_version = args.Length < 2 ? "1.0" : args[1];
int duration = args.Length < 3 ? 2 : int.Parse(args[2]);
// log licensing errors
// Qlm.Api.SetLogLevel(Qlm.LogLevel.err);
// alternatively, set the environment variable: QLM_LOG_LEVEL=err
// Licenses can be configured to be available only to a set of users.
// If you initialize the license system without specifying the user's email and password, you will never receive those licenses.
string? user_email = null, password = null;
var api = new Qlm.Api(user_email, password);
try
{
using (var license = api.CheckoutLicense(product_name, minimum_product_version))
{
Console.WriteLine($"Got license for product version {license.product_version}.");
Console.WriteLine($"Expiring {license.expiry}.\nFloating: {license.is_floating}.\nLicense properties:");
foreach (var kv in license.properties)
Console.WriteLine($" {kv.Key}: {kv.Value}");
Thread.Sleep(duration * 1000);
Console.WriteLine("Returning the license");
// the license is released when it is destroyed or its Dispose method is called
}
}
catch (Qlm.LicenseCheckoutError exc)
{
Console.WriteLine($"Exception: {exc}");
return 2;
}
return 0;
}
}
}