Ending a page flow

Topics: Web Client Software Factory, User Forum
Mar 27, 2007 at 11:02 AM
How do you end a page flow. I have a 3 step process ans I call MyPageFlow.Complete() on a button on the the last page. However when I click the link to start the process again I am sent to the last page of the flow. How do I clear out the current state after the complete is called?

I may also want to have the state cleared out anytime I hit a link on the sitemap, is this possible because in a previous project I had a requirement that a process could be restarted anytime by clicking the navigation.
Developer
Mar 27, 2007 at 2:45 PM
Hi SilverStirling, there are two ways for terminating a page flow.

As you said one is calling the Complete method and the other is calling the Abort method.

From docs:

“When a page flow successfully completes, you call the Complete method. This method ends the page flow instance and clears the information from the persistence store. This means you cannot resume a page flow that has been completed.“

“You use the Abort method to explicitly terminate a page flow instance before it completes. Like the Complete method, Abort ends the page flow instance and clears the information from the persistence store. If you specify true for the argument value, the provider redirects the page specified in the AbortUrl property of the page flow definition.”

The state is cleared when the workflow is completed or terminated. If you need to clear the state besides these events, you need to do that manually by getting all the keys form the "UserData" collection and calling "Remove" for each of one.

foreach (string key in StorePageFlow.UserData.Keys)
{
     StorePageFlow.UserData.Remove(key);
}
You can know the state of the page flow, using the property Status ie: “StorePageFlow.Status”.

The PageFlowStatus is an enum with the following options

  • NotStarted
  • Running
  • Terminated
  • Suspended

Also you can use the Abort method to restart your PageFlow.

public void Restart()
{
     StorePageFlow.Abort(false);
     StartNewProcess();
}
 
public void StartNewProcess()
{
     StorePageFlow.Start();
     StorePageFlow.RedirectToCurrentPage();
}
Take a look to the PageFlow Quickstarts, included in the WCSF SourceCode.

Let me know if this helps,
Ezequiel Jadib
http://staff.southworks.net/blogs/ejadib
Apr 2, 2007 at 9:06 AM
Thanks Ezequiel,

I had something like this previously, but I keep getting this error message:

Event "SetData" on interface type "Microsoft.Practices.PageFlow.WorkflowFoundation.IDataExchangeService" for instance id "1dd1b4f1-8399-44f6-90c9-1f0ff86ac63a" cannot be delivered.

I thought I was doing something wrong with the abort. Any ideas?
Developer
Apr 3, 2007 at 1:27 PM
Edited Apr 3, 2007 at 1:28 PM
Hi SilverStirling, the exception is thrown because the controller tries to start a pageflow that had been aborted.

Please try this and tell me if helps you.

Replace:

public void RestartShopping()
{
   StorePageFlow.Abort(false);
   StartNewProcess();
}
With this:
public void RestartShopping()
{
    StorePageFlow.Abort(false);
    _storePageFlow = null;
    StartNewProcess();
}
BTW - this is a bug in the PageFlowWithShoppingCart QuickStart. Thanks for the feedback.

Ezequiel Jadib
http://staff.southworks.net/blogs/ejadib
Apr 4, 2007 at 12:34 PM
Worked a treat,

thanks for the help.

S.