Exemple #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:NewQuestionDlg"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public NewQuestionDlg(Question baseQuestion)
		{
			m_baseQuestion = baseQuestion;
			InitializeComponent();

			lblReference.Text = String.Format(lblReference.Text, m_baseQuestion.ScriptureReference);
		}
Exemple #2
0
		/// --------------------------------------------------------------------------------
		/// <summary>
		/// Constructor to make a new Question.
		/// </summary>
		/// --------------------------------------------------------------------------------
		public Question(Question baseQuestion, string newQuestion, string answer)
		{
			ScriptureReference = baseQuestion.ScriptureReference;
			StartRef = baseQuestion.StartRef;
			EndRef = baseQuestion.EndRef;
			Text = newQuestion;

			if (!string.IsNullOrEmpty(answer))
				Answers = new [] { answer };
		}
		/// --------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="XmlTranslation"/> class for an
		/// insertion or addition.
		/// </summary>
		/// --------------------------------------------------------------------------------
		public PhraseCustomization(string basePhrase, Question addedPhrase,
			CustomizationType type)
		{
			Reference = addedPhrase.ScriptureReference;
			OriginalPhrase = basePhrase;
			ModifiedPhrase = addedPhrase.Text;
			if (addedPhrase.Answers != null && addedPhrase.Answers.Length == 1)
				Answer = addedPhrase.Answers[0];
			Type = type;
		}
		public static QuestionSections Generate(IEnumerable<string> sourceLines, Dictionary<string, string[]> alternatives)
		{
			m_canonicalBookNumbers = new HashSet<int>();

			// Initialize the ID textbox.
			Category currCat = null;
			string currRef = null;
			int startRef = 0, endRef = 0;
			Section currSection = null;
			bool currSectionRefSet = false;
			Question currQuestion = null;
			List<Section> sections = new List<Section>();
			List<Question> currentQuestions = new List<Question>();
			int cAnswers = 0, cComments = 0, cCategories = 0;
			int kSectHeadMarkerLen = s_kSectionHead.Length;
			int kRefMarkerLen = s_kRefMarker.Length;
			int kQMarkerLen = s_kQuestionMarker.Length;
			int kAMarkerLen = s_kAnswerMarker.Length;
			int kCommentMarkerLen = s_kCommentMarker.Length;
			Debug.Assert(s_kDetailsMarker.Length == s_kOverviewMarker.Length);
			int kCategoryMarkerLen = s_kDetailsMarker.Length;
			Regex regexVerseNum = new Regex(@"\((?<startVerse>\d+)(-(?<endVerse>\d+))?\)$", RegexOptions.Compiled);
			foreach (string sLine in SourceFields(sourceLines))
			{
				if (sLine.StartsWith(s_kQuestionMarker))
				{
					if (currQuestion != null && cAnswers == 0 && cComments == 0)
					{
						// Question continued in a subsequent field. Just append the text to the existing question.
						currQuestion.Text += " " + sLine.Substring(kQMarkerLen).Trim();
					}
					else
					{
						currQuestion = new Question();
						currentQuestions.Add(currQuestion);
						currQuestion.Text = sLine.Substring(kQMarkerLen).Trim();
						if (currRef != currSection.ScriptureReference)
						{
							currQuestion.ScriptureReference = currRef;
							currQuestion.StartRef = startRef;
							currQuestion.EndRef = endRef;
						}
						cAnswers = 0;
						cComments = 0;
					}
				}
				else if (sLine.StartsWith(s_kAnswerMarker))
				{
					string currAnswer = sLine.Substring(kAMarkerLen).Trim();
					if (!currCat.IsOverview)
					{
						Match match = regexVerseNum.Match(currAnswer);
						if (match.Success)
						{
							int startVerse = Int32.Parse(match.Result("${startVerse}"));
							string sEndVerse = match.Result("${endVerse}");
							int endVerse = string.IsNullOrEmpty(sEndVerse) ? startVerse : Int32.Parse(sEndVerse);
							BCVRef bcvStart, bcvEnd;
							if (currQuestion.StartRef > 0)
							{
								bcvStart = new BCVRef(currQuestion.StartRef);
								bcvEnd = new BCVRef(currQuestion.EndRef);
								if (startVerse < bcvStart.Verse)
									bcvStart.Verse = startVerse;
								if (endVerse > bcvEnd.Verse)
									bcvEnd.Verse = endVerse;
							}
							else
							{
								bcvStart = new BCVRef(currSection.StartRef);
								bcvEnd = new BCVRef(currSection.EndRef);
								bcvStart.Verse = startVerse;
								bcvEnd.Verse = endVerse;
							}
							currQuestion.StartRef = bcvStart.BBCCCVVV;
							currQuestion.EndRef = bcvEnd.BBCCCVVV;
							currQuestion.ScriptureReference = BCVRef.MakeReferenceString(
								currSection.ScriptureReference.Substring(0, 3), bcvStart, bcvEnd, ".", "-");
						}
					}
					string[] source = currQuestion.Answers;
					currQuestion.Answers = new string[cAnswers + 1];
					if (source != null)
						Array.Copy(source, currQuestion.Answers, cAnswers);

					currQuestion.Answers[cAnswers++] = currAnswer;
				}
				else if (sLine.StartsWith(s_kCommentMarker))
				{
					if (currQuestion != null)
					{
						string[] source = currQuestion.Notes;
						currQuestion.Notes = new string[cComments + 1];
						if (source != null)
							Array.Copy(source, currQuestion.Notes, cComments);

						currQuestion.Notes[cComments++] = sLine.Substring(kCommentMarkerLen).Trim();
					}
				}
				else
				{
					if (sLine.StartsWith(s_kRefMarker))
					{
						currRef = sLine.Substring(kRefMarkerLen).Trim();
						Parse(currRef, out startRef, out endRef);
						if (!currSectionRefSet)
						{
							currSection.ScriptureReference = currRef;
							currSection.StartRef = startRef;
							currSection.EndRef = endRef;
							currSectionRefSet = true;
						}
					}
					else if (sLine.StartsWith(s_kSectionHead))
					{
						if (currentQuestions.Count > 0)
						{
							currCat.Questions = currentQuestions.ToArray();
							currentQuestions.Clear();
						}
						currSection = new Section();
						sections.Add(currSection);
						cCategories = 1;
						currSection.Categories = new Category[cCategories];
						currSection.Categories[0] = currCat = new Category();
						currSection.Heading = sLine.Substring(kSectHeadMarkerLen).Trim();
						currSectionRefSet = false;
					}
					else
					{
						bool isOverviewMarker = sLine.StartsWith(s_kOverviewMarker);
						if (isOverviewMarker || sLine.StartsWith(s_kDetailsMarker))
						{
							if (currentQuestions.Count > 0)
							{
								currCat.Questions = currentQuestions.ToArray();
								currentQuestions.Clear();
							}
							if (currCat.Type != null || currCat.Questions != null)
							{
								currCat = new Category();
								Category[] source = currSection.Categories;
								currSection.Categories = new Category[cCategories + 1];
								if (source != null)
									Array.Copy(source, currSection.Categories, cCategories);

								currSection.Categories[cCategories++] = currCat;
							}
							currCat.Type = sLine.Substring(kCategoryMarkerLen).Trim();
							currCat.IsOverview = isOverviewMarker;
						}
					}

					if (currQuestion != null)
					{
						currQuestion = null;
						cAnswers = 0;
						cComments = 0;
					}
				}
			}
			if (currCat != null && currentQuestions.Count > 0)
				currCat.Questions = currentQuestions.ToArray();

			QuestionSections questionSections = new QuestionSections();
			questionSections.Items = sections.ToArray();
			GenerateAlternateForms(questionSections, alternatives);
			return questionSections;
		}