Example #1
0
        /// <summary>
        /// Converts the JSON to a <see cref="StreamingMessage"/> object.
        /// </summary>
        /// <param name="x">The JSON value.</param>
        /// <returns>The <see cref="StreamingMessage"/> object.</returns>
        public static StreamingMessage Parse(string x)
        {
            try
            {
                var j = JObject.Parse(x);
                StreamingMessage m;

                if (j["text"] != null)
                {
                    m = StatusMessage.Parse(j);
                }
                else if (j["direct_message"] != null)
                {
                    m = CoreBase.Convert <DirectMessageMessage>(x);
                }
                else if (j["friends"] != null)
                {
                    m = CoreBase.Convert <FriendsMessage>(x);
                }
                else if (j["event"] != null)
                {
                    m = EventMessage.Parse(j);
                }
                else if (j["for_user"] != null)
                {
                    m = EnvelopesMessage.Parse(j);
                }
                else if (j["control"] != null)
                {
                    m = CoreBase.Convert <ControlMessage>(x);
                }
                else
                {
                    m = ExtractRoot(j);
                }

                m.Json = x;
                return(m);
            }
            catch (ParsingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ParsingException("on streaming, cannot parse the json", x, e);
            }
        }
Example #2
0
        /// <summary>
        /// Parse the specified json
        /// </summary>
        internal static StreamingMessage Parse(TokensBase tokens, string x)
        {
            var j = JObject.Parse(x);

            try
            {
                if (j["text"] != null)
                {
                    return(StatusMessage.Parse(tokens, j));
                }
                else if (j["friends"] != null)
                {
                    return(CoreBase.Convert <FriendsMessage>(tokens, x));
                }
                else if (j["event"] != null)
                {
                    return(EventMessage.Parse(tokens, j));
                }
                else if (j["for_user"] != null)
                {
                    return(EnvelopesMessage.Parse(tokens, j));
                }
                else if (j["control"] != null)
                {
                    return(CoreBase.Convert <ControlMessage>(tokens, x));
                }
                else
                {
                    return(ExtractRoot(tokens, j));
                }
            }
            catch (ParsingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ParsingException("on streaming, cannot parse the json", j.ToString(Formatting.Indented), e);
            }
        }