tailieunhanh - Lập trình .net 4.0 và visual studio 2010 part 21
Microsoft cung cấp nhiều hoạt động ra khỏi hộp, nhưng bạn sẽ muốn và cần tạo ra các hoạt động của riêng bạn. Hoạt động có thể được tạo ra trong ba cách chính • Là một thành phần của các hoạt động khác hiện có • Trong code • Pure XAML | CHAPTER 6 WINDOWS WORKFLOW FOUNDATION 4 4. Open and add the following using statement using 5. Modify the Main method to the following to create and pass in a dictionary of our initial variables static void Main string args Dictionary string object Arguments new Dictionary string object FilmName Terminator ShowingDate NumberOfTickets 4 new Workflow1 Arguments 6. That s it you have just created your first workflow. Now press F5 to run it. 7. Try changing the NumberOfTickets to five. Do you get a different result Wow we covered a lot in that short example. You discovered the new workflow designer how to use arguments and variables and some of the new activities in WF4. Creating Your Own Activities Microsoft supplies many activities out of the box but you will want to and should create your own activities. Activities can be created in three main ways As a composition of other existing activities In code Pure XAML Creating an Activity Composed of Other Activities Let s create a simple activity to simulate writing a customer s ticket booking to a database. 1. Right-click on the project and add a new activity from the Workflow section called . 2. Open in the design view. 3. Create an argument for the SaveBooking activity String In called BookingReference. 4. Drag a Sequence activity onto the design surface. 5. Drag a WriteLine activity onto this activity and change its display name to Simulate booking storage. 142 CHAPTER 6 WINDOWS WORKFLOW FOUNDATION 4 6. We are not going to go to the bother of actually writing data access code so change the Value property of the WriteLine activity to Save booking BookingReference in database. Your workflow should look like Figure 6-12 note the quotes . 7. Click Save. 1 Save Booking xamJ X 1 SaveBooking Expand All Collapse All Sequence K4 Simulate booking .
đang nạp các trang xem trước