Sep 9, 2009

WF 4.0 Persistence

Day 3 starts with a recap of what we have done so far with WF4, including the

Testing practices

we did. Important here:

  • isolate dependecies (e.g. web service send/receive activities)
  • design workflow for testability (like creating testable sub workflows and putting all the untestable plumbing activities into a top-level workflow

Today we will have a look at the new workflow persistence concepts in WF4.0. There are samples to look at.

Workflow persistence

is a must for long-running workflows. An important concept here are bookmarks which are a kind of marker for unloaded/persisted workflow instances that can be resumed. What was formerly known as workflow services are now extensions. A persistence provider creates a provider to persist your instances. There is one provider for SQL Server at the moment as far as we’ve seen.

static SqlPersistenceProviderFactory persistenceProviderFactory;
persistenceProviderFactory = new SqlPersistenceProviderFactory(@"Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\SampleInstanceStore.mdf; Integrated Security=True", false, false, TimeSpan.FromSeconds(60));

// start, unload, run
WorkflowInstance instance = new WorkflowInstance(myWorkflow);
id = instance.Id; 
instance.OnIdle = () => IdleAction.Unload;
instance.OnUnloaded = () => instanceUnloaded.Set();

// load, resume
PersistenceProvider persistenceProvider = persistenceProviderFactory.CreateProvider(id);
WorkflowInstance instance = WorkflowInstance.Load(activity, persistenceProvider);
instance.OnUnloaded = () => instanceUnloaded.Set(); 
instance.ResumeBookmark(readLineBookmark, input);


No comments:

Post a Comment