using System; using System.Text; using System.Runtime.InteropServices; using PersistentSecurity; //******************************************************************** //* //* This sample demonstrates a real life scenario of using the Product //* Activation Server for a typical client application. It first checks //* whether there is a paid license available, if there is, it will //* retrieve it. If not, then it will attempt to obtain a demo license. //* available and all criteria are met, then a demo license will be //* installed on the client computer next to this running executable. //* //* This example checks for a license called "monitor" "6.0". //* //* If you are testing this on your local host you won't need to change //* the hostname in the two locations below. If not, you will need to //* change "localhost" to either an IP address or Domain name. //* //* MySQL and the Prodcut Activation Server will need to be running, //* and either of the "paid_node" or "demo_node" table records //* will need to be updated to add the above component name, version, and //* other information to enable this client app to get a license. If you //* use bin/create.sql to create the database and tables, these will be //* populated for you. //* //********************************************************************/ class PASnodelocked { static void Main() { String email = "bob@example.com"; String component = "monitor"; String version = "6.0"; String licensefile = "pas-nodelocked.lic"; String company = "localhost"; StringBuilder componentline = new StringBuilder(1024); StringBuilder szMessage = new StringBuilder(1024); StringBuilder serverline = new StringBuilder(1024); int retVal; int daysRemaining=0; // make this application use an external license file PSProlibProxy.sgSetAttrInt(PSProlibProxy.SG_ATTRTYPE.SG_ATTR_LICENSETYPE,(int)PSProlibProxy.SG_LICENSETYPE.SG_LICENSETYPE_EXTERNAL); Console.WriteLine("Checking for a license to run {0}.",component); // Are we already licensed? retVal = PSProlibProxy.sgAuthorized(licensefile,component,version); if (retVal != PSProlibProxy.SG_AUTHORIZED) { // we are going to use the email address as the unique paid customer identifier // it can be anything. But the email address "bob@example.com" must be in the // cust column of the paid_node table to identify the customer. Console.WriteLine("Checking for a paid license to run {0}.",component); retVal = PSProlibProxy.sgPaActivate(company, 29775, PSProlibProxy.SG_ACTIVATETYPE.SG_ACTIVATE_PAID_NODE, email, component, version, email, serverline, componentline); if ((retVal != PSProlibProxy.SG_SUCCESS) && (retVal != PSProlibProxy.SG_AUTHORIZED)) { Console.WriteLine("Checking for a demo license to run {0}.",component); retVal = PSProlibProxy.sgPaActivate(company, 29775, PSProlibProxy.SG_ACTIVATETYPE.SG_ACTIVATE_DEMO_NODE, null, component, version, email, serverline, componentline); if ((retVal != PSProlibProxy.SG_SUCCESS) && (retVal != PSProlibProxy.SG_AUTHORIZED)) { PSProlibProxy.sgGetLastErrorString(szMessage); Console.WriteLine("Problem with the activation server: {0}",szMessage); Environment.Exit(1); } else { // create the license file retVal = PSProlibProxy.sgEnableComponentLine(licensefile,componentline.ToString()); if (retVal != PSProlibProxy.SG_SUCCESS) { PSProlibProxy.sgGetLastErrorString(szMessage); Console.WriteLine("Problem installing the license: {0}",szMessage); Environment.Exit(1); } } } else { // create the license file retVal = PSProlibProxy.sgEnableComponentLine(licensefile,componentline.ToString()); if (retVal != PSProlibProxy.SG_SUCCESS) { PSProlibProxy.sgGetLastErrorString(szMessage); Console.WriteLine("Problem installing the license: {0}",szMessage); Environment.Exit(1); } } } // check once again in case the PAS sent us a new license file retVal = PSProlibProxy.sgAuthorized(licensefile,component,version); if (retVal != PSProlibProxy.SG_AUTHORIZED) { PSProlibProxy.sgGetLastErrorString(szMessage); Console.WriteLine("{0}",szMessage); Environment.Exit(1); } // create the int pointer retVal = PSProlibProxy.sgExpireDays(licensefile,component,version,ref daysRemaining); Console.WriteLine("Authorized to run the demo version of {0} for {1} more days.",component,daysRemaining); Environment.Exit(0); } }