Пример #1
0
 public override IEnumerable <TargetInfo> BuildCodeInfo()
 {
     foreach (var type in GetTypes())
     {
         var areaNameSpace = T4Help.GenerateNameSpace(type, null);
         yield return(new TargetInfo()
         {
             NamespaceName = $"FastFrame.Repository.{areaNameSpace}",
             ImportNames = new string[] {
                 $"FastFrame.Entity.{areaNameSpace}",
                 "FastFrame.Database",
                 "FastFrame.Infrastructure.Interface"
             },
             Summary = T4Help.GetClassSummary(type, XmlDocDir) + "[数据访问]",
             Name = $"{type.Name}Repository",
             BaseNames = new string[] { $"BaseRepository<{type.Name}>", $"IRepository<{type.Name}>" },
             Path = $"{TargetPath}",
             CategoryName = "class",
             Constructor = new ConstructorInfo()
             {
                 Parms = new ParameterInfo[] {
                     new ParameterInfo()
                     {
                         TypeName = "DataBase", DefineName = "context"
                     },
                     new ParameterInfo()
                     {
                         TypeName = "ICurrentUserProvider", DefineName = "currentUserProvider"
                     }
                 },
                 Super = new string[] { "context", "currentUserProvider" }
             }
         });
     }
 }
Пример #2
0
        public override IEnumerable <Info.TargetInfo> GetTargetInfoList()
        {
            foreach (var type in GetTypes())
            {
                var exportAttr = type.GetCustomAttribute <ExportAttribute>();

                if (exportAttr == null || !exportAttr.ExportMarks.Contains(ExportMark.ViewModel))
                {
                    continue;
                }

                var areaNameSpace = T4Help.GenerateNameSpace(type, null);
                yield return(new Info.TargetInfo
                {
                    NamespaceName = $"FastFrame.Application.{areaNameSpace}",
                    ImportNames = new[] { "System", "FastFrame.Entity.Enums" }
                    .Concat(type.GetProperties().Select(v => v.PropertyType.Namespace))
                    .Distinct(),
                    Summary = T4Help.GetClassSummary(type, XmlDocDir),
                    Name = $"{type.Name}ViewModel",
                    Path = $"{TargetPath}\\{areaNameSpace}\\{type.Name}\\Dto\\{type.Name}ViewModel.template.cs",
                    CategoryName = "class",
                    PropInfos = GetPropInfos(type),
                    BaseNames = new[] { "IViewModel" },
                    Constructor = new Info.ConstructorInfo
                    {
                        Modifier = "protected",
                    }
                });
            }
        }
Пример #3
0
 public override IEnumerable <TargetInfo> GetTargetInfoList()
 {
     foreach (var type in GetTypes())
     {
         var areaNameSpace = T4Help.GenerateNameSpace(type, null);
         yield return(new TargetInfo()
         {
             NamespaceName = $"FastFrame.Database.Mapping.{areaNameSpace}",
             ImportNames = new string[] { $"FastFrame.Entity.{areaNameSpace}", "Microsoft.EntityFrameworkCore.Metadata.Builders" },
             Summary = T4Help.GetClassSummary(type, XmlDocDir),
             Name = $"{type.Name}Mapping",
             BaseNames = new string[] { $"BaseEntityMapping<{type.Name}>" },
             Path = $"{TargetPath}\\{areaNameSpace}\\{type.Name}\\{type.Name}Mapping.template.cs",
             CategoryName = "class"
         });
     }
 }
Пример #4
0
        public TargetInfo GetTargetInfo(Type type)
        {
            var areaNameSpace = T4Help.GenerateNameSpace(type, null);

            var attrs = type.GetCustomAttributes <UniqueAttribute>().Select(x => new AttrInfo()
            {
                Name       = "Unique",
                Parameters = x.UniqueNames.Select(y => $"\"{y}\"")
            }).Union(type.GetCustomAttributes <RelatedFieldAttribute>().Select(x => new AttrInfo()
            {
                Name       = "RelatedField",
                Parameters = new[] {
                    $"\"{x.DefaultName}\""
                }.Union(x.OtherNames.Select(y => $"\"{y}\""))
            }));

            return(new Info.TargetInfo()
            {
                NamespaceName = $"FastFrame.Application.{areaNameSpace}",
                ImportNames = new string[] {
                    $"FastFrame.Entity.{areaNameSpace}",
                    "FastFrame.Infrastructure",
                    "System.ComponentModel.DataAnnotations",
                    "FastFrame.Entity.Enums",
                    "FastFrame.Entity.Basis",
                    "FastFrame.Entity",
                    "System.Collections.Generic",
                    "System"
                }
                .Union(type.GetProperties()
                       .Select(x => x.GetCustomAttribute <RelatedToAttribute>())
                       .Where(x => x != null)
                       .SelectMany(x => new[] { x.RelatedType.Namespace,
                                                $"FastFrame.Application.{T4Help.GenerateNameSpace(x.RelatedType,"")}" }))
                .Distinct(),
                Summary = T4Help.GetClassSummary(type, XmlDocDir),
                Name = $"{type.Name}Dto",
                BaseNames = new string[] { $"BaseDto<{type.Name}>" }
                .Concat(typeof(IHaveMultiFile).IsAssignableFrom(type) ? new[] { "IHaveMultiFileDto" } : Array.Empty <string>()),
                Path = $"{TargetPath}\\{areaNameSpace}\\{type.Name}\\Dto\\{type.Name}Dto.template.cs",
                CategoryName = "class",
                PropInfos = GetPropInfos(type),
                AttrInfos = Array.Empty <AttrInfo>() /*attrs*/
            });
        }
