private async Task InitializeViewModelAsync()
        {
            ClearSongs();
            //RATHER COMPLICATED BECAUSE OF ASYNC.  THE STEPS OF INITIALIZATION ARE:
            //1) GET NATIVE LANGUAGE
            //2) POPULATE SONGS

            //WE MUST FIRST KNOW WHAT THE USER'S NATIVE LANGUAGE IS.
            StudyDataRetriever retriever = null;

            #region Thinking (try..)
            var targetId = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            try
            {
                #endregion
                retriever = await StudyDataRetriever.CreateNewAsync();

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

            StudyData = retriever.StudyData;

            if (!retriever.StudyDataAlreadyExisted)
            {
                #region Thinking
                var targetId2 = Guid.NewGuid();
                History.Events.ThinkingAboutTargetEvent.Publish(targetId);
                #endregion
                AskUserForExtraDataAsync(async(s2, r2) =>
                {
                    #region Thinked
                    History.Events.ThinkedAboutTargetEvent.Publish(targetId2);
                    #endregion
                    if (r2.Error != null)
                    {
                        throw r2.Error;
                    }

                    StudyData = r2.Object;
                    await StartPopulateAllSongsAsync();
                });
            }
            else
            {
                await StartPopulateAllSongsAsync();
            }
        }
Exemplo n.º 2
0
        private async Task InitializeModelAsync()
        {
            #region Thinking
            var thinkId = System.Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(thinkId);
            #endregion
            var studyDataRetriever = await StudyDataRetriever.CreateNewAsync();

            #region Thinked
            History.Events.ThinkedAboutTargetEvent.Publish(thinkId);
            #endregion

            Model = studyDataRetriever.StudyData;
        }
Exemplo n.º 3
0
        public async Task GET_VIA_RETRIEVER()
        {
            StudyDataEdit      studyDataEdit = null;
            StudyDataRetriever retriever     = null;

            var isAsyncComplete = false;
            var hasError        = false;

            EnqueueConditional(() => isAsyncComplete);
            await Setup();

            try
            {
                retriever = await StudyDataRetriever.CreateNewAsync();

                studyDataEdit = retriever.StudyData;
            }
            catch
            {
                hasError = true;
            }
            finally
            {
                EnqueueCallback(
                    () => Assert.IsFalse(hasError),
                    () => Assert.IsNotNull(retriever),
                    () => Assert.IsNotNull(studyDataEdit),

                    //KEEP THIS LAST IN THE CALLBACKS
                    () => Teardown()
                    );

                EnqueueTestComplete();
                isAsyncComplete = true;
            }
        }
Exemplo n.º 4
0
        private async Task InitializeViewModelAsync()
        {
            //1) GET NATIVE LANGUAGE
            //2) POPULATE SONGS

            ClearSongs();

            //1) GET NATIVE LANGUAGE
            StudyDataRetriever retriever = null;

            #region Thinking (try..)
            var targetId = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            try
            {
                #endregion
                retriever = await StudyDataRetriever.CreateNewAsync();

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

            StudyData = retriever.StudyData;

            if (!retriever.StudyDataAlreadyExisted)
            {
                #region Thinking
                var targetId2 = Guid.NewGuid();
                History.Events.ThinkingAboutTargetEvent.Publish(targetId2);
                #endregion
                AskUserForExtraDataAsync(async(s2, r2) =>
                {
                    #region Thinked
                    History.Events.ThinkedAboutTargetEvent.Publish(targetId2);
                    #endregion
                    if (r2.Error != null)
                    {
                        throw r2.Error;
                    }

                    StudyData = r2.Object;
                    //2) POPULATE SONGS
                    History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                    {
                        await PopulateAllSongsAsync();
                    }
                    History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                });
            }
            else
            {
                //2) POPULATE SONGS
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                {
                    await PopulateAllSongsAsync();
                }
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
            }
        }
Exemplo n.º 5
0
        public async Task NEW_EDIT_BEGINSAVE_GET()
        {
            StudyDataEdit newStudyDataEdit    = null;
            StudyDataEdit savedStudyDataEdit  = null;
            StudyDataEdit gottenStudyDataEdit = null;

            var studyDataAlreadyExisted  = false;
            var editedStudyDataText      = "Spanish";
            StudyDataRetriever retriever = null;

            var isAsyncComplete = false;
            var hasError        = false;

            EnqueueConditional(() => isAsyncComplete);
            await Setup();

            try
            {
                //NEW
                retriever = await StudyDataRetriever.CreateNewAsync();

                newStudyDataEdit = retriever.StudyData;

                //EDIT
                newStudyDataEdit.NativeLanguageText = editedStudyDataText;
                //newStudyDataEdit.Username = SeedData.Ton.TestValidUsername;

                //SAVE
                savedStudyDataEdit = await newStudyDataEdit.SaveAsync();

                //GET (CONFIRM SAVE)
                retriever = await StudyDataRetriever.CreateNewAsync();

                gottenStudyDataEdit = retriever.StudyData;

                //STUDY DATA SHOULD HAVE ALREADY EXISTED AS WE JUST SAVED IT.
                studyDataAlreadyExisted = retriever.StudyDataAlreadyExisted;

                EnqueueTestComplete();
            }
            catch
            {
                hasError = true;
            }
            finally
            {
                EnqueueCallback(
                    () => Assert.IsFalse(hasError),
                    () => Assert.IsNotNull(newStudyDataEdit),
                    () => Assert.IsNotNull(savedStudyDataEdit),
                    () => Assert.IsNotNull(gottenStudyDataEdit),
                    () => Assert.AreEqual(savedStudyDataEdit.Id, gottenStudyDataEdit.Id),
                    () => Assert.AreEqual(editedStudyDataText, gottenStudyDataEdit.NativeLanguageText),
                    () => Assert.IsTrue(studyDataAlreadyExisted),
                    () => Assert.AreEqual(savedStudyDataEdit.NativeLanguageText,
                                          gottenStudyDataEdit.NativeLanguageText),
                    //KEEP THIS LAST IN THE CALLBACKS
                    () => Teardown()
                    );

                EnqueueTestComplete();
                isAsyncComplete = true;
            }
        }
Exemplo n.º 6
0
        public override async Task <ResultArgs <StudyItemViewModelArgs> > GetNextStudyItemViewModelAsync()
        {
            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            //USING THE TARGET PHRASE,
            //IF IT IS IN THE NATIVE LANGUAGE, THEN IT JUST POPS UP A NATIVE LANGUAGE STUDY QUESTION.
            //IF IT IS IN A DIFFERENT LANGUAGE, THEN IT POPS UP EITHER DIRECTION Q & A, 50% CHANCE.
            #region Thinking
            var targetId = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            #endregion
            var retriever = await StudyDataRetriever.CreateNewAsync();

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

            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            var nativeLanguageText = retriever.StudyData.NativeLanguageText;
            if (string.IsNullOrEmpty(nativeLanguageText))
            {
                throw new StudyException("No native language set.");
            }

            if (_Target == null)
            {
                throw new StudyException("No PhraseEdit to study, _StudyJobInfo.Target == null.");
            }

            var phraseEdit = _Target;
            var phraseText = phraseEdit.Text;
            if (string.IsNullOrEmpty(phraseText))
            {
                throw new StudyException("Attempted to study empty phrase text, (PhraseEdit)_Target.Text is null or empty.");
            }

            var languageText = phraseEdit.Language.Text;

            //WE HAVE A PHRASEEDIT WITH A LANGUAGE AND WE HAVE OUR NATIVE LANGUAGE,
            //SO WE HAVE ENOUGH TO PROCURE A VIEW MODEL NOW.
            var result = await StudyItemViewModelFactory.Ton.ProcureAsync(phraseEdit, nativeLanguageText);

            if (_AbortIsFlagged)
            {
                return(await StudyHelper.GetAbortedAsync());
            }

            var studyItemViewModel = result.Object;
            studyItemViewModel.Shown += new EventHandler(studyItemViewModel_Shown);
            var args       = new StudyItemViewModelArgs(studyItemViewModel);
            var resultArgs = new ResultArgs <StudyItemViewModelArgs>(args);
            _Phrase = phraseEdit;//hack
            return(await StudyHelper.WrapInTask <ResultArgs <StudyItemViewModelArgs> >(resultArgs));
        }