private bool FixLease(Lease lease, DateTime time, bool fixEndTime = true) { PostSharp.Sdk.Extensibility.Licensing.License parsedLicense = ParsedLicenseManager.GetParsedLicense(lease.License.LicenseKey); if (lease.EndTime <= lease.StartTime) { throw new Exception("Assertion failed."); } if (fixEndTime) { if (parsedLicense.ValidTo.HasValue && parsedLicense.ValidTo < lease.EndTime) { lease.EndTime = parsedLicense.ValidTo.Value; } if (lease.Grace) { DateTime graceEnd = lease.License.GraceStartTime.Value.AddDays(parsedLicense.GetGraceDaysOrDefault()); if (lease.EndTime > graceEnd) { lease.EndTime = graceEnd; } } if (lease.EndTime <= time) { return(false); } if (lease.EndTime <= lease.StartTime) { throw new Exception("Assertion failed."); } } lease.HMAC = this.GetSignature(lease); return(true); }
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); }
protected override void OnLoad(EventArgs e) { Database db = new Database(); License[] licenses = (from l in db.Licenses orderby l.Priority, l.LicenseId descending select l).ToArray(); List <LicenseInfo> licenseInfos = new List <LicenseInfo>(); for (int i = 0; i < licenses.Length; i++) { License license = licenses[i]; LicenseInfo licenseInfo = new LicenseInfo { LicenseId = license.LicenseId }; ParsedLicense parsedLicense = ParsedLicenseManager.GetParsedLicense(license.LicenseKey); if (parsedLicense == null) { licenseInfo.LicenseType = "INVALID"; } else { licenseInfo.LicenseType = parsedLicense.LicenseType.ToString(); licenseInfo.MaxUsers = parsedLicense.UserNumber; licenseInfo.CurrentUsers = db.GetActiveLeads(license.LicenseId, VirtualDateTime.UtcNow); licenseInfo.ProductCode = parsedLicense.Product.ToString(); licenseInfo.GraceStartTime = license.GraceStartTime; licenseInfo.Status = license.Priority >= 0 ? "Active" : "Disabled"; licenseInfo.MaintenanceEndDate = parsedLicense.SubscriptionEndDate; } licenseInfos.Add(licenseInfo); } this.noLicensePanel.Visible = licenseInfos.Count == 0; this.GridView1.DataSource = licenseInfos; this.GridView1.DataBind(); }
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); }
private static bool IsLicenseValid(License license) { return(ParsedLicenseManager.GetParsedLicense(license.LicenseKey) != null); }