Пример #1
0
        public static LeaderboardItem ParseJson(JToken leaderboardItem)
        {
            var li = new LeaderboardItem();

            var rank = Json.TryGetJsonProperty(leaderboardItem, "rank");

            li.Rank = "#" + rank;

            var scores = leaderboardItem["scores"];

            if (scores != null)
            {
                li.Scores = LeaderboardItemScores.ParseJson(scores);
            }

            var userJson = leaderboardItem["user"];

            if (userJson != null)
            {
                li.User = CompactUser.ParseJson(userJson);

                if (li.User != null)
                {
                    if (li.User.Relationship == FriendStatus.Self)
                    {
                        li.IsSelf = true;
                    }
                }
            }

            return(li);
        }
        public static LeaderboardItem ParseJson(JToken leaderboardItem)
        {
            var li = new LeaderboardItem();

            var rank = Json.TryGetJsonProperty(leaderboardItem, "rank");
            li.Rank = "#" + rank;

            var scores = leaderboardItem["scores"];
            if (scores != null)
            {
                li.Scores = LeaderboardItemScores.ParseJson(scores);
            }

            var userJson = leaderboardItem["user"];
            if (userJson != null)
            {
                li.User = CompactUser.ParseJson(userJson);

                if (li.User != null)
                {
                    if (li.User.Relationship == FriendStatus.Self)
                    {
                        li.IsSelf = true;
                    }
                }
            }

            return li;
        }
        // TODO: Scores and total from this entry... see how official app does it.


        public LeaderboardNotification(JToken item)
        {
            Message = Checkin.SanitizeString(Json.TryGetJsonProperty(item, "message"));

            var leaders = new List <LeaderboardItem>();
            var lj      = item["leaderboard"];

            if (lj != null)
            {
                foreach (var victor in lj)
                {
                    var wolverine = LeaderboardItem.ParseJson(victor);
                    if (wolverine != null)
                    {
                        leaders.Add(wolverine);
                    }
                }
            }

            Leaderboard = leaders;
        }
Пример #4
0
            /// <summary>
            /// Parses the JSON response to retrieve the leaderboard, parsing
            /// of individual items are handled by their compact object
            /// parse routines.
            /// </summary>
            protected override object DeserializeCore(JObject json, Type objectType, LeaderboardLoadContext context)
            {
                try
                {
                    var nv = new Leaderboard(context);

                    var results = json["leaderboard"];
                    var b       = new List <LeaderboardItem>();
                    if (results != null)
                    {
                        var items = results["items"];
                        if (items != null)
                        {
                            foreach (var entry in items)
                            {
                                var u = LeaderboardItem.ParseJson(entry);
                                if (u != null)
                                {
                                    b.Add(u);
                                }
                            }
                        }
                    }

                    nv.Board = b;

                    nv.IsLoadComplete = true;

                    return(nv);
                }
                catch (Exception e)
                {
                    throw new UserIntendedException(
                              "The leaderboard could not be refreshed right now.", e);
                }
            }