private static void CreateSection(SoonLearning.Assessment.Data.Section section,
                                          int index,
                                          FlowDocument flowDocument,
                                          bool showAnswer,
                                          bool showResponse,
                                          Exercise exercise)
        {
            Paragraph sectionPara = new Paragraph();

            flowDocument.Blocks.Add(sectionPara);

            // Section Title
            Run runTItle = new Run(section.Title + section.Description);

            sectionPara.Inlines.Add(runTItle);

            // Create Questions
            for (int i = 0; i < section.QuestionCollection.Count; i++)
            {
                CreateQuestion(section.QuestionCollection[i],
                               i,
                               flowDocument,
                               showAnswer,
                               showResponse,
                               exercise.GetQuestionResponse(section.QuestionCollection[i].Id));
            }
        }
Esempio n. 2
0
        protected override void AppendQuestion(SectionBaseInfo info, SoonLearning.Assessment.Data.Section section)
        {
            switch (info.QuestionType)
            {
            case QuestionType.MultiChoice:
                this.CreateMCQuestion(info, section);
                break;

            case QuestionType.FillInBlank:
                this.CreateFIBQuestion(info, section);
                break;

            case QuestionType.Table:
                this.CreateTableQuestion(info, section);
                break;
            }
        }
Esempio n. 3
0
        protected virtual SoonLearning.Assessment.Data.Section CreateSection(SectionBaseInfo info, BackgroundWorker worker)
        {
            SoonLearning.Assessment.Data.Section section = ObjectCreator.CreateSection(info.Name, info.Description);

            Random rand           = new Random((int)DateTime.Now.Ticks);
            int    generatedCount = 0;

            while (true)
            {
                if (generatedCount == info.QuestionCount ||
                    generatedCount == info.MaxQuestionCount)
                {
                    break;
                }

                try
                {
                    AppendQuestion(info, section);
                }
                catch (NoMoreQuestionException noMoreEx)
                {
                    Debug.Assert(false, noMoreEx.Message);
                    break;
                }
                catch (Exception ex)
                {
                    Debug.Assert(false, ex.Message);
                }

                worker.ReportProgress(0, null);
                Debug.WriteLine(generatedCount);

                generatedCount++;

                Thread.Sleep(50);
            }

            return(section);
        }
Esempio n. 4
0
 protected abstract void AppendQuestion(SectionBaseInfo info, SoonLearning.Assessment.Data.Section section);
        private void CreateMCQuestion(SectionBaseInfo sectionInfo, Section section)
        {
            Random rand = new Random((int)DateTime.Now.Ticks);

            int    divValue     = rand.Next(2, 9);
            string questionText = string.Format("请选出是质数的数。");

            MCQuestion mcQuestion = ObjectCreator.CreateMCQuestion((content) =>
            {
                content.Content     = questionText;
                content.ContentType = ContentType.Text;
                return;
            },
                                                                   () =>
            {
                List <QuestionOption> optionList = new List <QuestionOption>();
                int minValue = 10;
                int maxValue = 100;
                if (sectionInfo is SectionValueRangeInfo)
                {
                    SectionValueRangeInfo rangeInfo = sectionInfo as SectionValueRangeInfo;
                    minValue = decimal.ToInt32(rangeInfo.MinValue);
                    maxValue = decimal.ToInt32(rangeInfo.MaxValue);
                }
                foreach (QuestionOption option in ObjectCreator.CreateDecimalOptions(
                             4, minValue, maxValue, false,
                             (c) =>
                {
                    for (int j = 2; j < c / 2 + 1; j++)
                    {
                        if (c % j == 0)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }))
                {
                    optionList.Add(option);
                }

                return(optionList);
            }
                                                                   );

            section.QuestionCollection.Add(mcQuestion);

            StringBuilder strBuilder = new StringBuilder();

            foreach (QuestionOption option in mcQuestion.QuestionOptionCollection)
            {
                QuestionContent content = option.OptionContent;
                decimal         value   = System.Convert.ToDecimal(content.Content);
                int             flag    = 1;
                int             j       = 1;

                if (value == 0)
                {
                    flag = 0;
                }

                for (j = 2; j < value / 2 + 1; j++)
                {
                    if (value % j == 0)
                    {
                        flag = 2;
                        break;
                    }
                }

                if (flag == 0)
                {
                    strBuilder.AppendLine(string.Format("0不是质数。"));
                }
                else if (flag == 1)
                {
                    strBuilder.AppendLine(string.Format("{0}只有两个约数{1},{2},是正确答案。", value, 1, value));
                }
                else
                {
                    strBuilder.AppendLine(string.Format("{0}有约数{1},{2},{3}...,大于2个。", value, 1, value, j));
                }
            }
            mcQuestion.Solution.Content = strBuilder.ToString();
        }