Exemple #1
0
        internal PermissionModel GetPermissionModel(ulong modelID)
        {
            var modelNode = DesignTree.FindModelNode(ModelType.Permission, modelID);

            if (modelNode != null)
            {
                return((PermissionModel)modelNode.Model);
            }
            throw new Exception($"Cannot find EntityModel: {modelID}");
        }
Exemple #2
0
        public EntityModel GetEntityModel(ulong modelID)
        {
            var modelNode = DesignTree.FindModelNode(ModelType.Entity, modelID);

            if (modelNode != null)
            {
                return((EntityModel)modelNode.Model);
            }
            throw new Exception($"Cannot find EntityModel: {modelID}");
        }
        internal ApplicationNode(DesignTree tree, ApplicationModel model)
        {
            Model = model;
            Text  = model.Name;

            //添加各模型类型的根节点
            var modelRoot = new ModelRootNode(ModelType.Entity);

            Nodes.Add(modelRoot);
            tree.BindCheckoutInfo(modelRoot, false);

            modelRoot = new ModelRootNode(ModelType.Service);
            Nodes.Add(modelRoot);
            tree.BindCheckoutInfo(modelRoot, false);

            modelRoot = new ModelRootNode(ModelType.View);
            Nodes.Add(modelRoot);
            tree.BindCheckoutInfo(modelRoot, false);

            modelRoot = new ModelRootNode(ModelType.Workflow);
            Nodes.Add(modelRoot);
            tree.BindCheckoutInfo(modelRoot, false);

            modelRoot = new ModelRootNode(ModelType.Report);
            Nodes.Add(modelRoot);
            tree.BindCheckoutInfo(modelRoot, false);

            modelRoot = new ModelRootNode(ModelType.Enum);
            Nodes.Add(modelRoot);
            tree.BindCheckoutInfo(modelRoot, false);

            modelRoot = new ModelRootNode(ModelType.Event);
            Nodes.Add(modelRoot);
            tree.BindCheckoutInfo(modelRoot, false);

            modelRoot = new ModelRootNode(ModelType.Permission);
            Nodes.Add(modelRoot);
            tree.BindCheckoutInfo(modelRoot, false);

            //添加BlobStoreNode
            var blobNode = new BlobStoreNode();

            Nodes.Add(blobNode);
        }
Exemple #4
0
        /// <summary>
        /// 目前仅支持签出ModelRootNode及ModelNode
        /// </summary>
        public virtual async Task <bool> Checkout() //TODO:考虑加入参数允许签出所有下属节点
        {
            //判断是否已签出或者能否签出
            if (!AllowCheckout)
            {
                return(false);
            }
            if (IsCheckoutByMe)
            {
                return(true);
            }

            //调用签出服务
            List <CheckoutInfo> infos = new List <CheckoutInfo>();
            CheckoutInfo        info  = new CheckoutInfo(NodeType, CheckoutInfoTargetID, Version,
                                                         DesignTree.DesignHub.Session.Name,
                                                         DesignTree.DesignHub.Session.LeafOrgUnitID);

            infos.Add(info);
            CheckoutResult result = await CheckoutService.CheckoutAsync(infos);

            if (result.Success)
            {
                //签出成功则将请求的签出信息添加至当前的已签出列表
                DesignTree.AddCheckoutInfos(infos);
                //如果签出的是单个模型,且具备更新的版本,则更新
                if (this is ModelNode modelNode && result.ModelWithNewVersion != null)
                {
                    modelNode.Model = result.ModelWithNewVersion;                              //替换旧模型
                    await DesignTree.DesignHub.TypeSystem.UpdateModelDocumentAsync(modelNode); //更新为新模型的RoslynDocument
                }
                //更新当前节点的签出信息
                CheckoutInfo = infos[0];
            }

            return(result.Success);
        }
