Interface IActivationKeysLicenseProvider
Defines methods for license checks and license activation using activation keys.
Namespace: Sartorius.SAF.Licensing
Assembly: Sartorius.SAF.Licensing.dll
Syntax
[InheritedExport]
public interface IActivationKeysLicenseProvider : ILicenseProvider, IDisposable
Remarks
If you get a System.ComponentModel.Composition.ImportCardinalityMismatchException when trying to import the ILicenseProvider interface, you have to add an actual license provider implementation via nuget. E.g. Sartorius.Licensing.Mirage.
A license provider can require a configuration before it can be imported. For the configuration options see the specific license provider implementation you are using. You will get a System.ComponentModel.Composition.CompositionException during runtime when a required configuration object is missing. When required configuration entries are missing in the configuration object a System.Configuration.ConfigurationErrorsException is thrown at runtime. A class deriving from LicenseConfiguration will be exported automatically by using an inherited export.
A license provider can provide a typed configuration object you can derive from, allowing for a more convenient configuration workflow.
Examples
The following example shows how to import a license provider via MEF.
[ImportingConstructor]
public LicensingExamples(IActivationKeysLicenseProvider licenseProvider)
{
this.keysLicenseProvider = licenseProvider;
}
The following example shows how to configure the Mirage license provider (MirageLicenseProvider).
public class MyConfiguration : LicenseConfiguration
{
public MyConfiguration()
{
Add("ReadKey", LicensingTools.ReadKey);
}
}
Generally a license provider will also provide a typed configuration object which can be used more conveniently.
public class MyTypedConfiguration : MirageLicenseConfiguration
{
public override SecureString ReadKey => LicensingTools.ReadKey;
}
The following example shows how to apply an activation key to activate a feature.
try
{
this.keysLicenseProvider.ApplyActivationKeys(key);
}
catch (LicenseKeysException ex)
{
// show error message to the user
if (ex.InvalidKeys != null)
{
// show info about invalid keys.
foreach (var invalidKeyInfo in ex.InvalidKeys)
{
}
if (ex.UsedKeys != null)
{
// show info about used (but not activated keys). These keys cannot be used again.
}
}
}
//
// .. see other exceptions during ApplyActivationKeys().
//
The following example shows how to get information about activation keys.
try
{
var result = this.keysLicenseProvider.GetActivationKeyInfos(key1, key2);
// read the key infos
foreach(var keyInfo in result)
{
if (keyInfo is InvalidKeyInfo)
{
// show invalid key information
// ...
}
else if (keyInfo is ProtectionKeyInfo)
{
// show protection key information
// ...
}
else if (keyInfo is MirageFeatureKeyInfo)
{
// show feature key information
// ...
}
}
}
catch (InvalidLicenseException)
{
// show error message to the user
}
//
// .. see other exceptions during GetActivationKeyInfos().
//
Methods
View SourceApplyActivationKeys(String[])
Apply the given activation keys.
Declaration
void ApplyActivationKeys(params string[] keys)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | A license keys to be activated. |
Examples
The following example shows how to apply activation keys for the availability of a feature.
try
{
this.keysLicenseProvider.ApplyActivationKeys(key);
}
catch (LicenseKeysException ex)
{
// show error message to the user
if (ex.InvalidKeys != null)
{
// show info about invalid keys.
foreach (var invalidKeyInfo in ex.InvalidKeys)
{
}
if (ex.UsedKeys != null)
{
// show info about used (but not activated keys). These keys cannot be used again.
}
}
}
//
// .. see other exceptions during ApplyActivationKeys().
//
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
LicenseKeysException | One or more of the activation keys specified by |
InvalidLicenseException | The license file is damaged or incomplete. |
InvalidLicenseFileException | The license file is not a valid license file. |
LicenseException | An unknown exception occurred. See the System.Exception.InnerException for details. |
LicenseFileAccessException | The license file could not be accessed. |
SystemDateChangedException | The system date was tampered with and the application is locked. |
GetActivationKeyInfos(String[])
Get information about the provided activation keys.
Declaration
IEnumerable<KeyInfo> GetActivationKeyInfos(params string[] keys)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The license keys that should be analyzed. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<KeyInfo> | A list of KeyInfos containing all information provided by the license |
Examples
The following example shows how to get a information about activation keys.
try
{
var result = this.keysLicenseProvider.GetActivationKeyInfos(key1, key2);
// read the key infos
foreach(var keyInfo in result)
{
if (keyInfo is InvalidKeyInfo)
{
// show invalid key information
// ...
}
else if (keyInfo is ProtectionKeyInfo)
{
// show protection key information
// ...
}
else if (keyInfo is MirageFeatureKeyInfo)
{
// show feature key information
// ...
}
}
}
catch (InvalidLicenseException)
{
// show error message to the user
}
//
// .. see other exceptions during GetActivationKeyInfos().
//
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|
InvalidActivationKeyException | One or more of the activation keys specified by |
InvalidLicenseException | The license file is damaged or incomplete. |
InvalidLicenseFileException | The license file is not a valid license file. |
LicenseException | An unknown exception occurred. See the System.Exception.InnerException for details. |
LicenseFileAccessException | The license file could not be accessed. |
SystemDateChangedException | The system date was tampered with and the application is locked. |