龙空技术网

Arcengine C# 第6章许可管理

GISAI 238

前言:

今天你们对“arcengine融合算法”大概比较关怀,咱们都需要知道一些“arcengine融合算法”的相关文章。那么小编也在网摘上网罗了一些有关“arcengine融合算法””的相关内容,希望咱们能喜欢,兄弟们一起来学习一下吧!

6 Lic管理6.1 LIC代码初始化using System;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices;using ESRI.ArcGIS.esriSystem;using System.Windows.Forms;namespace ylpub{    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.esriLicenseProductCodeArcInfo);            if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)            {                licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcEditor);                if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)                {                    licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcView);                    if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)                    {                        licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);                        if (licenseStatus != esriLicenseStatus.esriLicenseCheckedOut)                        {                            licenseStatus = CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeEngine);                            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;        }        public esriLicenseStatus CheckOut(esriLicenseExtensionCode pesriLicenseExtensionCode)        {            esriLicenseStatus licenseStatus;                        licenseStatus = m_AoInitialize.CheckOutExtension(pesriLicenseExtensionCode);            if (licenseStatus != ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseCheckedOut)            {                MessageBox.Show("失败");            }            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;        }    }}6.2 初始化LIC   ylpub.LicenseInitializer aeLicInit = null;        private bool initae()        {            aeLicInit = new ylpub.LicenseInitializer();            if (!aeLicInit.InitializeApplication())            {                MessageBox.Show("LIc初始化失败");                return false;            }            return true;        }        private void button1_Click(object sender, EventArgs e)        {            if (!initae()) return;            MessageBox.Show("LIc初始化成功");        }6.3 释放LIC        private void Form1_FormClosed(object sender, FormClosedEventArgs e)        {            aeLicInit.ShutdownApplication();            aeLicInit = null;        }6.4 增加扩展模块aeLicInit.CheckOut(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);6.5 获得lic信息private void button1_Click(object sender, EventArgs e)        {            ESRI.ArcGIS.esriSystem.IAoInitialize aoInitialize = new ESRI.ArcGIS.esriSystem.AoInitializeClass();            ESRI.ArcGIS.esriSystem.ILicenseInformation licenseInformation = (ESRI.ArcGIS.esriSystem.ILicenseInformation)aoInitialize;            System.String string_Licenses = null;            try            {                ESRI.ArcGIS.esriSystem.esriLicenseProductCode licenseProductCode = aoInitialize.InitializedProduct();                System.String string_LicenseProductName = licenseInformation.GetLicenseProductName(licenseProductCode);                string_Licenses = "当前程序的lic" + System.Environment.NewLine + string_LicenseProductName + System.Environment.NewLine + "扩展模块:";                ESRI.ArcGIS.esriSystem.ILicenseInfoEnum licenseInfoEnum = licenseInformation.GetProductExtensions(licenseProductCode);                licenseInfoEnum.Reset();                ESRI.ArcGIS.esriSystem.esriLicenseExtensionCode licenseExtensionCode = licenseInfoEnum.Next();                while (!(System.Convert.ToInt32(licenseExtensionCode) == -1))                {                    if (aoInitialize.IsExtensionCheckedOut(licenseExtensionCode) == true)                    {                        System.String string_LicenseExtensionName = licenseInformation.GetLicenseExtensionName(licenseExtensionCode);                        string_Licenses = string_Licenses + System.Environment.NewLine + string_LicenseExtensionName;                    }                    licenseExtensionCode = licenseInfoEnum.Next();                }                System.Windows.Forms.MessageBox.Show(string_Licenses);            }            catch (System.Exception ex)            {                System.Windows.Forms.MessageBox.Show(ex.ToString());            }        }6.6 设置arcinfo和扩展模块private void button2_Click(object sender, EventArgs e)        {            ESRI.ArcGIS.esriSystem.IAoInitialize AoInitialize = new ESRI.ArcGIS.esriSystem.AoInitializeClass();            ESRI.ArcGIS.esriSystem.esriLicenseStatus licenseStatus = AoInitialize.                Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo);            if (licenseStatus != ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseCheckedOut)            {                MessageBox.Show(string.Format("不能设置 ArcInfo license, 错误原因 [0]", licenseStatus));                return;            }            else            {                MessageBox.Show("ok Arcinfo");            }            licenseStatus = AoInitialize.CheckOutExtension               (esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);            if (licenseStatus != ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseCheckedOut)            {                MessageBox.Show(string.Format("不能设置 分析扩展模块, 错误原因 [0]", licenseStatus));                return;            }            else            {                MessageBox.Show("ok SpatialAnalyst");            }        }

标签: #arcengine融合算法