WorkflowApplication ReadLine Host
This sample is a generic ReadLine host. You can load and run any workflow using the included
ReadLine activity (or other activities like it that get data from bookmarks resumed with strings). Output from the
WriteLine activity or anything writing to the TextWriter extension is directed to the host window. When an instance is idle, the available bookmarks for that instance appear in a combo box. Selecting a bookmark, inputting some text, and pressing the resume bookmark button continue the execution of the workflow. You can also cancel, abort, or terminate a selected workflow. Persistence is on by default – you can shut down the host and bring it back, and the instance list is populated with the instances stored in the database. Tracking is used to output WorkflowApplication-level events to the host with the option to add detailed tracking at the activity level.
There are two layers to this host: the view and the instance manager. The view consists of the
WorkflowApplicationInfo classes. The general pattern for this host is for the
HostView class to display available options to the user based on
WorkflowApplicationInfo objects that are kept reasonably in synchronization with the instances they represent. The instance manager layer consists of the
WorkflowApplicationManager class, which is the core of all host communications, and the
WorkflowDefinitionExtension class, which persists the relationship between an instance and the program definition it was started with and a few other classes. The
HostView calls control operations on the
WorkflowApplicationManager. These calls are typically asynchronous to maintain a responsive user interface. When the asynchronous calls complete, the
WorkflowApplicationManager makes calls back into the view layer through a well-defined interface (
HostView class most often dispatches these calls from the
WorkflowApplicationManager class to the user interface thread. Text writing is done to thread-safe TextWriter objects provided by the
HostView class. The user interface is not the only thing generating events. The WorkflowApplication objects also signal the
WorkflowApplicationManager when they go
Complete, or are
Aborted, for example. The
WorkflowApplicationManager class gets off the event thread by dispatching clean up or updating work to the host.
The recording of the file used to launch a WorkflowApplication is facilitated by the
WorkflowDefinitionExtension class. It implements the PersistenceIOParticipant interface to participate in persistence and persist the path to the workflow definition.
WorkflowApplicationManager.Load method uses the stored path to instantiate the workflow programs required for loading unfinished WorkflowApplication objects.
To set up, build, and run the sample
This sample requires SQL Express to be installed. SQL Express comes with Visual Studio 2010.
Open a Visual Studio 2010 command prompt.
Navigate to the sample directory (\WF\Basic\Execution\ControllingWorkflowApplications) and run CreateInstanceStore.cmd.
The CreateInstanceStore.cmd script attempts to create the database on the default instance of SQL Server 2008 Express. If you want to install the database on a different instance, modify the script to do so.
Compile the WorkflowApplicationReadLineHost project and run it from the command line.
Once running, you can optionally turn persistence off or on. Further, you can optionally turn detailed activity tracking on or off.
Press the ellipsis button next to the Run button to browse for a workflow defined in a XAML file
Two samples can be found under the SampleWorkflows folder. The parallel1.xaml example goes idle.
Once an example is selected, press the Run button.
If or when the workflow goes idle, the Bookmarks combo box is populated with available bookmarks.
The options at this point are to resume a bookmark, cancel, abort, or terminate the workflow. You can also shut down the host and restart it. If persistence is left on, the instances are unloaded on shutdown and reloaded on start up.
To resume a bookmark, select the desired bookmark, type in a value in the text box next to the combo box and press Resume Bookmark.
To remove the instance store database
Open a Visual Studio 2010 command prompt.
Navigate to the sample directory (\WF\Basic\Execution\ControllingWorkflowApplications) and run RemoveInstanceStore.cmd.
The samples may already be installed on your machine. Check for the following (default) directory before continuing.