Azure存储sdk v1.3到v2 => SetConfigurationSettingPublisher

Rap*_*aph 6 .net azure azure-storage

你怎么能在Azure存储v2.0中转换它,因为"SetConfigurationSettingPublisher"被删除了?

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();
      }
    }
  };
}
Run Code Online (Sandbox Code Playgroud)

);

谢谢

Fer*_*eia 9

根据Windows Azure存储客户端库2.0重大更改和迁移指南:

CloudStorageAccount.SetConfigurationSettingPublisher已被删除.相反,StorageCredentials的成员现在是可变的,允许用户通过简单地通过提供的UpdateKey方法改变与给定客户端相关联的StorageCredentials实例,以更加简化的方式完成类似的场景.

根据应用程序的要求,您可以直接使用该CloudConfigurationManager.GetSetting()方法,如升级到Azure Storage Client 2.0中所述:

var someSetting = CloudConfigurationManager.GetSetting(settingKey);
Run Code Online (Sandbox Code Playgroud)

如果在角色实例运行时需要响应配置更改,则可以按照读取存储客户端库的配置设置和处理更改的设置以及响应角色拓扑更改中的说明订阅RoleEnvironment.ChangingRoleEnvironment.Changed事件.