public IActionResult Get([FromQuery] DtoGameRequest pageRequest)

        {
            DtoGameResponse response = new DtoGameResponse();

            if (pageRequest == null)
            {
                pageRequest = new DtoGameRequest {
                    PageNumber = 1, PageSize = 5
                }
            }
            ;

            try
            {
                response = _logQuakeService.GetAll(pageRequest);
                if (response.Game == null || response.Game.Count == 0)
                {
                    _logger.LogWarning(LoggingEvents.Information, "Nada encontrado para a página {0} tamanho {1}", pageRequest.PageNumber, pageRequest.PageSize);
                    return(NotFound(response));
                }
                else
                {
                    return(Ok(response.Game));
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical(LoggingEvents.Critial, ex, "Falha ao realizar a busca pela página {0} com tamnho {1}", pageRequest.PageNumber, pageRequest.PageSize);
                response.AddNotification(Notifications.ErroInesperado, ex);
                return(BadRequest(response));
            }
        }
Exemple #2
0
        /// <summary>
        /// Busca no Banco de Dados os dados de todos os jogos, respeitando a paginação informada.
        /// </summary>
        /// <param name="pageRequest">parâmetros de paginação para buscar no Banco de Dados</param>
        public DtoGameResponse GetAll(PagingRequest pageRequest)
        {
            List <Kill> listaKill              = _unitOfWork.Kills.GetAll(pageRequest).ToList();
            Dictionary <string, Game> games    = new Dictionary <string, Game>();
            DtoGameResponse           response = new DtoGameResponse();

            if (listaKill.Count == 0)
            {
                _logger.LogWarning(LoggingEvents.Error, "GetAll página {0} com tamanho {1}", pageRequest.PageNumber, pageRequest.PageSize);
                response.AddNotification(Notifications.ItemNaoEncontrado, string.Format("Nenhum item encontrado ao buscar Game para a página {0} com tamanho {1}", pageRequest.PageNumber, pageRequest.PageSize), MethodBase.GetCurrentMethod().ToString());
                return(response);
            }

            try
            {
                ConvertKillListToGame(listaKill, games, ((pageRequest.PageNumber - 1) * pageRequest.PageSize) + 1);
            }
            catch (Exception ex)
            {
                _logger.LogCritical(LoggingEvents.Critial, "Falha ao converter lista de jogos.");
                response.AddNotification(Notifications.ErroInesperado, "Falha ao converter lista de jogos.", ex);
            }
            response.Game = games;

            return(response);
        }
        public IActionResult GetWithCacheRepository(int idGame)
        {
            DtoGameResponse response = new DtoGameResponse();

            try
            {
                response = _logQuakeService.GetCacheRepositoryById(idGame);
                if (response.Game == null || response.Game.Count == 0)
                {
                    _logger.LogWarning(LoggingEvents.Warning, "Não encontrado o item {ID}, para Cache de Repositório", idGame);
                    return(NotFound(response));
                }
                else
                {
                    _logger.LogInformation(LoggingEvents.Information, "Busca realizada com sucesso para o item {ID}, para Cache de Repositório", idGame);
                    return(Ok(response.Game));
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical(LoggingEvents.Critial, ex, "GetWithCacheRepository item {ID}", idGame);
                response.AddNotification(Notifications.ErroInesperado, ex);
                return(BadRequest(response));
            }
        }
        public IActionResult Get(int idGame)
        {
            ////conferindo se o scope é LogQuake
            //bool userHasRightScope = User.HasClaim("scope", "LogQuake");
            //if (userHasRightScope == false)
            //{
            //    throw new Exception("Invalid scope");
            //}
            ////obter as Claims associadas
            //var identity = (ClaimsIdentity)User.Identity;
            //IEnumerable<Claim> claims = identity.Claims;

            DtoGameResponse response = new DtoGameResponse();

            try
            {
                response = _logQuakeService.GetById(idGame);
                if (response.Game == null || response.Game.Count == 0)
                {
                    _logger.LogWarning(LoggingEvents.Warning, "Não encontrado o item {ID}", idGame);
                    return(NotFound(response));
                }
                else
                {
                    _logger.LogInformation(LoggingEvents.Information, "Busca realizada com sucesso para o item {ID}", idGame);
                    return(Ok(response.Game));
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical(LoggingEvents.Critial, ex, "Getting item {ID}", idGame);
                response.AddNotification(Notifications.ErroInesperado, ex);
                return(BadRequest(response));
            }
        }
Exemple #5
0
        /// <summary>
        /// Busca primeiramente no Cache de Serviço e depois no Banco de Dados os dados de um determinado Jogo.
        /// </summary>
        /// <param name="Id">Identificador do Jogo</param>
        public DtoGameResponse GetCacheById(int Id)
        {
            Dictionary <string, Game> games    = new Dictionary <string, Game>();
            DtoGameResponse           response = new DtoGameResponse();
            List <Kill> listaKill;

            try
            {
                _logger.LogInformation(LoggingEvents.Information, "Buscando no cache de Service o registro da partida {0}", Id);

                var key = $"LogQuakeService.GetCacheById{Id.ToString()}";

                if (!_cache.TryGetValue(key, out listaKill))
                {
                    lock (Cache.lockCache)                           // ensure concurrent request won't access DB at the same time
                    {
                        if (!_cache.TryGetValue(key, out listaKill)) // double-check
                        {
                            listaKill = _unitOfWork.Kills.GetByIdList(Id).ToList();
                            var minutes = _configuration.GetValue <int>("Cache:GamesController:SlidingExpiration");
                            var size    = _configuration.GetValue <int>("Cache:GamesController:Size");
                            _cache.Set(key, listaKill,
                                       new MemoryCacheEntryOptions()
                            {
                                SlidingExpiration = TimeSpan.FromMinutes(minutes), Size = size
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical(LoggingEvents.Critial, "Falha ao acessar o cache de service/banco de dados das partidas.");
                response.AddNotification(Notifications.ErroInesperado, "Falha ao acessar o banco de dados das partidas.", ex);
                return(response);
            }

            if (listaKill.Count == 0)
            {
                _logger.LogWarning(LoggingEvents.Error, "GetCacheById item {ID}", Id);
                response.AddNotification(Notifications.ItemNaoEncontrado, string.Format("Nenhum item encontrado ao buscar Game com o Id {0}", Id), MethodBase.GetCurrentMethod().ToString());
                return(response);
            }

            try
            {
                ConvertKillListToGame(listaKill, games, Id);
            }
            catch (Exception ex)
            {
                _logger.LogCritical(LoggingEvents.Critial, ex, "GetCacheById item {ID}", Id);
                response.AddNotification(Notifications.ErroInesperado, "GetCacheById - Falha ao converter lista de jogos.", ex);
                return(response);
            }

            response.Game = games;

            return(response);
        }
Exemple #6
0
        /// <summary>
        /// Busca primeiramente no Cache de Repositório e depois no Banco de Dados os dados de um determinado Jogo.
        /// </summary>
        /// <param name="Id">Identificador do Jogo</param>
        public DtoGameResponse GetCacheRepositoryById(int Id)
        {
            Dictionary <string, Game> games    = new Dictionary <string, Game>();
            DtoGameResponse           response = new DtoGameResponse();
            List <Kill> listaKill;

            try
            {
                _logger.LogInformation(LoggingEvents.Information, "Buscando o registro da partida {0}", Id);
                var key = $"KillRepository.FindByCached{Id.ToString()}";
                //Func<Kill, bool> predicate = item => item.IdGame == Id;
                bool predicate(Kill item) => item.IdGame == Id;

                listaKill = _unitOfWork.Kills.FindByCached(predicate, key);
            }
            catch (Exception ex)
            {
                _logger.LogCritical(LoggingEvents.Critial, "Falha ao acessar o banco de dados das partidas.");
                response.AddNotification(Notifications.ErroInesperado, "Falha ao acessar o banco de dados das partidas.", ex);
                return(response);
            }

            if (listaKill.Count == 0)
            {
                _logger.LogWarning(LoggingEvents.Error, "Getting item {ID}", Id);
                response.AddNotification(Notifications.ItemNaoEncontrado, string.Format("Nenhum item encontrado ao buscar Game com o Id {0}", Id), MethodBase.GetCurrentMethod().ToString());
                return(response);
            }

            try
            {
                ConvertKillListToGame(listaKill, games, Id);
            }
            catch (Exception ex)
            {
                response.AddNotification(Notifications.ErroInesperado, "Falha ao converter lista de jogos.", ex);
                return(response);
            }

            response.Game = games;

            return(response);
        }
Exemple #7
0
        /// <summary>
        /// Busca no Banco de Dados os dados de um determinado Jogo.
        /// </summary>
        /// <param name="Id">Identificador do Jogo</param>
        public DtoGameResponse GetById(int Id)
        {
            Dictionary <string, Game> games    = new Dictionary <string, Game>();
            DtoGameResponse           response = new DtoGameResponse();
            List <Kill> listaKill;

            try
            {
                _logger.LogInformation(LoggingEvents.Information, "Buscando o registro da partida {0}", Id);
                listaKill = _unitOfWork.Kills.GetByIdList(Id).ToList();
            }
            catch (Exception ex)
            {
                _logger.LogCritical(LoggingEvents.Critial, "Falha ao acessar o banco de dados das partidas.");
                response.AddNotification(Notifications.ErroInesperado, "Falha ao acessar o banco de dados das partidas.", ex);
                return(response);
            }

            if (listaKill.Count == 0)
            {
                _logger.LogWarning(LoggingEvents.Error, "Getting item {ID}", Id);
                response.AddNotification(Notifications.ItemNaoEncontrado, string.Format("Nenhum item encontrado ao buscar Game com o Id {0}", Id), MethodBase.GetCurrentMethod().ToString());
                return(response);
            }

            try
            {
                ConvertKillListToGame(listaKill, games, Id);
            }
            catch (Exception ex)
            {
                response.AddNotification(Notifications.ErroInesperado, "Falha ao converter lista de jogos.", ex);
                return(response);
            }

            response.Game = games;

            return(response);
        }