Exemple #5
0
        /// <summary>
        /// 根据实体模型生成虚拟代码
        /// </summary>
        public static string GenEntityDummyCode(EntityModel model, string appName, DesignTree designTree)
        {
            var sb = StringBuilderCache.Acquire();

            //sb.Append("using System;\n");
            sb.Append($"namespace {appName}.Entities {{\n");

            //TODO:生成注释
            //sb.Append("/// <summary>\n");
            //sb.AppendFormat("/// {0}\n", model.Name);
            //sb.Append("/// </summary>\n");
            sb.Append($"public class {model.Name}");
            //根据映射存储不同生成不同的继承
            if (model.SysStoreOptions != null)
            {
                sb.Append($": {TypeHelper.Type_SysEntityBase}");
            }
            else if (model.SqlStoreOptions != null)
            {
                sb.Append($": {TypeHelper.Type_SqlEntityBase}");
            }
            else if (model.CqlStoreOptions != null)
            {
                sb.Append($": {TypeHelper.Type_CqlEntityBase}");
            }
            else
            {
                sb.Append($": {TypeHelper.Type_EntityBase}");
            }
            sb.Append(" {\n");

            //生成静态TypeId属性
            sb.AppendFormat("[{0}(\"TypeId\")]\n", TypeHelper.MemberAccessInterceptorAttribute);
            sb.AppendLine("public const ulong TypeId = 0;");

            //生成成员属性
            EntityMemberModel[] ls = model.Members.ToArray();
            for (int i = 0; i < ls.Length; i++)
            {
                EntityMemberModel mm = ls[i];
                if (!string.IsNullOrEmpty(mm.Comment))
                {
                    sb.Append("/// <summary>\n");
                    sb.AppendFormat("/// {0}\n", mm.Comment);
                    sb.Append("/// </summary>\n");
                }

                string typeString = "object";
                bool   readOnly   = false;
                GetEntityMemberTypeStringAndReadOnly(mm, ref typeString, ref readOnly, designTree);

                sb.Append($"public {typeString} {mm.Name} {{get;");
                if (!readOnly)
                {
                    sb.Append("set;");
                }
                sb.Append("}\n");
            }

            //如果是分区表,生成带分区参数的构造方法
            if (model.SysStoreOptions != null && model.SysStoreOptions.HasPartitionKeys)
            {
                sb.Append($"public {model.Name}(");
                bool hasPreArg = false;
                for (int i = 0; i < model.SysStoreOptions.PartitionKeys.Length; i++)
                {
                    if (model.SysStoreOptions.PartitionKeys[i].MemberId != 0) //排除特殊分区键
                    {
                        if (hasPreArg)
                        {
                            sb.Append(',');
                        }
                        var    member     = model.GetMember(model.SysStoreOptions.PartitionKeys[i].MemberId, true);
                        string typeString = "object";
                        bool   readOnly   = false;
                        GetEntityMemberTypeStringAndReadOnly(member, ref typeString, ref readOnly, designTree);
                        sb.Append($"{typeString} {member.Name}");
                        hasPreArg = true;
                    }
                }
                sb.Append("){}");
            }
            //如果是SqlStore且具备主键生成主键参数构造,同时生成静态LoadAsync方法 //TODO:考虑排除自增主键
            if (model.SqlStoreOptions != null && model.SqlStoreOptions.HasPrimaryKeys)
            {
                var ctorsb = StringBuilderCache.Acquire();
                ctorsb.Append($"public {model.Name}(");
                sb.AppendFormat("[{0}(\"{1}\")]\n",
                                TypeHelper.InvocationInterceptorAttribute, LoadEntityInterceptor.Name);
                sb.Append($"public static System.Threading.Tasks.Task<{model.Name}> LoadAsync(");
                for (int i = 0; i < model.SqlStoreOptions.PrimaryKeys.Count; i++)
                {
                    var    mm         = model.GetMember(model.SqlStoreOptions.PrimaryKeys[i].MemberId, true);
                    string typeString = "object";
                    bool   readOnly   = false;
                    GetEntityMemberTypeStringAndReadOnly(mm, ref typeString, ref readOnly, designTree);
                    if (i != 0)
                    {
                        sb.Append(","); ctorsb.Append(",");
                    }
                    sb.Append($"{typeString} {mm.Name}"); //TODO:mm.Name转为小驼峰
                    ctorsb.Append($"{typeString} {mm.Name}");
                }
                sb.Append(") {return null;}\n");
                ctorsb.Append("){}");
                sb.Append(StringBuilderCache.GetStringAndRelease(ctorsb));
            }
            //如果是CqlStore生成主键参数构造, 同时生成静态LoadAsync方法
            if (model.CqlStoreOptions != null)
            {
                var ctorsb = StringBuilderCache.Acquire();
                ctorsb.Append($"public {model.Name}(");
                //sb.AppendFormat("[{0}(\"LoadEntity\")]\n", TypeHelper.InvocationInterceptorAttribute);
                //sb.Append($"public static System.Threading.Tasks.Task<{model.Name}> LoadAsync(");
                var pks = model.CqlStoreOptions.PrimaryKey.GetAllPKs();
                for (int i = 0; i < pks.Length; i++)
                {
                    var    mm         = model.GetMember(pks[i], true);
                    string typeString = "object";
                    bool   readOnly   = false;
                    GetEntityMemberTypeStringAndReadOnly(mm, ref typeString, ref readOnly, designTree);
                    if (i != 0)
                    {
                        ctorsb.Append(",");
                    }
                    //sb.Append($"{typeString} {mm.Name}"); //TODO:mm.Name转为小驼峰
                    ctorsb.Append($"{typeString} {mm.Name}");
                }
                //sb.Append(") {return null;}\n");
                ctorsb.Append("){}");
                sb.Append(StringBuilderCache.GetStringAndRelease(ctorsb));
            }

            //系统存储生成索引接口
            if (model.SysStoreOptions != null && model.SysStoreOptions.HasIndexes)
            {
                foreach (var index in model.SysStoreOptions.Indexes)
                {
                    sb.Append("public interface ");
                    sb.Append(index.Name);
                    sb.Append(" :IEntityIndex<");
                    sb.Append(model.Name);
                    sb.Append("> {");
                    for (int i = 0; i < index.Fields.Length; i++)
                    {
                        sb.Append("/// <summary>\n");
                        sb.AppendFormat("/// [{0}] {1}\n", i, index.Name); //TODO:OrderBy注释
                        sb.Append("/// </summary>\n");
                        var    mm         = model.GetMember(index.Fields[i].MemberId, true);
                        string typeString = "object";
                        bool   readOnly   = false;
                        GetEntityMemberTypeStringAndReadOnly(mm, ref typeString, ref readOnly, designTree);
                        sb.AppendFormat("{0} {1} {{get;}}", typeString, mm.Name);
                    }
                    sb.Append("}");
                }
            }

            //生成FetchEntitySet方法
            //sb.AppendFormat("\t\t[{0}(\"FetchEntitySetMethod\")]{1}", TypeHelper.InvocationInterceptorAttribute, Environment.NewLine);
            //sb.AppendFormat("\t\tpublic void FetchEntitySet<T>(System.Func<{0}.Entities.{1},EntityList<T>> selector) where T: EntityBase {{}}{2}"
            //                , model.AppID, model.Name, Environment.NewLine);
            //sb.AppendFormat("\t\t[{0}(\"FetchEntitySetMethod\")]{1}", TypeHelper.InvocationInterceptorAttribute, Environment.NewLine);
            //sb.AppendFormat("\t\tpublic void FetchEntitySet<T>(System.Func<{0}.Entities.{1},EntityList<T>> selector, System.Func<T, EntityBase[]> includes) where T: EntityBase {{}}{2}"
            //, model.AppID, model.Name, Environment.NewLine);

            sb.Append("}\n}");
            return(StringBuilderCache.GetStringAndRelease(sb));
        }
