예제 #1
0
        //Private

        #region # 验证服务器机器 —— void AuthenticateMachine()
        /// <summary>
        /// 验证服务器机器
        /// </summary>
        private void AuthenticateMachine()
        {
            bool authenticateMachine = true;

#if DEBUG
            authenticateMachine = false;
#endif
            if (authenticateMachine)
            {
                License?license = LicenseReader.GetLicense();

                if (license == null)
                {
                    throw new NoPermissionException("未找到许可证,请联系系统管理员!");
                }

                string uniqueCode = UniqueCode.Compute();
                bool   equal      = string.Equals(license.Value.UniqueCode, uniqueCode, StringComparison.CurrentCultureIgnoreCase);

                if (!equal)
                {
                    throw new NoPermissionException("许可证授权与本机不匹配,请联系系统管理员!");
                }
                if (DateTime.Today > license.Value.LicenseExpiredDate)
                {
                    throw new NoPermissionException("许可证授权已过期,请联系系统管理员!");
                }
            }
        }
예제 #2
0
        public void TestReadLicense()
        {
            License?license = LicenseReader.GetLicense();

            Assert.IsTrue(license != null);
            Assert.IsTrue(license.Value.EnterpriseName == "SD");
            Assert.IsTrue(license.Value.UniqueCode == "a1cab08d01ffc87b9ecaa873745592f1");
            Assert.IsTrue(license.Value.ServiceExpiredDate == CommonConstants.MaxDate);
            Assert.IsTrue(license.Value.LicenseExpiredDate == CommonConstants.MaxDate);
        }
예제 #3
0
        /// <summary>
        /// 打开按钮点击事件
        /// </summary>
        private void Btn_OpenLicense_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = @"License files (*.key)|*.key"
            };

            dialog.ShowDialog();

            string licenseFileName = dialog.FileName;

            if (!string.IsNullOrEmpty(licenseFileName))
            {
                License?license = LicenseReader.GetLicense(licenseFileName);

                if (license.HasValue)
                {
                    this.Txt_EnterpriseName.Text      = license.Value.EnterpriseName;
                    this.Txt_UniqueCode.Text          = license.Value.UniqueCode;
                    this.Dtp_ServiceExpiredDate.Value = license.Value.ServiceExpiredDate;
                    this.Dtp_LicenseExpiredDate.Value = license.Value.LicenseExpiredDate;
                }
            }
        }