building you build process with windows workflow foundation

46
Building you build process with Windows Workflow Foundation Abid Quereshi

Upload: zubin

Post on 14-Jan-2016

110 views

Category:

Documents


0 download

DESCRIPTION

Building you build process with Windows Workflow Foundation. Abid Quereshi. Agenda. Existing build technologies Promise of Workflow Foundation Demonstration – reusing Nant scripts Demonstration - Custom Task Authoring Modes Serialization and Deserialization Designer Re-Hosting. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Building you build process with Windows Workflow Foundation

1

Building you build process with Windows Workflow Foundation

Abid Quereshi

Page 2: Building you build process with Windows Workflow Foundation

2

Agenda

Existing build technologies

Promise of Workflow Foundation

Demonstration – reusing Nant scripts

Demonstration - Custom Task

Authoring Modes

Serialization and Deserialization

Designer Re-Hosting

Page 3: Building you build process with Windows Workflow Foundation

3

Cruise Control

MS Build

Nant/Ant

Visual Build

Automated Build Studio

DB Change management tools (DB Ghost, Embarcadero)

Make files, batch files, any other

Existing build technologies

Page 4: Building you build process with Windows Workflow Foundation

4

Motivation for new way of building software

Existing build technologies

ObjectivesVisual Configuration (script free)

Real-time distributed feedback

Parallel Task processing

Cheap

Page 5: Building you build process with Windows Workflow Foundation

5

Promise of Windows Workflow Foundation

Design by markup

Access to high level programming language- Threading, tracing, events

End user configuration

Possibilities that WF provides

Page 6: Building you build process with Windows Workflow Foundation

6

Promise of Windows Workflow Foundation

Co-ordinate work performed by people and software

Long-running and stateful

Based on extensible models

Transparent and dynamic throughout their life cycle

The Four Workflow Tenants:

Page 7: Building you build process with Windows Workflow Foundation

7

Promise of Windows Workflow Foundation

Build technologies

New software development technologies and platforms

Configuration

Motive for a Dynamic Build process

Page 8: Building you build process with Windows Workflow Foundation

8

Promise of Windows Workflow Foundation

ScenarioCheckout

Start

Compile in Release configuration

Compile in Debug configuration

Deploy

Stop

ConfigMode = Release?

Page 9: Building you build process with Windows Workflow Foundation

9

Promise of Windows Workflow Foundation

Reuse of existing scripts and build technologies

Example of a code only workflow

Build script encapsulation demo

Page 10: Building you build process with Windows Workflow Foundation

10

Authoring Modes

Promise of Windows Workflow Foundation

Code Only

Markup (XAML) + Compiled Code Beside

Full Visual Studio Support

Some Visual Studio Support + Prayer

Markup + Assembly binding

Page 11: Building you build process with Windows Workflow Foundation

11

Custom Activities

Workflow Customization

Part of Workflow tenants (Based on extensible models)

Reusable components

Possibility of Software Build DSL

Page 12: Building you build process with Windows Workflow Foundation

12

Domain Specific Language

Workflow Customization

Limited form of computer language designed for a specific class of problems.

Library(Framework) + Configuration (Process, algorithm or how to perform a process)

Most Frameworks in a particular platform address technical concerns

DSL’s address business concerns (Higher level level of abstraction)

Page 13: Building you build process with Windows Workflow Foundation

13

Domain Specific Language

Workflow Customization

DSL’s typically come with a code generation tool

• Constraint syntax• Accessible to non-developers

Page 14: Building you build process with Windows Workflow Foundation

14

Domain Specific Language

Workflow Customization

• May require a Parser• Schemas help to validate instructions• Algorithm Syntax - what is being said – is limited

Page 15: Building you build process with Windows Workflow Foundation

15

Domain Specific Language

Workflow Customization

Algorithm Syntax - what is being said – is limited

How it is being said may take two forms• Internal DSL - syntax of instruction is a subset of host

general purpose language code• External DSL – often a configuration file

Page 16: Building you build process with Windows Workflow Foundation

16

Custom Workflow

Workflow Customization

SequentialWorkflowActivity

SequenceActivity

CompositeActivity

Activity

DependencyObject<abstract>

MyCustomWorkflow

MyCustomActivity

System.Workflow.ComponentModel

Page 17: Building you build process with Windows Workflow Foundation

17

Activity Class

Workflow Customization

Methods to override:

• Execute• Cancel• Initialize

These are called by the WF runtime – not manually

Activity

DependencyObject<abstract>

Execute(ActivityExecutionContext):ActivityExecutionContext Cancel(ActivityExecutionContext):ActivityExecutionContext Initialize(IServiceProvider)

