Esempio n. 1
0
 private static void AddPercentageFilterSettings(Feature feature,
                                                 ICollection <FeatureFilterConfiguration> enabledFor)
 {
     enabledFor.Add(new FeatureFilterConfiguration
     {
         Name       = "Percentage",
         Parameters = new PercentageFilterSettings
         {
             Value = feature.RolloutPercentage.Percentage
         }
     });
 }
Esempio n. 2
0
 private static void AddTimeWindowFilterSettings(Feature feature,
                                                 ICollection <FeatureFilterConfiguration> enabledFor)
 {
     enabledFor.Add(new FeatureFilterConfiguration
     {
         Name       = "TimeWindow",
         Parameters = new TimeWindowFilterSettings
         {
             Start = feature.TimeWindow.Start,
             End   = feature.TimeWindow.End
         }
     });
 }
Esempio n. 3
0
        private static FeatureDefinition ReadFeatureDefinition(Feature feature)
        {
            var enabledFor = new List <FeatureFilterConfiguration>();

            if (feature.AlwaysOn ?? false)
            {
                enabledFor.Add(new FeatureFilterConfiguration
                {
                    Name = "AlwaysOn"
                });
            }
            else if ((feature.AlwaysOff ?? false) || !(feature.IsEnabled ?? false))
            {
                enabledFor.Add(new FeatureFilterConfiguration
                {
                    Name = "AlwaysOff"
                });
            }
            else
            {
                if (feature.BrowserRestrictions.Any(br => br.IsActive ?? false))
                {
                    AddBrowserRestrictionFilterSettings(feature, enabledFor);
                }

                if (feature.TimeWindow?.IsActive == true)
                {
                    AddTimeWindowFilterSettings(feature, enabledFor);
                }

                if (feature.RolloutPercentage?.IsActive == true)
                {
                    AddPercentageFilterSettings(feature, enabledFor);
                }

                //Aka Targeting
                if (feature.Audience?.IsActive == true)
                {
                    AddAudienceFilterSetting(feature, enabledFor);
                }
            }

            return(new FeatureDefinition
            {
                Name = feature.Name,
                EnabledFor = enabledFor
            });
        }
Esempio n. 4
0
 private static void AddBrowserRestrictionFilterSettings(Feature feature,
                                                         ICollection <FeatureFilterConfiguration> enabledFor)
 {
     enabledFor.Add(new FeatureFilterConfiguration
     {
         Name       = "Browser",
         Parameters = new BrowserFilterSettings
         {
             AllowedBrowsers = feature.BrowserRestrictions
                               .Where(b => b.IsActive ?? false)
                               .Select(b =>
                                       b.SupportedBrowserId != null
                         ? ((SupportedBrowserId)b.SupportedBrowserId).ToString()
                         : null)
                               .ToList()
         }
     });
 }
Esempio n. 5
0
 private static void AddAudienceFilterSetting(Feature feature,
                                              ICollection <FeatureFilterConfiguration> enabledFor)
 {
     enabledFor.Add(new FeatureFilterConfiguration
     {
         Name       = "Targeting",
         Parameters = new TargetingFilterSettings
         {
             Audience = new Microsoft.FeatureManagement.FeatureFilters.Audience
             {
                 Users  = feature.Audience.Users?.Select(u => u.UserName).ToList(),
                 Groups = feature.Audience.GroupRollouts?
                          .Select(g => new Microsoft.FeatureManagement.FeatureFilters.GroupRollout
                 {
                     Name = g.Name,
                     RolloutPercentage = g.RolloutPercentage
                 }).ToList(),
                 DefaultRolloutPercentage = feature.Audience.DefaultRolloutPercentage
             }
         }
     });
 }