Obtaining a List of Features with the License Manager

Declare Variables/Constants

String  CONTACT_SERVER = "localhost";
 
String ScopeFeatureInfoPart1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "+
"<sentinelScope>"+ "<feature index=\""; String ScopeFeatureInfoPart2 = "\"><name></name>"+ "<version></version>"+ "</feature>"+ "</sentinelScope>"; int iRetCode = (int)LicensingConstants.StatusCodes.SNTL_SUCCESS; int iFeatureIndex = 0; Attribute attrAppContext = null; ApplicationContext appContext = null;

API Calls

To obtain features list, execute the APIs in the specified sequential order only:

>attrAppContext = new Attribute();

>attrAppContext.set(LicensingConstants.SNTL_ATTR_APPCONTEXT_CONTACT_SERVER, CONTACT_SERVER);

NOTE   If instead the LSFORCEHOST or LSHOST environment variables are set, then the above mentioned steps are not required.

>appContext = new ApplicationContext(attrAppContext);

>Now call appContext.getInfo inside a while loop (incrementing the feature index, iFeatureIndex at each iteration, its initial value being 0), till the return code is SNTL_NO_MORE_FEATURES, as shown in the code snippet below:

 try
    {                
        attrAppContext = new Attribute();
        attrAppContext.set(LicensingConstants.SNTL_ATTR_APPCONTEXT_CONTACT_SERVER, CONTACT_SERVER);
        appContext = new ApplicationContext(attrAppContext);
      
        while (iRetCode != (int)LicensingConstants.StatusCodes.SNTL_NO_MORE_FEATURES)
        {
            StringBuilder buff = new StringBuilder(ScopeFeatureInfoPart1);
            buff.Append(iFeatureIndex++);
            buff.Append(ScopeFeatureInfoPart2);
            String ScopeFeatureInfo = buff.ToString();
            String featureInfo = appContext.getInfo(ScopeFeatureInfo, LicensingConstants.SNTL_QUERY_FEATURE_INFO_LATEST);
            /* Parse the XML output contained in featureInfo */
        }   /*end of while loop*/
    }
    catch (LicensingException e)
    {
        if (e.getStatusCode() != (int)LicensingConstants.StatusCodes.SNTL_NO_MORE_FEATURES)
        {
            Console.WriteLine("Got an exception : " + e);
            System.Console.Out.WriteLine("Failed with status " + e.getStatusCode());
            System.Console.Out.WriteLine("Status Message : \n" + e.Message);
        }
        else
        {
           Console.WriteLine("Reached end of enumeration...no more features");
        }
    }

On success during each iteration of the while loop, the featureInfo string contains an XML-based output having the detailed information.