コード例 #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("..");
        }
コード例 #2
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);
        }