Пример #1
0
        public RelatedResults(JsonData resultsJson)
        {
            if (resultsJson == null) return;

            ResultAnnotations = new Annotation(resultsJson.GetValue<JsonData>("annotations"));
            Score = resultsJson.GetValue<double>("score");
            Kind = resultsJson.GetValue<string>("kind");
            JsonData value = resultsJson.GetValue<JsonData>("value");
            ValueAnnotations = new Annotation(value.GetValue<JsonData>("annotations"));
            Retweeted = value.GetValue<bool>("retweeted");
            InReplyToScreenName = value.GetValue<string>("in_reply_to_screen_name");
            var contributors = value.GetValue<JsonData>("contributors");
            Contributors =
                contributors == null ?
                    new List<Contributor>() :
                    (from JsonData contributor in contributors
                     select new Contributor(contributor))
                    .ToList();
            Coordinates = new Coordinate(value.GetValue<JsonData>("coordinates"));
            Place = new Place(value.GetValue<JsonData>("place"));
            User = new User(value.GetValue<JsonData>("user"));
            RetweetCount = value.GetValue<int>("retweet_count");
            IDString = value.GetValue<string>("id_str");
            InReplyToUserID = value.GetValue<ulong>("in_reply_to_user_id");
            Favorited = value.GetValue<bool>("favorited");
            InReplyToStatusIDString = value.GetValue<string>("in_reply_to_status_id_str");
            InReplyToStatusID = value.GetValue<ulong>("in_reply_to_status_id");
            Source = value.GetValue<string>("source");
            CreatedAt = value.GetValue<string>("created_at").GetDate(DateTime.MaxValue);
            InReplyToUserIDString = value.GetValue<string>("in_reply_to_user_id_str");
            Truncated = value.GetValue<bool>("truncated");
            Geo = new Geo(value.GetValue<JsonData>("geo"));
            Text = value.GetValue<string>("text");
        }
Пример #2
0
        public static Annotation CreateAnnotation(XElement annotation)
        {
            if (annotation == null)
            {
                return null;
            }
            //XElement root = annotation.Element("annotation");

            var ann = new Annotation
            {
                Type = annotation.Element("type").Value,
                Attributes =
                    (from attr in annotation.Element("attributes").Elements("attribute")
                     select new
                     {
                         Key = attr.Element("name").Value,
                         Value = attr.Element("value").Value
                     })
                    .ToDictionary(
                        atr => atr.Key,
                        atr => atr.Value)
            };

            return ann;
        }
Пример #3
0
        public Status(JsonData status)
        {
            if (status == null) return;

            Retweeted = status.GetValue<bool>("retweeted");
            Source = status.GetValue<string>("source");
            InReplyToScreenName = status.GetValue<string>("in_reply_to_screen_name");
            PossiblySensitive = status.GetValue<bool>("possibly_sensitive");
            RetweetedStatus = new Status(status.GetValue<JsonData>("retweeted_status"));
            var contributors = status.GetValue<JsonData>("contributors");
            Contributors =
                contributors == null ?
                    new List<Contributor>() :
                    (from JsonData contributor in contributors
                     select new Contributor(contributor))
                    .ToList();
            var coords = status.GetValue<JsonData>("coordinates");
            if (coords != null)
            {
                Coordinates = new Coordinate(coords.GetValue<JsonData>("coordinates"));
            }
            else
            {
                Coordinates = new Coordinate();
            }
            Place = new Place(status.GetValue<JsonData>("place"));
            User = new User(status.GetValue<JsonData>("user"));
            RetweetCount = status.GetValue<int>("retweet_count");
            StatusID = status.GetValue<string>("id_str");
            FavoriteCount = status.GetValue<int?>("favorite_count");
            Favorited = status.GetValue<bool>("favorited");
            InReplyToStatusID = status.GetValue<string>("in_reply_to_status_id_str");
            Source = status.GetValue<string>("source");
            CreatedAt = status.GetValue<string>("created_at").GetDate(DateTime.MaxValue);
            InReplyToUserID = status.GetValue<string>("in_reply_to_user_id_str");
            Truncated = status.GetValue<bool>("truncated");
            Text = status.GetValue<string>("text");
            Annotation = new Annotation(status.GetValue<JsonData>("annotation"));
            Entities = new Entities(status.GetValue<JsonData>("entities"));
            var currentUserRetweet = status.GetValue<JsonData>("current_user_retweet");
            if (currentUserRetweet != null)
            {
                CurrentUserRetweet = currentUserRetweet.GetValue<ulong>("id");
            }
            var scopes = status.GetValue<JsonData>("scopes");
            Scopes =
                scopes == null ? new Dictionary<string, string>() :
                (from key in (scopes as IDictionary<string, JsonData>).Keys as List<string>
                 select new
                 {
                     Key = key,
                     Value = scopes[key].ToString()
                 })
                .ToDictionary(
                    key => key.Key,
                    val => val.Value);
            WithheldCopyright = status.GetValue<bool>("withheld_copyright");
            var withheldCountries = status.GetValue<JsonData>("withheld_in_countries");
            WithheldInCountries =
                withheldCountries == null ? new List<string>() :
                (from JsonData country in status.GetValue<JsonData>("withheld_in_countries")
                 select country.ToString())
                .ToList();
            WithheldScope = status.GetValue<string>("withheld_scope");
            MetaData = new StatusMetaData(status.GetValue<JsonData>("metadata"));
            Lang = status.GetValue<string>("lang");
            string filterLvl = status.GetValue<string>("filter_level");
            try
            {
                FilterLevel =
                    filterLvl == null ? FilterLevel.None :
                    (FilterLevel)Enum.Parse(typeof(FilterLevel), filterLvl, ignoreCase: true);
            }
            catch (ArgumentException)
            {
                FilterLevel = FilterLevel.None;
            }
        }