Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Workflow Foundation Ruwan Wijesinghe.

Slides:



Advertisements
Similar presentations
The Microsoft Technical Roadshow 2006 Windows Workflow Foundation Mike Taulty Developer & Platform Group Microsoft Ltd
Advertisements

Windows Workflow Foundation By Sam Nasr, MCAD October 23,
Developing Event Driven State Machine Workflows S1 S2 S3 S4 Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#
 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
Introduction to Windows Workflow Foundation (WF) Keith Elder Microsoft MVP Blog: Quicken Loans –
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
1 Chapter 12 Working With Access 2000 on the Internet.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
VBA Modules, Functions, Variables, and Constants
Using Visual Basic 6.0 to Create Web-Based Database Applications
Windows Vista for Syndication and Workflow Mike Ormond Developer & Platform Group, Microsoft Ltd
ASP.NET Programming with C# and SQL Server First Edition
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Usman Zafar Malik MCTS: MOSS 2007 MBMSS Dynamics CRM 3.0/4.0.
Using Microsoft SharePoint to Develop Workflow and Business Process Automation Ted Perrotte National Practice Manager, Quilogy, Microsoft Office SharePoint.
Workflows in SharePoint Brian Russo RJB Technical Consulting July 2009.
C# Event Processing Model Solving The Mystery. Agenda Introduction C# Event Processing Macro View Required Components Role of Each Component How To Create.
1 Developing Rules Driven Workflows in Windows Workflow Foundation Jurgen Willis COM318 Program Manager Microsoft Corporation.
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
ASP.Net, Web Forms and Web Controls 1 Outline Introduction Simple HTTP Transaction System Architecture Creating and Running a Simple Web Form Example Web.
Neal Stublen Practice Solution  Create a new solution  Add a WinForms project  Add a Class Library project  Reference the library.
Sage CRM Developers Course
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
ASP.NET  ASP.NET is a web development platform, which provides a programming model, a comprehensive software infrastructure and various services required.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Developing Workflows with SharePoint Designer David Coe Application Development Consultant Microsoft Corporation.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Workflow Development Overview Architecture Requirements Types of workflows Stages of workflow.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
MapReduce Kristof Bamps Wouter Deroey. Outline Problem overview MapReduce o overview o implementation o refinements o conclusion.
Office Business Applications Workshop Defining Business Process and Workflows.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
Object Oriented Software Development 10. Persistent Storage.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
C# GUI - Basics. Objectives.NET supports two types: WinForms, traditional, desktop GUI apps. WebForms – newer, for Web apps. Visual Studio.NET supports.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
A university for the world real R © 2009, Chapter 9 The Runtime Environment Michael Adams.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
IBM TSpaces Lab 3 Transactions Event Registration.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Practical Workflow Services Peter Goodman. Agenda  Why Workflow?  The Workflow Runtime  Workflow Services  Windows Server AppFabric  Demo.
Slide 1. Agenda  Introduction to Windows Workflow What is it? What are activities? Hosting  Out of the box Activities  Custom Activities and Dependency.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Building Custom Controls with ASP.NET and the Microsoft ®.NET Framework Rames Gantanant Microsoft Regional Director, Thailand
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Presentation Foundation Ruwan Wijesinghe.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
Windows Workflow Foundation Guy Burstein Senior Consultant Advantech – Microsoft Division
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Business Process Execution Language (BPEL) Pınar Tekin.
Business rules.
Computing with C# and the .NET Framework
XAML User Interface Creation in C#
Technology in Action! Windows Workflow Foundation Advanced Techniques
Introduction to Windows Workflow Foundation (WF)
Presentation transcript:

Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Windows Workflow Foundation Ruwan Wijesinghe

2 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Introduction Windows Workflow Foundation is a development framework that enables you to embed workflows in.NET Framework applications. Windows Workflow Foundation enables model-driven workflow development Providing natural design visibility and hiding system-level concerns such as transactions, state management, and concurrency control There are two primary facets of programming workflows. Designing workflows and their activities Using workflows within an application

3 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Workflow Authoring Code Only This is the default authoring mode for Windows Workflow Foundation, which enables you to use C# or Visual Basic code to specify a workflow using the Windows Workflow Foundation API set. Visual Studio IDE generates a visual representation of the workflow from this code, and support visual editing of workflow (similar to WinForms) Markup Only Design the workflow using an XAML based Workflow markup language called XOML. Code-Behind Design the workflow using an XAML based Workflow markup language and develop workflow control code in a separate code file (as a partial class). This is similar to ASP.NET 2.0 programming modal. Visual Studio supports a Visual editing of these workflows

