Example #1
0
        public override void GenerateCode()
        {
            if (_moduleViewModel == null)
            {
                throw new InvalidOperationException("需要先调用ShowUIAndValidate方法。");
            }

            Cursor currentCursor = Mouse.OverrideCursor;

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                var project = Context.ActiveProject;
                var entity  = _moduleViewModel.ModelType.CodeType;

                var entityPrimaryKeyType = "int";
                entityPrimaryKeyType = GetEntityPrimaryKeyType(entity);
                var entityName      = entity.Name;
                var entityNamespace = entity.Namespace.FullName;

                var projectNamespace = ProjectItemUtils.GetProjectName(entityNamespace);
                var functionName     = _moduleViewModel.FunctionName;
                var pluralEntityName = VmUtils.ToPlural(entityName);
                var entityFolerName  = ProjectItemUtils.GetModuleName(entityNamespace);
                var overwrite        = _moduleViewModel.OverwriteFiles;

                Dictionary <string, object> templateParams = new Dictionary <string, object>()
                {
                    { "AppName", projectNamespace }
                    ,
                    { "EntityNamespace", entityNamespace }
                    ,
                    { "EntityName", entityName }
                    ,
                    { "EntityPrimaryKeyType", entityPrimaryKeyType }
                    ,
                    { "EntityFolerName", entityFolerName }
                    ,
                    { "PluralEntityName", pluralEntityName }
                    ,
                    { "FunctionName", functionName }
                    ,
                    { "DtoMetaTable", _moduleViewModel.DtoClassMetadataViewModel.DataModel }
                };

                var templates = new[]
                {
                    @"{AppName}.Application\{EntityFolerName}\Dto\{Entity}EditDto.cs",
                    @"{AppName}.Application\{EntityFolerName}\Dto\{Entity}ListDto.cs",
                    @"{AppName}.Application\{EntityFolerName}\Dto\CreateOrUpdate{Entity}Input.cs",
                    @"{AppName}.Application\{EntityFolerName}\Dto\Get{Entity}ForEditOutput.cs",
                    @"{AppName}.Application\{EntityFolerName}\Dto\Get{Entity}ListInput.cs",
                    @"{AppName}.Application\{EntityFolerName}\{Entity}AppService.cs",
                    @"{AppName}.Application\{EntityFolerName}\I{Entity}AppService.cs",
                    @"{AppName}.Common\{Entity}Common.cs",
                    @"{AppName}.Core\IRepositories\I{Entity}Repository.cs",
                    @"{AppName}.EntityFramework\EntityFramework\Repositories\{Entity}Repository.cs"
                };
                foreach (var template in templates)
                {
                    string outputPath = Path.GetFileNameWithoutExtension(Path.Combine(@"_GeneratedCode\", template.Replace("{AppName}", projectNamespace)
                                                                                      .Replace("{EntityFolerName}", entityFolerName)
                                                                                      .Replace("{Entity}", entityName)));

                    string templatePath = Path.Combine(template);

                    AddFileFromTemplate(project, outputPath, templatePath, templateParams, !overwrite);
                }
            }
            finally
            {
                Mouse.OverrideCursor = currentCursor;
            }
        }
Example #2
0
        public override void GenerateCode()
        {
            if (_moduleViewModel == null)
            {
                throw new InvalidOperationException("需要先调用ShowUIAndValidate方法。");
            }

            Cursor currentCursor = Mouse.OverrideCursor;

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;

                var project          = Context.ActiveProject;
                var entity           = _moduleViewModel.ModelType.CodeType;
                var entityName       = entity.Name;
                var entityNamespace  = entity.Namespace.FullName;
                var entityFolerName  = ProjectItemUtils.GetModuleName(entityNamespace);
                var puralEntityName  = VmUtils.ToPlural(entityName);
                var projectNamespace = ProjectItemUtils.GetProjectName(entityNamespace);
                var overwrite        = _moduleViewModel.OverwriteFiles;
                Dictionary <string, object> templateParams = new Dictionary <string, object>()
                {
                    { "AppName", projectNamespace }
                    , { "EntityNamespace", entityNamespace }
                    , { "EntityFolerName", entityFolerName }
                    , { "PluralEntityName", puralEntityName }
                    , { "EntityName", entityName }
                    , { "DtoNamespace", _moduleViewModel.DtoNamespace }
                    , { "FunctionName", _moduleViewModel.FunctionName }
                    , { "DtoMetaTable", _moduleViewModel.DtoClassMetadataViewModel.DataModel }
                    , { "ItemMetaTable", _moduleViewModel.ItemClassMetadataViewModel.DataModel }
                };

                var templates = new[]
                {
                    @"{AppName}.Web\Areas\{Module}\Controllers\{PluralEntityName}Controller.cs",
                    @"{AppName}.Web\Areas\{Module}\Models\{PluralEntityName}\CreateOrEdit{Entity}ModalViewModel.cs",
                    @"{AppName}.Web\Areas\{Module}\Views\{PluralEntityName}\_CreateOrEditModal.cshtml",
                    @"{AppName}.Web\Areas\{Module}\Views\{PluralEntityName}\Index.cshtml",
                    @"{AppName}.Web\wwwroot\view-resources\Areas\{Module}\Views\{PluralEntityName}\_CreateOrEditModal.js",
                    @"{AppName}.Web\wwwroot\view-resources\Areas\{Module}\Views\{PluralEntityName}\Index.js",
                    @"{AppName}.Web\wwwroot\view-resources\Areas\{Module}\Views\{PluralEntityName}\index.less",
                    @"{AppName}.Common\{PluralEntityName}PageNames.cs",
                };
                foreach (var template in templates)
                {
                    string outputPath = Path.GetFileNameWithoutExtension(Path.Combine(@"_GeneratedCode\",
                                                                                      template.Replace("{AppName}", projectNamespace)
                                                                                      .Replace("{Module}", "Admin")
                                                                                      .Replace("{PluralEntityName}", puralEntityName)
                                                                                      .Replace("{Entity}", entityName)));

                    string templatePath = Path.Combine(template);

                    AddFileFromTemplate(project, outputPath, templatePath, templateParams, !overwrite);
                }
            }
            finally
            {
                Mouse.OverrideCursor = currentCursor;
            }
        }
Example #3
0
 private string getFunctionFolderName(string modelName)
 {
     modelName = modelName.Replace("Category", "");
     modelName = VmUtils.ToPlural(modelName);
     return(modelName);
 }