public Question PopQuestion(IQuestionKey keyToUseForReference)
            {
                ResolveDeletionsAndAdditions();

                PhraseCustomization questionToInsert;

                try
                {
                    questionToInsert = AdditionsAndInsertions.First();
                }
                catch (Exception e)
                {
                    throw new InvalidOperationException("PopQuestion should only be called for a customization that is not tied to any other question and has " +
                                                        "at least one insertion or addition.", e);
                }
                AdditionsAndInsertions.RemoveAt(0);
                var newQ = new Question(keyToUseForReference.ScriptureReference, keyToUseForReference.StartRef, keyToUseForReference.EndRef,
                                        questionToInsert.ModifiedPhrase ?? questionToInsert.OriginalPhrase, questionToInsert.Answer);

                SetExcludedAndModified(newQ);
                if (AllAnswers != null && AllAnswers.Any())                 // Note: If there are any, there are at least 2
                {
                    newQ.Answers = AllAnswers.ToArray();
                }
                return(newQ);
            }
            public bool IsInsertionAtOrBeforeReference(IQuestionKey keyToUseForReference, IEnumerable <Question> existingQuestionsInCategory, bool inclusive)
            {
                var addition = AdditionsAndInsertions.FirstOrDefault();

                return(addition != null && addition.Key.IsAtOrBeforeReference(keyToUseForReference, inclusive) &&
                       !existingQuestionsInCategory.Any(q => q.Matches(addition.Key)));
            }
Ejemplo n.º 3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="TranslatablePhrase"/> class.
 /// </summary>
 /// <param name="questionInfo">Information about the original question</param>
 /// <param name="category">The category (e.g. Overview vs. Detail question).</param>
 /// <param name="seqNumber">The sequence number (used to sort and/or uniquely identify
 /// a phrase within a particular category and reference).</param>
 /// ------------------------------------------------------------------------------------
 public TranslatablePhrase(IQuestionKey questionInfo, int category, int seqNumber)
     : this(questionInfo.Text, (questionInfo as Question)?.ModifiedPhrase)
 {
     m_questionInfo = questionInfo;
     Category       = category;
     SequenceNumber = seqNumber;
     // The following is normally done by the ModifiedPhrase setter, but there's a
     // chicken-and-egg problem when constructing this, so we need to do it here.
     if (IsUserAdded && m_sModifiedPhrase != null)
     {
         // This cast is entirely safe. Note above that for m_sModifiedPhrase to be non-null,
         // the questionInfo object
         ((Question)questionInfo).Text = m_sModifiedPhrase;
     }
 }
Ejemplo n.º 4
0
        public static int CompareTo(this IQuestionKey me, object obj)
        {
            var refsComparison = me.CompareRefs(obj);

            if (refsComparison != 0)
            {
                return(refsComparison);
            }

            // REVIEW: If both keys are for the same single verse or reference range, we can't say they are equal (because their text is different), but the comparison
            // is a little bit arbitrary. For built-in questions or insertions/additions hanging off them, this shouldn't be a problem, since they stay in their natural order.
            // Only questions added that do not correspond to any existing question could be compared. But generally, only one such "free" addition can happen for any given
            // reference (range). Any subsequent additions would be an insertion before that one or an addition after. Possible exception would be if two users independently
            // added questions.
            return(Compare(me.Text, ((IQuestionKey)obj).Text, StringComparison.Ordinal));
        }
Ejemplo n.º 5
0
        public static int CompareRefs(this IQuestionKey me, int startRef, int endRef)
        {
            var startRefComparison = me.StartRef.CompareTo(startRef);

            if (startRefComparison != 0)
            {
                return(startRefComparison);
            }
            if (me.EndRef == me.StartRef)
            {
                return(endRef == startRef ? 0 : 1);                // A key that represents a range always sorts before one that represents a single verse.
            }
            if (endRef == startRef)
            {
                return(-1);
            }
            return(me.EndRef.CompareTo(endRef));
        }
Ejemplo n.º 6
0
        public static int CompareRefs(this IQuestionKey me, object other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            if (me == other)
            {
                return(0);
            }
            var otherKey = other as IQuestionKey;

            if (otherKey == null)
            {
                throw new ArgumentException(nameof(other), $"Attempt to compare question key ({me}) to an unexpected object ({other}).");
            }

            return(me.CompareRefs(otherKey.StartRef, otherKey.EndRef));
        }
Ejemplo n.º 7
0
 public static bool Matches(this IQuestionKey me, IQuestionKey other)
 {
     return(me.CompareTo(other) == 0);
 }
 public UIQuestionDataString(IQuestionKey questionKey, bool original, bool useAnyAlternate)
 {
     m_questionKey    = questionKey;
     m_modifiedString = original || questionKey.PhraseInUse == questionKey.Text ? null : questionKey.PhraseInUse;
     UseAnyAlternate  = useAnyAlternate;
 }