6

How could you convert this in Azure storage v2.0 since "SetConfigurationSettingPublisher" was deleted ?

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();
      }
    }
  };
}

);

Thanks

4

1 回答 1

9

根据Windows Azure Storage Client Library 2.0 Breaking Changes & Migration Guide

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

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

var someSetting = CloudConfigurationManager.GetSetting(settingKey);

如果您需要在角色实例运行时响应配置更改,您可以订阅RoleEnvironment.ChangingRoleEnvironment.Changed事件,如Read Configuration Settings for the Storage Client Library 和 Handle Changed SettingsResponding to Role Topology Changes中所述。

于 2013-07-22T19:54:20.043 回答