Esempio n. 1
0
        public bool Put(Player player)
        {
            try
            {
                Execute(() =>
                {
                    var client = new HttpClient
                    {
                        BaseAddress = new Uri(_baseUrl)
                    };
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/bson"));

                    var req = new PutDataRequest
                    {
                        ApiKey  = _apiKey,
                        Context = "Player"
                    };
                    req.SetObject(player);

                    var bsonFormatter = new BsonMediaTypeFormatter();
                    var res           = client.PutAsync("api/admin/Data", req, bsonFormatter).Result;
                    res.EnsureSuccessStatusCode();
                }, 5);

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error($"Put(Player({player.Id}))", ex);
                return(false);
            }
        }
Esempio n. 2
0
        public bool Put(Player player)
        {
            var copy = player;

            if (player.HasMedals)
            {
                // Don't save medals on the remote server, as it will take too much space and there is no use to it (so far)
                copy = (Player)player.Clone();
                copy.PurgeMedals();
            }

            try
            {
                Execute(() =>
                {
                    var client = new HttpClient
                    {
                        BaseAddress = new Uri(_baseUrl)
                    };
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/bson"));

                    var req = new PutDataRequest
                    {
                        ApiKey  = _apiKey,
                        Context = "Player"
                    };
                    req.SetObject(copy);

                    var bsonFormatter = new BsonMediaTypeFormatter();
                    var res           = client.PutAsync("api/admin/Data", req, bsonFormatter).Result;
                    res.EnsureSuccessStatusCode();
                }, 5);

                return(true);
            }
            catch (Exception ex)
            {
                Log.Error($"Put(Player({player.Id}))", ex);
                return(false);
            }
        }