예제 #1
0
        /// <summary>
        /// Initializes ViewModel after navigated.
        /// </summary>
        /// <param name="message"></param>
        public void Handle(Navigation.EventMessages.NavigatedEventMessage message)
        {
            //WE ARE LISTENING FOR A MESSAGE THAT SAYS WE WERE SUCCESSFULLY NAVIGATED TO.
            //SO WE ONLY CARE ABOUT IT IF WE ARE THE TARGETPAGE CONTENT VIEWMODEL
            if (message.NavigationInfo.TargetPage.ContentViewModel != this)
            {
                return;
            }

            //WE HAVE BEEN SUCCESSFULLY NAVIGATED TO.

            var targetId = Guid.NewGuid();

            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            DisableNavigationRequestedEventMessage.Publish();
            try
            {
                var suppress = InitializeViewModelAsync();
            }
            finally
            {
                EnableNavigationRequestedEventMessage.Publish();
                History.Events.ThinkedAboutTargetEvent.Publish(targetId);
            }
        }
        protected override async Task InitializeForNewStudySessionAsync(
            MultiLineTextList multiLineTexts)
        {
            #region DisableNav/Thinking
            DisableNavigationRequestedEventMessage.Publish();
            var targetId = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            #endregion
            try
            {
                #region ThinkPing
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                #endregion
                var retrieverStudyData = await Business.StudyDataRetriever.CreateNewAsync();

                _CurrentUserNativeLanguageText = retrieverStudyData.StudyData.NativeLanguageText;
                #region ThinkPing
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                #endregion
                var retrieverRecentBeliefs = await MostRecentPhraseDataBeliefsRetriever.CreateNewAsync();

                _MostRecentPhraseBeliefsCache = retrieverRecentBeliefs.MostRecentPhraseBeliefs;
                #region ThinkPing
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                #endregion
            }
            finally
            {
                #region EnableNav/Thinked
                EnableNavigationRequestedEventMessage.Publish();
                History.Events.ThinkedAboutTargetEvent.Publish(targetId);
                #endregion
            }
        }
        protected override async Task <StudyItemViewModelBase> GetNextStudyItemViewModelAsync()
        {
            StudyItemViewModelBase qaViewModel   = null;
            PhraseEdit             phraseToStudy = null;

            DisableNavigationRequestedEventMessage.Publish();
            try
            {
                ///THINGS THAT MUST HAPPEN:
                ///CHOOSE A PHRASE/LINE TO STUDY FROM THE TARGET
                ///GET A VIEWMODEL FOR THAT PHRASE/LINE

                #region Thinking (try..)
                var targetId = Guid.NewGuid();
                History.Events.ThinkingAboutTargetEvent.Publish(targetId);
                try
                {
                    #endregion
                    ///SO, THE SIMPLEST FORM OF CHOOSING A PHRASE/LINE TO STUDY IS JUST GETTING
                    ///CHOOSING FROM THE MLT LIST AT RANDOM.
                    //PhraseEdit phraseToStudy = GetRandomPhrase(GetCurrentTarget());
                    phraseToStudy = await GetRandomUnknownPhrase(GetCurrentTarget());

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

                if (phraseToStudy == null)
                {
                    phraseToStudy = GetRandomPhrase(GetCurrentTarget());
                }

                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                {
                    qaViewModel = await StudyItemViewModelFactory.Ton.ProcureAsync(phraseToStudy,
                                                                                   _CurrentUserNativeLanguageText);
                }
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);


                //PUBLISH A REVIEWING PHRASE EVENT MESSAGE.
                History.Events.ReviewingPhraseEvent reviewingEvent =
                    new ReviewingPhraseEvent(phraseToStudy, qaViewModel.ReviewMethodId);
                History.HistoryPublisher.Ton.PublishEvent(reviewingEvent);
            }
            finally
            {
                EnableNavigationRequestedEventMessage.Publish();
            }

            return(qaViewModel);
        }
예제 #4
0
        private async Task InitializeModelAsync()
        {
            var thinkId = System.Guid.NewGuid();

            History.Events.ThinkingAboutTargetEvent.Publish(thinkId);
            DisableNavigationRequestedEventMessage.Publish();
            try
            {
                var newMultiLineTextEdit = await MultiLineTextEdit.NewMultiLineTextEditAsync();

                var songViewModel = Services.Container.GetExportedValue <AddSongMultiLineTextEditViewModel>();
                songViewModel.Model = newMultiLineTextEdit;
                Song = songViewModel;
            }
            finally
            {
                History.Events.ThinkedAboutTargetEvent.Publish(thinkId);
                EnableNavigationRequestedEventMessage.Publish();
            }
        }
