コード例 #1
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();
            }
        }