예제 #1
0
        private async Task GetBoardGames(CancellationToken token)
        {
            var listsRequest = new UserGameListsRequest
            {
                ClientId = "6XH5yEJAag",
                Username = "******"
            };

            var listsResponse = await _boardGameAtlasService.UserGameLists(listsRequest, token);

            var games = new List <BoardGameElement>();

            foreach (var list in listsResponse.Lists)
            {
                var listRequest = new GameListRequest
                {
                    ClientId = "6XH5yEJAag",
                    ListId   = list.Id
                };

                var listResponse = await _boardGameAtlasService.GameList(listRequest, token);

                games.AddRange(listResponse.Games);
            }

            BoardGameList.ItemCollection.Clear();

            AddItems(games);
        }
예제 #2
0
        public async Task <IEnumerable <BoardGameElement> > UserGameList(User user, CancellationToken token)
        {
            var request = new UserGameListsRequest
            {
                ClientId = "6XH5yEJAag",
                Username = user.Name
            };

            var listsResponse = await QueryAsync <UserGameListsResponse>(request, GameListRoute, token);

            var games = new List <BoardGameElement>();

            foreach (var list in listsResponse.Lists)
            {
                var listRequest = new GameListRequest
                {
                    ClientId = "6XH5yEJAag",
                    ListId   = list.Id
                };

                var listResponse = await QueryAsync <GameListResponse>(listRequest, SearchRoute, token);

                games.AddRange(listResponse.Games);
            }

            return(games);
        }
예제 #3
0
        public GameListResponse GetGameList(GameListRequest gamesListRequest)
        {
            string           content  = JsonConvert.SerializeObject(gamesListRequest);
            string           path     = string.Format("/gamestatistics/{0}/GameList", _vendorName);
            string           response = Post(content, path);
            GameListResponse gameConfiguratuionsResponse = JsonConvert.DeserializeObject <GameListResponse>(response);

            return(gameConfiguratuionsResponse);
        }
예제 #4
0
        protected virtual void RequestGameList()
        {
            this.Realm.WriteToLog("Requesting Game List", Color.Orange);
            GameListRequest packet = new GameListRequest(this.ReqID);

            this.Realm.SendPacket(packet);
            checked
            {
                this.ReqID += 1;
            }
        }
        /// <summary>
        /// Build Response for GameListController
        /// </summary>
        /// <param name="gameListRequestModel"></param>
        /// <param name="User"></param>
        /// <returns></returns>
        public GameListResponse GetResponse(GameListRequest gameListRequestModel,
                                            ClaimsPrincipal User)
        {
            const string ADMIN_ROLE = "Admin";

            //Get the amount of items to return to page for pagination
            var resultsPerPage = _configuration.GetValue <int>("Paging:ResultsPerPage");

            var defaultFromDate = _configuration.GetValue <string>("DefaultSearchDates:FromDate");

            var defaultToDate = _configuration.GetValue <string>("DefaultSearchDates:ToDate");

            var useTodaysDate = _configuration.GetValue <bool>("DefaultSearchDates:UseTodaysDate");

            var toDate = useTodaysDate ? DateTime.Now.ToString("dd/MM/yyyy") : defaultToDate;

            //Retrieve sorted values for view
            var consoleList = Dictionaries.ConsoleDictionary;

            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            IEnumerable <GameListModel> gameList = null;

            if (gameListRequestModel.ShowClientList)
            {
                gameList = _httpManager.GetClientResults(gameListRequestModel, userId).Result;
            }
            else
            {
                gameList = _httpManager.GetSortedResults(gameListRequestModel, userId).Result;
            }

            var currentPage = gameListRequestModel.Page ?? 1;

            //TODO: Remove page count from model
            const int PAGE_COUNT = 1000;

            // var pagedResults = gameList.ToPagedList(currentPage, resultsPerPage);

            return(new GameListResponse(gameList,
                                        User.Identity.IsAuthenticated,
                                        consoleList,
                                        User.IsInRole(ADMIN_ROLE),
                                        gameListRequestModel.SortingOptions,
                                        currentPage, PAGE_COUNT,
                                        gameListRequestModel.Platform,
                                        gameListRequestModel.SortingOptions,
                                        gameListRequestModel.ShowClientList,
                                        gameListRequestModel.ToDate ?? toDate,
                                        gameListRequestModel.FromDate ?? defaultFromDate.FromUnix(),
                                        resultsPerPage
                                        ));
        }
예제 #6
0
        /// <summary>
        /// Return a sorted list fromt the DB based on client options
        /// </summary>
        /// <param name="gameListRequestModel"></param>
        /// <returns></returns>
        public IEnumerable <GameListModel> GetFilteredResults(GameListRequest gameListRequestModel)
        {
            try
            {
                return(_httpManager.GetSortedResults(gameListRequestModel).Result);
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error retriving results from http manager");
            }

            return(null);
        }
