1 / 14

Custom Activities

Custom Activities. Developing Custom Activities. Why? Unit of encapsulation & re-use Model custom control flow Implement custom business logic Save to file system Process images Expand vocabulary of activities with domain specific activities . Activity Class Hierarchy. Approaches:

natalie
Download Presentation

Custom Activities

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Custom Activities

  2. Developing Custom Activities • Why? • Unit of encapsulation & re-use • Model custom control flow • Implement custom business logic • Save to file system • Process images • Expand vocabulary of activities with domain specific activities

  3. Activity Class Hierarchy • Approaches: • Code-based Atomic Activities – CodeActivity, Async & Native • Code-based Composite Activities - NativeActivity • XAML-based Composite Activities - Activity

  4. XAML-based Composite Activities MyActivity <p:Activity x:Class=MyActivity” …> <p:Sequence …> <my:DoWork1 ...> <my:DoWork2 ...> <my:DoWork3 ...> </p:Sequence> </p:Activity> DoWork1 DoWork2 DoWork3

  5. Code-Based Atomic Activities public InArgument<string> TextToLog {get;set;} public class SimpleLogActivity: CodeActivity{ protected override void Execute(CodeActivityExecutionContext context) { //activity logic goes herecontext.Track(new UserTrackingRecord(“Activity says: “ + TextToLog.Get(context))); } …} Derive from CodeActivity Override Execute method Use the Code Activity Execution Context

  6. Code-based Composite Activities public sealed class MyNativeActivity : NativeActivity { protected override void Execute(NativeActivityContext c) { } } Native Activity Use Similar to Code Activity Context enables more advanced scenarios

  7. Variables: Using Arguments & Variables in Custom Activities Result Arguments get data in or out of a custom activity Variables provide the means for a composite custom activity to share data with its children DoWork WorkToDo Result OutArgument InArgument DoWork WorkToDo Result

  8. Creating a Simple Custom Activity Implementing the ArithmeticAdd Activity

  9. Using ADO.NET for CRUD from Custom Activities • Inherit from CodeActivity • Override Execute method • Use DataReader, Command or DataAdapter CRUD Activity: CodeActivity In Arguments Out Arguments If using Integrated Security, ensure AppPool Identity has DB access • Execute • Get Connection String (web.config) • Open Connection • Perform CRUD ops • Write values to Output Arguments • Close Connection

  10. Database Activity Pack • Set of custom Activities • Perform CRUD using ADO.NET • Enable using SQL or Stored Procedure for command • Support mapping returned record collection to collection variable in workflow • Pull connection string from config Define complex mapping as activity sequence Easily process one record at a time Provides Out Argument as List<T> Returns # of Rows Affected

  11. DB Activities with Transactions Creates or Joins Ambient Transaction Transaction Scope Isolation Level Join ambient transaction • No persistence within transaction • No explicit rollback or commit activities OOB • NativeActivityContext can get current transaction (if needed) • TransactedReceiveScope activity supports flow-in of distributed transactions in workflow services Timeout Create Activity Exceptions thrown cause implicit rollback Update Activity Delete Activity Completion of Transaction Scope implicitly commits transaction & persists workflow

  12. Using the Database Activity Pack

  13. Custom Activity Design Time Experience Activity Designers WPF Based Validate individual properties or entire activity tree Validation Expression support Customize presentation & design time behavior Category Editors allow “batch” editing of multiple properties with single complex UI Custom Inline, Pop-Up & Dialog Property Value Editors Property Grid Extensibility

  14. Lab 4 • Custom Activities

More Related