Example #1
0
        /// <summary>
        /// If completed event, this shows the StudyViewModel populated with the produced IViewModelBase
        /// produced by the study partner.
        /// </summary>
        /// <param name="message"></param>
        public void Handle(IStatusUpdate <MultiLineTextList, IViewModelBase> message)
        {
            //WE ONLY CARE ABOUT STUDY UPDATES
            if (message.Category != StudyResources.CategoryStudy)
            {
                return;
            }

            //WE DON'T CARE ABOUT MESSAGES WE PUBLISH OURSELVES
            if (message.PublisherId == Id)
            {
                return;
            }

            //WE ONLY CARE ABOUT UPDATES TO OUR CURRENT OPPORTUNITIES
            if (message.Opportunity == null || !CurrentOpportunities.Contains(message.Opportunity))
            {
                return;
            }

            //THIS IS ONE OF THIS OBJECT'S UPDATES

            //IF THIS IS A COMPLETED STATUS UPDATE, THEN PRODUCT SHOULD BE SET.  SO, BUBBLE THIS ASPECT UP.
            if (message.Status == CommonResources.StatusCompleted)
            {
                if (message.JobInfo.Product == null)
                {
                    throw new StudyException("StatusCompleted posted but JobInfo.Product == null...Where is the product?");
                }

                //WE HAVE A PRODUCT OF TYPE IVIEWMODELBASE THAT HAS BEEN CREATED FOR US VIA
                //THE EXCHANGE!
                var productViewModel = message.JobInfo.Product;

                //MOVE THE OPPORTUNITY TO PAST OPPORTUNITIES
                CurrentOpportunities.Remove(message.Opportunity);
                PastOpportunities.Add(message.Opportunity);

                //LET HISTORY KNOW WE ARE DONE THINKING OF THIS OPPORTUNITY
                var targetId = message.Opportunity.Id;
                History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);

                ////GET THE STUDY VIEWMODEL THAT WILL HOUSE OUR CREATED IVIEWMODELBASE
                var studyViewModel = Services.Container.GetExportedValue <ExecuteStudySongsViewModel>();
                studyViewModel.StudyScreen = productViewModel;

                //NAVIGATE TO THE EXECUTE STUDY SONGS PAGE TO BEGIN STUDYING
                var executeStudySongsPage =
                    Services.Container.GetExportedValue <ExecuteStudySongsPage>();
                Navigation.Navigator.Ton.NavigateTo(executeStudySongsPage);
            }
        }
Example #2
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();
            }
        }