Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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
C#
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
Posted
Updated 15-Jun-12 5:17am
v2

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.
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900