Share via


資料流程元件的設計階段方法

適用於:SQL Server Azure Data Factory 中的 SSIS Integration Runtime

據說在執行之前,資料流程工作會設計狀態階段進行累加變更。 變更可包括元件的加入或移除、連接元件的路徑物件之加入或移除,以及對於元件中繼資料的變更。 當中繼資料變更發生時,元件可以監視變更並對其做出反應。 例如,元件可以不允許某些變更,或是做其他變更以回應變更。 在設計階段,設計工具會透過設計階段 IDTSDesigntimeComponent100 介面與元件互動。

設計階段實作

元件的設計階段介面是由 IDTSDesigntimeComponent100 介面所描述。 雖然您未明確地實作這個介面,不過熟悉定義在這個介面中的方法,將可協助您了解 PipelineComponent 基底類別的哪些方法與元件的設計階段執行個體對應。

在 SQL Server Data Tools (SSDT) 中載入元件時,會具現化元件的設計階段執行個體,並在編輯元件時,呼叫 IDTSDesigntimeComponent100 介面的方法。 基底類別的實作可讓您只覆寫元件所需的方法。 在許多情況下,您可以覆寫這些方法以防止對元件的不當編輯。 例如,若要防止使用者將輸出加入元件,請覆寫 InsertOutput 方法。 否則,呼叫由基底類別實作的此方法時,它會將輸出加入元件。

不論元件的目的或功能為何,您都應該覆寫 ProvideComponentPropertiesValidateReinitializeMetaData 方法。 如需 ValidateReinitializeMetaData 的詳細資訊,請參閱驗證資料流程元件

提供 ComponentProperties 方法

元件的初始化會發生在 ProvideComponentProperties 方法中。 當元件新增至資料流程工作時,SSIS 設計師會呼叫這個方法,此方法類似類別建構函式。 元件開發人員應該在此方法呼叫期間,建立並初始化輸入、輸出和自訂屬性。 ProvideComponentProperties 方法與建構函式不同,因為它並不會在每次具現化元件的設計階段執行個體或是執行階段執行個體時呼叫。

該方法的基底類別實作會將輸入和輸出加入元件,並將輸入的識別碼指派到 SynchronousInputID 屬性。 不過,在 SQL Server 中,並未命名基底類別新增的輸入和輸出物件。 如果封裝包含的元件所帶有的輸入或輸出物件未設定 Name 屬性,封裝將無法成功載入。 因此,當您使用基底實作時,必須將值明確地指派到預設輸入與輸出的 Name 屬性。

public override void ProvideComponentProperties()  
{  
    /// TODO: Reset the component.  
    /// TODO: Add custom properties.  
    /// TODO: Add input objects.  
    /// TODO: Add output objects.  
}  
Public Overrides Sub ProvideComponentProperties()  
    ' TODO: Reset the component.  
    ' TODO: Add custom properties.  
    ' TODO: Add input objects.  
    ' TODO: Add output objects.  
End Sub  

建立自訂屬性

在呼叫 ProvideComponentProperties 方法時,元件開發人員應該將自訂屬性 (IDTSCustomProperty100) 加入元件。 自訂屬性沒有資料類型屬性。 自訂屬性的資料類型是由您指派至其 Value 屬性的值資料類型所設定。 不過,在您將初始值指派到自訂屬性之後,您無法以不同的資料類型指派值。

注意

IDTSCustomProperty100 介面對於 Object 類型的屬性值之支援有限。 您可以儲存為自訂屬性值的唯一物件是簡單類型的陣列,例如字串或是整數。

您可以將自訂屬性的 ExpressionType 屬性值設定成 DTSCustomPropertyExpressionType 列舉的 CPET_NOTIFY,藉此指出自訂屬性支援屬性運算式,如下列範例所示。 您不必加入任何程式碼以處理或是驗證使用者所輸入的屬性運算式。 您可以為屬性設定預設值、驗證其值,以及正常地讀取和使用其值。

IDTSCustomProperty100 myCustomProperty;  
...  
myCustomProperty.ExpressionType = DTSCustomPropertyExpressionType.CPET_NOTIFY;  
Dim myCustomProperty As IDTSCustomProperty100  
...  
myCustomProperty.ExpressionType = DTSCustomPropertyExpressionType.CPET_NOTIFY  

您可以使用 TypeConverter 屬性,來限制使用者從列舉選取自訂屬性值,如下列範例所示,其中假設您已定義名為 MyValidValues 的公用列舉。

IDTSCustomProperty100 customProperty = outputColumn.CustomPropertyCollection.New();  
customProperty.Name = "My Custom Property";  
// This line associates the type with the custom property.  
customProperty.TypeConverter = typeof(MyValidValues).AssemblyQualifiedName;  
// Now you can use the enumeration values directly.  
customProperty.Value = MyValidValues.ValueOne;    
Dim customProperty As IDTSCustomProperty100 = outputColumn.CustomPropertyCollection.New   
customProperty.Name = "My Custom Property"   
' This line associates the type with the custom property.  
customProperty.TypeConverter = GetType(MyValidValues).AssemblyQualifiedName   
' Now you can use the enumeration values directly.  
customProperty.Value = MyValidValues.ValueOne  

如需詳細資訊,請參閱 MSDN Library 中的<通用類型轉換>與<實作類型轉換子>。

您可以使用 UITypeEditor 屬性,為自訂屬性值指定自訂編輯器對話方塊,如下列範例所示。 首先,如果您找不到符合需求的現有 UI 類型編輯器類別,您必須建立一個繼承自 System.Drawing.Design.UITypeEditor 的自訂類型編輯器。

public class MyCustomTypeEditor : UITypeEditor  
{  
...  
}  
Public Class MyCustomTypeEditor  
  Inherits UITypeEditor   
  ...  
End Class  

接著將此類別指定為自訂屬性的 UITypeEditor 屬性值。

IDTSCustomProperty100 customProperty = outputColumn.CustomPropertyCollection.New();  
customProperty.Name = "My Custom Property";  
// This line associates the editor with the custom property.  
customProperty.UITypeEditor = typeof(MyCustomTypeEditor).AssemblyQualifiedName;  
Dim customProperty As IDTSCustomProperty100 = outputColumn.CustomPropertyCollection.New   
customProperty.Name = "My Custom Property"   
' This line associates the editor with the custom property.  
customProperty.UITypeEditor = GetType(MyCustomTypeEditor).AssemblyQualifiedName  

如需詳細資訊,請參閱 MSDN Library 中的<實作 UI 類型編輯器>。

另請參閱

資料流程元件的執行階段方法