예제 #7
0
        public IActionResult Index(GameListRequest gameListRequestModel)
        {
            // HttpManager goo = new HttpManager();
            //  goo.GetAll();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            GameListResponse response = _gameListResponseBuilder.GetResponse(gameListRequestModel, User);

            return(View(response));
        }
예제 #8
0
        public async Task <IEnumerable <GameListModel> > GetClientResults(GameListRequest gameListRequest, string userId = null)
        {
            _userId = userId;
            int resultsPerPage = int.Parse(_configuration.GetSection("Paging:ResultsPerPage").Value);

            int pageSkip = 1;

            if (gameListRequest.Page != null)
            {
                pageSkip = (int)gameListRequest.Page * resultsPerPage;
            }

            #region Setup Http client
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("user-key", "b0d327604a696f914cafb0a23d782e6f");
            #endregion

            string queryString = string.Format("https://api-endpoint.igdb.com/games/{0}?fields=cover,name,first_release_date,popularity,rating,platforms", GetUserGameList());
            var    msg         = await GetResultsFromAPI(queryString);

            IEnumerable <GameListModel> result = JsonConvert.DeserializeObject <IEnumerable <GameListModel> >(msg);

            result.ToList().ForEach(X => X.First_release_date = string.IsNullOrEmpty(X.First_release_date) ? "No Release Date Available" : DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(X.First_release_date)).ToString("dd/MM/yyyy"));

            if (gameListRequest.FromDate != null && gameListRequest.ToDate != null)
            {
                result = result.Where(x => x.First_release_date.ToDateTime().ToUnix() > gameListRequest.FromDate.ToDateTime().ToUnix() && x.First_release_date.ToDateTime().ToUnix() < gameListRequest.ToDate.ToDateTime().ToUnix());
            }

            if (!string.IsNullOrEmpty(gameListRequest.SearchText))
            {
                result = result.Where(x => x.Name.ToUpper().Contains(gameListRequest.SearchText.ToUpper()));
            }

            if (!string.IsNullOrEmpty(gameListRequest.SortingOptions))
            {
                gameListRequest.SortingOptions = gameListRequest.SortingOptions.Replace(" ", "_").ToLower();
                var sortOption = gameListRequest.Switchsort ? " descending" : "";
                result = result.AsQueryable().OrderBy(gameListRequest.SortingOptions + sortOption);
            }

            if (!string.IsNullOrEmpty(gameListRequest.Platform))
            {
                result = result.Where(x => x.Platforms.Contains(gameListRequest.Platform));
            }

            return(result.Skip(pageSkip).Take(resultsPerPage));
        }
        public void GetResponse_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var             unitUnderTest        = CreateGameListResponseBuilder();
            GameListRequest gameListRequestModel = new GameListRequest();
            ClaimsPrincipal User = new ClaimsPrincipal();

            // Act
            var result = unitUnderTest.GetResponse(
                gameListRequestModel,
                User);

            // Assert
            Assert.Fail();
        }
예제 #10
0
        public void GetFilteredResults_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var             unitUnderTest        = CreateManager();
            GameListRequest gameListRequestModel = new GameListRequest()
            {
                Platform = "Jaguar", Page = 1, SearchText = null, ShowClientList = false, SortingOptions = null, Switchsort = false
            };

            // Act
            var result = unitUnderTest.GetFilteredResults(
                gameListRequestModel);

            // Assert
            Assert.Fail();
        }
예제 #11
0
        public GameListResponse GetResponse(GameListRequest gameListRequestModel,
                                            ClaimsPrincipal User,
                                            IEnumerable <GameListModel> gameList
                                            )
        {
            var currentPage = gameListRequestModel.Page ?? 1;
            var userId      = User.FindFirstValue(ClaimTypes.NameIdentifier);

            return(new GameListResponse(gameList,
                                        User.Identity.IsAuthenticated,
                                        Dictionaries.ConsoleDictionary,
                                        User.IsInRole("Admin"),
                                        gameListRequestModel.SortingOptions,
                                        currentPage, 1000,
                                        gameListRequestModel.Platform,
                                        gameListRequestModel.SortingOptions,
                                        gameListRequestModel.ShowClientList,
                                        gameListRequestModel.FromDate,
                                        gameListRequestModel.ToDate,
                                        5
                                        ));
        }
