- 浏览: 112000 次
- 来自: ...
文章分类
最新评论
-
Juanjuel:
Django多表查询 -
chenokia:
那么在\grails-app\conf 下的DataSourc ...
Grails如何使用外部配置文件 -
viking2439:
有没有方法去指定用户去获得某个权限呢?
[django]总结Django中的用户权限模块
这几天在研究Windows Workflow Foundation,天天上www.windowsworkflow.net 的论坛上查看和询问,全都是英文,头都看大了,对这金山词霸一个一个的啃。闲话少说,步入正题吧!
本篇主要讲WF在asp.net运用。如下:
我的流程设置如下:
设置了一个CodeActive和一个HandleExternalEventActive
CodeActive是执行一段代码的Active
HandleExternalEventActive是外联一个Event的Active
首先,配置web.config
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<authentication mode="Windows"/>
<compilation debug="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="Microsoft.Build.Utilities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.Build.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
</system.web>
<!--注册服务-->
<WorkflowRuntime Name="WorkflowServiceContainer">
<Services>
<add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Activities.ExternalDataExchangeService, System.Workflow.Activities, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" UnloadOnIdle="true" ConnectionString="Initial Catalog=PersistenceStore;Data Source=localhost;Integrated Security=SSPI;"/>
<add type="System.Workflow.Runtime.Tracking.SqlTrackingService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ConnectionString="Initial Catalog=TrackingStore;Data Source=localhost;Integrated Security=SSPI;"/>
</Services>
</WorkflowRuntime>
<!--设置追踪,会在网站根目录下出现WFTrace.log文件-->
<system.diagnostics>
<switches>
<add name="WorkflowTraceToDefault" value="1" />
<add name="Host" value="All" />
<add name="Runtime" value="All" />
<add name="Tracking" value="All" />
<add name="Activity" value="All" />
<add name="Rules" value="All" />
</switches>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="WFTrace.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
简单介绍上面的配置文件
a.注册服务
这里是将一些服务注册到 Workruntime中,你也可以在代码中使用AddServcie中注册服务。
注册好服务后,就可以在代码中
ExternalDataExchangeService dataService = workflowRuntime.GetService<ExternalDataExchangeService>();
以上方式得到服务。
b.跟踪
配置跟踪信息,非常有用,我有一次调试的时候,MSDTC 服务没有启动的错误,就是查看WFTrace.log文件而获得的。
然后,在Global中启动一个WorkRunTime
接着,就可以在程序中运行workflow了
最后,运行代码后,当运行完上图中的CodeActive后,该workflowinstance将进入等待状态(会触发workflowRuntinme的WorkflowIdled事件)。
这个时候你如果注册了SqlWorkflowPersistenceService服务,和创建了PersistenceStore数据库,则会将此
工作流保存到数据库中,已备下次使用,关于这块下次我再整理。
为什么工作流会等待了,
因为接下来的环节HandleExternalEventActive的Active必须需要触发了和他相关联的事件后,他才会继续的。
所以,我可以针对workflowRuntinme增加WorkflowIdled事件,实现事件的代码如下:
这样这个工作流就整个的执行完成了。
本篇主要讲WF在asp.net运用。如下:
我的流程设置如下:
设置了一个CodeActive和一个HandleExternalEventActive
CodeActive是执行一段代码的Active
HandleExternalEventActive是外联一个Event的Active
首先,配置web.config
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<authentication mode="Windows"/>
<compilation debug="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="Microsoft.Build.Utilities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.Build.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
</system.web>
<!--注册服务-->
<WorkflowRuntime Name="WorkflowServiceContainer">
<Services>
<add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Activities.ExternalDataExchangeService, System.Workflow.Activities, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" UnloadOnIdle="true" ConnectionString="Initial Catalog=PersistenceStore;Data Source=localhost;Integrated Security=SSPI;"/>
<add type="System.Workflow.Runtime.Tracking.SqlTrackingService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ConnectionString="Initial Catalog=TrackingStore;Data Source=localhost;Integrated Security=SSPI;"/>
</Services>
</WorkflowRuntime>
<!--设置追踪,会在网站根目录下出现WFTrace.log文件-->
<system.diagnostics>
<switches>
<add name="WorkflowTraceToDefault" value="1" />
<add name="Host" value="All" />
<add name="Runtime" value="All" />
<add name="Tracking" value="All" />
<add name="Activity" value="All" />
<add name="Rules" value="All" />
</switches>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="WFTrace.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
简单介绍上面的配置文件
a.注册服务
这里是将一些服务注册到 Workruntime中,你也可以在代码中使用AddServcie中注册服务。
注册好服务后,就可以在代码中
ExternalDataExchangeService dataService = workflowRuntime.GetService<ExternalDataExchangeService>();
以上方式得到服务。
b.跟踪
配置跟踪信息,非常有用,我有一次调试的时候,MSDTC 服务没有启动的错误,就是查看WFTrace.log文件而获得的。
然后,在Global中启动一个WorkRunTime
void Application_Start(object sender, EventArgs e)
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime("WorkflowRuntime");
Application["WorkflowRuntime"] = workflowRuntime;
System.Workflow.ComponentModel.Compiler.TypeProvider typeProvider = new System.Workflow.ComponentModel.Compiler.TypeProvider(workflowRuntime);
typeProvider.AddAssembly(typeof(WorkflowLibrary1.Workflow1).Assembly);
workflowRuntime.AddService(typeProvider);
workflowRuntime.StartRuntime();
}
void Application_End(object sender, EventArgs e)
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as System.Workflow.Runtime.WorkflowRuntime;
workflowRuntime.StopRuntime();
}
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime("WorkflowRuntime");
Application["WorkflowRuntime"] = workflowRuntime;
System.Workflow.ComponentModel.Compiler.TypeProvider typeProvider = new System.Workflow.ComponentModel.Compiler.TypeProvider(workflowRuntime);
typeProvider.AddAssembly(typeof(WorkflowLibrary1.Workflow1).Assembly);
workflowRuntime.AddService(typeProvider);
workflowRuntime.StartRuntime();
}
void Application_End(object sender, EventArgs e)
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as System.Workflow.Runtime.WorkflowRuntime;
workflowRuntime.StopRuntime();
}
接着,就可以在程序中运行workflow了
private void StartWorkflow()
{
WorkflowRuntime workflowRuntime = StartRuntime();
// Now get a refernece to the ManualWorkflowSchedulerService
ManualWorkflowSchedulerService scheduler =
workflowRuntime.GetService<ManualWorkflowSchedulerService>();
// Attach to the WorkflowCompleted event
workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(WorkflowRuntime_WorkflowCompleted);
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(WorkflowLibrary1.Workflow1));
workflowInstance.Start();
// Now run the workflow. This is necessary when
// using the ManualWorkflowSchedulerService
scheduler.RunWorkflow(workflowInstance.InstanceId);
}
private WorkflowRuntime StartRuntime()
{
WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as WorkflowRuntime;
ExternalDataExchangeService dataService = workflowRuntime.GetService<ExternalDataExchangeService>();
OrderLocalServices.OrderService orderService = workflowRuntime.GetService<OrderLocalServices.OrderService>();
if (orderService == null)
{
orderService = new OrderLocalServices.OrderService();
dataService.AddService(orderService);
}
// Attach to the WorkflowCompleted event
workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(WorkflowRuntime_WorkflowCompleted);
return workflowRuntime;
}
{
WorkflowRuntime workflowRuntime = StartRuntime();
// Now get a refernece to the ManualWorkflowSchedulerService
ManualWorkflowSchedulerService scheduler =
workflowRuntime.GetService<ManualWorkflowSchedulerService>();
// Attach to the WorkflowCompleted event
workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(WorkflowRuntime_WorkflowCompleted);
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(WorkflowLibrary1.Workflow1));
workflowInstance.Start();
// Now run the workflow. This is necessary when
// using the ManualWorkflowSchedulerService
scheduler.RunWorkflow(workflowInstance.InstanceId);
}
private WorkflowRuntime StartRuntime()
{
WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as WorkflowRuntime;
ExternalDataExchangeService dataService = workflowRuntime.GetService<ExternalDataExchangeService>();
OrderLocalServices.OrderService orderService = workflowRuntime.GetService<OrderLocalServices.OrderService>();
if (orderService == null)
{
orderService = new OrderLocalServices.OrderService();
dataService.AddService(orderService);
}
// Attach to the WorkflowCompleted event
workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(WorkflowRuntime_WorkflowCompleted);
return workflowRuntime;
}
最后,运行代码后,当运行完上图中的CodeActive后,该workflowinstance将进入等待状态(会触发workflowRuntinme的WorkflowIdled事件)。
这个时候你如果注册了SqlWorkflowPersistenceService服务,和创建了PersistenceStore数据库,则会将此
工作流保存到数据库中,已备下次使用,关于这块下次我再整理。
为什么工作流会等待了,
因为接下来的环节HandleExternalEventActive的Active必须需要触发了和他相关联的事件后,他才会继续的。
所以,我可以针对workflowRuntinme增加WorkflowIdled事件,实现事件的代码如下:
void workflowRuntime_WorkflowIdled(object sender, WorkflowEventArgs e)
{
WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"]
OrderService orderService = workflowRuntime.GetService<OrderService>();
WorkflowInstance instance = workflowRuntime.GetLoadedWorkflows()[0];
instance.Load();
//触发相关联的事件
orderService.RaiseOrderUpdatedEvent(instance.InstanceId);
}
{
WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"]
OrderService orderService = workflowRuntime.GetService<OrderService>();
WorkflowInstance instance = workflowRuntime.GetLoadedWorkflows()[0];
instance.Load();
//触发相关联的事件
orderService.RaiseOrderUpdatedEvent(instance.InstanceId);
}
这样这个工作流就整个的执行完成了。
发表评论
-
IBatisNet系列-介绍篇
2006-03-25 14:56 981IBatisNET从名字就可以看出,他是从Java的IBati ... -
IBatisNet系列二-QuickStart篇
2006-03-25 14:59 936本节我参考官方网站上的Quick Start Guide,网址 ... -
IBatisNet系列-执行存储过程
2006-03-25 15:24 1123映射xml文件书写如下 <?xml version=& ... -
IBatis.Net系列-Mapped Statements的语法
2006-03-29 15:25 852语法:<statement id="state ... -
Castle- Startable Facility 简单理解
2006-03-30 17:56 842最近在研究Castle开源项目,就下午学习Startable ... -
IBatis.Net系列-多参数的SQL语句的配置
2006-04-15 12:15 1419由于本人对IBatis.Net的并不是很精通,也是在边学边工作 ... -
MonoRail学习-介绍篇
2006-04-24 10:22 722刚刚结束了使用Castle MonoRail的一个项目,所以想 ... -
MonoRail学习-入门实例篇
2006-04-24 11:51 1270MonoRail学习目录实例代码下载:/Files/maply ... -
MonoRails学习- Layouts
2006-04-24 12:14 790MonoRail学习目录实例代码:/Files/maplye/ ... -
MonoRail学习-Component
2006-04-24 13:30 693MonoRail学习目录在我们asp.net中,经常有界面代码 ... -
Which Style of Workflow When?[转]
2006-05-24 16:58 719http://blogs.msdn.com/davegreen ... -
WF学习-Console Workflow Application
2006-05-26 16:51 888环境必备:.NET Framework 2.0VS.Net 2 ... -
WF学习-WorkFLow中的参数
2006-05-27 15:46 1115系统和WorkFlow交互有很多种方式,今天介绍的是通过Wor ... -
Castle ActiveRecord.chm
2006-05-31 18:06 724收集 TerryLee's Tech Space 和 SHY5 ... -
使用UserControl时,在Page中定义方式
2006-06-24 10:02 878我们通常,会将一些通用的页面模块作成用户控件,然后加载到页面中 ... -
ASP.Net2.0中自定义控件在page中的注册
2006-06-24 14:15 787今天在网上看到ASP.Net 2.0中注册自定义控件的好方法, ... -
Asp.Net中NHiernate的Session的管理
2006-06-26 11:08 644NHibernate中的Session,在我的理解似乎就相当于 ... -
GridView使用一些记录
2006-06-30 10:45 911现在有个项目开始使用ASP.NET 2.0开发,在开发过程中关 ... -
NHiernate中自定义Generator
2006-07-04 13:50 876我的这个自定义的Generator设置如下: <g ... -
NHibernate中使用generator为assigned的问题
2006-07-04 14:03 1830Hibernate version: 1.0.2.0 Mapp ...
相关推荐
What you'll learn WF 4.0 basics New activities and changes to existing activities in WF 4.0 Customizing your workflows Accessing your workflows in a variety of ways in a variety of situations Using WF...
Customizing your workflows * Accessing your workflows in a variety of ways in a variety of situations * Using WF with Web Services and ASP.NET * Integrating WCF and WF Who this book is for This book ...
Find complete coverage of the WPF, WCF, and WF foundations that support the core .NET platform. Who is this book for? This book is for anyone with some software development experience who is ...
书中介绍了c#的各种语言构造、.net 2.0的类、核心api、公共中间语言(cil)、动态程序集和asp.net扩展等内容;同时也介绍了.net 3.0和.net 3.5中新的编程api,包括wpf 、wcf和wf 的功能;另外,还介绍了最新的c# 3.0...
Includes all Xceed user interface, data manipulation and ASP.NET components. The only suite that offers both UI tools for application front-ends and data-handling libraries for application back-ends....
Discover all the new .NET 3.5 features nullable types, delegate covariance, ASP.NET 2.0 master pages, the new Windows Forms controls, and much more. Get a professional foothold targeted to ...
Pro ASP.NET 4 in C# 2010, Fourth Edition Illustrated C# 2010 Accelerated C# 2010 Visual Basic 2010 学习资源 Microsoft Visual Basic 2010 Step by Step Professional Visual Basic 2010 and .NET 4 ...
This is a step by step hand-on lab for WF from Microsoft Switzerland. In this Hands-On-Lab you will create a State Machine Workflow and integrate it in an existing ASP.NET Web Application.
This is a step by step hand-on lab for WF from Microsoft Switzerland. In this Hands-On-Lab you will create a State Machine Workflow and integrate it in an existing ASP.NET Web Application.
Beginning_WF_Windows_Workflow_in_NET_4:源码
How to build web applications using ASP.NET AJAX, Silverlight, and ASP.NET MVC Ideas for building Office and Mobile applications, WPF, WCF, and WF projects Ways to effectively analyze and identify ...