<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Leric&#039;s Blog &#187; state machine workflow</title>
	<atom:link href="http://www.leric.info/tag/state-machine-workflow/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leric.info</link>
	<description>Temec Nosce</description>
	<lastBuildDate>Sun, 18 Apr 2010 02:32:41 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>在ASP.net中使用State Machine Workflow</title>
		<link>http://www.leric.info/post/60.htm</link>
		<comments>http://www.leric.info/post/60.htm#comments</comments>
		<pubDate>Sun, 29 Nov 2009 09:07:34 +0000</pubDate>
		<dc:creator>Leric</dc:creator>
				<category><![CDATA[计算机技术]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[state machine workflow]]></category>
		<category><![CDATA[workflow]]></category>
		<category><![CDATA[工作流]]></category>
		<category><![CDATA[状态机]]></category>

		<guid isPermaLink="false">http://leric.net.cn/?p=60</guid>
		<description><![CDATA[在ASP.net里应用Workflow和客户端程序中差别还是很大的，但这本Pro WF书里对这部分一笔带过，给了个顺序工作流的例子，但看完了还是没什么头绪，后天来找到了一个例子，才弄明白了怎么做。
首先，在ASP.net的Web应用里，因为和用户交互是单线程的，异步的执行是没法把结果反馈给用户的，所以需要以同步（Synchronized）的方式执行工作流，这就需要创建一个ManualWorkflowSchedulerService得实例schedule，注册到WorkflowRuntime上，来覆盖了默认的DefaultWorkflowSchedulerService。在创建了Workfow Instance并调用了instance.Start()的时候，工作流还并没有开始运行，但已经On schedule了，这时候再调用schedule.RunWorkflow(instance.InstanceId)，这时工作流就开始执行了，RunWorkflow会在工作流进入等待，或者结束的时候返回。
另外就剩下工作流运行环境初始化的问题了。这部分工作可以在Global.asax文件里完成，一个ASP.net应用里，WorkflowRuntime的实例只需要又一个，所以在各个页面里去初始化就太浪费了，在Application_Start和Application_End里完成WorkflowRuntime的初始化和清理工作：
void Application_Start(object sender, EventArgs e)
{
	System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime(&#34;WorkflowRuntime&#34;);
	System.Workflow.ComponentModel.Compiler.TypeProvider typeProvider = new System.Workflow.ComponentModel.Compiler.TypeProvider(workflowRuntime);
	typeProvider.AddAssembly(typeof(Ganji.OA.Workflow.ExpensesClaim).Assembly);
	workflowRuntime.AddService(typeProvider);
	workflowRuntime.StartRuntime();
	Application[&#34;WorkflowRuntime&#34;] = workflowRuntime;
}

void Application_End(object sender, EventArgs e)
{
	System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application[&#34;WorkflowRuntime&#34;] as System.Workflow.Runtime.WorkflowRuntime;
	workflowRuntime.StopRuntime();
}
That’s all
]]></description>
			<content:encoded><![CDATA[<p>在ASP.net里应用Workflow和客户端程序中差别还是很大的，但这本Pro WF书里对这部分一笔带过，给了个顺序工作流的例子，但看完了还是没什么头绪，后天来找到了一个<a href="http://blogs.msdn.com/tomlake/archive/2006/05/17/examples-of-using-persistence-and-tracking-in-asp-net.aspx">例子</a>，才弄明白了怎么做。</p>
<p>首先，在ASP.net的Web应用里，因为和用户交互是单线程的，异步的执行是没法把结果反馈给用户的，所以需要以同步（Synchronized）的方式执行工作流，这就需要创建一个ManualWorkflowSchedulerService得实例schedule，注册到WorkflowRuntime上，来覆盖了默认的DefaultWorkflowSchedulerService。在创建了Workfow Instance并调用了instance.Start()的时候，工作流还并没有开始运行，但已经On schedule了，这时候再调用schedule.RunWorkflow(instance.InstanceId)，这时工作流就开始执行了，RunWorkflow会在工作流进入等待，或者结束的时候返回。</p>
<p>另外就剩下工作流运行环境初始化的问题了。这部分工作可以在Global.asax文件里完成，一个ASP.net应用里，WorkflowRuntime的实例只需要又一个，所以在各个页面里去初始化就太浪费了，在Application_Start和Application_End里完成WorkflowRuntime的初始化和清理工作：</p>
<pre class="c-sharp" name="code">void Application_Start(object sender, EventArgs e)
{
	System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime(&quot;WorkflowRuntime&quot;);
	System.Workflow.ComponentModel.Compiler.TypeProvider typeProvider = new System.Workflow.ComponentModel.Compiler.TypeProvider(workflowRuntime);
	typeProvider.AddAssembly(typeof(Ganji.OA.Workflow.ExpensesClaim).Assembly);
	workflowRuntime.AddService(typeProvider);
	workflowRuntime.StartRuntime();
	Application[&quot;WorkflowRuntime&quot;] = workflowRuntime;
}

void Application_End(object sender, EventArgs e)
{
	System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application[&quot;WorkflowRuntime&quot;] as System.Workflow.Runtime.WorkflowRuntime;
	workflowRuntime.StopRuntime();
}</pre>
<p>That’s all</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leric.info/post/60.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
