Пример #1
0
        public void RunService()
        {
            //Spawn new process - invoking the compiledFile
            UserProcess oProcess = new UserProcess();

            try
            {
                // set actual output file location
                actualOutputFileLocation = workingDirectory + actualOutputFile;

                //Set process start parameters
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.Arguments              = commandLineParams;
                psi.FileName               = compiledFileName;
                psi.WorkingDirectory       = workingDirectory;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError  = false;
                psi.UseShellExecute        = false;

                if (File.Exists(inputFileLocation))
                {
                    oProcess.InputFile = workingDirectory + Guid.NewGuid() + ".txt";
                    File.Copy(inputFileLocation, oProcess.InputFile, true);
                    psi.RedirectStandardInput = true;
                    try
                    {
                        SecurityACL dacl = new SecurityACL(Constants.AMUserName);
                        dacl.ApplyACLToFile(oProcess.InputFile);
                    }
                    catch (Exception)
                    {
                        // Continue on.  If we fail to apply the ACL, we may still be able
                        // to autocheck (i.e. if user has set custom permissions.
                    }
                }

                oProcess.StartInfo  = psi;
                oProcess.OutputFile = actualOutputFileLocation;

                //Log start
                SharedSupport.LogMessage(SharedSupport.GetLocalizedString("StudentAssignment_CheckStart"));

                if (!oProcess.Run(processTime))
                {
                    throw new System.Exception(SharedSupport.GetLocalizedString("ServerAction_FailedCreateTestProcess"));
                }

                //wait to see if process comes back in time.  Otherwise if it runs too long - kill it
                if (!oProcess.HasExited)
                {
                    SharedSupport.LogMessage(SharedSupport.GetLocalizedString("StudentAssignment_CheckKilled"));
                    throw new System.Exception(SharedSupport.GetLocalizedString("StudentAssignemtn_CheckExceededProcessTime"));
                }
                else
                {
                    SharedSupport.LogMessage(SharedSupport.GetLocalizedString("StudentAssignment_CheckEnd"));
                }
            }
            catch (Exception ex)
            {
                checkSuccessful = false;
                errorString     = ex.Message;
                SharedSupport.HandleError(ex);
            }
        }
Пример #2
0
        public void RunService()
        {
            //Create a new Process
            UserProcess compile = new UserProcess();

            try
            {
                System.Text.ASCIIEncoding AE = new System.Text.ASCIIEncoding();
                byte[] ByteArray             = { 34 };          // "
                string singleQuote           = AE.GetString(ByteArray);

                // path to output file
                string outputFilePath = SharedSupport.AddBackSlashToDirectory(workingDirectory) + OUTPUT_FILE;
                if (File.Exists(outputFilePath))
                {
                    File.Delete(outputFilePath);
                }

                //put quotes around command line arguments to avoid problems with spaces
                projectFileLocation = "\"" + projectFileLocation + "\"";
                buildType           = "\"" + buildType + "\"";
                projectName         = "\"" + projectName + "\"";

                //populate the process information
                compile.StartInfo.WorkingDirectory = workingDirectory;
                compile.StartInfo.FileName         = getDevEnvPath() + DEVENV;
                compile.StartInfo.Arguments        = projectFileLocation + BACKSLASH_BUILD + buildType + BACKSLASH_PROJECT + projectName + BACKSLASH_OUT + OUTPUT_FILE;
                compile.OutputFile = outputFilePath;
                compile.StartInfo.RedirectStandardOutput = true;
                compile.StartInfo.RedirectStandardError  = false;
                compile.StartInfo.UseShellExecute        = false;


                //start the compile process
                if (!compile.Run(processTime))
                {
                    throw new System.Exception(SharedSupport.GetLocalizedString("ServerAction_FailedCreateBuildProcess"));
                }

                // if the process exceeds allotted time, kill
                if (!compile.HasExited)
                {
                    outputExitCode = Constants.AUTOCOMPILE_RETURN_CODE_FAILURE;
                    buildResults   = SharedSupport.GetLocalizedString("StudentAssignment_Killed");
                }
                else
                {
                    // ok: exited before allotted time
                    outputExitCode = (int)compile.ExitCode;

                    // retrieve outcome from output.log file
                    StreamReader sr = new StreamReader(new FileStream(outputFilePath, FileMode.Open, FileAccess.Read));
                    buildResults = sr.ReadToEnd();
                    sr.Close();
                }

                // return compile results (true/false)
                if (outputExitCode == Constants.AUTOCOMPILE_RETURN_CODE_SUCCESS)
                {
                    buildSuccessful = true;
                }
            }
            catch (System.Exception ex)
            {
                buildResults    = ex.Message;
                buildSuccessful = false;
            }
        }