Пример #1
0
 public void TestOfferMessageRoundTrip()
 {
     MockRawMessage source = new MockRawMessage("", new TwitterMessagePointer(0), new TwitterUserPointer(""), DateTime.Now.ToString());
     OfferMessage orig = new OfferMessage();
     orig.AddThumbnail("thumb");
        // orig.Source = m;
        orig.RawText = source.Text;
        orig.Timestamp = source.Timestamp;
     orig.MessagePointer = source.Pointer;
     string json = JSON.Serialize(orig);
     Console.Out.WriteLine(json);
     OfferMessage deserialized = JSON.Deserialize<OfferMessage>(json);
     Assert.AreEqual(orig, deserialized);
 }
Пример #2
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;
        }