Exemplo 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("..");
        }
Exemplo n.º 2
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);
        }