Пример #1
0
        public IMessage Parse(IRawMessage source)
        {
            if (!(source is MockRawMessage))
            {
                throw new ApplicationException("MockSourceText only knows how to deal with MockSourceText");
            }

            // mockRawMessage saves you the trouble of parsing because - hey! its already parsed!
            MockRawMessage mockRaw = (MockRawMessage) source;
            OfferMessage msg = new OfferMessage();
            msg.CreatedBy = mockRaw.CreatedBy;
            msg.Location = mockRaw.Location;
            msg.MoreInfoURL = mockRaw.MoreInfoURL;
            msg.CreatedBy = mockRaw.CreatedBy;
            msg.MessageText = mockRaw.OfferText;
            if (mockRaw.EndBy.HasValue)
            {
                msg.SetEndBy(mockRaw.EndByText, mockRaw.EndBy.Value);
            }
            else
            {
                msg.ClearEndBy();
            }

            foreach (ITag tag in mockRaw.Tags)
            {
                msg.AddTag(tag);
            }

            //if (CONVERT_MOCK_TO_REAL)
            //{
            //    RawMessage realRawMessage = new RawMessage(source.Text, source.Pointer, source.CreatedBy, source.Timestamp);
            //    msg.Source = realRawMessage;
            //}

            //FIXME1 this all has to go - don't keep the source around!
            //msg.Source = mockRaw;
            msg.RawText = mockRaw.Text;
            msg.Timestamp = mockRaw.Timestamp;
            msg.MessagePointer = mockRaw.Pointer;
            return msg;
        }
Пример #2
0
 public void TestMessageExpiry()
 {
     ITag tag = MockData.UsedTags[1];
     List<IMessage> oldResults=new List<IMessage>(_target.GetMessagesForTags(new ITag[] { tag }));
     ITag expiredTag=tag;
     OfferMessage message = new OfferMessage();
     message.CreatedBy = new TwitterUserPointer("jim"); ;
     ////msg.Source = source; //Remove this
     message.Timestamp = DateTime.MinValue;
     message.MessagePointer = new OpenSocialMessagePointer("ooooby");
     message.RawText = "";
     message.MessageText = "";
     message.MoreInfoURL = "";
     message.SetEndBy("",DateTime.Now.AddMonths(-1));
     message.AddTag(tag);
     ((MessageRepository)_target).Save(message);
     List<IMessage>  newResults = new List<IMessage>(_target.GetMessagesForTags(new ITag[] { tag }));
     Assert.AreEqual(newResults,oldResults);
     OfferMessage message2 = new OfferMessage();
     message2.CreatedBy = new TwitterUserPointer("jim");
     ////msg.Source = source; //Remove this
     message2.Timestamp = DateTime.MinValue;
     message2.MessagePointer = new OpenSocialMessagePointer("ooooby2");
     message2.RawText = "";
     message2.MessageText = "";
     message2.MoreInfoURL = "";
     message2.SetEndBy("", DateTime.Now.AddMonths(3));
     message2.AddTag(tag);
     ((MessageRepository)_target).Save(message2);
     newResults = new List<IMessage>(_target.GetMessagesForTags(new ITag[] { tag }));
     Assert.AreNotEqual(newResults, oldResults);
 }
Пример #3
0
        public void TestMessageTypesRoundTrip()
        {
            OfferMessage offerMessage = new OfferMessage();
            offerMessage.AddTag(new Tag(TagType.group, "ooooby"));
            offerMessage.AddTag(new Tag(TagType.loc, "wellington"));
            offerMessage.RawText = "OFFER mulch available now in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch #ooooby";
            offerMessage.MessageText = "mulch available now in l:Cardboard box in town: for #free";

            string serialized = JSON.Serialize(offerMessage);
            OfferMessage deserializedOffer = JSON.Deserialize<OfferMessage>(serialized);
             Assert.AreEqual(offerMessage, deserializedOffer, "Expected to deserialize to the same object");

            WantedMessage wantedMessage = new WantedMessage();
            wantedMessage.AddTag(new Tag(TagType.group, "ooooby"));
            wantedMessage.AddTag(new Tag(TagType.loc, "wellington"));
            wantedMessage.RawText = "WANTED mulch in l:Cardboard box in town: for #free http://bit.ly/message0Info #mulch #ooooby";
            wantedMessage.MessageText = "mulch in l:Cardboard box in town: for #free";

            serialized = JSON.Serialize(wantedMessage);
            WantedMessage deserializedWanted = JSON.Deserialize<WantedMessage>(serialized);
            AssertMessagesIsTheSame(wantedMessage, deserializedWanted);
            //Assert.AreEqual(wantedMessage, deserializedWanted, "Expected to deserialize to the same object");
        }
Пример #4
0
        public IMessage Parse(IRawMessage rawMessage)
        {
            string sourceText = rawMessage.Text;

            IEnumerable<ITag> tags = ParseTags(sourceText, rawMessage);

            BaseMarketMessage msg;
            switch (GetMessageType(sourceText, tags))
            {
                case MessageType.need:
                case MessageType.needed:
                case MessageType.want:
                case MessageType.wanted:
                    msg = new WantedMessage();
                    break;

                case MessageType.offer:
                case MessageType.available:
                default:
                    msg = new OfferMessage();
                    break;
            }

            msg.CreatedBy = rawMessage.CreatedBy;
            msg.Timestamp = rawMessage.Timestamp;
            msg.MessagePointer = rawMessage.Pointer;
            msg.RawText = rawMessage.Text;
            bool containsGroup = false;
            foreach (ITag tag in tags)
            {
                if (tag.Type == TagType.msg_type) continue; //skip tags of this Type
                if(tag.Type==TagType.group) containsGroup = true;
                msg.AddTag(tag);
            }

            if (!containsGroup)
            {
                ITag possibleGroup = CheckForAtSymbolGroup(sourceText);
                if(possibleGroup != null)
                {
                    //remove the @chchneeds tag from the messages
                    sourceText=sourceText.Replace("@" + possibleGroup.Text, "");
                    msg.AddTag(possibleGroup);
                }
            }

            if (msg.HasValidTags())
            {
                // for efficiency don't even both trying to parse the google address
                // unless it at least has some valid tags
                ILocation location = ParseLocation(sourceText);
                if (location != null)
                {
                    msg.Location = location;
                    foreach (ITag s in location.Tags)
                    {
                        msg.AddTag(s);
                    }
                }
            }
            msg.MessageText = sourceText;
            msg.MoreInfoURL = GetMoreInfoUrl(sourceText);

            string untilText;
            DateTime until;
            if (ParseUntil(sourceText, out untilText, out until))
            {
                msg.SetEndBy(untilText, until);
            }
            msg.AddThumbnail(GetImageUrl(sourceText));
            return msg;
        }