In DTS development record (2) -- Data Pipeline and plug-in, we introduced the data pipeline. The CreateDataPipe method of IDataPipeFactory requires an IConnection parameter, which indicates a connection.
Public IDataPipe CreateDataPipe (IConnection conn)
IConnection is defined as follows:
/// <Summary>
/// IConnection indicates the connection to the data source or data target.
/// </Summary>
Public interface IConnection
{
ConnectionType {get ;}
String ConnectionText {get ;}
String PKeyName {get; set ;}
}
Public enum ConnectionType
{
DataBase, File
}
Whether the connection is directed to a database table or a structured file, you must set a primary key name. The function of setting the primary key name is in two aspects:
(1) used for paging (some databases may do not need to know the primary key for paging, such as Oracle)
(2) used for incremental export.
Up to now, there are two types of connections: Database Type and file type. You can use a connection string to mark database-type connections. You can use a file path to mark file-type connections.
We know that databases are divided into different types, which are marked by DataBaseType. files also have different types, such as. Xml and. Txt. How can we differentiate them? Yes. Use the file extension because the file extension of the same type is the same. Therefore, we can see that FileConnection has an ExtendName attribute.
The ConnectionText attribute is the same as the ToString () method. In this way, when we need to display IConnection on the UI, we can use the ConnectionText attribute value. For file-type connections, it returns the file path; for database-type connections, it returns the connection string and the name of the target data table.
The following is a class diagram of FileConnection and DatabaseConnection:
Here, I can talk about the process of creating a data pipeline in IDataPipeFactory. First, obtain ConnectionType from IConnection. If it is a file type, convert it down to FileConnection and obtain the ExtendName attribute, finally, find the data pipeline plug-in that supports the ExtendName in the data pipeline plug-in list. For database-type IConnection, the process is similar, except that it is based on DataBaseType to find the corresponding data pipeline plug-in.
If you compare it with the data pipeline plug-in, you will be more clear:
A connection pair contains the connection information of a data source and a data target. The advantage of separating connections is that when a connection pair is configured, it can be reused in different places, for example, when editing the ing, during data verification, and during data transmission.
Using ConnectionPair can make our program structure very clear, because it abstracts the underlying connection type. However, it is not that easy to configure ConnectionPair through the interface. You may encounter many downward conversions as a last resort. I am thinking about a solution to avoid this downward conversion. Do you have a good idea?
Go to: DTS development records (sequence)