예제 #1
0
        /// <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);
        }
예제 #3
0
 /// <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;
        }