Example #1
0
        public void DoPaper(PaperDTO paper, int redo = 0)
        {
            //Task.Factory.StartNew(() => {
            Core.MainWindow.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Input, new ThreadStart(() =>
            {
                Core.MainWindow.lbStatus.Content = "狀態 : 正在做Paper #" + paper.PaperId;
            }));

            String paperId = "500359";
            //var paperId = paper.PaperId;
            var section = paper.Section;

            var timeUseMinSeconds = (int)TimeSpan.FromMinutes(Core.TimeUseMin).TotalSeconds;
            var timeUseMaxSeconds = (int)TimeSpan.FromMinutes(Core.TimeUseMax).TotalSeconds;
            var randomUseSeconds = new Random().Next(timeUseMinSeconds, timeUseMaxSeconds);
            //Normal paper should be 45mins, but mock paper is variable
            var secondLeft = (int)TimeSpan.FromMinutes(45).TotalSeconds - randomUseSeconds;

            //Submit the paper first in order to get the answer
            String tmpSubmitResult = WebClientEx.Instance.Post(Constants.SUBMIT_PAPER,
                String.Format("PaperID={0}&section={1}&redo1={2}&extype=0&secondleft={3}&Action=submit", paperId.ToString(), section.ToString(), redo.ToString(), secondLeft),
                String.Format("http://www2.i-learner.com.hk/dse/dsemock2015.php?p={0}&sec={1}", paperId.ToString(), section.ToString()));

            System.Windows.MessageBox.Show(tmpSubmitResult);
            String tmpExeId = JObject.Parse(tmpSubmitResult)["exeID"].ToString();
            System.Windows.MessageBox.Show(tmpExeId);

            //var questionAnalyseJsonString = WebClientEx.Instance.Post(Constants.GET_QUESTION_ANALYSE,
            //    String.Format("PaperID={0}&section={1}", paperId, section),
            //    String.Format("http://www2.i-learner.com.hk/dse/dsemock2015.php?p={0}&sec={1}", paper.PaperId, paper.Section));

            var questionAnalyseJsonString = WebClientEx.Instance.Post(Constants.GET_QUESTION_ANALYSE,
                String.Format("PaperID={0}&section={1}&eid={2}&redo={3}", paperId, section, tmpExeId, redo.ToString()),
                String.Format("http://www2.i-learner.com.hk/dse/dsemock2015.php?p={0}&sec={1}", paper.PaperId, paper.Section));

            var questionAnalyseObj = JsonConvert.DeserializeObject<QuestionAnalyseRootObject>(questionAnalyseJsonString);

            System.Windows.MessageBox.Show(questionAnalyseJsonString);
            var modelAnswers = questionAnalyseObj.modelAnswers;

            var correctPercentage = Core.CorrectPercentage;
            //If not 50 cannot submit
            if (correctPercentage < 50)
                correctPercentage = 50;
            var correctQuestionCount = (int)Math.Round(((double)(correctPercentage * modelAnswers.Count) / 100));
            var wrongQuestionCount = modelAnswers.Count - correctQuestionCount;

            var postData = BuildDoPaperPostData(paper, modelAnswers, secondLeft, wrongQuestionCount, redo);
            //System.IO.File.WriteAllText("D:\\post_new.txt", postData);
            //return true;

            var submitResult = WebClientEx.Instance.Post(Constants.SUBMIT_PAPER,
                                                         postData,
                                                         String.Format("http://www2.i-learner.com.hk/dse/dsemock2015.php?p={0}&sec={1}", paper.PaperId, paper.Section));
            string exeId = JObject.Parse(submitResult)["exeID"].ToString();

            WebClientEx.Instance.Post(Constants.GET_QUESTION_ANALYSE,
                String.Format("PaperID={0}&section={1}&redo1=0&eid={2}", paperId, section, exeId),
                String.Format("http://www2.i-learner.com.hk/dse/dsemock2015.php?p={0}&sec={1}", paper.PaperId, paper.Section));

            //Confirm and save marks
            WebClientEx.Instance.Post(Constants.SAVE_MARKS_URL,
                String.Format("PaperID={0}&section={1}", paperId, section),
                String.Format("http://www2.i-learner.com.hk/dse/dsemock2015.php?p={0}&sec={1}", paper.PaperId, paper.Section));

            Core.MainWindow.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Input, new ThreadStart(() =>
            {
                Core.MainWindow.lbStatus.Content = "狀態 : 準備";
            }));
            //});
        }
