示例#1
0
        private void UpdateRespondeModel(ref TestModelDto testModel, string status)
        {
            testModel.Point = 0;
            switch (status)
            {
            case "TO":
            {
                testModel.ExecutionTime = "Time Limit Exceeeded!";
                testModel.Message       = "Time Limit Exceeded!";
                testModel.MemoryUsed    = _responseDictionary["cg-mem"];
                break;
            }

            case "SG":
            {
                testModel.ExecutionTime = "Memory limit exceeeded!";
                testModel.Message       = "Caught fatal signal 9!";
                testModel.MemoryUsed    = "Caught fatal signal 9";
                break;
            }

            case "RE":
            {
                testModel.ExecutionTime = "Runtime Error!";
                testModel.Message       = "Runtime Error!";
                testModel.MemoryUsed    = "Runtime Error";
                break;
            }
            }
        }
示例#2
0
 public RpcResponse <bool> AddData(TestModelDto model)
 {
     return(RpcCommHelper.GetReponse <bool>(() =>
     {
         return TestDateHelper.AddDataByModel(model).Id > 0;
     }));
 }
示例#3
0
 public RpcResponse <bool> UpdateData(TestModelDto model)
 {
     return(RpcCommHelper.GetReponse <bool>(() =>
     {
         return TestDateHelper.UpdateData();
     }));
 }
