コード例 #1
0
        /// <summary>
        /// Creates a study item using the phrase and nativeLanguageText.  If the phrase.Language
        /// is the same as the native language, then this will be a study item related to studying
        /// the meaning of the phrase, all in the native language.  If these two languages are
        /// different, then it will procure a translation study item.
        /// This prepares the view model so that all that is necessary for the caller is to call
        /// viewmodel.Show(...);
        /// </summary>
        public async Task <StudyItemViewModelBase> ProcureAsync(PhraseEdit phrase,
                                                                string nativeLanguageText)
        //public async Task<ResultArgs<StudyItemViewModelBase>> ProcureAsync(PhraseEdit phrase,
        {
            //FOR NOW, THIS WILL JUST CREATE ONE TYPE OF STUDY ITEM VIEW MODEL: STUDY QUESTION ANSWER VIEWMODEL.
            //IT WILL SHOW THE QUESTION AND HIDE THE ANSWER FOR VARIOUS AMOUNTS OF TIME, DEPENDING ON QUESTION
            //LENGTH, AND OTHER FACTORS.
            //IN THE FUTURE, THIS WILL BE EXTENSIBILITY POINT WHERE WE CAN SELECT DIFFERENT VARIETIES OF Q AND A
            //TRANSLATION VIEW MODELS BASED ON HOW SUCCESSFUL THEY ARE.  WE CAN ALSO HAVE DIFFERENT CONFIGURATIONS
            //OF VARIETIES BE SELECTED HERE.

            //ViewModels.StudyTimedQuestionAnswerViewModel viewModel = new ViewModels.StudyTimedQuestionAnswerViewModel();

            var languageText = phrase.Language.Text;

            //IF THE TARGET LANGUAGE IS DIFFERENT FROM THE PHRASE LANGUAGE, THEN WE CREATE A TRANSLATION Q & A.
            //IF THE TWO LANGUAGES ARE THE SAME, THEN WE CREATE A STUDY NATIVE LANGUAGE PHRASE Q & A.

            bool phraseIsInForeignLanguage = (languageText != nativeLanguageText);

            if (phraseIsInForeignLanguage)
            {
                //DO A TRANSLATION Q & A
                //WE NEED TO FIND A TRANSLATION FOR THIS FOREIGN LANGUAGE PHRASE.
                PhraseEdit translatedPhrase = null;
                #region Thinking (try..)
                var targetId = Guid.NewGuid();
                History.Events.ThinkingAboutTargetEvent.Publish(targetId);
                try
                {
                    #endregion
                    var result = await GetTranslatedPhrase(phrase, nativeLanguageText);

                    translatedPhrase = result.Object;
                    #region (...finally) Thinked
                }
                finally
                {
                    History.Events.ThinkedAboutTargetEvent.Publish(targetId);
                }
                #endregion

                //RIGHT NOW, WE HAVE A MANUAL AND A TIMED QA.
                var timedQA  = new ViewModels.StudyPhraseTimedQuestionAnswerViewModel();
                var manualQA = new ViewModels.StudyPhraseTimedQuestionAnswerViewModel();
                //hack: I'm just setting these both to timed, because that is what I've corrected
                //for the async stuff and I want to make sure that it works.
                //var manualQA = new ViewModels.StudyPhraseManualQuestionAnswerViewModel();

                //PICK A RANDOM VIEW MODEL, EITHER TIMED OR MANUAL
                StudyItemViewModelBase dummy = null;
                var qaViewModel = RandomPicker.Ton.PickOne <StudyItemViewModelBase>(timedQA, manualQA, out dummy);

                //ASSIGN QUESTION/ANSWER RANDOMLY FROM PHRASE AND TRANSLATED PHRASE
                PhraseEdit answer   = null;
                var        question = RandomPicker.Ton.PickOne(phrase, translatedPhrase, out answer);

                //INITIALIZE VIEWMODEL WITH Q & A
                if (qaViewModel is ViewModels.StudyPhraseTimedQuestionAnswerViewModel)
                {
                    ((ViewModels.StudyPhraseTimedQuestionAnswerViewModel)qaViewModel).Initialize(question, answer);//, (e1) =>
                }
                else
                {
                    ((ViewModels.StudyPhraseTimedQuestionAnswerViewModel)qaViewModel).Initialize(question, answer);
                }
                //((ViewModels.StudyPhraseManualQuestionAnswerViewModel)qaViewModel).Initialize(question, answer);

                return(qaViewModel);
                //var resultQAViewModel = new ResultArgs<StudyItemViewModelBase>(qaViewModel);
                //return await StudyHelper.WrapInTask<ResultArgs<StudyItemViewModelBase>>(resultQAViewModel);
            }
            else
            {
                //DO A NATIVE LANGUAGE Q & A
                throw new NotImplementedException();
            }
        }
