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 static bool isOutImageExists(string md5, HttpServerUtility Server) { return(System.IO.File.Exists(FmriCommon.getOutImageDir(Server) + md5 + ".png")); }
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."); }