/// <summary> /// Validate a license key. /// </summary> /// <param name="Key">The key to validate.</param> /// <returns>A LicenceState enumeration.</returns> public static LicenseState ValidateLicense(string Key) { try { LicenseBase license = new LicenseBase(Key); if (license.ProductObject.ProductCode != Product.Products.XEditNetCtrl) { return(LicenseState.Invalid); } if (license.ReleaseObject.Value != 0) { return(LicenseState.Invalid); } switch (license.LicenseObject.Type) { case LicenseType.LicenseTypes.Full: return(LicenseState.Full); case LicenseType.LicenseTypes.Invalid: return(LicenseState.Invalid); case LicenseType.LicenseTypes.None: return(LicenseState.None); case LicenseType.LicenseTypes.Trial: if (DateTime.Now <= license.ExpiryDate.LicenseDateTime) { return(LicenseState.Trial_Active); } return(LicenseState.Trial_Expired); } } catch { return(LicenseState.Invalid); } return(LicenseState.Invalid); }
public XEditNetLicence(string strSavedLicense) { /* * Constructor, creates and destroys the underlying real BaseLicense, * providing access to the 3 public Members, LicenseKey, Validity and ExpiryDate * */ try { LicenseBase licReal = new LicenseBase(strSavedLicense.ToUpper()); licenseKey = licReal.LicenseKey; validity = XEditNetLicenseValidator.ValidateLicense(LicenseKey); if (licReal.LicenseObject.Type == LicenseType.LicenseTypes.Trial) { expiryDate = licReal.ExpiryDate.LicenseDateTime; } licReal = null; } catch (InvalidLicenseException) { validity = LicenseState.Invalid; expiryDate = DateTime.MinValue; } }