Skip to content

Commit

Permalink
simplify generate data
Browse files Browse the repository at this point in the history
  • Loading branch information
volkanceylan committed Oct 18, 2023
1 parent dfc5479 commit f7c27ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ namespace Serenity.CodeGenerator;

public partial class GenerateCommand
{
private static void UpdateConfigTable(EntityModelInputs inputs, string tableName,
GeneratorConfig.Connection confConnection,
GeneratorConfig.Table confTable)
private static void UpdateConfigTableFor(EntityModelInputs inputs,
GeneratorConfig.Connection confConnection)
{
var tableName = string.IsNullOrEmpty(inputs.Schema) ? inputs.Table : (inputs.Schema + "." + inputs.Table);

var confTable = confConnection?.Tables.FirstOrDefault(x => string.Compare(x.Tablename, tableName,
StringComparison.OrdinalIgnoreCase) == 0);

if (confConnection == null)
{
confConnection = new GeneratorConfig.Connection
Expand All @@ -25,7 +29,7 @@ private static void UpdateConfigTable(EntityModelInputs inputs, string tableName
Identifier = inputs.Identifier,
Module = inputs.Module,
PermissionKey = inputs.PermissionKey,
Tablename = tableName
Tablename = string.IsNullOrEmpty(inputs.Schema) ? inputs.Table : (inputs.Schema + "." + inputs.Table)
};

confConnection.Tables.Add(confTable);
Expand Down
33 changes: 14 additions & 19 deletions src/Serenity.Net.CodeGenerator/Commands/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class GenerateCommand : BaseFileSystemCommand
{
private readonly IAnsiConsole ansiConsole;

public GenerateCommand(IGeneratorFileSystem fileSystem, IAnsiConsole ansiConsole)
public GenerateCommand(IGeneratorFileSystem fileSystem, IAnsiConsole ansiConsole)
: base(fileSystem)
{
this.ansiConsole = ansiConsole ?? throw new ArgumentNullException(nameof(ansiConsole));
Expand Down Expand Up @@ -76,7 +76,7 @@ public ExitCodes Run(string csproj, string[] args)

string module = null;
var permissionKey = argsPermissionKey ?? "Administration:General";
var generateData = new Dictionary<string, (string module, string identifier, string permissionKey, TableName table)>();
var inputsList = new List<EntityModelInputs>();

foreach (var tableName in selectedTableNames)
{
Expand Down Expand Up @@ -107,7 +107,16 @@ public ExitCodes Run(string csproj, string[] args)

permissionKey = argsPermissionKey ?? SelectPermissionKey(tableName, confTable?.PermissionKey?.TrimToNull() ?? permissionKey);

generateData.Add(tableName, (module, identifier, permissionKey, tableEntry));
inputsList.Add(new()
{
ConnectionKey = connectionKey,
Config = config,
Schema = tableEntry.Schema,
Table = tableEntry.Tablename,
Module = module,
Identifier = identifier,
PermissionKey = permissionKey
});
}

if (what != null)
Expand All @@ -126,23 +135,9 @@ public ExitCodes Run(string csproj, string[] args)
config.GenerateCustom = whatToGenerate.Contains("Custom");
}

foreach (var data in generateData)
foreach (var inputs in inputsList)
{
var confTable = confConnection?.Tables.FirstOrDefault(x => string.Compare(x.Tablename, data.Key,
StringComparison.OrdinalIgnoreCase) == 0);

var inputs = new EntityModelInputs
{
Config = config,
ConnectionKey = connectionKey,
Identifier = data.Value.identifier,
Module = data.Value.module,
PermissionKey = data.Value.permissionKey,
Table = data.Value.table.Table,
Schema = data.Value.table.Schema
};

UpdateConfigTable(inputs, data.Value.table.Tablename, confConnection, confTable);
UpdateConfigTableFor(inputs, confConnection);

var generator = CreateCodeGenerator(inputs, new EntityModelGenerator(),
csproj, fileSystem, sqlConnections, interactive: argsIdentifier is null);
Expand Down

0 comments on commit f7c27ec

Please sign in to comment.