Exemple #6
0
        private static void GetEntityMemberTypeStringAndReadOnly(EntityMemberModel mm,
                                                                 ref string typeString, ref bool readOnly, DesignTree designTree)
        {
            switch (mm.Type)
            {
            case EntityMemberType.DataField:
                //判断是否是枚举
                DataFieldModel dmm = mm as DataFieldModel;
                //if (dmm.DataType == EntityFieldType.Enum)
                //{
                //    if (string.IsNullOrEmpty(dmm.EnumModelID))
                //        typeString = "int";
                //    else
                //    {
                //        string[] sr = dmm.EnumModelID.Split('.');
                //        typeString = sr[0] + ".Enums." + sr[1];
                //    }
                //}
                if (dmm.DataType == EntityFieldType.EntityId)
                {
                    typeString = "EntityId";
                }
                else
                {
                    typeString = dmm.DataType.GetValueType().FullName;     //TODO:简化类型名称
                }

                //系统存储分区键与sql存储的主键为只读
                readOnly |= dmm.IsPartitionKey || dmm.IsPrimaryKey;

                if (dmm.AllowNull && (dmm.DataType != EntityFieldType.String &&
                                      dmm.DataType != EntityFieldType.EntityId &&
                                      dmm.DataType != EntityFieldType.Binary && typeString != "object"))
                {
                    typeString += "?";
                }
                break;

            case EntityMemberType.EntityRef:
                EntityRefModel rm = (EntityRefModel)mm;
                if (rm.IsAggregationRef)
                {
                    typeString = TypeHelper.Type_EntityBase;
                }
                else
                {
                    if (rm.RefModelIds.Count == 0)     //Todo:待移除,因误删除模型引用项导致异常
                    {
                        typeString = TypeHelper.Type_EntityBase;
                    }
                    else
                    {
                        var targetModelNode = designTree.FindModelNode(ModelType.Entity, rm.RefModelIds[0]);
                        typeString = $"{targetModelNode.AppNode.Model.Name}.Entities.{targetModelNode.Model.Name}";
                    }
                }
                break;

            case EntityMemberType.EntitySet:
            {
                EntitySetModel sm = (EntitySetModel)mm;
                var            targetModelNode = designTree.FindModelNode(ModelType.Entity, sm.RefModelId);
                typeString = $"EntityList<{targetModelNode.AppNode.Model.Name}.Entities.{targetModelNode.Model.Name}>";
                readOnly   = true;
            }
            break;

            case EntityMemberType.AggregationRefField:
                typeString = "object";
                readOnly   = true;
                break;

            //case EntityMemberType.Formula:
            //case EntityMemberType.Aggregate:
            //FormulaModel fmm = mm as FormulaModel;
            //typeString = TypeService.GetEntityFieldValueType(fmm.DataType).FullName;
            //readOnly = true;
            //break;
            case EntityMemberType.Tracker:
                throw ExceptionHelper.NotImplemented();

            //GetEntityMemberTypeStringAndReadOnly(
            //    (mm as TrackerModel).TargetMember, ref typeString, ref readOnly);
            //readOnly = true;
            //break;
            case EntityMemberType.AutoNumber:
                typeString = "string";
                readOnly   = true;
                break;

            //case EntityMemberType.ImageRef:
            //typeString = TypeHelper.Type_IImageSource;
            //readOnly = false;
            //break;
            default:
                typeString = "object";
                break;
            }
        }
Exemple #7
0
 public ApplicationRootNode(DesignTree treeView)
 {
     _treeView = treeView;
     Text      = "Applications";
 }
Exemple #8
0
 public ApplicationModel GetApplicationModel(uint appId)
 {
     return(DesignTree.FindApplicationNode(appId).Model);
 }
Exemple #9
0
 public DesignHub(ISessionInfo session)
 {
     Session    = session ?? throw new ArgumentNullException(nameof(session));
     TypeSystem = new TypeSystem();
     DesignTree = new DesignTree(this);
 }
 internal DataStoreRootNode(DesignTree designTree)
 {
     _designTree = designTree;
     Text        = "DataStore";
 }