Esempio n. 1
0
        protected void AddButton_OnClick(object sender, EventArgs e)
        {
            ParsedLicense parsedLicense = ParsedLicense.Deserialize(this.licenseKeyTextBox.Text);

            if (parsedLicense == null)
            {
                this.errorLabel.Text    = "Invalid license key.";
                this.errorLabel.Visible = true;
                return;
            }

            if (!parsedLicense.IsLicenseServerElligible())
            {
                this.errorLabel.Text = string.Format("Cannot add a {0} of {1} to the server.",
                                                     parsedLicense.GetLicenseTypeName() ?? "(unknown license type)",
                                                     parsedLicense.GetProductName( ));
                this.errorLabel.Visible = true;
                return;
            }

            License license = new License
            {
                LicenseId   = parsedLicense.LicenseId,
                LicenseKey  = ParsedLicense.CleanLicenseString(this.licenseKeyTextBox.Text),
                CreatedOn   = VirtualDateTime.UtcNow,
                ProductCode = parsedLicense.Product.ToString(),
            };
            Database db = new Database();

            db.Licenses.InsertOnSubmit(license);
            db.SubmitChanges();

            this.Response.Redirect("..");
        }
 public LicenseState(DateTime time, Database db, License license, ParsedLicense parsedLicense)
 {
     this.time          = time;
     this.db            = db;
     this.license       = license;
     this.ParsedLicense = parsedLicense;
 }
Esempio n. 3
0
        public static ParsedLicense GetParsedLicense(string licenseKey)
        {
            ParsedLicense parsedLicense;

            if (!parsedLicenses.TryGetValue(licenseKey, out parsedLicense))
            {
                parsedLicense = ParsedLicense.Deserialize(licenseKey);

                string errorDescription;
                if (parsedLicense == null || !parsedLicense.Validate(null, out errorDescription))
                {
                    return(null);
                }

                parsedLicenses.Add(licenseKey, parsedLicense);
            }

            return(parsedLicense);
        }
Esempio n. 4
0
        private static LicenseState GetLicenseState(Database db, License license, DateTime?buildDate, DateTime now, Dictionary <int, LicenseState> cache, Dictionary <int, string> errors)
        {
            LicenseState licenseState;

            if (cache.TryGetValue(license.LicenseId, out licenseState))
            {
                return(licenseState);
            }

            ParsedLicense parsedLicense = ParsedLicenseManager.GetParsedLicense(license.LicenseKey);

            if (parsedLicense == null)
            {
                errors[license.LicenseId] = string.Format("The license key #{0} is invalid.", license.LicenseId);
                return(null);
            }

            if (!parsedLicense.IsLicenseServerElligible())
            {
                errors[license.LicenseId] = string.Format("The license #{0}, of type {1}, cannot be used in the license server.",
                                                          license.LicenseId, parsedLicense.LicenseType);
                return(null);
            }


            if (!(buildDate == null || parsedLicense.SubscriptionEndDate == null || buildDate <= parsedLicense.SubscriptionEndDate))
            {
                errors[license.LicenseId] = string.Format("The maintenance subscription of license #{0} ends on {1:d} but the requested version has been built on {2:d}.",
                                                          license.LicenseId, parsedLicense.SubscriptionEndDate, buildDate);
                return(null);
            }


            licenseState = new LicenseState(now, db, license, parsedLicense);
            cache.Add(license.LicenseId, licenseState);
            return(licenseState);
        }
        private static LicenseState GetLicenseState(Database db, License license, Version version, DateTime?buildDate, DateTime now, Dictionary <int, LicenseState> cache, Dictionary <int, string> errors)
        {
            LicenseState licenseState;

            if (cache.TryGetValue(license.LicenseId, out licenseState))
            {
                return(licenseState);
            }

            ParsedLicense parsedLicense = ParsedLicenseManager.GetParsedLicense(license.LicenseKey);

            if (parsedLicense == null)
            {
                errors[license.LicenseId] = string.Format("The license key #{0} is invalid.", license.LicenseId);
                return(null);
            }

            if (parsedLicense.MinPostSharpVersion > ApplicationInfo.Version)
            {
                errors[license.LicenseId] = string.Format(
                    "The license #{0} requires higher version of PostSharp on the License Server. Please upgrade PostSharp NuGet package of the License Server to >= {1}.{2}.{3}",
                    license.LicenseId,
                    parsedLicense.MinPostSharpVersion.Major,
                    parsedLicense.MinPostSharpVersion.Minor,
                    parsedLicense.MinPostSharpVersion.Build);
                return(null);
            }

            if (parsedLicense.MinPostSharpVersion > version)
            {
                errors[license.LicenseId] = string.Format(
                    "The license #{0} of type {1} requires PostSharp version >= {2}.{3}.{4} but the requested version is {5}.{6}.{7}.",
                    license.LicenseId,
                    parsedLicense.LicenseType,
                    parsedLicense.MinPostSharpVersion.Major,
                    parsedLicense.MinPostSharpVersion.Minor,
                    parsedLicense.MinPostSharpVersion.Build,
                    version.Major,
                    version.Minor,
                    version.Build);
                return(null);
            }

            if (!parsedLicense.IsLicenseServerEligible())
            {
                errors[license.LicenseId] = string.Format("The license #{0}, of type {1}, cannot be used in the license server.",
                                                          license.LicenseId, parsedLicense.LicenseType);
                return(null);
            }


            if (!(buildDate == null || parsedLicense.SubscriptionEndDate == null || buildDate <= parsedLicense.SubscriptionEndDate))
            {
                // PostSharp version number has been introduced in the license server protocol in PostSharp v5.
                if (version.Major >= 5)
                {
                    errors[license.LicenseId] = string.Format(
                        "The maintenance subscription of license #{0} ends on {1:d} but the requested version {2}.{3}.{4} has been built on {5:d}.",
                        license.LicenseId,
                        parsedLicense.SubscriptionEndDate,
                        version.Major,
                        version.Minor,
                        version.Build,
                        buildDate);
                }
                else
                {
                    errors[license.LicenseId] = string.Format(
                        "The maintenance subscription of license #{0} ends on {1:d} but the requested version has been built on {2:d}.",
                        license.LicenseId,
                        parsedLicense.SubscriptionEndDate,
                        buildDate);
                }

                return(null);
            }


            licenseState = new LicenseState(now, db, license, parsedLicense);
            cache.Add(license.LicenseId, licenseState);
            return(licenseState);
        }
 public LicenseState( DateTime time, Database db, License license, ParsedLicense parsedLicense )
 {
     this.time = time;
     this.db = db;
     this.license = license;
     this.ParsedLicense = parsedLicense;
 }