Manual Activation Code Snippets (FAQ148)

How do I enable Manual Activation in my application using Software Potential ?

Overview

If you want to support manual activation (see FAQ114) in your application you need to provide the following functionality in the Manual Activation dialog:

  1. Capture the Activation key, validate the key and create a Manual Activation request.
  2. Display the Activation Request in a Textbox and allow it to be copied to the clipboard
  3. Navigate to the received license file and then install the license

Please see a sample Manual Activation Dialog:

ManualActivationDialog.png

Once the Activation Request has been copied the customer must submit this to the Software Potential service for processing. One option is to submit the request to you so that you can process the request manually via the manual activation page of the the Software Potential service e.g. allow the request to be submitted and license file returned by email.

Alternatively, you could automate the process by creating a web page to allow customers both submit manual Activation Requests and retrieve license files directly (without requiring you to login to your Software Potential account to manually process the requests).

Implementation Steps

Note : The following steps include code snippets for both the classic Microsoft.Licensing and new Sp.Agent runtimes.

Step 1: Generating Manual Activation Request

To create a manual Activation request you will need to

  • Capture the Activation Key;
  • Generate the Manual Activation request as a string (see code below);
  • Display the request in a text area so it can be copied for onward transmission to the Software Potential service for processing.

With Sp.Agent NuGet packages:

string requestString = SpAgent.Product.Activation.Advanced().CreateManualActivationRequest(activationKey, null);

In Microsoft.Licensing runtime:

string permShortcode = "abc12"; //TODO: substitute in you vendor's own permutation short code.

private static string CreateManualActivationRequestString( string permShortcode, string activationKey )
{
    using ( var runtime = new SLMRuntime(permShortcode) )
    {
        ILicenseRequestBuilder licenseRequestBuilder = runtime.Activation.GetLicenseRequestBuilder( activationKey );
        licenseRequestBuilder.AddAvailableLicenseStores();	
	}
}

Step 2: Submitting Manual Activation Requests to SP Activation Service.

There are two options for request submission and and retrieval of the resulting license file on successful activation:

  • Process the request using the Manual Activation page in the Software Potential portal. Once you receive the Activaiton request string from the customer, you logon to the Software Potential portal https://srv.softwarepotential.com/ -> Licenses -> Manual Activation page to process the request. On successful activation, you can can download the corresponding license file (.bin file) and transmit it to the customer to install on the device. 
  • Provide a public web page where a customer can submit a Manual Activation request directly and then download the resultant license file on successful activation. Removing the need for your manual intervention simplifies and shortens the Manual Activation process

You can find a sample MVC application for such a web page on our GitHub account Manual Activation Sample (uses Sp.Agent Nuget).

 

Step 3: Install the license file on the machine that originated the activation request.

To install the retrieved license file, in your application you will need 

  • A UI to load/store the license file and
  • Amechanism to extract the license.

With Sp.Agent NuGet packages:

//Read the license file into byte[]
var licenseBlob = File.ReadAllBytes(@"U:\file.bin ");
//Install the license file "file.bin" 
SpAgent.Product.Stores.Install(licenseBlob);

In Microsoft.Licensing runtime:

private static void InstallLicenseFromFile( string permShortcode, string licenseFilename )
{
    using ( var runtime = new SLMRuntime(permShortcode) )
    {
        var license = runtime.Licenses.OpenLicense( licenseFilename );
        runtime.Licenses.InstallLicense( license );
    }
}

License File Locking

If the license is Machine Locked the license (.bin) file returned on successful activation can only be used on the machine on which the activation request was generated.

If the license is not Machine Locked the license file resulting from manual activation can be installed on an unlimited number of machines.

 

Link to this

FAQ148

You can link to this item directly, using the shorter URL support.inishtech.com/FAQ148.