diff --git a/src/CodeGeneratorPackage.cs b/src/CodeGeneratorPackage.cs index f0bd1df..10721cb 100644 --- a/src/CodeGeneratorPackage.cs +++ b/src/CodeGeneratorPackage.cs @@ -58,10 +58,10 @@ protected async override System.Threading.Tasks.Task InitializeAsync(Cancellatio private void ExecuteAsync(object sender, EventArgs e) { NewItemTarget target = NewItemTarget.Create(_dte); - NewItemTarget domain= NewItemTarget.Create(_dte, DOMAINPROJECT); - NewItemTarget infrastructure = NewItemTarget.Create(_dte, INFRASTRUCTUREPROJECT); - NewItemTarget ui = NewItemTarget.Create(_dte, UIPROJECT); - var includes = new string[] { "IEntity", "BaseEntity", "BaseAuditableEntity", "BaseAuditableSoftDeleteEntity", "AuditTrail", "OwnerPropertyEntity" }; + NewItemTarget domain= NewItemTarget.Create(_dte,"Domain"); + 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 objectlist = ProjectHelpers.GetEntities(domain.Project) .Where(x => includes.Contains(x.BaseName) && !includes.Contains(x.Name)); var entities = objectlist.Select(x=>x.Name).Distinct().ToArray(); diff --git a/src/Templatemap.cs b/src/Templatemap.cs index 5dbd7c0..de15c34 100644 --- a/src/Templatemap.cs +++ b/src/Templatemap.cs @@ -34,11 +34,11 @@ static TemplateMap() _folder = Path.Combine(Path.GetDirectoryName(assembly), "Templates"); _templateFiles.AddRange(Directory.GetFiles(_folder, "*" + _defaultExt, SearchOption.AllDirectories)); } - - public static async Task GetTemplateFilePathAsync(Project project, IntellisenseObject classObject, string file,string itemname,string selectFolder) + + public static async Task GetTemplateFilePathAsync(Project project, IntellisenseObject classObject, string file, string itemname, string selectFolder) { - var templatefolders =new string[]{ + var templatefolders = new string[]{ "Commands\\AcceptChanges", "Commands\\Create", "Commands\\Delete", @@ -70,18 +70,18 @@ public static async Task GetTemplateFilePathAsync(Project project, Intel // Look for direct file name matches if (list.Any(f => { - var pattern = templatefolders.Where(x => relative.IndexOf(x, StringComparison.OrdinalIgnoreCase) >= 0).First().Replace("\\","\\\\"); - var result = Regex.IsMatch(f, pattern, RegexOptions.IgnoreCase); - return result; - - }) ) + var pattern = templatefolders.Where(x => relative.IndexOf(x, StringComparison.OrdinalIgnoreCase) >= 0).First().Replace("\\", "\\\\"); + var result = Regex.IsMatch(f, pattern, RegexOptions.IgnoreCase); + return result; + + })) { - var tmplFile = list.OrderByDescending(x=>x.Length).FirstOrDefault(f => { + var tmplFile = list.OrderByDescending(x => x.Length).FirstOrDefault(f => { var pattern = templatefolders.Where(x => relative.IndexOf(x, StringComparison.OrdinalIgnoreCase) >= 0).First().Replace("\\", "\\\\"); ; var result = Regex.IsMatch(f, pattern, RegexOptions.IgnoreCase); if (result) { - return Path.GetFileNameWithoutExtension(f).Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).All(x=>name.IndexOf(x, StringComparison.OrdinalIgnoreCase)>=0); + return Path.GetFileNameWithoutExtension(f).Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).All(x => name.IndexOf(x, StringComparison.OrdinalIgnoreCase) >= 0); } return false; }); @@ -116,7 +116,7 @@ private static void AddTemplatesFromCurrentFolder(List list, string dir) list.InsertRange(0, dynaList); } - private static async Task ReplaceTokensAsync(Project project, IntellisenseObject classObject, string name, string relative,string selectRelative, string templateFile) + private static async Task ReplaceTokensAsync(Project project, IntellisenseObject classObject, string name, string relative, string selectRelative, string templateFile) { if (string.IsNullOrEmpty(templateFile)) { @@ -148,8 +148,8 @@ private static async Task ReplaceTokensAsync(Project project, Intellisen var mudFormFieldDefinition = createMudFormFieldDefinition(classObject); var fieldAssignmentDefinition = createFieldAssignmentDefinition(classObject); return content.Replace("{rootnamespace}", _defaultNamespace) - .Replace("{namespace}", ns) - .Replace("{selectns}", selectNs) + .Replace("{namespace}", ns) + .Replace("{selectns}", selectNs) .Replace("{itemname}", name) .Replace("{nameofPlural}", nameofPlural) .Replace("{dtoFieldDefinition}", dtoFieldDefinition) @@ -195,7 +195,7 @@ private static string splitCamelCase(string str) private static string createDtoFieldDefinition(IntellisenseObject classObject) { var output = new StringBuilder(); - foreach(var property in classObject.Properties.Where(x => x.Type.IsKnownType == true)) + foreach (var property in classObject.Properties.Where(x => x.Type.IsKnownType == true)) { output.Append($" [Description(\"{splitCamelCase(property.Name)}\")]\r\n"); if (property.Name == PRIMARYKEY) @@ -208,7 +208,7 @@ private static string createDtoFieldDefinition(IntellisenseObject classObject) { case "string" when property.Name.Equals("Name", StringComparison.OrdinalIgnoreCase): output.Append($" public {property.Type.CodeName} {property.Name} {{get;set;}} = String.Empty; \r\n"); - break; + break; case "string" when !property.Name.Equals("Name", StringComparison.OrdinalIgnoreCase) && !property.Type.IsArray && !property.Type.IsDictionary: output.Append($" public {property.Type.CodeName}? {property.Name} {{get;set;}} \r\n"); break; @@ -247,7 +247,7 @@ private static string createDtoFieldDefinition(IntellisenseObject classObject) } break; } - + } } return output.ToString(); @@ -333,10 +333,11 @@ private static string createMudTdDefinition(IntellisenseObject classObject) output.Append(" "); output.Append($" @context.Name\r\n"); } - if (classObject.Properties.Where(x => x.Type.IsKnownType == true && x.Name == defaultfieldName.Last()).Any()) { + if (classObject.Properties.Where(x => x.Type.IsKnownType == true && x.Name == defaultfieldName.Last()).Any()) + { output.Append(" "); output.Append($" @context.Description\r\n"); - } + } output.Append(" "); output.Append($" \r\n"); output.Append(" "); @@ -350,7 +351,7 @@ private static string createMudTdDefinition(IntellisenseObject classObject) { output.Append($" x.{property.Name})]\" > \r\n"); } - else if(property.Type.CodeName.Equals("System.DateTime", StringComparison.OrdinalIgnoreCase)) + else if (property.Type.CodeName.Equals("System.DateTime", StringComparison.OrdinalIgnoreCase)) { output.Append($" x.{property.Name}))]\" >@context.{property.Name}.Date.ToString(\"d\") \r\n"); } @@ -362,7 +363,7 @@ private static string createMudTdDefinition(IntellisenseObject classObject) { output.Append($" .{property.Name})]\" >@context.{property.Name} \r\n"); } - + } return output.ToString(); } @@ -421,7 +422,7 @@ private static string createMudFormFieldDefinition(IntellisenseObject classObjec output.Append(" "); output.Append($" \r\n"); break; - case "system.datetime?": + case "system.datetime?": output.Append($" \r\n"); output.Append(" "); output.Append($" x.{property.Name})]\" @bind-Date=\"model.{property.Name}\" For=\"@(() => model.{property.Name})\" Required=\"false\" RequiredError=\"@L[\"{splitCamelCase(property.Name).ToLower()} is required!\"]\">\r\n"); @@ -437,7 +438,7 @@ private static string createMudFormFieldDefinition(IntellisenseObject classObjec break; } - + } return output.ToString(); } @@ -446,9 +447,8 @@ private static string createMudFormFieldDefinition(IntellisenseObject classObjec private static string createFieldAssignmentDefinition(IntellisenseObject classObject) { var output = new StringBuilder(); - foreach (var property in classObject.Properties.Where(x => x.Type.IsKnownType == true)) + foreach (var property in classObject.Properties.Where(x => x.Type.IsKnownType == true && x.Name != "Id")) { - output.Append($" "); output.Append($" {property.Name} = dto.{property.Name}, \r\n"); } return output.ToString(); diff --git a/src/Templates/DTOs/.dto.cs.txt b/src/Templates/DTOs/.dto.cs.txt index 5c1c727..87fc26a 100644 --- a/src/Templates/DTOs/.dto.cs.txt +++ b/src/Templates/DTOs/.dto.cs.txt @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; namespace {namespace}; [Description("{nameofPlural}")] diff --git a/src/Templates/Pages/.razor.txt b/src/Templates/Pages/.razor.txt index 304fcd0..05ac46e 100644 --- a/src/Templates/Pages/.razor.txt +++ b/src/Templates/Pages/.razor.txt @@ -295,10 +295,9 @@ } private async Task OnClone() { - var copyitem = _selectedItems.First(); + var dto = _selectedItems.First(); var command = new AddEdit{itemname}Command(){ - Name = copyitem.Name, - Description = copyitem.Description, + {fieldAssignmentDefinition} }; var parameters = new DialogParameters<{itemname}FormDialog> { @@ -311,7 +310,7 @@ if (!state.Canceled) { await _table.ReloadServerData(); - _selectedItems.Remove(copyitem); + _selectedItems=new HashSet<{itemname}Dto>(); } } private async Task OnEdit({itemname}Dto dto) @@ -337,7 +336,7 @@ var parameters = new DialogParameters { { x=>x.Command, command }, - { x=>x.ContentText, string.Format(ConstantString.DeleteConfirmation, dto.Name) } + { x=>x.ContentText, string.Format(ConstantString.DeleteConfirmation, dto.Id) } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.Small, FullWidth = true, DisableBackdropClick = true }; var dialog = DialogService.Show(ConstantString.DeleteConfirmationTitle, parameters, options);