public void TestWorkflowAdd() { Workflow wf = new Workflow { Creator = "test add", Name = "testing add", Status = 0, CreateTime = DateTime.Now, WorkflowDefinitionID = "1", }; dao.Add(wf); WorkflowQueryForm form = new WorkflowQueryForm { ID = wf.ID, }; var statement = dao.Mapper.GetMappedStatement("QueryWorkflow"); if (!dao.Mapper.IsSessionStarted) { dao.Mapper.OpenConnection(); } RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, form, dao.Mapper.LocalSession); string result = scope.PreparedStatement.PreparedSql; var list = dao.Query(form); Assert.AreEqual(1, list.Count); Assert.AreEqual("testing add", list[0].Name); Assert.AreEqual("1", list[0].WorkflowDefinitionID); Assert.AreEqual("test add", list[0].Creator); Assert.AreEqual(0, list[0].Status); dao.Delete(form); }
/// <summary> /// 把流程实体新增到数据库 /// </summary> /// <returns></returns> public bool Create() { ISqlMapper mapper = MapperHelper.GetMapper(); WorkflowDao workflowdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); LinkDao linkdao = new LinkDao(mapper); ActivityAuthDao authdao = new ActivityAuthDao(mapper); workflowdao.Add(this.Value); var activities = this.Root.GetList(); List <Link> linkList = new List <Link>(); //保存节点 foreach (var activity in activities) { activitydao.Add(activity.Value); var activityinstance = activity as ActivityModel; //保存连接 if (activityinstance.PreLinks != null) { foreach (var link in activityinstance.PreLinks) { if (!linkList.Contains(link.Value)) { linkList.Add(link.Value); } } } if (activityinstance.NextLinks != null) { foreach (var link in activityinstance.NextLinks) { if (!linkList.Contains(link.Value)) { linkList.Add(link.Value); } } } //保存权限 foreach (var auth in activityinstance.Auth) { authdao.Add(auth); } } foreach (var link in linkList) { linkdao.Add(link); } return(true); }
public void Init() { WorkflowDao dao = new WorkflowDao(); dao.Delete(new WorkflowQueryForm { ID = "1" }); dao.Add(new Workflow { ID = "1", WorkflowDefinitionID = "1", Name = "UnitTest", CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, }); }
public WorkflowModel StartNew(string creator, string processid, IWorkflowAuthority iauth) { var mapper = MapperHelper.GetMapper(); WorkflowDao workflowdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); LinkDao linkdao = new LinkDao(mapper); ActivityAuthDao aadd = new ActivityAuthDao(mapper); TaskDao taskdao = new TaskDao(mapper); WorkflowModel model = null; Workflow wf = this.value.ConvertTo <Workflow>(); wf.ID = null; wf.Creator = creator; wf.Status = (int)WorkflowProcessStatus.Started; wf.WorkflowDefinitionID = this.value.ID; wf.ProcessID = processid; workflowdao.Add(wf); var activites = this.ActivityDefinitionList; var links = this.LinkDefinitionList; List <Activity> activityEntities = new List <Activity>(); foreach (var a in activites) { Activity activity = a.Value.ConvertTo <Activity>(); activity.Creator = creator; activity.ID = null; activity.WorkflowID = wf.ID; activity.ActivityDefinitionID = a.Value.ID; activity.Title = a.Value.Title; activity.Status = (int)ActivityProcessStatus.Started; List <ActivityAuth> authList = new List <ActivityAuth>(); //如果是开始节点,就设置为已处理 if (this.Root.Equals(a)) { activity.Status = (int)ActivityProcessStatus.Processed; activity.ProcessTime = DateTime.Now; } if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a)) { activity.Status = (int)ActivityProcessStatus.Processing; } activitydao.Add(activity); activityEntities.Add(activity); //权限处理 foreach (var ad in a.AuthDefinition) { ActivityAuth auth = ad.ConvertTo <ActivityAuth>(); auth.Creator = creator; auth.WorkflowID = wf.ID; auth.ActivityID = activity.ID; auth.ID = null; auth.ActivityAuthDefinitionID = ad.ID; aadd.Add(auth); authList.Add(auth); } //如果是第二节点,就设置成正在处理 if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a)) { ActivityModel activitymodel = new ActivityModel { Value = activity, }; var idlist = iauth.GetUserIDList(authList); var tasklist = activitymodel.GetTask(creator, idlist); foreach (var task in tasklist) { taskdao.Add(task); } } } foreach (var l in links) { Link link = l.Value.ConvertTo <Link>(); link.Creator = creator; link.WorkflowID = wf.ID; link.ID = null; link.LinkDefinitionID = l.Value.ID; var fromactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.FromActivityDefinitionID); var totactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.ToActivityDefinitionID); if (fromactivity != null) { link.FromActivityID = fromactivity.ID; } if (totactivity != null) { link.ToAcivityID = totactivity.ID; } linkdao.Add(link); } model = WorkflowModel.Load(wf.ID); return(model); }
/// <summary> /// 把流程实体新增到数据库 /// </summary> /// <returns></returns> public bool Create() { ISqlMapper mapper = MapperHelper.GetMapper(); WorkflowDao workflowdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); LinkDao linkdao = new LinkDao(mapper); ActivityAuthDao authdao = new ActivityAuthDao(mapper); workflowdao.Add(this.Value); var activities = this.Root.GetList(); List<Link> linkList = new List<Link>(); //保存节点 foreach (var activity in activities) { activitydao.Add(activity.Value); var activityinstance = activity as ActivityModel; //保存连接 if (activityinstance.PreLinks != null) { foreach (var link in activityinstance.PreLinks) { if (!linkList.Contains(link.Value)) { linkList.Add(link.Value); } } } if (activityinstance.NextLinks != null) { foreach (var link in activityinstance.NextLinks) { if (!linkList.Contains(link.Value)) { linkList.Add(link.Value); } } } //保存权限 foreach (var auth in activityinstance.Auth) { authdao.Add(auth); } } foreach (var link in linkList) { linkdao.Add(link); } return true; }
public WorkflowModel StartNew(string creator, string processid, IWorkflowAuthority iauth) { var mapper = MapperHelper.GetMapper(); WorkflowDao workflowdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); LinkDao linkdao = new LinkDao(mapper); ActivityAuthDao aadd = new ActivityAuthDao(mapper); TaskDao taskdao = new TaskDao(mapper); WorkflowModel model = null; Workflow wf = this.value.ConvertTo<Workflow>(); wf.ID = null; wf.Creator = creator; wf.Status = (int)WorkflowProcessStatus.Started; wf.WorkflowDefinitionID = this.value.ID; wf.ProcessID = processid; workflowdao.Add(wf); var activites = this.ActivityDefinitionList; var links = this.LinkDefinitionList; List<Activity> activityEntities = new List<Activity>(); foreach (var a in activites) { Activity activity = a.Value.ConvertTo<Activity>(); activity.Creator = creator; activity.ID = null; activity.WorkflowID = wf.ID; activity.ActivityDefinitionID = a.Value.ID; activity.Title = a.Value.Title; activity.Status = (int)ActivityProcessStatus.Started; List<ActivityAuth> authList = new List<ActivityAuth>(); //如果是开始节点,就设置为已处理 if (this.Root.Equals(a)) { activity.Status = (int)ActivityProcessStatus.Processed; activity.ProcessTime = DateTime.Now; } if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a)) { activity.Status = (int)ActivityProcessStatus.Processing; } activitydao.Add(activity); activityEntities.Add(activity); //权限处理 foreach (var ad in a.AuthDefinition) { ActivityAuth auth = ad.ConvertTo<ActivityAuth>(); auth.Creator = creator; auth.WorkflowID = wf.ID; auth.ActivityID = activity.ID; auth.ID = null; auth.ActivityAuthDefinitionID = ad.ID; aadd.Add(auth); authList.Add(auth); } //如果是第二节点,就设置成正在处理 if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a)) { ActivityModel activitymodel = new ActivityModel { Value = activity, }; var idlist = iauth.GetUserIDList(authList); var tasklist = activitymodel.GetTask(creator, idlist); foreach (var task in tasklist) { taskdao.Add(task); } } } foreach (var l in links) { Link link = l.Value.ConvertTo<Link>(); link.Creator = creator; link.WorkflowID = wf.ID; link.ID = null; link.LinkDefinitionID = l.Value.ID; var fromactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.FromActivityDefinitionID); var totactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.ToActivityDefinitionID); if (fromactivity != null) { link.FromActivityID = fromactivity.ID; } if (totactivity != null) { link.ToAcivityID = totactivity.ID; } linkdao.Add(link); } model = WorkflowModel.Load(wf.ID); return model; }