public async Task GetLeaderboard()
        {
            LeaderboardQuery query = new LeaderboardQuery
            {
                StatName = "Jumps",
                MaxItems = 100,
            };
            LeaderboardResult result = await this.leaderboardService.GetLeaderboardAsync(this.user, query);

            MockXboxLiveData.MockRequestData mockRequestData = MockXboxLiveData.MockResponses["defaultLeaderboardData"];
            JObject responseJson = JObject.Parse(mockRequestData.Response.ResponseBodyString);

            Assert.AreEqual("GET", mockRequestData.Request.Method);
            Assert.AreEqual("https://leaderboards.xboxlive.com/scids/00000000-0000-0000-0000-0000694f5acb/leaderboards/stat(Jumps)?maxItems=100", mockRequestData.Request.Url);
            Assert.IsTrue(result.HasNext);
            VerifyLeaderboardResult(result, responseJson);

            // Testing continuation token with GetNext.
            LeaderboardQuery  nextQuery  = new LeaderboardQuery(query, "6");
            LeaderboardResult nextResult = await this.leaderboardService.GetLeaderboardAsync(this.user, nextQuery);

            MockXboxLiveData.MockRequestData mockRequestDataWithContinuationToken = MockXboxLiveData.MockResponses["defaultLeaderboardDataWithContinuationToken"];
            JObject responseJsonWithContinuationToken = JObject.Parse(mockRequestDataWithContinuationToken.Response.ResponseBodyString);

            Assert.AreEqual("GET", mockRequestDataWithContinuationToken.Request.Method);
            Assert.AreEqual("https://leaderboards.xboxlive.com/scids/00000000-0000-0000-0000-0000694f5acb/leaderboards/stat(Jumps)?maxItems=100&continuationToken=6", mockRequestDataWithContinuationToken.Request.Url);
            Assert.IsFalse(nextResult.HasNext);
            VerifyLeaderboardResult(nextResult, responseJsonWithContinuationToken);
        }
Example #2
0
 public Leaderboard(LeaderboardQuery flag, LeaderboardSort sort, bool allowEmptyValues = false, int pageSize = 10)
 {
     Flag             = flag;
     Sort             = sort;
     AllowEmptyValues = allowEmptyValues;
     PageSize         = pageSize;
 }
Example #3
0
    private void UpdateData(uint newPage)
    {
#if ENABLE_WINMD_SUPPORT
        if (!this.isLocalUserAdded)
        {
            return;
        }

        if (this.stat == null)
        {
            return;
        }

        if (this.XboxLiveUser == null)
        {
            this.XboxLiveUser = XboxLiveUserManager.Instance.GetSingleModeUser();
        }

        LeaderboardQuery query;
        if (newPage == this.currentPage + 1 && this.leaderboardData != null && this.leaderboardData.HasNext)
        {
            query = this.leaderboardData.GetNextQuery();
        }
        else
        {
            switch (leaderboardType)
            {
            case LeaderboardTypes.Global:
                socialGroup = string.Empty;
                break;

            case LeaderboardTypes.Favorites:
                socialGroup = "favorite";
                break;

            case LeaderboardTypes.Friends:
                socialGroup = "all";
                break;
            }

            query = new LeaderboardQuery
            {
                SkipResultToRank = newPage == 0 ? 0 : (newPage * this.entryCount) + 1,
                MaxItems         = this.entryCount,
            };
        }

        this.currentPage = newPage;

        if (socialGroup == string.Empty)
        {
            StatisticManager.SingletonInstance.GetLeaderboard(this.XboxLiveUser.User, this.stat.ID, query);
        }
        else
        {
            StatisticManager.SingletonInstance.GetSocialLeaderboard(this.XboxLiveUser.User, this.stat.ID, socialGroup, query);
        }
#endif
    }
