예제 #1
0
    public virtual async Task <GetFeatureListResultDto> GetAsync([NotNull] string providerName, string providerKey)
    {
        await CheckProviderPolicy(providerName, providerKey);

        var result = new GetFeatureListResultDto
        {
            Groups = new List <FeatureGroupDto>()
        };

        foreach (var group in FeatureDefinitionManager.GetGroups())
        {
            var groupDto = new FeatureGroupDto
            {
                Name        = group.Name,
                DisplayName = group.DisplayName.Localize(StringLocalizerFactory),
                Features    = new List <FeatureDto>()
            };

            foreach (var featureDefinition in group.GetFeaturesWithChildren())
            {
                if (providerName == TenantFeatureValueProvider.ProviderName &&
                    CurrentTenant.Id == null &&
                    providerKey == null &&
                    !featureDefinition.IsAvailableToHost)
                {
                    continue;
                }

                var feature = await FeatureManager.GetOrNullWithProviderAsync(featureDefinition.Name, providerName, providerKey);

                groupDto.Features.Add(new FeatureDto
                {
                    Name        = featureDefinition.Name,
                    DisplayName = featureDefinition.DisplayName?.Localize(StringLocalizerFactory),
                    ValueType   = featureDefinition.ValueType,
                    Description = featureDefinition.Description?.Localize(StringLocalizerFactory),
                    ParentName  = featureDefinition.Parent?.Name,
                    Value       = feature.Value,
                    Provider    = new FeatureProviderDto
                    {
                        Name = feature.Provider?.Name,
                        Key  = feature.Provider?.Key
                    }
                });
            }

            SetFeatureDepth(groupDto.Features, providerName, providerKey);

            if (groupDto.Features.Any())
            {
                result.Groups.Add(groupDto);
            }
        }

        return(result);
    }