コード例 #1
0
        void ParseJson(string json)
        {
            JsonData jsonObj = JsonMapper.ToObject(json);
            if (jsonObj == null || jsonObj.InstObject == null)
            {
                EntityType = StreamEntityType.Unknown;
                return;
            }
            var inst = jsonObj.InstObject;

            try
            {
                if (inst.ContainsKey("control"))
                {
                    EntityType = StreamEntityType.Control;
                    Entity = new Control(jsonObj);
                }
                else if (inst.ContainsKey("delete"))
                {
                    EntityType = StreamEntityType.Delete;
                    Entity = new Delete(jsonObj);
                }
                else if (inst.ContainsKey("direct_message"))
                {
                    EntityType = StreamEntityType.DirectMessage;
                    var dmObj = jsonObj.GetValue<JsonData>("direct_message");
                    Entity = new DirectMessage(dmObj);
                }
                else if (inst.ContainsKey("disconnect"))
                {
                    EntityType = StreamEntityType.Disconnect;
                    Entity = new Disconnect(jsonObj);
                }
                else if (inst.ContainsKey("event"))
                {
                    EntityType = StreamEntityType.Event;
                    Entity = new Event(jsonObj);
                }
                else if (inst.ContainsKey("for_user"))
                {
                    EntityType = StreamEntityType.ForUser;
                    Entity = new ForUser(jsonObj);
                }
                else if (inst.ContainsKey("friends") && inst.Count == 1)
                {
                    EntityType = StreamEntityType.FriendsList;
                    Entity = new FriendsList(jsonObj);
                }
                else if (inst.ContainsKey("geo_scrub"))
                {
                    EntityType = StreamEntityType.GeoScrub;
                    Entity = new GeoScrub(jsonObj);
                }
                else if (inst.ContainsKey("limit"))
                {
                    EntityType = StreamEntityType.Limit;
                    Entity = new Limit(jsonObj);
                }
                else if (inst.ContainsKey("warning") && inst.ContainsKey("percent_full"))
                {
                    EntityType = StreamEntityType.Stall;
                    Entity = new Stall(jsonObj);
                }
                else if (inst.ContainsKey("status_withheld"))
                {
                    EntityType = StreamEntityType.StatusWithheld;
                    Entity = new StatusWithheld(jsonObj);
                }
                else if (inst.ContainsKey("warning") && inst.ContainsKey("user_id"))
                {
                    EntityType = StreamEntityType.TooManyFollows;
                    Entity = new TooManyFollows(jsonObj);
                }
                else if (inst.ContainsKey("retweeted"))
                {
                    EntityType = StreamEntityType.Status;
                    Entity = new Status(jsonObj);
                }
                else if (inst.ContainsKey("user_withheld"))
                {
                    EntityType = StreamEntityType.UserWithheld;
                    Entity = new UserWithheld(jsonObj);
                }
                else
                {
                    EntityType = StreamEntityType.Unknown;
                }
            }
            catch (Exception ex)
            {
                string parseError = string.Format(
                    "Error parsing twitter message. Please create a new issue on the LINQ to Twitter site at https://linqtotwitter.codeplex.com/ " +
                    "with this info. \n\nMessage Type: {0}, Message Text:\n {1} \nException Details: {2} \n", EntityType, json, ex.ToString());
                
                EntityType = StreamEntityType.ParseError;
                Entity = parseError;

                if (TwitterExecute.Log != null)
                    TwitterExecute.Log.WriteLine(parseError);
            }
        }
コード例 #2
0
        void ParseJson(string json)
        {
            JsonData jsonObj = JsonMapper.ToObject(json);

            if (jsonObj == null || jsonObj.InstObject == null)
            {
                EntityType = StreamEntityType.Unknown;
                return;
            }
            var inst = jsonObj.InstObject;

            try
            {
                if (inst.ContainsKey("control"))
                {
                    EntityType = StreamEntityType.Control;
                    Entity     = new Control(jsonObj);
                }
                else if (inst.ContainsKey("delete"))
                {
                    EntityType = StreamEntityType.Delete;
                    Entity     = new Delete(jsonObj);
                }
                else if (inst.ContainsKey("direct_message"))
                {
                    EntityType = StreamEntityType.DirectMessage;
                    var dmObj = jsonObj.GetValue <JsonData>("direct_message");
                    Entity = new DirectMessage(dmObj);
                }
                else if (inst.ContainsKey("disconnect"))
                {
                    EntityType = StreamEntityType.Disconnect;
                    Entity     = new Disconnect(jsonObj);
                }
                else if (inst.ContainsKey("event"))
                {
                    EntityType = StreamEntityType.Event;
                    Entity     = new Event(jsonObj);
                }
                else if (inst.ContainsKey("for_user"))
                {
                    EntityType = StreamEntityType.ForUser;
                    Entity     = new ForUser(jsonObj);
                }
                else if (inst.ContainsKey("friends") && inst.Count == 1)
                {
                    EntityType = StreamEntityType.FriendsList;
                    Entity     = new FriendsList(jsonObj);
                }
                else if (inst.ContainsKey("geo_scrub"))
                {
                    EntityType = StreamEntityType.GeoScrub;
                    Entity     = new GeoScrub(jsonObj);
                }
                else if (inst.ContainsKey("limit"))
                {
                    EntityType = StreamEntityType.Limit;
                    Entity     = new Limit(jsonObj);
                }
                else if (inst.ContainsKey("warning") && inst.ContainsKey("percent_full"))
                {
                    EntityType = StreamEntityType.Stall;
                    Entity     = new Stall(jsonObj);
                }
                else if (inst.ContainsKey("status_withheld"))
                {
                    EntityType = StreamEntityType.StatusWithheld;
                    Entity     = new StatusWithheld(jsonObj);
                }
                else if (inst.ContainsKey("warning") && inst.ContainsKey("user_id"))
                {
                    EntityType = StreamEntityType.TooManyFollows;
                    Entity     = new TooManyFollows(jsonObj);
                }
                else if (inst.ContainsKey("retweeted"))
                {
                    EntityType = StreamEntityType.Status;
                    Entity     = new Status(jsonObj);
                }
                else if (inst.ContainsKey("user_withheld"))
                {
                    EntityType = StreamEntityType.UserWithheld;
                    Entity     = new UserWithheld(jsonObj);
                }
                else
                {
                    EntityType = StreamEntityType.Unknown;
                }
            }
            catch (Exception ex)
            {
                string parseError = string.Format(
                    "Error parsing twitter message. Please create a new issue on the LINQ to Twitter site at https://linqtotwitter.codeplex.com/ " +
                    "with this info. \n\nMessage Type: {0}, Message Text:\n {1} \nException Details: {2} \n", EntityType, json, ex.ToString());

                EntityType = StreamEntityType.ParseError;
                Entity     = parseError;

                if (TwitterExecute.Log != null)
                {
                    TwitterExecute.Log.WriteLine(parseError);
                }
            }
        }