Ejemplo n.º 1
0
        private void GenerateAppDbContext(CodeGenerateDto dto)
        {
            var appDbContextTemplate = new AppDbContextTemplate();

            appDbContextTemplate.EntityNames = dto.Entities.Select(a => a.Name).ToList();
            Directory.CreateDirectory($@"{dto.BasePath}\Infrastructure");
            System.IO.File.WriteAllText($@"{dto.BasePath}\Infrastructure\AppDbContextPartial.cs", appDbContextTemplate.TransformText());
        }
Ejemplo n.º 2
0
        private void GenerateEnumJs(CodeGenerateDto dto)
        {
            var enumJsTemplate = new EnumJsTemplate();

            enumJsTemplate.Model = dto.Enums;
            Directory.CreateDirectory($@"{dto.BasePath}\Web\ClientApp\src\utils");
            System.IO.File.WriteAllText($@"{dto.BasePath}\Web\ClientApp\src\utils\enum.js", enumJsTemplate.TransformText());
        }
Ejemplo n.º 3
0
        private void GenerateVueApi(CodeGenerateDto dto)
        {
            var vueApiTemplate = new VueApiTemplate();

            vueApiTemplate.EntityNames = dto.Entities.Select(a => CodeGeneraterHelper.ToCamel(a.Name)).Where(a => !dto.ExceptApis.Contains(a, StringComparer.OrdinalIgnoreCase)).ToList();
            Directory.CreateDirectory($@"{dto.BasePath}\Web\ClientApp\src\api");
            System.IO.File.WriteAllText($@"{dto.BasePath}\Web\ClientApp\src\api\basic.js", vueApiTemplate.TransformText());
        }
Ejemplo n.º 4
0
 private void GenerateEntity(CodeGenerateDto dto)
 {
     foreach (var entity in dto.Entities)
     {
         var entityTemplate = new EntityTemplate();
         entityTemplate.Entity = entity;
         Directory.CreateDirectory($@"{dto.BasePath}\ApplicationCore\Entities");
         System.IO.File.WriteAllText($@"{dto.BasePath}\ApplicationCore\Entities\{entity.Name}.cs", entityTemplate.TransformText());
     }
 }
Ejemplo n.º 5
0
        private void GenerateVueRouter(CodeGenerateDto dto)
        {
            var vueRouterTemplate = new VueRouterTemplate();

            vueRouterTemplate.VueRouteModels = dto.Entities.Select(a => new VueRouteModel {
                Name = CodeGeneraterHelper.ToCamel(a.Name), Comment = a.Comment
            }).Where(a => !dto.ExceptApis.Contains(a.Name, StringComparer.OrdinalIgnoreCase)).ToList();
            Directory.CreateDirectory($@"{dto.BasePath}\Web\ClientApp\src\router");
            System.IO.File.WriteAllText($@"{dto.BasePath}\Web\ClientApp\src\router\basicRouters.js", vueRouterTemplate.TransformText());
        }
Ejemplo n.º 6
0
 private void GenerateEnum(CodeGenerateDto dto)
 {
     foreach (var enumModel in dto.Enums)
     {
         var enumTemplate = new EnumTemplate();
         enumTemplate.Model = enumModel;
         Directory.CreateDirectory($@"{dto.BasePath}\ApplicationCore\Enums");
         System.IO.File.WriteAllText($@"{dto.BasePath}\ApplicationCore\Enums\{enumModel.Name}.cs", enumTemplate.TransformText());
     }
 }
Ejemplo n.º 7
0
 private void GenerateEntityConfig(CodeGenerateDto dto)
 {
     foreach (var entity in dto.Entities)
     {
         var entityConfigTemplate = new EntityConfigTemplate();
         entityConfigTemplate.Entity = entity;
         Directory.CreateDirectory($@"{dto.BasePath}\Infrastructure\EntityTypeConfigurations");
         System.IO.File.WriteAllText($@"{dto.BasePath}\Infrastructure\EntityTypeConfigurations\{entity.Name}Configuration.cs", entityConfigTemplate.TransformText());
     }
 }
