Esempio n. 1
0
        public async void LoadCollection()
        {
            UserCollection.Clear();


            if (string.IsNullOrEmpty(_Username))
            {
                return;
            }

            LoadCollectionFromCache();

            Messenger.Default.Send <CollectionLoadingMessage>(new CollectionLoadingMessage()
            {
                isQuick = true
            });

            IEnumerable <Boardgame> items = await Client.LoadCollection(_Username);

            foreach (Boardgame item in items)
            {
                BoardGameDataItem cdi = BoardGameStorage.LoadGame(item.GameId);
                if (cdi == null)// Add to main store
                {
                    cdi = new BoardGameDataItem();
                    cdi.IsFullyLoaded = false; // Indicate Loadgame should get individual results from API
                    BoardGameStorage.AddGame(cdi);
                }

                cdi.Name            = item.Name;
                cdi.NumPlays        = item.NumPlays;
                cdi.Thumbnail       = item.Thumbnail;
                cdi.YearPublished   = item.YearPublished;
                cdi.GameId          = item.GameId;
                cdi.ForTrade        = item.ForTrade;
                cdi.Owned           = item.Owned;
                cdi.PreOrdered      = item.PreOrdered;
                cdi.Want            = item.Want;
                cdi.PreviouslyOwned = item.PreviousOwned;
                cdi.WantToBuy       = item.WantToBuy;
                cdi.WantToPlay      = item.WantToPlay;
                cdi.Wishlist        = item.WishList;
                cdi.Rating          = item.Rating;
                cdi.AverageRating   = item.AverageRating;
                cdi.BGGRating       = item.BGGRating;
                cdi.Image           = item.Image;
                cdi.MaxPlayers      = item.MaxPlayers;
                cdi.MinPlayers      = item.MinPlayers;
                cdi.PlayingTime     = item.PlayingTime;
                cdi.IsExpansion     = item.IsExpansion;
                cdi.Rank            = item.Rank;
                cdi.UserComment     = item.UserComment;

                if (cdi.IsValidCollectionMember)
                {
                    cdi.IsCollectionItem = true;
                    if (UserCollection.Contains(cdi))
                    {
                        UserCollection.Remove(cdi);
                    }

                    UserCollection.Add(cdi);
                }
            }

            UpdateCollectionForHub();

            Messenger.Default.Send <CollectionLoadedMessage>(new CollectionLoadedMessage()
            {
                isQuick = true
            });

            LoadCollectionFully();
        }
Esempio n. 2
0
        /// <summary>
        /// Loads a game, first from cache, if not found from the BGG Service
        /// </summary>
        /// <param name="GameId"></param>
        /// <param name="ForceReload"></param>
        /// <returns></returns>
        public async Task <BoardGameDataItem> LoadGame(int GameId, bool ForceReload = false)
        {
            BoardGameDataItem bgdi = BoardGameStorage.LoadGame(GameId);

            // If Force reload, the item should be removed from the storage and fetched anew.
            if (bgdi != null)
            {
                if (ForceReload)
                {
                    BoardGameStorage.RemoveGame(bgdi);
                    bgdi = null;
                }
                else if (bgdi.DataVersion < BoardGameDataItem.CurrentDataVersion)
                {
                    BoardGameStorage.RemoveGame(bgdi);
                    bgdi = null;
                }
            }

            if (bgdi == null || !bgdi.IsFullyLoaded)
            {
                Boardgame game = await Client.LoadGame(GameId);

                if (game != null)
                {
                    #region Filling values
                    if (bgdi == null)
                    {
                        bgdi = new BoardGameDataItem();
                        BoardGameStorage.AddGame(bgdi);
                    }
                    else
                    {
                        bgdi.DisableUpdate = true;
                    }

                    bgdi.Description   = WebUtility.HtmlDecode(game.Description);
                    bgdi.GameId        = game.GameId;
                    bgdi.Image         = game.Image;
                    bgdi.MaxPlayers    = game.MaxPlayers;
                    bgdi.MinPlayers    = game.MinPlayers;
                    bgdi.Name          = game.Name;
                    bgdi.Thumbnail     = game.Thumbnail;
                    bgdi.YearPublished = game.YearPublished;
                    bgdi.PlayingTime   = game.PlayingTime;
                    bgdi.AverageRating = game.AverageRating;
                    bgdi.Rank          = game.Rank;
                    bgdi.BGGRating     = game.BGGRating;
                    bgdi.FetchDate     = DateTime.Now;
                    bgdi.IsExpansion   = game.IsExpansion;
                    bgdi.TotalComments = game.TotalComments;
                    bgdi.IsFullyLoaded = true;

                    foreach (string publisher in game.Publishers)
                    {
                        bgdi.Publishers.Add(publisher);
                    }
                    foreach (string designer in game.Designers)
                    {
                        bgdi.Designers.Add(designer);
                    }
                    foreach (string artist in game.Artists)
                    {
                        bgdi.Artists.Add(artist);
                    }

                    foreach (Comment comment in game.Comments.OrderByDescending(x => x.Text.Length))
                    {
                        bgdi.Comments.Add(new CommentDataItem()
                        {
                            Rating   = comment.Rating,
                            Text     = comment.Text,
                            Username = comment.Username
                        });
                    }

                    foreach (PlayerPollResult result in game.PlayerPollResults.OrderBy(x => x.NumPlayers + (x.NumPlayersIsAndHigher ? 1 : 0))) // add one to 4+ , making it 5 and the highest
                    {
                        bgdi.PlayerPollResults.Add(new PlayerPollResultDataItem()
                        {
                            Best                  = result.Best,
                            NumPlayers            = result.NumPlayers,
                            NumPlayersIsAndHigher = result.NumPlayersIsAndHigher,
                            NotRecommended        = result.NotRecommended,
                            Recommended           = result.Recommended
                        });
                    }

                    //if (BoardGameStorage.LoadGame(GameId) == null) // a different thread could have inserted the game by now!


                    bgdi.DisableUpdate = false;
                    #endregion
                }
                else
                {
                    return(null);
                }
            }
            return(bgdi);
        }