/// <summary>
        /// Loops over a set and returns the correct answer if found or any possibilities.
        /// </summary>
        /// <param name="url">The url of the set</param>
        /// <returns></returns>
        void GetSetInfo(String url, String userEnterQuestion, List <QuestionInfo> possible, List <QuestionInfo> correct, ParallelLoopState state)
        {
            // ScrapingBrowser scrapingBrowser = new ScrapingBrowser();

            List <QuestionInfo> setInfo = new List <QuestionInfo>();

            //  WebPage page = scrapingBrowser.NavigateToPage(new Uri(url));

            HtmlDocument htmlDocument = GetHtmlDocument(url);
            HtmlNode     n            = htmlDocument.DocumentNode;



            // HtmlNode n = page.Html;

            String name = n.Descendants("title").FirstOrDefault().InnerHtml;

            var stuff = n.Descendants("span").Where(x => x.GetAttributeValue("class", "").Contains("TermText")).ToList();

            for (int i = 0; i < stuff.Count() - 2; i += 2)
            {
                // Make sure all leading and trailing white spaces are gone. Lowercase the entire string
                String foundQuestion = stuff[i].InnerText.ToLower().Trim();
                String answer        = stuff[i + 1].InnerText;


                QuestionInfo questionInfo = new QuestionInfo(foundQuestion, answer, userEnterQuestion);


                // Add the question info to the dictionary. Use the found question as the key.
                if (!addedQuestions.Contains(foundQuestion))
                {
                    addedQuestions.Add(foundQuestion);

                    //Check if we have found the exact answer
                    if (questionInfo.Matches().foundType == FoundType.CORRECT)
                    {
                        correct.Add(questionInfo);

                        state.Break();
                    }
                    // Add a possibility to the list of questions
                    else if (questionInfo.Matches().foundType == FoundType.POSSIBLE)
                    {
                        possible.Add(questionInfo);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the current question info to the xml
        /// </summary>
        /// <param name="questionInfo"></param>
        public void AddQuestionInfo(QuestionInfo questionInfo)
        {
            FoundType foundType = questionInfo.Matches().foundType;

            XElement questionAnswer = new XElement("QuestionAnswer", new XAttribute("CorrectMatch", foundType.ToString()));

            questionAnswer.Add(new XElement("Question", questionInfo.Question));
            questionAnswer.Add(new XElement("Answer", questionInfo.Answer));
            root.Add(questionAnswer);
        }