Floating License

Floating licenses offer flexibility and scalability in managing software licenses across multiple users or machines. With Babel Licensing, you can create floating licenses using the intuitive Babel User Interface (Babel UI) on the Babel Licensing Service. This enables you to allocate a pool of licenses that can be shared among users or machines on a network. In this introduction, we will explore how to create a floating license using the Babel User Interface and configure a client .NET application to consume the floating license using the Babel Licensing library.

Prerequisites

To enable floating license functionality in Babel Licensing Service, follow these steps. First, ensure that Babel Licensing Service is up and running on your server according to the instructions provided in the Getting Started section. Then, create a test product and a corresponding template license by referring to the instructions provided below. This will establish the foundation for generating floating licenses.

Next, you'll need to download the floating license client source code from GitHub. This client code will be used to integrate floating license capabilities into your .NET application.

git clone https://github.com/babelfornet/floating-license-console-example.git

The creation of a floating license for this example requires the creation of a corresponding license template. To create the license template for your test client, please refer to the instructions outlined in the "Creating License Template" section. Follow the provided steps to ensure the successful creation of the license template required for generating the floating license.

Creating a Floating License

The Babel User Interface provides a user-friendly interface for managing licenses on the Babel Licensing Service. Through this interface, you can easily create and configure floating licenses. You can define the total number of licenses in the pool and set usage restrictions, such as the number of concurrent users or machines allowed to access the license at a given time. By creating a floating license, you empower your application to dynamically acquire and release licenses from the pool as needed, providing flexibility in license allocation and usage.

To register a floating license in the Babel User Interface, follow these steps:

  1. Start the Babel User Interface and navigate to the Data section.

  2. Click on the "Licenses" link to display the list of existing licenses.

  3. Click on the "New License" button on the grid header to create a new license.

  4. In the License Template combo box, select the appropriate license template (see License Templates).

  5. The License fields will automatically populate with the information from the selected template.

  6. In the "Licensing Mode" field, select "Floating" as the licensing model for the license.

  7. In the "Allowed Sites" column, enter the desired number of floating sites or licenses.

  8. Generate a new User Key by pressing the arrow button located at the right end of the "User Key" field. The client application will use this unique code to request a floating license.

  1. Enter the necessary details for the license, such as the licensee information, license fields, allowed features, and expiration date.

  2. Press the Generate button to generate the license, and then save by clicking the "Save" button.

The public key extracted from the Keys.snk file, which is necessary for license validation, is already configured in the example source code.

  1. The newly registered floating license will now appear in the licenses grid with a unique license key and other relevant information.

By following these steps, you can register a floating license in the Babel User Interface. This license can then be assigned to users or machines, and the Babel Licensing Service will manage the concurrent usage of the licenses based on the specified number of floating sites.

Configuring a Client

Once the floating license is created on the Babel Licensing Service, you need to configure your client .NET application to consume the license. This involves integrating the Babel Licensing library into your application and implementing the necessary code to request and release licenses from the floating license pool. The Babel Licensing library provides a set of APIs and methods that simplify the process of license validation and enforcement. By leveraging these APIs, you can seamlessly integrate the floating license mechanism into your application's licensing workflow.

To open the floating license sample project, follow these steps:

  1. Navigate to the location where the floating license sample project is stored and double-click on the ClientFloating.sln solution file to open it in your preferred Integrated Development Environment (IDE), such as Visual Studio.

  2. Once the project is open, ensure that the Babel Licensing client library is referenced correctly. If the reference is missing, please refer to the Client Components paragraph to configure a local NuGet repository.

  3. After ensuring the correct references, build the solution by selecting the "Build" or "Rebuild" option from the IDE's menu.

  4. Once the solution is successfully built, you can run the application in debug configuration by pressing the "Start Debugging" button or using the keyboard shortcut specific to your IDE (e.g., F5 in Visual Studio).

  5. The floating license sample application will launch, allowing you to interact with the licensing functionality and test the floating license workflow.

  6. Enter the floating license key generated for the license and press ENTER.

Follows the complete license activation example source code:

using Babel.Licensing;

// Create a new configuration object
BabelLicensingConfiguration config = new BabelLicensingConfiguration() {
    // Set the service URL
    ServiceUrl = "http://localhost:5005",
    
    // Set the public key used to verify the license signature
    SignatureProvider = RSASignature.FromKeys("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDE1VRiIdr6fiVZKve7NVgjIvGdRiRx0Mjjm+Yzf6tLbzFnxLs0fat5EoRcubxx0QQQDfydsJBE/fc7cwRWSrE2xK6X4Eb4W8O47pCMjqvTQZfDqQywEZJrLlxpp9hlKz6FDYX4SagrjmP1gdw8olo+n+IBz8ubkNxRhvycikxuDQIDAQAB"),
    
    // Set a unique client ID in case multiple instances of the application are running on the same machine
    ClientId = Guid.NewGuid().ToString()
};

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

// Ask the user to enter the floating license key
Console.WriteLine("Please enter your floating license key: ");
string? userKey = Console.ReadLine();

try
{
    var result = await client.RequestFloatingLicenseAsync(userKey, typeof(Program));

    Console.WriteLine($"License {result.License.Id} requested.");
}
catch (Exception ex)
{
    Console.WriteLine($"Could not request floating license: {ex.Message}");
    return;
}

try
{
    // Simulate a long task which requires the allocation of a license
    for (int i = 0; i < 10; i++)
    {
        // Validate the license
        // This will contact the server to validate the license
        var result = await client.ValidateLicenseAsync(userKey, typeof(Program));
        Console.WriteLine($"{i}) License {result.License.Id} valid.");

        // Wait 1 second
        await Task.Delay(1000);
    }

    try
    {
        // Release the license to allow other clients to use it
        await client.ReleaseFloatingLicenseAsync(userKey);
        Console.WriteLine("License released.");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Could not release license: {ex.Message}");
    }

}
catch (Exception ex)
{
    Console.WriteLine($"License not valid: {ex.Message}");
    return;
}

The BabelLicensing class is instantiated to communicate with the licensing server. The public key to validate the license is assigned in the service configuration as well as the URL to communicate with the service.

The user is prompted to enter the floating license key. The license key is used by the client to request a floating license by calling the RequestFloatingLicenseAsync method. The user key and the type of the program are passed as parameters. If successful, the method returns a result object containing the requested license information.

The code simulates a long-running task that requires the allocated license. In a loop, the license is validated using the ValidateLicenseAsync method. The user key and the type of the program are passed as parameters. If the license is valid, the method returns a result object containing the license information. The loop also includes a delay of one second to simulate the task's duration.

After the task is completed, the client releases the floating license using the ReleaseFloatingLicenseAsync method.

By creating and consuming floating licenses with Babel Licensing, you can efficiently manage software licenses across a network of users or machines. This approach optimizes license utilization, reduces administrative overhead, and provides a scalable licensing solution. Whether you need to allocate licenses dynamically to a growing user base or distribute licenses across different departments or teams, the floating license capability offered by Babel Licensing simplifies the process and provides a seamless licensing experience for your users.

Last updated