Example #4
0
    private void UpdateData(uint newPage)
    {
        if (!this.isLocalUserAdded)
        {
            return;
        }

        if (this.stat == null)
        {
            return;
        }

        if (this.XboxLiveUser == null)
        {
            this.XboxLiveUser = XboxLiveUserManager.Instance.GetSingleModeUser();
        }

        LeaderboardQuery query;

        if (newPage == this.currentPage + 1 && this.leaderboardData != null && this.leaderboardData.HasNext)
        {
            query = this.leaderboardData.NextQuery;
        }
        else
        {
            switch (leaderboardType)
            {
            case LeaderboardTypes.Global:
                socialGroup = null;
                break;

            case LeaderboardTypes.Favorites:
                socialGroup = "favorite";
                break;

            case LeaderboardTypes.Friends:
                socialGroup = "all";
                break;
            }

            query = new LeaderboardQuery
            {
                StatName          = this.stat.ID,
                SocialGroup       = socialGroup,
                SkipResultsToRank = newPage == 0 ? 0 : (this.currentPage * this.entryCount) - 1,
                MaxItems          = this.entryCount,
            };

            // Handle last page
            if (this.totalPages > 0 && newPage == this.totalPages)
            {
                query.SkipResultsToRank = (newPage * this.entryCount) - 1;
                newPage -= 1;
            }
        }

        this.currentPage = newPage;
        XboxLive.Instance.StatsManager.GetLeaderboard(this.XboxLiveUser.User, query);
    }
Example #5
0
 private async void socialLeaderboardButton_Click(object sender, RoutedEventArgs e)
 {
     if (this.xblUser.IsSignedIn)
     {
         LeaderboardQuery query = new LeaderboardQuery();
         query.MaxItems = 1;
         StatsManager.Singleton.GetSocialLeaderboard(this.xblUser, "headshots", "all", query);
     }
 }
        public void GetLeaderboard(XboxLiveUser user, string statName, LeaderboardQuery query)
        {
            if (!LocalUsers.Contains(user))
            {
                throw new ArgumentException("Local User needs to be added.");
            }

            if (!mStats.ContainsKey(statName))
            {
                mStats[statName] = new StatisticValue()
                {
                    Name      = statName,
                    AsInteger = 300,
                    AsNumber  = 300,
                    DataType  = StatisticDataType.Number
                };
            }

            StatisticValue stat = mStats[statName];

            List <LeaderboardRow> rows = new List <LeaderboardRow>();
            uint maxScore      = query.MaxItems * 100;
            uint rankOffset    = query.SkipResultToRank == 0 ? 1 : query.SkipResultToRank;
            bool userDisplayed = false;

            for (uint i = 0; i < query.MaxItems; i++)
            {
                uint           score = maxScore - i * 100;
                LeaderboardRow row;
                if (!userDisplayed && stat.DataType == StatisticDataType.Number && (stat.AsNumber >= score || stat.AsInteger >= score))
                {
                    userDisplayed = true;
                    row           = new LeaderboardRow(new List <string> {
                        stat.AsNumber.ToString()
                    }, i + rankOffset, 0.8, user.XboxUserId, user.Gamertag);
                }
                else
                {
                    row = new LeaderboardRow(new List <string> {
                        score.ToString()
                    }, i + rankOffset, 0.8, string.Format("{0}{0}{0}{0}{0}{0}{0}{0}", i), string.Format("Gamertag {0}", i));
                }

                rows.Add(row);
            }

            List <LeaderboardColumn> cols = new List <LeaderboardColumn>();

            cols.Add(new LeaderboardColumn(stat.DataType == StatisticDataType.String ? LeaderboardStatType.String : LeaderboardStatType.Integer, ""));

            LeaderboardResult result = new LeaderboardResult(rows, cols, query.MaxItems);

            LeaderboardResultEventArgs args = new LeaderboardResultEventArgs(result);

            mStatEventList.Add(new StatisticEvent(StatisticEventType.GetLeaderboardComplete, user, args));
        }
 /// <summary>
 /// Create a continuation query from an existing query combined with a continuation token.
 /// </summary>
 /// <param name="query">The query that this continuation query is based on.</param>
 /// <param name="continuationToken">The continuation token for the next request.</param>
 public LeaderboardQuery(LeaderboardQuery query, string continuationToken)
 {
     this.StatName          = query.StatName;
     this.SocialGroup       = query.SocialGroup;
     this.MaxItems          = query.MaxItems;
     this.Order             = query.Order;
     this.SkipResultsToRank = query.SkipResultsToRank;
     this.SkipResultToMe    = query.SkipResultToMe;
     this.ContinuationToken = continuationToken;
 }
 private void socialLeaderboardButton_Click(object sender, RoutedEventArgs e)
 {
     if (this.User.IsSignedIn)
     {
         LeaderboardQuery query = new LeaderboardQuery
         {
             MaxItems = 3
         };
         this.StatsManager.GetSocialLeaderboard(this.User, "headshots", "all", query);
     }
 }
