Ejemplo n.º 1
0
        public bool Save(ISqlMapper mapper)
        {
            ActivityDefinitionDao dao = new ActivityDefinitionDao(mapper);
            var activity = dao.Query(new ActivityDefinitionQueryForm {
                ID = this.Value.ID
            }).FirstOrDefault();

            if (activity == null)
            {
                dao.Add(this.Value);
            }
            else
            {
                dao.Update(new ActivityDefinitionUpdateForm {
                    Entity = this.Value, ActivityDefinitionQueryForm = new ActivityDefinitionQueryForm {
                        ID = this.Value.ID
                    }
                });
            }
            return(true);
        }
        public static WorkflowDefinitionModel Load(string id)
        {
            var mapper = MapperHelper.GetMapper();
            WorkflowDefinitionDao         wfdao        = new WorkflowDefinitionDao(mapper);
            ActivityDefinitionDao         addao        = new ActivityDefinitionDao(mapper);
            LinkDefinitionDao             linkdao      = new LinkDefinitionDao(mapper);
            ActivityAuthDefinitionDao     aadd         = new ActivityAuthDefinitionDao(mapper);
            WorkflowDefinition            workflow     = null;
            List <ActivityDefinition>     activityList = new List <ActivityDefinition>();
            List <LinkDefinition>         linkList     = new List <LinkDefinition>();
            List <ActivityAuthDefinition> authList     = new List <ActivityAuthDefinition>();
            WorkflowDefinitionModel       model        = null;
            var item = cache.GetItem(id);

            if (item != null)
            {
                model = item.Value as WorkflowDefinitionModel;
                return(model);
            }
            workflow = wfdao.Query(new WorkflowDefinitionQueryForm {
                ID = id, Enabled = 1
            }).FirstOrDefault();
            activityList = addao.Query(new ActivityDefinitionQueryForm {
                WorkflowDefinitionID = id, Enabled = 1
            });
            linkList = linkdao.Query(new LinkDefinitionQueryForm {
                WorkflowDefinitionID = id
            });
            authList = aadd.Query(new ActivityAuthDefinitionQueryForm {
                WorkflowDefinitionID = id
            });
            if (workflow != null)
            {
                List <ActivityDefinitionModel> activityModelList = new List <ActivityDefinitionModel>();
                List <LinkDefinitionModel>     linkModelList     = new List <LinkDefinitionModel>();
                model = new WorkflowDefinitionModel
                {
                    value = workflow,
                };
                bool foundRoot = false;
                foreach (var link in linkList)
                {
                    linkModelList.Add(new LinkDefinitionModel
                    {
                        Value = link,
                    });
                }
                foreach (var activity in activityList)
                {
                    List <LinkDefinitionModel> preLinks = new List <LinkDefinitionModel>();
                    var preLinksTemp = linkModelList.FindAll(t => t.Value.ToActivityDefinitionID == activity.ID);

                    List <LinkDefinitionModel> nextLinks = new List <LinkDefinitionModel>();
                    var nextLinksTemp = linkModelList.FindAll(t => t.Value.FromActivityDefinitionID == activity.ID);


                    ActivityDefinitionModel activitymodel = new ActivityDefinitionModel
                    {
                        Value = activity,
                    };
                    if (authList != null)
                    {
                        activitymodel.AuthDefinition = authList.FindAll(t => t.ActivityDefinitionID == activity.ID);
                    }
                    activitymodel.PreLinks  = preLinksTemp;
                    activitymodel.NextLinks = nextLinksTemp;
                    activityModelList.Add(activitymodel);
                    //没有父连接说明是根节点
                    if (!foundRoot && preLinksTemp.Count == 0)
                    {
                        model.Root = activitymodel;
                        foundRoot  = true;
                    }
                }
                item = new CacheItem(id, model);
                cache.AddItem(item, 30 * 60);
            }

            return(model);
        }
        public static WorkflowDefinitionModel Load(string id)
        {
            var mapper = MapperHelper.GetMapper();
            WorkflowDefinitionDao wfdao = new WorkflowDefinitionDao(mapper);
            ActivityDefinitionDao addao = new ActivityDefinitionDao(mapper);
            LinkDefinitionDao linkdao = new LinkDefinitionDao(mapper);
            ActivityAuthDefinitionDao aadd = new ActivityAuthDefinitionDao(mapper);
            WorkflowDefinition workflow = null;
            List<ActivityDefinition> activityList = new List<ActivityDefinition>();
            List<LinkDefinition> linkList = new List<LinkDefinition>();
            List<ActivityAuthDefinition> authList = new List<ActivityAuthDefinition>();
            WorkflowDefinitionModel model = null;
            var item = cache.GetItem(id);
            if (item != null)
            {
                model = item.Value as WorkflowDefinitionModel;
                return model;
            }
            workflow = wfdao.Query(new WorkflowDefinitionQueryForm { ID = id, Enabled = 1 }).FirstOrDefault();
            activityList = addao.Query(new ActivityDefinitionQueryForm { WorkflowDefinitionID = id, Enabled = 1 });
            linkList = linkdao.Query(new LinkDefinitionQueryForm { WorkflowDefinitionID = id });
            authList = aadd.Query(new ActivityAuthDefinitionQueryForm { WorkflowDefinitionID = id });
            if (workflow != null)
            {
                List<ActivityDefinitionModel> activityModelList = new List<ActivityDefinitionModel>();
                List<LinkDefinitionModel> linkModelList = new List<LinkDefinitionModel>();
                model = new WorkflowDefinitionModel
                {
                    value = workflow,
                };
                bool foundRoot = false;
                foreach (var link in linkList)
                {
                    linkModelList.Add(new LinkDefinitionModel
                    {
                        Value = link,
                    });
                }
                foreach (var activity in activityList)
                {
                    List<LinkDefinitionModel> preLinks = new List<LinkDefinitionModel>();
                    var preLinksTemp = linkModelList.FindAll(t => t.Value.ToActivityDefinitionID == activity.ID);

                    List<LinkDefinitionModel> nextLinks = new List<LinkDefinitionModel>();
                    var nextLinksTemp = linkModelList.FindAll(t => t.Value.FromActivityDefinitionID == activity.ID);

                    ActivityDefinitionModel activitymodel = new ActivityDefinitionModel
                    {
                        Value = activity,
                    };
                    if (authList != null)
                    {
                        activitymodel.AuthDefinition = authList.FindAll(t => t.ActivityDefinitionID == activity.ID);
                    }
                    activitymodel.PreLinks = preLinksTemp;
                    activitymodel.NextLinks = nextLinksTemp;
                    activityModelList.Add(activitymodel);
                    //没有父连接说明是根节点
                    if (!foundRoot && preLinksTemp.Count == 0)
                    {
                        model.Root = activitymodel;
                        foundRoot = true;
                    }
                }
                item = new CacheItem(id, model);
                cache.AddItem(item, 30 * 60);
            }

            return model;
        }