Ejemplo n.º 8
0
 private void Generater(CodeGenerateDto configDto)
 {
     GenerateEntity(configDto);
     GenerateService(configDto);
     GenerateEntityConfig(configDto);
     GenerateDto(configDto);
     GenerateController(configDto);
     GenerateAppDbContext(configDto);
     GenerateVue(configDto);
     GenerateVueApi(configDto);
     GenerateVueRouter(configDto);
     GenerateEnumJs(configDto);
     GenerateEnum(configDto);
 }
Ejemplo n.º 9
0
 private void GenerateService(CodeGenerateDto dto)
 {
     foreach (var entity in dto.Entities)
     {
         if (dto.ExceptServices.Contains(entity.Name, StringComparer.OrdinalIgnoreCase))
         {
             continue;
         }
         var serviceTemplate = new ServiceTemplate();
         serviceTemplate.Name = entity.Name;
         Directory.CreateDirectory($@"{dto.BasePath}\Service");
         System.IO.File.WriteAllText($@"{dto.BasePath}\Service\{entity.Name}Service.cs", serviceTemplate.TransformText());
     }
 }
Ejemplo n.º 10
0
 private void GenerateController(CodeGenerateDto dto)
 {
     foreach (var entity in dto.Entities)
     {
         if (dto.ExceptApis.Contains(entity.Name, StringComparer.OrdinalIgnoreCase))
         {
             continue;
         }
         var controllerTemplate = new ControllerTemplate();
         controllerTemplate.Name    = entity.Name;
         controllerTemplate.Comment = entity.Comment;
         Directory.CreateDirectory($@"{dto.BasePath}\Web\Controllers");
         System.IO.File.WriteAllText($@"{dto.BasePath}\Web\Controllers\{entity.Name}Controller.cs", controllerTemplate.TransformText());
     }
 }
Ejemplo n.º 11
0
        private void GenerateVue(CodeGenerateDto dto)
        {
            var vueModels = CodeGeneraterHelper.GenerateVueModelFromEntityModels(dto.Entities);

            foreach (var vue in vueModels)
            {
                if (dto.ExceptApis.Contains(vue.Name, StringComparer.OrdinalIgnoreCase))
                {
                    continue;
                }
                var vueTemplate = new VueTemplate();
                vueTemplate.Vue = vue;
                Directory.CreateDirectory($@"{dto.BasePath}\Web\ClientApp\src\views\basic");
                System.IO.File.WriteAllText($@"{dto.BasePath}\Web\ClientApp\src\views\basic\{vue.Name}.vue", vueTemplate.TransformText());
            }
        }
Ejemplo n.º 12
0
 private void GenerateDto(CodeGenerateDto dto)
 {
     foreach (var entity in dto.Entities)
     {
         new List <string> {
             "Result", "Save", "Source", "Query"
         }.ForEach(preFix =>
         {
             var dtoTemplate = new DtoTemplate();
             dtoTemplate.Dto = new DtoModel {
                 Name = entity.Name, Fields = preFix == "Query" ? new List <EntityFieldModel>() : entity.Fields, Prefix = preFix, BaseClass = preFix == "Query" ? "BasePagination,IDto" : "DefaultBaseDto"
             };
             dtoTemplate.Dto.Fields.ForEach(field =>
             {
                 if (field.Type.StartsWith("E") && field.Attributes != null)
                 {
                     field.Attributes = field.Attributes.Where(a => !a.Contains("MaxLength")).ToList();// dto的枚举过滤MaxLength特性
                 }
             });
             Directory.CreateDirectory($@"{dto.BasePath}\ApplicationCore\Dtos\{entity.Name}");
             System.IO.File.WriteAllText($@"{dto.BasePath}\ApplicationCore\Dtos\{entity.Name}\{entity.Name}{preFix}Dto.cs", dtoTemplate.TransformText());
         });
     }
 }