コード例 #2
0
        protected virtual async Task StudyAsync(MultiLineTextList multiLineTexts)
        {
            _AbortIsFlagged = false;
            StudyItemViewModelBase contentVM  = null;
            IFeedbackViewModelBase feedbackVM = _ViewModel.FeedbackViewModel;

            ///INITIALIZE HISTORY PUBLISHER
            History.HistoryPublisher.Ton.PublishEvent(new StartingStudySessionEvent());


            ///OKAY, SO AT THIS POINT, WE HAVE DONE OUR WORK THROUGH THE EXCHANGE.
            ///THE CALLER HAS A REFERENCE TO OUR _VIEWMODEL PROPERTY.  WE HAVE CONTROL
            ///OF THE STUDY PROCESS THROUGH THIS _VIEWMODEL PROPERTY.  WE USE TWO SUB VIEWMODELS
            ///AT THIS POINT: STUDYITEM VIEWMODEL, AND FEEDBACK VIEWMODEL.  WE WILL IGNORE TIMEOUTS
            ///TO SIMPLIFY THINGS.  WE JUST NEED TO DO A FEW THINGS:
            ///1) INITIALIZE FOR OUR STUDY SESSION
            ///2) GET NEXT/ ASSIGN _VIEWMODEL.STUDYITEMVIEWMODEL AND _VIEWMODEL.FEEDBACKVIEWMODEL.
            ///3) SHOW STUDYITEMVIEWMODEL.
            ///4) WHEN SHOW IS DONE, ENABLE FEEDBACK VIEWMODEL AND GET FEEDBACK


            #region Thinking (try..)
            var targetId = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            try
            {
                #endregion
                ///1) INITIALIZE FOR OUR STUDY SESSION
                await InitializeForNewStudySessionAsync(multiLineTexts);

                #region (...finally) Thinked
            }
            finally
            {
                History.Events.ThinkedAboutTargetEvent.Publish(targetId);
            }
            #endregion

            //STUDY SESSION LOOP
            while (!_CompleteIsFlagged && !_AbortIsFlagged)
            {
                //BEGINNING OF A SINGLE STUDY ITEM
                _IsStudying = true;
                _ViewModel.FeedbackViewModel.IsEnabled = false;

                ///2) GET NEXT/ ASSIGN _VIEWMODEL.STUDYITEMVIEWMODEL AND _VIEWMODEL.FEEDBACKVIEWMODEL.
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                //STUDY ITEM VIEWMODEL CONTENT
                _ViewModel.StudyItemViewModel = await GetNextStudyItemViewModelAsync();

                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);

                contentVM = _ViewModel.StudyItemViewModel;
                if (contentVM == null)
                {
                    //IF WE CAN'T GET A NEW STUDY ITEM VIEWMODEL, THEN THE STUDY SESSION IS COMPLETED.
                    _CompleteIsFlagged = true;
                    break;
                }

                #region Abort Check
                if (_AbortIsFlagged)
                {
                    _IsStudying = false;
                    break;
                }
                #endregion

                ///3) SHOW STUDY ITEM VIEWMODEL.
                ///   DO *NOT* THINK BEFORE AFTER, CAUSE THIS IS WAITING FOR USER INPUT
                await contentVM.ShowAsync();

                #region Abort Check
                if (_AbortIsFlagged)
                {
                    _IsStudying = false;
                    break;
                }
                #endregion

                ///4) WHEN SHOW IS DONE, GET FEEDBACK
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                var feedbackTimeout = int.Parse(StudyResources.DefaultFeedbackTimeoutMilliseconds);
                var feedback        = await feedbackVM.GetFeedbackAsync(feedbackTimeout);

                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);

                //RIGHT NOW I'M NOT DOING ANYTHING WITH THIS FEEDBACK, AS IT IS PUBLISHED WHEN
                //IT IS CREATED BY THE FEEDBACKVM. I'M JUST KEEPING IT HERE TO SHOW THAT I CAN
                //GET THE FEEDBACK HERE. THERE MIGHT BE A BETTER WAY TO DO THIS ANYWAY.
                #region Abort Check
                if (_AbortIsFlagged)
                {
                    _IsStudying = false;
                    break;
                }
                #endregion
            }
        }