private string GetBotStatusTimes() { using (var db = new DB()) { MonkeyWrench.WebServices.Authentication.Authenticate(Context, db, login, null, true); limit = Utils.TryParseInt32(Request.QueryString ["limit"]) ?? 1; // We only want the last job by default or more if asked. // Get hosts and statuses GetHostsResponse response = Utils.LocalWebService.GetHosts(login); GetBuildBotStatusResponse statuses = Utils.LocalWebService.GetBuildBotStatus(login); var results = new List <object>(); foreach (DBHost host in response.Hosts) { DBBuildBotStatus status = null; foreach (var tmp in statuses.Status) { if (tmp.host_id == host.id) { status = tmp; break; } } results.Add(new Dictionary <string, object> { { "id", host.id }, { "host", host.host }, { "enabled", host.enabled }, { "description", host.description }, { "architecture", host.architecture }, { "last_seen", status != null ? status.report_date.ToString("yyyy/MM/dd HH:mm:ss UTC") : "" }, { "last_job", this.GetHostHistory(db, host.id) }, }); } return(JsonConvert.SerializeObject(results, Formatting.Indented)); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string action = Request ["action"]; int host_id; if (!string.IsNullOrEmpty(action)) { switch (action) { case "remove": if (!int.TryParse(Request ["host_id"], out host_id)) { break; } Response.Redirect("Delete.aspx?action=delete-host&host_id=" + host_id.ToString()); return; case "add": try { Master.WebService.AddHost(Master.WebServiceLogin, Request ["host"]); Response.Redirect("EditHosts.aspx"); return; } catch (Exception ex) { lblMessage.Text = Utils.FormatException(ex); } break; default: // do nothing break; } } } else if (!string.IsNullOrEmpty(Request ["txtHost"])) { try { Master.WebService.AddHost(Master.WebServiceLogin, Request ["txtHost"]); Response.Redirect("EditHosts.aspx"); return; } catch (Exception ex) { lblMessage.Text = Utils.FormatException(ex); } } GetHostsResponse response = Master.WebService.GetHosts(Master.WebServiceLogin); GetBuildBotStatusResponse statuses = Master.WebService.GetBuildBotStatus(Master.WebServiceLogin); // TODO: make only 1 call TableRow row; foreach (DBHost host in response.Hosts) { DBBuildBotStatus status = null; foreach (var tmp in statuses.Status) { if (tmp.host_id == host.id) { status = tmp; break; } } var color = GetReportDateColor(host.enabled, status != null ? status.report_date : (DateTime?)null); row = new TableRow(); row.Cells.Add(Utils.CreateTableCell(string.Format("<a style='color:{2}' href='EditHost.aspx?host_id={0}'>{1}</a>", host.id, host.host, color))); row.Cells.Add(Utils.CreateTableCell( string.Format("<a style='color:{1}' href='EditHosts.aspx?host_id={0}&action=remove'>Delete</a> ", host.id, color) + string.Format("<a style='color:{1}' href='ViewHostHistory.aspx?host_id={0}'>View history</a>", host.id, color))); row.Cells.Add(Utils.CreateTableCell(host.description)); row.Cells.Add(Utils.CreateTableCell(host.architecture)); row.Cells.Add(Utils.CreateTableCell(status == null ? "-" : status.report_date.ToString("yyyy/MM/dd HH:mm:ss UTC"))); row.Style.Add(HtmlTextWriterStyle.Color, color); tblHosts.Rows.Add(row); } }