public void creatOnequestion(QuestionObj Question)
        {
            question.cQID      = Question.cQID;
            question.cQuestion = Question.question;
            answer.cQID        = Question.cQID;
            try
            {
                List <Action>    tasks      = new List <Action>();
                AnswerPathHelper ansPath    = new AnswerPathHelper(Question.CourseID, 0);
                Action           outputTask = new Action(() => question.OutputExample = storeOutputExample(Question, ansPath));
                tasks.Add(outputTask);
                Action inputTask = new Action(() => storeTestinput(Question, ansPath));
                tasks.Add(inputTask);
                Action answerTask = new Action(() => answer.cAnswer_Input = storeAnswer(Question, ansPath));
                tasks.Add(answerTask);

                Parallel.Invoke(tasks.ToArray());
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
        }
        public string storeOutputExample(QuestionObj oneQuestion, AnswerPathHelper Apath)
        {
            string       filepath = Apath.AnswerFormatFilePath + @"\" + oneQuestion.cQID + @".txt";
            StreamWriter example  = new StreamWriter(filepath, false);

            example.Write(oneQuestion.outputformat);
            example.Close();
            return(filepath);
        }
        public void storeTestinput(QuestionObj oneQuestion, AnswerPathHelper Apath)
        {
            string[] Inputs = oneQuestion.testinput.Split(new string[] { segmentsCut + "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int      count  = 1;

            foreach (string input in Inputs)
            {
                string       filepath  = Apath.AnswerInputFilePath + @"\" + oneQuestion.cQID + @"_" + count + @".txt";
                StreamWriter testinput = new StreamWriter(filepath, false);
                testinput.Write(input);
                testinput.Close();
                count += 1;
            }
        }
        public string storeAnswer(QuestionObj oneQuestion, AnswerPathHelper Apath)
        {
            string[] Answers = oneQuestion.answer.Split(new string[] { segmentsCut + "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int      count   = 1;

            foreach (string Answer in Answers)
            {
                string       filepath  = Apath.AnswerFilePath + @"\" + oneQuestion.cQID + @"_" + count + @".txt";
                StreamWriter testinput = new StreamWriter(filepath, false);
                testinput.Write(Answer);
                testinput.Close();
                count += 1;
            }
            answer.cTestingDataAmount = (count - 1).ToString();
            return(Apath.AnswerFilePath);
        }
示例#5
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);
        }
示例#6
0
        public string CorrectTask(string ProgramFilePath, string cQID, string StuProgramFN, string questionNum)
        {
            try
            {
                List <HW_Exam>         StuHW   = new List <HW_Exam>();
                List <StuCouHWDe_prog> StuHWDe = new List <StuCouHWDe_prog>();
                Program_Answer         answer;

                if (StuProgramFN == "all")
                {
                    HWPathHelper HWFilePath = new HWPathHelper(ProgramFilePath);
                    HWFilePath.HWPathdir();
                    answer = this.Answerrepository.Get(x => x.cQID == cQID);
                    AnswerPathHelper         CorrectAnswer = new AnswerPathHelper(answer.cAnswer_Input);
                    List <string>            fileFullname  = new List <string>();
                    string                   fileName;
                    List <CorrectTaskReturn> FinalResult = new List <CorrectTaskReturn>();
                    DirectoryInfo            direct      = new DirectoryInfo(HWFilePath.HWProgFilePath);
                    foreach (var file in direct.EnumerateFiles("*.cpp", SearchOption.AllDirectories))
                    {
                        if (file.Name.IndexOf("afterMF") == -1)
                        {
                            fileFullname.Add(file.FullName);
                            fileName = Path.GetFileNameWithoutExtension(file.FullName);
                            StuCouHWDe_prog getdata = this.StuCouHWDerepository.Get(x => x.StuProgramFN == fileName);
                            StuHW.Add(this.HWrepository.Get(x => x.StuCouHWDe_ID == getdata.StuCouHWDe_ID));
                            StuHWDe.Add(getdata);
                        }
                    }
                    Parallel.ForEach(fileFullname, (onefile, loopState) =>
                    {
                        FinalResult.Add(StartCorrect(HWFilePath, onefile, answer));
                    });
                    foreach (var result in FinalResult)
                    {
                        StuCouHWDe_prog StuHWDeNow = StuHWDe.Find(x => x.StuProgramFN == result.resultID);
                        HW_Exam         StuHWNow   = StuHW.Find(x => x.StuCouHWDe_ID == StuHWDeNow.StuCouHWDe_ID);
                        StuHWNow.HW_Exam_grade       = result.score(questionNum);
                        StuHWDeNow.Pass_compilation  = result.ComplationErrorMessage;
                        StuHWDeNow.Success_execution = result.ExecutionErrorMessage;
                        StuHWDeNow.Compare_situation = result.compareresult.TrimEnd(',');
                        this.HWrepository.Update(StuHWNow);
                        this.StuCouHWDerepository.Update(StuHWDeNow);
                    }
                }
                else
                {
                    HWPathHelper HWFilePath = new HWPathHelper(ProgramFilePath);
                    HWFilePath.HWPathdir();
                    answer = this.Answerrepository.Get(x => x.cQID == cQID);
                    AnswerPathHelper  CorrectAnswer = new AnswerPathHelper(answer.cAnswer_Input);
                    DirectoryInfo     direct        = new DirectoryInfo(HWFilePath.HWProgFilePath);
                    string            fileName;
                    CorrectTaskReturn FinalResult = new CorrectTaskReturn();
                    foreach (var file in direct.EnumerateFiles(StuProgramFN + ".cpp", SearchOption.AllDirectories))
                    {
                        if (file.Name.IndexOf("afterMF") == -1)
                        {
                            StuCouHWDe_prog StuHWDeNow = StuHWDe.Find(x => x.StuProgramFN == FinalResult.resultID);
                            HW_Exam         StuHWNow   = StuHW.Find(x => x.StuCouHWDe_ID == StuHWDeNow.StuCouHWDe_ID);
                            fileName                     = Path.GetFileNameWithoutExtension(file.FullName);
                            FinalResult                  = StartCorrect(HWFilePath, file.FullName, answer);
                            StuHWNow.HW_Exam_grade       = FinalResult.score(questionNum);
                            StuHWDeNow.Pass_compilation  = FinalResult.ComplationErrorMessage;
                            StuHWDeNow.Success_execution = FinalResult.ExecutionErrorMessage;
                            StuHWDeNow.Compare_situation = FinalResult.compareresult.TrimEnd(',');
                            this.HWrepository.Update(StuHWNow);
                            this.StuCouHWDerepository.Update(StuHWDeNow);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return("Some errors happen in the process when marking Programs!");
            }
            return("It is success when marking Programs!");
        }