BabelLicenseManager

Namespace: Babel.Licensing Assembly: Babel.Licensing.dll

Provides properties and methods to manage a ILicenseProvider. This class cannot be inherited.

public sealed class BabelLicenseManager

Inheritance

objectBabelLicenseManager

Inherited Members

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

BabelLicenseManager()

public BabelLicenseManager()

Properties

CurrentContext

Gets the current , which specifies when you can use the licensed object.

public static ILicenseContext CurrentContext { get; }

Property Value

ILicenseContext

Methods

GetLicenseProvider(Type)

Gets a registered license provider of a given type.

public static ILicenseProvider GetLicenseProvider(Type type)

Parameters

NameDescription

type Type

A

Returns

NameDescription

The license provider instance.

IsLicensed(Type)

Returns whether the given type has a valid license.

public static bool IsLicensed(Type type)

Parameters

NameDescription

type Type

The to find a valid license for.

Returns

NameDescription

true if the given type is licensed; otherwise, false.

Examples

// Register the license provider before calling any BabelLicenseManager validation method
BabelLicenseManager.RegisterLicenseProvider(typeof(MyApp), new BabelFileLicenseProvider());

// Check if MyApp type is licensed
if (BabelLicenseManager.IsLicensed(typeof(MyApp)))
{
	// MyApp is licensed
}

IsLicensedAsync(Type, CancellationToken)

Async method that returns whether the given type has a valid license.

public static Task<bool> IsLicensedAsync(Type type, CancellationToken cancellationToken = default)

Parameters

NameDescription

type Type

The to find a valid license for.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

true if the given type is licensed; otherwise, false.

IsValid(Type)

Determines whether a valid license can be granted for the specified type.

public static bool IsValid(Type type)

Parameters

NameDescription

type Type

A that represents the type of object that requests the license.

Returns

NameDescription

true if a valid license can be granted; otherwise, false.

IsValid(Type, object, out ILicense)

Determines whether a valid license can be granted for the specified instance of the type. This method creates a valid License.

public static bool IsValid(Type type, object instance, out ILicense license)

Parameters

NameDescription

type Type

A that represents the type of object that requests the license.

instance object

An object of the specified type or a type derived from the specified type.

license ILicense

A that is a valid license, or null if a valid license cannot be granted.

Returns

NameDescription

true if a valid license can be granted; otherwise, false.

RegisterLicenseProvider(Type, ILicenseProvider)

Registers the license provider.

public static void RegisterLicenseProvider(Type type, ILicenseProvider provider)

Parameters

NameDescription

type Type

A

The license provider instance.

Examples

// Register the license provider before calling any BabelLicenseManager validation method
BabelLicenseManager.RegisterLicenseProvider(typeof(MyApp), new BabelRegistryLicenseProvider());

// Validate the license using the RegistryLicenseProvider
ILicense license = BabelLicenseManager.Validate(typeof(MyApp), this);

Validate(Type)

Determines whether a license can be granted for the specified type.

public static void Validate(Type type)

Parameters

NameDescription

type Type

A that represents the type of object that requests the license.

Examples

// Register the license provider before calling any BabelLicenseManager validation method
BabelLicenseManager.RegisterLicenseProvider(typeof(MyApp), new BabelRegistryLicenseProvider());

// Validate the license using the BabelRegistryLicenseProvider
try
{
    ILicense license = BabelLicenseManager.Validate(typeof(MyApp));
    // ...
}
catch (BabelLicenseException ex)
{
	// Handle license validation errors
}

Exceptions

NameDescription

A License cannot be granted.

Validate(Type, object)

Determines whether a license can be granted for the instance of the specified type.

public static ILicense Validate(Type type, object instance)

Parameters

NameDescription

type Type

A that represents the type of object that requests the license.

instance object

An object of the specified type or a type derived from the specified type.

Returns

NameDescription

An valid license.

Examples

// Register the license provider before calling any BabelLicenseManager validation method
BabelLicenseManager.RegisterLicenseProvider(typeof(MyApp), new BabelRegistryLicenseProvider());

// Validate the license using the BabelRegistryLicenseProvider
try
{
    ILicense license = BabelLicenseManager.Validate(typeof(MyApp));
    // ...
}
catch (BabelLicenseException ex)
{
	// Handle license validation errors
}

Exceptions

NameDescription

The type is licensed, but a License cannot be granted.

ValidateAsync(Type, CancellationToken)

Determines whether a license can be granted for the specified type.

public static Task<ILicense> ValidateAsync(Type type, CancellationToken cancellationToken = default)

Parameters

NameDescription

type Type

A that represents the type of object that requests the license.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

Exceptions

NameDescription

ValidateAsync(Type, object, CancellationToken)

Determines whether a license can be granted for the instance of the specified type.

public static Task<ILicense> ValidateAsync(Type type, object instance, CancellationToken cancellationToken = default)

Parameters

NameDescription

type Type

A that represents the type of object that requests the license.

instance object

An object of the specified type or a type derived from the specified type.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

An valid license.

Exceptions

NameDescription

The type is licensed, but a License cannot be granted.

Last updated