<%@ Page Language="c#" Codebehind="Admin.aspx.cs" AutoEventWireup="false" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="edu.jhu.Cas" %>
<%@ Import Namespace="edu.jhu.Cas.Util" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="net.ivoa.data" %>
<%
    DataSet ds = SqlFactory.select("select getdate() as current_db_time\nselect * from servicestatus");
    ds.Tables[1].Columns.Add("status", typeof(string));
    bool panic = false;
    DateTime currentDBTime = (DateTime)ds.Tables[0].Rows[0][0];
    string ok = "<span style=\"color:green\">OK</span>";
    string notok = "<span style=\"color:red\">PANIC!</span>";
    foreach (DataRow dr in ds.Tables[1].Rows) {
        DateTime lastCycle = (DateTime)dr["LastCycle"];
        int pminutes = (int)dr["PanicMinutes"];
        TimeSpan tdif = currentDBTime - lastCycle;
        if (tdif.TotalMinutes > pminutes) {
            dr["status"] = notok;
            panic = true;
        } else dr["status"] = ok;  
    }
    if (panic)
        Response.StatusCode = 501; // make BB happy
    DataSetWrapper dsw = new DataSetWrapper(ds);
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>casjobs service status</title>
</head>
<body>
    <%=WrapperFactory.Wrapper2HTML(dsw,2000) %>
</body>
</html>
