internal LeaderboardResult CreateLeaderboardResponse(LeaderboardQuery query) { LeaderboardResponse lbResponse = JsonConvert.DeserializeObject <LeaderboardResponse>(@"{""pagingInfo"":null,""leaderboardInfo"":{""totalCount"":10,""columnDefinition"":{""statName"":""EnemysDefeated"",""type"":""Double""}},""userList"":[{""gamertag"":""Fake User 1"",""xuid"":""1111111111111111"",""percentile"":0.1,""rank"":1,""globalrank"":10,""value"":""1000"",""valuemetadata"":null},{""gamertag"":""Fake User 2"",""xuid"":""2222222222222222"",""percentile"":0.2,""rank"":2,""globalrank"":20,""value"":""900"",""valuemetadata"":null},{""gamertag"":""Fake User 3"",""xuid"":""3333333333333333"",""percentile"":0.3,""rank"":3,""globalrank"":30,""value"":""800"",""valuemetadata"":null},{""gamertag"":""Fake User 4"",""xuid"":""4444444444444444"",""percentile"":0.4,""rank"":4,""globalrank"":40,""value"":""700"",""valuemetadata"":null},{""gamertag"":""Fake User 5"",""xuid"":""5555555555555555"",""percentile"":0.5,""rank"":5,""globalrank"":50,""value"":""600"",""valuemetadata"":null},{""gamertag"":""Fake User 6"",""xuid"":""6666666666666666"",""percentile"":0.6,""rank"":6,""globalrank"":60,""value"":""500"",""valuemetadata"":null},{""gamertag"":""Fake User 7"",""xuid"":""7777777777777777"",""percentile"":0.7,""rank"":7,""globalrank"":70,""value"":""400"",""valuemetadata"":null},{""gamertag"":""Fake User 8"",""xuid"":""8888888888888888"",""percentile"":0.8,""rank"":8,""globalrank"":80,""value"":""300"",""valuemetadata"":null},{""gamertag"":""Fake User 9"",""xuid"":""9999999999999999"",""percentile"":0.9,""rank"":9,""globalrank"":90,""value"":""200"",""valuemetadata"":null},{""gamertag"":""Fake User 10"",""xuid"":""1010101010101010"",""percentile"":1.0,""rank"":10,""globalrank"":100,""value"":""100"",""valuemetadata"":null},]}"); IList <LeaderboardColumn> columns = new List <LeaderboardColumn> { lbResponse.LeaderboardInfo.Column }; IList <LeaderboardRow> rows = lbResponse.Rows.Select(row => new LeaderboardRow { Gamertag = row.Gamertag, Percentile = row.Percentile, Rank = (uint)row.Rank, XboxUserId = row.XboxUserId, Values = row.Value != null ? new List <string> { row.Value } : row.Values }).ToList(); // Create a result with an 'empty' next query so that it won't have paging. LeaderboardResult result = new LeaderboardResult(rows, columns, lbResponse.LeaderboardInfo.TotalCount); return(result); }
/// <inheritdoc /> public Task <LeaderboardResult> GetLeaderboardAsync(XboxLiveUser user, LeaderboardQuery query) { string skipToXboxUserId = null; if (query.SkipResultToMe) { skipToXboxUserId = user.XboxUserId; } string requestPath; if (string.IsNullOrEmpty(query.SocialGroup)) { requestPath = CreateLeaderboardUrlPath(this.appConfig.PrimaryServiceConfigId, query.StatName, query.MaxItems, skipToXboxUserId, query.SkipResultsToRank, query.ContinuationToken); } else { requestPath = CreateSocialLeaderboardUrlPath(this.appConfig.PrimaryServiceConfigId, query.StatName, user.XboxUserId, query.MaxItems, skipToXboxUserId, query.SkipResultsToRank, query.ContinuationToken, query.SocialGroup); } XboxLiveHttpRequest request = XboxLiveHttpRequest.Create(HttpMethod.Get, leaderboardsBaseUri.ToString(), requestPath); request.ContractVersion = leaderboardApiContract; return(request.GetResponseWithAuth(user) .ContinueWith( responseTask => { return this.HandleLeaderboardResponse(responseTask, query); })); }
public LeaderboardQuery GetNextQueryImpl() { // Allocates memory for returned objects IntPtr cErrMessage = Marshal.AllocHGlobal(MarshalingHelpers.SizeOf <IntPtr>()); IntPtr cNextQuery = Marshal.AllocHGlobal(MarshalingHelpers.SizeOf <IntPtr>()); // Invokes the c method XSAPI_RESULT errCode = LeaderboardResultGetNextQuery(m_leaderboardResultPtr, cNextQuery, cErrMessage); // Handles error string errMessage = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(cErrMessage)); Marshal.FreeHGlobal(cErrMessage); if (errCode != XSAPI_RESULT.XSAPI_RESULT_OK) { // todo do something } // Does local work LeaderboardQuery nextQuery = new LeaderboardQuery(Marshal.ReadIntPtr(cNextQuery)); Marshal.FreeHGlobal(cNextQuery); return(nextQuery); }
public LeaderboardQuery(LeaderboardQuery query) { this.MaxItems = query.MaxItems; this.Order = query.Order; this.SkipResultsToRank = query.SkipResultsToRank; this.SkipResultToMe = query.SkipResultToMe; }
internal LeaderboardResult HandleLeaderboardResponse(Task <XboxLiveHttpResponse> responseTask, LeaderboardQuery query) { XboxLiveHttpResponse response = responseTask.Result; LeaderboardResponse lbResponse = JsonSerialization.FromJson <LeaderboardResponse>(response.ResponseBodyString); IList <LeaderboardColumn> columns = new List <LeaderboardColumn> { lbResponse.LeaderboardInfo.Column }; IList <LeaderboardRow> rows = new List <LeaderboardRow>(); foreach (LeaderboardRowResponse row in lbResponse.Rows) { LeaderboardRow newRow = new LeaderboardRow { Gamertag = row.Gamertag, Percentile = row.Percentile, Rank = row.Rank, XboxUserId = row.XboxUserId, Values = row.Value != null ? new List <string> { row.Value } : row.Values, }; rows.Add(newRow); } LeaderboardQuery nextQuery = new LeaderboardQuery(query, lbResponse.PagingInfo != null ? lbResponse.PagingInfo.ContinuationToken : null); LeaderboardResult result = new LeaderboardResult(lbResponse.LeaderboardInfo.TotalCount, columns, rows, nextQuery); return(result); }
public Task <LeaderboardResult> GetLeaderboardAsync(string statName, LeaderboardQuery query) { string xuid = null; if (query.SkipResultToMe) { xuid = userContext.XboxUserId; } return(this.GetLeaderboardInternal(userContext.XboxUserId, appConfig.ServiceConfigurationId, statName, null, query, LeaderboardRequestType.Global)); }
public LeaderboardQueryImpl(IntPtr ptr, LeaderboardQuery query) { m_leaderboardQueryPtr = ptr; LEADERBOARD_QUERY cLeaderboardQuery = MarshalingHelpers.PtrToStructure <LEADERBOARD_QUERY>(m_leaderboardQueryPtr); m_skipResultToMe = cLeaderboardQuery.SkipResultToMe; m_skipResultToRank = cLeaderboardQuery.SkipResultToRank; m_maxItems = cLeaderboardQuery.MaxItems; m_order = cLeaderboardQuery.Order; query.StatName = MarshalingHelpers.Utf8ToString(cLeaderboardQuery.StatName); query.SocialGroup = MarshalingHelpers.Utf8ToString(cLeaderboardQuery.SocialGroup); query.HasNext = cLeaderboardQuery.HasNext; }
internal Task <LeaderboardResult> GetLeaderboardInternal(string xuid, string serviceConfigurationId, string leaderboardName, string socialGroup, LeaderboardQuery query, LeaderboardRequestType leaderboardType) { string requestPath = ""; string skipToXboxUserId = null; if (query.SkipResultToMe) { skipToXboxUserId = userContext.XboxUserId; } if (leaderboardType == LeaderboardRequestType.Social) { requestPath = CreateSocialLeaderboardUrlPath(serviceConfigurationId, leaderboardName, xuid, query.MaxItems, skipToXboxUserId, query.SkipResultsToRank, query.ContinuationToken, socialGroup); } else { requestPath = CreateLeaderboardUrlPath(serviceConfigurationId, leaderboardName, xuid, query.MaxItems, skipToXboxUserId, query.SkipResultsToRank, query.ContinuationToken, socialGroup); } XboxLiveHttpRequest request = XboxLiveHttpRequest.Create(xboxLiveContextSettings, HttpMethod.Get, leaderboardsBaseUri.ToString(), requestPath); request.ContractVersion = leaderboardAPIContract; return(request.GetResponseWithAuth(userContext, HttpCallResponseBodyType.JsonBody) .ContinueWith( responseTask => { var leaderboardRequestType = LeaderboardRequestType.Global; if (socialGroup != null) { leaderboardRequestType = LeaderboardRequestType.Social; } LeaderboardRequest leaderboardRequest = new LeaderboardRequest(leaderboardRequestType, leaderboardName); LeaderboardQuery nextQuery = new LeaderboardQuery(query); nextQuery.StatName = leaderboardName; nextQuery.SocialGroup = socialGroup; return this.HandleLeaderboardResponse(leaderboardRequest, responseTask, nextQuery); })); }
public Task <LeaderboardResult> GetLeaderboardAsync(XboxLiveUser user, LeaderboardQuery query) { return(Task.FromResult(this.CreateLeaderboardResponse(query))); }
public Task <LeaderboardResult> GetLeaderboardAsync(XboxLiveUser user, LeaderboardQuery query) { throw new NotImplementedException(); }
// todo remove after removing leaderboard service internal LeaderboardQuery(LeaderboardQuery query, string continuation) { }
internal LeaderboardResult HandleLeaderboardResponse(LeaderboardRequest request, Task <XboxLiveHttpResponse> responseTask, LeaderboardQuery nextQuery) { XboxLiveHttpResponse response = responseTask.Result; LeaderboardResponse lbResponse = JsonSerialization.FromJson <LeaderboardResponse>(response.ResponseBodyString); IList <LeaderboardColumn> columns = new List <LeaderboardColumn>() { lbResponse.LeaderboardInfo.Column }; IList <LeaderboardRow> rows = new List <LeaderboardRow>(); foreach (LeaderboardRowResponse row in lbResponse.Rows) { LeaderboardRow newRow = new LeaderboardRow() { Gamertag = row.Gamertag, Percentile = row.Percentile, Rank = row.Rank, XboxUserId = row.XboxUserId, }; if (row.Value != null) { newRow.Values = new List <string>(); newRow.Values.Add(row.Value); } else { newRow.Values = row.Values; } rows.Add(newRow); } if (lbResponse.PagingInfo != null) { nextQuery.ContinuationToken = lbResponse.PagingInfo.ContinuationToken; } LeaderboardResult result = new LeaderboardResult(lbResponse.LeaderboardInfo.TotalCount, columns, rows, userContext, xboxLiveContextSettings, appConfig) { NextQuery = nextQuery }; return(result); }
public Task <LeaderboardResult> GetSocialLeaderboardAsync(string leaderboardName, string socialGroup, LeaderboardQuery query) { if (string.IsNullOrEmpty(socialGroup)) { throw new XboxException("socialGroup parameter is required for getting Leaderboard for social group."); } if (string.Equals(socialGroup, "people", StringComparison.CurrentCultureIgnoreCase)) { socialGroup = "all"; } return(this.GetLeaderboardInternal(userContext.XboxUserId, appConfig.ServiceConfigurationId, leaderboardName, socialGroup, query, LeaderboardRequestType.Social)); }
public LeaderboardResult(uint totalRowCount, IList <LeaderboardColumn> columns, IList <LeaderboardRow> rows, LeaderboardQuery nextQuery) { if (nextQuery == null) { throw new ArgumentNullException("nextQuery"); } this.TotalRowCount = totalRowCount; this.Columns = columns; this.Rows = rows; this.NextQuery = nextQuery; }
public Task <LeaderboardResult> GetSocialLeaderboardAsync(string leaderboardName, string socialGroup, LeaderboardQuery query) { return(Task.FromResult(this.CreateLeaderboardResponse())); }
public Task <LeaderboardResult> GetLeaderboardAsync(string statName, LeaderboardQuery query) { return(Task.FromResult(this.CreateLeaderboardResponse())); }