Skip to content

Commit 74d2951

Browse files
committed
1. fix Entity template bug
2. Optimize log output
1 parent 137acad commit 74d2951

File tree

6 files changed

+50
-23
lines changed

6 files changed

+50
-23
lines changed

doc/SmartCode.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Output:
1414

1515
# 构建任务
1616
Build:
17+
1718
ClearDir:
1819
Type: Clear
1920
Paramters:

src/SmartCode.App/BuildTasks/ProcessBuildTask.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ namespace SmartCode.App.BuildTasks
99
{
1010
public class ProcessBuildTask : IBuildTask
1111
{
12+
const string CREATE_NO_WINDOW = "CreateNoWindow";
1213
const string WORKING_DIRECTORY = "WorkingDirectory";
1314
const string FILE_NAME = "FileName";
1415
const string ARGS = "Args";
1516
const string TIMEOUT = "Timeout";
1617
private readonly ILogger<ProcessBuildTask> _logger;
1718
const int DEFAULT_TIME_OUT = 30 * 1000;
19+
const bool DEFAULT_CREATE_NO_WINDOW = true;
1820
public bool Initialized => true;
1921

2022
public string Name => "Process";
@@ -35,27 +37,34 @@ public Task Build(BuildContext context)
3537
}
3638
var process = new Process();
3739
var startInfo = process.StartInfo;
38-
//startInfo.CreateNoWindow = true;
39-
var timeOut = DEFAULT_TIME_OUT;
40-
if (context.Build.Paramters.TryGetValue(TIMEOUT, out object timeoutObj))
41-
{
42-
if (int.TryParse(timeoutObj.ToString(), out int _timeout))
43-
{
44-
timeOut = _timeout;
45-
}
46-
}
40+
startInfo.CreateNoWindow = DEFAULT_CREATE_NO_WINDOW;
4741
startInfo.FileName = fileNameObj.ToString();
4842
startInfo.Arguments = argsObj.ToString();
4943
if (context.Build.Paramters.TryGetValue(WORKING_DIRECTORY, out object workingDicObj))
5044
{
5145
startInfo.WorkingDirectory = workingDicObj.ToString();
5246
}
47+
if (context.Build.Paramters.TryGetValue(CREATE_NO_WINDOW, out object createNoWinObj))
48+
{
49+
if (bool.TryParse(createNoWinObj.ToString(), out bool createNoWin))
50+
{
51+
startInfo.CreateNoWindow = createNoWin;
52+
}
53+
}
5354
_logger.LogDebug($"--------Process.FileName:{startInfo.FileName},Args:{startInfo.Arguments} Start--------");
5455
process.ErrorDataReceived += Process_ErrorDataReceived;
5556
process.OutputDataReceived += Process_OutputDataReceived;
5657
try
5758
{
5859
process.Start();
60+
var timeOut = DEFAULT_TIME_OUT;
61+
if (context.Build.Paramters.TryGetValue(TIMEOUT, out object timeoutObj))
62+
{
63+
if (int.TryParse(timeoutObj.ToString(), out int _timeout))
64+
{
65+
timeOut = _timeout;
66+
}
67+
}
5968
process.WaitForExit(timeOut);
6069
_logger.LogDebug($"--------Process.FileName:{startInfo.FileName},Args:{startInfo.Arguments} End--------");
6170
}

src/SmartCode.App/SmartCodeApp.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private void RegisterServices()
5858
Services.AddSingleton<IPluginManager, PluginManager>();
5959
Services.AddSingleton<IProjectBuilder, ProjectBuilder>();
6060
ServiceProvider = Services.BuildServiceProvider();
61+
Logger = ServiceProvider.GetRequiredService<ILogger<SmartCodeApp>>();
6162
}
6263

6364
private void RegisterPlugins()
@@ -84,12 +85,18 @@ private void RegisterPlugins()
8485

8586
public async Task Run()
8687
{
87-
Handlebars.Configuration.TextEncoder = NullTextEncoder.Instance;
88-
var logger = ServiceProvider.GetRequiredService<ILogger<SmartCodeApp>>();
89-
var projectBuilder = ServiceProvider.GetRequiredService<IProjectBuilder>();
90-
logger.LogInformation($"------- Build ConfigPath:{ConfigPath} Start! --------");
91-
await projectBuilder.Build();
92-
logger.LogInformation($"-------- Build ConfigPath:{ConfigPath},Output:{Project.OutputPath} End! --------");
88+
try
89+
{
90+
Handlebars.Configuration.TextEncoder = NullTextEncoder.Instance;
91+
var projectBuilder = ServiceProvider.GetRequiredService<IProjectBuilder>();
92+
Logger.LogInformation($"------- Build ConfigPath:{ConfigPath} Start! --------");
93+
await projectBuilder.Build();
94+
Logger.LogInformation($"-------- Build ConfigPath:{ConfigPath},Output:{Project.OutputPath} End! --------");
95+
}
96+
catch (SmartCodeException scEx)
97+
{
98+
Logger.LogError(new EventId(scEx.HResult), scEx, scEx.Message);
99+
}
93100
}
94101

95102
public class NullTextEncoder : ITextEncoder

src/SmartCode.CLI/Program.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,22 @@ static async Task Main(string[] args)
3939
configPath = DEFAULT_CONFIG_PATH;
4040
}
4141
}
42-
SmartCodeApp app = new DefaultSmartCodeAppBuilder().Build(configPath);
43-
await app.Run();
44-
Thread.Sleep(200);//Wait for Logger
45-
Console.ForegroundColor = ConsoleColor.Green;
46-
Console.WriteLine($"------------ SmartCode Build End! Output:[{app.Project.OutputPath}] --------------");
47-
Console.ResetColor();
42+
try
43+
{
44+
SmartCodeApp app = new DefaultSmartCodeAppBuilder().Build(configPath);
45+
await app.Run();
46+
Thread.Sleep(200);//Wait for Logger
47+
Console.ForegroundColor = ConsoleColor.Green;
48+
Console.WriteLine($"------------ SmartCode Build End! Output:[{app.Project.OutputPath}] --------------");
49+
}
50+
catch (Exception ex)
51+
{
52+
throw ex;
53+
}
54+
finally
55+
{
56+
Console.ResetColor();
57+
}
4858
}
4959
}
5060
}

src/SmartCode.CLI/RazorTemplates/Entity.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace @(project.Module)[email protected]
4545
@Html.PadLeft(8)@Html.NewLine()
4646
@Html.PadLeft(8)@("///</summary>")
4747
@Html.PadLeft(8)@Html.NewLine()
48-
@Html.PadLeft(8)<text>public</text> <text>@column.LanguageType</text><text>@(ConvertLangType(column))</text> <text>@column.ConvertedName</text> <text>{ get; set; }</text>
48+
@Html.PadLeft(8)<text>public</text> <text>@(ConvertLangType(column))</text> <text>@column.ConvertedName</text> <text>{ get; set; }</text>
4949
@Html.PadLeft(8)@Html.NewLine()
5050
}
5151
}

src/SmartCode.CLI/SmartCode.CLI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<RepositoryType>Github</RepositoryType>
2121
<PackageTags>SmartCode SmartSql</PackageTags>
2222
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
23-
<Version>1.7.8</Version>
23+
<Version>1.8.0</Version>
2424
<PackageIconUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartCode/master/doc/Logo.png</PackageIconUrl>
2525
<PackageReleaseNotes>u SmartSql.DIExtension version</PackageReleaseNotes>
2626
</PropertyGroup>

0 commit comments

Comments
 (0)