Exemple #1
0
        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);
        }
        private void HandleSetPresenceResponse(XboxLiveUser xboxLiveUser, XboxLiveHttpResponse httpResponse)
        {
            if (httpResponse.Headers.ContainsKey(HeartBeatFromServiceHeaderName))
            {
                var heartBeatFromServiceInSecs = int.Parse(httpResponse.Headers[HeartBeatFromServiceHeaderName]);
                usersBeingTrackedMap[xboxLiveUser].HeartBeatIntervalInMins = (heartBeatFromServiceInSecs / 60);
            }
            else
            {
                usersBeingTrackedMap[xboxLiveUser].HeartBeatIntervalInMins = defaultHeartBeatDelayInMins;
            }

            if (usersBeingTrackedMap[xboxLiveUser].ShouldRemove)
            {
                usersBeingTrackedMap.Remove(xboxLiveUser);
            }
        }
Exemple #3
0
        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 UpdateStatsValueDocument(StatsValueDocument statValuePostDocument)
        {
            string endpoint     = XboxLiveEndpoint.GetEndpointForService("statswrite", this.config);
            string pathAndQuery = PathAndQueryStatSubpath(
                this.context.User.XboxUserId,
                this.config.ServiceConfigurationId,
                false
                );

            XboxLiveHttpRequest req = XboxLiveHttpRequest.Create(this.settings, "POST", endpoint, pathAndQuery);
            var svdModel            = new Models.StatsValueDocumentModel()
            {
                Revision  = statValuePostDocument.Revision,
                Timestamp = DateTime.Now,
                Stats     = new Models.Stats()
                {
                    Title = new Dictionary <string, Models.Stat>()
                }
            };

            svdModel.Stats.Title = statValuePostDocument.Stats.ToDictionary(
                stat => stat.Key,
                stat => new Models.Stat()
            {
                Value = stat.Value.Value
            });

            req.RequestBody = JsonConvert.SerializeObject(svdModel, new JsonSerializerSettings
            {
            });

            return(req.GetResponseWithAuth(this.context.User, HttpCallResponseBodyType.JsonBody).ContinueWith(task =>
            {
                XboxLiveHttpResponse response = task.Result;
                if (response.ErrorCode == 0)
                {
                    ++statValuePostDocument.Revision;
                }
            }));
        }
        public Task <StatsValueDocument> GetStatsValueDocument()
        {
            string endpoint     = XboxLiveEndpoint.GetEndpointForService("statsread", this.config);
            string pathAndQuery = PathAndQueryStatSubpath(
                this.context.User.XboxUserId,
                this.config.ServiceConfigurationId,
                false
                );

            XboxLiveHttpRequest req = XboxLiveHttpRequest.Create(this.settings, "GET", endpoint, pathAndQuery);

            return(req.GetResponseWithAuth(this.context.User, HttpCallResponseBodyType.JsonBody).ContinueWith(task =>
            {
                XboxLiveHttpResponse response = task.Result;
                var svdModel = JsonConvert.DeserializeObject <Models.StatsValueDocumentModel>(response.ResponseBodyJson);
                var svd = new StatsValueDocument(svdModel.Stats.Title)
                {
                    Revision = svdModel.Revision
                };
                return svd;
            }));
        }
