示例#1
0
        public Task UpdateStatsValueDocument(XboxLiveUser user, StatsValueDocument statValuePostDocument)
        {
            string pathAndQuery = PathAndQueryStatSubpath(
                user.XboxUserId,
                this.config.PrimaryServiceConfigId,
                false
                );

            XboxLiveHttpRequest req = XboxLiveHttpRequest.Create(HttpMethod.Post, this.statsWriteEndpoint, 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, serializerSettings);
            return(req.GetResponseWithAuth(user));
        }
        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;
                }
            }));
        }