Example #9
0
 private static string GetHeader(LeaderboardQuery flag)
 {
     return(flag switch
     {
         LeaderboardQuery.Money => "> 📈 **Leaderboard: Wealth**",
         LeaderboardQuery.Debt => "> 📈 **Leaderboard: Debt**",
         LeaderboardQuery.Level => "> 📈 **Leaderboard: Experience**",
         LeaderboardQuery.Chips => "> 📈 **Leaderboard: Casino**",
         LeaderboardQuery.Merits => "> 📈 **Leaderboard: Merits**",
         _ => "> 📈 **Leaderboard**"
     });
Example #10
0
        public async Task GetLeaderboardAsync(LeaderboardQuery flag = LeaderboardQuery.Default, LeaderboardSort sort = LeaderboardSort.Most, int page = 1)
        {
            if (flag == LeaderboardQuery.Custom)
            {
                flag = LeaderboardQuery.Default;
            }

            var    board  = new Leaderboard(flag, sort);
            string result = board.Write(Context.Account, Context.Data.Users.Values.Values, --page);

            await Context.Channel.SendMessageAsync(result);
        }
        private void NextLb_Click(object sender, RoutedEventArgs e)
        {
            if (!this.User.IsSignedIn)
            {
                return;
            }

            if (this.LeaderboardResult.HasNext)
            {
                LeaderboardQuery nextQuery = this.LeaderboardResult.GetNextQuery();
                this.StatsManager.GetLeaderboard(this.User, nextQuery.StatName, nextQuery);
            }
        }
 public void GetLeaderboard(XboxLiveUser user, string statName, LeaderboardQuery query)
 {
     this.CheckUserValid(user);
     this.userStatContextMap[user.XboxUserId].xboxLiveContext.LeaderboardService.GetLeaderboardAsync(statName, query).ContinueWith(responseTask =>
     {
         ((StatsManager)Singleton).AddEvent(
             new StatEvent(StatEventType.GetLeaderboardComplete,
                           user,
                           responseTask.Exception,
                           new LeaderboardResultEventArgs(responseTask.Result)
                           ));
     });
 }
 public void GetLeaderboard(XboxLiveUser user, LeaderboardQuery query)
 {
     this.CheckUserValid(user);
     this.leaderboardService.GetLeaderboardAsync(user, query).ContinueWith(responseTask =>
     {
         this.AddEvent(
             new StatEvent(StatEventType.GetLeaderboardComplete,
                           user,
                           responseTask.Exception,
                           new LeaderboardResultEventArgs(responseTask.Result)
                           ));
     });
 }
    private void UpdateData(uint newPage)
    {
        if (!this.isLocalUserAdded)
        {
            return;
        }

        if (this.stat == null)
        {
            return;
        }

        if (this.XboxLiveUser == null)
        {
            this.XboxLiveUser = XboxLiveUserManager.Instance.GetSingleModeUser();
        }

        LeaderboardQuery query;

        if (newPage == this.currentPage + 1 && this.leaderboardData != null && this.leaderboardData.HasNext)
        {
            query = this.leaderboardData.GetNextQuery();
        }
        else
        {
            switch (leaderboardType)
            {
            case LeaderboardTypes.Global:
                socialGroup = "";
                break;

            case LeaderboardTypes.Favorites:
                socialGroup = "favorite";
                break;

            case LeaderboardTypes.Friends:
                socialGroup = "all";
                break;
            }

            query = new LeaderboardQuery()
            {
                SkipResultToRank = newPage == 0 ? 0 : ((newPage - 1) * this.entryCount),
                MaxItems         = this.entryCount,
            };
        }

        this.currentPage = newPage;
        XboxLive.Instance.StatsManager.GetLeaderboard(this.XboxLiveUser.User, this.stat.ID, query);
    }
        private void globalLeaderboardButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.User.IsSignedIn)
            {
                this.StatsManager.RequestFlushToService(this.User, true);
                this.StatsManager.DoWork();

                LeaderboardQuery query = new LeaderboardQuery
                {
                    MaxItems = 3,
                };
                this.StatsManager.GetLeaderboard(this.User, "jumps", query);
            }
        }
        private void UpdateData(uint pageNumber, LeaderboardFilter filter)
        {
            this.viewFilter = filter;

            if (!this.isLocalUserAdded)
            {
                return;
            }

            if (this.stat == null)
            {
                return;
            }

            if (this.xboxLiveUser == null)
            {
                this.xboxLiveUser = SignInManager.Instance.GetPlayer(this.PlayerNumber);
            }

            LeaderboardQuery query;

            if (pageNumber == this.currentPage + 1 && this.leaderboardData != null && this.leaderboardData.HasNext)
            {
                query = this.leaderboardData.GetNextQuery();
            }
            else
            {
                socialGroup = LeaderboardHelper.GetSocialGroupFromLeaderboardType(this.leaderboardType);
                if (filter == LeaderboardFilter.Default)
                {
                    query = new LeaderboardQuery()
                    {
                        SkipResultToRank = pageNumber == 0 ? 0 : ((pageNumber - 1) * this.entryCount),
                        MaxItems         = this.entryCount,
                    };
                }
                else
                {
                    query = new LeaderboardQuery()
                    {
                        SkipResultToMe = true,
                        MaxItems       = this.entryCount,
                    };
                }
            }

            this.currentPage = pageNumber;
            XboxLive.Instance.StatsManager.GetLeaderboard(this.xboxLiveUser, this.stat.ID, query);
        }
