ArcGIS Engine developer kit产品以及相应的产品许可安装以后,只是为你的应用程序实现许可允许的功能提供了可能性,要想真的使得你的应用程序拥有这些功能,你还需要做一个许可文件的初始化工作。
注意:如果不做这个初始化工作,你有可能会在实现某些功能时碰到你没有相应的许可的提示。
这个许可文件的初试化工作需要在你的应用程序的入口处实现。下面是c#的初始化的代码示例
using ESRI.ArcGIS.esriSystem;
namespace LicenseInitializer
{
public class LicenseInitializer
{
private IAoInitialize m_AoInitialize = new AoInitializeClass();
public bool InitializeApplication()
{
bool bInitialized = true;
if (m_AoInitialize == null)
{
System.Windows.Forms.MessageBox.Show("Unable to initialize. This application cannot run!");
bInitialized = false;
}
//初始化应用程序
esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeEngine);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcView);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
System.Windows.Forms.MessageBox.Show(LicenseMessage(licenseStatus));
bInitialized = false;
}
}
}
}
return bInitialized;
}
public void ShutdownApplication()
{
if (m_AoInitialize == null) return;
//关闭 AoInitilaize对象
m_AoInitialize.Shutdown();
m_AoInitialize = null;
}
private esriLicenseStatus CheckOutLicenses(esriLicenseProductCode productCode)
{
esriLicenseStatus licenseStatus;
//是否产品是可能的
licenseStatus = m_AoInitialize.IsProductCodeAvailable(productCode);
if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
{
//用相应的许可文件进行初始化
licenseStatus = m_AoInitialize.Initialize(productCode);
}
return licenseStatus;
}
private string LicenseMessage(esriLicenseStatus licenseStatus)
{
string message = "";
//没有许可
if (licenseStatus == esriLicenseStatus.esriLicenseNotInitialized)
{
message = "You are not licensed to run this product!";
}
//许可正在使用
else if (licenseStatus == esriLicenseStatus.esriLicenseUnavailable)
{
message = "There are insuffient licenses to run!";
}
//未知错误
else if (licenseStatus == esriLicenseStatus.esriLicenseFailure)
{
message = "Unexpected license failure! Please contact your administrator.";
}
//已经初始化
else if (licenseStatus == esriLicenseStatus.esriLicenseAlreadyInitialized)
{
message = "The license has already been initialized! Please check your implementation.";
}
return message;
}
}
}
注意:如果不做这个初始化工作,你有可能会在实现某些功能时碰到你没有相应的许可的提示。
这个许可文件的初试化工作需要在你的应用程序的入口处实现。下面是c#的初始化的代码示例
using ESRI.ArcGIS.esriSystem;
namespace LicenseInitializer
{
public class LicenseInitializer
{
private IAoInitialize m_AoInitialize = new AoInitializeClass();
public bool InitializeApplication()
{
bool bInitialized = true;
if (m_AoInitialize == null)
{
System.Windows.Forms.MessageBox.Show("Unable to initialize. This application cannot run!");
bInitialized = false;
}
//初始化应用程序
esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeEngine);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcView);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)
{
System.Windows.Forms.MessageBox.Show(LicenseMessage(licenseStatus));
bInitialized = false;
}
}
}
}
return bInitialized;
}
public void ShutdownApplication()
{
if (m_AoInitialize == null) return;
//关闭 AoInitilaize对象
m_AoInitialize.Shutdown();
m_AoInitialize = null;
}
private esriLicenseStatus CheckOutLicenses(esriLicenseProductCode productCode)
{
esriLicenseStatus licenseStatus;
//是否产品是可能的
licenseStatus = m_AoInitialize.IsProductCodeAvailable(productCode);
if (licenseStatus == esriLicenseStatus.esriLicenseAvailable)
{
//用相应的许可文件进行初始化
licenseStatus = m_AoInitialize.Initialize(productCode);
}
return licenseStatus;
}
private string LicenseMessage(esriLicenseStatus licenseStatus)
{
string message = "";
//没有许可
if (licenseStatus == esriLicenseStatus.esriLicenseNotInitialized)
{
message = "You are not licensed to run this product!";
}
//许可正在使用
else if (licenseStatus == esriLicenseStatus.esriLicenseUnavailable)
{
message = "There are insuffient licenses to run!";
}
//未知错误
else if (licenseStatus == esriLicenseStatus.esriLicenseFailure)
{
message = "Unexpected license failure! Please contact your administrator.";
}
//已经初始化
else if (licenseStatus == esriLicenseStatus.esriLicenseAlreadyInitialized)
{
message = "The license has already been initialized! Please check your implementation.";
}
return message;
}
}
}