Presentation is loading. Please wait.

Presentation is loading. Please wait.

控制流程實作 胡百敬 精誠公司恆逸資訊 二○一七年三月十九日

Similar presentations


Presentation on theme: "控制流程實作 胡百敬 精誠公司恆逸資訊 二○一七年三月十九日"— Presentation transcript:

1 控制流程實作 胡百敬 精誠公司恆逸資訊 二○一七年三月十九日
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

2 大綱 控制流程概論 容器 工作 優先順序條件約束 二○一七年三月十九日
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

3 控制流程概論 封裝是由控制流程以及選擇性的一或多個資料流程所組成 控制流程由三種不同類型的元素組成: 提供封裝中的結構之容器 提供功能的工作
將容器和工作連接成順序流程的優先順序條件約束

4 大綱 容器 控制流程概論 工作 優先順序條件約束 二○一七年三月十九日
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

5 容器 提供各個工作(task)相同的基本服務,如共通的屬性設定、中斷除錯等
支援個別單一工作的 TaskHost 容器 沒有 UI 設計畫面 讓封裝設計結構化,支援封裝中的重複控制流程,且會將工作和容器分組成有意義的工作單位 For 迴圈容器 Foreach 迴圈容器 時序容器 除了包含工作外,容器還可包含其他容器

6 For 迴圈容器 Demo 透過 For 迴圈產生多個資料檔案
重複的流程。與程式語言中 For/While 迴圈的結構類似。在每次迴圈重複時,評估運算式並重複其工作流程,直到運算式評估為 False 為止。 「For 迴圈」容器使用下列元素定義迴圈: 初始化運算式(選擇性):指派初始值給迴圈計數器 評估運算式:測試迴圈應停止或繼續的運算式,如果只設定這一項,就如同 While 迴圈 反覆運算式(選擇性):累加或遞減迴圈計數器 Demo 透過 For 迴圈產生多個資料檔案

7 Demo 透過 Foreach 迴圈讀取多個資料檔案
與程式語言 Foreach 迴圈類似,使用 Foreach 列舉。以列舉的每個成員重複流程 提供下列列舉類型: Foreach ADO 、Foreach ADO.NET 結構描述資料、 Foreach 檔案、Foreach From Variable 、Foreach 項目、Foreach Nodelist、Foreach SMO 變數和屬性運算式的組合,以列舉值更新封裝物件屬性:對應至使用者定義的變數,以該變數實作屬性運算式 Demo 透過 Foreach 迴圈讀取多個資料檔案

8 時序容器 定義屬於封裝控制流程子集的控制流程。將封裝納入多個不同的控制流程中,而各流程中包含在整個封裝控制流程內執行的一或多項工作和容器: 停用工作群組,以便將封裝偵錯的焦點放在封裝控制流程的子集上。 在同一個位置藉由設定「時序容器」而非個別工作的屬性,來管理多項工作的屬性。如 Log、相關工作和容器所使用變數的範圍等。 管理交易 Demo 透過 時序容器管理交易

9 大綱 工作 概論 容器 優先順序條件約束 二○一七年三月十九日
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

10 工作類別列表(1/4) 資料流程工作:擷取資料、資料紀錄轉換,以及載入資料等
資料準備工作:複製檔案和目錄、下載檔案和資料、執行 Web 方法,以及套用作業至 XML 文件等 檔案系統工作 FTP 工作 Web 服務工作 XML 工作 指令碼工作:使用指令碼擴充封裝功能 ActiveX Script 工作 指令碼工作

11 工作類別列表(2/4) 工作流程工作:與其他程序溝通以利執行封裝、程式或批次檔,在封裝之間傳送和接收訊息、電子郵件、讀取 Windows Management Instrumentation (WMI) 資料,以及監看 WMI 事件等。 執行封裝工作 執行 DTS 2000 封裝工作 執行處理工作 訊息佇列工作 傳送郵件工作 WMI 資料讀取器工作 WMI 事件監看員工作 SQL Server 工作

12 工作類別列表(3/4) 存取、複製、插入、刪除以及修改 SQL Server 物件和資料 大量插入工作 執行 SQL 工作 傳送資料庫工作
傳送錯誤訊息工作 傳送作業工作 傳送登入工作 傳送主要預存程序工作 傳送 SQL Server 物件工作