예제 #5
0
        /// <summary>
        /// This method is called when the user presses the Go button.
        /// </summary>
        public async Task Go()
        {
            if (!CanGo)
            {
                return;
            }

            DisableNavigationRequestedEventMessage.Publish();
            GoInProgress = true;
            try
            {
                var ids = new MobileList <Guid>();
                foreach (var songViewModel in Items)
                {
                    if (songViewModel.IsChecked)
                    {
                        Guid id      = default(Guid);
                        var  results = from entry in _MultiLineTextIdsAndTitles
                                       where entry.Value == songViewModel.SongTitle
                                       select entry;
                        id = results.First().Key;
                        ids.Add(id);
                    }
                }
                MultiLineTextList songs = null;
                #region Try ...(thinking)
                //var targetId = new Guid(@"5D4355FE-C46E-4AA1-9E4A-45288C341C44");
                var targetId = Guid.NewGuid();
                History.Events.ThinkingAboutTargetEvent.Publish(targetId);
                try
                {
                    #endregion
                    songs = await MultiLineTextList.NewMultiLineTextListAsync(ids);

                    #region ...Finally (thinked)
                }

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

                var nativeLanguage = await LanguageEdit.GetLanguageEditAsync(GetNativeLanguageText());

                var noExpirationDate = StudyJobInfo <MultiLineTextList, IViewModelBase> .NoExpirationDate;
                var precision        = double.Parse(StudyResources.DefaultExpectedPrecision);

                //CREATE JOB INFO
                var studyJobInfo = new StudyJobInfo <MultiLineTextList, IViewModelBase>(songs,
                                                                                        nativeLanguage,
                                                                                        noExpirationDate,
                                                                                        precision);
                //CREATE OPPORTUNITY
                var opportunity = new Opportunity <MultiLineTextList, IViewModelBase>(Id,
                                                                                      this,
                                                                                      studyJobInfo,
                                                                                      StudyResources.CategoryStudy);

                //ADD OPPORTUNITY TO OUR FUTURE OPPORTUNITIES
                FutureOpportunities.Add(opportunity);

                //LET THE HISTORY SHOW THAT YOU ARE THINKING ABOUT THIS OPPORTUNITY
                var opportunityId = opportunity.Id;
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);

                //PUBLISH THE OPPORTUNITY
                Exchange.Ton.Publish(opportunity);

                //NOW, WE WAIT UNTIL WE HEAR A HANDLE(OFFER) MESSAGE.
                //TODO: TIMEOUT FOR OPPORTUNITY, BOTH EXPIRATION DATE AND WAITING FOR OFFER TIMEOUT
            }
            finally
            {
                EnableNavigationRequestedEventMessage.Publish();
            }
        }
