private License LoadLicense()
        {
            License license = null;

            try
            {
                string text = this.privateStorer.LoadKey();
                if (text != null && text.Length > 0)
                {
                    license = LicenseConverter.KeyToLicense(this.decoder, text);
                }
                else
                {
                    text    = this.publicStorer.LoadKey();
                    license = LicenseConverter.KeyToLicense(this.decoder, text);
                }
            }
            catch (Exception ex)
            {
                Log.ReportException(ex);
            }
            if (license != null && LicenseVerificator.IsCorrect(license) && LicenseVerificator.IsPregenerated(license))
            {
                License license2 = this.LoadOldLicense();
                if (license2 != null && LicenseVerificator.IsCorrect(license2) && !LicenseVerificator.IsPregenerated(license2))
                {
                    if (LicenseVerificator.IsOutdatedForVersion2x(license2))
                    {
                        license2.UpgradeEvaluation = true;
                        license2.StartTime         = license.StartTime;
                        license2.EndTime           = license.EndTime;
                        license = license2;
                    }
                    else
                    {
                        license = license2;
                    }
                }
            }
            else
            {
                if (license == null)
                {
                    License license3 = this.LoadOldLicense();
                    if (license3 != null && LicenseVerificator.IsCorrect(license3))
                    {
                        license = license3;
                    }
                }
            }
            return(license);
        }
 private static void AppendUpgradeEvaluationExpirationInfo(StringBuilder builder, License license, DateTime now)
 {
     if (!LicenseVerificator.IsExpired(license, now))
     {
         int num = LicenseVerificator.DaysToExpire(license, now);
         if (num <= 30)
         {
             builder.AppendFormat("Temporary evaluation license expires in {0} day(s)\r\n", num);
             return;
         }
         builder.AppendFormat("Temporary evaluation license expires on {0:d}\r\n", license.EndTime);
     }
 }
 private void CacheLicense(License license)
 {
     this.cachedLicense = license;
     try
     {
         this.cachedIsRegistered = LicenseVerificator.IsValid(license, DateTime.UtcNow);
     }
     catch (Exception ex)
     {
         Log.ReportException(ex);
         this.cachedIsRegistered = false;
     }
     this.licenseIsCached = true;
 }
        public bool IsValidKey(string key)
        {
            bool result;

            try
            {
                key = KeyStringFormatter.ParseKey(key);
                License license = LicenseConverter.KeyToLicense(this.decoder, key);
                result = LicenseVerificator.IsValid(license, DateTime.UtcNow);
            }
            catch (LicensingException)
            {
                result = false;
            }
            return(result);
        }
        public bool RegisterKey(string key)
        {
            key = KeyStringFormatter.ParseKey(key);
            License license = LicenseConverter.KeyToLicense(this.decoder, key);

            if (!LicenseVerificator.IsValid(license, DateTime.UtcNow))
            {
                return(false);
            }
            this.privateStorer.SaveKey(key);
            this.CacheLicense(license);
            if (this.RegistrationChanged != null)
            {
                this.RegistrationChanged(this);
            }
            return(true);
        }
        private static void AppendLicenseExpirationInfo(StringBuilder builder, License license, DateTime now)
        {
            if (LicenseVerificator.IsExpired(license, now))
            {
                builder.AppendFormat("License expired on {0:d}\r\n", license.EndTime);
                return;
            }
            if (!LicenseVerificator.IsStarted(license, now))
            {
                builder.AppendFormat("License will be valid from {0:d}\r\n", license.StartTime);
                return;
            }
            int num = LicenseVerificator.DaysToExpire(license, now);

            if (num <= 30)
            {
                builder.AppendFormat("License expires in {0} day(s)\r\n", num);
                return;
            }
            builder.AppendFormat("License expires on {0:d}\r\n", license.EndTime);
        }
        public static string Format(License license, DateTime now)
        {
            if (license == null)
            {
                return("No license");
            }
            if (!LicenseVerificator.IsCorrect(license))
            {
                return("Unknown license");
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (license.UpgradeEvaluation)
            {
                LicenseInformationFormatter.AppendLicenseOutdatedInfo(stringBuilder);
                LicenseInformationFormatter.AppendUpgradeEvaluationExpirationInfo(stringBuilder, license, now);
            }
            else
            {
                if (LicenseVerificator.IsOutdatedForVersion2x(license))
                {
                    LicenseInformationFormatter.AppendLicenseOutdatedInfo(stringBuilder);
                }
                else
                {
                    LicenseInformationFormatter.AppendLicenseTypeInfo(stringBuilder, license);
                    LicenseInformationFormatter.AppendLicensedToInfo(stringBuilder, license);
                    if (LicenseVerificator.IsTimeLimited(license))
                    {
                        LicenseInformationFormatter.AppendLicenseExpirationInfo(stringBuilder, license, now);
                    }
                }
            }
            return(stringBuilder.ToString().TrimEnd(new char[]
            {
                '\r',
                '\n'
            }));
        }
Example #8
0
 public static bool IsExpiringSoon(License license, DateTime now)
 {
     return(LicenseVerificator.DaysToExpire(license, now) <= 7);
 }
Example #9
0
 public static bool IsOutdatedForVersion2x(License license)
 {
     return(!(license.PurchaseDate == DateTime.MinValue) && !(license.PurchaseDate == DateTime.MaxValue) && license.Type != LicenseType.OpenSource && !LicenseVerificator.IsTimeLimited(license) && license.PurchaseDate < LicenseVerificator.VisualStudio2010Beta2ReleaseDate);
 }
Example #10
0
 public static bool IsValid(License license, DateTime now)
 {
     return(license != null && LicenseVerificator.IsCorrect(license) && LicenseVerificator.IsStarted(license, now) && !LicenseVerificator.IsExpired(license, now) && !LicenseVerificator.IsOutdatedForVersion2x(license));
 }