Пример #5
0
 private string ReplacePlaceholder(string line, Type type)
 {
     return(line.Replace("{{AreaName}}", T4Help.GenerateNameSpace(type, ""))
            .Replace("{{ModuleName}}", type.Name)
            .Replace("{{Description}}", T4Help.GetClassSummary(type, this.XmlDocDir)));
 }
Пример #6
0
        public override IEnumerable <TargetInfo> GetTargetInfoList()
        {
            foreach (var type in GetTypes())
            {
                var exportAttr = type.GetCustomAttribute <ExportAttribute>();

                if (exportAttr == null || !exportAttr.ExportMarks.Contains(ExportMark.Controller))
                {
                    continue;
                }

                var spaceName = T4Help.GenerateNameSpace(type, null);
                var name      = type.Name;
                var summary   = T4Help.GetClassSummary(type, XmlDocDir);

                var baseNames = new List <string>();
                if (typeof(Entity.IHasManage).IsAssignableFrom(type))
                {
                    baseNames.Add($"BaseCURDController<{name}Dto>");
                }
                else
                {
                    baseNames.Add($"BaseController<{name}Dto>");
                }

                yield return(new TargetInfo()
                {
                    Summary = summary,
                    Path = $"{TargetPath}\\{spaceName}\\{type.Name}\\{type.Name}Controller.template.cs",
                    NamespaceName = $"FastFrame.WebHost.Controllers.{spaceName}",
                    ImportNames = new string[] {
                        //$"FastFrame.Entity.{spaceName}",
                        $"FastFrame.Application.{spaceName}",
                        //"FastFrame.Infrastructure.Permission",
                        //"FastFrame.Infrastructure.Interface"
                    },
                    CategoryName = "class",
                    Name = $"{name}Controller",
                    BaseNames = baseNames,
                    FieldInfos = new FieldInfo[] {
                        new FieldInfo()
                        {
                            TypeName = $"{name}Service", FieldName = "service"
                        }
                    },
                    Constructor = new Info.ConstructorInfo()
                    {
                        Parms = new ParameterInfo[] {
                            new ParameterInfo()
                            {
                                TypeName = $"{name}Service", DefineName = "service"
                            }
                        },
                        Super = new string[] { "service" },
                        CodeBlock = new string[] {
                            "this.service = service;"
                        }
                    },
                    //AttrInfos = new[] {
                    //    new AttrInfo()
                    //    {
                    //        Name="PermissionGroup",
                    //        Parameters=new string[]{ $"nameof({name})" , $"\"{summary}\"" }
                    //    }
                    //}
                });
            }
        }