Exemple #6
0
        public Task <StatsValueDocument> GetStatsValueDocument(XboxLiveUser user)
        {
            string pathAndQuery = PathAndQueryStatSubpath(
                user.XboxUserId,
                this.config.PrimaryServiceConfigId,
                false
                );

            XboxLiveHttpRequest req = XboxLiveHttpRequest.Create(HttpMethod.Get, this.statsReadEndpoint, pathAndQuery);

            return(req.GetResponseWithAuth(user).ContinueWith(task =>
            {
                XboxLiveHttpResponse response = task.Result;
                var svdModel = JsonConvert.DeserializeObject <Models.StatsValueDocumentModel>(response.ResponseBodyString);
                var svd = new StatsValueDocument(svdModel.Stats.Title, svdModel.Revision)
                {
                    State = StatsValueDocument.StatValueDocumentState.Loaded,
                    User = user
                };
                return svd;
            }));
        }
        private static async Task <JobStatusResponse> CheckJobStatus(UserResetJob userResetJob)
        {
            using (var submitRequest = new XboxLiveHttpRequest(true, userResetJob.Scid, userResetJob.Sandbox))
            {
                XboxLiveHttpResponse xblResponse = await submitRequest.SendAsync(() =>
                {
                    var requestMsg = new HttpRequestMessage(HttpMethod.Get, new Uri(baseUri, "jobs/" + userResetJob.JobId));
                    if (!string.IsNullOrEmpty(userResetJob.CorrelationId))
                    {
                        requestMsg.Headers.Add("X-XblCorrelationId", userResetJob.CorrelationId);
                    }
                    requestMsg.Headers.Add("x-xbl-contract-version", "100");

                    return(requestMsg);
                });

                // There is a chance if polling too early for job status, it will return 400.
                // We threat it as job queue and wait for next poll.
                if (xblResponse.Response.StatusCode == System.Net.HttpStatusCode.BadRequest)
                {
                    return(new JobStatusResponse
                    {
                        Status = "Queued",
                        JobId = userResetJob.JobId
                    });
                }

                // Throw HttpRequestExcetpion for other HTTP status code
                xblResponse.Response.EnsureSuccessStatusCode();

                string responseConent = await xblResponse.Response.Content.ReadAsStringAsync();

                var jobstatus = JsonConvert.DeserializeObject <JobStatusResponse>(responseConent);

                Log.WriteLog($"Checking {userResetJob.JobId} job stauts: {jobstatus.Status}");

                return(jobstatus);
            }
        }
        public Task <List <XboxUserProfile> > GetUserProfilesAsync(XboxLiveUser user, List <string> xboxUserIds)
        {
            if (xboxUserIds == null)
            {
                throw new ArgumentNullException("xboxUserIds");
            }
            if (xboxUserIds.Count == 0)
            {
                throw new ArgumentOutOfRangeException("xboxUserIds", "Empty list of user ids");
            }

            if (XboxLive.UseMockServices)
            {
                Random rand = new Random();
                List <XboxUserProfile> outputUsers = new List <XboxUserProfile>(xboxUserIds.Count);
                foreach (string xuid in xboxUserIds)
                {
                    // generate a fake dev gamertag
                    string          gamertag = "2 dev " + rand.Next(10000);
                    XboxUserProfile profile  = new XboxUserProfile()
                    {
                        XboxUserId                         = xuid,
                        ApplicationDisplayName             = gamertag,
                        ApplicationDisplayPictureResizeUri = new Uri("http://images-eds.xboxlive.com/image?url=z951ykn43p4FqWbbFvR2Ec.8vbDhj8G2Xe7JngaTToBrrCmIEEXHC9UNrdJ6P7KI4AAOijCgOA3.jozKovAH98vieJP1ResWJCw2dp82QtambLRqzQbSIiqrCug0AvP4&format=png"),
                        GameDisplayName                    = gamertag,
                        GameDisplayPictureResizeUri        = new Uri("http://images-eds.xboxlive.com/image?url=z951ykn43p4FqWbbFvR2Ec.8vbDhj8G2Xe7JngaTToBrrCmIEEXHC9UNrdJ6P7KI4AAOijCgOA3.jozKovAH98vieJP1ResWJCw2dp82QtambLRqzQbSIiqrCug0AvP4&format=png"),
                        Gamerscore                         = rand.Next(250000).ToString(),
                        Gamertag = gamertag
                    };

                    outputUsers.Add(profile);
                }

                return(Task.FromResult(outputUsers));
            }
            else
            {
                XboxLiveHttpRequest req = XboxLiveHttpRequest.Create(HttpMethod.Post, profileEndpoint, "/users/batch/profile/settings");

                req.ContractVersion = "2";
                req.ContentType     = "application/json; charset=utf-8";
                Models.ProfileSettingsRequest reqBodyObject = new Models.ProfileSettingsRequest(xboxUserIds, true);
                req.RequestBody = JsonSerialization.ToJson(reqBodyObject);
                req.XboxLiveAPI = XboxLiveAPIName.GetUserProfiles;
                return(req.GetResponseWithAuth(user).ContinueWith(task =>
                {
                    XboxLiveHttpResponse response = task.Result;
                    Models.ProfileSettingsResponse responseBody = new Models.ProfileSettingsResponse();
                    responseBody = JsonSerialization.FromJson <Models.ProfileSettingsResponse>(response.ResponseBodyString);

                    List <XboxUserProfile> outputUsers = new List <XboxUserProfile>();
                    foreach (Models.ProfileUser entry in responseBody.profileUsers)
                    {
                        XboxUserProfile profile = new XboxUserProfile()
                        {
                            XboxUserId = entry.id,
                            Gamertag = entry.Gamertag(),
                            GameDisplayName = entry.GameDisplayName(),
                            GameDisplayPictureResizeUri = new Uri(entry.GameDisplayPic()),
                            ApplicationDisplayName = entry.AppDisplayName(),
                            ApplicationDisplayPictureResizeUri = new Uri(entry.AppDisplayPic()),
                            Gamerscore = entry.Gamerscore()
                        };

                        outputUsers.Add(profile);
                    }

                    return outputUsers;
                }));
            }
        }