4 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Types of Workflows Sequential workflows This style is straightforward and useful for repetitive, predictable operations, such as designing a set of activities to be performed in a prescribed sequence that is always the same. These workflows execute activities in a sequential manner until the last activity completes. They can have separate “Cancel Handling” and “Fault Handling” workflows as well State Machine workflow These workflows are made up of set of states. One state is denoted as a start state. Each state can receive a certain set of events. Based on an event a transition can be made to another state. The state machine workflow can have a final state. When a transition is made to the final state the workflow completes.

5 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL A Simple Sequential Workflow This is a simple workflow diagram generated using Visual Studio 2005 IDE

6 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Code Only 1 Workflow1.designer.cs partial class Workflow1 { #region Designer generated code [System.Diagnostics.DebuggerNonUserCode] private void InitializeComponent() { this.CanModifyActivities = true; // codeActivity1 this.codeActivity1 = new System.Workflow.Activities.CodeActivity(); this.codeActivity1.Name = "codeActivity1"; this.codeActivity1.ExecuteCode += new System.EventHandler(this.PrintHello); // Workflow1 this.Activities.Add(this.codeActivity1); this.Name = "Workflow1"; this.CanModifyActivities = false; } #endregion private CodeActivity codeActivity1; }

7 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Code Only 2 Workflow1.cs public sealed partial class Workflow1: SequentialWorkflowActivity { public Workflow1() { InitializeComponent(); } public void PrintHello(object sender, EventArgs e) { Console.WriteLine("Hello World"); }

8 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Code Behind Mode Workflow1.xoml <SequentialWorkflowActivity x:Class="WorkflowConsoleApplication1.Workflow1" x:Name="Workflow2" xmlns:x=" xmlns=" Workflow1.xoml.cs namespace WorkflowConsoleApplication1 { public partial class Workflow1 : SequentialWorkflowActivity { public void PrintHello(object sender, EventArgs e){ Console.WriteLine("Hello World"); }

9 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Activities Activities are the elemental unit of a workflow Windows Workflow Foundation contains a library of standard activities as well as provides the mechanisms for you to create your own. Workflow state information

10 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL CodeActivity Activity Execute a method in the Workflow class This method must have a normal event handler format E.g. private void OnApproved (object sender, EventArgs e) { }

11 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL CallExternalMethodActivity Activity Used to call methods in custom local services The external method is defined using interfaces The properties in the workflow class or its activities can be passed as parameters to the external method The actual services that implements the interface is defined by the application that host the workflow runtime (using AddService method of the workflow runtime class) wfRuntime = new WorkflowRuntime(); myWorkflowService = new MyWorkflowService(); wfRuntime.AddService(myWorkflowService);

12 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL HandleExternalEventActivity Activity Suspend the code execution until an external event occurs The event arguments can be assigned to the properties of the workflow class, once the event occurs The external event is defined using an interface This activity requires an “ExternalDataExchangeService” service instance added to the workflow runtime using “AddService” method The actual service class that generates the event (that implements the above event interface) must be add to the ExternalDataExchangeService instance using its “AddService” method, by the workflow hosting application. wfRuntime = new WorkflowRuntime(); ExternalDataExchangeService dataService = new ExternalDataExchangeService(); wfRuntime.AddService(dataService); eventService = new WorkflowEvents(); dataService.AddService(eventService);

13 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Simple Workflow with Branches GetMarksActivity - CallExternalMethodActivity Interface: IMyService1 Method: int GetMarks() Return value: Marks DisplayPass - CallExternalMethodActivity Interface: IMyService1 Method: void PrintMessage(string msg) msg: Pass DisplayFail - CallExternalMethodActivity Interface: IMyService1 Method: void PrintMessage(string msg) msg: Fail

14 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL IMyServiceInterface Interface: [System.Workflow.Activities.ExternalDataExchange] interface IMyService1 { int GetMarks(); void PrintMessage(string msg); } An Implementation: class MyService1: IMyService1 { public int GetMarks(){ return 30; } public void PrintMessage(string msg){ Console.WriteLine(msg); }

15 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Hosting Workflow using(WorkflowRuntime workflowRuntime = new WorkflowRuntime()) { MyService1 myService = new MyService1(); workflowRuntime.AddService(myService); WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Workflow2)); instance.Start(); }

16 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Branch Condition IfElseActivity requires a condition to be defined for each of its branch These conditions are generally defined using the value of the properties of the workflow class Two types of conditions can be used Declarative Rule Condition – These conditions can be created using Visual Studio IDE and saved as an xml file with the extension rules Code Condition These conditions are defined as event handling methods The branch that does not have any condition assigned will be executed if no condition is met (if you have only two branches, the branch with no condition is the else branch)

17 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Workflow Class with a property public partial class Workflow2 : SequentialWorkflowActivity { private int marks; public int Marks { get { return marks; } set { marks = value; } }

18 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Defining a Declarative Rule Condition

19 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Code Condition Code condition is defined as a method in the workflow class as follows (CheckMarks method), public void CheckMarks(object sender, ConditionalEventArgs e) { if (marks > 50) e.Result = true; else e.Result = false; }

20 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Some useful activities DelayActivityDelay execution of workflow for a given amount of time InvokeWebServiceActivityInvoke a web service method ListenActivityThe first activity of each of the branch of this activity must be an event handling activity. This activity pause the workflow until any one of these event occurs and then continue along the branch correspond to that event ParallelActivityExecute each branch workflow in parallel TerminateActivityTerminate the workflow execution ThrowActivityThrow an exception TransactionScopeActivityExecute the sub activities in this activity inside a transaction WhileActivityExecute the sub activities until the given condition is met

21 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL State Machine Workflows These workflows contains a finite number of states Each state can have separate sequential sub workflows for, State initialization State finalization Respond to each predefined set of events State Machine workflow stats from the state marked as “Initial State” It ends at the state marked as “Completed State” (Note that only an empty state can be marked as a “Completed State” These workflows can have separate event handling workflows independent of the state Each sequential workflow can have separate “Cancel Handling” and “Fault Handling” Workflows

22 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL A Simple State Machine Workflow

23 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL An Event Handling Sub Workflow

24 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL RuleSets PolicyActivity can be used to apply a set of rules (a RuleSet) to the workflow parameters (properties of the workflow class) Rules are evaluate as follows Start with the list of active rules. Find the highest priority rule. Evaluate the rule and execute its Then/Else actions as appropriate. If the actions of a rule update a field/property that is used by a previous rule in the list (one with a higher priority), reevaluate that previous rule and execute its actions as appropriate. Note that only those rules with a specific dependency are reevaluated. Continue the process until all rules in the RuleSet have been evaluated.

25 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Creating a RuleSet

26 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Services Some of the operations in workflow runtime relies on external services provided by the hosting application of the workflow runtime. These services can be added to the runtime using AddService method These external services are Persistence Tracking Scheduling (process and thread scheduling) Transactions Workflow runtime creates default services for Scheduling and Transactions if the runtime host did not provide them WinFx comes with SQL Server based Persistence (SqlWorkflowPersistenceService) and Tacking (SqlTrackingService) services by default

27 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL SQL Server based services The database to be used by the SQL Server based services can be prepared by executing the SQL scripts in the following folder, %WinDir%\WinFX\v3.0\Windows Workflow Foundation\SQL\EN Both SqlWorkflowPersistenceService and SqlTrackingService services requires the connection strings to this database

28 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Persistence Service Workflow runtime can save its workflow execution states in a persistent storage if a persistence service is provided to it using “AddService” method We can make the runtime to save its execution states using “TryUload” method. “WorkflowIdled” event of the workflow runtime is a good place to do this. We have to save the instance id (in a database or in some other place) in order to reactivated a persisted work flow. This can be obtained using “WorkflowId” property of the workflow instance Persisted workflow can be reactivated using its instance id as follows, WorkflowInstance inst = wfRuntime.GetWorkflow(instanceId);

29 Copyright ©2004 Virtusa Corporation | CONFIDENTIAL Persistence Service (Unloading Example) void InitWorkflow () { wfRuntime = new WorkflowRuntime(); wfRuntime.WorkflowIdled += new EventHandler (wr_WorkflowIdled); SqlWorkflowPersistenceService persistanceService = new SqlWorkflowPersistenceService (persistDbConnectionString); wfRuntime.AddService (persistanceService); wfRuntime.StartRuntime (); } void wr_WorkflowIdled (object sender, WorkflowEventArgs e) { ThreadPool.QueueUserWorkItem (UnloadInstance, e.WorkflowInstance); } static void UnloadInstance (object workflowInstance) { ((WorkflowInstance) workflowInstance).TryUnload(); }