Пример #7
0
        public virtual void ModelEntityCreating(EntityTypeBuilder <T> entityTypeBuilder)
        {
            //Debugger.Launch();

            var entityType    = typeof(T);
            var currNameSpace = string.Join(",", entityType.Namespace.Split(new char[] { '.' }).Skip(2));

            if (typeof(IEntity).IsAssignableFrom(entityType))
            {
                /*指定主键*/
                entityTypeBuilder.HasKey("Id");
                entityTypeBuilder.Property("Id").ValueGeneratedNever();
                entityTypeBuilder.ToTable($"{currNameSpace}_{entityType.Name}".ToLower());
                entityTypeBuilder.HasComment(T4Help.GetClassSummary(entityType, AppDomain.CurrentDomain.BaseDirectory));
            }
            else
            {
                entityTypeBuilder
                .HasNoKey()
                .ToView($"{currNameSpace}_{entityType.Name}".ToLower());
            }


            /*过滤掉软删除的*/
            if (typeof(IHasSoftDelete).IsAssignableFrom(entityType))
            {
                entityTypeBuilder.Property <bool>("isdeleted");
                entityTypeBuilder.HasQueryFilter(v => !EF.Property <bool>(v, "isdeleted"));
                entityTypeBuilder.HasIndex("isdeleted").HasDatabaseName($"Index_{entityType.Name}_isdeleted");
            }

            if (typeof(IHasTenant).IsAssignableFrom(entityType))
            {
                entityTypeBuilder.Property <string>("tenant_id").HasMaxLength(25);
                entityTypeBuilder.HasIndex("tenant_id").HasDatabaseName($"Index_{entityType.Name}_tenant_id");
            }

            foreach (var item in typeof(T).GetProperties())
            {
                if (item.GetCustomAttribute <NotMappedAttribute>() != null)
                {
                    continue;
                }

                var propType = T4Help.GetNullableType(item.PropertyType);

                var propertyBuilder = entityTypeBuilder
                                      .Property(item.Name)
                                      .HasColumnName(item.Name.ToLower());

                propertyBuilder.HasComment(T4Help.GetPropertySummary(item, AppDomain.CurrentDomain.BaseDirectory));

                /*索引ID*/
                if (typeof(IEntity).IsAssignableFrom(entityType))
                {
                    if (item.Name.EndsWith("Id") && item.Name != "Id")
                    {
                        entityTypeBuilder.HasIndex(item.Name).HasDatabaseName($"Index_{entityType.Name}_{item.Name}");
                    }

                    if (propType == typeof(string))
                    {
                        /*所有字符串,指定为unicode*/
                        propertyBuilder.IsUnicode();

                        /*所有ID,指定长度为25*/
                        if (item.Name.EndsWith("Id"))
                        {
                            propertyBuilder.HasMaxLength(25);
                        }
                    }
                }
                if (propType == typeof(decimal))
                {
                    propertyBuilder.HasPrecision(10, 2);
                }

                else if (propType.IsEnum)
                {
                    propertyBuilder.HasConversion <string>().HasMaxLength(50);
                }
            }
        }
Пример #8
0
        public Info.TargetInfo Build(Type type)
        {
            /*当前类型区域名称*/
            string areaName = T4Help.GenerateNameSpace(type, null);

            /*所依赖[引用]的类型*/
            IEnumerable <RelatedToAttribute> relatedTypes = type.GetProperties()
                                                            .Select(x => x.GetCustomAttribute <RelatedToAttribute>())
                                                            .Where(x => x != null);

            /*要导入的命名空间*/
            IEnumerable <string> importNames = relatedTypes
                                               .Select(x => T4Help.GenerateNameSpace(x.RelatedType, null))
                                               .Union(new[] { areaName })
                                               .SelectMany(x => new string[] { $"FastFrame.Entity.{x}", })
                                               .Union(new string[] {
                $"FastFrame.Infrastructure.Interface",
                "FastFrame.Infrastructure",
                "FastFrame.Repository",
                "FastFrame.Entity.Basis",
                "System.Linq",
                "Microsoft.EntityFrameworkCore",
                "System.Threading.Tasks"
            })
                                               .Union(type.GetProperties()
                                                      .Select(x => x.GetCustomAttribute <RelatedToAttribute>())
                                                      .Where(x => x != null)
                                                      .SelectMany(x => new[] { x.RelatedType.Namespace,
                                                                               $"FastFrame.Application.{T4Help.GenerateNameSpace(x.RelatedType,"")}" }))
                                               .Distinct();

            /*要导入的依赖*/
            var depends = relatedTypes
                          .Select(x => x.RelatedType.Name)
                          .Union(new[] { "User", type.Name })
                          .Distinct()
                          .Select(x => new { type = $"IRepository<{x}>", name = $"{x.ToFirstLower()}Repository" });


            return(new Info.TargetInfo()
            {
                NamespaceName = $"FastFrame.Application.{areaName}",
                ImportNames = importNames,
                Name = $"{type.Name}Service",
                CategoryName = "class",
                BaseNames = new string[] { $"BaseService<{type.Name}, {type.Name}Dto>" },
                FieldInfos = depends.Select(x => new FieldInfo()
                {
                    FieldName = x.name, TypeName = x.type
                }),
                Constructor = new Info.ConstructorInfo()
                {
                    Parms = depends.Select(x => new ParameterInfo()
                    {
                        TypeName = x.type, DefineName = x.name
                    }),
                    Super = new string[] { $"{type.Name.ToFirstLower()}Repository" },
                    CodeBlock = depends.Select(x => $"this.{x.name}={x.name};")
                },
                MethodInfos = GetMethods(type),
                Summary = $"{T4Help.GetClassSummary(type, XmlDocDir)} 服务实现",
                Path = $"{TargetPath}\\{areaName}\\{type.Name}\\{type.Name}Service.template.cs"
            });
        }