Exemplo n.º 1
0
        public CorrectTaskReturn StartCorrect(HWPathHelper HWFilePath, string assignmentPath, Program_Answer answer)
        {
            AnswerPathHelper  CorrectAnswer = new AnswerPathHelper(answer.cAnswer_Input);
            string            filename;
            CorrectTaskReturn FinalResult;
            CorrectTaskResult compilationResult;
            CorrectTaskResult executionResult;

            filename             = Path.GetFileNameWithoutExtension(assignmentPath);
            FinalResult          = new CorrectTaskReturn();
            compilationResult    = new CorrectTaskResult();
            executionResult      = new CorrectTaskResult();
            compilationResult    = CorrectTaskHelper.compileprogram(HWFilePath, assignmentPath);
            FinalResult.resultID = filename;

            if (compilationResult.Success)
            {
                FinalResult.IsCompilationSuccess = true;
                DirectoryInfo direct = new DirectoryInfo(CorrectAnswer.AnswerInputFilePath);
                int           count  = 0;
                foreach (var file in direct.GetFiles(answer.cQID + "-*.txt"))
                {
                    count++;
                    string testnum = file.Name.Replace(".txt", "").Substring(file.Name.Replace(".txt", "").IndexOf("-"));
                    executionResult = CorrectTaskHelper.executeprogram(HWFilePath, filename, CorrectAnswer.AnswerInputFilePath + @"\" + file.Name);
                    if (executionResult.Success)
                    {
                        CorrectTaskHelper.adjustoutput(HWFilePath, filename + testnum);
                        CorrectTaskHelper.comparefile(HWFilePath, filename + testnum, CorrectAnswer.AnswerFilePath + @"\" + file.Name);
                        FinalResult.IsExecutionSuccess.Add(true);
                        FinalResult.IsComparsionSuccess.Add(CorrectTaskHelper.PassOrNot(HWFilePath, filename + testnum));
                        FinalResult.addcomparsion(CorrectTaskHelper.PassOrNot(HWFilePath, filename + testnum));
                    }
                    else
                    {
                        FinalResult.ExecutionErrorMessage += "測試" + testnum + @"執行錯誤:" + executionResult.errorMessage + "\r\n";
                    }
                }
                FinalResult.testnum = count;
            }
            else
            {
                FinalResult.ComplationErrorMessage = compilationResult.errorMessage;
            }

            return(FinalResult);
        }
Exemplo n.º 2
0
        //get the execution result
        public static CorrectTaskResult IsExecutionSuccess(HWPathHelper HWfilepath, string filename)
        {
            CorrectTaskResult result             = new CorrectTaskResult(false);
            string            ExecutionErrorfile = HWfilepath.HWExeErrorFilePath + @"\" + filename;
            StreamReader      errorFile          = new StreamReader(ExecutionErrorfile, System.Text.Encoding.UTF8);
            string            errorString        = null;

            errorString = errorFile.ReadToEnd();
            errorFile.Close();
            if (errorString == "")
            {
                result.Success = true;
                return(result);
            }
            else
            {
                result.errorMessage = errorString;
                return(result);
            }
        }
Exemplo n.º 3
0
        //get the compilation result
        public static CorrectTaskResult IsCompilationSuccess(string CompErrfilepath, string filename)
        {
            CorrectTaskResult result = new CorrectTaskResult(false);
            string            ComparisonErrorfile = CompErrfilepath + @"\" + filename;
            StreamReader      errorFile           = new StreamReader(ComparisonErrorfile, System.Text.Encoding.Default);
            string            errorString         = null;

            errorString = errorFile.ReadToEnd();
            errorFile.Close();
            if (errorString == "")
            {
                result.Success = true;
                return(result);
            }
            else
            {
                result.errorMessage = errorString;
                return(result);
            }
        }