C# Software Licensing

Hello World

To add software licensing to a C# application add a helper class to your project and put a library file (DLL on Windows) in your execution path. You can then call the CheckLicense method to load the license information and check that the user has a valid license. You need to specify a folder location for the license file, the license key issued to the user and the name of the application.

try
{
    string licenseKey = File.ReadAllText("HelloWorld.ini").Trim();
    LicenseHelper.CheckLicense(".", licenseKey, "Hello World");
    Console.WriteLine("Hello world!");
    return 0;
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
    return 1;
}

Building the Example

The library download includes a C# example application showing the use of the software licensing library with the developer password for the free test drive environment. For this step by step guide to building and running an example we will be using Visual Studio 2015 on a Windows development machine, and the web portal test drive environment to create licenses for our test application.

Download the Nuvovis package for Windows from the web portal and extract it to a work folder. Browse to the csharp\HelloWorld folder, open the Visual Studio project file and build the project.

If you open up the LicenseHelper.cs you will see that it uses the native DLL pgslicmt.dll. Open up Windows Explorer and copy and paste pgslicmt.dll and HelloWorld.ini from the bin folder (32-bit) into the csharp\HelloWorld\bin\Debug folder where we will run our example program.

Creating a License

The example cannot run until we have created a license for the application. In the web portal click on the New button to create a new Software License. Change the client field to one of the customer names and the product name to "Hello World". Save the new license to store the new license in Genux-B. The new Software License will now have a License Key field value. In the folder where the executable was written open the HelloWorld.ini file with a text editor and copy and paste the license key into the ini file and save the file.

Now our application is licensed and we can use it. Open a command window and run the HelloWorld executable. We should get a message and a license file in the current folder.

C:\>cd nuvovis_2.0.1490\csharp\HelloWorld\bin\Debug

C:\nuvovis_2.0.1490\csharp\HelloWorld\bin\Debug>HelloWorld.exe
Hello world!

C:\nuvovis_2.0.1490\csharp\HelloWorld\bin\Debug>dir

 Directory of C:\nuvovis_2.0.1490\csharp\HelloWorld\bin\Debug

13/05/2016  20:00               697 1-9-543.lic
13/05/2016  19:59             6,144 HelloWorld.exe
13/05/2016  19:28                36 HelloWorld.ini
13/05/2016  19:59            13,824 HelloWorld.pdb
13/05/2016  19:36            22,696 HelloWorld.vshost.exe
30/10/2015  08:19               490 HelloWorld.vshost.exe.manifest
13/05/2016  19:28           769,024 pgslicmt.dll

Back in the web portal you can now see that the license has been used by clicking on the license id link in the license list view for the new Software License.