Пример #1
0
        public async Task <List <FeatureNameValueWithGrantedProvider> > GetAllWithProviderAsync(string providerName,
                                                                                                string providerKey, bool fallback = true)
        {
            Check.NotNull(providerName, nameof(providerName));

            var featureDefinitions = FeatureDefinitionManager.GetAll();
            var providers          = Enumerable.Reverse(Providers)
                                     .SkipWhile(c => c.Name != providerName);

            if (!fallback)
            {
                providers = providers.TakeWhile(c => c.Name == providerName);
            }

            var providerList = providers.Reverse().ToList();

            if (!providerList.Any())
            {
                return(new List <FeatureNameValueWithGrantedProvider>());
            }

            var featureValues = new Dictionary <string, FeatureNameValueWithGrantedProvider>();

            foreach (var feature in featureDefinitions)
            {
                var featureNameValueWithGrantedProvider = new FeatureNameValueWithGrantedProvider(feature.Name, null);
                foreach (var provider in providerList)
                {
                    string pk = null;
                    if (provider.Compatible(providerName))
                    {
                        pk = providerKey;
                    }

                    var value = await provider.GetOrNullAsync(feature, pk);

                    if (value != null)
                    {
                        featureNameValueWithGrantedProvider.Value    = value;
                        featureNameValueWithGrantedProvider.Provider = new FeatureValueProviderInfo(provider.Name, pk);
                        break;
                    }
                }

                if (featureNameValueWithGrantedProvider.Value != null)
                {
                    featureValues[feature.Name] = featureNameValueWithGrantedProvider;
                }
            }

            return(featureValues.Values.ToList());
        }
Пример #2
0
        protected virtual async Task <FeatureNameValueWithGrantedProvider> GetOrNullInternalAsync(
            string name,
            string providerName,
            string providerKey,
            bool fallback = true) //TODO: Fallback is not used
        {
            var feature   = FeatureDefinitionManager.Get(name);
            var providers = Enumerable
                            .Reverse(Providers);

            if (providerName != null)
            {
                providers = providers.SkipWhile(c => c.Name != providerName);
            }

            var featureNameValueWithGrantedProvider = new FeatureNameValueWithGrantedProvider(name, null);

            foreach (var provider in providers)
            {
                string pk = null;
                if (provider.Compatible(providerName))
                {
                    pk = providerKey;
                }

                var value = await provider.GetOrNullAsync(feature, pk);

                if (value != null)
                {
                    featureNameValueWithGrantedProvider.Value    = value;
                    featureNameValueWithGrantedProvider.Provider = new FeatureValueProviderInfo(provider.Name, pk);
                    break;
                }
            }

            return(featureNameValueWithGrantedProvider);
        }