예제 #6
0
        public void Handle(IOffer <MultiLineTextList, IViewModelBase> message)
        {
            History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
            DisableNavigationRequestedEventMessage.Publish();
            try
            {
                //WE ONLY CARE ABOUT OFFERS IN THE STUDY CATEGORY
                if (message.Category != StudyResources.CategoryStudy)
                {
                    return;
                }
                //WE DON'T CARE ABOUT MESSAGES WE PUBLISH OURSELVES
                if (message.PublisherId == Id)
                {
                    return;
                }

                //WE ONLY CARE ABOUT OFFERS PERTAINING TO OUR FUTURE AND PAST OPPORTUNITIES
                var resultsFuture = (from opportunity in FutureOpportunities
                                     where opportunity.Id == message.Opportunity.Id
                                     select opportunity);
                if (resultsFuture.Count() != 1)
                {
                    //NO OPEN FUTURE OPPORTUNITIES, NOW CHECK OUR PAST
                    var resultsOther = (from opportunity in PastOpportunities
                                        where opportunity.Id == message.Opportunity.Id
                                        select opportunity).Concat
                                           (from opportunity in CurrentOpportunities
                                           where opportunity.Id == message.Opportunity.Id
                                           select opportunity);

                    if (resultsOther.Count() >= 1)
                    {
                        //WE HAVE THIS IN THE PAST OR CURRENT, SO THIS OPPORTUNITY HAS ALREADY BEEN/IS ALREADY BEING
                        //HANDLED, SO WE WILL DENY THIS OFFER
                        var denyResponse      = OfferResources.OfferResponseDeny;
                        var denyOfferResponse = new OfferResponse <MultiLineTextList, IViewModelBase>(message, Id, this, denyResponse,
                                                                                                      StudyResources.CategoryStudy, null);

                        //PUBLISH DENY OFFER RESPONSE
                        Exchange.Ton.Publish(denyOfferResponse);
                        return;
                    }
                    else
                    {
                        //NOT IN FUTURE OR PAST, SO DOESN'T PERTAIN TO US
                        return;
                    }
                }

                //THIS PERTAINS TO A FUTURE OPPORTUNITY, SO WE WILL EXAMINE THIS FURTHER
                //FOR NOW, THIS MEANS THAT WHATEVER THE OFFER IS, WE WILL ACCEPT IT.
                //IN THE POSSIBLY NEAR FUTURE, WE WILL HAVE TO CONSIDER IF SOMEONE ELSE
                //HAS SOMETHING MORE IMPORTANT TO DO
                var pertinentOpportunity = resultsFuture.First();

                var acceptResponse      = OfferResources.OfferResponseAccept;
                var acceptOfferResponse = new OfferResponse <MultiLineTextList, IViewModelBase>(message, Id, this, acceptResponse,
                                                                                                StudyResources.CategoryStudy, null);

                //BEFORE PUBLISHING, MOVE OPPORTUNITY TO CURRENT OPPORTUNITIES.
                FutureOpportunities.Remove(pertinentOpportunity);
                CurrentOpportunities.Add(pertinentOpportunity);

                //PUBLISH ACCEPT OFFER RESPONSE
                Exchange.Ton.Publish(acceptOfferResponse);
                GoInProgress = false;
            }
            finally
            {
                EnableNavigationRequestedEventMessage.Publish();
            }
        }
        public async Task SaveAnswer()
        {
            AnswerIsReadOnly          = true;
            SaveAnswerButtonIsEnabled = false;

            #region Thinking (try..)
            var targetId = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            DisableNavigationRequestedEventMessage.Publish();
            try
            {
                #endregion
                #region Get the DB version of answer, then modify it and save

                //STORE OUR MODIFIED TEXT
                _ModifiedAnswerText = Answer.Text;

                //PREPARE ANSWER TO BE SEARCHED FOR IN DB
                Answer.Text = _InitialAnswerText;
                PhrasesByTextAndLanguageRetriever retriever = null;
                #region SEARCH IN DB FOR ANSWER (WITH INITIAL TEXT)
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                {
                    retriever = await Business.PhrasesByTextAndLanguageRetriever.CreateNewAsync(Answer);
                }
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);

                var dbAnswer = retriever.RetrievedSinglePhrase;
                if (dbAnswer == null)
                {
                    //ANSWER NOT IN DB, BUT ANSWER IS A CHILD
                    if (Answer.IsChild)
                    {
                        //CANNOT SAVE THE ANSWER DIRECTLY BECAUSE IT IS A CHILD
                        #region CREATE NEW PHRASE EDIT, LOAD FROM ANSWER DTO, SAVE ANSWER
                        var newAnswerObj = await PhraseEdit.NewPhraseEditAsync();

                        Answer.Text = _ModifiedAnswerText;
                        var dto = Answer.CreateDto();
                        dto.Id = Guid.NewGuid();

                        newAnswerObj.LoadFromDtoBypassPropertyChecks(dto);
                        Answer = newAnswerObj;

                        #region Save Answer
                        Answer = await Answer.SaveAsync();

                        _InitialAnswerText        = Answer.Text;
                        _ModifiedAnswerText       = "";
                        SaveAnswerButtonIsEnabled = true;
                        AnswerIsReadOnly          = true;
                        UpdateEditAnswerButtonVisibilities();
                        #endregion
                        #endregion
                    }
                    //ANSWER NOT IN DB, BUT ANSWER IS NOT A CHILD
                    else
                    {
                        #region SAVE THE ANSWER DIRECTLY, B/C IT IS NOT A CHILD
                        Answer = await Answer.SaveAsync();

                        _InitialAnswerText        = Answer.Text;
                        _ModifiedAnswerText       = "";
                        SaveAnswerButtonIsEnabled = true;
                        AnswerIsReadOnly          = true;
                        UpdateEditAnswerButtonVisibilities();
                        #endregion
                    }
                }
                //ANSWER WAS FOUND IN DB
                else
                {
                    #region REASSIGN THE ANSWER WITH THE DBANSWER, SAVE WITH THE MODIFIED TEXT
                    Answer      = dbAnswer;
                    Answer.Text = _ModifiedAnswerText;
                    Answer      = await Answer.SaveAsync();

                    _InitialAnswerText        = Answer.Text;
                    _ModifiedAnswerText       = "";
                    SaveAnswerButtonIsEnabled = true;
                    AnswerIsReadOnly          = true;
                    UpdateEditAnswerButtonVisibilities();
                    #endregion
                }

                #endregion

                #endregion
                #region (...finally) Thinked
            }
            finally
            {
                EnableNavigationRequestedEventMessage.Publish();
                History.Events.ThinkedAboutTargetEvent.Publish(targetId);
            }
            #endregion
        }
        public async Task SaveQuestion()
        {
            QuestionIsReadOnly          = true;
            SaveQuestionButtonIsEnabled = false;
            #region Thinking (try..)
            var targetId = Guid.NewGuid();
            History.Events.ThinkingAboutTargetEvent.Publish(targetId);
            DisableNavigationRequestedEventMessage.Publish();
            try
            {
                #endregion

                #region Get the DB version of question, then modify it and save

                //STORE OUR MODIFIED TEXT
                _ModifiedQuestionText = Question.Text;

                //PREPARE QUESTION TO BE SEARCHED FOR IN DB
                Question.Text = _InitialQuestionText;

                #region SEARCH IN DB FOR QUESTION (WITH INITIAL TEXT)
                PhrasesByTextAndLanguageRetriever retriever = null;
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
                {
                    retriever = await Business.PhrasesByTextAndLanguageRetriever.CreateNewAsync(Question);
                }
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);

                var dbQuestion = retriever.RetrievedSinglePhrase;
                if (dbQuestion == null)
                {
                    //QUESTION NOT IN DB, BUT QUESTION IS A CHILD
                    if (Question.IsChild)
                    {
                        //CANNOT SAVE THE QUESTION DIRECTLY BECAUSE IT IS A CHILD
                        #region CREATE NEW PHRASE EDIT, LOAD FROM QUESTION DTO, SAVE QUESTION
                        var newQuestionObj = await PhraseEdit.NewPhraseEditAsync();

                        Question.Text = _ModifiedQuestionText;
                        var dto = Question.CreateDto();
                        dto.Id = Guid.NewGuid();

                        newQuestionObj.LoadFromDtoBypassPropertyChecks(dto);
                        Question = newQuestionObj;

                        #region Save Question
                        Question = await Question.SaveAsync();

                        _InitialQuestionText        = Question.Text;
                        _ModifiedQuestionText       = "";
                        SaveQuestionButtonIsEnabled = true;
                        QuestionIsReadOnly          = true;
                        UpdateEditQuestionButtonVisibilities();
                        #endregion
                        #endregion
                    }
                    //QUESTION NOT IN DB, BUT QUESTION IS NOT A CHILD
                    else
                    {
                        #region SAVE THE QUESTION DIRECTLY, B/C IT IS NOT A CHILD
                        Question = await Question.SaveAsync();

                        _InitialQuestionText        = Question.Text;
                        _ModifiedQuestionText       = "";
                        SaveQuestionButtonIsEnabled = true;
                        QuestionIsReadOnly          = true;
                        UpdateEditQuestionButtonVisibilities();
                        #endregion
                    }
                }
                //QUESTION WAS FOUND IN DB
                else
                {
                    #region REASSIGN THE QUESTION WITH THE DBQUESTION, SAVE WITH THE MODIFIED TEXT
                    Question      = dbQuestion;
                    Question.Text = _ModifiedQuestionText;
                    Question      = await Question.SaveAsync();

                    _InitialQuestionText        = Question.Text;
                    _ModifiedQuestionText       = "";
                    SaveQuestionButtonIsEnabled = true;
                    QuestionIsReadOnly          = true;
                    UpdateEditQuestionButtonVisibilities();
                    #endregion
                }

                #endregion

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