private Dictionary <string, string> GetAllTransitionState(StateMachineWorkflowInstance stateMachine) { //CompositeActivity act = stateMachine.CurrentState as CompositeActivity; Dictionary <string, string> transictionState = GetSetStateInfoRecursive(stateMachine.CurrentState); //foreach (Activity item in act.EnabledActivities) //{ // if (item is EventDrivenActivity) // { // EventDrivenActivity evn = item as EventDrivenActivity; // foreach (Activity item2 in evn.EnabledActivities) // { // } // if (item is SetStateActivity) // { // transictionState.Add(((SetStateActivity)item).TargetStateName, ((SetStateActivity)item).Description); // } // } //} //Collection<string> states = new Collection<string>(); //foreach (string item in stateMachine.PossibleStateTransitions) //{ // states.Add(item); //} //Activity activ = stateMachine.StateMachineWorkflow.Activities[stateMachine.CurrentStateName]; //CompositeActivity Comactiv = stateMachine.StateMachineWorkflow.Activities[stateMachine.CurrentStateName] as CompositeActivity; return(transictionState); }
public static string GetWorkflowState(Guid instanceID) { //Check.ArgumentIsNotNull(instanceID, "instanceID"); InitilizeRuntime(); string result; StateMachineWorkflowInstance instance = null; try { instance = new StateMachineWorkflowInstance(Runtime, instanceID); } catch (InvalidOperationException) { // the workflow wasnt in the persistence store // so we can assume it isn't running } if (instance != null) { result = instance.CurrentStateName; } else { result = string.Empty; } return(result); }
/// <summary> /// Run the workflow in a synchronous way using the ManualWorkflowSchedulerService /// </summary> /// <param name="workflowInstanceId"></param> private void RunWorkFlow(Guid workflowInstanceId) { StateMachineWorkflowInstance stateMachine = new StateMachineWorkflowInstance(_workflowRuntime, workflowInstanceId); StateActivity oldState = stateMachine.CurrentState; ManualWorkflowSchedulerService service = _workflowRuntime.GetService <ManualWorkflowSchedulerService>(); service.RunWorkflow(workflowInstanceId); // Hack : This is not the best way to handle exceptions (sychronously) in Workflows // Read more about the best practice here - http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=833203&SiteID=1 // And here - http://www.topxml.com/rbnews/Orchestration---Workflow/re-60988_Synchronous-CallWorkflow-sample-revisited.aspx if (CallContext.GetData("Exception") != null) { // This is the compensation activity - that should be ideally defined in the workflow itself // In our case, the only activity that occurs after External Method Calls for Book, Cancel etc. // is the state change activity. We just reverse it here. // Ideally, we can have a fault handler for each event driven activity // that will set the call context with a "WCFException" and halt the execution of the workflow. stateMachine.SetState(oldState); service.RunWorkflow(workflowInstanceId); Exception exceptionToThrow = (Exception)CallContext.GetData("Exception"); CallContext.SetData("Exception", null); throw exceptionToThrow; } }
/// <summary> /// 获取当前实例的状态代码 /// </summary> /// <param name="WfRuntime"></param> /// <param name="instance"></param> /// <param name="CurrentStateName"></param> /// <returns></returns> public static string GetNextState(WorkflowRuntime WfRuntime, WorkflowInstance instance, string CurrentStateName) { try { string StateName = CurrentStateName; LogHelper.WriteLog("循环获取当前实例的状态代码 (开始)instance=" + (instance != null ? instance.InstanceId.ToString() : "null") + " StateName=" + StateName); while (StateName == CurrentStateName) { if (instance == null) { StateName = "EndFlow"; return(StateName); } StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(WfRuntime, instance.InstanceId); StateName = workflowinstance.CurrentStateName; } LogHelper.WriteLog("循环获取当前实例的状态代码 (结束)instance=" + (instance != null ? instance.InstanceId.ToString() : "null") + " StateName=" + StateName); return(StateName); } catch (Exception ex) { LogHelper.WriteLog("GetNextState异常信息 :" + ex.ToString()); throw new Exception(ex.Message); } }
private Guid StartOrderWorkflow() { // NOTE: "Late-binding to the OrderWorkflows" assembly so we // ...can easily copy this exe and project into another soluton // Load the OrderWorkflows assembly Assembly orderWorkflowsAssembly = Assembly.Load("OrderWorkflows"); // Get a reference to the System.Type for the OrderWorkflows.Workflow1 Type workflowType = orderWorkflowsAssembly.GetType("Microsoft.Samples.Workflow.OrderApplication.SampleWorkflow"); if (workflowType == null) { return(Guid.Empty); } WorkflowInstance instance = runtime.CreateWorkflow(workflowType); StateMachineWorkflowInstance stateMachineInstance = new StateMachineWorkflowInstance(runtime, instance.InstanceId); instance.Start(); // Add the StateMachineInstance object for our Workflow to our dictionary this.stateMachineInstances.Add(instance.InstanceId.ToString(), stateMachineInstance); // Return the WorkflowInstanceId return(instance.InstanceId); }
private void ButtonSetState_Click(object sender, EventArgs e) { // If nothing is selected, return. if (comboBoxWorkflowStates.SelectedItem == null) { return; } // Get a reference to the StateMachineInstance for the selected workflow StateMachineWorkflowInstance targetStateMachineInstance = this.GetSelectedStateMachineInstance(); if (targetStateMachineInstance == null) { MessageBox.Show("Please select a order and try again.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { // Get the ID of the state that was selected in the drop-down list string selectedStateId = this.comboBoxWorkflowStates.SelectedItem.ToString(); // Change the state of the workflow to the selected state targetStateMachineInstance.SetState(selectedStateId); } UpdateUI(); }
public ReadOnlyCollection <string> GetStateMachineTransitions(Guid instanceID) { Check.ArgumentIsNotNull(instanceID, "instanceID"); ReadOnlyCollection <string> result = null; StateMachineWorkflowInstance instance = null; try { instance = new StateMachineWorkflowInstance(Runtime, instanceID); } catch (InvalidOperationException) { // the workflow wasnt in the persistence store // so we can assume it isn't running } if (instance != null) { result = instance.PossibleStateTransitions; } else { result = new List <string>().AsReadOnly(); } return(result); }
private Collection <string> GetNextEvents(StateMachineWorkflowInstance stateMachine) { Collection <string> events = new Collection <string>(); Activity activ = stateMachine.StateMachineWorkflow.Activities[stateMachine.CurrentStateName]; CompositeActivity act = stateMachine.StateMachineWorkflow.Activities[stateMachine.CurrentStateName] as CompositeActivity; CompositeActivity act2 = null; for (int i = 0; i < act.Activities.Count; i++) { act2 = act.Activities[i] as CompositeActivity; if (act2 is EventDrivenActivity) { foreach (Activity act3 in act2.Activities) { if (act3 is HandleExternalEventActivity) { HandleExternalEventActivity handl = act3 as HandleExternalEventActivity; events.Add(handl.EventName); } } } } return(events); }
public IEnumerable <string> GetCurrentFormEvents(Guid instanceId) { DoInitialize(0); IEnumerable <string> eventNames = new StateMachineWorkflowInstance(WorkflowFacade.WorkflowRuntime, instanceId).GetCurrentEventNames(typeof(IFormsWorkflowEventService)); return(eventNames); }
private void Runtime_WorkflowIdled(object sender, WorkflowEventArgs e) { // Get the underlying WorkflowInstance StateMachineWorkflowInstance stateMachineInstance = new StateMachineWorkflowInstance(runtime, e.WorkflowInstance.InstanceId); // Update the Workflow State & Status on the ListItem this.UpdateListItem(stateMachineInstance.WorkflowInstance, stateMachineInstance.CurrentState.Name, "Running"); // Update the status of the buttons for the selected ListItem this.UpdateUI(); }
/// <summary> /// 获取指定最后操作时间段和指定状态下的工作流实例 /// </summary> /// <param name="workflowName">Name of the workflow.</param> /// <param name="startDate">起始日期</param> /// <param name="endDate">终止日期</param> /// <param name="stateName">实例所处状态</param> /// <param name="unitCode">单位代码.</param> /// <returns></returns> protected override List <StateMachineWorkflowInstance> GetWorkflowInstance(string workflowName, DateTime startDate, DateTime endDate, string[] stateNames, string unitCode) { List <StateMachineWorkflowInstance> instanceList = new List <StateMachineWorkflowInstance>(); List <NHStateMachineInstance> nHInstanceList = dao.GetInstanceByPersisteTime(workflowName, startDate, endDate, stateNames, unitCode); foreach (NHStateMachineInstance nHInstance in nHInstanceList) { StateMachineWorkflowInstance instance = ConvertNHToInstance(nHInstance, false); instanceList.Add(instance); } return(instanceList); }
/// <summary> /// 保存工作流实例 /// </summary> /// <param name="instance"></param> protected override StateMachineWorkflowInstance SaveWorkflowInstance(StateMachineWorkflowInstance instance) { foreach (Activity activity in instance.ExecutedActivities) { AddApprovalActivity(activity); } NHStateMachineInstance nHInstance = dao.GetById(instance.Id, false); ConvertNHFromInstance(instance, nHInstance); dao.Save(nHInstance); return(instance); }
/// <summary> /// 克隆一个实例 /// </summary> /// <param name="WfRuntimeClone"></param> /// <param name="instanceClone"></param> /// <param name="WfRuntime"></param> /// <returns></returns> public static WorkflowInstance CloneWorkflowInstance(WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, WorkflowRuntime WfRuntime) { try { if (!WfRuntimeClone.IsStarted) { WfRuntimeClone.StartRuntime(); } StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(WfRuntimeClone, instanceClone.InstanceId); System.Workflow.Activities.StateMachineWorkflowActivity smworkflow = new StateMachineWorkflowActivity(); smworkflow = workflowinstance.StateMachineWorkflow; RuleDefinitions ruleDefinitions = smworkflow.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions; WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer(); StringBuilder xoml = new StringBuilder(); StringBuilder rule = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(xoml); XmlWriter ruleWriter = XmlWriter.Create(rule); markupSerializer.Serialize(xmlWriter, smworkflow); if (ruleDefinitions != null) { markupSerializer.Serialize(ruleWriter, ruleDefinitions); } xmlWriter.Close(); ruleWriter.Close(); StringReader readxoml = new StringReader(xoml.ToString()); XmlReader readerxoml = XmlReader.Create(readxoml); WorkflowInstance instance; if (ruleDefinitions == null) { instance = WfRuntime.CreateWorkflow(readerxoml); } else { StringReader readrule = new StringReader(rule.ToString()); XmlReader readerrule = XmlReader.Create(readrule); instance = WfRuntime.CreateWorkflow(readerxoml, readerrule, null); } instance.Start(); return(instance); } catch (Exception ex) { LogHelper.WriteLog("CloneWorkflowInstance异常信息 :" + ex.ToString()); throw new Exception(ex.Message); } }
/// <summary> /// 获取某立项对应的实例 /// </summary> /// <param name="workflowName"></param> /// <param name="eaId">立项Id</param> /// <param name="isAttachMore">是否需要加载其他信息:该实例所有执行动作的实例</param> /// <returns></returns> protected override List <StateMachineWorkflowInstance> GetWorkflowInstance(string workflowName, int eaId, bool isAttachMore) { List <StateMachineWorkflowInstance> instanceList = new List <StateMachineWorkflowInstance>(); List <NHStateMachineInstance> nHInstanceList = new List <NHStateMachineInstance>(); nHInstanceList = dao.GetUserInstance(workflowName, eaId); foreach (NHStateMachineInstance nHInstance in nHInstanceList) { StateMachineWorkflowInstance instance = ConvertNHToInstance(nHInstance, isAttachMore); instanceList.Add(instance); } return(instanceList); }
/// <summary> /// 插入一条新的工作流 /// </summary> /// <param name="instance"></param> protected override StateMachineWorkflowInstance InsertWorkflowInstance(StateMachineWorkflowInstance instance) { foreach (Activity activity in instance.ExecutedActivities) { AddApprovalActivity(activity); } NHStateMachineInstance nHInstance = new NHStateMachineInstance(); nHInstance.Id = instance.Id; ConvertNHFromInstance(instance, nHInstance); dao.Save(nHInstance); return(instance); }
/// <summary> /// 按创建者单位,Id,和实例状态获取实例 /// </summary> /// <param name="workflowName">Name of the workflow.</param> /// <param name="stateName">实例状态名称</param> /// <param name="createUserId">创建者Id</param> /// <param name="unitCode">创建者单位代码</param> /// <returns></returns> protected override List <StateMachineWorkflowInstance> GetWorkflowInstance(string workflowName, string[] stateNames, string createUserId, string unitCode) { List <StateMachineWorkflowInstance> instanceList = new List <StateMachineWorkflowInstance>(); List <NHStateMachineInstance> nHInstanceList = new List <NHStateMachineInstance>(); nHInstanceList = dao.GetUserInstance(workflowName, stateNames, createUserId, unitCode); foreach (NHStateMachineInstance nHInstance in nHInstanceList) { StateMachineWorkflowInstance instance = ConvertNHToInstance(nHInstance, false); instanceList.Add(instance); } return(instanceList); }
/// <summary> /// 将NHStateMachineInstance对象反序列化为状态机工作流对象 /// </summary> /// <param name="instance">The instance.</param> /// <param name="isAttachMore">是否需要加载其他信息:该实例所有执行动作的实例</param> /// <returns></returns> private StateMachineWorkflowInstance ConvertNHToInstance(NHStateMachineInstance instance, bool isAttachMore) { StateMachineWorkflowInstance newInstance = new StateMachineWorkflowInstance(); newInstance.WorkflowName = instance.WorkflowName; newInstance.EaId = instance.EaId; newInstance.Id = instance.Id; if (!string.IsNullOrEmpty(instance.ParentId)) { newInstance.ParentId = new Guid(instance.ParentId); } newInstance.PersistTime = instance.PersistTime; newInstance.Properties.Add("UnitCode", instance.CreaterUnit); newInstance.Properties.Add("CreaterUserId", instance.CreaterUserId); newInstance.StateName = instance.StateName; if (!string.IsNullOrEmpty(instance.Children)) { string[] childrenId = instance.Children.Split(';'); List <Guid> childrenIds = new List <Guid>(); for (int i = 0; i < childrenId.Length; i++) { Guid childId = new Guid(childrenId[i]); childrenIds.Add(childId); } newInstance.ChildrenId = childrenIds; } if (!string.IsNullOrEmpty(instance.StateRecord)) { string[] stateNames = instance.StateRecord.Split(';'); newInstance.StateRecordNames = new List <string>(stateNames); } if (isAttachMore) { if (!string.IsNullOrEmpty(instance.ExecuteActivitiesIds)) { string[] ids = instance.ExecuteActivitiesIds.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); List <long> allIds = new List <long>(); for (int i = 0; i < ids.Length; i++) { long activityId; if (long.TryParse(ids[i], out activityId)) { allIds.Add(activityId); } } newInstance.ExecutedActivities.AddRange(GetApprovalActivitys(allIds.ToArray())); } } return(newInstance); }
/// <summary> /// 获取处于某状态下的所有状态机工作流实例 /// </summary> /// <param name="workflowName">Name of the workflow.</param> /// <param name="stateName">状态名称</param> /// <param name="type">The type.</param> /// <returns></returns> protected override List <StateMachineWorkflowInstance> GetWorkflowInstance(string workflowName, string[] stateNames, Type type) { List <NHStateMachineInstance> nHInstanceList = new List <NHStateMachineInstance>(); nHInstanceList = dao.GetInstanceByStateName(workflowName, stateNames, type.Name); List <StateMachineWorkflowInstance> instanceList = new List <StateMachineWorkflowInstance>(); foreach (NHStateMachineInstance instance in nHInstanceList) { StateMachineWorkflowInstance stateMachineInstance = ConvertNHToInstance(instance, false); instanceList.Add(stateMachineInstance); } return(instanceList); }
private static void DumpStateMachine(WorkflowRuntime runtime, Guid instanceId) { var instance = new StateMachineWorkflowInstance(runtime, instanceId); Console.WriteLine("Workflow ID: {0}", instanceId); Console.WriteLine("Current State: {0}", instance.CurrentStateName); Console.WriteLine("Possible Transitions: {0}", instance.PossibleStateTransitions.Count); foreach (string name in instance.PossibleStateTransitions) { Console.WriteLine("\t{0}", name); } }
/// <summary> /// Ensures that an appropriate exception is thrown in case the state machine /// encounters an invalid state transition. The exceptions that the workflow runtime /// current throws ("Event Delivery failed") is not helpful /// </summary> /// <param name="stateToTransition">The operation which has been called which is the state to which the /// transition will occur (if valid)</param> /// <param name="workflowInstanceId">Guid - workflow instance Id</param> private void EnsureTransitionPossible(string stateToTransition, Guid workflowInstanceId) { SetupWorkflowEnvironment(); StateMachineWorkflowInstance stateMachine = new StateMachineWorkflowInstance(_workflowRuntime, workflowInstanceId); if (!stateMachine.PossibleStateTransitions.Contains(stateToTransition)) { string[] transitions = new string[stateMachine.PossibleStateTransitions.Count]; stateMachine.PossibleStateTransitions.CopyTo(transitions, 0); string message = String.Format("The appointment can be {0} but not {1}", string.Join(",", transitions), stateToTransition); throw new InvalidBusinessOperationException(message); } }
/// <summary> /// 激发事件到一下状态,并获取状态代码 /// </summary> /// <param name="WfRuntime"></param> /// <param name="instance"></param> /// <param name="CurrentStateName"></param> /// <param name="xml"></param> /// <returns></returns> public static string GetNextStateByEvent(WorkflowRuntime WfRuntime, WorkflowInstance instance, string CurrentStateName, string xml) { try { if (!WfRuntime.IsStarted) { WfRuntime.StartRuntime(); } WfRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { instance = null; }; StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(WfRuntime, instance.InstanceId); ManualWorkflowSchedulerService scheduleService = WfRuntime.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService; scheduleService.RunWorkflow(workflowinstance.InstanceId); workflowinstance.SetState(CurrentStateName); FlowDataType.FlowData FlowData = new FlowDataType.FlowData(); FlowData.xml = xml; scheduleService.RunWorkflow(instance.InstanceId); WfRuntime.GetService <FlowEvent>().OnDoFlow(instance.InstanceId, FlowData);//激发流程引擎流转到下一状态 scheduleService.RunWorkflow(instance.InstanceId); //while (true) //{ // string stateName = workflowinstance.CurrentStateName; // if (stateName != null && stateName.ToUpper().IndexOf("START") == -1) // { // break; // } //} //System.Threading.Thread.Sleep(1000); if (instance == null) { return("EndFlow"); } StateMachineWorkflowInstance workflowinstance1 = new StateMachineWorkflowInstance(WfRuntime, instance.InstanceId); return(workflowinstance1.CurrentStateName); //return GetNextState(WfRuntime, instance, CurrentStateName); } catch (Exception ex) { LogHelper.WriteLog("GetNextStateByEvent异常信息 :" + ex.ToString()); throw new Exception(ex.Message); } }
private void PopulateSetStateComboBox() { // clear the items in the combo box and reload them comboBoxWorkflowStates.Items.Clear(); // Get a reference to the StateMachineInstance for the selected workflow StateMachineWorkflowInstance targetStateMachineInstance = this.GetSelectedStateMachineInstance(); // Get the list of states for the selected StateMachine WorkflowInstance ReadOnlyCollection <StateActivity> states = targetStateMachineInstance.States; // Add the Id for each possible state to the comboBox foreach (StateActivity possibleState in states) { this.comboBoxWorkflowStates.Items.Add(possibleState.Name); } }
/// <summary> /// Handle the WorkflowIdled event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WorkflowRuntime_WorkflowIdled( object sender, WorkflowEventArgs e) { UpdateDelegate theDelegate = delegate() { //first disable all buttons EnableEventButtons(false); //determine which events are allowed. //Note: ReadOnlyCollection is in the //System.Collections.ObjectModel namespace. ReadOnlyCollection <WorkflowQueueInfo> queueInfoData = _instanceWrapper.WorkflowInstance.GetWorkflowQueueData(); if (queueInfoData != null) { foreach (WorkflowQueueInfo info in queueInfoData) { EventQueueName eventQueue = info.QueueName as EventQueueName; if (eventQueue == null) { break; } //enable the button that is associated //with this event EnableButtonForEvent(eventQueue.MethodName); } } #if STATEMACHINEINSTANCE StateMachineWorkflowInstance stateMachine = new StateMachineWorkflowInstance( _workflowManager.WorkflowRuntime, _instanceWrapper.WorkflowInstance.InstanceId); //set the form title to the current state name this.Text = String.Format( "State: {0}", stateMachine.CurrentStateName); #endif }; //execute the anonymous delegate on the UI thread this.Invoke(theDelegate); }
public void Rebook(int ubrn, Guid slotId) { Appointment businessAppointment = Helper.GetApplication().FindAppointmentById(ubrn); // Ensure Current state is Booked StateMachineWorkflowInstance stateMachine = new StateMachineWorkflowInstance(_workflowRuntime, (Guid)businessAppointment.WorkflowId); if (stateMachine.CurrentStateName != "Booked") { throw new InvalidBusinessOperationException("This operation is only valid for booked appointments"); } EnsureTransitionPossible("Booked", (Guid)businessAppointment.WorkflowId); _appointmentLocalService.RaiseAppointmentReBookEvent ((Guid)businessAppointment.WorkflowId, ubrn, slotId); RunWorkFlow((Guid)businessAppointment.WorkflowId); }
public static IEnumerable <string> GetCurrentEventNames(this StateMachineWorkflowInstance stateMachineWorkflowInstance, Type eventServiceType) { if (stateMachineWorkflowInstance == null) { throw new ArgumentNullException("stateMachineWorkflowInstance"); } if (eventServiceType == null) { throw new ArgumentNullException("eventServiceType"); } Verify.IsNotNull(stateMachineWorkflowInstance.CurrentState, "The workflow has already been canceled."); foreach (Activity currentStateActivity in stateMachineWorkflowInstance.CurrentState.Activities) { if (currentStateActivity.Enabled == false) { continue; } if ((currentStateActivity is EventDrivenActivity) == false) { continue; } HandleExternalEventActivity handleExternalEventActivity = ((EventDrivenActivity)currentStateActivity).EventActivity as HandleExternalEventActivity; if (handleExternalEventActivity == null) { continue; } if (handleExternalEventActivity.Enabled == false) { continue; } if (handleExternalEventActivity.InterfaceType != eventServiceType) { continue; } yield return(handleExternalEventActivity.EventName); } }
/// <exclude /> protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { StateMachineWorkflowInstance instance = WorkflowFacade.GetStateMachineWorkflowInstance(this.WorkflowInstanceId); bool result = Condition.Evaluate(this, executionContext); SetStateEventArgs args; if (result) { args = new SetStateEventArgs(this.TrueTargetStateName); } else { args = new SetStateEventArgs(this.FalseTargetStateName); } // instance.EnqueueItemOnIdle("SetStateQueue", args, null, null); return(ActivityExecutionStatus.Closed); }
public DataTable GetActionName() { if (this.CurrentWorkflowInstanceId == Guid.Empty) { return(null); } StateMachineWorkflowInstance instance = new StateMachineWorkflowInstance(this.GetWorkflowRuntime(), this.CurrentWorkflowInstanceId); Dictionary <string, string> nextStates = GetAllTransitionState(instance); DataTable dtNextEvents = new DataTable(); dtNextEvents.Columns.Add("EventName", typeof(string)); dtNextEvents.Columns.Add("EventAlias", typeof(string)); foreach (KeyValuePair <string, string> kvp in nextStates) { dtNextEvents.Rows.Add(kvp.Key, kvp.Value); } return(dtNextEvents); }
public static Guid StartWorkflow() { // Get a reference to the System.Type for the OrderWorkflows.Workflow1 Type workflowType = typeof(IgrssWorkflowLibrary.ValuationProcess); if (workflowType == null) { return(Guid.Empty); } WorkflowInstance instance = runtime.CreateWorkflow(workflowType); StateMachineWorkflowInstance stateMachineInstance = new StateMachineWorkflowInstance(runtime, instance.InstanceId); instance.Start(); // Add the StateMachineInstance object for our Workflow to our dictionary stateMachineInstances.Add(instance.InstanceId.ToString(), stateMachineInstance); lastWf = instance.InstanceId; // Return the WorkflowInstanceId return(lastWf); }
private void btnStartWorkflow_Click(object sender, EventArgs e) { // Start the Workflow stateMachineInstance = this.StartSpeechWorkflow(); }
/// <summary> /// 将状态机工作流实例序列化转换为NHStateMachineInstance /// </summary> /// <param name="instance">The instance.</param> /// <param name="nHInstance">The n H instance.</param> private void ConvertNHFromInstance(StateMachineWorkflowInstance instance, NHStateMachineInstance nHInstance) { nHInstance.EaId = instance.EaId; if (instance.ParentId != Guid.Empty) { nHInstance.ParentId = instance.ParentId.ToString(); } nHInstance.WorkflowName = instance.WorkflowName; nHInstance.StateName = instance.StateName; nHInstance.CreaterUserId = instance.Properties["CreaterUserId"]; nHInstance.CreaterUnit = instance.Properties["UnitCode"]; nHInstance.PersistTime = instance.PersistTime; nHInstance.TypeName = typeof(StateMachineWorkflowInstance).Name; if (instance.ChildrenId != null) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < instance.ChildrenId.Count; i++) { if (i != 0) { sb.Append(";"); } sb.Append(instance.ChildrenId[i].ToString()); } nHInstance.Children = sb.ToString(); } else { nHInstance.Children = string.Empty; } if (instance.ExecutedActivities != null) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < instance.ExecutedActivities.Count; i++) { if (i != 0) { sb.Append(";"); } sb.Append(instance.ExecutedActivities[i].Id.ToString()); } nHInstance.ExecuteActivitiesIds = sb.ToString(); } else { nHInstance.ExecuteActivitiesIds = string.Empty; } if (instance.StateRecordNames != null) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < instance.StateRecordNames.Count; i++) { if (i != 0) { sb.Append(";"); } sb.Append(instance.StateRecordNames[i]); } nHInstance.StateRecord = sb.ToString(); } else { nHInstance.StateRecord = string.Empty; } }