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;
            }));
        }
Ejemplo n.º 3
0
        public Task <List <XboxUserProfile> > GetUserProfilesAsync(List <string> xboxUserIds)
        {
            if (xboxUserIds == null)
            {
                throw new ArgumentNullException("xboxUserIds");
            }
            if (xboxUserIds.Count == 0)
            {
                throw new ArgumentOutOfRangeException("xboxUserIds", "Empty list of user ids");
            }

            if (XboxLiveContext.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
            {
                string endpoint         = XboxLiveEndpoint.GetEndpointForService("profile", this.config);
                XboxLiveHttpRequest req = XboxLiveHttpRequest.Create(this.settings, "POST", endpoint, "/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);
                return(req.GetResponseWithAuth(this.context.User, HttpCallResponseBodyType.JsonBody).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;
                }));
            }
        }
 public PeopleHubService(XboxLiveContextSettings httpCallSettings, XboxLiveAppConfiguration appConfig)
 {
     this.httpCallSettings = httpCallSettings;
     this.appConfig        = appConfig;
     this.peopleHubHost    = XboxLiveEndpoint.GetEndpointForService("peoplehub", appConfig);
 }