自从“SetConfigurationSettingPublisher”被删除后,你怎么能在Azure存储v2.0中转换它?
CloudStorageAccount.SetConfigurationSettingPublisher(
( configName, configSetter ) =>
{
// Provide the configSetter with the initial value
configSetter( RoleEnvironment.GetConfigurationSettingValue( configName ) );
RoleEnvironment.Changed += ( sender, arg ) =>
{
if( arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>( ).Any( (change) =>
( change.ConfigurationSettingName == configName ) ) )
{
// The corresponding configuration setting has changed, so propagate the value
if( !configSetter( RoleEnvironment.GetConfigurationSettingValue( configName ) ) )
{
// In this case, the change to the storage account credentials in the
// service configuration is significant enough that the role needs to be
// recycled in order to use the latest settings (for example, the
// endpoint may have changed)
RoleEnvironment.RequestRecycle();
}
}
};
}
);
由于
答案 0 :(得分:9)
根据Windows Azure Storage Client Library 2.0 Breaking Changes & Migration Guide:
CloudStorageAccount.SetConfigurationSettingPublisher已被删除。相反,StorageCredentials的成员现在是可变的,允许用户通过简单地通过提供的UpdateKey方法改变与给定客户端相关联的StorageCredentials实例,以更简化的方式完成类似的场景。
根据您的应用程序的要求,您可以直接使用CloudConfigurationManager.GetSetting()
方法,如Upgrading to Azure Storage Client 2.0中所述:
var someSetting = CloudConfigurationManager.GetSetting(settingKey);
如果您需要在角色实例运行时响应配置更改,则可以按RoleEnvironment.Changing
和RoleEnvironment.Changed
中所述订阅Read Configuration Settings for the Storage Client Library and Handle Changed Settings和Responding to Role Topology Changes个事件。