public object doInWorkflowSession(RuntimeContext ctx) { WorkflowDefinition workflowDef = ctx.DefinitionService.GetTheLatestVersionOfWorkflowDefinition(wfprocessId); WorkflowProcess wfProcess = null; wfProcess = workflowDef.getWorkflowProcess(); if (wfProcess == null) { throw new Exception("Workflow process NOT found,id=[" + wfprocessId + "]"); } ProcessInstance processInstance = new ProcessInstance(); processInstance.CreatorId = creatorId; processInstance.ProcessId = wfProcess.Id; processInstance.Version = workflowDef.Version; processInstance.DisplayName = wfProcess.DisplayName; processInstance.Name = wfProcess.Name; processInstance.State = ProcessInstanceEnum.INITIALIZED; processInstance.CreatedTime = ctx.CalendarService.getSysDate(); processInstance.ParentProcessInstanceId = parentProcessInstanceId; processInstance.ParentTaskInstanceId = parentTaskInstanceId; ctx.PersistenceService.SaveOrUpdateProcessInstance( processInstance); // 初始化流程变量 List <DataField> datafields = wfProcess.DataFields; for (int i = 0; datafields != null && i < datafields.Count; i++) { DataField df = (DataField)datafields[i]; if (df.DataType == DataTypeEnum.STRING) { if (df.InitialValue != null) { processInstance.setProcessInstanceVariable(df.Name, df.InitialValue); } else { processInstance.setProcessInstanceVariable(df.Name, ""); } } else if (df.DataType == DataTypeEnum.INTEGER) { if (df.InitialValue != null) { try { Int32 intValue = Int32.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, intValue); } catch (Exception) { } } else { processInstance.setProcessInstanceVariable(df.Name, (Int32)0); } } else if (df.DataType == DataTypeEnum.LONG) { if (df.InitialValue != null) { try { long longValue = long.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, longValue); } catch (Exception) { } } else { processInstance.setProcessInstanceVariable(df.Name, (long)0); } } else if (df.DataType == DataTypeEnum.FLOAT) { if (df.InitialValue != null) { float floatValue = float.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, floatValue); } else { processInstance.setProcessInstanceVariable(df.Name, (float)0); } } else if (df.DataType == DataTypeEnum.DOUBLE) { if (df.InitialValue != null) { Double doubleValue = Double.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df .Name, doubleValue); } else { processInstance.setProcessInstanceVariable(df.Name, (Double)0); } } else if (df.DataType == DataTypeEnum.BOOLEAN) { if (df.InitialValue != null) { Boolean booleanValue = Boolean.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, booleanValue); } else { processInstance.setProcessInstanceVariable(df.Name, false); } } else if (df.DataType == DataTypeEnum.DATETIME) { // TODO 需要完善一下 if (df.InitialValue != null && df.DataPattern != null) { try { //SimpleDateFormat dFormat = new SimpleDateFormat(df.DataPattern); DateTime dateTmp = DateTime.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, dateTmp); } catch (Exception) { processInstance.setProcessInstanceVariable(df.Name, null); //e.printStackTrace(); } } else { processInstance.setProcessInstanceVariable(df.Name, null); } } } ctx.PersistenceService.SaveOrUpdateProcessInstance( processInstance); return(processInstance); }
public object doInWorkflowSession(RuntimeContext ctx) { WorkflowDefinition workflowDef = ctx.DefinitionService.GetTheLatestVersionOfWorkflowDefinition(wfprocessId); WorkflowProcess wfProcess = null; wfProcess = workflowDef.getWorkflowProcess(); if (wfProcess == null) { throw new Exception("Workflow process NOT found,id=[" + wfprocessId + "]"); } ProcessInstance processInstance = new ProcessInstance(); processInstance.CreatorId=creatorId; processInstance.ProcessId=wfProcess.Id; processInstance.Version=workflowDef.Version; processInstance.DisplayName=wfProcess.DisplayName; processInstance.Name=wfProcess.Name; processInstance.State=ProcessInstanceEnum.INITIALIZED; processInstance.CreatedTime=ctx.CalendarService.getSysDate(); processInstance.ParentProcessInstanceId=parentProcessInstanceId; processInstance.ParentTaskInstanceId=parentTaskInstanceId; ctx.PersistenceService.SaveOrUpdateProcessInstance( processInstance); // 初始化流程变量 List<DataField> datafields = wfProcess.DataFields; for (int i = 0; datafields != null && i < datafields.Count; i++) { DataField df = (DataField)datafields[i]; if (df.DataType == DataTypeEnum.STRING) { if (df.InitialValue != null) { processInstance.setProcessInstanceVariable(df.Name, df.InitialValue); } else { processInstance.setProcessInstanceVariable(df.Name, ""); } } else if (df.DataType == DataTypeEnum.INTEGER) { if (df.InitialValue != null) { try { Int32 intValue = Int32.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, intValue); } catch (Exception ) { } } else { processInstance.setProcessInstanceVariable(df.Name, (Int32)0); } } else if (df.DataType == DataTypeEnum.LONG) { if (df.InitialValue != null) { try { long longValue = long.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, longValue); } catch (Exception ) { } } else { processInstance.setProcessInstanceVariable(df.Name, (long)0); } } else if (df.DataType == DataTypeEnum.FLOAT) { if (df.InitialValue != null) { float floatValue = float.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, floatValue); } else { processInstance.setProcessInstanceVariable(df.Name, (float)0); } } else if (df.DataType == DataTypeEnum.DOUBLE) { if (df.InitialValue != null) { Double doubleValue = Double.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df .Name, doubleValue); } else { processInstance.setProcessInstanceVariable(df.Name, (Double)0); } } else if (df.DataType == DataTypeEnum.BOOLEAN) { if (df.InitialValue != null) { Boolean booleanValue = Boolean.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, booleanValue); } else { processInstance.setProcessInstanceVariable(df.Name, false); } } else if (df.DataType == DataTypeEnum.DATETIME) { // TODO 需要完善一下 if (df.InitialValue != null && df.DataPattern != null) { try { //SimpleDateFormat dFormat = new SimpleDateFormat(df.DataPattern); DateTime dateTmp = DateTime.Parse(df.InitialValue); processInstance.setProcessInstanceVariable(df.Name, dateTmp); } catch (Exception ) { processInstance.setProcessInstanceVariable(df.Name, null); //e.printStackTrace(); } } else { processInstance.setProcessInstanceVariable(df.Name, null); } } } ctx.PersistenceService.SaveOrUpdateProcessInstance( processInstance); return processInstance; }