/// <summary> /// 构造函数 /// </summary> /// <param name="engineContext">流程引擎上下文</param> /// <param name="processInst">流程实例</param> /// <param name="activityInst">活动实例</param> public ActivityContext(ProcessInst processInst, ActivityInst activityInst) { this.ProcessInst = processInst; this.ActivityInst = activityInst; }
/// <summary> /// 构造函数 /// </summary> /// <param name="engineContext">流程引擎上下文</param> /// <param name="processInst">流程实例</param> /// <param name="activityInst">活动实例</param> /// <param name="workItem">工作项</param> public WorkItemContext(ProcessInst processInst, ActivityInst activityInst, WorkItem workItem) { this.ProcessInst = processInst; this.ActivityInst = activityInst; this.WorkItem = workItem; }
/// <summary> /// 创建流程实例 /// </summary> /// <param name="processDefID">流程定义ID</param> /// <param name="parentProcessDefID">父流程ID</param> /// <param name="parentActivityID">父活动ID</param> /// <returns></returns> public string CreateAProcess(string processDefID, string parentProcessDefID, string parentActivityID) { ProcessDef processDef = repository.GetDomain<ProcessDef>(processDefID); if (processDef == null) { WFUtil.HandleException(new MessageException() { PromptMessage = string.Format("ID={0}的流程不存在", processDefID), Source = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, }); return string.Empty; } if (processDef.CurrentState == (short)ProcessStatus.Candidate) { WFUtil.HandleException(new MessageException() { PromptMessage = string.Format("ID={0}的流程还未发布,不能创建流程", processDefID), Source = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, }); return string.Empty; } DateTime startTime = DateTime.Now.AddSeconds(-2); ProcessDefine define = GetProcessDefine(processDefID); ProcessInst processInst = new ProcessInst() { ID = IdGenerator.NewComb().ToString(), ProcessDefID = processDefID, CreateTime = DateTime.Now, Creator = WFUtil.User.ID, CurrentState = (short)ProcessInstStatus.NoStart, IsTimeOut = 0, Name = processDef.Text, Description = processDef.Description, ParentProcessID = parentProcessDefID, ParentActivityID = parentActivityID, StartTime = startTime, EndTime = WFUtil.MaxDate, FinalTime = WFUtil.MaxDate, LimitTime = WFUtil.MaxDate, ProcessDefName = processDef.Text, ProcessVersion = processDef.Version, RemindTime = WFUtil.MaxDate, TimeOutTime = WFUtil.MaxDate }; Activity ad = Persistence.GetStartActivity(processDefID); ActivityInst activityInst = new ActivityInst() { ID = IdGenerator.NewComb().ToString(), ActivityDefID = ad.ID, CreateTime = DateTime.Now, CurrentState = (short)ActivityInstStatus.Compeleted, Description = ad.Description, EndTime = WFUtil.MaxDate, Name = string.Format("启动{0}", processDef.Text), ProcessInstID = processInst.ID, RollbackFlag = 0, StartTime = startTime, SubProcessInstID = string.Empty, Type = (short)ActivityType.StartActivity }; UnitOfWork.ExecuteWithTrans<ProcessInst>(() => { repository.SaveOrUpdate(processInst); repository.SaveOrUpdate(activityInst); if (processDef.IsActive != 1) { processDef.IsActive = 1; repository.SaveOrUpdate(processDef); } }); return processInst.ID; }