private static List <CodeTemplateInfo> CreateCodeTemplates() { BasicOptionCfg option = Global.Option; EntityModel entity = Global.Entity; SolutionInfoModel solutionInfo = Global.SolutionInfo; string directoryName = Path.GetDirectoryName(typeof(CommonConsts).Assembly.Location); string directoryName2 = Path.GetDirectoryName(Global.SolutionInfo.CurrentSelectFilePath); string text = string.Empty; string str = directoryName2.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault <string>(); string uiParentDirName = string.Join("-", str.ConvertLowerSplitArray()); if (directoryName2.StartsWith(Global.SolutionInfo.Application.BasePath)) { text = directoryName2.Replace(Global.SolutionInfo.Application.BasePath + "\\", string.Empty); } if (directoryName2.StartsWith(Global.SolutionInfo.Core.BasePath)) { text = directoryName2.Replace(Global.SolutionInfo.Core.BasePath + "\\", string.Empty); } if (directoryName2.StartsWith(Global.SolutionInfo.EF.BasePath)) { text = directoryName2.Replace(Global.SolutionInfo.EF.BasePath + "\\", string.Empty); } if (option.IsAbpZero) { if (directoryName2.StartsWith(Global.SolutionInfo.Application_Shared.BasePath)) { text = directoryName2.Replace(Global.SolutionInfo.Application_Shared.BasePath + "\\", string.Empty); } if (directoryName2.StartsWith(Global.SolutionInfo.Core_Shared.BasePath)) { text = directoryName2.Replace(Global.SolutionInfo.Core_Shared.BasePath + "\\", string.Empty); } } string.IsNullOrWhiteSpace(text); CodeGenDto codeGenDto = new CodeGenDto(); codeGenDto.EntityDir = text; codeGenDto.TemplateBasePath = directoryName; codeGenDto.option = option; codeGenDto.UiParentDirName = uiParentDirName; codeGenDto.Entity = entity; codeGenDto.solutionInfoModel = solutionInfo; if (Global.MainViewModel.MainExtendedCfg.IsXstSolution) { return(CodeGen.GetMoonsXStCodeTemplates(codeGenDto)); } return(CodeGen.Get52abpDefaultCodeTemplates(codeGenDto)); }
public static MainPageViewModel Create(SolutionInfoModel model) { MainPageViewModel mainPageViewModel = new MainPageViewModel(); mainPageViewModel.OptionCfg = new BasicOptionCfg { IsAbpZero = model.IsAbpZero }; if (mainPageViewModel.OptionCfg.IsAbpZero) { mainPageViewModel.VersionInfo = "当前项目为ABP Zero"; } return(mainPageViewModel); }
public static GeneratorCodeReplaceInfo Create(SolutionInfoModel solutionInfo, BasicOptionCfg option, EntityModel entity) { GeneratorCodeReplaceInfo generatorCodeReplaceInfo = new GeneratorCodeReplaceInfo(); generatorCodeReplaceInfo.Multi_Language = new List <TranslatorTextList>(); generatorCodeReplaceInfo.SolutionNamespace = solutionInfo.SolutionNamespace; generatorCodeReplaceInfo.CompanyNamespace = solutionInfo.CompanyNamespace; generatorCodeReplaceInfo.BaseClassDtoReplacement = ": " + entity.BaseClassDtoName; if (generatorCodeReplaceInfo.BaseClassDtoReplacement == ": ") { generatorCodeReplaceInfo.BaseClassDtoReplacement = string.Empty; } else if (!string.IsNullOrEmpty(entity.BaseClassNameList)) { generatorCodeReplaceInfo.BaseClassDtoReplacement = generatorCodeReplaceInfo.BaseClassDtoReplacement + "," + entity.BaseClassNameList; } if (option.UseDomainManagerCode || option.IsAllGeneratorCode) { generatorCodeReplaceInfo.DomainServicesNamespace = "using " + entity.Namespace + ".DomainService;"; generatorCodeReplaceInfo.PrivateIEntityNameManager = string.Concat(new string[] { "private readonly I", entity.Name, "Manager _", entity.LowerName, "Manager;" }); generatorCodeReplaceInfo.IEntityNameManager = string.Concat(new string[] { ",I", entity.Name, "Manager ", entity.LowerName, "Manager" }); generatorCodeReplaceInfo.EntityNameManager = string.Concat(new string[] { "_", entity.LowerName, "Manager = ", entity.LowerName, "Manager;" }); } if (option.UseDomainAuthorizeCode || option.IsAllGeneratorCode) { generatorCodeReplaceInfo.DomainAuthorizationNamespace = "using " + entity.Namespace + ".Authorization;"; generatorCodeReplaceInfo.PermissionNode = string.Concat(new string[] { "[AbpAuthorize(", entity.Name, "Permissions.", "Node)]" }); generatorCodeReplaceInfo.PermissionQuery = string.Concat(new string[] { "[AbpAuthorize(", entity.Name, "Permissions.", "Query)]" }); generatorCodeReplaceInfo.PermissionCreate = string.Concat(new string[] { "[AbpAuthorize(", entity.Name, "Permissions.", "Create)]" }); generatorCodeReplaceInfo.PermissionEdit = string.Concat(new string[] { "[AbpAuthorize(", entity.Name, "Permissions.", "Edit)]" }); generatorCodeReplaceInfo.PermissionDelete = string.Concat(new string[] { "[AbpAuthorize(", entity.Name, "Permissions.", "Delete)]" }); generatorCodeReplaceInfo.PermissionBatchDelete = string.Concat(new string[] { "[AbpAuthorize(", entity.Name, "Permissions.", "BatchDelete)]" }); generatorCodeReplaceInfo.PermissionExportExcel = string.Concat(new string[] { "[AbpAuthorize(", entity.Name, "Permissions.", "ExportExcel)]" }); generatorCodeReplaceInfo.EntityCreateOrEditPermission = string.Concat(new string[] { "[AbpAuthorize(", entity.Name, "Permissions.", "Create, ", entity.Name, "Permissions.", "Edit)]" }); } return(generatorCodeReplaceInfo); }
public static SolutionInfoModel Create(Document currentSelectedDocument) { bool isAbpZero = false; Solution solution = currentSelectedDocument.Project.Solution; currentSelectedDocument.GetPossibleProjects(); List <Project> allProject = solution.Projects.ToList <Project>(); string currentProjectName = currentSelectedDocument.Project.Name; if (currentProjectName.Contains("(")) { currentProjectName = currentProjectName.Substring(0, currentProjectName.IndexOf("(")); } string projectStartName = currentSelectedDocument.Project.Name.Substring(0, currentProjectName.LastIndexOf(".")); if (allProject.Exists((Project p) => p.Name.Contains(".Shared"))) { isAbpZero = true; } Project application_SharedProject = null; Project core_SharedProject = null; Project applicationProject; Project coreProject; Project efProject; Project mvcProject; Project portalProject; Project hostProject; Project webCoreProject; if (isAbpZero) { applicationProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Application") && !item.Name.Contains(".Shared")); application_SharedProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Application.Shared")); coreProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Core") && !item.Name.Contains(".Shared")); core_SharedProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Core.Shared")); efProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".EntityFrameworkCore") && !item.Name.Contains(".Shared")); mvcProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Web.Mvc")); portalProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Web.Portal")); hostProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Web.Host")); webCoreProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Web.Core")); } else { applicationProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Application")); coreProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Core")); efProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".EntityFrameworkCore")); mvcProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Web.Mvc")); portalProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Web.Portal")); hostProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Web.Host")); webCoreProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Web.Core")); if (efProject == null) { "生成器只支持.net core/standard版本!不支持.net framework版本!".ErrorMsg(); return(null); } } Project xUnitTestsProject = allProject.Find((Project item) => item.Name.StartsWith(projectStartName + ".Tests")); if (applicationProject == null || coreProject == null || efProject == null) { "当前项目不是标准的ABP框架结构!请检查框架是否正确!".ErrorMsg(); return(null); } string solutionNamespace = string.Empty; string companyNamespace = string.Empty; ProjectPathInfo application = new ProjectPathInfo { PType = ProjectType.Application, BasePath = applicationProject.GetProjectPath(), ProjectName = applicationProject.Name }; ProjectPathInfo core = new ProjectPathInfo { PType = ProjectType.Core, BasePath = coreProject.GetProjectPath(), ProjectName = coreProject.Name }; ProjectPathInfo ef = new ProjectPathInfo { PType = ProjectType.Ef, BasePath = efProject.GetProjectPath(), ProjectName = efProject.Name }; string[] dtoSplitStrings = currentProjectName.Split(new char[] { '.' }); if (dtoSplitStrings.Length < 3) { solutionNamespace = dtoSplitStrings[0]; companyNamespace = string.Empty; } else { if (dtoSplitStrings.Length <= 2) { throw new Exception("解决方案项目的多层架构不符合52ABP规范,建议名称为Company.Project的形式。"); } solutionNamespace = dtoSplitStrings[1]; companyNamespace = dtoSplitStrings[0] + "."; } SolutionInfoModel solutionInfoModel = new SolutionInfoModel(); solutionInfoModel.IsAbpZero = isAbpZero; solutionInfoModel.Application = application; solutionInfoModel.Core = core; solutionInfoModel.EF = ef; solutionInfoModel.SolutionNamespace = solutionNamespace; solutionInfoModel.CompanyNamespace = companyNamespace; solutionInfoModel.CurrentProjectName = currentProjectName; solutionInfoModel.CurrentSelectFilePath = currentSelectedDocument.FilePath; solutionInfoModel.SolutionPath = Path.GetDirectoryName(solution.FilePath); if (hostProject != null) { ProjectPathInfo host = new ProjectPathInfo { PType = ProjectType.Host, BasePath = hostProject.GetProjectPath(), ProjectName = hostProject.Name }; solutionInfoModel.Host = host; } if (webCoreProject != null) { ProjectPathInfo webCore = new ProjectPathInfo { PType = ProjectType.WebCore, BasePath = webCoreProject.GetProjectPath(), ProjectName = webCoreProject.Name }; solutionInfoModel.WebCore = webCore; } if (mvcProject != null) { ProjectPathInfo mvc = new ProjectPathInfo { PType = ProjectType.Mvc, BasePath = mvcProject.GetProjectPath(), ProjectName = mvcProject.Name }; solutionInfoModel.MVC = mvc; } if (xUnitTestsProject != null) { ProjectPathInfo xUnitTests = new ProjectPathInfo { PType = ProjectType.XUnitTests, BasePath = xUnitTestsProject.GetProjectPath(), ProjectName = xUnitTestsProject.Name }; solutionInfoModel.Tests = xUnitTests; } if (portalProject != null) { ProjectPathInfo portal = new ProjectPathInfo { PType = ProjectType.Portal, BasePath = portalProject.GetProjectPath(), ProjectName = portalProject.Name }; solutionInfoModel.Portal = portal; } if (isAbpZero) { ProjectPathInfo application_Shared = new ProjectPathInfo { PType = ProjectType.Application_Shared, BasePath = application_SharedProject.GetProjectPath(), ProjectName = application_SharedProject.Name }; solutionInfoModel.Application_Shared = application_Shared; ProjectPathInfo projectPathInfo = new ProjectPathInfo(); projectPathInfo.PType = ProjectType.Core_Shared; projectPathInfo.BasePath = core_SharedProject.GetProjectPath(); projectPathInfo.ProjectName = core_SharedProject.Name; solutionInfoModel.Core_Shared = application_Shared; } return(solutionInfoModel); }
private static List <CodeTemplateInfo> Get52abpDefaultCodeTemplates(CodeGenDto dto) { List <CodeTemplateInfo> list = new List <CodeTemplateInfo>(); BasicOptionCfg option = dto.option; string entityDir = dto.EntityDir; string templateBasePath = dto.TemplateBasePath; EntityModel entity = dto.Entity; string uiParentDirName = dto.UiParentDirName; SolutionInfoModel solutionInfoModel = dto.solutionInfoModel; if (option.IsAllGeneratorCode || option.UseApplicationServiceCode) { string basePath = Global.SolutionInfo.Application.BasePath; string buildPath = Path.Combine(basePath, entityDir, "Mapper", entity.Name + "DtoAutoMapper.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\Mapper\\EntityDtoAutoMapper.txt"), buildPath)); if (option.UseExportExcel) { buildPath = Path.Combine(basePath, entityDir, "Exporting", "I" + entity.Name + "ListExcelExporter.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\Exporting\\IEntityListExcelExporter.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Exporting", entity.Name + "ListExcelExporter.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\Exporting\\EntityListExcelExporter.txt"), buildPath)); } buildPath = Path.Combine(basePath, entityDir, "I" + entity.Name + "AppService.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\IEntityApplicationService.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, entity.Name + "AppService.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\EntityApplicationService.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Dtos", "CreateOrUpdate" + entity.Name + "Input.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\Dtos\\CreateOrUpdateEntityInput.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Dtos", "Get" + entity.Name + "ForEditOutput.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\Dtos\\GetEntityForEditOutput.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Dtos", "Get" + entity.Name + "sInput.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\Dtos\\GetEntitysInput.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Dtos", entity.Name + "EditDto.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\Dtos\\EntityEditDto.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Dtos", entity.Name + "ListDto.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Application\\Dtos\\EntityListDto.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Readme.md"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Readme.txt"), buildPath)); if (option.UseNgZorro) { buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, "Readme.md" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Client\\NGZorro\\Readme.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, "create-or-edit-" + entity.SplitName, "create-or-edit-" + entity.SplitName + ".component.less" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Client\\NGZorro\\EntityEditViewCss.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, "create-or-edit-" + entity.SplitName, "create-or-edit-" + entity.SplitName + ".component.html" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Client\\NGZorro\\EntityEditViewHtml.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, "create-or-edit-" + entity.SplitName, "create-or-edit-" + entity.SplitName + ".component.ts" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Client\\NGZorro\\EntityEditViewTs.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, entity.SplitName + ".component.less" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Client\\NGZorro\\EntityListViewCss.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, entity.SplitName + ".component.html" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Client\\NGZorro\\EntityListViewHtml.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, entity.SplitName + ".component.ts" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Client\\NGZorro\\EntityListViewTs.txt"), buildPath)); } } if (option.IsAllGeneratorCode || option.UseDomainAuthorizeCode || option.UseDomainManagerCode) { string basePath2 = Global.SolutionInfo.Core.BasePath; string buildPath2 = string.Empty; if (option.UseDomainAuthorizeCode) { buildPath2 = Path.Combine(basePath2, entityDir, "Authorization", entity.Name + "AuthorizationProvider.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Domain\\Authorization\\EntityAuthorizationProvider.txt"), buildPath2)); buildPath2 = Path.Combine(basePath2, entityDir, "Authorization", entity.Name + "Permissions.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Domain\\Authorization\\EntityPermissions.txt"), buildPath2)); } if (option.UseDomainManagerCode) { buildPath2 = Path.Combine(basePath2, entityDir, "DomainService", "I" + entity.Name + "Manager.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Domain\\DomainService\\IEntityManager.txt"), buildPath2)); buildPath2 = Path.Combine(basePath2, entityDir, "DomainService", entity.Name + "Manager.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Domain\\DomainService\\EntityManager.txt"), buildPath2)); buildPath2 = Path.Combine(basePath2, entityDir, "Duoyuyan.md"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Domain\\Duoyuyan.txt"), buildPath2)); } buildPath2 = Path.Combine(basePath2, entityDir, "Readme.md"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Readme.txt"), buildPath2)); } string buildPath3 = Path.Combine(Global.SolutionInfo.EF.BasePath, "EntityMapper", entity.Name + "s", entity.Name + "Cfg.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\EntityFrameworkCore\\EntityMapper\\EntityCfg.txt"), buildPath3)); if (option.UseXUnitTests) { string buildPath4 = Path.Combine(Global.SolutionInfo.Tests.BasePath, entity.Name + "s", entity.Name + "AppService_Tests.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\Tests\\EntityAppService_Tests.txt"), buildPath4)); } if (option.InitGeneratorCode) { string basePath3 = Global.SolutionInfo.Application.BasePath; string buildPath5 = Path.Combine(basePath3, "Dtos", "PagedAndFilteredInputDto.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\InitGeneratorCode\\Dtos\\PagedAndFilteredInputDto.txt"), buildPath5)); buildPath5 = Path.Combine(basePath3, "Dtos", "PagedAndSortedInputDto.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\InitGeneratorCode\\Dtos\\PagedAndSortedInputDto.txt"), buildPath5)); buildPath5 = Path.Combine(basePath3, "Dtos", "PagedInputDto.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\InitGeneratorCode\\Dtos\\PagedInputDto.txt"), buildPath5)); buildPath5 = Path.Combine(basePath3, "Dtos", "PagedSortedAndFilteredInputDto.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\InitGeneratorCode\\Dtos\\PagedSortedAndFilteredInputDto.txt"), buildPath5)); basePath3 = Global.SolutionInfo.Core.BasePath; buildPath5 = Path.Combine(basePath3, "Authorization", "AppLtmPermissions.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\InitGeneratorCode\\AppLtmPermissions.txt"), buildPath5)); buildPath5 = Path.Combine(basePath3, solutionInfoModel.SolutionNamespace + "DomainServiceBase.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\InitGeneratorCode\\SolutionNameDomainServiceBase.txt"), buildPath5)); buildPath5 = Path.Combine(basePath3, "AppLtmConsts.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\InitGeneratorCode\\AppLtmConsts.txt"), buildPath5)); buildPath5 = Path.Combine(basePath3, "YoYoAbpefCoreConsts.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Server\\InitGeneratorCode\\YoYoAbpefCoreConsts.txt"), buildPath5)); } return(list); }
private static List <CodeTemplateInfo> GetMoonsXStCodeTemplates(CodeGenDto dto) { List <CodeTemplateInfo> list = new List <CodeTemplateInfo>(); BasicOptionCfg option = dto.option; string entityDir = dto.EntityDir; string templateBasePath = dto.TemplateBasePath; EntityModel entity = dto.Entity; string uiParentDirName = dto.UiParentDirName; SolutionInfoModel solutionInfoModel = dto.solutionInfoModel; if (option.IsAllGeneratorCode || option.UseApplicationServiceCode) { string basePath = Global.SolutionInfo.Application_Shared.BasePath; string buildPath = Path.Combine(basePath, entityDir, "I" + entity.Name + "AppService.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Application\\IEntityApplicationService.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Dtos", "Get" + entity.Name + "ForEditOutput.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Application\\Dtos\\GetEntityForEditOutput.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Dtos", entity.Name + "EditDto.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Application\\Dtos\\EntityEditDto.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Dtos", "Get" + entity.Name + "ForViewDto.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Application\\Dtos\\GetEntityForViewDto.txt"), buildPath)); basePath = Global.SolutionInfo.Application.BasePath; buildPath = Path.Combine(basePath, entityDir, "Mapper", entity.Name + "DtoAutoMapper.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Application\\Mapper\\EntityDtoAutoMapper.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, entity.Name + "AppService.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Application\\EntityApplicationService.txt"), buildPath)); buildPath = Path.Combine(basePath, entityDir, "Readme.md"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Readme.txt"), buildPath)); basePath = Global.SolutionInfo.Host.BasePath; buildPath = Path.Combine(new string[] { basePath, "wwwroot", "ConfigFiles", "ListViews", entity.ParentDirName + "." + entity.Name + ".xml" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\WebHost\\wwwroot\\EntityListViews.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, "wwwroot", "ConfigFiles", "PageFilters", entity.ParentDirName + "." + entity.Name + ".json" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\WebHost\\wwwroot\\PageFilters.txt"), buildPath)); if (!option.IsAbpZero && option.UseNgZorro) { buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, "Readme.md" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Moons\\Client\\NGZorro\\Readme.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, "create-or-edit-" + entity.SplitName, "create-or-edit-" + entity.SplitName + ".component.less" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Moons\\Client\\NGZorro\\EntityEditViewCss.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, "create-or-edit-" + entity.SplitName, "create-or-edit-" + entity.SplitName + ".component.html" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Moons\\Client\\NGZorro\\EntityEditViewHtml.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, "create-or-edit-" + entity.SplitName, "create-or-edit-" + entity.SplitName + ".component.ts" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Moons\\Client\\NGZorro\\EntityEditViewTs.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, entity.SplitName + ".component.less" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Client, Path.Combine(templateBasePath, "Templates\\Moons\\Client\\NGZorro\\EntityListViewCss.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, entity.SplitName + ".component.html" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Client\\NGZorro\\EntityListViewHtml.txt"), buildPath)); buildPath = Path.Combine(new string[] { basePath, entityDir, "Client", "NGZorro", uiParentDirName, entity.SplitName + ".component.ts" }); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Client\\NGZorro\\EntityListViewTs.txt"), buildPath)); } } if (option.IsAllGeneratorCode || option.UseDomainAuthorizeCode || option.UseDomainManagerCode) { string basePath2 = Global.SolutionInfo.Core.BasePath; string buildPath2 = string.Empty; if (option.UseDomainAuthorizeCode) { buildPath2 = Path.Combine(basePath2, entityDir, "Authorization", entity.Name + "Permissions.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Domain\\Authorization\\EntityPermissions.txt"), buildPath2)); } if (option.UseDomainManagerCode) { buildPath2 = Path.Combine(basePath2, entityDir, "DomainService", "I" + entity.Name + "Manager.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Domain\\DomainService\\IEntityManager.txt"), buildPath2)); buildPath2 = Path.Combine(basePath2, entityDir, "DomainService", entity.Name + "Manager.cs"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Domain\\DomainService\\EntityManager.txt"), buildPath2)); } buildPath2 = Path.Combine(basePath2, entityDir, "Readme.md"); list.Add(CodeTemplateInfo.Create(CodeTemplateType.Server, Path.Combine(templateBasePath, "Templates\\Moons\\Server\\Readme.txt"), buildPath2)); } return(list); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); try { VisualStudioWorkspace workspace = ((IComponentModel)Package.GetGlobalService(typeof(SComponentModel))).GetService <VisualStudioWorkspace>(); ProjectItem selectedItem = this.GetSelectedSolutionExplorerItem(); if (selectedItem != null && selectedItem.Name != null && !selectedItem.Name.EndsWith(".cs")) { "52ABP代码生成器(官网:52abp.com),仅支持C#文件!".ErrorMsg(); } else { Document currentSelectedDocument; if (((selectedItem != null) ? selectedItem.Document : null) != null) { currentSelectedDocument = workspace.CurrentSolution.GetDocumentByFilePath(selectedItem.Document.FullName); } else { if (selectedItem == null) { "致命异常-无法获得当前选择的解决方案:请重新打开这个解决方案,然后重试本工具。(官网:52abp.com)".ErrorMsg(); return; } string file = selectedItem.Name; string projectName = selectedItem.ContainingProject.Name; List <Project> allProjects = workspace.CurrentSolution.Projects.ToList <Project>(); List <Project> tmpProjects = (from o in allProjects where o.Name.StartsWith(projectName + "(net") select o).ToList <Project>(); List <Document> docs; if (allProjects.Exists((Project p) => p.Name.Contains(".Shared"))) { docs = (from d in (from p in allProjects where p.Name.Contains(projectName) && !p.Name.Contains(".Shared") select p).FirstOrDefault <Project>().Documents where d.Name == file select d).ToList <Document>(); } else if (tmpProjects.Count > 1) { docs = (from d in tmpProjects.FirstOrDefault <Project>().Documents where d.Name == file select d).ToList <Document>(); } else { docs = (from d in (from p in allProjects where p.Name == projectName select p).SelectMany((Project p) => p.Documents) where d.Name == file select d).ToList <Document>(); } if (docs.Count == 0) { "致命异常-无法获得当前选择的解决方案。请尝试重新打开解决方案,然后再使用本工具(官网:52abp.com)".ErrorMsg(); return; } if (docs.Count > 1) { "当前解决方案中,有多个同名的类文件,请处理之后再使用本工具,比如删除一个^_^(官网:52abp.com)。".ErrorMsg(); return; } currentSelectedDocument = docs.FirstOrDefault <Document>(); } SolutionInfoModel solutionInfo = SolutionInfoCreator.Create(currentSelectedDocument); string path = Path.Combine(solutionInfo.SolutionPath, "solutionInfo.json"); string solutionInfoJson = JsonConvert.SerializeObject(solutionInfo); path.CreateFile(solutionInfoJson); ProcessStartInfo processStartInfo = new ProcessStartInfo(); string exePath = Path.Combine(Path.GetDirectoryName(typeof(CommonConsts).Assembly.Location), "YoyoAbpCodePowerProject.WPF.exe"); processStartInfo.FileName = exePath; processStartInfo.Arguments = " \"" + solutionInfo.SolutionPath + "\""; Process.Start(processStartInfo); } } catch (Exception ex) { try { "发生了一个异常。请复制 c/p 堆栈信息,然后打开项目网站(https://github.com/52ABP/52ABP.CodeGenerator),补充问题和增加简短描述。".ErrorMsg(); StringBuilder sb = new StringBuilder(); sb.Append("<html><head></head><body><a hrf='https://github.com/52ABP/52ABP.CodeGenerator/issues/new'>baidu</a><br>"); sb.Append(ex.ToString()); sb.Append("</body></html>"); string tmpFile = Path.GetTempFileName(); File.WriteAllText(tmpFile, sb.ToString()); VsShellUtilities.OpenBrowser("file:///" + tmpFile); } catch (Exception) { "发生了一个异常。 无法将堆栈跟踪写入临时目录.".ErrorMsg(); } } }