override public IntrospectWiringInfo introspectWiring(OperatorInstance instance, int[] inputIndices) { Operator.IntrospectWiringInfo wiringInfo; wiringInfo = new IntrospectWiringInfo(); wiringInfo.type = IntrospectWiringInfo.EnumType.VALIDWIRING; wiringInfo.ouputIndices = new int[inputIndices.Length]; // NOTE< we let the environemnt catch all indexing errors > // maybe this is not good int i; for (i = 0; i < inputIndices.Length; i++) { int queriedIndex = inputIndices[i]; System.Diagnostics.Debug.Assert(instance.constants[queriedIndex].type == Datastructures.Variadic.EnumType.INT); int resultIndex = instance.constants[queriedIndex].valueInt; wiringInfo.ouputIndices[i] = resultIndex; } return(wiringInfo); }
override public void setParameterOperatorInstances(OperatorInstance instance, List <OperatorInstance> parameterInstances) { System.Diagnostics.Debug.Assert(parameterInstances.Count == 1); instance.constants = new Variadic[1]; instance.constants[0] = parameterInstances[0].constants[0]; }
override public IntrospectWiringInfo introspectWiring(OperatorInstance instance, int[] inputIndices) { IntrospectWiringInfo result; result = new IntrospectWiringInfo(); result.type = IntrospectWiringInfo.EnumType.NOWIRING; return(result); }
override public void setParameterOperatorInstances(OperatorInstance instance, List <OperatorInstance> parameterInstances) { if (parameterInstances.Count != 2) { throw new Exception("OperatorAdd: The must be only two parameterInstances!"); } instance.calleeOperatorInstances = new OperatorInstance[2]; instance.calleeOperatorInstances[0] = parameterInstances[0]; instance.calleeOperatorInstances[1] = parameterInstances[1]; }
override public ExecutionResult executeSingleStep(OperatorInstance instance) { EnumOperationState operationState; operationState = (EnumOperationState)instance.operationState; if (operationState == EnumOperationState.EXECUTELEFTOPERAND) { return(Operator.ExecutionResult.createExecuteInstance(instance.calleeOperatorInstances[0])); } else if (operationState == EnumOperationState.EXECUTERIGHTOPERAND) { return(Operator.ExecutionResult.createExecuteInstance(instance.calleeOperatorInstances[1])); } else // operationState == EnumOperationState.execute { bool resultAsFloat; Variadic resultVariadic; resultVariadic = null; resultAsFloat = instance.calleeResults[0].type == Variadic.EnumType.FLOAT || instance.calleeResults[1].type == Variadic.EnumType.FLOAT; if (resultAsFloat) { float a, b, floatResult; a = getVariadicAsFloat(instance.calleeResults[0]); b = getVariadicAsFloat(instance.calleeResults[1]); floatResult = a + b; resultVariadic = new Variadic(Variadic.EnumType.FLOAT); resultVariadic.valueFloat = floatResult; } else { int a, b, intResult; a = instance.calleeResults[0].valueInt; b = instance.calleeResults[1].valueInt; intResult = a + b; resultVariadic = new Variadic(Variadic.EnumType.INT); resultVariadic.valueInt = intResult; } return(ExecutionResult.createResultInstance(resultVariadic)); } }
override public void operationCleanup(OperatorInstance instance);
// gets called from the executive if a (requested execution) operator(instance) was executed override public void feedOperatorInstanceResult(OperatorInstance instance, Variadic result);
override public ExecutionResult executeSingleStep(OperatorInstance instance);
override public void initializeOperatorInstance(OperatorInstance instance);
override public void setParameterOperatorInstances(OperatorInstance instance, List <OperatorInstance> parameterInstances);
override public IntrospectWiringInfo introspectWiring(OperatorInstance instance, int[] inputIndices) { throw new NotImplementedException(); }
override public ExecutionResult executeSingleStep(OperatorInstance instance) { return(ExecutionResult.createResultInstance(instance.constants[0])); }
// gets called from the executive if a (requested execution) operator(instance) was executed override public void feedOperatorInstanceResult(OperatorInstance instance, Variadic result) { instance.calleeResults.Add(result); instance.operationState++; }
override public void initializeOperatorInstance(OperatorInstance instance) { instance.calleeResults = new List <Variadic>(); }
/**//// <summary> /// 提交流程 /// </summary> /// <param name="userid"></param> /// <param name="operatorInsId"></param> /// <param name="commandName"></param> public string Run(string userid, string operatorInsId, string commandName) { if (string.IsNullOrEmpty(userid)) return WorkFlowConst.IsNullUserIdCode; if (string.IsNullOrEmpty(operatorInsId)) return WorkFlowConst.IsNullOperatorInsIdCode; if (string.IsNullOrEmpty(commandName)) return WorkFlowConst.IsNullCommandNameCode; DataTable operdt = OperatorInstance.GetOperatorInstance(operatorInsId); if (operdt != null && operdt.Rows.Count > 0) { WorkFlowId = operdt.Rows[0]["workflowId"].ToString(); WorkTaskId = operdt.Rows[0]["WorkTaskId"].ToString(); WorkFlowInstanceId = operdt.Rows[0]["workflowInsId"].ToString(); WorkTaskInstanceId = operdt.Rows[0]["worktaskInsId"].ToString(); UserId = userid; OperatorInstanceId = operatorInsId; CommandName = commandName; return Run(); } else { return WorkFlowConst.NoFoundInstanceCode; } } /**//// <summary> /// 启动流程,草稿和启动两种状态 /// </summary> public string Start() { try { if (string.IsNullOrEmpty(WorkFlowInstanceId)) WorkFlowInstanceId = Guid.NewGuid().ToString(); if (string.IsNullOrEmpty(WorkTaskInstanceId)) WorkTaskInstanceId = Guid.NewGuid().ToString(); if (string.IsNullOrEmpty(OperatorInstanceId)) OperatorInstanceId = Guid.NewGuid().ToString(); if (string.IsNullOrEmpty(UserId)) return WorkFlowConst.IsNullUserIdCode; if (string.IsNullOrEmpty(WorkFlowId)) return WorkFlowConst.IsNullWorkFlowIdCode; if (string.IsNullOrEmpty(WorkTaskId)) return WorkFlowConst.IsNullWorkTaskIdCode; if (string.IsNullOrEmpty(CommandName)) return WorkFlowConst.IsNullCommandNameCode; if (string.IsNullOrEmpty(WorkFlowNo)) return WorkFlowConst.IsNullWorkFlowNoCode; if (string.IsNullOrEmpty(WorkflowInsCaption)) return WorkFlowConst.IsNullWorkflowInsCaption; if (WorkFlowHelper.isTaskInsCompleted(WorkTaskInstanceId)) return WorkFlowConst.InstanceIsCompletedCode;//流程实例已完成,不能重复提交 //检查是否已经保存过草稿。如果已经保存过则不需要再创建实例,只保存业务表单数据, //此处的处理与交互节点的处理不同,需要加判断。 if (WorkTaskInstance.Exists(WorkTaskInstanceId)==false)//实例不存在,说明未保存过 { //创建流程实例 WorkFlowInstance workflowInstance = new WorkFlowInstance(); workflowInstance.WorkflowId = WorkFlowId; workflowInstance.WorkflowInsId = WorkFlowInstanceId; workflowInstance.WorkflowNo = WorkFlowNo; workflowInstance.WorkflowInsCaption = WorkflowInsCaption; workflowInstance.Description = Description; workflowInstance.Priority = Priority; if (IsDraft) workflowInstance.Status = "1"; else workflowInstance.Status = Status; workflowInstance.NowTaskId = WorkTaskId;//当前流程所处流程模板的位置 workflowInstance.isSubWorkflow = isSubWorkflow; workflowInstance.MainWorkflowInsId = MainWorkflowInsId; workflowInstance.MainWorktaskId = MainWorktaskId; workflowInstance.MainWorkflowId = MainWorkflowId; workflowInstance.MainWorktaskInsId = MainWorktaskInsId; workflowInstance.Create(); //创建启动节点的任务实例 WorkTaskInstance workTaskInstance = new WorkTaskInstance(); workTaskInstance.WorkflowId = WorkFlowId; workTaskInstance.WorktaskId = WorkTaskId; workTaskInstance.WorkflowInsId = WorkFlowInstanceId; workTaskInstance.WorktaskInsId = WorkTaskInstanceId; workTaskInstance.TaskInsCaption = WorkFlowTask.GetTaskCaption(WorkTaskId); if (isSubWorkflow)//是子流程调用,需要放到未认领任务中 { //workTaskInstance.PreviousTaskId = WorkTaskInstanceId; workTaskInstance.PreviousTaskId = MainWorktaskInsId; workTaskInstance.Status = "1"; } else//不是子流程调用,启动节点直接放入已认领任务中 { workTaskInstance.PreviousTaskId = WorkTaskInstanceId;//开始节点的前一节点等于自己 if (IsDraft) workTaskInstance.Status = "1"; else workTaskInstance.Status = "2"; } workTaskInstance.Create(); //创建启动节点的处理人实例 OperatorInstance operatorInstance = new OperatorInstance(); operatorInstance.OperatorInsId = OperatorInstanceId; operatorInstance.WorkflowId = WorkFlowId; operatorInstance.WorktaskId = WorkTaskId; operatorInstance.WorkflowInsId = WorkFlowInstanceId; operatorInstance.WorktaskInsId = WorkTaskInstanceId; operatorInstance.UserId = UserId; operatorInstance.OperRealtion = 0; operatorInstance.OperContent = UserId; string userName = UserData.GetUserNameById(UserId); if (string.IsNullOrEmpty(userName)) userName = "******"; operatorInstance.OperContentText = userName; operatorInstance.OperType = 3; if (isSubWorkflow)//是子流程调用,需要放到未认领任务中 operatorInstance.OperStatus = "0"; else//不是子流程调用,启动节点直接放入已认领任务中 { if (IsDraft) operatorInstance.OperStatus = "0"; else operatorInstance.OperStatus = "3"; } operatorInstance.Create(); } if (!IsDraft)//不是草稿状态,提交任务 { string result= WorkFlowHelper.CreateNextTaskInstance(UserId, WorkFlowId, WorkTaskId, WorkFlowInstanceId, WorkTaskInstanceId, OperatorInstanceId, CommandName); if (result != WorkFlowConst.SuccessCode) { WorkFlowEventArgs e = new WorkFlowEventArgs(this); e.ResultMsg = result; OnRunFail(this, e); return result; } else { WorkFlowEventArgs e = new WorkFlowEventArgs(this); e.ResultMsg = WorkFlowConst.SuccessMsg; OnRunSuccess(this, e); } } return WorkFlowConst.SuccessCode; } catch (Exception ex) { string msg = string.Format(WorkFlowConst.EngineErrorMsg, ex.Message); WorkFlowEventArgs e = new WorkFlowEventArgs(this); e.ResultMsg = msg; OnRunFail(this, e); return WorkFlowConst.OtherErrorCode; } }