ArcEngine 10.0以上 许可检查及初始化



        该流程参考arcengine帮助文档介绍

///


        /// 检查ArcGIS许可并初始化(强制检查,有不通过项时直接退出)
        /// Initialization of an application with a license must be performed in the following order:
        ///1.Check that the product license is available with the IsProductCodeAvailable method.
        ///2.Check that extension licenses are available (if required) with the IsExtensionCodeAvailable method.
        ///3.Initialize the application with the product license.
        ///4.As required, check out and in the extension(s) by calling the CheckOutExtension and CheckInExtension methods.
        ///5.Shutdown the application.
        ///

        private void InitializeEngineLicense()
        { 
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
                AoInitialize aoi = new AoInitializeClass();
                string LiscenseMessage = "";
                esriLicenseStatus LiscenseStatus=aoi.IsProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
                //验证许可的可用性
                if (LiscenseStatus == esriLicenseStatus.esriLicenseAvailable)
                {
                    LiscenseStatus = aoi.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
                }
                else
                {
                    LiscenseMessage += "\"ArcEngine许可\"不可用\n";
                } 
                //扩展许可 
                //数据互操作
                LiscenseStatus = aoi.IsExtensionCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB, esriLicenseExtensionCode.esriLicenseExtensionCodeDataInteroperability);
                if (LiscenseStatus == esriLicenseStatus.esriLicenseAvailable)
                {
                    LiscenseStatus = aoi.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeDataInteroperability);
                }
                else
                {
                    LiscenseMessage += "\"数据互操作许可\"不可用\n";
                }
                //空间分析
                LiscenseStatus = aoi.IsExtensionCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB, esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);
                if (LiscenseStatus == esriLicenseStatus.esriLicenseAvailable)
                {
                    LiscenseStatus = aoi.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);
                }
                else
                {
                    LiscenseMessage += "\"空间分析许可\"不可用\n";
                }
                //动态跟踪
                LiscenseStatus = aoi.IsExtensionCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB, esriLicenseExtensionCode.esriLicenseExtensionCodeTracking);
                if (LiscenseStatus == esriLicenseStatus.esriLicenseAvailable)
                {
                    LiscenseStatus = aoi.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeTracking);
                }
                else
                {
                    LiscenseMessage += "\"动态跟踪许可\"不可用\n";
                }

                //图表
                LiscenseStatus = aoi.IsExtensionCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB, esriLicenseExtensionCode.esriLicenseExtensionCodeSchematics);
                if (LiscenseStatus == esriLicenseStatus.esriLicenseAvailable)
                {
                    LiscenseStatus = aoi.CheckInExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeSchematics);
                }
                else
                {
                    LiscenseMessage += "\"图表许可\"不可用\n";
                }
              
                if (!string.IsNullOrEmpty(LiscenseMessage))
                {
                    MessageBox.Show("ArcGIS许可验证不通过\n" + LiscenseMessage + "系统将退出", "严重警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                    App.Current.Shutdown();
               }
        }

你可能感兴趣的:(ArcEngine 10.0以上 许可检查及初始化)