Example #17
0
 public void GetLeaderboard(XboxLiveUser user, string statName, LeaderboardQuery query)
 {
     if (mockLBService == null)
     {
         throw new ArgumentException("Local User needs to be added.");
     }
     mockLBService.GetLeaderboardAsync(statName, query).ContinueWith(responseTask =>
     {
         this.statEventList.Add(
             new StatEvent(StatEventType.GetLeaderboardComplete,
                           user,
                           responseTask.Exception,
                           new LeaderboardResultEventArgs(responseTask.Result)
                           ));
     });;
 }
Example #18
0
        public void GetLeaderboard(XboxLiveUser user, string statName, LeaderboardQuery query)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            IntPtr cErrMessage;
            // Invokes the c method
            XSAPI_RESULT errCode = StatsManagerGetLeaderboard(user.Impl.XboxLiveUserPtr, statName, query.GetPtr(), out cErrMessage);

            if (errCode > 0)
            {
                throw new XboxException(errCode, cErrMessage);
            }
        }
Example #19
0
        public void GetLeaderboard(XboxLiveUser user, LeaderboardQuery query)
        {
            if (!this.LocalUsers.Contains(user))
            {
                throw new ArgumentException("Local User needs to be added.");
            }

            this.leaderboardService.GetLeaderboardAsync(user, query).ContinueWith(responseTask =>
            {
                this.statEventList.Add(
                    new StatEvent(StatEventType.GetLeaderboardComplete,
                                  user,
                                  responseTask.Exception,
                                  new LeaderboardResultEventArgs(responseTask.Result)
                                  ));
            });
        }
        public static void PrintStats()
        {
            if (!XboxLiveObject.IsReady)
            {
                return;
            }

            var stats = XboxLiveStatsManager.StatsManager.GetStatisticNames(XboxLiveObject.CurrentUser);

            Debug.WriteLine("######### Printing Stats #######");
            foreach (string stat in stats)
            {
                Debug.WriteLine("~~~~~~~" + stat + "~~~~~~~");
                var ret = XboxLiveStatsManager.StatsManager.GetStatistic(XboxLiveObject.CurrentUser, stat);
                XboxLiveStatsManager.StatsManager.DoWork();
                Debug.WriteLine(ret.AsInteger);

                var query = new LeaderboardQuery {
                    MaxItems = 10
                };
                XboxLiveStatsManager.StatsManager.GetLeaderboard(XboxLiveObject.CurrentUser, stat, query);
                var stat_events = XboxLiveStatsManager.StatsManager.DoWork();
                while (stat_events.Count == 0)
                {
                    stat_events = XboxLiveStatsManager.StatsManager.DoWork();
                }
                foreach (var stat_event in stat_events)
                {
                    if (stat_event.EventType == StatisticEventType.GetLeaderboardComplete &&
                        stat_event.ErrorCode == 0)
                    {
                        try {
                            var leader_args        = (LeaderboardResultEventArgs)stat_event.EventArgs;
                            var leaderboard_result = leader_args.Result;
                            foreach (var leader_row in leaderboard_result.Rows)
                            {
                                Debug.WriteLine("Rank: {0} | Gamertag: {1} | Score: {2}", leader_row.Rank, leader_row.Gamertag, leader_row.Values[0]);
                            }
                        } catch {}
                    }
                }
            }

            Debug.WriteLine("######### Printing Stats #######");
        }
 public void NextPage()
 {
     if (this.leaderboardData != null && this.leaderboardData.NextQuery != null && this.leaderboardData.NextQuery.HasNext)
     {
         LeaderboardQuery query = this.leaderboardData.NextQuery;
         this.currentPage++;
         if (isLocalUserAdded)
         {
             if (isConfigured || string.IsNullOrEmpty(socialGroup))
             {
                 StatsManager.Singleton.GetLeaderboard(XboxLive.Instance.User, query.StatName, query);
             }
             else
             {
                 StatsManager.Singleton.GetSocialLeaderboard(XboxLive.Instance.User, query.StatName, socialGroup, query);
             }
         }
     }
 }
    private void UpdateData()
    {
        LeaderboardQuery query = new LeaderboardQuery
        {
            SkipResultsToRank = this.currentPage * this.entryCount,
            MaxItems          = this.entryCount,
        };

        if (isLocalUserAdded && Stat != null)
        {
            if (isConfigured || string.IsNullOrEmpty(socialGroup))
            {
                StatsManager.Singleton.GetLeaderboard(XboxLive.Instance.User, Stat.Name, query);
            }
            else
            {
                StatsManager.Singleton.GetSocialLeaderboard(XboxLive.Instance.User, Stat.Name, socialGroup, query);
            }
        }
    }
        public void GetLeaderboard(XboxLiveUser user, string statName, LeaderboardQuery query)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            // Allocates memory for returned objects
            IntPtr cErrMessage = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

            // Invokes the c method
            XSAPI_RESULT errCode = StatsManagerGetLeaderboard(user.Impl.XboxLiveUserPtr, statName, query.GetPtr(), cErrMessage);

            // Handles error
            string errMessage = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(cErrMessage));

            Marshal.FreeHGlobal(cErrMessage);

            if (errCode > 0)
            {
                // todo do something
            }
        }
