示例#1
0
        public async Task <IEnumerable <Play> > LoadLastPlays(string Username)
        {
            try
            {
                Uri       teamDataURI = new Uri(string.Format(BASE_URL + "/plays?username={0}", Username));
                XDocument xDoc        = await ReadData(teamDataURI);

                IEnumerable <Play> gameCollection = from Boardgame in xDoc.Descendants("play")
                                                    select new Play
                {
                    PlayId        = int.Parse(Boardgame.Attribute("id").Value),
                    BoardGameName = Boardgame.Element("item").Attribute("name").Value,
                    BoardGameId   = int.Parse(Boardgame.Element("item").Attribute("objectid").Value),
                    PlayDate      = safeParseDateTime(Boardgame.Attribute("date").Value),
                    NumberOfPlays = int.Parse(Boardgame.Attribute("quantity").Value),
                    Length        = int.Parse(Boardgame.Attribute("length").Value),
                    UserComment   = GetStringValue(Boardgame.Element("comments")),
                    Players       = LoadPlayersStatsList(Boardgame.Element("players"))
                };

                return(gameCollection);
            }
            catch (Exception)
            {
                return(new List <Play>());
            }
        }
示例#2
0
        public async Task <IEnumerable <Boardgame> > LoadHotness()
        {
            try
            {
                Uri       teamDataURI = new Uri(BASE_URL + "/hot?thing=boardgame");
                XDocument xDoc        = await ReadData(teamDataURI);

                // LINQ to XML.
                IEnumerable <Boardgame> gameCollection = from Boardgame in xDoc.Descendants("item")
                                                         select new Boardgame
                {
                    Name          = Boardgame.Element("name").Attribute("value").Value,
                    YearPublished = Boardgame.Element("yearpublished") != null?int.Parse(Boardgame.Element("yearpublished").Attribute("value").Value) : 0,
                                        Thumbnail = Boardgame.Element("thumbnail").Attribute("value").Value,
                                        GameId    = int.Parse(Boardgame.Attribute("id").Value)
                };

                return(gameCollection);
            }
            catch (Exception ex)
            {
                //ExceptionHandler(ex);
                return(new List <Boardgame>());
            }
        }
示例#3
0
        public async Task <User> LoadUserDetails(string username)
        {
            try
            {
                Uri teamDataURI = new Uri(string.Format(BASE_URL + "/user?name={0}", username));

                XDocument xDoc = await ReadData(teamDataURI);

                IEnumerable <User> users = from Boardgame in xDoc.Descendants("user")
                                           select new User
                {
                    BggUserId      = int.Parse(Boardgame.Attribute("id").Value),
                    Username       = Boardgame.Attribute("name").Value,
                    Avatar         = GetStringValue(Boardgame.Element("avatarlink"), "value"),
                    FirstName      = GetStringValue(Boardgame.Element("firstname"), "value"),
                    LastName       = GetStringValue(Boardgame.Element("lastname"), "value"),
                    YearRegistered = GetStringValue(Boardgame.Element("yearregistered"), "value"),
                };
                return(users.FirstOrDefault());
            }
            catch (Exception)
            {
                return(new User());
            }
        }
