WF4.0 Beta2: Use of Pick Activity

Source: Internet
Author: User

WF4.0 beta2 provides the Pick activity to complete the event-based control flow. This activity can have multiple PickBranch branches. Each branch has two parts: Trigger and Action. When a Trigger is triggered, the Activity in the Action is executed. As long as one PickBranch Trigger is triggered for a Pick activity, other PickBranch will not be triggered.

1. For example: there are two branches, and we will end after the user input expires. The work is as follows:

2. The XAML of the workflow is as follows:

<Activity mc: Ignorable = "sap" x: Class = "......> <Sequence sad: XamlDebuggerXmlReader. fileName = "...... \ Sequence1.xaml "sap: VirtualizedContainerService. hintSize = "656,462"> <Sequence. variables> <Variable x: TypeArguments = "x: String" Name = "name"/> </Sequence. variables> <sap: WorkflowViewStateService. viewState> <scg: Dictionary x: TypeArguments = "x: String, x: Object"> <x: Boolean x: Key = "IsExpanded"> True </x: boolean> </scg: Dictionary> </sap: WorkflowViewStateService. viewState> <Pick sap: VirtualizedContainerService. hintSize = "634,338"> <PickBranch sap: VirtualizedContainerService. hintSize = "240,292"> <PickBranch. trigger> <local: ReadString BookmarkName = "[& quot; UserName & quot;]" DisplayName = "read input" sap: VirtualizedContainerService
. HintSize = "210,100" Result = "[name]"/> </PickBranch. trigger> <WriteLine DisplayName = "show welcome information" sap: VirtualizedContainerService. hintSize = "210,100" Text = "[& quot; Hello:
O & quot; & amp; name] "/> </PickBranch> <PickBranch sap: VirtualizedContainerService. hintSize = "240,292"> <PickBranch. trigger> <Delay DisplayName = "set expiration time" Duration = "[System. timeSpan. fromSeconds (5)] "sap: VirtualizedContainerService
. HintSize = "210,100"/> </PickBranch. trigger> <WriteLine DisplayName = "Time Expiration Prompt" sap: VirtualizedContainerService. hintSize = "210,100" Text = "expired"/> </PickBranch> </Pick> </Sequence> </Activity>
3. The workflow is designed in a visualized way. You can also use the code method as follows:
Static Activity CreateWF () {Variable <string> name = new Variable <string> (); // Body Sequence body = new Sequence () {Variables = {name }, activities = {new Pick {Branches = {new PickBranch {Trigger = new ReadString {Result = name, BookmarkName = bookmarkName }, action = new WriteLine {Text = new InArgument <string> (env => "Hello:" + name. get (env) }}, new PickBranch {Trigger = new Delay {Duration = TimeSpan. fromSeconds (5) }, Action = new WriteLine {Text = "Time expired" }}}}; return body ;}

4. We need to prepare an activity for reading input. The Code is as follows:

public sealed class ReadString : NativeActivity<string>    {        [RequiredArgument]        public InArgument<string> BookmarkName { get; set; }        protected override bool CanInduceIdle        {            get            {                return true;            }        }        protected override void Execute(NativeActivityContext context)        {            context.CreateBookmark(this.BookmarkName.Get(context), new BookmarkCallback(OnReadComplete));        }        void OnReadComplete(NativeActivityContext context, Bookmark bookmark, object state)        {            string input = state as string;            context.SetValue(this.Result, input);        }    }

5. The host Program is as follows:

Static string bookmarkName = "UserName"; public static void Main (string [] args) {ManualResetEvent completedEvent = new ManualResetEvent (false); AutoResetEvent idleEvent = new AutoResetEvent (false ); // WorkflowApplication application = new WorkflowApplication (new Sequence1 (); WorkflowApplication application = new WorkflowApplication (CreateWF (); application. idle + = delegate (WorkflowApplicationIdleEventArgs e) {idleEvent. set () ;}; application. completed + = delegate (WorkflowApplicationCompletedEventArgs e) {completedEvent. set () ;}; application. run (); idleEvent. waitOne (); Console. writeLine ("What is your name (5 seconds)"); string text = Console. readLine ();
Application. ResumeBookmark (bookmarkName, text); completedEvent. WaitOne (); Console. WriteLine ("workflow execution completed"); Console. ReadLine ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.