LicenseProviderBundle

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

Represents a bundle of license providers that implement the interface. This class allows you to combine multiple license providers and retrieve licenses from them sequentially.

public class LicenseProviderBundle : IAsyncLicenseProvider, ILicenseProvider, ICollection<ILicenseProvider>, IEnumerable<ILicenseProvider>, IEnumerable

Inheritance

objectLicenseProviderBundle

Implements

IAsyncLicenseProvider, ILicenseProvider, ICollection<ILicenseProvider>, IEnumerable<ILicenseProvider>, IEnumerable

Inherited Members

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

Constructors

LicenseProviderBundle()

Initializes a new instance of the class. This class is used to combine multiple license providers and retrieve licenses from them sequentially.

public LicenseProviderBundle()

Examples

var bundle = new LicenseProviderBundle();

// Create a local file license provider that will look for a license file in the current directory
// or will load the specified license file path from the MY_APPLICATION_LICENSE_PATH environment variable.
var localProvider = new BabelFileLicenseProvider();
localProvider.EnvironmentVariable = "MY_APPLICATION_LICENSE_PATH";

bundle.Add(localProvider);

// Create service license provider that will contact the Babel Licensing Service to validate the license
BabelLicensingConfiguration config = new BabelLicensingConfiguration() {
    // Set the service URL
    ServiceUrl = "http://localhost:5005",

    // Set the unique client ID
    ClientId = "my application client ID",
};

// Create the client object used to communicate with the server
var client = new BabelLicensing(config);

// Use BabelServiceLicenseProvider to cache a local copy of the license for offline use
BabelServiceLicenseProvider remoteProvider = new BabelServiceLicenseProvider(client) {
    // Refresh the license contacting the server every 7 days
    // If set to TimeSpan.Zero, the license will be validated every time on the server
    LicenseRefreshInterval = TimeSpan.FromDays(7)
};

bundle.Add(remoteProvider);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {

    // On Windows OS use BabelServiceRegistryLicenseProvider to store a local copy of the license
    BabelServiceRegistryLicenseProvider registryProvider = new BabelServiceRegistryLicenseProvider(client) {

        // Specify where license information will be stored in the registry
        // If not provided babel will hide the license information in the registry
        RegistryKey = Registry.CurrentUser,
        RegistryPath = @"Software\MyApplication",
    };

    bundle.Add(registryProvider);
};

BabelLicenseManager.RegisterLicenseProvider(typeof(Obfuscator), bundle);

Properties

Count

Gets the number of license providers in the bundle.

public int Count { get; }

Property Value

int

IsReadOnly

Gets a value indicating whether the collection is read-only.

public bool IsReadOnly { get; }

Property Value

bool

ValidLicenseProvider

Returns the instance of the that validate successfully the license.

public ILicenseProvider ValidLicenseProvider { get; }

Property Value

ILicenseProvider

Methods

Add(ILicenseProvider)

Adds a license provider to the bundle. The license provider will be used to retrieve a license if the previous license provider in the bundle failed to validate the license.

public void Add(ILicenseProvider item)

Parameters

NameDescription

The license provider to add.

Exceptions

NameDescription

Thrown when item is null.

Clear()

Removes all license providers from the bundle.

public void Clear()

Contains(ILicenseProvider)

Determines whether the bundle contains a specific license provider.

public bool Contains(ILicenseProvider item)

Parameters

NameDescription

The license provider to locate.

Returns

NameDescription

true if the license provider is found in the bundle; otherwise, false.

CopyTo(ILicenseProvider[], int)

Copies the license providers in the bundle to an array, starting at a particular array index.

public void CopyTo(ILicenseProvider[] array, int arrayIndex)

Parameters

NameDescription

The one-dimensional array that is the destination of the elements copied from the bundle.

arrayIndex int

The zero-based index in array at which copying begins.

GetEnumerator()

Returns an enumerator that iterates through the license providers in the bundle.

public IEnumerator<ILicenseProvider> GetEnumerator()

Returns

NameDescription

An enumerator that can be used to iterate through the license providers in the bundle.

GetLicense(ILicenseContext, Type, object)

Synchronously gets a license for an instance or type of component from the bundle.

public ILicense GetLicense(ILicenseContext context, Type type, object instance)

Parameters

NameDescription

A that specifies where you can use the licensed object.

type Type

A that represents the component requesting the license.

instance object

An object that is requesting the license.

Returns

NameDescription

A valid for the specified context, type, and instance.

GetLicenseAsync(ILicenseContext, Type, object, CancellationToken)

Asynchronously gets a license for an instance or type of component from the bundle.

public Task<ILicense> GetLicenseAsync(ILicenseContext context, Type type, object instance, CancellationToken cancellationToken = default)

Parameters

NameDescription

A that specifies where you can use the licensed object.

type Type

A that represents the component requesting the license.

instance object

An object that is requesting the license.

cancellationToken CancellationToken

A token that can be used to request cancellation of the asynchronous operation.

Returns

NameDescription

A task that represents the asynchronous operation and contains a valid .

Remove(ILicenseProvider)

Removes a license provider from the bundle.

public bool Remove(ILicenseProvider item)

Parameters

NameDescription

The license provider to remove.

Returns

NameDescription

true if the license provider was successfully removed; otherwise, false.

Last updated