.. _license_handling:

==================
License handling
==================

Activating a license 
=====================

One of the following methods can be used to activate a license programmatically:

- :ref:`id3_bioseal_bioseal_license_activate_class_method`
- :ref:`id3_bioseal_bioseal_license_activate_buffer_class_method`
- :ref:`id3_bioseal_bioseal_license_activate_activation_key_class_method`
- :ref:`id3_bioseal_bioseal_license_activate_activation_key_buffer_class_method`
- :ref:`id3_bioseal_bioseal_license_activate_serial_key_class_method`
- :ref:`id3_bioseal_bioseal_license_activate_serial_key_buffer_class_method`

Here is an example how to activate a license using a serial number:

.. tab-set::

    .. tab-item:: Python
        :sync: Python
   
        .. literalinclude:: /../../samples/sample.py
            :language: python
            :start-after: [license_activation]
            :end-before: [license_activation]
            :dedent: 4
            
    .. tab-item:: C#
        :sync: C#
   
        .. code-block:: csharp
            
            using id3.Bioseal;
            using System;
            
            try
            {
                // Get the hardware code for this device
                // Choose the appropriate hardware code type based on your platform:
                // - LicenseHardwareCodeType.WindowsOs for Windows
                // - LicenseHardwareCodeType.MacOs for macOS
                // - LicenseHardwareCodeType.LinuxOs for Linux
                string hardwareCode = BiosealLicense.GetHostHardwareCode(LicenseHardwareCodeType.WindowsOs);
                
                // Activate the license using an activation key
                string activationKey = "YOUR_ACTIVATION_KEY";
                string commentary = "Activation from C# application";
                string licensePath = "path/to/save/license.lic";
                
                // Activate and save the license to a file
                BiosealLicense.ActivateActivationKey(
                    hardwareCode,
                    activationKey,
                    commentary,
                    licensePath
                );
                
                // Check the license to verify it's valid
                BiosealLicense.CheckLicense(licensePath);
                
                Console.WriteLine($"License activated successfully! Valid until: {BiosealLicense.GetExpiryDate()}");
                Console.WriteLine($"License saved to: {licensePath}");
            }
            catch (BiosealException ex)
            {
                Console.WriteLine($"Error during license activation: {ex.Message}");
            }
            
    .. tab-item:: Dart
        :sync: Dart
   
        .. code-block:: dart
            
            import 'package:id3_bioseal/id3_bioseal.dart';
            
            void main() async {
              try {
                // Get the hardware code for this device
                // Choose the appropriate hardware code type based on your platform:
                // - windowsOs for Windows
                // - macOs for macOS
                // - linuxOs for Linux
                final hardwareCode = BiosealLicense.getHostHardwareCode(LicenseHardwareCodeType.windowsOs);
                
                // Activate the license using an activation key
                const activationKey = 'YOUR_ACTIVATION_KEY';
                const commentary = 'Activation from Dart application';
                const licensePath = 'path/to/save/license.lic';
                
                // Activate and save the license to a file
                BiosealLicense.activateActivationKey(
                  hardwareCode,
                  activationKey,
                  commentary,
                  licensePath,
                );
                
                // Check the license to verify it's valid
                BiosealLicense.checkLicense(licensePath);
                
                final expiryDate = BiosealLicense.getExpiryDate();
                print('License activated successfully! Valid until: $expiryDate');
                print('License saved to: $licensePath');
              } on BiosealException catch (e) {
                print('Error during license activation: ${e.message}');
              }
            }

.. important:: 
    On Android and iOS platforms, it is not possible, for reasons of confidentiality, to retrieve a truly unique hardware identifier. The side effect is that the hardware code is different (but fixed) for every application you develop, even on the same device.

.. hint:: 
    We recommend that you activate the application the first time you run it, and then store the license on the device for future use.

.. warning:: Internet usage permission is required for the activation process.

Checking the license
====================

Before calling any function of the SDK, you need to check a valid license file first.

.. .. note:: To obtain a license file, please use the provided activation tool or call one of the activation methods in your application.

.. tab-set::

    .. tab-item:: Python
        :sync: Python
   
        .. literalinclude:: /../../samples/sample.py
            :language: python
            :start-after: [license_check]
            :end-before: [license_check]
            :dedent: 4


See also
========
- :ref:`license_activation`
- :ref:`license_hardware_id`
- :ref:`id3_bioseal_bioseal_license_activate_activation_key_class_method`
- :ref:`id3_bioseal_bioseal_license_get_host_hardware_code_class_method`
