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); }
protected override void OnLoad(EventArgs e) { Database db = new Database(); LicenseId = int.Parse(this.Request.QueryString["id"]); Days = int.Parse(this.Request.QueryString["days"] ?? "30"); DateTime endDate = VirtualDateTime.UtcNow.Date.AddDays(1); DateTime startDate = endDate.AddDays(-Days); // Retrieve license information. License license = (from l in db.Licenses where l.LicenseId == LicenseId select l).Single(); ParsedLicense parsedLicense = ParsedLicense.Deserialize(license.LicenseKey); if (parsedLicense != null) { if (parsedLicense.UserNumber.HasValue) { this.Maximum = parsedLicense.UserNumber; this.GraceMaximum = this.Maximum.GetValueOrDefault() * (100 + parsedLicense.GetGracePercentOrDefault()) / 100; this.AxisMaximum = GraceMaximum.GetValueOrDefault(); } } var q = from l in db.GetLeaseCountingPoints(LicenseId, startDate, endDate) group l by l.Time.Date into d select new { Date = d.Key, Count = d.Max(point => point.LeaseCount), LastCount = d.OrderByDescending(point => point.Time).First().LeaseCount }; // Fill the array with data. this.Keys = new string[Days]; this.Values = new string[Days]; var lastValues = new int?[Days]; foreach (var point in q) { int day = (int)Math.Floor(point.Date.Subtract(startDate).TotalDays); if (point.Count > this.AxisMaximum) { this.AxisMaximum = point.Count; } if (day < 0) { this.Values[0] = point.Count.ToString(); lastValues[0] = point.LastCount; } else if (day < Days) { this.Values[day] = point.Count.ToString(); lastValues[day] = point.LastCount; } } // Do extrapolation of missing values. string lastValue = "0"; for (int i = 0; i < Days; i++) { DateTime date = startDate.AddDays(i); if (date.DayOfWeek == DayOfWeek.Monday) { this.Keys[i] = date.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture); } if (this.Values[i] == null) { if (i > 0) { this.Values[i] = lastValue; } else { this.Values[0] = lastValue; } } if (lastValues[i] != null) { lastValue = lastValues[i].ToString(); } } this.AxisMaximum = (int)Math.Ceiling(Math.Ceiling(this.AxisMaximum * 1.2) / 10) * 10; }
partial void DeleteLicense(License instance);
partial void UpdateLicense(License instance);
partial void InsertLicense(License instance);