我尝试寻找适用于此任务的合适C# SDK,但遗憾的是,我没有成功识别出应该使用的SDK。您能帮我找到正确的SDK来解决这个问题吗?
您可以使用 Azure.Data.AppConfiguration 包通过.NET代码更新Azure应用配置过滤器。
代码示例:
using Azure.Data.AppConfiguration;
using System;
using System.Collections.Generic;
var connectionString = "你的连接字符串";
var featureFlag = "featureA";
var filterName = "Microsoft.Targeting";
KeyValuePair<string, object>[] keyValuePairs = new KeyValuePair<string, object>[]
{
new KeyValuePair<string, object>("DefaultRolloutPercentage", 50),
new KeyValuePair<string, object>("Users", new string[] { "user1", "user2" }),
new KeyValuePair<string, object>("Groups", new object[] { })
};
IDictionary<string, object> dictionary = new Dictionary<string, object>();
dictionary.Add("Audience", new Dictionary<string, object>());
foreach (var kvp in keyValuePairs)
{
((Dictionary<string, object>)dictionary["Audience"]).Add(kvp.Key, kvp.Value);
}
var client = new ConfigurationClient(connectionString);
var featureFlagSetting = new FeatureFlagConfigurationSetting(featureFlag, isEnabled: true);
var featureflagfilter = new FeatureFlagFilter(filterName, dictionary);
featureFlagSetting.ClientFilters.Add(featureflagfilter);
client.SetConfigurationSetting(featureFlagSetting);
以上代码通过指定的连接字符串,在Azure应用配置中设置了一个名为 featureA
的功能标志,并应用了受众定向过滤器。它定义了如 DefaultRolloutPercentage
、用户列表
和 组
等过滤条件,并在应用配置存储中更新了配置。
参考文档:
类 FeatureFlagFilter | Azure SDK for .NET (windows.net)