【发布时间】:2011-05-04 13:11:31
【问题描述】:
我将 WF 4 与 ASP.NET 一起使用,作为工作流的一部分,系统可能需要重定向到其他页面,以便用户在某些情况下输入其他信息。一旦他们输入了这些信息,系统就需要从中断的地方恢复工作流程。
到目前为止,我在启动流程的初始页面中拥有此代码,并在工作流中设置书签的活动。
static InstanceStore instanceStore;
static AutoResetEvent instanceUnloaded = new AutoResetEvent(false);
static Guid id;
protected void Page_Load(object sender, EventArgs e)
{
SetupInstanceStore();
}
protected void btnStartWorkflow_Click(object sender, EventArgs e)
{
app = Session["applicant"];
Dictionary<string, object> workflowInputs = new Dictionary<string, object>();
workflowInputs.Add("Applicant", app.Applicant);
WorkflowApplication workflowApplication = new WorkflowApplication(new IdentityCheckActivites.IdentityCheckWorkflow(), workflowInputs);
workflowApplication.InstanceStore = instanceStore;
//returning IdleAction.Unload instructs the WorkflowApplication to persist application state and remove it from memory
workflowApplication.PersistableIdle = (a) =>
{
return PersistableIdleAction.Persist;
};
workflowApplication.Unloaded = (a) =>
{
instanceUnloaded.Set();
};
workflowApplication.Completed = (a) =>
{
instanceUnloaded.Set();
};
workflowApplication.Persist();
id = workflowApplication.Id;
workflowApplication.Run();
Session["id"] = id;
workflowApplication.Idle = (a) =>
{
instanceUnloaded.Set();
};
instanceUnloaded.WaitOne();
var bookmarks = workflowApplication.GetBookmarks();
if (bookmarks != null && bookmarks[0].OwnerDisplayName == "CC")
{
workflowApplication.Unload();
Context.Response.Redirect("SecondPage.aspx");
}
Context.Response.Redirect("FinalPage.aspx");
}
private static void SetupInstanceStore()
{
instanceStore = new SqlWorkflowInstanceStore(@"Data Source=xxx;Initial Catalog=SampleInstanceStore;User Id=xxx;Password=xxx;Asynchronous Processing=True");
InstanceHandle handle = instanceStore.CreateInstanceHandle();
InstanceView view = instanceStore.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
handle.Free();
instanceStore.DefaultInstanceOwner = view.InstanceOwner;
}
这似乎工作得很好,因为它将工作流保存到数据库中,如果设置了书签,我想重定向到第二个页面,以便用户输入更多数据。
这是我遇到问题的代码部分:-
var bookmarks = workflowApplication.GetBookmarks();
if (bookmarks != null && bookmarks[0].OwnerDisplayName == "CC")
{
workflowApplication.Unload();
Context.Response.Redirect("SecondPage.aspx");
}
Context.Response.Redirect("FinalPage.aspx");
如果设置了书签,我会重定向到中间页面,如果没有并且不需要用户干预,则页面将重定向到最终页面。
如果设置了书签,则此方法有效,但如果未设置,则 workflowApplication.GetBookmarks() 语句会引发异常,告诉我工作流已完成。
在这个阶段我似乎无法找到一种方法来检测工作流所处的状态,以便我可以重定向到相关页面。
也许我总体上有错误的想法,尽管我搜索了很多,但我似乎找不到关于这个主题的很多指导。
有什么想法吗?
谢谢,
吉姆。
【问题讨论】:
标签: asp.net workflow-foundation workflow-foundation-4