Ejemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         DirectoryInfo di    = new DirectoryInfo(FmriCommon.getSrcImageDir(Server));
         FileInfo[]    lstFI = di.GetFiles("*.mat");
         foreach (FileInfo f in lstFI)
         {
             lstImageName.Items.Add(f.Name);
         }
     }
 }
Ejemplo n.º 2
0
    protected string isFilenameOK(string filename)
    {
        if (!filename.EndsWith(".mat"))
        {
            return(" Filename must end with '.mat' suffix! ");
        }
        if (System.IO.File.Exists(FmriCommon.getSrcImageDir(Server) + filename))
        {
            return(" Filename already exists on the server! ");
        }

        return(null);
    }
Ejemplo n.º 3
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblSFNValidationMessage.Visible = true;

        string errMsg = isFilenameOK(txtServerFileName.Text);

        if (errMsg != null)
        {
            lblSFNValidationMessage.Text = errMsg;
            return;
        }

        lblSFNValidationMessage.Visible = false;



        debugString("Got " + uploadCtrl.FileBytes.Length + " bytes...");
        string fname = FmriCommon.getSrcImageDir(Server) + txtServerFileName.Text;

        try
        {
            FileStream fs = new FileStream(
                fname,
                FileMode.CreateNew);
            fs.Write(uploadCtrl.FileBytes, 0, uploadCtrl.FileBytes.Length);
            fs.Close();

            debugString("Written successfully into " + fname + ".");

            lblResult.Text      = "File was successfully uploaded.";
            lblResult.ForeColor = System.Drawing.Color.Green;
            pnlResult.Visible   = true;
        }
        catch (IOException ioe)
        {
            lblResult.Text      = ioe.Message;
            lblResult.ForeColor = System.Drawing.Color.Red;
            pnlResult.Visible   = true;
        }
    }
Ejemplo n.º 4
0
    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.");
    }