//public ProcessEngine() //{ // this._ProcessInstances = new Dictionary<string, ProcessInstance>(); // this.modelInstanceIDMaps = new Dictionary<string, string>(); //} public string CreateProcessInstance(string Identity, int User, Dictionary <string, object> InputData = null) { // 获取流程模板 var def = ProcessModelCache.Instance[Identity]; // 获取流程的监听者 var _Ob = UnityContainerHelper.GetServer <IObservation>(def.ProcessOb.Name); var pID = Guid.NewGuid().ToString(); // 生成流程实例 var pi = new ProcessInstance() { ID = pID, Name = def.ID, }; pi.StartDate = DateTime.Now; pi.Version = 1; pi.CreateUser = User; pi.InputData = InputData; // 流程资源 def.Resources.ForEach(r => { var prs = new ProcessResouce() { Key = r.ID, Users = new Dictionary <string, string>() }; r.Users.ForEach(u => { prs.Users.Add(u.ID, u.Name); }); pi.ProcessResouces.Add(r.ID, prs); }); // 编译脚本代码 if (!string.IsNullOrEmpty(def.ConditionCode)) { pi.Compiled = ConditionExpression.Evaluator(def.ConditionCode, def.ID); } // 生成流程脚本实例 pi.GeneratTasks(def, InputData, _Ob); // 缓存流程实例 _ProcessInstances.Add(pID, pi); // 保存生成的流程实例 BPMDBService.Create(pi); return(pID); }
/// <summary> /// 恢复流程实例 /// </summary> /// <param name="TaskID"></param> /// <returns></returns> public static ProcessInstance BackUpInstance(string TaskID) { //var _IBPMProcessTaskIDMapService = UnityContainerHelper.GetServer<IBPMProcessTaskIDMapService>(); //var _IBPMProcessInstanceService = UnityContainerHelper.GetServer<IBPMProcessInstanceService>(); //var _IBPMTaskInstanceService = UnityContainerHelper.GetServer<IBPMTaskInstanceService>(); var _IBPMProcessTaskIDMapService = new BPMProcessTaskIDMapService(); var _IBPMProcessInstanceService = new BPMProcessInstanceService(); var _IBPMTaskInstanceService = new BPMTaskInstanceService(); var task = _IBPMTaskInstanceService.Get(new Guid(TaskID)); var tasks = _IBPMTaskInstanceService.GetList(t => t.ProcessID == task.ProcessID); var process = _IBPMProcessInstanceService.Get(task.ProcessID); var idMaps = _IBPMProcessTaskIDMapService.GetList(m => m.ProcessID == task.ProcessID); // 获取流程模板 var def = ProcessModelCache.Instance[process.Name]; // 获取流程的监听者 var _Ob = UnityContainerHelper.GetServer <IObservation>(def.ProcessOb.Name); // 生成流程实例 var pi = new ProcessInstance() { ID = task.ProcessID.ToString(), Name = def.Name, StartDate = process.StartDate, Version = process.Version }; // 编译脚本代码 if (!string.IsNullOrEmpty(def.ConditionCode)) { pi.Compiled = ConditionExpression.Evaluator(def.ConditionCode, def.ID); } // 流程资源 def.Resources.ForEach(r => { var prs = new ProcessResouce() { Key = r.ID, Users = new Dictionary <string, string>() }; r.Users.ForEach(u => { prs.Users.Add(u.ID, u.Name); }); pi.ProcessResouces.Add(r.ID, prs); }); pi.ModelInstanceIDMaps = new Dictionary <string, string>(); idMaps.ForEach(m => { pi.ModelInstanceIDMaps.Add(m.TaskKey, m.TaskID.ToString()); }); pi.OB = _Ob; // 生成流程脚本实例 pi.BackUpTasks(def, tasks); return(pi); }