2013-07-22 21 views
6

Làm thế nào bạn có thể chuyển đổi điều này trong Azure lưu trữ v2.0 vì "SetConfigurationSettingPublisher" đã bị xóa?Azure sdk lưu trữ v1.3 để v2 => 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(); 
     } 
    } 
    }; 
} 

);

Cảm ơn

Trả lời

9

Theo Windows Azure Storage Client Library 2.0 Breaking Changes & Migration Guide:

CloudStorageAccount.SetConfigurationSettingPublisher đã bị xoá. Thay vào đó, các thành viên của StorageCredentials bây giờ có thể thay đổi cho phép người dùng thực hiện các kịch bản tương tự theo cách sắp xếp hợp lý hơn bằng cách thay đổi cá thể StorageCredentials được liên kết với một (các) ứng dụng cụ thể thông qua các phương thức UpdateKey đã cung cấp.

Tùy thuộc vào yêu cầu của ứng dụng của bạn, bạn chỉ đơn giản là có thể sử dụng phương pháp CloudConfigurationManager.GetSetting() trực tiếp, như mô tả trong Upgrading to Azure Storage Client 2.0:

var someSetting = CloudConfigurationManager.GetSetting(settingKey); 

Nếu bạn cần để đối phó với thay đổi cấu hình trong khi các trường hợp vai trò đang chạy, bạn có thể đăng ký với các sự kiện RoleEnvironment.ChangingRoleEnvironment.Changed như được mô tả trong Read Configuration Settings for the Storage Client Library and Handle Changed SettingsResponding to Role Topology Changes.

Các vấn đề liên quan