示例#4
0
        public async Task <Boardgame> LoadGame(int GameId)
        {
            try
            {
                Uri       teamDataURI = new Uri(string.Format(BASE_URL + "/thing?id={0}&stats=1&comments=1", GameId));
                XDocument xDoc        = await ReadData(teamDataURI);

                // LINQ to XML.
                IEnumerable <Boardgame> gameCollection = from Boardgame in xDoc.Descendants("items")
                                                         select new Boardgame
                {
                    Name              = (from p in Boardgame.Element("item").Elements("name") where p.Attribute("type").Value == "primary" select p.Attribute("value").Value).SingleOrDefault(),
                    GameId            = int.Parse(Boardgame.Element("item").Attribute("id").Value),
                    Image             = Boardgame.Element("item").Element("image") != null?Boardgame.Element("item").Element("image").Value         : string.Empty,
                    Thumbnail         = Boardgame.Element("item").Element("thumbnail") != null?Boardgame.Element("item").Element("thumbnail").Value : string.Empty,
                    Description       = Boardgame.Element("item").Element("description").Value,
                    MaxPlayers        = int.Parse(Boardgame.Element("item").Element("maxplayers").Attribute("value").Value),
                    MinPlayers        = int.Parse(Boardgame.Element("item").Element("minplayers").Attribute("value").Value),
                    YearPublished     = int.Parse(Boardgame.Element("item").Element("yearpublished").Attribute("value").Value),
                    PlayingTime       = int.Parse(Boardgame.Element("item").Element("playingtime").Attribute("value").Value),
                    AverageRating     = decimal.Parse(Boardgame.Element("item").Element("statistics").Element("ratings").Element("average").Attribute("value").Value),
                    BGGRating         = decimal.Parse(Boardgame.Element("item").Element("statistics").Element("ratings").Element("bayesaverage").Attribute("value").Value),
                    Rank              = GetRanking(Boardgame.Element("item").Element("statistics").Element("ratings").Element("ranks")),
                    Publishers        = (from p in Boardgame.Element("item").Elements("link") where p.Attribute("type").Value == "boardgamepublisher" select p.Attribute("value").Value).ToList(),
                    Designers         = (from p in Boardgame.Element("item").Elements("link") where p.Attribute("type").Value == "boardgamedesigner" select p.Attribute("value").Value).ToList(),
                    Artists           = (from p in Boardgame.Element("item").Elements("link") where p.Attribute("type").Value == "boardgameartist" select p.Attribute("value").Value).ToList(),
                    Comments          = LoadComments(Boardgame.Element("item").Element("comments")),
                    PlayerPollResults = LoadPlayerPollResults(Boardgame.Element("item").Element("poll")),
                    IsExpansion       = SetIsExpansion(Boardgame),
                    TotalComments     = int.Parse(Boardgame.Element("item").Element("comments").Attribute("totalitems").Value)
                };


                return(gameCollection.FirstOrDefault());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
示例#5
0
        public async Task <BGGUser> LoadUserDetails(string username)
        {
            try
            {
                Uri teamDataURI = new Uri(string.Format(BASE_URL + "/user?name={0}", username));

                XDocument xDoc = await ReadData(teamDataURI);

                // LINQ to XML.
                IEnumerable <BGGUser> users = from Boardgame in xDoc.Descendants("user")
                                              select new BGGUser
                {
                    Avatar   = GetStringValue(Boardgame.Element("avatarlink"), "value"),
                    Username = username
                };
                return(users.FirstOrDefault());
            }
            catch (Exception ex)
            {
                return(new BGGUser());
            }
        }
示例#6
0
        public async Task <IEnumerable <SearchResult> > Search(string query)
        {
            try
            {
                Uri teamDataURI = new Uri(string.Format(BASE_URL + "/search?query={0}&type=boardgame", query));

                XDocument xDoc = await ReadData(teamDataURI);

                // LINQ to XML.
                IEnumerable <SearchResult> gameCollection = from Boardgame in xDoc.Descendants("item")
                                                            select new SearchResult
                {
                    Name   = GetStringValue(Boardgame.Element("name"), "value"),
                    GameId = GetIntValue(Boardgame, "id")
                };
                return(gameCollection);
            }
            catch (Exception ex)
            {
                return(new List <SearchResult>());
            }
        }
示例#7
0
        public async Task <IEnumerable <PlayItem> > LoadLastPlays(string Username)
        {
            try
            {
                Uri       teamDataURI = new Uri(string.Format(BASE_URL + "/plays?username={0}&subtype=boardgame&excludesubtype=videogame", Username));
                XDocument xDoc        = await ReadData(teamDataURI);

                // LINQ to XML.
                IEnumerable <PlayItem> gameCollection = from Boardgame in xDoc.Descendants("play")
                                                        select new PlayItem
                {
                    Name     = Boardgame.Element("item").Attribute("name").Value,
                    NumPlays = int.Parse(Boardgame.Attribute("quantity").Value),
                    GameId   = int.Parse(Boardgame.Element("item").Attribute("objectid").Value),
                    PlayDate = safeParseDateTime(Boardgame.Attribute("date").Value)
                };
                return(gameCollection);
            }
            catch (Exception ex)
            {
                return(new List <PlayItem>());
            }
        }
示例#8
0
        public async Task <IEnumerable <HotItem> > LoadHotItems()
        {
            try
            {
                Uri       teamDataURI = new Uri(BASE_URL + "/hot?type=boardgame");
                XDocument xDoc        = await ReadData(teamDataURI);

                IEnumerable <HotItem> hotBoardGamesCollection = from Boardgame in xDoc.Descendants("item")
                                                                select new HotItem
                {
                    Name          = Boardgame.Element("name").Attribute("value").Value,
                    YearPublished = Boardgame.Element("yearpublished") != null?int.Parse(Boardgame.Element("yearpublished").Attribute("value").Value) : 0,
                                        ThumbnailWeb = "http:" + Boardgame.Element("thumbnail").Attribute("value").Value,
                                        BoardGameId  = int.Parse(Boardgame.Attribute("id").Value),
                                        Rank         = int.Parse(Boardgame.Attribute("rank").Value)
                };
                return(hotBoardGamesCollection);
            }
            catch (Exception)
            {
                return(new List <HotItem>());
            }
        }
示例#9
0
        public async Task <IEnumerable <SearchResult> > Search(string query, CancellationTokenSource cts)
        {
            try
            {
                query = query.Replace(" ", "+");
                Uri teamDataURI = new Uri(string.Format(BASE_URL + "/search?query={0}&type=boardgame", query));

                XDocument xDoc = await ReadData(teamDataURI, cts);

                IEnumerable <SearchResult> searchResults = from Boardgame in xDoc.Descendants("item")
                                                           select new SearchResult
                {
                    BoardGameName = GetStringValue(Boardgame.Element("name"), "value"),
                    BoardGameId   = GetIntValue(Boardgame, "id"),
                    YearPublished = GetIntValue(Boardgame.Element("yearpublished"), "value")
                };
                return(searchResults);
            }
            catch (Exception)
            {
                return(new List <SearchResult>());
            }
        }
示例#10
0
        public async Task <Plays> LoadPlays(string username, int page = 1, DateTime?minDate = null, DateTime?maxDate = null)
        {
            try
            {
                string url = string.Format(BASE_URL2 + "/plays?username={0}&subtype=boardgame&excludesubtype=videogame&page={1}", username, page);
                if (minDate != null)
                {
                    url += "&mindate=" + minDate.Value.ToString("yyyy-MM-dd");
                }
                if (maxDate != null)
                {
                    url += "&maxdate=" + maxDate.Value.ToString("yyyy-MM-dd");
                }
                Uri       teamDataURI = new Uri(url);
                XDocument xDoc        = await ReadData(teamDataURI);

                // LINQ to XML.
                IEnumerable <PlayItem> gameCollection = from Boardgame in xDoc.Descendants("play")
                                                        select new PlayItem
                {
                    Name     = Boardgame.Element("item").Attribute("name").Value,
                    NumPlays = int.Parse(Boardgame.Attribute("quantity").Value),
                    GameId   = int.Parse(Boardgame.Element("item").Attribute("objectid").Value),
                    PlayDate = safeParseDateTime(Boardgame.Attribute("date").Value),
                    Comments = Boardgame.Element("comments") != null?TrimmedStringOrNull(Boardgame.Element("comments").Value) : null
                };
                var plays = new Plays();
                plays.Total = int.Parse(xDoc.Root.Attribute("total").Value);
                plays.Items = gameCollection;
                return(plays);
            }
            catch (Exception ex)
            {
                throw;
                //return new Plays();
            }
        }
示例#11
0
        public async Task <GameDetails> LoadGame(int GameId, bool useLongCache)
        {
            GameDetails details = null;

            if (useLongCache)
            {
                details = _gameCache.Get(Cache.LongThingKey(GameId)) as GameDetails;
            }

            if (details != null)
            {
                return(details);
            }

            try
            {
                Uri       teamDataURI = new Uri(string.Format(BASE_URL2 + "/thing?id={0}&stats=1", GameId));
                XDocument xDoc        = await ReadData(teamDataURI);

                // LINQ to XML.
                IEnumerable <GameDetails> gameCollection = from Boardgame in xDoc.Descendants("items")
                                                           select new GameDetails
                {
                    Name          = (from p in Boardgame.Element("item").Elements("name") where p.Attribute("type").Value == "primary" select p.Attribute("value").Value).SingleOrDefault(),
                    GameId        = int.Parse(Boardgame.Element("item").Attribute("id").Value),
                    Artists       = (from p in Boardgame.Element("item").Elements("link") where p.Attribute("type").Value == "boardgameartist" select p.Attribute("value").Value).ToList(),
                    AverageRating = decimal.Parse(Boardgame.Element("item").Element("statistics").Element("ratings").Element("average").Attribute("value").Value),
                    BGGRating     = decimal.Parse(Boardgame.Element("item").Element("statistics").Element("ratings").Element("bayesaverage").Attribute("value").Value),
                    //Comments = LoadComments(Boardgame.Element("item").Element("comments")),
                    Description       = Boardgame.Element("item").Element("description").Value,
                    Designers         = (from p in Boardgame.Element("item").Elements("link") where p.Attribute("type").Value == "boardgamedesigner" select p.Attribute("value").Value).ToList(),
                    Expands           = SetExpandsLinks(Boardgame),
                    Expansions        = SetExpansionsLinks(Boardgame),
                    Mechanics         = (from p in Boardgame.Element("item").Elements("link") where p.Attribute("type").Value == "boardgamemechanic" select p.Attribute("value").Value).ToList(),
                    Image             = Boardgame.Element("item").Element("image") != null?Boardgame.Element("item").Element("image").Value : string.Empty,
                    IsExpansion       = SetIsExpansion(Boardgame),
                    Thumbnail         = Boardgame.Element("item").Element("thumbnail") != null?Boardgame.Element("item").Element("thumbnail").Value : string.Empty,
                    MaxPlayers        = int.Parse(Boardgame.Element("item").Element("maxplayers").Attribute("value").Value),
                    MinPlayers        = int.Parse(Boardgame.Element("item").Element("minplayers").Attribute("value").Value),
                    PlayerPollResults = LoadPlayerPollResults(Boardgame.Element("item").Element("poll")),
                    PlayingTime       = int.Parse(Boardgame.Element("item").Element("playingtime").Attribute("value").Value),
                    Publishers        = (from p in Boardgame.Element("item").Elements("link") where p.Attribute("type").Value == "boardgamepublisher" select p.Attribute("value").Value).ToList(),
                    Rank = GetRanking(Boardgame.Element("item").Element("statistics").Element("ratings").Element("ranks")),
                    //TotalComments = int.Parse(Boardgame.Element("item").Element("comments").Attribute("totalitems").Value),
                    YearPublished = int.Parse(Boardgame.Element("item").Element("yearpublished").Attribute("value").Value)
                };

                details = gameCollection.FirstOrDefault();

                if (details.Expands != null && details.Expands.Count == 0)
                {
                    details.Expands = null;
                }
                if (details.Expansions != null && details.Expansions.Count == 0)
                {
                    details.Expansions = null;
                }

                if (details != null)
                {
                    _gameCache.Set(Cache.LongThingKey(details.GameId), details, DateTimeOffset.Now.AddSeconds(GameCacheDuration));
                }

                return(details);
            }
            catch (Exception ex)
            {
                throw;
                //return null;
            }
        }