卸载和加载工作流实例后无法调用事件 [英] Not able to call events after unloading and loading of a workflow instance

查看:72
本文介绍了卸载和加载工作流实例后无法调用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我是工作流程的新手.我创建了一个新的工作流程,并在单击按钮事件后将其卸载,并在触发另一个按钮后加载了该事件.但是在这里,我无法从一种状态转移到另一种状态.这是我的代码:

Hi Everybody,
I am new to workflows. I am created a new workflow and i unloaded it after a button click event and I am loading the event after firing another button. But here I am not able to move from one state to other state. Here my code is:

protected void SendData_Click(object sender, EventArgs e)
        {
            Guid state_ID = Guid.NewGuid();
            Dictionary<string,> Params = new Dictionary<string,>();
            WorkflowInstance instance = null;
            StateMachineWorkflowInstance ins = null;
            SqlWorkflowPersistenceService sqlPersistenceService = new SqlWorkflowPersistenceService(ConfigurationManager.ConnectionStrings["PersistenceConnectionString"].ToString());

            WorkFlowDemo.states.state state = new WorkFlowDemo.states.state();
            ExternalDataExchangeService ExDateExchService = new ExternalDataExchangeService();
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();
            workflowRuntime.AddService(sqlPersistenceService);
            workflowRuntime.AddService(ExDateExchService);
            //workflowRuntime.InstanceStore = store;
            ExDateExchService.AddService(state);
            instance =
                workflowRuntime.CreateWorkflow(typeof(Workflow1), Params, state_ID);
            Session["state_ID"] = state_ID;
            instance.Start();
            ins = new StateMachineWorkflowInstance(workflowRuntime, state_ID);
            state.SubmitContent(state_ID);

            if (ins.CurrentStateName == "Submitted")
            {
                SendData.Visible = false;
                Approve.Visible = true;
                Reject.Visible = true;
                Incomplete.Visible = true;
                Cancel.Visible = true;
            }
            instance.Unload();
        }

 protected void Approve_Click(object sender, EventArgs e)
        {
            Guid state_ID = Guid.NewGuid();
            Dictionary<string,> Params = new Dictionary<string,>();
            WorkflowInstance instance = null;
            StateMachineWorkflowInstance ins = null;
            SqlWorkflowPersistenceService sqlPersistenceService = new SqlWorkflowPersistenceService(ConfigurationManager.ConnectionStrings["PersistenceConnectionString"].ToString());


            //WorkFlowDemo.states.state state = new WorkFlowDemo.states.state();
            //ExternalDataExchangeService ExDateExchService = new ExternalDataExchangeService();
            //WorkflowRuntime workflowRuntime = new WorkflowRuntime();
            //workflowRuntime.AddService(sqlPersistenceService);
            //workflowRuntime.AddService(ExDateExchService);
            ////workflowRuntime.InstanceStore = store;
            //ExDateExchService.AddService(state);
            //instance =
            //    workflowRuntime.CreateWorkflow(typeof(Workflow1), Params, state_ID);

            
            WorkFlowDemo.states.state state = new WorkFlowDemo.states.state();
            ExternalDataExchangeService ExDateExchService = new ExternalDataExchangeService();
            WorkflowRuntime workflowRuntime = new WorkflowRuntime();
            workflowRuntime.AddService(sqlPersistenceService);
            workflowRuntime.AddService(ExDateExchService);
            Guid workflowId = new Guid(Session["state_ID"].ToString());
            //workflowRuntime.CurrentWorkflowInstanceID = workflowId;
            workflowRuntime.StartRuntime();

            if (workflowRuntime.IsStarted)
            {
                instance = workflowRuntime.GetWorkflow(workflowId);
            }
            instance.Load();
            //instance.ReloadTrackingProfiles();
            //workflowRuntime.AddService(ExDateExchService);
            state.Approved(state_ID);
            ins = new StateMachineWorkflowInstance(workflowRuntime, state_ID);

            if (ins.CurrentStateName == "Complete")
            {
                Data.Visible = true;
                Data.InnerText = "Approved";
                ContentTextBox.Visible = false;
                SendData.Visible = false;
                Approve.Visible = false;
                Reject.Visible = false;
                Incomplete.Visible = false;
                Cancel.Visible = false;
                if (workflowRuntime != null)
                {
                    workflowRuntime.StopRuntime();
                    workflowRuntime.Dispose();
                }
            }
        }



这里的事件是



Here events are

namespace WorkFlowDemo
{
   public class states
    {
       [Serializable]
       public class state: Istates,ISendDataService
       {
           private string getassigneddata;
           public event EventHandler<System.Workflow.Activities.ExternalDataEventArgs> submitted;
           public event EventHandler<System.Workflow.Activities.ExternalDataEventArgs> approved;
           public event EventHandler<System.Workflow.Activities.ExternalDataEventArgs> rejected;
           public event EventHandler<System.Workflow.Activities.ExternalDataEventArgs> completed;
           public event EventHandler<ReceivedDataEventArgs> ReceivedDataEvent;

           public void SubmitContent(Guid instanceID)
           {
               if (this.submitted != null)
               {
                  this.submitted(this, new System.Workflow.Activities.ExternalDataEventArgs(instanceID));
               }
           }

           public void Rejected(Guid instanceID)
           {
               if (this.rejected != null)
               {
                   this.rejected(this, new System.Workflow.Activities.ExternalDataEventArgs(instanceID));
               }
           }

           public void Approved(Guid instanceID)
           {
               if (this.approved != null)
                   this.approved(this, new System.Workflow.Activities.ExternalDataEventArgs(instanceID));
           }


}
}
}



加载工作流程后,任何人都可以告诉我如何从一种状态转换为另一种状态吗?



Can any body tell how can i move from one state to other state after loading the work flow

推荐答案

使用
StateMachineWorkflowInstance ins =新的StateMachineWorkflowInstance(workflowRuntime,工作流ID);

ins.CurrentStateName将给出当前状态,在上述情况下,我认为它正在从一种状态转移到另一种状态.
By using
StateMachineWorkflowInstance ins = new StateMachineWorkflowInstance(workflowRuntime, workflowId);

ins.CurrentStateName will give the current state i think it is moving from one state to other in above case.


通过使用stateMachineWorkflow,我可以在使用sqlpersistence之前获得currentstatename. wokflow ID如下所示:

实例= workflowRuntime.GetWorkflow(workflowId);

之后,此代码可帮助我知道我是否处于哪种状态:

StateMachineWorkflowInstance ins =新的StateMachineWorkflowInstance(workflowRuntime,工作流ID);

ins.CurrentStateName

因此,我们可以知道我们是否能够从一种状态转移到另一种状态
By using stateMachineWorkflow i got the currentstatename before that by using sqlpersistence I am able to get the wokflow id as shown below:

instance = workflowRuntime.GetWorkflow(workflowId);

after that this code helps me to know whether I am in which state:

StateMachineWorkflowInstance ins = new StateMachineWorkflowInstance(workflowRuntime, workflowId);

ins.CurrentStateName

Hence we can know whether we are able to move from one state to other


这篇关于卸载和加载工作流实例后无法调用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