Beispiel #1
0
        public static Tuple <bool, FlowTemplate, List <string> > createFlowTemplate(
            string guid, string name, string displayName,
            string version, string code, string flowTemplateJson,
            bool isPublished = false, bool isValidated = false)
        {
            List <string> errors           = new List <string>();
            var           basicCheckResult = validateFlowTemplateBasic(
                guid, name, displayName, version, code, flowTemplateJson,
                isPublished, isValidated);

            if (basicCheckResult.Item1 == false)
            {
                return(new Tuple <bool, FlowTemplate, List <string> >(
                           false, null, basicCheckResult.Item2));
            }

            bool result = true;

            using (var db = new EnouFlowTemplateDbContext())
            {
                #region 创建流程模板记录的检查
                if (db.flowTemplates.ToList().Exists(
                        obj => obj.code == code &&
                        obj.version == version))
                {
                    result = false;
                    errors.Add(string.Format(
                                   @"不能多次创建相同代码'{0}'相同版本'{1}'的流程模板;",
                                   code, version));
                }

                if (db.flowTemplates.ToList().Exists(obj => obj.guid == guid))
                {
                    result = false;
                    errors.Add(string.Format(
                                   @"不能多次创建相同guid'{0}'的流程模板;", guid));
                }
                if (!result)
                {
                    return(new Tuple <bool, FlowTemplate, List <string> >
                               (false, null, errors));
                }
                #endregion

                var flowTemplate = db.flowTemplates.Create();
                flowTemplate.guid             = guid;
                flowTemplate.name             = name;
                flowTemplate.displayName      = displayName;
                flowTemplate.version          = version;
                flowTemplate.code             = code;
                flowTemplate.flowTemplateJson = flowTemplateJson;
                flowTemplate.isPublished      = isPublished;
                flowTemplate.isValidated      = isValidated;
                db.flowTemplates.Add(flowTemplate);
                db.SaveChanges();
                return(new Tuple <bool, FlowTemplate, List <string> >(
                           true, flowTemplate, null));
            }
        }
Beispiel #2
0
        public static Tuple <bool, FlowDynamicUser, List <string> > createFlowDynamicUser(
            string guid, string name, string displayName, string script, string memo,
            bool isPublished = false, bool isValidated = false)
        {
            List <string> errors           = new List <string>();
            var           basicCheckResult = validateFlowDynamicUserBasic(
                guid, name, displayName, script, memo, isPublished, isValidated);

            if (basicCheckResult.Item1 == false)
            {
                return(new Tuple <bool, FlowDynamicUser, List <string> >(
                           false, null, basicCheckResult.Item2));
            }

            bool result = true;

            using (var db = new EnouFlowTemplateDbContext())
            {
                #region 创建流程动态用户的检查
                if (db.flowDynamicUsers.ToList().Exists(
                        obj => obj.name == name))
                {
                    result = false;
                    errors.Add(string.Format(
                                   @"不能多次创建相同名称'{0}'的流程动态用户;",
                                   name));
                }

                if (db.flowDynamicUsers.ToList().Exists(obj => obj.guid == guid))
                {
                    result = false;
                    errors.Add(string.Format(
                                   @"不能多次创建相同guid'{0}'的流程动态用户;", guid));
                }
                if (!result)
                {
                    return(new Tuple <bool, FlowDynamicUser, List <string> >
                               (false, null, errors));
                }
                #endregion

                var flowDynamicUser = db.flowDynamicUsers.Create();
                if (!string.IsNullOrWhiteSpace(guid))
                { // 支持自动生成guid
                    flowDynamicUser.guid = guid;
                }
                flowDynamicUser.name        = name;
                flowDynamicUser.displayName = displayName;
                flowDynamicUser.script      = script;
                flowDynamicUser.memo        = memo;
                flowDynamicUser.isPublished = isPublished;
                flowDynamicUser.isValidated = isValidated;
                db.flowDynamicUsers.Add(flowDynamicUser);
                db.SaveChanges();
                return(new Tuple <bool, FlowDynamicUser, List <string> >(
                           true, flowDynamicUser, null));
            }
        }
Beispiel #3
0
 public static void togglePublishOfFlowTemplate(int flowTemplateId)
 {
     using (var db = new EnouFlowTemplateDbContext())
     {
         var tpl = db.flowTemplates.Find(flowTemplateId);
         tpl.isPublished = !tpl.isPublished;
         db.SaveChanges();
     }
 }
