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);
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);
Guid workflowId = new Guid(Session["state_ID"].ToString());
workflowRuntime.StartRuntime();
if (workflowRuntime.IsStarted)
{
instance = workflowRuntime.GetWorkflow(workflowId);
}
instance.Load();
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