ArcFM Desktop Overview > ArcFM Solution Basics > Application Runtime Environment > License Check In/Out C# Code Sample |
This code sample checks out an ArcFM Solution product license and extension. In the example below, the CheckOutLicenses class checks out and releases ArcFM and Esri licenses as needed. The second example below illustrates how to call the CheckOutLicenses class and request specific licenses.
Declare a pointer to the IMMAppInitialize interface.
Check out an Esri license. If a license is not available, an error is thrown.
On Shutdown, release the Esri license.
Check out an ArcFM license using the mmLicensedProductCode enumeration. If a license is not available, an error is thrown.
On Shutdown, release the ArcFM license.
C# Sample |
Copy Code
|
---|---|
public class CheckOutLicenses { // Esri Application Initilization object located in Esri.ArcGIS.System.dll private IAoInitialize _aoInit; // ArcFM Application Initialization object located in Miner.Interop.System.DLL private IMMAppInitialize _mmAppInit; public CheckOutLicenses() { _aoInit = new AoInitializeClass(); //1 _mmAppInit = new MMAppInitializeClass(); } /// <summary> /// The following code will check out an Esri License based on a /// license enumeration value passed into the function /// If a license cannot be checked out, the function will throw an error /// </summary> /// <param name="LicenseToCheckOut">Enumerated value of an Esri license to check out</param> //2 public void GetEsriLicense(esriLicenseProductCode LicenseToCheckOut) { // check and see if the type of license is available to check out esriLicenseStatus EsriLicense = (esriLicenseStatus)_aoInit.IsProductCodeAvailable(LicenseToCheckOut); if (EsriLicense == esriLicenseStatus.esriLicenseAvailable) { // if the license is available, try to check it out. EsriLicense = _aoInit.Initialize(LicenseToCheckOut); if(EsriLicense != esriLicenseStatus.esriLicenseCheckedOut) { // if the license cannot be checked out, an exception is raised throw new Exception("The Esri license requested could not be checked out"); } } } /// <summary> /// Call to shutdown the Esri AO Initialize object. /// Should be the last call to the object /// </summary> //3 public void ReleaseEsriLicense() { _aoInit.Shutdown(); } /// <summary> /// Check out an ArcFM License by passing in an enumerated value of /// license options to check out. Gets an ArcFM license if one exists, /// attempts to check it out, and throws an exception if one cannot be checked out. /// </summary> /// <param name="LicenseToCheckOut">Enumerated value of the license to check out</param> //4 public void GetArcFMLicense(mmLicensedProductCode LicenseToCheckOut) { // check and see if the type of license is available to check out mmLicenseStatus mmLS = _mmAppInit.IsProductCodeAvailable(LicenseToCheckOut); if(mmLS == mmLicenseStatus.mmLicenseAvailable) { // if the license is available, try to check it out. mmLicenseStatus arcFMLicenseStatus = _mmAppInit.Initialize(LicenseToCheckOut); if(arcFMLicenseStatus!=mmLicenseStatus.mmLicenseCheckedOut) { // if the license cannot be checked out, an exception is raised throw new Exception("The ArcFM license requested could not be checked out"); } } } /// <summary> /// Shutdown the ArcFM Application Initializion object /// Should be the last call to make on the object. /// </summary> //5 public void ReleaseArcFMLicense() { _mmAppInit.Shutdown(); } } } |
The sample below illustrates how to call this class and request specific ArcFM and Esri licenses for a standalone application.
Calls the CheckOutLicense class displayed above.
Requests a specific Esri license using a value from the esriLicenseProductCode enumeration (see Esri developer help for more information about this enumeration).
Requests a specific ArcFM license using a value from the mmLicensedProductCode enumeration.
Releases the requested licenses.
C# Sample |
Copy Code
|
---|---|
namespace Miner.Samples.LicenseCheckout { /// <summary> /// Summary description for MainProgram. /// </summary> public class MainProgram { public static void Main(string[] args) { //1 CheckOutLicenses arcfmLicenseCheckout = new CheckOutLicenses(); // obtain the ArcFM and Esri Licenses. try { //2 arcfmLicenseCheckout.GetEsriLicense(esriLicenseProductCode.esriLicenseProductCodeArcInfo); } catch { // was not able to obtain an esri license. terminate code execution. return; } try { //3 arcfmLicenseCheckout.GetArcFMLicense(mmLicensedProductCode.mmLPArcFM); } catch { // was not able to check out an ArcFM License. terminate code execution. return; } // the Esri and ArcFM licenses are checked out. // put the custom logic here // release the ArcFM and Esri licenses. //4 arcfmLicenseCheckout.ReleaseArcFMLicense(); arcfmLicenseCheckout.ReleaseEsriLicense(); } } |