using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Runtime.Hosting;
namespace NumeralSociety.WFInterface
{
/// <summary>
/// 工作流持久化助手
/// </summary>
public class WorkflowPersistenceUtility
{
/// <summary>
/// 运行时
/// </summary>
WorkflowRuntime runtime;//运行时
/// <summary>
/// 实例
/// </summary>
WorkflowInstance instance;//实例
/// <summary>
/// 外部数据交换服务
/// </summary>
ExternalDataExchangeService service;//外部数据交换服务
/// <summary>
/// 持久化服务
/// </summary>
WorkflowPersistenceService perService;//持久化服务
/// <summary>
/// 实例化相关类,并加载
/// </summary>
/// <param name="PersistenceConnectionString"></param>
/// <param name="achieveObject"></param>
public void mInstance(string PersistenceConnectionString,object achieveObject)
{
runtime = new WorkflowRuntime();
service = new ExternalDataExchangeService();
perService = new SqlWorkflowPersistenceService(PersistenceConnectionString);
if (runtime.GetService(service.GetType()) == null)//服务不能重复加入
{
runtime.AddService(service);
}
if (runtime.GetService(perService.GetType()) == null)
{
runtime.AddService(perService);
}
if (service.GetService(achieveObject.GetType()) == null)
{
service.AddService(achieveObject);//将此类加入外部数据交换服务
}
runtime.WorkflowIdled += OnWorkflowIdled;//工作流闲置事件
runtime.StartRuntime();
}
public void OnWorkflowIdled(object sender, WorkflowEventArgs e)
{
e.WorkflowInstance.TryUnload();//将内存数据持久化到数据库中
}
public void CreateWorkflowAndStart(Type worlflowType)
{
instance = runtime.CreateWorkflow(worlflowType);
instance.Start();
}
public void GetWorkflow(Guid workflowId)
{
instance=runtime.GetWorkflow(workflowId);
}
public Guid GetInstanceId()
{
return instance.InstanceId;
}
}
}
工作流持久化助手
最新推荐文章于 2025-01-04 16:50:38 发布