Пример #1
0
        /// <summary>
        /// 生成EntityManager
        /// </summary>
        /// <param name="entityFolder"></param>
        private void CreateEntityManager(ProjectItem entityFolder)
        {
            string content  = Engine.Razor.RunCompile("ManagerTemplate", typeof(EntityFileModel), fileModel);
            string fileName = $"{fileModel.Name}Manager.cs";

            SolutionUnit.AddFileToProjectItem(entityFolder, content, fileName);
        }
Пример #2
0
        /// <summary>
        /// 生成枚举文件
        /// </summary>
        /// <param name="entityFolder"></param>
        /// <param name="enumEntity"></param>
        private void CreateEnum(ProjectItem entityFolder, EnumEntity enumEntity)
        {
            enumEntity.NameSpace = fileModel.EntityNamespace;
            string content  = Engine.Razor.RunCompile("EnumTemplate", typeof(EnumEntity), enumEntity);
            string fileName = $"{enumEntity.EnumName}.cs";

            SolutionUnit.AddFileToProjectItem(entityFolder, content, fileName);
        }
Пример #3
0
        /// <summary>
        /// 生成创建Entity的Dto
        /// </summary>
        /// <param name="entityFolder"></param>
        private void CreateCreateEntityDto(ProjectItem entityFolder)
        {
            var dtoFolder = entityFolder.ProjectItems.AddFolder("Dtos");

            fileModel.Namespace += $".{entityFolder.Name}";
            fileModel.DirName    = dtoFolder.Name;
            string content = Engine.Razor.RunCompile("CreateEntityDtoTemplate", typeof(EntityFileModel), fileModel);
            // content = content.Replace("< /summary>", "</summary>");
            string fileName = $"{fileModel.Name}EditDto.cs";

            SolutionUnit.AddFileToProjectItem(dtoFolder, content, fileName);
        }
Пример #4
0
        /// <summary>
        /// 生成EntityAppService
        /// </summary>
        private void CreateEntityAppService()
        {
            var appServiceFolder = applicationProject.ProjectItems.AddFolder(fileModel.Name + "s");

            fileModel.Namespace = applicationProject.Name;
            fileModel.DirName   = appServiceFolder.Name;
            string content  = Engine.Razor.RunCompile("AppServiceTemplate", typeof(EntityFileModel), fileModel);
            string fileName = $"{fileModel.Name}AppService.cs";

            SolutionUnit.AddFileToProjectItem(appServiceFolder, content, fileName);

            CreateServiceDto(appServiceFolder);
        }
Пример #5
0
        /// <summary>
        /// 生成Entity类
        /// </summary>
        private void CreateEntity()
        {
            /*
             *  1. 在Core下新建一个文件夹
             *  2. 生成Entity文件
             *  3. 生成创建Entity的Dto
             *  4. 生成EntityManager
             */
            var entityFolder = coreProject.ProjectItems.AddFolder(fileModel.Name + "s");

            fileModel.Namespace       = $"{coreProject.Name}";
            fileModel.DirName         = entityFolder.Name;
            fileModel.EntityNamespace = $"{coreProject.Name}.{entityFolder.Name}";
            string content = Engine.Razor.RunCompile("EntityTemplate", typeof(EntityFileModel), fileModel);

            content = content.Replace("&quot;", "\"");
            string fileName = fileModel.Name + ".cs";

            SolutionUnit.AddFileToProjectItem(entityFolder, content, fileName);

            SetDbSetToDbContext($"{fileModel.Namespace}.{fileModel.DirName}", fileModel.Name);
            SetPermissionName(fileModel.Name, fileModel.Description);

            if (chkManager.Checked)
            {
                CreateEntityManager(entityFolder);
            }

            CreateCreateEntityDto(entityFolder);

            if (enumEntities != null && enumEntities.Count > 0)
            {
                foreach (var item in enumEntities)
                {
                    CreateEnum(entityFolder, item);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 生成Service下的Dto
        /// </summary>
        /// <param name="serviceFolder"></param>
        private void CreateServiceDto(ProjectItem serviceFolder)
        {
            var dtoFolder = serviceFolder.ProjectItems.AddFolder("Dtos");

            fileModel.Namespace += $".{fileModel.DirName}";
            fileModel.DirName    = dtoFolder.Name;

            // 分页查询输入
            string content  = Engine.Razor.RunCompile("GetPagedInputTemplate", typeof(EntityFileModel), fileModel);
            string fileName = $"GetPaged{fileModel.Name}Input.cs";

            SolutionUnit.AddFileToProjectItem(dtoFolder, content, fileName);

            // 分页结果
            content  = Engine.Razor.RunCompile("GetPagedOutputTemplate", typeof(EntityFileModel), fileModel);
            fileName = $"GetPaged{fileModel.Name}Output.cs";
            SolutionUnit.AddFileToProjectItem(dtoFolder, content, fileName);

            // 单条编辑返回结果
            content  = Engine.Razor.RunCompile("GetForEditOutputTemplate", typeof(EntityFileModel), fileModel);
            fileName = $"Get{fileModel.Name}ForEditOutput.cs";
            SolutionUnit.AddFileToProjectItem(dtoFolder, content, fileName);
        }
Пример #7
0
        private void btnBuild_Click(object sender, EventArgs e)
        {
            var    selectItem   = (ProjectItemFullPath)comboBox1.SelectedValue;
            var    projectItem  = selectItem.ProjectItem;
            string namespaceStr = selectItem.Namespace;

            var dtoFileModel = new DtoFileModel
            {
                Description     = txtRemark.Text,
                Name            = txtName.Text,
                EntityName      = lblSelectEntity.Text,
                UsingName       = lblSelectEntity.Tag.ToString(),
                DirName         = "",
                Namespace       = namespaceStr,
                ClassProperties = new List <ClassProperty>()
            };

            foreach (TextValue item in listSelectEntity.SelectedItems)
            {
                dtoFileModel.ClassProperties.Add(new ClassProperty
                {
                    CnName       = item.Text,
                    Name         = item.Value.Name,
                    PropertyType = item.Value.PropertyType
                });
            }

            string content = Engine.Razor.RunCompile("DtoTemplate", typeof(DtoFileModel), dtoFileModel);

            content = content.Replace("< /summary>", "</summary>");
            string fileName = dtoFileModel.Name + ".cs";

            SolutionUnit.AddFileToProjectItem(projectItem, content, fileName);

            MessageBox.Show("生成成功");
            this.Close();
        }