QuickOPC User's Guide and Reference
RegisterManagedResourceWithExistenceCheck Method
Example 



OpcLabs.BaseLib Assembly > OpcLabs.BaseLib.ComponentModel Namespace > LicensingManagement Class : RegisterManagedResourceWithExistenceCheck Method
Name of the licensing component for which the location of the license should be registered. Consult the documentation for the value that corresponds to your product.
ID of the license for whose location should be registered. Consult the documentation for the values to be used with your product.
The assembly in which the embedded managed resource resides.
The name of the embedded managed resource containing the license, or a pattern identifying a single such resource.
Registers a license located in an embedded managed resource, checking whether the resource exists.
Syntax
'Declaration
 
Public Sub RegisterManagedResourceWithExistenceCheck( _
   ByVal componentName As String, _
   ByVal licenseId As String, _
   ByVal assembly As Assembly, _
   ByVal resourceNameOrPattern As String _
) 
'Usage
 
Dim instance As LicensingManagement
Dim componentName As String
Dim licenseId As String
Dim assembly As Assembly
Dim resourceNameOrPattern As String
 
instance.RegisterManagedResourceWithExistenceCheck(componentName, licenseId, assembly, resourceNameOrPattern)
public void RegisterManagedResourceWithExistenceCheck( 
   string componentName,
   string licenseId,
   Assembly assembly,
   string resourceNameOrPattern
)
public:
void RegisterManagedResourceWithExistenceCheck( 
   String^ componentName,
   String^ licenseId,
   Assembly^ assembly,
   String^ resourceNameOrPattern
) 

Parameters

componentName
Name of the licensing component for which the location of the license should be registered. Consult the documentation for the value that corresponds to your product.
licenseId
ID of the license for whose location should be registered. Consult the documentation for the values to be used with your product.
assembly
The assembly in which the embedded managed resource resides.
resourceNameOrPattern
The name of the embedded managed resource containing the license, or a pattern identifying a single such resource.
Exceptions
ExceptionDescription
A license resource is already registered for componentName and licenseId.
The specified license resource does not exist or is not accessible.

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

The same combination of componentName and licenseId must not (and cannot) be registered more than once. An attempt to do so will result in an System.ArgumentException. Be careful not to put the registration code into Web request handlers (without further logic) which are called repeatedly.

Example

.NET

// Shows how to register a license located in an embedded managed resource, verifying its existence upfront.

using System;
using System.Reflection;
using OpcLabs.BaseLib.ComponentModel;
using OpcLabs.BaseLib.Portable;
using OpcLabs.EasyOpc.UA;

namespace UADocExamples.Licensing
{
    partial class _LicensingManagement
    {
        public static void RegisterManagedResourceWithExistenceCheck()
        {
            // Register a license that is we embed as a managed resource in this program.

            // The first two arguments should always be "QuickOPC" and "Multipurpose".
            // The third argument determines the assembly where the license resides.
            // The fourth argument is the namespace-qualified name of the managed resource, or a pattern identifying it.
            // We could use precise "UADocExamples.Licensing.Key-DemoOrTrial-WebForm-1999003494-20180611.bin" instead.
            try
            {
                LicensingManagement.Instance.RegisterManagedResourceWithExistenceCheck("QuickOPC", "Multipurpose",
                    Assembly.GetExecutingAssembly(), "*.Key-*.*");
            }
            // This exception will be thrown if the specified managed resource does not exist or is not accessible.
            // Note, however, that the validity of the license is not checked at this point.
            // You can experiment with this code path by modifying the resource name in the call above.
            catch (CustomException customException)
            {
                Console.WriteLine($"*** Failure: {customException.Message}");
                return;
            }

            // Instantiate the client object, obtain the serial number from the license info, and display the serial number.
            var client = new EasyUAClient();
            long serialNumber = (uint)client.LicenseInfo["Multipurpose.SerialNumber"];
            Console.WriteLine("SerialNumber: {0}", serialNumber);

            // The license we ship for this purpose is a trial license with low runtime limit, so it won't be of much use.
            // But you get the point...
        }
    }
}
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also