15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The Workflow runtime ❘ OC301<br />

In Figure 57-18, we have selected the OrderDate property of a workflow (OrderDate is defined as a regular<br />

.<strong>NET</strong> property on the workflow). Any bindable property can be bound to either a property of the workflow<br />

that the activity is defined within or a property of any activity that resides in the workflow above the current<br />

activity. Note that the data type of the property being bound must match the data type of the property you<br />

are binding to — the dialog will not permit you to bind nonmatching types.<br />

figure 57-18<br />

The code for the Date property is shown here to show how binding works <strong>and</strong> is explained in the following<br />

paragraphs:<br />

public DateTime Date<br />

{<br />

get { return (DateTime)base.GetValue(DaysOfWeekActivity.DateProperty); }<br />

set { base.SetValue(DaysOfWeekActivity.DateProperty, value); }<br />

}<br />

When you bind a property in the workflow, an object of type ActivityBind is constructed behind the<br />

scenes, <strong>and</strong> it is this “value” that is stored within the dependency property. So, the property setter will<br />

be passed an object of type ActivityBind, <strong>and</strong> this is stored within the dictionary of properties on this<br />

activity. This ActivityBind object consists of data that describes the activity being bound to <strong>and</strong> the<br />

property of that activity that is to be used at runtime.<br />

When reading the value of the property, the GetValue method of the DependencyObject is called, <strong>and</strong> this<br />

method checks the underlying property value to see if it is an ActivityBind object. If so, it resolves the<br />

activity to which this binding is linked <strong>and</strong> then reads the real property value from that activity. If, however,<br />

the bound value is another type, it simply returns that object from the GetValue method.<br />

The WorKfloW runTime<br />

In order to start a workflow, it is necessary to create an instance of the WorkflowRuntime class. This is<br />

typically done once within your application, <strong>and</strong> this object is usually defined as a static member of the<br />

application so that it can be accessed anywhere within the application.<br />

When you start the runtime, it can then reload any workflow instances that were executing the last time the<br />

application was executed by reading these instances from the persistence store. This uses a service called<br />

the persistence service, which is defined in the following section.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!