示例#4
0
        public TestModelDto GetTestObject(int id)
        {
            TestModelDto testObj = null;

            try
            {
                QuestionModelDto       questionObj            = null;
                AnswerModelDto         answerObj              = null;
                QuestionWithAnswersDto questionWithAnswersObj = null;
                List <AnswerModelDto>  answersList            = null;

                using (var conn = new SqlConnection(base.GetConnectionString()))
                {
                    conn.Open();
                    var test = testRepo.GetTests(conn).First(obj => obj.TestID == id);
                    testObj = mapper.Map <Test, TestModelDto>(test);

                    var questions       = questionRepo.GetQuestionsByTestID(testObj.TestID, conn);
                    var questionAnswers = questionAnswerRepo.GetQuestionAnswers(conn);
                    var answers         = answerRepo.GetAnswers(conn);

                    testObj.Questions = new List <QuestionWithAnswersDto>();

                    foreach (var question in questions)
                    {
                        questionObj = mapper.Map <Question, QuestionModelDto>(question);

                        var questAnsw = questionAnswers.Where(q => q.QuestionID == question.QuestionID);
                        answersList = new List <AnswerModelDto>();
                        foreach (var qAnsw in questAnsw)
                        {
                            var answer = answers.First(x => x.AnswerID == qAnsw.AnswerID);
                            answerObj         = mapper.Map <Answer, AnswerModelDto>(answer);
                            answerObj.Correct = qAnsw.Correct;
                            answersList.Add(answerObj);
                        }

                        questionWithAnswersObj = new QuestionWithAnswersDto()
                        {
                            Question = questionObj,
                            Answers  = answersList
                        };

                        testObj.Questions.Add(questionWithAnswersObj);
                    }

                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error("GetTestObject() error. Test: " + testObj.Naming, e);
            }

            return(testObj);
        }
示例#5
0
        public Tuple <string, int> SerializeReponseTest(List <ResponseExecutionModel> responseExecutionModels)
        {
            //first property represent the status: "time:1.125---time-wall:1.143---max-rss:4972---csw-voluntary:1---csw-forced:315---cg-mem:2512---"
            //second parameter represent the resut:Response: Incorrect!\n
            //we parse all the result and we'll serialize the list where we store the new results
            int sumPoints = 0;

            foreach (var item in responseExecutionModels)
            {
                _responseDictionary = new Dictionary <string, string>();
                string executionResult = item.ExecutionResults;
                string executionOutput = item.ExecutionStatus;

                var options = executionResult.Split(new string[] { "---" }, StringSplitOptions.None);
                foreach (var metaParameter in options)
                {
                    var splitOption = metaParameter.Split(':');
                    if (splitOption.Length > 1)
                    {
                        var key = splitOption[0];
                        var val = splitOption[1];
                        _responseDictionary.Add(key, val);
                    }
                }

                var testModel = new TestModelDto();
                if (_responseDictionary.ContainsKey("status"))
                {
                    //we have an error
                    //see what is the status (TLE, OR MEM)
                    string val = _responseDictionary["status"];
                    UpdateRespondeModel(ref testModel, val);
                }
                else
                {
                    //don't have errors
                    testModel.ExecutionTime = _responseDictionary["time"];
                    testModel.MemoryUsed    = _responseDictionary["cg-mem"];

                    if (executionOutput.Contains("Ok!"))
                    {
                        testModel.Point   = 10;
                        testModel.Message = "Ok!";
                        sumPoints        += 10;
                    }
                    else
                    {
                        testModel.Point   = 0;
                        testModel.Message = "Incorrect!";
                    }
                }

                _listTestModel.Add(testModel);
            }

            var serializedList = JsonConvert.SerializeObject(_listTestModel);

            return(new Tuple <string, int>(serializedList, sumPoints));
        }
示例#6
0
        public ActionResult Post([FromBody] TestModelDto test)
        {
            int testId = testFacade.AddTestObject(test);

            _log.Info("Insert a new test: " + test.Naming);

            return(Ok("Succes"));
        }
示例#7
0
 public static TestModelDto AddDataByModel(TestModelDto model)
 {
     using (var provider = ProvidersHelper.Resolve <ITestProvider>())
     {
         var daoModel = MapperHelper.AutoMapTo <DaoTestModel>(model);
         var rsDao    = provider.AddData(daoModel);
         var rsDto    = MapperHelper.AutoMapTo <TestModelDto>(rsDao);
         return(rsDto);
     }
 }
示例#8
0
        public async Task <ActionResult> Post([FromBody] TestModelDto dto)
        {
            var model = TestModelDto.ToTestModel(dto);

            await _unitOfWork.TestModelRepository.DbSet.AddAsync(model);

            await _unitOfWork.CommitAsync();

            return(Ok());
        }
示例#9
0
        public int AddTestObject(TestModelDto test)
        {
            int testId = -1;

            try
            {
                int      questionID;
                int      answerID;
                Test     testObj     = null;
                Question questionObj = null;
                Answer   answerObj   = null;

                using (var conn = new SqlConnection(base.GetConnectionString()))
                {
                    conn.Open();
                    testObj = mapper.Map <TestModelDto, Test>(test);
                    testId  = testRepo.AddTest(testObj, conn);

                    if (test.Questions != null)
                    {
                        foreach (var question in test.Questions)
                        {
                            questionObj        = mapper.Map <QuestionModelDto, Question>(question.Question);
                            questionObj.TestID = testId;
                            questionID         = questionRepo.AddQuestion(questionObj, conn);
                            if (question.Answers != null)
                            {
                                foreach (var answer in question.Answers)
                                {
                                    answerObj = mapper.Map <AnswerModelDto, Answer>(answer);
                                    answerID  = answerRepo.AddAnswer(answerObj, conn);
                                    questionAnswerRepo.AddOrUpdateQuestionAnswer(questionID, answerID, answer.Correct, conn);
                                }
                            }
                        }
                    }

                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error("AddTestObject() error. Test: " + test.Naming, e);
            }

            return(testId);
        }
示例#10
0
 public async Task SaveMessage(TestModelDto dto)
 {
     var model = Mapper.Map <TestModel>(dto);
     await Daos.CurrentDao.AddOrUpdate <TestModel, int>(model);
 }
示例#11
0
        public ActionResult Put([FromBody] TestModelDto test)
        {
            var id = testFacade.UpdateTest(test);

            return(Ok(id));
        }