13 工作類別列表(4/4) Analysis Services 工作:建立、修改、刪除以及處理 Analysis Services 物件
Analysis Services 執行 DDL 工作 資料採礦查詢工作 維護工作:執行管理功能如備份和壓縮 SQL Server 資料庫、重建和重新組織索引,以及執行 SQL Server Agent 諸多工作,在之後的 slide 會表列… 自訂工作:可使用支援 COM (如 Visual Basic) 或 .NET 的程式語言 (如 C#) 撰寫。如果要在 SSIS 設計師存取自訂工作,可為該工作建立及註冊使用者介面

14 指令碼工作 Demo 執行指令碼工作 使用 Visual Studio for Application/VB .Net 延伸功能
二○一七年三月十九日 指令碼工作 使用 Visual Studio for Application/VB .Net 延伸功能 可呼叫外部組件 讀取或修改封裝的屬性 無法存取某個工作或轉換的內部工作,無法修改 pipeline 的 metadata (例如:加入 pipe 的欄位數) Speaker Notes The Script Task allows you to create code and make a decision. So open the Script Task, select Script notice that the script language says Microsoft Visual Basic.NET, but that’s your only choice. Select Design Script, this opens Visual Studio for applications. The middle part of this shows you what you need to fill in, SSIS will call this method, it needs to be called Main and you need to be able to see what it’s doing. So what we have in the text file expressions is a version of the final script. So you can copy that in and replace the sub-main and sub with that script. So what this script is going to do is first of all create an internal variable named “My Variable” as a variables collection so this is for a collection of variables. In order to use a variable, you first need to lock it and put it into your list. You use a variable dispenser to do this. So first you call the variable dispenser and tell that you want to lock a variable to write the variable you want to lock is File Found and you want to put it into the list of variables that’s in My Variables. If you go into lock multiple variables either for read or for write you leave out the word One and you leave out the destination and create into your little variable dispenser a list of all the variables that you might want to use. The variable dispenser then when you say go and get the variables will try to obtain all those variables locking them for read or for write as you choose. If it is successful of getting all of the locks it will put the variables into your list of variables. Because we are only doing a single variable, we can use the shortcut version and lock one and have it put it into the variable list all at once. Notice that you don’t need to release the variables at the end you can if you choose to you can unlock. But you don’t need to do that because at the end of the sub, it will automatically release. Now once you got the variable we need to assign a value to that variable and the value of the variable is just going to use the System File IO function to check and see if a file exists. We don’t want to hard code the name of the file in so instead we will use the SSIS connection. So this is from the current SSIS Package, go look at the connections and find a connection named President’s Destination. Let’s make sure that that’s the name of the connection. It’s a little bit hard to see down there so when we are through let’s just look and see and make sure that we have a variable called President’s Destination down there. But it’s going to look for the connection named President’s Destination. Grab the connection string from that connection and use that to determine whether the file exists. In either of that, whether the file is found or not you want to return success from the task itself. If there is a serious problem you want to return failure whether the file exists or not, either one of those is a successful condition it’s only if there’s something serious that happens that you would ever get failure. So let’s close the Visual Studio for applications. And there’s the Script Task ready to run. Notice that it is President’s Destination so the name of the Connection Manager is correct. Now what we want to do is connect the Script Task with the Precedence Constraint to File Not Found. Well this will say that whenever this task completes successfully it will go around the file not found. We want that to be only if it’s successful and the result was that the file found was equal to False. So double click the connection and notice if there is a choice here that in addition to simply the success failure constraint. You can use expression and constraint. So first of all the task has to succeed and then you need an expression. So what we want the expression to be is at File Found in an expression you sign to indicate you want to use the value of the variable equal equals false. If the file is not found then we want to go and create it and incidentally create, populate the table as well. What happens if the file is found? Well because we used an expression in addition to this constraint we get a second green arrow. We can then drag this green arrow to the file found and modify its expression to be constraint plus expression but this time it will File Found equals equals True. So if the file is found then it will execute this path. Now remember the situation of looking up Precedence Constraint is being a horse waiting for the gates to rise. Right now what’s going to happen is that its going to wait until the file is found. But it will also have to wait until the file is not found and this code is executed in order for this constraint to be met. In other words this code here would never ever run. The solution when you have two input Precedence Constrains going into a single object is to change the multiple constraints form logical And to logical OR. Changing one of constrains to OR automatically changes all of constrains to OR. So now if either the file is found or if the file is not found. But we are successful at creating it then we want to be able to go over here and do this part of the task which is what we will do when we are ready to do the actual fuzzy look up itself. To test this, you can execute the package and because the file does currently exist it goes directly from the Script Task to the File Found Task without executing the Recreate. But if you go back to the file system and delete the destination file and then run the package. It should take the first branch, execute everything it needs to and then go off and run the file found. So you see both flows work you could use the same mechanism to create a multiple branch structure if you want to. But each branch needs to provide its own condition there is no concept of an else in this kind of branching. Demo 執行指令碼工作 © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

15 執行 SQL 工作 Demo 透過執行 SQL 工作存取資料庫
執行 SQL 陳述式或預存程序。工作可以包含逐次執行的單一或多重 SQL 陳述式: 清理資料表或檢視含蓋的紀錄,為插入資料做準備 建立、改變和卸除資料庫物件,例如資料表和檢視 將查詢傳回的資料列集存到變數中 注意資料連線的設定,會影響 SQL 語法參數設定的撰寫與回傳結果的物件架構 Demo 透過執行 SQL 工作存取資料庫

16 執行 DTS 2000 封裝工作 Demo 執行 DTS 2000 封裝
執行透過 SQL Server 2000 工具開發的封裝。藉由此工作,可以在 SQL Server 2005 資料轉換方案中包含 SQL Server 2000 DTS 封裝 可以自微軟網站下載 DTS 的設計環境 Microsoft SQL Server 2000 DTS Designer Components ( Demo 執行 DTS 2000 封裝

17 執行封裝工作 Demo 執行封裝 將其他封裝當作工作流程的一部份來執行
細分複雜的封裝工作流程:將工作流程分解成多個封裝,以方便讀取、測試和維護 重複使用部份封裝:類似呼叫副函數的方式重複使用子封裝。例如,呼叫不同封裝的資料擷取模組。被呼叫的各個封裝可以執行不同的資料刪除、篩選或彙總作業 群組工作單位:工作的單位可以分割成個別的封裝,並整合父封裝流程的交易管理 以「父封裝變數」組態將值從父封裝傳遞至子封裝。組態建立在子封裝上,並使用父封裝中的變數 Demo 執行封裝

18 Analysis Services 執行 DDL 工作
建立、卸除或修改採礦模型和多維度物件 (如 Cube 和維度) 的資料定義語言 (DDL) 陳述式 使用 Analysis Services 連接管理員連接到 Analysis Services 的執行個體或 Analysis Services 專案 Demo 執行 Analysis Services 的 DDL

19 檔案系統工作 Demo 管理檔案 維護檔案系統中的檔案和目錄,如: 建立、移動或刪除目錄和檔案。
設定檔案和目錄的屬性。例如將檔案設為隱藏或唯讀。 Demo 管理檔案

20 Web 服務工作 Demo 呼叫 Web Services 呼叫 Web Service 的方法

21 資料庫維護工作 備份資料庫工作 執行 T-SQL 陳述式工作 檢查資料庫完整性工作 通知操作員工作 重新組織索引工作 重建索引工作
執行 SQL Server Agent 作業工作 歷程記錄清除工作 執行 T-SQL 陳述式工作 通知操作員工作 重建索引工作 壓縮資料庫工作 更新統計資料工作

22 大綱 優先順序條件約束 概論 容器 工作 二○一七年三月十九日
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

23 優先順序條件約束 Demo 設定優先順序條件約束 指定評估作業:可同時使用條件約束值和運算式,或使用其中之一,來決定條件約束相關工作是否執行
執行結果:指定執行結果為成功、失敗或完成 評估結果:提供評估為布林的運算式 提供下列評估: 前一個可執行檔之執行結果,以決定條件約束可執行檔是否執行。執行結果可以是完成、成功或失敗 運算式,對其進行評估以決定條件約束可執行檔是否執行。如果運算式評估為 true,則條件約束可執行檔會執行 運算式與條件約束,此條件約束會組合優先順序可執行檔之執行結果與評估運算式之傳回結果兩者的需求 運算式或條件約束,此條件約束會使用優先順序可執行檔的執行結果或評估運算式的傳回結果 Demo 設定優先順序條件約束

24 結論 豐富的功能,彈性的條件約束,定義更細緻的控制流程 透過容器與執行封裝工作結構化地設計封裝 整合資料庫的維護工作
二○一七年三月十九日 結論 豐富的功能,彈性的條件約束,定義更細緻的控制流程 透過容器與執行封裝工作結構化地設計封裝 整合資料庫的維護工作 與 BI 平台 (IS-AS-RS) 整合在一起 © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

25 參考資源 www.SQLIS.com www.SQLDTS.com www.microsoftelearning.com


Download ppt "控制流程實作 胡百敬 精誠公司恆逸資訊 二○一七年三月十九日"

Similar presentations


Ads by Google