示例#1
0
        private void frmMain_Shown(object sender, EventArgs e)
        {
            //Initialize variables with default values
            MyLicense     _lic = null;
            var           _msg = string.Empty;
            LicenseStatus _status;

            //Read public key from resources
            _certPubicKeyData = DemoLicense.Properties.Resource.Licensing;

            //Check if the XML license file exists
            if (File.Exists("license.lic"))
            {
                _lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String(
                    typeof(MyLicense),
                    File.ReadAllText("license.lic"),
                    _certPubicKeyData,
                    out _status);
            }
            else
            {
                _status = LicenseStatus.INVALID;
                _msg    = "Your copy of this application is not activated";
            }

            switch (_status)
            {
            case LicenseStatus.VALID:

                //TODO: If license is valid, you can do extra checking here
                //TODO: E.g., check license expiry date if you have added expiry date property to your license entity
                //TODO: Also, you can set feature switch here based on the different properties you added to your license entity

                //Here for demo, just show the license information and RETURN without additional checking
                licInfo.ShowLicenseInfo(_lic);

                return;

            default:
                //for the other status of license file, show the warning message
                //and also popup the activation form for user to activate your application
                MessageBox.Show(_msg, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                using (var frm = new frmActivation())
                {
                    frm.CertificatePublicKeyData = _certPubicKeyData;
                    frm.ShowDialog();

                    //Exit the application after activation to reload the license file
                    //Actually it is not nessessary, you may just call the API to reload the license file
                    //Here just simplied the demo process

                    Application.Exit();
                }
                break;
            }
        }
示例#2
0
        private void frmMain_Shown(object sender, EventArgs e)
        {
            //Initialize variables with default values
            MyLicense _lic = null;
            string _msg = string.Empty;
            LicenseStatus _status = LicenseStatus.UNDEFINED;

            //Check if the XML license file exists
            if (File.Exists("license.lic"))
            {
                _lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String(typeof(MyLicense), File.ReadAllText("license.lic"), "LicenseVerify.cer", out _status, out _msg);
            }
            else
            {                
                _status = LicenseStatus.INVALID;
                _msg = "Your copy of this application is not activated";
            }

            switch (_status)
            {
                case LicenseStatus.VALID:

                    //TODO: If license is valid, you can do extra checking here
                    //TODO: E.g., check license expiry date if you have added expiry date property to your license entity
                    //TODO: Also, you can set feature switch here based on the different properties you added to your license entity 

                    //Here for demo, just show the license information and RETURN without additional checking       
                    licInfo.ShowLicenseInfo(_lic);
                            
                    return;

                default:
                    //for the other status of license file, show the warning message
                    //and also popup the activation form for user to activate your application
                    MessageBox.Show(_msg, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    using (frmActivation frm = new frmActivation())
                    {
                        frm.ShowDialog();

                        //Exit the application after activation to reload the license file 
                        //Actually it is not nessessary, you may just call the API to reload the license file
                        //Here just simplied the demo process
                        
                        Application.Exit();
                    }
                    break;
            }
        }