workflow学习笔记1,workflow运行时
2010-03-20 19:33
369 查看
当你在workflow环境中执行任务时,需要一些minitor来监视整个的代码执行过程,这个monitor命名为WorkflowRuntime,WorkflowRuntime会启动一个新的instance来完成上面的工作,在你的任务的执行的过程中,instance会根据外部的事件来执行对应的事件处理函数,需要指出的是这个WorkflowRuntime还能够指定一个service来保持跟踪,比如说添加一个SqlWorkflowPersistenceService服务,能够将正在执行的Workflow保存到sql server中,然后还可以将保存在数据库中的实例恢复。
Workflow应用程序通常的框架是:首先需要一个宿主程序,这个宿主程序可以是windows forms,控制台的应用程序,asp web程序,甚至可以是windows server,在宿主程序中添加Workflow工程的引用(具体的做法就是首先将该workflow工程编译完的.exe文件添加到宿主工程中),在苏中程序中:
_runtime = WorkflowFactory.GetWorkflowRuntime();
_instance = _runtime.CreateWorkflow(typeof(PersistedWorkflow.Workflow1));
PersistedWorkflow.Workflow1是workflow工程编译完的.exe添加引用之后的类似于命名空间的类型,使用上面的代码得到instance,然后该instance开始监控代码执行。
WorkflowRuntime常见属性和方法
AddService : 为workflow运行时添加指定的服务。能添加的服务类型和时间受到种种限制。。
CreateWorkflow : 创建一个workflow实例,它包含一些指定(但可选)的参数。假如workflow运行时没有启动,该方法就调用StartRuntime方法。
GetWorkflow : 通过 指明workflow实例的标识符(由一个Guid组成)来检索workflow实例。假如这个workflow 实例是空闲和持久化保存的,它将被重新加载并执行。
StartRuntime : 启动workflow 运行时和相关服务,并引发“Started”事件。
StopRuntime : 停止workflow 运行时和相关服务,并引发“Stoped”事件。
下面是一个WorkflowFactory的实现,使用单件的设计模式:
/*
* File : WorkflowFactory.cs
* Function : create Workflow and use singlenton, pay attention
* to that if you wnat to add service to the Workflow
* instance, add the service in this file, do not add
* the service in other file because after calling the
* GetWorkflowInstance(), the instance is runnning.
*/
using System;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using System.Configuration;
namespace WorkflowPersister
{
public static class WorkflowFactory
{
private static WorkflowRuntime _workflowRuntime =
null;
private static object _syncRoot = new object();
public static WorkflowRuntime GetWorkflowRuntime ()
{
lock (_syncRoot)
{
if (null == _workflowRuntime)
{
AppDomain.CurrentDomain.ProcessExit +=
new EventHandler(StopWorkflowRuntime);
AppDomain.CurrentDomain.DomainUnload +=
new EventHandler(StopWorkflowRuntime);
_workflowRuntime = new WorkflowRuntime();
// Add service
string conn =
ConfigurationManager.ConnectionStrings["StorageDataBase"].ConnectionString;
_workflowRuntime.AddService(new SqlWorkflowPersistenceService(conn));
_workflowRuntime.StartRuntime();
}
}
return _workflowRuntime;
}
public static void StopWorkflowRuntime (object sender, EventArgs e)
{
if (_workflowRuntime != null)
{
if (_workflowRuntime.IsStarted)
{
try
{
_workflowRuntime.StartRuntime();
}
catch (ObjectDisposedException ex)
{
}
}
}
}
}
}
Workflow应用程序通常的框架是:首先需要一个宿主程序,这个宿主程序可以是windows forms,控制台的应用程序,asp web程序,甚至可以是windows server,在宿主程序中添加Workflow工程的引用(具体的做法就是首先将该workflow工程编译完的.exe文件添加到宿主工程中),在苏中程序中:
_runtime = WorkflowFactory.GetWorkflowRuntime();
_instance = _runtime.CreateWorkflow(typeof(PersistedWorkflow.Workflow1));
PersistedWorkflow.Workflow1是workflow工程编译完的.exe添加引用之后的类似于命名空间的类型,使用上面的代码得到instance,然后该instance开始监控代码执行。
WorkflowRuntime常见属性和方法
AddService : 为workflow运行时添加指定的服务。能添加的服务类型和时间受到种种限制。。
CreateWorkflow : 创建一个workflow实例,它包含一些指定(但可选)的参数。假如workflow运行时没有启动,该方法就调用StartRuntime方法。
GetWorkflow : 通过 指明workflow实例的标识符(由一个Guid组成)来检索workflow实例。假如这个workflow 实例是空闲和持久化保存的,它将被重新加载并执行。
StartRuntime : 启动workflow 运行时和相关服务,并引发“Started”事件。
StopRuntime : 停止workflow 运行时和相关服务,并引发“Stoped”事件。
下面是一个WorkflowFactory的实现,使用单件的设计模式:
/*
* File : WorkflowFactory.cs
* Function : create Workflow and use singlenton, pay attention
* to that if you wnat to add service to the Workflow
* instance, add the service in this file, do not add
* the service in other file because after calling the
* GetWorkflowInstance(), the instance is runnning.
*/
using System;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using System.Configuration;
namespace WorkflowPersister
{
public static class WorkflowFactory
{
private static WorkflowRuntime _workflowRuntime =
null;
private static object _syncRoot = new object();
public static WorkflowRuntime GetWorkflowRuntime ()
{
lock (_syncRoot)
{
if (null == _workflowRuntime)
{
AppDomain.CurrentDomain.ProcessExit +=
new EventHandler(StopWorkflowRuntime);
AppDomain.CurrentDomain.DomainUnload +=
new EventHandler(StopWorkflowRuntime);
_workflowRuntime = new WorkflowRuntime();
// Add service
string conn =
ConfigurationManager.ConnectionStrings["StorageDataBase"].ConnectionString;
_workflowRuntime.AddService(new SqlWorkflowPersistenceService(conn));
_workflowRuntime.StartRuntime();
}
}
return _workflowRuntime;
}
public static void StopWorkflowRuntime (object sender, EventArgs e)
{
if (_workflowRuntime != null)
{
if (_workflowRuntime.IsStarted)
{
try
{
_workflowRuntime.StartRuntime();
}
catch (ObjectDisposedException ex)
{
}
}
}
}
}
}
相关文章推荐
- workflow学习笔记1,workflow运行时
- Spark学习笔记-安装部署与运行实例
- WF实例学习笔记:(2)通过Workflow 调用 WCF Data Services 获取数据
- LR学习笔记四 之 调试、日志、动态运行
- STM32学习笔记之测量某个函数运行时间
- libevent学习笔记【使用篇】——3. 运行event loop
- 学习笔记 学习jvm 原理 最基本概念(编译与运行概念)
- Windows Workflow Foundation (wwf) 学习笔记(一)
- vue.js学习笔记之安装以及项目的创建和运行
- 韩顺平_php从入门到精通_视频教程_第1讲_html介绍_html运行原理①_学习笔记_源代码图解_PPT文档整理
- 【byte-of-python 学习笔记】——DOS运行python
- (转)Android开发学习笔记(二)——编译和运行原理(2)
- tiny_tty.c 在3.X 内核版本上不能运行 的解决办法 <LDD3 学习笔记>
- Hadoop学习笔记3---安装并运行Hadoop
- iOS学习笔记50-IOS后台运行 之 后台播放音乐
- Javascript学习笔记十——网页运行原理
- python学习笔记(一)运行,输入输出,数据类型
- [原创]java WEB学习笔记91:Hibernate学习之路-- -HQL 迫切左外连接,左外连接,迫切内连接,内连接,关联级别运行时的检索策略 比较。理论,在于理解
- HDFS学习笔记(2)HDFS运行机制
- C++学习笔记二十一-运行时类型识别