Skip to content

Commit

Permalink
Try to create the editing file if it does not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenjiang110 committed Jul 27, 2024
1 parent 2015388 commit 912b2b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
48 changes: 34 additions & 14 deletions Bob.Abp.AppGen/DteExtension/AbpCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,52 @@ public void CreateOrEditFiles(AbpMainFile abpFile)
{
var ahPrjItems = abpFile.GetAhProjectItems(_entity);
var templateData = new TemplateData(_entity);
foreach (var ahProjectItem in ahPrjItems)
foreach (var ahPrjItem in ahPrjItems)
{
if (ahProjectItem is AhEditProjectItem ahPrjItem)
if (ahPrjItem is AhEditProjectItem)
{
EditFile(templateData, ahPrjItem);
EditFile(templateData, ahPrjItem as AhEditProjectItem);
}
else
{
var prj = _sln.GetProject(ahProjectItem.ProjectType);
string fileName = ahProjectItem.FileName;
string fullFileName = _sln.GetAbsolutePath(ahProjectItem.ProjectType, ahProjectItem.RelativeFolder, fileName);
if ((!ahProjectItem.Secured && !_safeMode) || !File.Exists(fullFileName))
{
TemplateData data = new TemplateData(_entity);
string codes = data.Build(ahProjectItem);
prj.AddFileFromContent(ahProjectItem.RelativeFolder, fileName, codes);
}
CreateFile(ahPrjItem);
}
}
}

private bool CreateFile(AhProjectItem ahPrjItem)
{
var prj = _sln.GetProject(ahPrjItem.ProjectType);
string fileName = ahPrjItem.FileName;
string fullFileName = _sln.GetAbsolutePath(ahPrjItem.ProjectType, ahPrjItem.RelativeFolder, fileName);
if ((!ahPrjItem.Secured && !_safeMode) || !File.Exists(fullFileName))
{
TemplateData data = new TemplateData(_entity);
string codes = data.Build(ahPrjItem);
if (codes != null)
{
prj.AddFileFromContent(ahPrjItem.RelativeFolder, fileName, codes);
return true;
}
}
return false;
}

private bool EditFile(TemplateData templateData, AhEditProjectItem ahPrjItem)
{
var prjItem = ahPrjItem.ToProjectItem(_sln);
if (prjItem == null) return false; //ignore if file to modify donesn't exist.

if (prjItem == null)
{
if (CreateFile(ahPrjItem))
{
prjItem = ahPrjItem.ToProjectItem(_sln);
if (prjItem == null) return false;
}
else
{
return false;
}
}
CodeElement mainCodeElement = null;
//Core element's existence means assistant element was already prepared (added).
//And !safeMode means force to update the core element and only the core element.
Expand Down
1 change: 0 additions & 1 deletion Bob.Abp.AppGen/Models/Enums/AbpMainFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static class AbpMainFileExtension
new AhEditProjectItem(AbpProjectType.EntityFrameworkCore, "EntityFrameworkCore", "{0}DbContext.cs", vsCMElement.vsCMElementProperty, "{1}_s", "DbContext")
.AddEditPoint(null, vsCMElement.vsCMElementNamespace, Positions.Before, TemplateType.Using)
.AddEditPoint("{0}DbContext", vsCMElement.vsCMElementFunction, Positions.Before, TemplateType.Main),
new AhProjectItem(AbpProjectType.EntityFrameworkCore, "EntityFrameworkCore", "{0}DbContextModelCreatingExtensions.cs", "CreatingExtensions", secured: true),
new AhEditProjectItem(AbpProjectType.EntityFrameworkCore, "EntityFrameworkCore", "{0}DbContext.cs", vsCMElement.vsCMElementOther, "builder.Configure{0}()", "Configure")
.AddEditPoint("OnModelCreating", vsCMElement.vsCMElementFunction, Positions.End, TemplateType.Main),
new AhEditProjectItem(AbpProjectType.EntityFrameworkCore, "EntityFrameworkCore", "{0}DbContextModelCreatingExtensions.cs", vsCMElement.vsCMElementFunction, "Configure{1}", "CreatingExtensions")
Expand Down

0 comments on commit 912b2b8

Please sign in to comment.