License Checks
License checks have a crucial role in the protection of your application.
This guide will explain online and offline license checks, their efficient organization within the application, and the implementation of a grace period.
Prerequisites
Before proceeding, make sure you have completed the Getting Started (C++) or Getting Started (.NET/C#) tutorial and accomplished the following steps:
Initialize LicenseManager (or LicenseHandler) with your configuration using the appropriate settings.
Activate a license for your application.
Implement the mechanism to retrieve the current license.
Local Check
Local check does not require an Internet connection and performs the following actions:
Verify license state
Verify if the license is enabled, active, and valid. If the license is not in a valid state, it will raise LicenseStateException in C++ or the following exceptions in .Net:
LicenseDeletedExceptionLicenseDisabledExceptionTrialLicenseExpiredExceptionLicenseExpiredExceptionLicenseInactiveException
To perform a local check, call the LocalCheck method:
auto license = licenseManager->getCurrentLicense();
license->localCheck();var license = licenseManager.CurrentLicense();
license.LocalCheck();try license.localCheck()manager = LicenseManager(conf)
license = manager.load_license()
license.local_check() // Go SDK v2
license_data, check_resp, err := lh.LocalCheck(true)License license = licenseManager.getCurrent();
license.localCheck();const license = licenseManager.loadLicense();
license.localCheck().then(response => {
console.log('ok');
}).catch(error => {
console.error(error);
});Online Check
Verify if the license is enabled, active, and valid. If the license is not in a valid state, it will raise
LicenseStateExceptionin C++ or the following exceptions in .Net:LicenseDeletedExceptionLicenseDisabledExceptionTrialLicenseExpiredExceptionLicenseExpiredExceptionLicenseInactiveException
Synchronize the consumption of consumption licenses and features. If there is not enough consumption left, it will raise
NotEnoughConsumptionException.Update the license with data from the license server.
Retrieve the most recent installation file for the product.
Register a floating license. If there are no floating slots available, it will raise
MaxFloatingReachedException.
It can throw the exceptions related to connection issues: NetworkException, NetworkTimeoutException, and LicenseServerException. You can implement a grace period to allow using the application without connection to the server for a limited period.
To run the online check call Check method:
License Check Optimization
License checks can take up to a couple of seconds. It is recommended to run them in a background thread.
Perform local checks on every application startup to ensure the user has a valid license.
However, since calling an online check at every start of the application is redundant, we recommend performing it every few days, using the last check date value saved in the license.
If you need to synchronize consumption more often, you can use SyncConsumption and SyncFeatureConsumption methods.
Grace Period
A grace period can be helpful when you don't want to restrict application usage due to online check failures caused by the lack of an internet connection or internal LicenseSpring server issues.
To implement this, define how long it is allowed to use the application without connecting to the server and handle network exceptions accordingly.
The grace period feature is available in C++ SDK from v7.26.0 and in .Net SDK from v7.22.0. It covers License::check, License::syncConsumption, License::syncFeatureConsumption, and License::sendDeviceVariables methods.
By default grace period is 48 hours. You can set another value using:
The License class has methods to check if the grace period started and get the grace period end date:
The grace period starts when one of the covered requests fails and resets after a successful request. The license is currently in its grace period if either it is a non-floating license, or it is a floating license with at least one hour remaining before expiration.
Last updated
Was this helpful?