流程操作
更新时间: 2024-11-22 浏览次数: {{ hits }}

重新激活流程

示例:

H3.Workflow.Messages.ActivateInstanceMessage   activiteinstanceMessage = new   H3.Workflow.Messages.ActivateInstanceMessage(this.Request.InstanceId); //传递参数为流程实例ID

this.Request.Engine.WorkflowInstanceManager.SendMessage(activiteinstanceMessage);//只会激活流程,并不会触发运行的节点

 

激活某个活动节点

示例:

H3.Workflow.Messages.ActivateActivityMessage activiteMessage =   new H3.Workflow.Messages.ActivateActivityMessage(this.Request.InstanceId,

                  "Activity3", H3.Workflow.Instance.Token.UnspecifiedId, new   string[] {}, null, false, H3.Workflow.WorkItem.ActionEventType.Adjust);//参数对应描述:流程实例ID,活动节点编码,令牌ID,参与者,前驱令牌,是否检测入口条件,激活类型

this.Request.Engine.WorkflowInstanceManager.SendMessage(activiteMessage);//1.不会取消正在运行的节点。2.进行中的流程才能激活调整。

 

取消某个活动节点

示例:

H3.Workflow.Messages.CancelActivityMessage cancelMessage = new   H3.Workflow.Messages.CancelActivityMessage(this.Request.InstanceId,   "Activity3", false);

this.Request.Engine.WorkflowInstanceManager.SendMessage(cancelMessage);

 

取消流程

示例:

H3.Workflow.Messages.CancelInstanceMessage cancelMessage = new   H3.Workflow.Messages.CancelInstanceMessage(this.Request.InstanceId,false);

this.Request.Engine.WorkflowInstanceManager.SendMessage(cancelMessage);

 

结束流程

示例:

H3.Workflow.Instance.WorkflowInstance instance = this.Request.Engine.WorkflowInstanceManager.GetWorkflowInstance(this.Request.InstanceId); //获取当前流程实例对象
H3.Workflow.Messages.FinishInstanceMessage cancelMessage = new   H3.Workflow.Messages.FinishInstanceMessage(this.Request.InstanceId,(int)instance.FinalTokenId);
this.Request.Engine.WorkflowInstanceManager.SendMessage(cancelMessage);

 

 

结束流程时执行特定的业务逻辑

示例:

protected override void   OnWorkflowInstanceStateChanged(H3.Workflow.Instance.WorkflowInstanceState   oldState, H3.Workflow.Instance.WorkflowInstanceState newState)

    {

        //流程审批结束事件(先执行业务规则,在执行该方法)。

        if(oldState ==   H3.Workflow.Instance.WorkflowInstanceState.Running && newState ==   H3.Workflow.Instance.WorkflowInstanceState.Finished)

        {

            //执行业务代码逻辑

        }

 

        //流程审批结束后,重新激活事件(先执行业务规则,在执行该方法)。

        if(oldState ==   H3.Workflow.Instance.WorkflowInstanceState.Finished && newState ==   H3.Workflow.Instance.WorkflowInstanceState.Running)

        {

            //执行业务代码逻辑

        }

          base.OnWorkflowInstanceStateChanged(oldState, newState);

    }

需要注意,如果流程设置的是发起节点直接到结束节点,或者审批节点全部符合自动通过逻辑,流程状态是从草稿变为生效的,见如下代码示例:

protected override void   OnWorkflowInstanceStateChanged(H3.Workflow.Instance.WorkflowInstanceState   oldState, H3.Workflow.Instance.WorkflowInstanceState newState)

    {

        //流程审批结束事件(先执行业务规则,在执行该方法)。

         if((oldState == H3.Workflow.Instance.WorkflowInstanceState.Running ||oldState == H3.Workflow.Instance.WorkflowInstanceState.Initiated)  && newState == H3.Workflow.Instance.WorkflowInstanceState.Finished)

        {

            //执行业务代码逻辑

        }

 

        //流程审批结束后,重新激活事件(先执行业务规则,在执行该方法)。

        if(oldState ==   H3.Workflow.Instance.WorkflowInstanceState.Finished && newState ==   H3.Workflow.Instance.WorkflowInstanceState.Running)

        {

            //执行业务代码逻辑

        }

          base.OnWorkflowInstanceStateChanged(oldState, newState);

    }