Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney
Table of Contents -Introduction -Scripts -Activities -Services -Deployment
Requirements Required: -Windows Workflow Foundation (.NET 3.0) -VB.NET or C#.NET Recommended: -Visual Studio 2005 or higher
Introduction - Workflow Integration Options: -Scripts -Activities Advanced Integration Options: -Workflow Runtime Services -Windows Communication Foundation (WCF)
Workflow Architecture
Workflow Terminology Activity – Basic unit of a workflow, a step in the workflow process Runtime – The part of the workflow service that executes the workflow Designer – The application that allows you to create workflows which can be executed Workflow Server – The service that executes and manages published workflows Workflow Subscriber – The service that monitors Laserfiche repositories for events that are of interest to workflows
Scripts “Internal” workflow integrations
Scripts - Introductions Code snippets that are compiled to perform custom workflow actions Script activities are part of the workflow rule
Workflow Definitions An activity is an object you place on the workflow canvas:
Workflow Definitions - continued The workflow canvas is the collection of all activities that make up your rule:
Workflow Definitions - continued These are created in the Designer:
Scripts - Activities ‘Scripting’ Category in the toolbox Script Activities: Script (C#) Script (VB) Toolkit (C#) Toolkit (VB)
What is the difference? Script Activity –A basic script that does not ‘talk’ to a Laserfiche server Toolkit Script –Provides a connection to Laserfiche –Retrieves an entry from the repository
Sample – Script activity C# Visual Basic
Sample – Toolkit script C# Visual Basic
All Scripts – Pros and Cons Pros: Easy to write ‘Hands free’ integration Customizable Cons: ‘Slower’ Harder to debug Limited
Cons explained Scripts have to be loaded and executed ‘on the fly’ when workflows run Debugging is difficult. We’ve provided the ‘MsgBox’ to help (It shows a message box!) Scripts are limited to one ‘code file’ and can not add additional references
Scripts - Features Advanced Editor: Code suggestions Export/Import Syntax Highlighting Tokens: Creating Replacing Testing
Scripts – Code suggestions Code suggestions and auto-complete
Scripts – Syntax Highlighting Keywords and string highlighting
Scripts – Compile Errors Compile errors are clearly reported.
Scripts - Tokens Tokens used in the script can be tested
Toolkit Script – Picking an entry Starting Entry Other workflow entries
About Using Scripts When to use: -For a simple, one time only task. -Setting a token -Setting a property When not to use: -A task that may be needed in more than one workflow, especially if there are variable properties.
Activities Custom Workflow actions
Workflow Activities – Two Parts Runtime (Workflow Activity): -Execution -Persistence Design Time (Activity Proxy): -Properties -Publishing Custom activities are made of two parts
Activities and Proxies The ‘Runtime’ workflow activity is a Windows Workflow activity and is executed on the Workflow Server. The ‘Design Time’ workflow activity is called an Activity Proxy and runs in the Workflow Designer.
Runtime
Runtime Activities Windows Workflow Activity Runs on workflow server Does the ‘work’
Runtime Activities – Keep it simple Examples of simple: Create an entry Change template fields Send an Examples of not simple: More than one task at a time Activities should perform simple tasks.
Runtime Activities – Keep it short Workflow execution time is scarce. Example of short: Simple Tasks Processing a row in a database table. Example of not short: OCR / Image Processing Iterating through a database table Waiting on an event*
Runtime Activities – Keep it Small Long running workflows are saved (persisted) -Any class variable in the activity will be saved -Do not have ‘large’ variables in your activities -Data Sets -Large arrays, collections, or lists -Use the NonSerialized (MSDN) attribute on any necessary large variable(s)NonSerialized (MSDN)
Terminology Attributes –An attribute is metadata for code. More on Attributes (MSDN) VB C#
Create a ‘Workflow Activity Library’ Visual Studio
Runtime Activities – Creating Add a reference to System.Workflow.ComponentModel (MSDN)System.Workflow.ComponentModel Derive/Inherit from System.Workflow.ComponentModel.Activity (MSDN) System.Workflow.ComponentModel.Activity Implement the Execute Method (MSDN) Execute Method
Runtime Activities - Laserfiche Alternatively, use the LaserficheActivity Connects to a Laserfiche repository Add a reference to Laserfiche.Workflow Derive/Inherit from Laserfiche.Workflow.Activities.LaserficheActivity Implement the OnExecuteCode method
Runtime Activities - Resources Windows Workflow: Building Custom Activities Activity Persistence Windows Workflow Foundation Activities
Design Time User Interface
Workflow Designer
Toolbox Canvas Property Viewer
Proxies and the Workflow Designer The Activity Proxy Generator utility will generate the code to display your activity in the Toolbox, Canvas, and Property Viewer The proxy will have default properties, serialization, and publishing code
Activity Proxy Generator
Creating a proxy Use the proxy generator! –Browse to your activity assembly (the.dll!) –Choose the base class Activity Proxy – Your activity derives from ‘Activity’ LaserficheActivityProxy – Your activity derives from ‘LaserficheActivity’ –Save the file or Copy and Paste –Customize Properties Serialization Publishing
Proxy Tips Public properties show up in the property pane. The property pane makes use of attributes to customize how properties look. Property types like ‘int’ and ‘string’ are supported out of the box. Complex property types will require more work.
Attribute Example [DisplayName(“Activity Name”)] public string Name { get; set; } ‘String’ displays a text box
Simple ‘custom’ property control [EditControl(typeof(EditMultilineTextBoxControl))] public string Description { get; set;} EditControlAttribute is used to customize how a property is edited in the Designer
Complex ‘custom’ property control
Publishing - Overall Publishing – The process of taking a designed workflow and preparing it to be executed on the Workflow Server. Involves –Serialization (Loading and Saving) –Code Generation (also called Publishing) –Compiling
Publishing Serialization Publishing Process Workflow Designer saves WFX Workflow Xml File Uploads Workflow Server Generates and Compiles Workflow Code File
What is Serialization? Serialization is the creation of the Workflow Xml File (.wfx) Two Methods to be implemented: –ReadProperties XmlReader (MSDN)XmlReader (MSDN) –WriteProperties XmlWriter (MSDN)XmlWriter (MSDN) Generated by the proxy generator –PropertySerializer class –MemberwiseSerializableAttribute IXmlSerializable interface (MSDN)
What is Publishing? Code Generation –Generate code that sets the properties of the runtime activity. –Produces a code file Publishing of many properties are handled automatically by workflow. Generated by the proxy generator Advanced code generation –CodeDOM Serialization (MSDN)CodeDOM Serialization (MSDN)
Deployment
Workflow Server Side The activity’s assembly must be placed somewhere that is accessible by the workflow server The configuration file for the workflow server must be updated to look for the assembly in the location Restart service after modifying the configuration file
Workflow Service Configuration File
Workflow Designer Side Activities should be placed in the CommonFiles\Laserfiche\Workflow\Activities folder on the designer machine Your activity should now be available as a toolbox item
Troubleshooting Tips Saving and Opening files from the workflow designer will help find serialization issues Exporting to a Windows Workflow will help find publishing issues Make sure the deployment steps are completed on the Workflow Service before attempting to publish a workflow with your new activity
Advanced Integration Topic
Advanced Topics Runtime Services –Runtime services can be added to the configuration file. These are needed to handle complex actions like event handling. WCF Services –Workflow communicates using WCF services. These services can be used by other applications. SQL Tables –All workflow activity is stored in SQL tables. These tables can be read to gather statistical information about workflows and activities.
Runtime Workflow Services Adding Workflow Services (MSDN)Adding Workflow Services WorkflowRuntimeService class (MSDN)WorkflowRuntimeService class
WCF Services Creating A WCF Client (MSDN)Creating A WCF Client Interacting with WCF Services (MSDN)Interacting with WCF Services
Windows Workflow Foundation Benefits: -Scalable -Reliable -Extensible Links: - -