Esempio n. 1
0
        public void InitStuCouHWDe_prog_record(string StuCouHWDe_ID, string StuProgramFN)
        {
            StuCouHWDe_prog NewData = new StuCouHWDe_prog();

            NewData.StuCouHWDe_ID = StuCouHWDe_ID;
            NewData.StuProgramFN  = StuProgramFN;
            this.StuCouHWDerepository.Create(NewData);
        }
Esempio n. 2
0
        public IResult Update(StuCouHWDe_prog instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException();
            }

            IResult result = new Result(false);

            try
            {
                this.StuCouHWDerepository.Update(instance);
                result.Success = true;
            }
            catch (Exception ex)
            {
                result.Exception = ex;
            }
            return(result);
        }
Esempio n. 3
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!");
        }