%@ LANGUAGE="JSCRIPT" %><%
//
// 22-Jan-11 rbd GEM:574 (3.3) Initial edit
// 01-Jan-14 rbd 3.6 Add "Most Recent" to scheduler log page
// 10-Jan-14 rbd 3.6 GEM:1074 Fix HTML title for Scheduler vs ACP log
// 22-Jan-14 rbd GEM:1083 No more DBRelay hack :-)
// 17-Jan-19 rbd GEM:1660 Modern DOCTYPE and HTML declarations
// 07-Jan-21 rbd GEM:1801 Substitute 'd' fpor degree symbol in log text.
// Add a link and instructions for downloading the log.
// 14-Jul-23 rbd GEM:1906 "How did this ever work?"
//
//
// Enhance String with a trim() method
//
String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
};
var DB = Scheduler.Database;
var FSO = new ActiveXObject("Scripting.FileSystemObject");
Response.ExpiresAbsolute = new Date("Jan 1, 2000").getVarDate(); // Expire even with clock offsets
Response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
var op = Request.Form("op").Item; // Type of log
var title = "";
var logName = "";
var logData = ""; // Slurped contents of log
var tlName = ""; // Name for downloaded log
//
// TODO - REFACTOR!!
//
if (op == "SCH") // Scheduler's engine log
{
//
// sviewlog.asp?op=SCH
//
logName = title = "Scheduler Engine Log";
SH = new ActiveXObject("WScript.Shell");
try {
var relayPath = SH.RegRead("HKLM\\Software\\Denny\\ACP Scheduler\\InstallPath") + "\\CurrentLogPath.txt"
if (relayPath !== "") {
var rFile = FSO.OpenTextFile(relayPath.trim());
var logPath = rFile.ReadLine().trim();
rFile.Close();
tlName = FSO.GetFileName(logPath);
logName = "Most Recent Scheduler Engine Log " + tlName;
var lFile = FSO.OpenTextFile(logPath);
logData = lFile.ReadAll();
lFile.Close();
}
} catch (ex) {
logName = "Failed to get Scheduler Log";
logData = ex.message + "\r\n";
}
}
if (op == "ACP")
{
//
// sviewlog?op=ACP&oid=nnn where 'nnn' is the database ID of the Observation
//
var oid = Request.Form("oid").Item;
var O = DB.Observation(oid);
var logPath = O.LastSequencerLog;
tlName = FSO.GetFileName(logPath);
title = "ACP Run Log ";
logName = title + tlName + "
\r\n" +
" For Observation " + O.Name + " of Plan " + O.Plan.Name;
if (O.SetCount > 1)
logName += "
\r\nThis is for repeat " + O.SetsCompleted +
" of " + O.SetCount;
var lFile = FSO.OpenTextFile(logPath);
logData = lFile.ReadAll();
lFile.Close();
}
//
// Create the folder for storing the relayed logs if needed, then delete
// any existing relayed logs so they don't pile up.
//
var tfPath = Server.MapPath("/logRelay");
if(!FSO.FolderExists(tfPath))
FSO.CreateFolder(tfPath);
FSO.DeleteFile(tfPath + "\\*.*", true);
//
// Make temp text file reachable from web URL for downloading
//
var tlPath = Server.MapPath("/logRelay/" + tlName);
var tlFile = FSO.CreateTextFile(tlPath, true); // Create URL-accessible copy of this log
tlFile.Write(logData.replace("°", "d"));
tlFile.Close();
%>
To download this log, click the right-click the link above and select "Save link as..." or "Save target as..."
<%= logData.replace("°", "d") %>