290 likes | 562 Views
Required Slide. SESSION CODE: ASI303. Building Activities to Leverage the Power of Windows Workflow Foundation in .NET Framework 4. m att winkler p rogram manager m icrosoft corporation http://blogs.msdn.com/mwinkle. Agenda. Activities 101 Base types Activity Composition
E N D
Required Slide SESSION CODE: ASI303 Building Activities to Leverage the Power of Windows Workflow Foundation in .NET Framework 4 matt winkler program manager microsoftcorporation http://blogs.msdn.com/mwinkle
Agenda • Activities 101 • Base types • Activity Composition • Code Activity • Activities 102 • Native Activities • ActivityDelegate • Expressions as Activities • Activity Designers
Goals When you leave this talk, you should… • Understand the activity programming model • Know when to use which base type • Create custom control flow activities to encapsulate execution logic • Use advanced activity features like ActivityDelegate and Activities as Expressions • Construct a visual experience for users of your activities • Leverage activities for fun and profit!
Non Goals • Out of the box activities • Migrating WF3 => WF4 • Consuming / Hosting WCF Services • Persistence Extensibility
Activities 101 Activity Basics, Base Classes, Activity Composition, CodeActivity
Activities 101 • Activities are the unit of work for WF • Activities = Data + Work • Data • Arguments – Shape • Variables – Storage • Work • Code you write • Code Microsoft wrote (Out of the box activities) • Other activities
Type Hierarchy CodeActivity AsyncCodeActivity Activity ActivityWithResult NativeActivity DynamicActivity
Activity Composition • Compose a new type out of existing activities • Purely declarative • Compile, or execute directly via DynamicActivity • Use when: • You are creating an additional level of abstraction • Creating an element of reuse • Don’t use when: • You work against the grain (write custom composite first)
CodeActivity • Extending WF by creating your own atoms of execution • Inherit from CodeActivity, override .Execute() • Use When: • You have existing methods you want to easily encapsulate • Quickly create a custom activity with a little bit of code • Don’t use when: • You need to schedule other activities (use NativeActivity) • Be careful about: • Blocking the execution thread (use AsyncCodeActivity)
Activity Basics Creating a composed activity, via code and designer Execute with DynamicActivity Creating a CodeActivity Doing asynchronous, parallel work with AsyncCodeActivity DEMO
Activities 102 NativeActivity, ActivityDelegate, Expressions, Designers
NativeActivity • “lowest level” activity authoring model • Provides greatest degree of control and extensibility • Use when: • You need to directly interact with the WF Runtime • You write a custom composite • You want to create a bookmark for a resumption point • Don’t use when: • You just want to write some code in Execute (use CodeActivity to compute π) • Be careful about: • Handling error conditions, cancellation • Explicit vs implicit child management
Execution Model • Multiple activity instances per activity definition • *Context resolves to the instance • Hence the theArgument.Get(context) syntax • Extensions provide access to host provided functionality • Interesting implications • Variables can be scoped • “Normal” properties become static across all instances of the activity
NativeActivity Intro to bookmarks Writing control flow activities Using Extensions Understanding Argument Evaluation DEMO
Swiss Cheese Activities, or, Using ActivityDelegate • Allow consumers to plug in their own functionality • Equivalent to a property of Func, Action or Predicate on a traditional type • Use when: • Want to create a schematized placeholder for some work • Consumers can customize parts of the activity execution • Don’t use when: • Schematization not required (just write a composite) • Be careful about: • Syntax to pass values • Need to create a designer Approval Payment Process Order Receive Order Reserve Inventory Ship Order background info
ActivityDelegate Basic ActivityAction usage Intro to ActivityFunc DEMO
Expressions As Activities • A common pattern of activities has a single return value • ActivityWithResult, and more commonly, Activity<Tresult>, has a .Result OutArgument • Compose directly into InArguments • Use when: • Activity is more functional, that is, it does work on a set of inputs and has one well defined output • Don’t use when: • Be careful about: • No native designer experience • Side effects that may rely on evaluation order
Expressions As Activities Continuing with ActivityFunc Creating Activity<T> DEMO
Building Activity Designers • Customize the visualization of activities • Use when: • You want to display some properties on canvas • Child elements to display • Create a different experience in a rehosted designer • Don’t use when: • You don’t think you need it (the default works well for many leaf activities) • Be careful about: • Expecting to get values out of Arguments (they resolve at runtime)
Building Activity Designers Surface key data Display contained elements ExpressionTextBox WorkflowItemPresenter WorkflowItemsPresenter
Building Activity Designers Walkthrough of basic types & usage Creating a rehosting app as a test harness Creating an activity designer and using in Visual Studio DEMO
Conclusion • Activities = Data + Work • Activities provide • A way to model the work that you want to orchestrate • A simple model to compose, encapsulate and reuse work • Ways to add long-running-ness, trackability, and other interesting aspects into your programs • A mechanism to allow for customization via Activity Delegate • A customizable view to help your customers compose workflows • WRITE ACTIVITIES!!!
A Quick Request • If you’re interested in State Machine, let me know, we’d like to get some feedback from you
Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. ASI Track Resources • Website – www.Microsoft.com/WindowsAzure/AppFabric • MSDN Developer Center – http://msdn.microsoft.com/en-us/azure/netservices.aspx • Blog – http://blogs.msdn.com/b/netservices/ • Twitter – http://twitter.com/azure_appfabric • Website – http://www.microsoft.com/biztalk/ • Website – http://msdn.microsoft.com/biztalk/ • Blog – http://blogs.msdn.com/biztalk_server_team_blog • Blog – http://www.biztalkblogs.com/ • Application Infrastructure Virtual Launch Event – www.appinfrastructure.com • AppFabric on Microsoft.com – http://www.microsoft.com/appfabric • Developer Center – http://msdn.microsoft.com/appfabric
Required Slide Resources Learning • Sessions On-Demand & Community • Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning • Resources for IT Professionals • Resources for Developers • http://microsoft.com/technet • http://microsoft.com/msdn
Required Slide Complete an evaluation on CommNet and enter to win!
Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st http://northamerica.msteched.com/registration You can also register at the North America 2011 kiosk located at registrationJoin us in Atlanta next year
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.