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); }
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(); }
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; }