コード例 #1
0
        public string GetGameThumbnail(int gameId)
        {
            var thumbnail = "";

            try
            {
                var apiUri = new Uri(BASE_URL_API_V2 + $"/thing?id={gameId}");
                var xDoc   = _apiDownloadService.DownloadApiResult(apiUri);

                var xElements = xDoc.Descendants("items").ToList();
                if (xElements.Count() == 1)
                {
                    var firstImageElement = xElements.First().Element("item").Element("image");
                    if (firstImageElement != null)
                    {
                        thumbnail = firstImageElement.GetStringValue();
                    }
                }
            }
            catch (Exception ex)
            {
                _rollbar.SendException(ex);
            }

            return(thumbnail);
        }
コード例 #2
0
        public GameDetails GetGameDetails(int gameId)
        {
            GameDetails details = null;


            try
            {
                var teamDataURI = new Uri(string.Format(BASE_URL_API_V2 + "/thing?id={0}&stats=1", gameId));

                var xDoc = _apiDownloadService.DownloadApiResult(teamDataURI);


                // LINQ to XML.
                var xElements = xDoc.Descendants("items").ToList();
                if (xElements.Count() == 1)
                {
                    var gameCollection = from boardgame in xElements
                                         select new GameDetails
                    {
                        Name          = boardgame.GetBoardGameName(),
                        GameId        = boardgame.Element("item").GetIntValue("id"),
                        Artists       = boardgame.GetArtists(),
                        AverageRating =
                            boardgame.Element("item")
                            .Element("statistics")
                            .Element("ratings")
                            .Element("average")
                            .GetDecimalValue("value"),
                        BGGRating =
                            boardgame.Element("item")
                            .Element("statistics")
                            .Element("ratings")
                            .Element("bayesaverage")
                            .GetDecimalValue("value"),
                        Description       = boardgame.Element("item").Element("description").Value,
                        Designers         = boardgame.GetDesigners(),
                        Expansions        = boardgame.GetExpansionsLinks(),
                        Mechanics         = boardgame.GetMechanics(),
                        Categories        = boardgame.GetCategories(),
                        Image             = boardgame.Element("item").Element("image").GetStringValue(),
                        IsExpansion       = boardgame.IsExpansion(),
                        Thumbnail         = boardgame.Element("item").Element("thumbnail").GetStringValue(),
                        MaxPlayers        = boardgame.Element("item").Element("maxplayers").GetIntValue("value"),
                        MinPlayers        = boardgame.Element("item").Element("minplayers").GetIntValue("value"),
                        PlayerPollResults = boardgame.Element("item").Element("poll").GetPlayerPollResults(),
                        PlayingTime       = boardgame.Element("item").Element("playingtime").GetIntValue("value"),
                        Publishers        = boardgame.GetPublishers(),
                        Rank =
                            boardgame.Element("item")
                            .Element("statistics")
                            .Element("ratings")
                            .Element("ranks")
                            .GetRanking(),
                        YearPublished = boardgame.Element("item").Element("yearpublished").GetIntValue("value"),
                    };

                    details = gameCollection.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception on GetGameDetails for ID " + gameId + "." + ex);
            }

            return(details);
        }