コード例 #1
0
        public async Task <Models.ApiResource> FindApiResourceAsync(string name)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    throw new ArgumentException(
                              "name can't be null or whitespace in FindApiResourceAsync");
                }

                var ncacheApiResource =
                    await _apiRepository.GetSingleAsync($"{name}");

                var model = ncacheApiResource.ToModel();

                if (_isDebugLoggingEnabled)
                {
                    if (model == null)
                    {
                        _logger.LogDebug(
                            "Did not find {api} API resource in NCache", name);
                    }
                    else
                    {
                        _logger.LogDebug(
                            "Found {api} API resource in NCache", name);
                    }
                }

                return(model);
            }
            catch (Exception ex)
            {
                if (_isErrorLoggingEnabled)
                {
                    _logger.LogError(
                        ex,
                        $"Something went wrong with FindApiResourceAsync " +
                        $"for {name}");
                }

                throw;
            }
        }
コード例 #2
0
        public async Task <Models.Client> FindClientByIdAsync(string clientId)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(clientId))
                {
                    throw new ArgumentNullException(
                              "client Id can't be null or white space");
                }

                var ncacheClient =
                    await _repository.GetSingleAsync($"{clientId}");

                if (ncacheClient == null)
                {
                    if (_isErrorLoggingEnabled)
                    {
                        _logger.LogError($"Client with ID {clientId} not found");
                    }
                    return(null);
                }

                if (_isDebugLoggingEnabled)
                {
                    _logger.LogDebug($"Client with ID {clientId} found");
                }
                return(ncacheClient.ToModel());
            }
            catch (Exception ex)
            {
                if (_isErrorLoggingEnabled)
                {
                    _logger.LogError(
                        ex,
                        $"Something went wrong with FindClientByIdAsync " +
                        $"for client id {clientId}");
                }
                throw;
            }
        }