Пример #1
0
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            MyLicense license = null;

            string cpuid = GetCpuID();

            cpuid = DESLicense.Encrypt(cpuid);//加密

            if (context != null)
            {
                if (context.UsageMode == LicenseUsageMode.Runtime)
                {
                    String savedLicenseKey = context.GetSavedLicenseKey(type, null);
                    if (cpuid.Equals(savedLicenseKey))
                    {
                        return(new MyLicense(this, cpuid));
                    }
                }
                if (license != null)
                {
                    return(license);
                }

                // 打开License文件 'MyLicense.dat'
                if (Validation(cpuid))
                {
                    license = new MyLicense(this, cpuid);
                }
                if (license != null)
                {
                    context.SetSavedLicenseKey(type, cpuid);
                }
            }

            if (license == null)
            {
                //System.Windows.Forms.MessageBox.Show("!!!尚未注册!!!");
                throw new LicenseException(type, instance, "Your license is invalid");;
                //return new MyLicense(this,"no");
            }

            return(license);
        }
Пример #2
0
 public static bool Validation(string cpuid = null, string licFile = null)
 {
     if (string.IsNullOrWhiteSpace(cpuid))
     {
         cpuid = GetCpuID();
         cpuid = DESLicense.Encrypt(cpuid);//加密
     }
     if (string.IsNullOrWhiteSpace(licFile))
     {
         licFile = LicenseFullPath;
     }
     if (File.Exists(licFile))
     {
         var f = Serialize.Read <ChemLicense>(licFile);
         if (f != null && cpuid.Equals(f.CpuID))
         {
             return(true);
         }
     }
     return(false);
 }