public void InitializeApplication(esriLicenseProductCode[] products,esriLicenseExtensionCode [] extensions)
        {
            // Binding a product
            RuntimeManager.Bind(ProductCode.EngineOrDesktop);
            // Initialize a product code
            m_AoInit = new AoInitializeClass();
            esriLicenseProductCode currentProduct = new esriLicenseProductCode();
            foreach (esriLicenseProductCode prod in products)
            {
                esriLicenseStatus prodStatus = m_AoInit.IsProductCodeAvailable(prod);
                if(prodStatus==esriLicenseStatus.esriLicenseAvailable)
                {
                    prodStatus=m_AoInit.Initialize(prod);
                    if(prodStatus==esriLicenseStatus.esriLicenseAlreadyInitialized||prodStatus==esriLicenseStatus.esriLicenseCheckedOut)
                    {
                        currentProduct = prod;
                    }
                }
            }

            if(m_AoInit.InitializedProduct()!=null)
            {
                foreach (esriLicenseExtensionCode ext in extensions)
                {
                    m_RequetedExtensionCodes.Add(ext);

                    esriLicenseStatus extStatus = m_AoInit.IsExtensionCodeAvailable(currentProduct,ext);
                    if (extStatus == esriLicenseStatus.esriLicenseAvailable)
                        m_AoInit.CheckOutExtension(ext);

                }
            }
        }
Пример #2
0
        /// <summary>
        /// A summary of the status of product and extensions initialization.
        /// </summary>
        public string LicenseMessage()
        {
            string prodStatus = string.Empty;

            if (m_productStatus == null || m_productStatus.Count == 0)
            {
                prodStatus = MessageNoLicensesRequested + Environment.NewLine;
            }
            else if (m_productStatus.ContainsValue(esriLicenseStatus.esriLicenseAlreadyInitialized) ||
                     m_productStatus.ContainsValue(esriLicenseStatus.esriLicenseCheckedOut))
            {
                prodStatus = ReportInformation(m_AoInit as ILicenseInformation,
                                               m_AoInit.InitializedProduct(),
                                               esriLicenseStatus.esriLicenseCheckedOut) + Environment.NewLine;
            }
            else
            {
                //Failed...
                foreach (KeyValuePair <esriLicenseProductCode, esriLicenseStatus> item in m_productStatus)
                {
                    prodStatus += ReportInformation(m_AoInit as ILicenseInformation,
                                                    item.Key, item.Value) + Environment.NewLine;
                }
            }

            string extStatus = string.Empty;

            foreach (KeyValuePair <esriLicenseExtensionCode, esriLicenseStatus> item in m_extensionStatus)
            {
                string info = ReportInformation(m_AoInit as ILicenseInformation, item.Key, item.Value);
                if (!string.IsNullOrEmpty(info))
                {
                    extStatus += info + Environment.NewLine;
                }
            }

            string status = prodStatus + extStatus;

            return(status.Trim());
        }
Пример #3
0
        //签出产品许可
        private bool CheckOutLicenseMain(esriLicenseProductCode code)
        {
            try
            {
                if (m_AoInitializeClass.IsProductCodeAvailable(code) == esriLicenseStatus.esriLicenseAvailable)
                {
                    if (m_AoInitializeClass.Initialize(code) == esriLicenseStatus.esriLicenseCheckedOut)
                    {
                        m_AoInitializeClass.InitializedProduct();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }

            return(false);
        }
        private bool Initialize()
        {
            //Version 10 check
            //if (RuntimeManager.ActiveRuntime == null)
            //    return false;

            if (m_requestedProducts == null || m_requestedProducts.Count == 0)
                return false;

            bool productInitialized = false;

            m_requestedProducts.Sort();
            if (!InitializeLowerProductFirst) //Request license from highest to lowest
                m_requestedProducts.Reverse();

            m_AoInit = new AoInitializeClass();
            esriLicenseProductCode currentProduct = new esriLicenseProductCode();

            //version 9.3 check
            //Try to initialize a product
            ILicenseInformation licInfo = (ILicenseInformation)m_AoInit;
            // licInfo is not used??

            foreach (int prodNumber in m_requestedProducts)
            {
                esriLicenseProductCode prod = (esriLicenseProductCode)Enum.ToObject(typeof(esriLicenseProductCode), prodNumber);
                esriLicenseStatus status = m_AoInit.IsProductCodeAvailable(prod);
                if (status == esriLicenseStatus.esriLicenseAvailable)
                {
                    status = m_AoInit.Initialize(prod);
                    if (status == esriLicenseStatus.esriLicenseAlreadyInitialized ||
                        status == esriLicenseStatus.esriLicenseCheckedOut)
                    {
                        productInitialized = true;
                        currentProduct = m_AoInit.InitializedProduct();
                    }
                }

                m_productStatus.Add(prod, status);

                if (productInitialized)
                    break;
            }

            m_hasInitializeProduct = productInitialized;
            m_requestedProducts.Clear();

            //No product is initialized after trying all requested licenses, quit
            if (!productInitialized)
            {
                return false;
            }

            //Check out extension licenses
            return CheckOutLicenses(currentProduct);
        }