예제 #12
0
        public async Task <IEnumerable <GameListModel> > GetSortedResults(GameListRequest gameListRequest, string userId = null)
        {
            _userId = userId;
            //TODO: Massive clean up on this method!

            #region Setup Http client
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("user-key", "b0d327604a696f914cafb0a23d782e6f");
            #endregion

            #region date filters
            var defaultFromDate = _configuration.GetSection("DefaultSearchDates:FromDate").Value.ToString();
            var defaultToDate   = _configuration.GetSection("DefaultSearchDates:ToDate").Value.ToString();
            int resultsPerPage  = int.Parse(_configuration.GetSection("Paging:ResultsPerPage").Value);
            var useTodaysDate   = bool.Parse(_configuration.GetSection("DefaultSearchDates:UseTodaysDate").Value);

            string toDate   = null;
            string fromDate = null;
            if (string.IsNullOrEmpty(gameListRequest.FromDate))
            {
                fromDate = "&filter[first_release_date][gt]=" + defaultFromDate;
            }
            else
            {
                var d = gameListRequest.FromDate.ToDateTime();
                fromDate = "&filter[first_release_date][gt]=" + d.ToUnix().ToString();
            }


            if (string.IsNullOrEmpty(gameListRequest.ToDate))
            {
                toDate = "&filter[first_release_date][lte]=" + (useTodaysDate ? DateTime.Now.ToString("dd/MM/yyyy").ToDateTime().ToUnix().ToString() : defaultToDate);
            }
            else
            {
                var d = gameListRequest.ToDate.ToDateTime();
                toDate = "&filter[first_release_date][lte]=" + d.ToUnix().ToString();
            }
            #endregion

            #region paging

            if (gameListRequest.Page != null && gameListRequest.Page > 0)
            {
                gameListRequest.Page--;
            }
            else
            {
                gameListRequest.Page = 0;
            }
            #endregion

            #region Searching
            string searchType   = string.IsNullOrEmpty(gameListRequest.Platform) ? "any" : "in";
            string searchString = string.IsNullOrEmpty(gameListRequest.SearchText) ? "" : string.Format("search={0}&", gameListRequest.SearchText);
            searchString = searchString.Replace(" ", "%20");
            #endregion

            #region Sorting and filtering

            if (!string.IsNullOrEmpty(gameListRequest.SortingOptions))
            {
                gameListRequest.SortingOptions = gameListRequest.SortingOptions.Replace(" ", "_").ToLower();
            }

            string orderOption   = gameListRequest.Switchsort ? ":asc" : ":desc";
            string orderByOption = "";
            string filterText    = "";

            if (!string.IsNullOrEmpty(gameListRequest.Platform) && gameListRequest.Platform != "Other")
            {
                filterText = string.Format("&filter[platforms][{0}]={1}", searchType, gameListRequest.Platform);
            }
            else if (gameListRequest.Platform == "Other")
            {
                filterText = string.Format("&filter[platforms][{0}]={1}", "not_in", GetConsoleListString());
            }
            else
            {
                filterText = "";
            }

            if (!string.IsNullOrEmpty(gameListRequest.SearchText) && string.IsNullOrEmpty(gameListRequest.SortingOptions))
            {
                orderByOption = "";
                orderOption   = "";
            }
            else if (string.IsNullOrEmpty(gameListRequest.SearchText) && string.IsNullOrEmpty(gameListRequest.SortingOptions))
            {
                orderByOption = "&order=popularity";
            }
            else
            {
                orderByOption = "&order=" + gameListRequest.SortingOptions;
            }

            #endregion

            string queryString = string.Format("https://api-endpoint.igdb.com/games/{7}?{4}fields=cover,name,first_release_date,popularity,rating,platforms{0}{1}&offset={2}{3}&limit={8}{5}{6}",
                                               orderByOption,
                                               orderOption,
                                               gameListRequest.Page * resultsPerPage,
                                               filterText,
                                               searchString,
                                               fromDate ?? "",
                                               toDate ?? "",
                                               gameListRequest.ShowClientList ? GetUserGameList() : "",
                                               resultsPerPage
                                               );

            //string msg = await client.GetStringAsync(queryString);
            var msg = await GetResultsFromAPI(queryString);

            IEnumerable <GameListModel> result = JsonConvert.DeserializeObject <IEnumerable <GameListModel> >(msg);

            //Convert returned Unix time stamps to date strings
            result.ToList().ForEach(X => X.First_release_date = string.IsNullOrEmpty(X.First_release_date) ? "No Release Date Available" : DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(X.First_release_date)).ToString("dd/MM/yyyy"));

            return(result);
        }
예제 #13
0
        public void GetGameList()
        {
            GameListRequest gameListRequest = new GameListRequest(curUser);

            client.Send(AbstractMessage.ToBytes(gameListRequest));
        }
예제 #14
0
 public async Task <GameListResponse> GameList(GameListRequest request, CancellationToken token)
 {
     return(await GetQueryAsync <GameListResponse>(request, SearchRoute, token));
 }