Skip to content

Commit

Permalink
Merge pull request #89 from neozhu/improvement
Browse files Browse the repository at this point in the history
Improvement
  • Loading branch information
neozhu authored Sep 14, 2024
2 parents 049f956 + 70cdc3a commit ad192b1
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 90 deletions.
28 changes: 15 additions & 13 deletions src/CodeGeneratorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public sealed class CodeGeneratorPackage : AsyncPackage

public static DTE2 _dte;

protected async override System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
protected async override Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await JoinableTaskFactory.SwitchToMainThreadAsync();

Expand All @@ -62,9 +62,11 @@ private void ExecuteAsync(object sender, EventArgs e)
NewItemTarget infrastructure = NewItemTarget.Create(_dte, "Infrastructure");
NewItemTarget ui = NewItemTarget.Create(_dte, "Server.UI");
var includes = new string[] { "IEntity", "BaseEntity", "BaseAuditableEntity", "BaseAuditableSoftDeleteEntity", "AuditTrail", "OwnerPropertyEntity","KeyValue" };

var testlist = ProjectHelpers.GetEntities(domain.Project);
var objectlist = ProjectHelpers.GetEntities(domain.Project)
.Where(x => includes.Contains(x.BaseName) && !includes.Contains(x.Name));
var entities = objectlist.Select(x=>x.Name).Distinct().ToArray();
.Where(x => x.IsEnum || (includes.Contains(x.BaseName) && !includes.Contains(x.Name)));
var entities = objectlist.Where(x=>x.IsEnum==false).Select(x=>x.Name).ToArray();
if (target == null && target.Project.Name == APPLICATIONPROJECT)
{
MessageBox.Show(
Expand Down Expand Up @@ -106,7 +108,7 @@ private void ExecuteAsync(object sender, EventArgs e)
};
foreach (var item in configurations)
{
AddItemAsync(objectClass, item, name, infrastructure).Forget();
AddItemAsync(objectClass, item, name, infrastructure, objectlist).Forget();
}

var list = new List<string>()
Expand Down Expand Up @@ -137,7 +139,7 @@ private void ExecuteAsync(object sender, EventArgs e)
};
foreach (var item in list)
{
AddItemAsync(objectClass,item, name, target).Forget();
AddItemAsync(objectClass,item, name, target, objectlist).Forget();
}

var pages = new List<string>()
Expand All @@ -150,7 +152,7 @@ private void ExecuteAsync(object sender, EventArgs e)
};
foreach (var item in pages)
{
AddItemAsync(objectClass,item, name, ui).Forget();
AddItemAsync(objectClass,item, name, ui, objectlist).Forget();
}

}
Expand All @@ -166,7 +168,7 @@ private void ExecuteAsync(object sender, EventArgs e)
}
}

private async Task AddItemAsync(IntellisenseObject classObject, string name,string itemname, NewItemTarget target)
private async Task AddItemAsync(IntellisenseObject classObject, string name,string itemname, NewItemTarget target,IEnumerable<IntellisenseObject> objectlist=null)
{
// The naming rules that apply to files created on disk also apply to virtual solution folders,
// so regardless of what type of item we are creating, we need to validate the name.
Expand All @@ -186,7 +188,7 @@ private async Task AddItemAsync(IntellisenseObject classObject, string name,stri
}
else
{
await AddFileAsync(classObject,name, itemname, target);
await AddFileAsync(classObject,name, itemname, target, objectlist);
}
}

Expand All @@ -210,7 +212,7 @@ private void ValidatePath(string path)
} while (!string.IsNullOrEmpty(path));
}

private async Task AddFileAsync(IntellisenseObject classObject, string name,string itemname, NewItemTarget target)
private async Task AddFileAsync(IntellisenseObject classObject, string name,string itemname, NewItemTarget target,IEnumerable<IntellisenseObject> objectlist=null)
{
await JoinableTaskFactory.SwitchToMainThreadAsync();
FileInfo file;
Expand Down Expand Up @@ -244,7 +246,7 @@ private async Task AddFileAsync(IntellisenseObject classObject, string name,stri
project = target.Project;
}

int position = await WriteFileAsync(project, classObject, file.FullName, itemname, target.Directory);
int position = await WriteFileAsync(project, classObject, file.FullName, itemname, target.Directory, objectlist);
if (target.ProjectItem != null && target.ProjectItem.IsKind(Constants.vsProjectItemKindVirtualFolder))
{
target.ProjectItem.ProjectItems.AddFromFile(file.FullName);
Expand Down Expand Up @@ -277,9 +279,9 @@ private async Task AddFileAsync(IntellisenseObject classObject, string name,stri
}
}

private static async Task<int> WriteFileAsync(Project project, IntellisenseObject classObject, string file,string itemname,string selectFolder)
private static async Task<int> WriteFileAsync(Project project, IntellisenseObject classObject, string file,string itemname,string selectFolder,IEnumerable<IntellisenseObject> objectlist=null)
{
string template = await TemplateMap.GetTemplateFilePathAsync(project, classObject,file, itemname, selectFolder);
string template = await TemplateMap.GetTemplateFilePathAsync(project, classObject,file, itemname, selectFolder, objectlist);

if (!string.IsNullOrEmpty(template))
{
Expand All @@ -299,7 +301,7 @@ private static async Task<int> WriteFileAsync(Project project, IntellisenseObjec
return 0;
}

private static async System.Threading.Tasks.Task WriteToDiskAsync(string file, string content)
private static async Task WriteToDiskAsync(string file, string content)
{
using (StreamWriter writer = new StreamWriter(file, false, GetFileEncoding(file)))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/IntellisenseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static void ProcessElement(CodeElement element, List<IntellisenseObject>
.FirstOrDefault(c => c.FullName != "System.Object");
}
catch { /* Silently continue. */ }
var baseClasses = new string[] { "BaseAuditableSoftDeleteEntity", "BaseAuditableEntity", "BaseEntity", "IEntity", "ISoftDelete" };
var baseClasses = new string[] { "BaseAuditableSoftDeleteEntity", "BaseAuditableEntity", "BaseEntity", "IEntity", "ISoftDelete", "OwnerPropertyEntity" };
if (baseClass != null && baseClasses.Contains(GetClassName(baseClass)))
{
ProcessClass(cc, baseClass, list, underProcess);
Expand Down
Loading

0 comments on commit ad192b1

Please sign in to comment.