private string AddServices(string fileData, IEntityAdditionOptions options, string projectFolder) { string contractNamespace = GetContractNamespace(options, projectFolder); fileData = UsingStatements.Add(fileData, contractNamespace); string projectNamespace = GetProjectNamespace(options, projectFolder); fileData = UsingStatements.Add(fileData, projectNamespace); // Insert into Startup-Method StringEditor stringEditor = new StringEditor(fileData); string addScopedStatement = GetAddScopedStatement(options.EntityNamePlural, projectFolder); stringEditor.NextThatContains($"void Startup{options.Domain}"); stringEditor.Next(); stringEditor.NextThatContains("}"); if (!stringEditor.GetLineAtOffset(-1).Trim().Equals("{")) { stringEditor.InsertNewLine(); } stringEditor.InsertLine($" // {options.EntityNamePlural}"); stringEditor.InsertLine(addScopedStatement); return(stringEditor.GetText()); }
public void UpdateDependencyProvider(IEntityAdditionOptions options, string projectFolder, string fileName) { string filePath = GetFilePath(options, projectFolder, fileName); string fileData = UpdateFileData(options, filePath, projectFolder); CsharpClassWriter.Write(filePath, fileData); }
public void Add(IEntityAdditionOptions options) { string filePath = this.pathService.GetAbsolutePathForDbContext(options); string fileData = UpdateFileData(options, filePath); CsharpClassWriter.Write(filePath, fileData); }
private string UpdateFileData(IEntityAdditionOptions options, string filePath) { string fileData = File.ReadAllText(filePath); string usingStatement = $"{options.ProjectName}.Persistence.Modules.{options.Domain}.{options.EntityNamePlural}"; fileData = UsingStatements.Add(fileData, usingStatement); StringEditor stringEditor = new StringEditor(fileData); // ----------- DbSet ----------- stringEditor.NextThatContains("CustomInstantiate"); stringEditor.InsertLine(GetDbSetLine(options)); stringEditor.InsertNewLine(); // ----------- OnModelCreating ----------- stringEditor.NextThatContains("this.OnModelCreatingPartial(modelBuilder);"); stringEditor.InsertLine(GetEmptyModelBuilderEntityLine(options)); stringEditor.InsertNewLine(); return(stringEditor.GetText()); }
private string GetFilePath(IEntityAdditionOptions options) { string fileName = options.DbProjectName + ".sqlproj"; string filePath = Path.Combine(options.DbDestinationFolder, fileName); return(filePath); }
private string UpdateFileData(IEntityAdditionOptions options, string filePath) { string fileData = File.ReadAllText(filePath); fileData = UsingStatements.Add(fileData, $"{options.ProjectName}.Persistence.Modules.{options.Domain}.{options.EntityNamePlural}"); fileData = UsingStatements.Add(fileData, $"{options.ProjectName}.Persistence.Tests.Modules.{options.Domain}.{options.EntityNamePlural}"); // ----------- DbSet ----------- StringEditor stringEditor = new StringEditor(fileData); stringEditor.NextThatContains("persistenceDbContext.SaveChanges();"); if (options.HasRequestScope) { stringEditor.InsertLine($" persistenceDbContext.{options.EntityNamePlural}.Add(Db{options.EntityName}.ToEf{options.EntityName}(Db{options.EntityName}Test.DbDefault(), {options.EntityName}TestValues.{options.RequestScopeName}IdDbDefault));"); stringEditor.InsertLine($" persistenceDbContext.{options.EntityNamePlural}.Add(Db{options.EntityName}.ToEf{options.EntityName}(Db{options.EntityName}Test.DbDefault2(), {options.EntityName}TestValues.{options.RequestScopeName}IdDbDefault));"); } else { stringEditor.InsertLine($" persistenceDbContext.{options.EntityNamePlural}.Add(Db{options.EntityName}.ToEf{options.EntityName}(Db{options.EntityName}Test.DbDefault()));"); stringEditor.InsertLine($" persistenceDbContext.{options.EntityNamePlural}.Add(Db{options.EntityName}.ToEf{options.EntityName}(Db{options.EntityName}Test.DbDefault2()));"); } stringEditor.InsertNewLine(); return(stringEditor.GetText()); }
public void AddDto(IEntityAdditionOptions options, string domainFolder, string templateFilePath, string templateFileName) { string filePath = GetFilePath(options, domainFolder, templateFileName); string fileData = GetFileData(options, templateFilePath); CsharpClassWriter.Write(filePath, fileData); }
public void Add(IEntityAdditionOptions options) { string filePath = GetFilePath(options); string fileData = UpdateFileData(options, filePath); File.WriteAllText(filePath, fileData); }
public void AddEntityCore(IEntityAdditionOptions options, string domainFolder, string templateFilePath, string templateFileName) { string fileData = GetFileData(options, templateFilePath); string filePath = GetFilePath(options, domainFolder, templateFileName); TypescriptClassWriter.Write(filePath, fileData); }
public void AddEntityCore(IEntityAdditionOptions options, string domainFolder, string templateFilePath, string templateFileName) { string fileData = GetFileData(options, templateFilePath); string filePath = GetFilePath(options, domainFolder, templateFileName); File.WriteAllText(filePath, fileData); }
private string GetFilePath(IEntityAdditionOptions options, string domainFolder, string templateFileName) { string absolutePathForDTOs = this.pathService.GetAbsolutePathForDTOs(options, domainFolder); string fileName = templateFileName.Replace("Entity", options.EntityName); string filePath = Path.Combine(absolutePathForDTOs, fileName); return(filePath); }
private string GetAppRoutingLine(IEntityAdditionOptions options) { return (" {\n" + $" path: '{options.EntityNamePlural.ToKebab()}',\n" + $" loadChildren: () => import('./{options.EntityNamePlural.ToKebab()}/{options.EntityNamePlural.ToKebab()}-pages.module').then(m => m.{options.EntityNamePlural}PagesModule)\n" + " },"); }
public EntityAdditionOptions(IEntityAdditionOptions options) : base(options) { this.EntityName = options.EntityName; this.EntityNamePlural = options.EntityNamePlural; this.RequestScopeDomain = options.RequestScopeDomain; this.RequestScopeName = options.RequestScopeName; this.RequestScopeNamePlural = options.RequestScopeNamePlural; }
private string UpdateFileData(IEntityAdditionOptions options, string filePath, string projectFolder) { string fileData = File.ReadAllText(filePath); fileData = AddServices(fileData, options, projectFolder); return(fileData); }
private string GetFilePath(IEntityAdditionOptions options, string domainFolder, string templateFileName) { string absolutePathForDTOs = this.pathService.GetAbsolutePathForFrontendModel(options, domainFolder); string fileName = templateFileName.Replace("entity-kebab", StringConverter.PascalToKebabCase(options.EntityName)); string filePath = Path.Combine(absolutePathForDTOs, fileName); return(filePath); }
private string GetEmptyModelBuilderEntityLine(IEntityAdditionOptions options) { return($" modelBuilder.Entity<Ef{options.EntityName}>(entity =>\n" + " {\n" + $" entity.ToTable(\"{options.EntityNamePlural}\");\n" + "\n" + $" entity.Property(e => e.Id).ValueGeneratedNever();\n" + " });"); }
private string GetFilePath(IRelationAdditionOptions options, string domainFolder, string templateFileName) { IEntityAdditionOptions entityOptions = RelationAdditionOptions.GetPropertyForFrom(options); string absolutePathForDTOs = this.pathService.GetAbsolutePathForDTOs(entityOptions, domainFolder); string fileName = templateFileName.Replace("Entity", entityOptions.EntityName); string filePath = Path.Combine(absolutePathForDTOs, fileName); return(filePath); }
public void AddDtoFolder(IEntityAdditionOptions options, string domainFolder) { string absolutePathForDTOs = GetAbsolutePathForDTOs(options, domainFolder); if (!Directory.Exists(absolutePathForDTOs)) { Directory.CreateDirectory(absolutePathForDTOs); } }
public static string GetFileNameForEntityAddition(IEntityAdditionOptions options, string originalTemplateFileName) { if (options.HasRequestScope) { originalTemplateFileName = originalTemplateFileName.Replace(".txt", "-RequestScope.txt"); } return(originalTemplateFileName); }
public string GetAbsolutePathForEntity(IEntityAdditionOptions options, string domainFolder) { string relativePath = domainFolder; relativePath = relativePath.Replace("{Domain}", options.Domain); relativePath = relativePath.Replace("{Entities}", options.EntityNamePlural); string absolutePathForDomain = Path.Combine(options.BackendDestinationFolder, relativePath); return(absolutePathForDomain); }
public void PerformAddEntityCommand(IEntityAdditionOptions options) { try { this.AddEntity(options); } catch (Exception e) { Console.WriteLine("Fehler bei Entity-Generierung: " + e.Message); } }
public string GetAbsolutePathForFrontendPages(IEntityAdditionOptions options, string domainFolder) { string relativePath = domainFolder; relativePath = relativePath.Replace("{domain-kebab}", StringConverter.PascalToKebabCase(options.Domain)); relativePath = relativePath.Replace("{entity-kebab}", StringConverter.PascalToKebabCase(options.EntityName)); relativePath = relativePath.Replace("{entities-kebab}", StringConverter.PascalToKebabCase(options.EntityNamePlural)); string absolutePathForDomain = Path.Combine(options.FrontendDestinationFolder, relativePath); return(absolutePathForDomain); }
public void AddEntity(IEntityAdditionOptions options) { if (!EntityAdditionOptions.Validate(options)) { throw new OptionValidationException("Die Optionen sind nicht korrekt formatiert."); } foreach (ClassGeneration classGeneration in classGenerations) { classGeneration.PerformAddEntityCommand(options); } }
private string GetFilePath(IRelationAdditionOptions options, string domainFolder, string templateFileName) { IEntityAdditionOptions entityOptions = RelationAdditionOptions.GetPropertyForTo(options); string absolutePathForDomain = this.pathService.GetAbsolutePathForFrontendModel(entityOptions, domainFolder); string fileName = templateFileName.Replace("entities-kebab", StringConverter.PascalToKebabCase(entityOptions.EntityNamePlural)); fileName = fileName.Replace("entity-kebab", StringConverter.PascalToKebabCase(entityOptions.EntityName)); fileName = fileName.Replace("domain-kebab", StringConverter.PascalToKebabCase(entityOptions.Domain)); string filePath = Path.Combine(absolutePathForDomain, fileName); return(filePath); }
private string GetProjectNamespace(IEntityAdditionOptions options, string projectFolder) { if (projectFolder.Equals("Logic")) { return($"{options.ProjectName}.Logic.Modules.{options.Domain}.{options.EntityNamePlural}"); } else if (projectFolder.Equals("Persistence")) { return($"{options.ProjectName}.Persistence.Modules.{options.Domain}.{options.EntityNamePlural}"); } throw new ArgumentException("Argument 'projectFolder' invalid"); }
private string UpdateFileData(IEntityAdditionOptions options, string filePath) { string fileData = File.ReadAllText(filePath); StringEditor stringEditor = new StringEditor(fileData); // ----------- DbSet ----------- stringEditor.NextThatContains("const routes: Routes = ["); stringEditor.NextThatContains("];"); stringEditor.InsertLine(GetAppRoutingLine(options)); return(stringEditor.GetText()); }
private string GetFileData(IEntityAdditionOptions options, string templateFileName) { string fileData = File.ReadAllText(templateFileName); fileData = fileData.Replace("ProjectName", options.ProjectName); fileData = fileData.Replace("entities-kebab", StringConverter.PascalToKebabCase(options.EntityNamePlural)); fileData = fileData.Replace("entity-kebab", StringConverter.PascalToKebabCase(options.EntityName)); fileData = fileData.Replace("Domain", options.Domain); fileData = fileData.Replace("Entities", options.EntityNamePlural); fileData = fileData.Replace("Entity", options.EntityName); fileData = fileData.Replace("entities", options.EntityNamePluralLower); fileData = fileData.Replace("entity", options.EntityNameLower); return(fileData); }
private string GetFileData(IEntityAdditionOptions options, string templateFilePath) { string fileData = File.ReadAllText(templateFilePath); fileData = fileData.Replace("RequestScopeDomain", options.RequestScopeDomain); fileData = fileData.Replace("RequestScopes", options.RequestScopeNamePlural); fileData = fileData.Replace("RequestScope", options.RequestScopeName); fileData = fileData.Replace("Entities", options.EntityNamePlural); fileData = fileData.Replace("Entity", options.EntityName); fileData = fileData.Replace("entities", options.EntityNamePluralLower); fileData = fileData.Replace("entity", options.EntityNameLower); fileData = fileData.Replace("ProjectName", options.ProjectName); fileData = fileData.Replace("Domain", options.Domain); return(fileData); }
private static void ParseOptions(IEntityAdditionOptions options, string[] args) { string entityName = args[2]; options.Domain = entityName.Split('.')[0]; options.EntityName = entityName.Split('.')[1].Split(':')[0]; options.EntityNamePlural = entityName.Split(':')[1]; if (ArgumentParser.HasArgument(args, "-s", "--scope")) { string st = ArgumentParser.ExtractArgument(args, "-s", "--scope"); options.RequestScopeDomain = st.Split(':')[0].Split('.')[0]; options.RequestScopeName = st.Split(':')[0].Split('.')[1]; options.RequestScopeNamePlural = st.Split(':')[1]; } }
public static bool Validate(IEntityAdditionOptions options) { if (!DomainAdditionOptions.Validate(options) || string.IsNullOrEmpty(options.EntityName) || string.IsNullOrEmpty(options.EntityNamePlural) || !options.EntityName.IsAlpha() || !options.EntityNamePlural.IsAlpha()) { return(false); } options.EntityName = options.EntityName.UpperFirstChar(); options.EntityNamePlural = options.EntityNamePlural.UpperFirstChar(); return(true); }