예제 #1
0
    protected void Button_click(object sender, EventArgs e)
    {
        // Generate a random string for file name
        randomString rs = new randomString();

        // GUI control
        extension = codeList.SelectedValue;
        code      = codeText.Text;
        input     = codeInput.Text;

        // input text set to STDIN by default
        if (input == "STDIN")
        {
            input = "";
        }

        // generating code files to save them in root directory
        // the file is either C or CPP
        if (extension == ".c" || extension == ".cpp")
        {
            // calling the method to get a file name
            fileName = rs.generateFileName();
            // making a full source code name
            fullCodeFile = fileName + extension;
            // Saving the code file into the disk for further process
            generateFile gf = new generateFile();
            gf.generateCodeFile(root + fullCodeFile, code);
        }
        // generating code files to save them in root directory
        // the file is either C or CPP
        else if (extension == ".java")
        {
            // Same goes for JAVA as above
            fileName     = "Main";
            fullCodeFile = fileName + extension;
            generateFile gf = new generateFile();
            gf.generateCodeFile(root + fullCodeFile, code);
        }



        if (File.Exists(root + fullCodeFile))
        {
            // we'll only try to compile if the file is generated successfully
            try
            {
                compile(fullCodeFile, fileName, extension, input);
            }
            catch (Exception ex)
            {
                stat.Compile_status = "COMPILE FAILED!";

                //REDIRECT to another page
            }
        }

        show();
    }
예제 #2
0
    protected void submitBtn_Click(object sender, EventArgs e)
    {
        code      = Request.Form["hidden"];
        extension = codeList.SelectedValue;
        input     = Request.Form["stdin"];


        // Generate a random string for file name
        randomString rs = new randomString();

        // GUI control


        // input text set to STDIN by default
        if (code == "")
        {
            return;
        }

        stat.Code  = code;
        stat.STDIN = input;

        // generating code files to save them in root directory
        // the file is either C or CPP
        if (extension == ".c" || extension == ".cpp")
        {
            // calling the method to get a file name
            fileName = rs.generateFileName();
            // making a full source code name
            fullCodeFile = fileName + extension;

            stat.FileNameExt = fullCodeFile;
            // Saving the code file into the disk for further process
            generateFile gf = new generateFile();
            gf.generateCodeFile(root + fullCodeFile, code);
        }
        // generating code files to save them in root directory
        // the file is either C or CPP
        else if (extension == ".java")
        {
            // Same goes for JAVA as above
            fileName     = "Main";
            fullCodeFile = fileName + extension;

            stat.FileNameExt = fullCodeFile;
            generateFile gf = new generateFile();
            gf.generateCodeFile(root + fullCodeFile, code);
        }

        if (File.Exists(root + fullCodeFile))
        {
            // we'll only try to compile if the file is generated successfully
            try
            {
                compile(fullCodeFile, fileName, extension, input);
            }
            catch (Exception ex)
            {
                stat.Compile_status = "COMPILE FAILED!";
                showCompileStatus.Attributes["class"] = "alert alert-danger";
                //REDIRECT to another page
            }
        }
        show();
    }