Example #24
0
    private void UpdateData(uint newPage)
    {
        if (!this.isLocalUserAdded)
        {
            return;
        }
        if (this.stat == null)
        {
            return;
        }

        if (this.isConfigured && string.IsNullOrEmpty(this.socialGroup))
        {
            throw new InvalidOperationException("If you are using a configured leaderboard you must specify a social group.");
        }

        LeaderboardQuery query;

        if (newPage == this.currentPage + 1 && this.leaderboardData != null && this.leaderboardData.HasNext)
        {
            query = this.leaderboardData.NextQuery;
        }
        else
        {
            query = new LeaderboardQuery
            {
                StatName          = this.stat.Name,
                SocialGroup       = this.socialGroup,
                SkipResultsToRank = this.currentPage * this.entryCount,
                MaxItems          = this.entryCount,
            };
        }

        this.currentPage = newPage;
        XboxLive.Instance.StatsManager.GetLeaderboard(XboxLiveComponent.Instance.User, query);
    }
        public void GetSocialLeaderboard(XboxLiveUser user, string statName, string socialGroup, LeaderboardQuery query)
        {
            if (!LocalUsers.Contains(user))
            {
                throw new ArgumentException("Local User needs to be added.");
            }

            GetLeaderboard(user, statName, query);
        }