Page 18: Building you build process with Windows Workflow Foundation

18

Activity Class State

Workflow State

Compensating

Closed FaultingCanceling

Executing

Initialized

Page 19: Building you build process with Windows Workflow Foundation

19

Dependency Object & Dependency Properties

Workflow State

DependencyObject<abstract>

• Activity data storage mechanism• Allows activities to project their properties onto their

children• Essential provision for WF tenent (Long-running and

stateful)

Page 20: Building you build process with Windows Workflow Foundation

20

Dependency Object

Workflow State

• Hash table

• Essential provision for WF tenant (Long-running and stateful)

• Add a public static instance of Dependency Property to manage that property for all instances of the activity

• Implement .NET Property that accesses an activities Dependency Property

Page 21: Building you build process with Windows Workflow Foundation

21

Dependency Properties

Workflow State

Must derive from DependencyObject

Register property then define property

Page 22: Building you build process with Windows Workflow Foundation

22

Dependency Properties

Workflow State

public static DependencyProperty MyDepPropProperty = DependencyProperty.Register( “MyDepProp",

typeof(String), typeof(MyClass));

Property name

Property Type

Owner Type

Page 23: Building you build process with Windows Workflow Foundation

23

Dependency Properties

Workflow State

public String CompilationMode{ get { return (String)(base.GetValue(MyClass. MyDepPropProperty)); } set { base.SetValue(MyClass.MyDepPropProperty, value); }}

Page 24: Building you build process with Windows Workflow Foundation

24

Parameter Passing

Workflow State

Dictionary<String, Object> Args = new Dictionary<string, object>();

Args.Add("RepositorySource", "C:\\Projects\\BuildManager\\Repository");

Args.Add("CompilationMode", "Release");

Args.Add("Application", "C:\\Projects\\BuildManager\\Checkout\\BuildMeWinApp\\BuildMeWinApp.sln");

Args.Add("Target", "C:\\Projects\\BuildManager\\BuildTarget");

WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(BuildTasks.Builder), Args);

Page 25: Building you build process with Windows Workflow Foundation

25

Custom Workflow

Domain specific activities

Domain specific workflow

Example of Code+Markup workflow

Build custom workflow demo

Page 26: Building you build process with Windows Workflow Foundation

26

Markup

Authoring Modes

<SequentialWorkflowActivity x:Class="MarkupBuild.Build" x:Name="Build"

xmlns:ns0="clr-namespace:BuildTasks;Assembly=BuildTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">

<ns0:Checkout BuildFile="{x:Null}" x:Name="checkout1" RepositorySource="{x:Null}" />

<ns0:Compile BuildFile="{x:Null}" x:Name="compile1" CompilationMode="{x:Null}" Application="{x:Null}" />

<ns0:Deploy BuildFile="{x:Null}" x:Name="deploy1" CompilationMode="{x:Null}" Target="{x:Null}" />

</SequentialWorkflowActivity>

Page 27: Building you build process with Windows Workflow Foundation

27

XOML

Authoring Modes

Extensible Orchestration Markup Language (XOML) files, a special case of XAML file types, which specify the workflow logic within an application.

Page 28: Building you build process with Windows Workflow Foundation

28

Binding

Authoring Modes

<SequentialWorkflowActivity x:Class="MarkupBuild.Build" x:Name="Build"

xmlns:ns0="clr-namespace:BuildTasks;Assembly=BuildTasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">

<ns0:Checkout x:Name="checkout1" RepositorySource="{ActivityBind Build,Path=RepositorySource}" />

<ns0:Compile x:Name="compile1" CompilationMode="{ActivityBind Build,Path=CompilationMode}" Application="{ActivityBind Build,Path=Application}" />

<ns0:Deploy x:Name="deploy1" Target="{ActivityBind Build,Path=Target}" CompilationMode="{ActivityBind Build,Path=CompilationMode}" />

</SequentialWorkflowActivity>

Page 29: Building you build process with Windows Workflow Foundation

29

Authoring Modes

Binding

gives a dependency property an ActivityBind object to evaluate when asked for its value

ActivityBind can point to other fields, properties, or methods of activities inside a workflow.

One activity could bind its input properties to a previous activity's outputs.

Binding makes the data flow a part of the workflow model.

Page 30: Building you build process with Windows Workflow Foundation

30

Markup-only workflows

Authoring Modes

Allows for declarative programming

Facilitates the highest degree of encapsulation

Facilitates usage of code-generation tool

Requires mechanism to serialize and deserialize WF

