WorkFlowHelper
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Runtime.Hosting;
using OrderWorkflows;
using BaoxiaoWF;
namespace WebService1
{
public class WorkFlowHelper
{
private static WorkflowRuntime _WorkflowRuntime_;
public static WorkflowRuntime WorkflowRuntime_
{
get
{
if (_WorkflowRuntime_ == null)
_WorkflowRuntime_ = HttpContext.Current.Application["WorkflowRuntime"] as WorkflowRuntime;
return _WorkflowRuntime_;
}
}
private static ManualWorkflowSchedulerService _ManualWorkflowSchedulerService_;
public static ManualWorkflowSchedulerService ManualWorkflowSchedulerService_
{
get
{
if (_ManualWorkflowSchedulerService_ == null)
_ManualWorkflowSchedulerService_ = WorkflowRuntime_.GetService<ManualWorkflowSchedulerService>();
return _ManualWorkflowSchedulerService_;
}
}
private static ExternalDataExchangeService _ExternalDataExchangeService_;
public static ExternalDataExchangeService ExternalDataExchangeService_
{
get
{
if (_ExternalDataExchangeService_ == null)
_ExternalDataExchangeService_ = WorkflowRuntime_.GetService<ExternalDataExchangeService>();
return _ExternalDataExchangeService_;
}
}
private static OrderService _OrderService_;
public static OrderService OrderService_
{
get
{
if (_OrderService_ == null)
{
_OrderService_ = new OrderService();
ExternalDataExchangeService_.AddService(_OrderService_);
}
return _OrderService_;
}
}
private static Baoxiao _BaoxiaoService_;
public static Baoxiao BaoxiaoService_
{
get
{
if (_BaoxiaoService_ == null)
{
_BaoxiaoService_ = new Baoxiao();
ExternalDataExchangeService_.AddService(_BaoxiaoService_);
}
return _BaoxiaoService_;
}
}
public static void RunInstanceInManualWorkflowSchedulerService(Guid instanceId)
{
ManualWorkflowSchedulerService_.RunWorkflow(instanceId);
}
public static string GetCurrentState(Guid instanceId)
{
StateMachineWorkflowInstance stateInstance = new StateMachineWorkflowInstance(WorkflowRuntime_, instanceId);
return stateInstance.CurrentStateName;
}
public static string GetInstanceExecutionStatus(WorkflowInstance instance)
{
/*
ActivityExecutionStatus枚举值
Canceling 活动正在取消中。
Closed 活动已被关闭。
Compensating 活动处于补偿状态。
Executing 活动当前正在运行。
Faulting 活动已产生并维持一个异常。
Initialized 活动已被初始化但还未运行。 */
return instance.GetWorkflowDefinition().ExecutionStatus.ToString();
}
public static string GetInstanceExecutionStatus(Guid instanceID)
{
WorkflowInstance instance = WorkflowRuntime_.GetWorkflow(instanceID);
return GetInstanceExecutionStatus(instance);
}
}
}