Skip to content

Commit

Permalink
Merge pull request #1 from postsharp/feature/story-13182
Browse files Browse the repository at this point in the history
  • Loading branch information
prochan2 committed Apr 20, 2016
2 parents b7b36b1 + 4ad4fcd commit 1022906
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 139 deletions.
Binary file added .nuget/nuget.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions src/PostSharp.LicenseServer/Admin/Details.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@

</p>

<p>
<asp:LinkButton ID="disableHyperlink" runat="server" Text="Disable license key" OnClick="disableHyperlink_OnClick" /> <br/>
<asp:LinkButton ID="enableHyperlink" runat="server" Text="Enable license key" OnClick="enableHyperlink_OnClick"/> <br/>
<asp:LinkButton ID="deleteHyperlink" runat="server" Text="Delete license key and its leases" OnClick="deleteHyperlink_OnClick" OnClientClick="return confirm('Are you certain you want to delete this license key and all associate leases?');"/>
</p>

<p>
Page generated on <%=VirtualDateTime.UtcNow.ToLocalTime()%>.
</p>
Expand Down
45 changes: 44 additions & 1 deletion src/PostSharp.LicenseServer/Admin/Details.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace PostSharp.LicenseServer.Admin
Expand All @@ -22,7 +23,8 @@ protected override void OnLoad( EventArgs e )
int licenseId = int.Parse( this.Request.QueryString["id"] );
this.licenseIdLabel.Text = licenseId.ToString();

Database db = new Database();
Database db = new Database();
License license = db.Licenses.Single(l => l.LicenseId == licenseId);

DateTime now = VirtualDateTime.UtcNow;
List<Lease> leases = (from l in db.Leases
Expand All @@ -42,6 +44,47 @@ orderby l.StartTime

this.leaseCountLiteral.Text = leases.Count.ToString();
this.concurrentUserCountLiteral.Text = db.GetActiveLeads( licenseId, now ).ToString();

bool disabled = license.Priority < 0;
this.enableHyperlink.Visible = disabled;
this.deleteHyperlink.Visible = disabled;
this.disableHyperlink.Visible = !disabled;

}

private void ChangePriority(int priority)
{
int licenseId = int.Parse(this.Request.QueryString["id"]);

Database db = new Database();
License license = db.Licenses.Single(l => l.LicenseId == licenseId);
license.Priority = priority;
db.SubmitChanges();

this.Response.Redirect("..");
}

protected void disableHyperlink_OnClick(object sender, EventArgs e)
{
this.ChangePriority(-1);
}

protected void enableHyperlink_OnClick(object sender, EventArgs e)
{
this.ChangePriority(0);
}

protected void deleteHyperlink_OnClick(object sender, EventArgs e)
{
int licenseId = int.Parse(this.Request.QueryString["id"]);

Database db = new Database();
License license = db.Licenses.Single(l => l.LicenseId == licenseId);
db.Leases.DeleteAllOnSubmit(license.Leases);
db.Licenses.DeleteOnSubmit(license);
db.SubmitChanges();

this.Response.Redirect("..");
}
}
}
129 changes: 78 additions & 51 deletions src/PostSharp.LicenseServer/Admin/Details.aspx.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/PostSharp.LicenseServer/Admin/GenerateDemoData.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ protected void Button1_Click( object sender, EventArgs e )
// Which machine will he use this day?
int machineIndex = (int) Math.Floor( random.NextDouble()*user.Machines.Count );
string machine = user.Machines[machineIndex];
List<string> errors = new List<string>();
Dictionary<int, string> errors = new Dictionary<int, string>();
time = time.AddHours( random.NextDouble()*3.0/activeUsers.Count );
Lease lease = leaseService.GetLease( db, product, machine, user.UserName, user.AuthenticatedName, time, errors );
DateTime buildDate = time;
Lease lease = leaseService.GetLease( db, product, buildDate, machine, user.UserName, user.AuthenticatedName, time, errors );
if ( lease != null )
{
db.SubmitChanges();
Expand Down
2 changes: 2 additions & 0 deletions src/PostSharp.LicenseServer/Default.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<asp:BoundField DataField="GraceStartTime" HeaderText="Grace Period Started On" />
<asp:BoundField DataField="MaxUsers" HeaderText="Max Number of Users" />
<asp:BoundField DataField="CurrentUsers" HeaderText="Current Number Of Users" />
<asp:BoundField DataField="MaintenanceEndDate" HeaderText="End of Maintenance" DataFormatString="{0:d}"/>
<asp:BoundField DataField="Status" HeaderText="Status"/>
<asp:HyperLinkField DataNavigateUrlFields="LicenseId" DataNavigateUrlFormatString="Admin/Details.aspx?id={0}"
Text="Detail" />
<asp:HyperLinkField DataNavigateUrlFields="LicenseId" DataNavigateUrlFormatString="Graph.aspx?id={0}"
Expand Down
6 changes: 5 additions & 1 deletion src/PostSharp.LicenseServer/Default.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public partial class DefaultPage : Page
protected override void OnLoad( EventArgs e )
{
Database db = new Database();
License[] licenses = (from l in db.Licenses orderby l.ProductCode , l.Priority select l).ToArray();
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++ )
Expand All @@ -40,6 +40,8 @@ protected override void OnLoad( EventArgs e )
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 );
Expand All @@ -58,6 +60,8 @@ private class LicenseInfo
public int? MaxUsers { get; set; }
public int CurrentUsers { get; set; }
public DateTime? GraceStartTime { get; set; }
public string Status { get; set; }
public DateTime? MaintenanceEndDate { get; set; }
}
}
}
Loading

0 comments on commit 1022906

Please sign in to comment.