Page 31: Building you build process with Windows Workflow Foundation

31

Serialization

Serialization

Serialization

Create a XAML workflow markup file from an in-memory workflow model

Deserialization

Reads markup and creates in-memory object containing definition of workflow model

Page 32: Building you build process with Windows Workflow Foundation

32

Serialization

Serialization

private static void SerializeToMarkup(Activity workflow, String fileName)

{

try

{

using (XmlWriter xmlWriter = XmlWriter.Create(fileName))

{

WorkflowMarkupSerializer mrkupSerializer = new WorkflowMarkupSerializer();

mrkupSerializer.Serialize(xmlWriter, workflow);

}

}

catch (Exception e)

{

Console.WriteLine("Exception during serialization: {0}" e.Message);

}

}

Page 33: Building you build process with Windows Workflow Foundation

33

Serialization

Deserializer needs knowledge of the types referenced in the markup

ServiceContainer, TypeProvider, DesignSerializationManager

Deserialization

Page 34: Building you build process with Windows Workflow Foundation

34

Serialization

Activity workflow = null;

ServiceContainer container = new ServiceContainer();

Add a TypeProvider to resolve BuildTask references

TypeProvider provider = new TypeProvider(container);

provider.AddAssembly(typeof(SharedWorkflows.MarkupOnlyBaseWorkflow).Assembly);

container.AddService(typeof(ITypeProvider), provider);

Add ServiceContainer with the TypeProvider to serialization manager

DesignerSerializationManager dsm = new DesignerSerializationManager(container);

XmlReader xmlReader = XmlReader.Create(fileName)

WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer();

workflow = markupSerializer.Deserialize(dsm, xmlReader) as Activity;

Page 35: Building you build process with Windows Workflow Foundation

35

Designer Re-Hosting

Code generation tool

Configurable by end user

Page 36: Building you build process with Windows Workflow Foundation

36

Introduction

Designer Re-hosting

The logic of a build process is often simple enough for to allow drag and drop process design by non-developers

WF allows for re-hosting the workflow designer in a windows application (outside of the Visual Studio environment)

Powerful proposition

Page 37: Building you build process with Windows Workflow Foundation

37

Designer Classes

System.ComponentModel.Design.DesignSurface

General-purpose design canvas

System.Workflow.ComponentModel.Design.

WorkflowDesignerLoader

Serialization/Deserialization

Loading of services used by the designer

System.Workflow.ComponentModel.Design.WorkflowView

Implements visual representation of your workflow model

Page 38: Building you build process with Windows Workflow Foundation

38

Designer Classes

IDesignerHost

Persisted Workflow Models

(.xoml files)

Design Surface

MyDesignerLoader: WorkflowDesignerLoader

Load services and populate visual treeIRootDesigner

WorkflowView

BeginLoad method

GetServices method

GetDesigner method

GetView method

Page 39: Building you build process with Windows Workflow Foundation

39

Property Attributes

Designer Re-hosting

Description

Category

Browsable

DesignerSerializationVisibility

Page 40: Building you build process with Windows Workflow Foundation

40

Designer Re-hosting

Abstract

Must be implemented in a derived class

Responsible for loading workflow from peristable tore .xoml and populating tree of visual objects in the designer and Vise-Versa

WorkflowDesignerLoader

Page 41: Building you build process with Windows Workflow Foundation

41

Designer Re-hosting

Services

IMenuCommandService

ITypeProvider

IToolboxService

IPropertyValueUIService

IEventBindingService

Page 42: Building you build process with Windows Workflow Foundation

42

Designer Re-hosting

Demo

Simple workflow

Workflow with conditional branch

Page 43: Building you build process with Windows Workflow Foundation

43

Conclusion

Revisiting Objectives

Visual Configuration (script free)

Real-time distributed feedback

Parallel Task processing

Cheap

Page 44: Building you build process with Windows Workflow Foundation

44

Conclusion

Real-time distributed feedback

Limitation is due to fact that WF Markup is a subset of XAML – the markup parser is not extensible

Parallel Task processing

Parallel task activity is not multithreaded

This can be implemented but it’s not out-of-the box functionality

Page 45: Building you build process with Windows Workflow Foundation

45

Conclusion

References

• Pro WF Windows Workflow in .NET 3.0, Apress, Bruce Bukovics

• Professional Windows Workflow Foundation, Wrox, Todd Kitta

• Introduction to Domain Specific Languages, Martin Fowler, http://www.infoq.com/presentations/domain-specific-languages

Page 46: Building you build process with Windows Workflow Foundation

46

Blank Slide

Serialization