Example #2
0
        private string BuildDoPaperPostData(PaperDTO paper, List<ModelAnswer> modelAnswers, int secondLeft, int _wrongQuestionCount, int redo = 0)
        {
            #if DEBUG
            System.Windows.MessageBox.Show("Second Left = " + secondLeft + " = " + TimeSpan.FromSeconds(secondLeft).TotalMinutes.ToString() + "\r\n"
                                           + "Marks expected = " + (modelAnswers.Count - _wrongQuestionCount) + "/" + modelAnswers.Count);
            #endif
            string basicInfo = String.Format("PaperID={0}&section={1}&redo1={2}", paper.PaperId, paper.Section, redo);
            StringBuilder data = new StringBuilder();

            for (int i = 0; i < modelAnswers.Count; i++)
            {
                var ans = modelAnswers[i];
                int questionId = i + 1;

                #region "StudentSubmitData"
                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[Sequence]=" + questionId);

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[QuestionLevel]=0");

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[questionID]=" + questionId);

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[correct]=0");

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[contentpoints]=1");

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[fullmark]=0");

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[forRedo]=0");

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[score]=0");

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[runatserver]=1");

                data.Append("&StudentSubmitData[" + i + "]");
                data.Append("[answertext]=");
                #endregion
            }

            ProcessPaperDom(paper, modelAnswers, data, _wrongQuestionCount);

            data.Append("&totalquestion=" + paper.TotalQuestion);
            data.Append("&extype=" + paper.Section);
            data.Append("&secondleft=" + secondLeft);
            data.Append("&Action=submit");

            return basicInfo + Uri.EscapeUriString(data.ToString())
                .Replace("%3d", "=")
                .Replace("%26", "&")
                .Replace("%5b", "%5B")
                .Replace("%5d", "%5D");
        }
Example #3
0
        private void ProcessPaperDom(PaperDTO paper, List<ModelAnswer> modelAnswers, StringBuilder data, int _wrongQuestionCount)
        {
            //WebClientEx.Instance.WcGetAsync(String.Format(Constants.GET_PAPER_URL, paper.PaperId, paper.Section), (result) =>
            //{
            int wrongQuestionCount = _wrongQuestionCount;
            var result = WebClientEx.Instance.Get(String.Format(Constants.GET_PAPER_URL, paper.PaperId, paper.Section));
            HtmlDocument htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(result);
            var docNode = htmlDoc.DocumentNode;
            var answerBook = docNode.QuerySelector(".answerbook");
            if (answerBook != null)
            {
                for (int i = 0; i < modelAnswers.Count; i++)
                {
                    var currentAns = modelAnswers[i];
                    int questionNo = Convert.ToInt32(currentAns.questionno);
                    var nodeQ = docNode.QuerySelector("#q" + questionNo);
                    if (nodeQ == null)
                    {
                        System.Windows.MessageBox.Show("NodeQ is null, skip it.");
                        continue;
                    }
                    if (currentAns.modelanswer == @"N\/A" || currentAns.modelanswer == @"N\A" || currentAns.modelanswer == @"N/A")
                    {
                        //Don't have model answer, TODO
                        System.Windows.MessageBox.Show("No Model Answer, skip");
                        continue;
                    }
                    var classes = nodeQ.Attributes["class"].Value.Split(' ').ToList();
                    data.Append("&UserAnswer[" + i + "]");
                    data.Append("[questionID]=" + questionNo);

                    data.Append("&UserAnswer[" + i + "]");
                    data.Append("[forBlank]=1");

                    data.Append("&UserAnswer[" + i + "]");

                    if (wrongQuestionCount > 0)
                    {
                        data.Append("[useranswer]=" + "A");
                        wrongQuestionCount--;
                    }
                    else if (classes.Contains("mc"))
                    {
                        //data.Append("[useranswer]=" + correntAnswerChoice);
                        data.Append("[useranswer]=" + "D");
                    }
                    else if (classes.Contains("op"))
                    {
                        data.Append("[useranswer]=" + currentAns.modelanswer);
                    }
                    else
                    {
                        //TODO
                        data.Append("[useranswer]=" + "N/A");
                    }

                    data.Append("&UserAnswer[" + i + "]");
                    data.Append("[correct]=-1");
                }
            }
            //});
        }
Example #4
0
        public List<PaperDTO> GetPaperList()
        {
            GetMyScheduleMenu(Core.StudentLevel);
            List<PaperDTO> papers = new List<PaperDTO>();
            List<MyScheduleMenu> menu = LatestMyScheduleMenu;

            string lastTitle = "";
            int time = 0;

            foreach (var paper in menu)
            {
                if (Convert.ToInt32(paper.ready) == 0)
                    continue;

                PaperDTO dto = new PaperDTO();

                if (paper.lv1MenuLabel == null || paper.lv1MenuLabel.IsEmpty())
                    dto.Category = "Unknown";
                else
                    dto.Category = paper.lv1MenuLabel;

                dto.PaperId = Convert.ToInt32(paper.paperID);
                dto.Section = Convert.ToInt32(paper.extype);

                //dto.Available = Convert.ToInt32(paper.ready) == 0 ? false : true;

                /*
                bool somethingIsMissing = false;
                if (paper.lv2MenuLabel == null || paper.lv3MenuLabel == null)
                    somethingIsMissing = true;
                */

                if (paper.lv1MenuLabel == "Reading")
                    dto.Title = paper.lv2MenuLabel;
                else
                    dto.Title = String.Format("[{0}] {1}", paper.lv2MenuLabel, paper.lv3MenuLabel);

                if (dto.Title == lastTitle)
                    time++;
                else
                    time = 1;

                dto.Exercise = time;

                if (paper.total_question == null || paper.total_question == null)
                {
                    dto.TotalQuestion = 0;
                    dto.AnswerCorrect = 0;
                    dto.Done = false;
                }
                else
                {
                    dto.TotalQuestion = Convert.ToInt32(paper.total_question);
                    dto.AnswerCorrect = Convert.ToInt32(paper.total_answer_correct);
                    dto.Done = true;
                }

                lastTitle = dto.Title;

                papers.Add(dto);
            }

            return papers;
        }