Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Using Windows Workflow to Control ASP.NET Navigation : Page 2

Windows Workflow is not only ideal for defining page-flow logic visually, but also for letting different systems communicate.


advertisement
Sample Application Walkthrough
Create a blank Visual Studio solution (File --> New Project --> Other Project Types --> Visual Studio Solutions --> Blank Solution) as shown in Figure 1.

Add a Class Library project and name it MiddleBit (File --> Add --> New Project --> Visual C# --> Class Library) as shown in Figure 2.

 
Figure 1. New Project Dialog: Create a new blank solution by selecting that template from the "Other Project Types/Visual Studio Solutions" area.
 
Figure 2. Add Class Library Project: Here's where you'll find the Class Library project template in the Add New Project dialog.
 
Figure 3. Add Sequential Workflow: The Sequential Workflow project template is under the Workflow template types in the Add New Project dialog.
Paste the code for IGenericInterface, GenericInterface, and GenericInformationEventArgs into this project. You'll also need to add a reference to System.Workflow.Activities to the project references and add the code using System.Workflow.Activities; at the top.

Now add a new Sequential Workflow Console Application project (see Figure 3) to the solution (File --> Add --> New Project --> Visual C#/Workflow --> Sequential Workflow Console Application), and name it MyWorkflows.

Reference the MiddleBit project from the Sequential Workflow project.

At this point, the workflow designer will open, prompting you to drop activities on the design surface. First, you want to call an external method to tell ASP.NET to go get some information. Drag the CallExternalMethod activity to the canvas. Right click, and select "Properties." You'll see something like Figure 4.

 
Figure 4. CallExternalMethod Properties: In this dialog, you set various properties for the CallExternalMethod activity.
Note that you must set the InterfaceType and MethodName properties before you can set the informationName property. The dialog tells WF which method from what interface to call.
 
Figure 5. HandleExternalEvent Properties: Here's the dialog in which you set properties for the HandleExternalEvent activity.

Rename the activity to getNameAndPageChoicesActivity.

So far you have a workflow that—when run—calls an external method to ask for some information. Now you need to tell the workflow to wait until the data arrives. Drag a HandleExternalEvent activity just underneath the first activity. Set its properties as shown in Figure 5.

The activity property settings in Figure 5 tell the workflow to wait for an event named InformationReceived fired from the IGenericInformationService. Notice that the e parameter—the GenericInformationEventArgs class defined earlier in the event declaration—is not set. Here's the earlier declaration:

event EventHandler <GenericInformationEventArgs> InformationReceived;

 
Figure 6. Bind Parameter: Bind the "e" parameter to a new property named "nameAndPageChoicesArgs."
Click on the right column of "e" and bind "e" to a new field. Clicking the ellipses (…) brings up a dialog with two tabs. You want to bind to a new member, so the dialog should look like Figure 6.

Clicking OK creates the following code in the workflow1.cs file:

public static DependencyProperty nameAndPageChoicesArgsProperty = DependencyProperty.Register( "nameAndPageChoicesArgs", typeof( MiddleBit.GenericInformationEventArgs), typeof(MyWorkflows.Workflow1)); [DesignerSerializationVisibilityAttribute( DesignerSerializationVisibility.Visible )] [BrowsableAttribute( true )] [CategoryAttribute( "Parameters" )] public GenericInformationEventArgs nameAndPageChoicesArgs { get { return ( (MiddleBit.GenericInformationEventArgs) ( base.GetValue( MyWorkflows.Workflow1. nameAndPageChoicesArgsProperty ) ) ); } set { base.SetValue( MyWorkflows.Workflow1.nameAndPageChoicesArgsProperty, value ); } }

Note that the new property has the DependencyProperty type, not the GenericInformationEventArgs type. The property calls the base methods GetValue and SetValue.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date