Meningkatkan Versi Komponen Aliran Data

Berlaku untuk: SQL Server SSIS Integration Runtime di Azure Data Factory

Paket yang dibuat dengan versi lama komponen Anda mungkin berisi metadata yang tidak lagi valid, seperti properti kustom yang penggunaannya telah dimodifikasi dalam versi komponen yang lebih baru. Anda dapat mengambil PerformUpgrade alih metode PipelineComponent kelas dasar untuk memperbarui metadata yang sebelumnya disimpan dalam paket yang lebih lama untuk mencerminkan properti komponen Anda saat ini.

Catatan

Saat Anda mengkombinasi ulang komponen kustom untuk versi baru Integration Services, Anda tidak perlu mengubah nilai CurrentVersion properti jika properti komponen tidak berubah.

Contoh

Sampel berikut berisi kode dari komponen aliran data fiktif versi 2.0. Nomor versi baru ditentukan dalam CurrentVersion properti .DtsPipelineComponentAttribute Komponen memiliki properti yang menentukan bagaimana nilai numerik yang melebihi ambang batas akan ditangani. Dalam versi 1.0 dari komponen fiktif, properti ini diberi nama RaiseErrorOnInvalidValue dan menerima nilai Boolean true atau false. Dalam versi 2.0 dari komponen fiktif, properti telah diganti namanya menjadi InvalidValueHandling dan menerima salah satu dari empat nilai yang mungkin dari enumerasi kustom.

Metode yang ditimpa PerformUpgrade dalam sampel berikut melakukan tindakan berikut:

  • Mendapatkan versi komponen saat ini.

  • Mendapatkan nilai properti kustom lama.

  • Menghapus properti lama dari kumpulan properti kustom.

  • Mengatur nilai properti kustom baru berdasarkan nilai properti lama, jika memungkinkan.

  • Mengatur metadata versi ke versi komponen saat ini.

Catatan

Mesin aliran data meneruskan nomor versinya sendiri ke dalam PerformUpgrade metode dalam parameter pipelineVersion . Parameter ini tidak berguna dalam Layanan Integrasi versi 1.0, tetapi mungkin berguna dalam versi berikutnya.

Kode sampel hanya menggunakan dua nilai enumerasi yang memetakan langsung ke nilai Boolean sebelumnya untuk properti kustom. Pengguna dapat memilih nilai enumerasi lain yang tersedia melalui antarmuka pengguna kustom komponen, di Editor Lanjutan, atau secara terprogram. Untuk informasi tentang menampilkan nilai enumerasi untuk properti kustom di Editor Lanjutan, lihat "Membuat Properti Kustom" dalam Metode Waktu Desain Komponen Aliran Data.

Imports Microsoft.SqlServer.Dts.Pipeline  
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper  
  
<DtsPipelineComponent(ComponentType:=ComponentType.Transform, CurrentVersion:=2)> _  
Public Class PerformUpgrade  
  Inherits PipelineComponent  
  
  ' Define the set of possible values for the new custom property.  
  Private Enum InvalidValueHandling  
    Ignore  
    FireInformation  
    FireWarning  
    FireError  
  End Enum  
  
  Public Overloads Overrides Sub PerformUpgrade(ByVal pipelineVersion As Integer)  
  
    ' Obtain the current component version from the attribute.  
    Dim componentAttribute As DtsPipelineComponentAttribute = _  
      CType(Attribute.GetCustomAttribute(Me.GetType, _  
      GetType(DtsPipelineComponentAttribute), False), _  
      DtsPipelineComponentAttribute)  
    Dim currentVersion As Integer = componentAttribute.CurrentVersion  
  
    ' If the component version saved in the package is less than  
    '  the current version, Version 2, perform the upgrade.  
    If ComponentMetaData.Version < currentVersion Then  
  
      ' Get the current value of the old custom property, RaiseErrorOnInvalidValue,   
      ' and then remove the property from the custom property collection.  
      Dim oldValue As Boolean = False  
      Try  
        Dim oldProperty As IDTSCustomProperty100 = _  
          ComponentMetaData.CustomPropertyCollection("RaiseErrorOnInvalidValue")  
        oldValue = CType(oldProperty.Value, Boolean)  
        ComponentMetaData.CustomPropertyCollection.RemoveObjectByIndex("RaiseErrorOnInvalidValue")  
      Catch ex As Exception  
        ' If the old custom property is not available, ignore the error.  
      End Try  
  
      ' Set the value of the new custom property, InvalidValueHandling,  
      '  by using the appropriate enumeration value.  
      Dim newProperty As IDTSCustomProperty100 = _  
        ComponentMetaData.CustomPropertyCollection("InvalidValueHandling")  
      If oldValue = True Then  
        newProperty.Value = InvalidValueHandling.FireError  
      Else  
        newProperty.Value = InvalidValueHandling.Ignore  
      End If  
  
    End If  
  
    ' Update the saved component version metadata to the current version.  
    ComponentMetaData.Version = currentVersion  
  
  End Sub  
  
End Class  
using System;  
using Microsoft.SqlServer.Dts.Pipeline;  
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;  
  
[DtsPipelineComponent(ComponentType = ComponentType.Transform, CurrentVersion = 2)]  
public class PerformUpgradeCS :  
  PipelineComponent  
  
  // Define the set of possible values for the new custom property.  
{  
  private enum InvalidValueHandling  
  {  
    Ignore,  
    FireInformation,  
    FireWarning,  
    FireError  
  };  
  
  public override void PerformUpgrade(int pipelineVersion)  
  {  
  
    // Obtain the current component version from the attribute.  
    DtsPipelineComponentAttribute componentAttribute =   
      (DtsPipelineComponentAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(DtsPipelineComponentAttribute), false);  
    int currentVersion = componentAttribute.CurrentVersion;  
  
    // If the component version saved in the package is less than  
    //  the current version, Version 2, perform the upgrade.  
    if (ComponentMetaData.Version < currentVersion)  
  
    // Get the current value of the old custom property, RaiseErrorOnInvalidValue,   
    // and then remove the property from the custom property collection.  
    {  
      bool oldValue = false;  
      try  
      {  
        IDTSCustomProperty100 oldProperty =   
          ComponentMetaData.CustomPropertyCollection["RaiseErrorOnInvalidValue"];  
        oldValue = (bool)oldProperty.Value;  
        ComponentMetaData.CustomPropertyCollection.RemoveObjectByIndex("RaiseErrorOnInvalidValue");  
      }  
      catch (Exception ex)  
      {  
        // If the old custom property is not available, ignore the error.  
      }  
  
      // Set the value of the new custom property, InvalidValueHandling,  
      //  by using the appropriate enumeration value.  
      IDTSCustomProperty100 newProperty =   
         ComponentMetaData.CustomPropertyCollection["InvalidValueHandling"];  
      if (oldValue == true)  
      {  
        newProperty.Value = InvalidValueHandling.FireError;  
      }  
      else  
      {  
        newProperty.Value = InvalidValueHandling.Ignore;  
      }  
  
    }  
  
    // Update the saved component version metadata to the current version.  
    ComponentMetaData.Version = currentVersion;  
  
  }  
  
}