Automasikan Pengambilan Nombor Versi daripada Fail .Dtsx
Pengenalan:
Pengambilan semula pakej secara manual versi untuk banyak fail SSIS boleh membosankan. Artikel ini menyediakan pelbagai pendekatan untuk mengautomasikan proses ini.
Menggunakan Pembolehubah Sistem dalam Pakej SSIS:
Akses pembolehubah sistem SSIS dalam pakej untuk mendapatkan semula versi maklumat:
Mendapatkan Versi daripada Fail .dtsx:
Hilangkan fail dtsx sebagai XML/Teks:
Gunakan Regex:
Gunakan XML Penghurai:
Mengambil Maklumat daripada Fail .dtsx Tersimpan dalam Sql Pelayan:
Rujuk pautan berikut untuk pertanyaan:
Mengekstrak Data daripada .dtsx Fail Tidak Disimpan dalam Pelayan Sql:
Contoh Kod Menggunakan Regex:
Public Sub ReadPackagesInfo(ByVal strDirectory As String) ' Initialize a list to store package information m_lst.Clear() Dim strPackageFormatVersion As String = "" Dim strCreationDate As String = "" ' ... (Additional property variables) For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories) ' Read the file contents Dim strContent As String = "" Using sr As New IO.StreamReader(strFile) strContent = sr.ReadToEnd sr.Close() End Using ' Use Regex to extract package version and other properties strPackageFormatVersion = Regex.Match(strContent, "(?<=""PackageFormatVersion"">)(.*)(?=</DTS:Property>)", RegexOptions.Singleline).Value ' ... (Additional regex patterns for other properties) ' Add package information to the list m_lst.Add(New PackageInfo With { .PackageFileName = strFile, .PackageFormatVersion = strPackageFormatVersion, ' ... (Additional properties) }) Next End Sub
Contoh Kod Menggunakan Penghurai Xml:
Public Sub ReadPackagesInfoUsingXmlParser(ByVal strDirectory As String) ' Initialize a list to store package information m_lst.Clear() Dim strPackageFormatVersion As String = "" Dim strCreationDate As String = "" ' ... (Additional property variables) For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories) ' Load the file as XML document Dim xml = XDocument.Load(strFile) ' Create a namespace manager Dim ns As XNamespace = "www.microsoft.com/SqlServer/Dts" Dim man As XmlNamespaceManager = New XmlNamespaceManager(New NameTable()) man.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts") If Not xml.Root Is Nothing AndAlso Not xml.Root.Descendants(ns + "Property").Attributes(ns + "Name") Is Nothing AndAlso xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").Count > 0 Then ' Extract package version and other properties using XPaths strPackageFormatVersion = xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").FirstOrDefault.Parent.Value ' ... (Additional property extraction using XPaths) End If ' Add package information to the list m_lst.Add(New PackageInfo With { .PackageFileName = strFile, .PackageFormatVersion = strPackageFormatVersion, ' ... (Additional properties) }) Next End Sub
Atas ialah kandungan terperinci Bagaimanakah Saya Boleh Mengautomasikan Pengambilan Nombor Versi daripada Berbilang Fail .dtsx?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!