FindApiResourcesByScopeAsync(IEnumerable <string> scopeNames)
        {
            try
            {
                if (scopeNames == null)
                {
                    throw new ArgumentNullException(nameof(scopeNames));
                }

                var scopeNameList = new List <string>();

                foreach (var scopeName in scopeNames)
                {
                    scopeNameList.Add($"{scopeName}");
                }
                var ncacheApiResources =
                    new List <Entities.ApiResource>(
                        await _apiRepository.GetMultipleByTagsAsync(
                            scopeNameList));

                if (ncacheApiResources.Count == 0)
                {
                    return(new List <Models.ApiResource>());
                }

                var apiResources = ncacheApiResources.Select(x => x.ToModel());

                if (_isDebugLoggingEnabled)
                {
                    _logger.LogDebug(
                        "Found {scopes} api resources in NCache",
                        apiResources.Select(x => x.Name));
                }

                return(apiResources);
            }
            catch (Exception ex)
            {
                if (_isErrorLoggingEnabled)
                {
                    _logger.LogError(
                        ex,
                        $"Something went wrong with " +
                        $"FindApiResourcesByScopeAsync");
                }

                throw;
            }
        }
        public async Task <Resources> GetAllResourcesAsync()
        {
            try
            {
                List <Models.IdentityResource> identityResources =
                    new List <Models.IdentityResource>();
                List <Models.ApiResource> apiResources =
                    new List <Models.ApiResource>();

                var ncacheIdentityResources =
                    await _idRepository.GetMultipleByTagsAsync(
                        new string[] { "IdentityResource" }
                        );

                var ncacheApiResources =
                    await _apiRepository.GetMultipleByTagsAsync(
                        new string[] { "ApiResource" });

                if (ncacheIdentityResources.Count(x => true) > 0)
                {
                    identityResources =
                        ncacheIdentityResources
                        .ToArray()
                        .Select(x => x.ToModel()).ToList();
                }

                if (ncacheApiResources.Count(x => true) > 0)
                {
                    apiResources =
                        ncacheApiResources
                        .ToArray()
                        .Select(x => x.ToModel()).ToList();
                }

                var result = new Resources(
                    identityResources,
                    apiResources);

                if (_isDebugLoggingEnabled)
                {
                    _logger.LogDebug(
                        "Found {scopes} as all scopes in NCache",
                        result.IdentityResources.Select(x => x.Name)
                        .Union(
                            result.ApiResources
                            .SelectMany(x => x.Scopes)
                            .Select(x => x.Name)));
                }

                return(result);
            }
            catch (Exception ex)
            {
                if (_isErrorLoggingEnabled)
                {
                    _logger.LogError(
                        ex,
                        $"Something went wrong with GetAllResourcesAsync");
                }
                throw;
            }
        }