- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
CONDITIONAL ACTIVITIES in Visual C#
CHAPTER 3 CONDITIONAL ACTIVITIES Paint Data Matrix 2d Barcode In Visual C#.NET Using Barcode creator for Visual Studio .NET Control to generate, create Data Matrix ECC200 image in VS .NET applications. www.OnBarcode.comDataMatrix Recognizer In Visual C#.NET Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comPublic Sub Branch1Condition(ByVal sender As Object, ByVal e As ConditionalEventArgs) e.Result = IntInputValue > 50 End Sub Public Sub Branch2Condition(ByVal sender As Object, ByVal e As ConditionalEventArgs) e.Result = IntInputValue > 25 End Sub The declaration of each sub contains two parameters. The first isn t relevant, but is necessary. You use the second one (e) to let the workflow know if the branch should be executed or not. e.Result needs to evaluate to either a True or False condition. The workflow uses this result when evaluating each branch to determine if that branch should be executed. To finish this connection, you must tell the IfElseBranch activity to look at the appropriate sub when evaluating that branch. To do this, return to the Workflow Designer and click the Branch1 IfElseBranch activity and view the properties. From the drop-down list for the Condition property, choose System.Workflow.Activities.CodeCondition. The Condition property will then have a plus sign next to it; use this to expand the property to see another Condition property. For this property, enter Branch1Condition, as shown in Figure 3-2. Encode EAN128 In Visual C#.NET Using Barcode drawer for .NET Control to generate, create UCC-128 image in VS .NET applications. www.OnBarcode.comCode 39 Extended Creator In Visual C#.NET Using Barcode encoder for .NET framework Control to generate, create USS Code 39 image in VS .NET applications. www.OnBarcode.comFigure 3-2. Condition property for Branch1 Repeat this for Branch2, setting the Condition property to Branch2Condition. By setting this property for each branch, you re telling the workflow engine where to look to evaluate which branch is True. Within each sub that you define as the condition, you can perform any code you want, as long as the e.Result line of code returns either a True or False. To best see what s going on, add a breakpoint to the whole IfElse activity (right-click the activity and choose Breakpoint). Debug the workflow and enter 45 for the input value. You ll notice as you step through that the IfElse activity goes right to Branch2. The workflow evaluated the condition on Branch1 and determined that to be False, then moved to Branch2. The Branch 2 message box appears. Finally, debug the workflow again and enter 10 as the input value. When the breakpoint is activated and you step through, you ll notice that neither Branch1 nor Branch2 is executed; instead, the next step is to the end of the workflow. This is because neither branch evaluated as True. Close this project and create a new C# Sequential Workflow Console Application called CIfElseSequentialExample. Open the Workflow.cs file and view the code. Add a private variable called IntInputValue and a public variable called InputValue with only a set statement (so it s write-only): Create PDF 417 In Visual C#.NET Using Barcode creator for VS .NET Control to generate, create PDF 417 image in .NET applications. www.OnBarcode.comDrawing EAN / UCC - 13 In Visual C#.NET Using Barcode generation for VS .NET Control to generate, create UPC - 13 image in Visual Studio .NET applications. www.OnBarcode.comCHAPTER 3 CONDITIONAL ACTIVITIES
Barcode Generation In C#.NET Using Barcode maker for .NET Control to generate, create Barcode image in .NET applications. www.OnBarcode.comMaking ISBN In Visual C# Using Barcode generation for VS .NET Control to generate, create ISBN - 10 image in VS .NET applications. www.OnBarcode.comprivate int IntInputValue; public int InputValue { set { IntInputValue = value; } } Open the Program.cs file and add a dictionary called parms. Then add a parm called InputValue, and pass that parm dictionary when creating the workflow instance. The beginning of Main looks like the following: static void Main(string[] args) { WorkflowRuntime workflowRuntime = new WorkflowRuntime(); AutoResetEvent waitHandle = new AutoResetEvent(false); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();}; workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine(e.Exception.Message); waitHandle.Set(); }; Dictionary<string, object> parms= new Dictionary<string, object>(); Also, add a console.readline similar to what was done in the VB example, so that both examples take interactive input from the user. To read the line from the console and make sure the data type is correct, use the following line of code: parms["InputValue"] = System.Convert.ToInt32 (Console.ReadLine()); The completed Main follows: static void Main(string[] args) { WorkflowRuntime workflowRuntime = new WorkflowRuntime(); AutoResetEvent waitHandle = new AutoResetEvent(false); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();}; workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine(e.Exception.Message); waitHandle.Set(); }; Data Matrix ECC200 Maker In None Using Barcode creation for Font Control to generate, create Data Matrix ECC200 image in Font applications. www.OnBarcode.comGenerate DataMatrix In Java Using Barcode creator for Java Control to generate, create ECC200 image in Java applications. www.OnBarcode.comCHAPTER 3 CONDITIONAL ACTIVITIES
Generate Code-128 In Java Using Barcode generator for BIRT reports Control to generate, create Code 128C image in BIRT applications. www.OnBarcode.comPaint Code 128B In VB.NET Using Barcode creation for VS .NET Control to generate, create USS Code 128 image in VS .NET applications. www.OnBarcode.comDictionary<string, object> parms= new Dictionary<string, object>(); Console.WriteLine("Input Value"); parms["InputValue"] = System.Convert.ToInt32 (Console.ReadLine()); WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof( CIfElseSequentialExample.Workflow1),parms); instance.Start(); waitHandle.WaitOne(); } Drag and drop an IfElse activity onto the Workflow Designer. Rename the left branch to Branch1. While you re on the Properties page of the left branch, also tie this into the condition. Within C#, this action is a little different, and actually easier. From the condition drop-down within the Properties window, choose System.Workflow.Activities.CodeCondition and enter Branch1Condition as the condition. Once you do this and move from that property, the Branch1Condition definition is automatically created for you, and that code appears. Then, just add the same condition for e.Result, as was done in the VB sample. Do the same with Branch2. To finish this example, add a Code activity to each branch, and set up each Code activity the same way as in the VB example. The rest of the code behind the workflow looks like the following: private void Branch1Condition(object sender, ConditionalEventArgs e) { e.Result = IntInputValue > 50; } private void Branch2Condition(object sender, ConditionalEventArgs e) { e.Result = IntInputValue > 25; } private void Branch1Code_ExecuteCode(object sender, EventArgs e) { Console.WriteLine("Branch1"); } private void Branch2Code_ExecuteCode(object sender, EventArgs e) { Console.WriteLine("Branch2"); } Finally, just as in the VB example, add a breakpoint to the IfElse activity and debug the application, the first time with the value 45, and the second time with the value 10. You ll see the same results; when 45 is entered, Branch2 is executed, and when 10 is entered, neither is executed. GS1 - 13 Drawer In None Using Barcode creator for Online Control to generate, create EAN-13 Supplement 5 image in Online applications. www.OnBarcode.comEncoding UPC-A Supplement 2 In Visual Studio .NET Using Barcode generator for Reporting Service Control to generate, create UPC A image in Reporting Service applications. www.OnBarcode.comECC200 Maker In None Using Barcode maker for Online Control to generate, create Data Matrix ECC200 image in Online applications. www.OnBarcode.comUPC - 13 Creator In .NET Using Barcode creator for Visual Studio .NET Control to generate, create European Article Number 13 image in .NET framework applications. www.OnBarcode.comGenerate EAN / UCC - 14 In Java Using Barcode maker for Android Control to generate, create GS1 128 image in Android applications. www.OnBarcode.comUPC-A Creator In None Using Barcode drawer for Online Control to generate, create UPC Code image in Online applications. www.OnBarcode.comBarcode Generator In Java Using Barcode generation for Java Control to generate, create Barcode image in Java applications. www.OnBarcode.comDrawing Code 128B In Java Using Barcode generator for Java Control to generate, create USS Code 128 image in Java applications. www.OnBarcode.com |
|