Beispiel #4
0
        public static Tuple <bool, FlowDynamicUser, List <string> > updateFlowDynamicUser(
            string guid, string name, string displayName, string script, string memo,
            bool isPublished = false, bool isValidated = false, bool forceChangeName = false)
        {
            List <string> errors           = new List <string>();
            var           basicCheckResult = validateFlowDynamicUserBasic(
                guid, name, displayName, script, memo, isPublished, isValidated);

            if (basicCheckResult.Item1 == false)
            {
                return(new Tuple <bool, FlowDynamicUser, List <string> >(
                           false, null, basicCheckResult.Item2));
            }
            using (var db = new EnouFlowTemplateDbContext())
            {
                var flowDynamicUser = db.flowDynamicUsers.Where(
                    obj => obj.guid == guid).FirstOrDefault();

                #region 修改记录的检查
                if (flowDynamicUser == null)
                {
                    errors.Add("该流程动态用户在数据库中不存在,是否尚未在数据库中创建?");
                    return(new Tuple <bool, FlowDynamicUser, List <string> >(
                               false, flowDynamicUser, errors));
                }
                if (flowDynamicUser.isPublished)
                {
                    errors.Add("为不影响业务,不能直接更改已被发布的流程动态用户;");
                    return(new Tuple <bool, FlowDynamicUser, List <string> >(
                               false, flowDynamicUser, errors));
                }

                if (!forceChangeName && flowDynamicUser.name != name)
                {
                    errors.Add("如果需要对流程动态用户更名,需要指定forceChangeName参数为true;");
                    return(new Tuple <bool, FlowDynamicUser, List <string> >(
                               false, flowDynamicUser, errors));
                }
                #endregion
                flowDynamicUser.name        = name;
                flowDynamicUser.displayName = displayName;
                flowDynamicUser.script      = script;
                flowDynamicUser.memo        = memo;
                flowDynamicUser.isPublished = isPublished;
                flowDynamicUser.isValidated = isValidated;
                db.SaveChanges();

                return(new Tuple <bool, FlowDynamicUser, List <string> >(
                           true, flowDynamicUser, null));
            }
        }
Beispiel #5
0
        public static Tuple <bool, FlowTemplate, List <string> > setPublishStateOfFlowTemplate(
            string guid, bool isPublished = true)
        {
            List <string> errors = new List <string>();

            using (var db = new EnouFlowTemplateDbContext())
            {
                var flowTemplate = getFlowTemplate(guid);
                #region 修改流程模板记录的检查,暂无
                #endregion
                flowTemplate.isPublished = isPublished;
                db.SaveChanges();
                return(new Tuple <bool, FlowTemplate, List <string> >(
                           true, flowTemplate, null));
            }
        }
Beispiel #6
0
        public static void saveCreatedFlowTemplate(FlowTemplate flowTemplate)
        {
            using (var db = new EnouFlowTemplateDbContext())
            {
                //不能创建同名同版本且已被发布使用的流程模板
                if (db.flowTemplates.ToList().Exists(
                        obj => obj.name == flowTemplate.name &&
                        obj.version == flowTemplate.version &&
                        obj.isPublished == true))
                {
                    throw new DataLogicException("不能创建同名同版本且已被发布使用的流程模板.");
                }

                // TODO: 加入其它验证和字段的自动设置
                db.flowTemplates.Add(flowTemplate);
                db.SaveChanges();
            }
        }
Beispiel #7
0
        public static Tuple <bool, FlowTemplate, List <string> > updateFlowTemplate(
            string guid, string name, string displayName,
            string version, string code, string flowTemplateJson,
            bool isPublished = false, bool isValidated = false)
        {
            List <string> errors           = new List <string>();
            var           basicCheckResult = validateFlowTemplateBasic(
                guid, name, displayName, version, code, flowTemplateJson,
                isPublished, isValidated);

            if (basicCheckResult.Item1 == false)
            {
                return(new Tuple <bool, FlowTemplate, List <string> >(
                           false, null, basicCheckResult.Item2));
            }
            using (var db = new EnouFlowTemplateDbContext())
            {
                var flowTemplate = getFlowTemplate(guid);
                #region 修改流程模板记录的检查
                if (flowTemplate == null)
                {
                    errors.Add("该流程模板在数据库中不存在,是否尚未在数据库中创建?");
                    return(new Tuple <bool, FlowTemplate, List <string> >(
                               false, flowTemplate, errors));
                }
                if (flowTemplate.isPublished)
                {
                    errors.Add("为不影响业务,不能更改已被发布的流程模板;");
                    return(new Tuple <bool, FlowTemplate, List <string> >(
                               false, flowTemplate, errors));
                }
                #endregion
                flowTemplate.name             = name;
                flowTemplate.displayName      = displayName;
                flowTemplate.version          = version;
                flowTemplate.code             = code;
                flowTemplate.flowTemplateJson = flowTemplateJson;
                flowTemplate.isPublished      = isPublished;
                flowTemplate.isValidated      = isValidated;
                db.SaveChanges();
                return(new Tuple <bool, FlowTemplate, List <string> >(
                           true, flowTemplate, null));
            }
        }