原創(chuàng)|使用教程|編輯:何躍|2021-08-31 10:48:42.510|閱讀 330 次
概述:通過.NET庫 "IntelliLock.Licensing.dll",你能夠在運行時確定你的鎖定軟件的當(dāng)前許可狀態(tài)。你只需要在你的項目中引用這個庫并訪問相應(yīng)的方法和屬性。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
首先要引入程序集 using IntelliLock.Licensing;
1. 檢查授權(quán)是否有效
    /*** Check if a valid license file is available. ***/
    public bool IsValidLicenseAvailable()
    {
        return (EvaluationMonitor.CurrentLicense.LicenseStatus == IntelliLock.Licensing.LicenseStatus.Licensed);
    }
2. 讀取授權(quán)文件中的信息
    /*** Read additonal license information from a license file ***/
    public void ReadAdditonalLicenseInformation()
    {
        /* Check first if a valid license file is found */
        if (EvaluationMonitor.CurrentLicense.LicenseStatus == IntelliLock.Licensing.LicenseStatus.Licensed)
        {
            /* Read additional license information */
            for (int i = 0; i < EvaluationMonitor.CurrentLicense.LicenseInformation.Count; i++)
            {
                string key = EvaluationMonitor.CurrentLicense.LicenseInformation.GetKey(i).ToString();
                string value = EvaluationMonitor.CurrentLicense.LicenseInformation.GetByIndex(i).ToString();
            }
        }
    }
3. 檢查過期鎖狀態(tài)
/*** Check the license status of the Expiration Days Lock ***/
    public void CheckExpirationDaysLock()
    {
        bool lock_enabled = EvaluationMonitor.CurrentLicense.ExpirationDays_Enabled;
        int days = EvaluationMonitor.CurrentLicense.ExpirationDays;
        int days_current = EvaluationMonitor.CurrentLicense.ExpirationDays_Current;
    }
4. 依然是檢查過期鎖狀態(tài)
    /*** Check the license status of the Expiration Date Lock ***/
    public void CheckExpirationDateLock()
    {
        bool lock_enabled = EvaluationMonitor.CurrentLicense.ExpirationDate_Enabled;
        System.DateTime expiration_date = EvaluationMonitor.CurrentLicense.ExpirationDate;
    }
 
5. 檢查執(zhí)行鎖狀態(tài)
   /*** Check the license status of the Executions Lock ***/
    public void CheckExecutionsLock()
    {
        bool lock_enabled = EvaluationMonitor.CurrentLicense.Executions_Enabled;
        int max_executions = EvaluationMonitor.CurrentLicense.Executions;
        int current_executions = EvaluationMonitor.CurrentLicense.Executions_Current;
    }
6. 檢查實例鎖狀態(tài)
   /*** Check the license status of the Instances Lock ***/
    public void CheckNumberOfInstancesLock()
    {
        bool lock_enabled = EvaluationMonitor.CurrentLicense.Instances_Enabled;
        int max_instances = EvaluationMonitor.CurrentLicense.Instances;
    }
7. 檢查硬件鎖狀態(tài)
    /*** Check the license status of Hardware Lock ***/
    public void CheckHardwareLock()
    {
        bool lock_enabled = EvaluationMonitor.CurrentLicense.HardwareLock_Enabled;
 
        if (lock_enabled)
        {
            /* Get Hardware ID stored in the license file */
            string lic_hardware_id = EvaluationMonitor.CurrentLicense.HardwareID;
        }
    }
8. 獲得硬件ID
    /*** Get Hardware ID of the current machine ***/
    public string GetHardwareID()
    {
        return HardwareID.GetHardwareID(true, true, false, true, true, false);
    }
9. 對比硬件鎖
    /*** Compare current Hardware ID with Hardware ID stored in License File ***/
    public bool CompareHardwareID()
    {
        if (HardwareID.GetHardwareID(true, true, false, true, true, false) == EvaluationMonitor.CurrentLicense.HardwareID)
            return true;
        else
            return false;
    }
10. 作廢授權(quán)
    /*** Invalidate the license. Please note, your protected software does not accept a license file anymore! ***/
    public void InvalidateLicense()
    {
        string confirmation_code = License_DeActivator.DeactivateLicense();
    }
11. 重新激活授權(quán)
 /*** Reactivate an invalidated license. ***/
    public bool ReactivateLicense(string reactivation_code)
    {
        return License_DeActivator.ReactivateLicense(reactivation_code);
    }
12. 使用文件名手動加載一個許可證
 /*** Load the license. ***/
    public void LoadLicense(string filename)
    {
        EvaluationMonitor.LoadLicense(filename);
    }
13. 使用byte[]加載許可證
    /*** Load the license. ***/
    public void LoadLicense(byte[] license)
    {
        EvaluationMonitor.LoadLicense(license);
    }
14.  獲取加載的許可證(如果有的話),作為byte[] 。
 /*** Get the license. ***/
    public byte[] GetLicense()
    {
        return EvaluationMonitor.GetCurrentLicenseAsByteArray();   
    }
15. 異步檢查許可證狀態(tài)以防止啟動延遲
/*** Check the license. ***/
    class Program
    {
        // To automatically check the license asynchronously the option "Asynchronous License Check" must be enabled in IntelliLock
        static void Main(string[] args)
        {
            IntelliLock.Licensing.EvaluationMonitor.LicenseCheckFinished += () =>
            {
                Console.WriteLine(IntelliLock.Licensing.HardwareID.GetHardwareID(false, true, false, true, true, false));
                Console.WriteLine(IntelliLock.Licensing.CurrentLicense.LicenseStatus.ToString());
            };
 
            Console.ReadLine();
        }
    }
或者這樣寫也可以
/*** Check the license. ***/
    class Program
    {
        // To automatically check the license asynchronously the option "Asynchronous License Check" must be enabled in IntelliLock
        static void Main(string[] args)
        {
            string licenseFile = @"C:\license.license";
           
           // To ensure SDK method calls doesn't block/delay the control flow the SDK method LoadLicense(...) should be run in asynchronous context (new Action()..) as well
            new Action(() =>
            {
                IntelliLock.Licensing.EvaluationMonitor.LoadLicense(File.ReadAllBytes(licenseFile));
                IntelliLock.Licensing.EvaluationMonitor.LicenseCheckFinished += () =>
                {
                    Console.WriteLine(IntelliLock.Licensing.HardwareID.GetHardwareID(false, true, false, true, true, false));
                    Console.WriteLine(IntelliLock.Licensing.CurrentLicense.LicenseStatus.ToString());
                };
            }).BeginInvoke(null, null);
 
            Console.WriteLine("Due to asynchronous control flow this line is displayed first");
            Console.ReadLine();       
    }
	
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn