Exemple #1
0
        /// <summary>
        /// When the viewmodel is shown, we know we are the entity that started it.  We should
        /// publish an event saying we are studying an entire line.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void ViewModelShownWhenStudyingAnEntireLine(object sender, EventArgs e)
        //{
        //  var viewModel = (IStudyItemViewModelBase)sender;
        //  var reviewMethodId = viewModel.ReviewMethodId;
        //  var reviewingLineEvent = new History.Events.ReviewingLineEvent(_Target, reviewMethodId);
        //  HistoryPublisher.Ton.PublishEvent(reviewingLineEvent);
        //}

        private async Task PopulateStudiersWithAggregatePhraseTexts()
        {
            if (_AbortIsFlagged)
            {
                return;
            }
            _Studiers.Clear();
            _LastStudiedIndex = -1;

            #region IF WE ONLY HAVE ONE AGGREGATE PHRASE TEXT, THEN POPULATE OUR STUDIER WITH OUR TARGET LINE

            if (AggregatePhraseTexts.Count == 1)
            {
                var studier = new DefaultPhraseMeaningStudier();
                #region Thinking (try..)
                var targetId = Guid.NewGuid();
                History.Events.ThinkingAboutTargetEvent.Publish(targetId);
                try
                {
                    #endregion
                    await studier.InitializeForNewStudySessionAsync(_Target.Phrase);

                    #region (...finally) Thinked
                }
                finally
                {
                    History.Events.ThinkedAboutTargetEvent.Publish(targetId);
                }
                #endregion
                _Studiers.Add(0, studier);
                return;
            }

            #endregion

            var phraseTextsCriteria =
                new Business.Criteria.PhraseTextsCriteria(_Target.Phrase.Language.Text, AggregatePhraseTexts);
            PhraseList phraseList = null;
            #region Thinking (try..)
            var targetId2 = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId2);
            try
            {
                #endregion
                phraseList = await PhraseList.NewPhraseListAsync(phraseTextsCriteria);

                #region (...finally) Thinked
            }
            finally
            {
                History.Events.ThinkedAboutTargetEvent.Publish(targetId2);
            }
            #endregion
            if (_AbortIsFlagged)
            {
                return;
            }

            List <PhraseEdit> unknownPhraseEdits = new List <PhraseEdit>();
            for (int i = 0; i < AggregatePhraseTexts.Count; i++)
            {
                if (_AbortIsFlagged)
                {
                    return;
                }
                var results = from phrase in phraseList
                              where phrase.Text == AggregatePhraseTexts[i]
                              select phrase;
                unknownPhraseEdits.Insert(i, results.First());
            }

            //WE NOW HAVE AN ORDERED LIST OF KNOWN AND UNKNOWN AGGREGATE PHRASEEDITS.
            //WE NEED TO FIND, AND KEEP IN RELATIVE ORDER, ONLY THE UNKNOWN PHRASEEDITS.
            //EACH PHRASE EDIT IS THE SAME INDEX AS ITS PHRASETEXT COUNTERPART.

            //WE NEED TO FIND THE COUNT OF UNKNOWN TEXTS FIRST, TO INCREMENT OUR COUNTER FOR ASYNC FUNCTIONALITY.
            int unknownCount = 0;
            for (int i = 0; i < AggregatePhraseTexts.Count; i++)
            {
                if (_AbortIsFlagged)
                {
                    return;
                }

                var phraseText = AggregatePhraseTexts[i];
                if (!IsPhraseKnown(phraseText))
                {
                    unknownCount++;
                }
            }

            //UNKNOWNRELATIVEORDER: UNKNOWN IN THAT OUR PHRASE IS UNKNOWN.  RELATIVE ORDER MEANS
            //THE ORDER/POSITION OF THIS PHRASE RELATIVE TO THE OTHER _UNKNOWN_ PHRASES.
            var unknownRelativeOrder = -1;
            int initializedCount     = 0;
            for (int i = 0; i < AggregatePhraseTexts.Count; i++)
            {
                if (_AbortIsFlagged)
                {
                    return;
                }

                var phraseText = AggregatePhraseTexts[i];
                if (IsPhraseKnown(phraseText))
                {
                    continue;
                }

                //PHRASE IS UNKNOWN, SO INC OUR RELATIVE ORDER AND ADD THE STUDIER TO STUDIERS, INITIALIZING EACH STUDIER.
                unknownRelativeOrder++;
                var studier = new DefaultPhraseMeaningStudier();
                #region Thinking (try..)
                var targetId3 = Guid.NewGuid();
                History.Events.ThinkingAboutTargetEvent.Publish(targetId3);
                try
                {
                    #endregion
                    await studier.InitializeForNewStudySessionAsync(unknownPhraseEdits[i]);

                    #region (...finally) Thinked
                }
                finally
                {
                    History.Events.ThinkedAboutTargetEvent.Publish(targetId3);
                }
                #endregion
                if (_AbortIsFlagged)
                {
                    return;
                }

                _Studiers.Add(unknownRelativeOrder, studier);
                initializedCount++;
                //IF WE HAVE INITIALIZED ALL OF OUR UNKNOWN PHRASES, THEN WE ARE DONE AND CAN CALL CALLBACK.
                if (initializedCount == unknownCount)
                {
                    return;
                }
            }

            //THIS LINE IS ENTIRELY KNOWN, SO INITIALIZE A NEW STUDIER WITH THE ENTIRE LINE.
            if (unknownCount == 0)
            {
                var studier = new DefaultPhraseMeaningStudier();

                #region Thinking (try..)
                var targetId4 = Guid.NewGuid();
                History.Events.ThinkingAboutTargetEvent.Publish(targetId4);
                try
                {
                    #endregion
                    await studier.InitializeForNewStudySessionAsync(_Target.Phrase);

                    #region (...finally) Thinked
                }
                finally
                {
                    History.Events.ThinkedAboutTargetEvent.Publish(targetId4);
                }
                #endregion
                _Studiers.Add(0, studier);
                return;
            }
        }
