public void EnqueueRequest(FmriRequest req) { lock (m_queue) { m_queue.Enqueue(req); } m_newItemEvent.Set(); }
public void EnqueueRequest(FmriRequest req) { lock (m_queue) { m_queue.Enqueue(req); } m_newItemEvent.Set(); }
public List <FmriRequest> GetQueueList() { FmriRequest[] queueArray; lock (m_queue) { queueArray = new FmriRequest[m_queue.Count]; m_queue.CopyTo(queueArray, 0); } return(new List <FmriRequest>(queueArray)); }
public List <FmriRequest> GetDoneList() { FmriRequest[] doneArray; lock (m_doneList) { doneArray = new FmriRequest[m_doneList.Count]; m_doneList.CopyTo(doneArray); } return(new List <FmriRequest>(doneArray)); }
protected void Page_Load(object sender, EventArgs e) { MatlabRunner m = FmriCommon.getMatlabRunner(Application, Server); List <FmriRequest> reqList; reqList = m.GetQueueList(); reqList.Reverse(); foreach (FmriRequest req in reqList) { TableRow r = new TableRow(); r.Height = 40; TableCell c; c = new TableCell(); c.Text = "Queue"; c.BackColor = Color.Orange; r.Cells.Add(c); AddCells(r.Cells, req); tblReq.Rows.Add(r); } reqList.Reverse(); FmriRequest currReq = m.CurrentRequest; if (currReq != null) { TableRow r = new TableRow(); r.Height = 40; TableCell c; c = new TableCell(); c.Text = "In Progress"; c.BackColor = Color.DarkGreen; c.ForeColor = Color.White; r.Cells.Add(c); AddCells(r.Cells, currReq); c = new TableCell(); c.Text = Convert.ToString(currReq.TimeExecuted); r.Cells.Add(c); tblReq.Rows.Add(r); } handleDone(m.GetDoneList(), tblReq, "Finished", Color.DarkSlateBlue, Color.White); handleDone((List <FmriRequest>)Application["ReqHist"], tblReq, "History", Color.LightGray, Color.Black); }
private void AddCells(TableCellCollection cells, FmriRequest req) { TableCell c; c = new TableCell(); c.Text = req.ImageName; cells.Add(c); c = new TableCell(); c.Text = "" + req.X1 + "-" + req.X2; cells.Add(c); c = new TableCell(); c.Text = "" + req.Y1 + "-" + req.Y2; cells.Add(c); c = new TableCell(); c.Text = "" + req.Z1 + "-" + req.Z2; cells.Add(c); c = new TableCell(); c.Text = Convert.ToString(req.Threshold); cells.Add(c); c = new TableCell(); c.Text = "" + req.T1 + "-" + req.T2; cells.Add(c); c = new TableCell(); c.Text = "" + req.CS1 + "-" + req.CS2; cells.Add(c); c = new TableCell(); c.Text = req.IPAddress; cells.Add(c); c = new TableCell(); c.Text = Convert.ToString(req.TimeSubmitted); cells.Add(c); }
private void execute(string imageName, int x1, int x2, int y1, int y2, int z1, int z2, double threshold, int t1, int t2, int cs1, int cs2) { debugString("Running on image: " + imageName); debugString("X=[" + x1 + "," + x2 + "]"); debugString("Y=[" + y1 + "," + y2 + "]"); debugString("Z=[" + z1 + "," + z2 + "]"); debugString("Threshold: " + threshold); FmriRequest req = new FmriRequest(imageName, x1, x2, y1, y2, z1, z2, threshold, t1, t2, cs1, cs2, Request.UserHostAddress); refStr.Value = req.AreaStringWithThresholdMD5; refNoThreshold.Value = req.AreaStringMD5; debugString("AreaString: " + req.AreaString + " (" + req.AreaStringMD5 + ")"); debugString("AreaStringWithThreshold: " + req.AreaStringWithThreshold + " (" + req.AreaStringWithThresholdMD5 + ")"); if (FmriCommon.isOutImageExists(req.AreaStringWithThresholdMD5, Server)) { debugString("Filename: \"" + FmriCommon.getOutImageDir(Server) + req.AreaStringWithThresholdMD5 + ".png" + "\" exists. good."); lblRef.ForeColor = System.Drawing.Color.Green; lblRef.Text = "Your request is completed. See results page!"; } else { MatlabRunner m = FmriCommon.getMatlabRunner(Application, Server); m.EnqueueRequest(req); debugString("Posted to queue."); lblRef.ForeColor = System.Drawing.Color.Blue; lblRef.Text = "Your request was posted to the queue. Try the results page later."; } }
private void execute(string imageName, int x1, int x2, int y1, int y2, int z1, int z2, double threshold, int t1, int t2, int cs1, int cs2) { debugString("Running on image: " + imageName); debugString("X=[" + x1 + "," + x2 + "]"); debugString("Y=[" + y1 + "," + y2 + "]"); debugString("Z=[" + z1 + "," + z2 + "]"); debugString("Threshold: " + threshold); FmriRequest req = new FmriRequest(imageName, x1, x2, y1, y2, z1, z2, threshold, t1, t2, cs1, cs2, Request.UserHostAddress); refStr.Value = req.AreaStringWithThresholdMD5; refNoThreshold.Value = req.AreaStringMD5; debugString("AreaString: " + req.AreaString + " (" + req.AreaStringMD5 + ")"); debugString("AreaStringWithThreshold: " + req.AreaStringWithThreshold + " (" + req.AreaStringWithThresholdMD5 + ")"); if (FmriCommon.isOutImageExists(req.AreaStringWithThresholdMD5, Server)) { debugString("Filename: \"" + FmriCommon.getOutImageDir(Server) + req.AreaStringWithThresholdMD5 + ".png" + "\" exists. good."); lblRef.ForeColor = System.Drawing.Color.Green; lblRef.Text = "Your request is completed. See results page!"; } else { MatlabRunner m = FmriCommon.getMatlabRunner(Application, Server); m.EnqueueRequest(req); debugString("Posted to queue."); lblRef.ForeColor = System.Drawing.Color.Blue; lblRef.Text = "Your request was posted to the queue. Try the results page later."; } }
public void handleRequest(FmriRequest req) { FmriCommon.LogToFile("MatlabRunner - handling request: {0}", req.AreaStringWithThreshold); m_currentRequest = req; string mtx_filename = FmriCommon.getMatrixDir(m_server) + req.AreaStringMD5 + ".mat"; string xls_filename = FmriCommon.getExcelDir(m_server) + req.AreaStringMD5 + ".csv"; string zip_filename = FmriCommon.getExcelDir(m_server) + req.AreaStringMD5 + ".zip"; try { if (!System.IO.File.Exists(mtx_filename)) { RunMatlabAndLog("should_calc_corr_matrix = 1;"); RunMatlabAndLog("src_image_filename = '" + FmriCommon.getSrcImageDir(m_server) + req.ImageName + "';"); object[] range = { req.X1, req.X2, req.Y1, req.Y2, req.Z1, req.Z2, req.T1, req.T2 }; RunMatlabAndLog(String.Format("x1={0};x2={1};y1={2};y2={3};z1={4};z2={5};t1={6};t2={7};", range)); RunMatlabAndLog("corr_matrix_out_filename = '" + mtx_filename + "';"); } else { RunMatlabAndLog("should_calc_corr_matrix = 0;"); RunMatlabAndLog("corr_matrix_in_filename = '" + mtx_filename + "';"); } if (!System.IO.File.Exists(xls_filename)) { RunMatlabAndLog("should_write_xls = 1;"); RunMatlabAndLog("xls_out_filename = '" + xls_filename + "';"); RunMatlabAndLog("zip_out_filename = '" + zip_filename + "';"); } else { RunMatlabAndLog("should_write_xls = 0;"); } RunMatlabAndLog("threshold = " + Convert.ToString(req.Threshold) + ";"); string out_image_filename = FmriCommon.getOutImageDir(m_server) + req.AreaStringWithThresholdMD5 + ".png"; RunMatlabAndLog("corr_image_out_filename = '" + out_image_filename + "';"); // Finished initializing variables. Run the MATLAB script now! req.executedNow(); RunMatlabAndLog("analyze;"); req.Result = m_matlab.LastResult; } catch (Exception e) { req.Result = e.Message; FmriCommon.LogToFile("MatlabRunner - exception caught: {0} [{1}]", e.Message, e.StackTrace); } finally { m_currentRequest = null; } try { string clique_filename = FmriCommon.getCliquesDir(m_server) + req.AreaStringWithThresholdMD5 + ".txt"; string jar_filename = FmriCommon.getJarFilename(m_server); object[] commandline = { jar_filename, xls_filename, req.Threshold, req.CS1, req.CS2, clique_filename }; System.Diagnostics.ProcessStartInfo psinfo = new System.Diagnostics.ProcessStartInfo( "java", String.Format("-jar {0} {1} {2} {3} {4} {5}", commandline)); psinfo.RedirectStandardError = true; psinfo.RedirectStandardOutput = true; psinfo.UseShellExecute = false; System.Diagnostics.Process java = System.Diagnostics.Process.Start(psinfo); FmriCommon.LogToFile("JAVA: started, PID=" + java.Id); java.WaitForExit(); FmriCommon.LogToFile("JAVA: finished, ExitCode=" + java.ExitCode); string stdout = java.StandardOutput.ReadToEnd().Trim(); string stderr = java.StandardError.ReadToEnd().Trim(); if (stdout != "" && stderr != "") { req.CliquesResult = stdout + ";\n" + stderr; } else if (stdout != "") { req.CliquesResult = stdout; } else { req.CliquesResult = stderr; } FmriCommon.LogToFile("JAVA: " + req.CliquesResult); } catch (Exception e) { req.CliquesResult = e.Message; FmriCommon.LogToFile("MatlabRunner - exception caught (cliques): {0} [{1}]", e.Message, e.StackTrace); } lock (m_doneList) { m_doneList.Add(req); } FmriCommon.LogToFile("MatlabRunner - request finished."); }
public List<FmriRequest> GetDoneList() { FmriRequest[] doneArray; lock (m_doneList) { doneArray = new FmriRequest[m_doneList.Count]; m_doneList.CopyTo(doneArray); } return new List<FmriRequest>(doneArray); }
public void handleRequest(FmriRequest req) { FmriCommon.LogToFile("MatlabRunner - handling request: {0}", req.AreaStringWithThreshold); m_currentRequest = req; string mtx_filename = FmriCommon.getMatrixDir(m_server) + req.AreaStringMD5 + ".mat"; string xls_filename = FmriCommon.getExcelDir(m_server) + req.AreaStringMD5 + ".csv"; string zip_filename = FmriCommon.getExcelDir(m_server) + req.AreaStringMD5 + ".zip"; try { if (!System.IO.File.Exists(mtx_filename)) { RunMatlabAndLog("should_calc_corr_matrix = 1;"); RunMatlabAndLog("src_image_filename = '" + FmriCommon.getSrcImageDir(m_server) + req.ImageName + "';"); object[] range = { req.X1, req.X2, req.Y1, req.Y2, req.Z1, req.Z2, req.T1, req.T2 }; RunMatlabAndLog(String.Format("x1={0};x2={1};y1={2};y2={3};z1={4};z2={5};t1={6};t2={7};", range)); RunMatlabAndLog("corr_matrix_out_filename = '" + mtx_filename + "';"); } else { RunMatlabAndLog("should_calc_corr_matrix = 0;"); RunMatlabAndLog("corr_matrix_in_filename = '" + mtx_filename + "';"); } if (!System.IO.File.Exists(xls_filename)) { RunMatlabAndLog("should_write_xls = 1;"); RunMatlabAndLog("xls_out_filename = '" + xls_filename + "';"); RunMatlabAndLog("zip_out_filename = '" + zip_filename + "';"); } else { RunMatlabAndLog("should_write_xls = 0;"); } RunMatlabAndLog("threshold = " + Convert.ToString(req.Threshold) + ";"); string out_image_filename = FmriCommon.getOutImageDir(m_server) + req.AreaStringWithThresholdMD5 + ".png"; RunMatlabAndLog("corr_image_out_filename = '" + out_image_filename + "';"); // Finished initializing variables. Run the MATLAB script now! req.executedNow(); RunMatlabAndLog("analyze;"); req.Result = m_matlab.LastResult; } catch (Exception e) { req.Result = e.Message; FmriCommon.LogToFile("MatlabRunner - exception caught: {0} [{1}]", e.Message, e.StackTrace); } finally { m_currentRequest = null; } try { string clique_filename = FmriCommon.getCliquesDir(m_server) + req.AreaStringWithThresholdMD5 + ".txt"; string jar_filename = FmriCommon.getJarFilename(m_server); object[] commandline = { jar_filename, xls_filename, req.Threshold, req.CS1, req.CS2, clique_filename }; System.Diagnostics.ProcessStartInfo psinfo = new System.Diagnostics.ProcessStartInfo( "java", String.Format("-jar {0} {1} {2} {3} {4} {5}", commandline)); psinfo.RedirectStandardError = true; psinfo.RedirectStandardOutput = true; psinfo.UseShellExecute = false; System.Diagnostics.Process java = System.Diagnostics.Process.Start(psinfo); FmriCommon.LogToFile("JAVA: started, PID=" + java.Id); java.WaitForExit(); FmriCommon.LogToFile("JAVA: finished, ExitCode=" + java.ExitCode); string stdout = java.StandardOutput.ReadToEnd().Trim(); string stderr = java.StandardError.ReadToEnd().Trim(); if( stdout != "" && stderr != "" ) { req.CliquesResult = stdout + ";\n" + stderr; } else if(stdout != "") { req.CliquesResult = stdout; } else { req.CliquesResult = stderr; } FmriCommon.LogToFile("JAVA: " + req.CliquesResult); } catch (Exception e) { req.CliquesResult = e.Message; FmriCommon.LogToFile("MatlabRunner - exception caught (cliques): {0} [{1}]", e.Message, e.StackTrace); } lock (m_doneList) { m_doneList.Add(req); } FmriCommon.LogToFile("MatlabRunner - request finished."); }
public List<FmriRequest> GetQueueList() { FmriRequest[] queueArray; lock (m_queue) { queueArray = new FmriRequest[m_queue.Count]; m_queue.CopyTo(queueArray, 0); } return new List<FmriRequest>(queueArray); }
private void AddCells(TableCellCollection cells, FmriRequest req) { TableCell c; c = new TableCell(); c.Text = req.ImageName; cells.Add(c); c = new TableCell(); c.Text = "" + req.X1 + "-" + req.X2; cells.Add(c); c = new TableCell(); c.Text = "" + req.Y1 + "-" + req.Y2; cells.Add(c); c = new TableCell(); c.Text = "" + req.Z1 + "-" + req.Z2; cells.Add(c); c = new TableCell(); c.Text = Convert.ToString(req.Threshold); cells.Add(c); c = new TableCell(); c.Text = "" + req.T1 + "-" + req.T2; cells.Add(c); c = new TableCell(); c.Text = "" + req.CS1 + "-" + req.CS2; cells.Add(c); c = new TableCell(); c.Text = req.IPAddress; cells.Add(c); c = new TableCell(); c.Text = Convert.ToString(req.TimeSubmitted); cells.Add(c); }