Exemple #2
0
        public override async Task <ResultArgs <StudyItemViewModelArgs> > GetNextStudyItemViewModelAsync()
        {
            #region Abort Check
            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }
            #endregion

            //IF OUR _LASTSTUDIEDINDEX IS MAXED OUT STUDIERS COUNT, THEN WE
            //HAVE COMPLETED ONE ITERATION THROUGH OUR UNKNOWN AGGREGATE PHRASE TEXTS.
            if (_Studiers == null || _LastStudiedIndex >= (_Studiers.Count - 1))
            {
                //NOW WE WILL AGGREGATE OUR ADJACENT KNOWN TEXTS AND REPOPULATE OUR PHRASE STUDIERS
                //WITH ONLY THOSE PHRASES THAT WE DON'T KNOW
                var maxIterations = int.Parse(StudyResources.DefaultMaxIterationsAggregateAdjacentKnownPhraseTexts);
                #region Abort Check
                if (_AbortIsFlagged)
                {
                    return(await StudyHelper.GetAbortedAsync());
                }
                #endregion
                AggregateAdjacentKnownPhraseTexts(maxIterations);

                #region Abort Check
                if (_AbortIsFlagged)
                {
                    return(await StudyHelper.GetAbortedAsync());
                }
                #endregion
                await PopulateStudiersWithAggregatePhraseTexts();

                #region Abort Check
                if (_AbortIsFlagged)
                {
                    return(await StudyHelper.GetAbortedAsync());
                }
                #endregion
                if (_Studiers.Count == 0)
                {
                    //WE KNOW OUR ENTIRE LINE, SO POPULATE STUDIERS WITH A SINGLE PHRASE STUDIER WITH OUR LINE.PHRASE
                    var studier = new DefaultPhraseMeaningStudier();
                    await studier.InitializeForNewStudySessionAsync(_Target.Phrase);

                    _Studiers.Add(0, studier);
                    _LastStudiedIndex = 0;
                    return(await _Studiers[0].GetNextStudyItemViewModelAsync());
                }
                else
                {
                    //WE RETURN OUR FIRST STUDIER FOR THIS NEW STUDY CYCLE
                    return(await _Studiers[0].GetNextStudyItemViewModelAsync());
                }
            }
            else
            {
                #region Abort Check
                if (_AbortIsFlagged)
                {
                    return(await StudyHelper.GetAbortedAsync());
                }
                #endregion

                //WE ARE CONTINUING A STUDY CYCLE, SO RUN THE NEXT ONE AND UPDATE OUR LAST STUDIED INDEX.
                var indexToStudy = _LastStudiedIndex + 1;
                _LastStudiedIndex++;
                return(await _Studiers[indexToStudy].GetNextStudyItemViewModelAsync());
            }
        }