Skip to content

Commit 4fa7e84

Browse files
committed
修复使用RazorEngineCore模板引擎生成报错问题。修改模板。
1 parent 93039be commit 4fa7e84

51 files changed

Lines changed: 624 additions & 445 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README-EN.md‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Output:
5858
Type: File
5959
Path: 'E:\SmartSql-Starter'
6060
Parameters:
61-
SmartSqlVersion: '4.0.46'
62-
SmartSqlSchemaVersion: '4.0.42'
61+
SmartSqlVersion: '4.1.64'
62+
SmartSqlSchemaVersion: '4.1.30'
6363
BuildDir: 'E:\SmartSql-Starter\build'
6464
DockerImage: 'smartsql.starter'
6565

@@ -127,7 +127,7 @@ Build:
127127
{Key: "API/AppSettings.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'appsettings',Extension: '.json'}},
128128
{Key: "API/AppSettings-Development.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'appsettings.Development',Extension: '.json'}},
129129
{Key: "API/Program.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Program',Extension: '.cs'}},
130-
{Key: "API/Startup.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Startup',Extension: '.cs'}},
130+
# {Key: "API/Startup.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Startup',Extension: '.cs'}},
131131
{Key: "API/APIException.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Exceptions',Name: 'APIException',Extension: '.cs'}},
132132
{Key: "API/GlobalExceptionFilter.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Filters',Name: 'GlobalExceptionFilter',Extension: '.cs'}},
133133
{Key: "API/GlobalValidateModelFilter.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Filters',Name: 'GlobalValidateModelFilter',Extension: '.cs'}},
@@ -197,6 +197,34 @@ Build:
197197
IgnoreNoPKTable: true
198198
IgnoreView: true
199199

200+
AddEntityProj:
201+
Type: Process
202+
Parameters:
203+
FileName: powershell
204+
WorkingDirectory: '{{Project.Output.Path}}'
205+
Args: dotnet sln add -s API src/{{Project.Module}}.Entity/{{Project.Module}}.Entity.csproj
206+
207+
AddRepositryProj:
208+
Type: Process
209+
Parameters:
210+
FileName: powershell
211+
WorkingDirectory: '{{Project.Output.Path}}'
212+
Args: dotnet sln add -s API src/{{Project.Module}}.Repository/{{Project.Module}}.Repository.csproj
213+
214+
AddServiceProj:
215+
Type: Process
216+
Parameters:
217+
FileName: powershell
218+
WorkingDirectory: '{{Project.Output.Path}}'
219+
Args: dotnet sln add -s API src/{{Project.Module}}.Service/{{Project.Module}}.Service.csproj
220+
221+
AddApiProj:
222+
Type: Process
223+
Parameters:
224+
FileName: powershell
225+
WorkingDirectory: '{{Project.Output.Path}}'
226+
Args: dotnet sln add -s API src/{{Project.Module}}.API/{{Project.Module}}.API.csproj
227+
200228
# Please install dotnet-format first!
201229
# dotnet tool install -g dotnet-format
202230
CodeFormat:

‎README.md‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Output:
5858
Type: File
5959
Path: 'E:\SmartSql-Starter'
6060
Parameters:
61-
SmartSqlVersion: '4.0.46'
62-
SmartSqlSchemaVersion: '4.0.42'
61+
SmartSqlVersion: '4.1.64'
62+
SmartSqlSchemaVersion: '4.1.30'
6363
BuildDir: 'E:\SmartSql-Starter\build'
6464
DockerImage: 'smartsql.starter'
6565

@@ -127,7 +127,7 @@ Build:
127127
{Key: "API/AppSettings.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'appsettings',Extension: '.json'}},
128128
{Key: "API/AppSettings-Development.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'appsettings.Development',Extension: '.json'}},
129129
{Key: "API/Program.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Program',Extension: '.cs'}},
130-
{Key: "API/Startup.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Startup',Extension: '.cs'}},
130+
# {Key: "API/Startup.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Startup',Extension: '.cs'}},
131131
{Key: "API/APIException.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Exceptions',Name: 'APIException',Extension: '.cs'}},
132132
{Key: "API/GlobalExceptionFilter.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Filters',Name: 'GlobalExceptionFilter',Extension: '.cs'}},
133133
{Key: "API/GlobalValidateModelFilter.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Filters',Name: 'GlobalValidateModelFilter',Extension: '.cs'}},
@@ -197,6 +197,34 @@ Build:
197197
IgnoreNoPKTable: true
198198
IgnoreView: true
199199

200+
AddEntityProj:
201+
Type: Process
202+
Parameters:
203+
FileName: powershell
204+
WorkingDirectory: '{{Project.Output.Path}}'
205+
Args: dotnet sln add -s API src/{{Project.Module}}.Entity/{{Project.Module}}.Entity.csproj
206+
207+
AddRepositryProj:
208+
Type: Process
209+
Parameters:
210+
FileName: powershell
211+
WorkingDirectory: '{{Project.Output.Path}}'
212+
Args: dotnet sln add -s API src/{{Project.Module}}.Repository/{{Project.Module}}.Repository.csproj
213+
214+
AddServiceProj:
215+
Type: Process
216+
Parameters:
217+
FileName: powershell
218+
WorkingDirectory: '{{Project.Output.Path}}'
219+
Args: dotnet sln add -s API src/{{Project.Module}}.Service/{{Project.Module}}.Service.csproj
220+
221+
AddApiProj:
222+
Type: Process
223+
Parameters:
224+
FileName: powershell
225+
WorkingDirectory: '{{Project.Output.Path}}'
226+
Args: dotnet sln add -s API src/{{Project.Module}}.API/{{Project.Module}}.API.csproj
227+
200228
# Please install dotnet-format first!
201229
# dotnet tool install -g dotnet-format
202230
CodeFormat:

‎doc/SmartCode.yml‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Output:
1414
Type: File
1515
Path: 'D:\SmartSql-Starter'
1616
Parameters:
17-
SmartSqlVersion: '4.1.42'
17+
SmartSqlVersion: '4.1.64'
1818
SmartSqlSchemaVersion: '4.1.30'
1919
BuildDir: 'D:\SmartSql-Starter\build'
2020
DockerImage: 'smartsql.starter'
@@ -87,7 +87,7 @@ Build:
8787
{Key: "API/AppSettings.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'appsettings',Extension: '.json'}},
8888
{Key: "API/AppSettings-Development.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'appsettings.Development',Extension: '.json'}},
8989
{Key: "API/Program.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Program',Extension: '.cs'}},
90-
{Key: "API/Startup.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Startup',Extension: '.cs'}},
90+
# {Key: "API/Startup.cshtml",Output: {Path: 'src/{{Project.Module}}.API',Name: 'Startup',Extension: '.cs'}},
9191
{Key: "API/APIException.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Exceptions',Name: 'APIException',Extension: '.cs'}},
9292
{Key: "API/GlobalExceptionFilter.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Filters',Name: 'GlobalExceptionFilter',Extension: '.cs'}},
9393
{Key: "API/GlobalValidateModelFilter.cshtml",Output: {Path: 'src/{{Project.Module}}.API/Filters',Name: 'GlobalValidateModelFilter',Extension: '.cs'}},
@@ -151,6 +151,34 @@ Build:
151151
Name: '{{Items.CurrentTable.ConvertedName}}'
152152
Extension: .xml
153153

154+
AddEntityProj:
155+
Type: Process
156+
Parameters:
157+
FileName: powershell
158+
WorkingDirectory: '{{Project.Output.Path}}'
159+
Args: dotnet sln add -s API src/{{Project.Module}}.Entity/{{Project.Module}}.Entity.csproj
160+
161+
AddRepositryProj:
162+
Type: Process
163+
Parameters:
164+
FileName: powershell
165+
WorkingDirectory: '{{Project.Output.Path}}'
166+
Args: dotnet sln add -s API src/{{Project.Module}}.Repository/{{Project.Module}}.Repository.csproj
167+
168+
AddServiceProj:
169+
Type: Process
170+
Parameters:
171+
FileName: powershell
172+
WorkingDirectory: '{{Project.Output.Path}}'
173+
Args: dotnet sln add -s API src/{{Project.Module}}.Service/{{Project.Module}}.Service.csproj
174+
175+
AddApiProj:
176+
Type: Process
177+
Parameters:
178+
FileName: powershell
179+
WorkingDirectory: '{{Project.Output.Path}}'
180+
Args: dotnet sln add -s API src/{{Project.Module}}.API/{{Project.Module}}.API.csproj
181+
154182
# Please install dotnet-format first!
155183
# dotnet tool install -g dotnet-format
156184
CodeFormat:

‎src/SmartCode.Generator/RazorTemplates/CSharp/API/APIController.cshtml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
@using SmartCode
22
@using SmartCode.Generator.Extensions
3-
@model BuildContext
3+
@inherits SmartCode.TemplateEngine.Impl.RazorCoreTemplate<BuildContext>
44
@{
5-
Layout = "../_CSharpLayout.cshtml";
65
var project = Model.Project;
76
var table = Model.GetCurrentTable();
87
var pkType = table.PKColumn.LanguageType;
@@ -14,6 +13,7 @@
1413
var repositoryName = $"{table.ConvertedName}Repository";
1514
var repositoryCamelName = NamingUtil.CamelCase(repositoryName);
1615
}
16+
@Include("../Copyright.cshtml", Model)
1717

1818
using System;
1919
using System.Collections;

‎src/SmartCode.Generator/RazorTemplates/CSharp/API/APIException.cshtml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@using SmartCode
2-
@model BuildContext
2+
@inherits SmartCode.TemplateEngine.Impl.RazorCoreTemplate<BuildContext>
33
@{
4-
Layout = "../_CSharpLayout.cshtml";
54
var project = Model.Project;
65
}
6+
@Include("../Copyright.cshtml", Model)
77

88
using System;
99
using System.Collections.Generic;

‎src/SmartCode.Generator/RazorTemplates/CSharp/API/AppSettings-Development.cshtml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@using SmartCode
2-
@model BuildContext
2+
@inherits SmartCode.TemplateEngine.Impl.RazorCoreTemplate<BuildContext>
33
@{
44

55
var project = Model.Project;

‎src/SmartCode.Generator/RazorTemplates/CSharp/API/AppSettings.cshtml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@using SmartCode
2-
@model BuildContext
2+
@inherits SmartCode.TemplateEngine.Impl.RazorCoreTemplate<BuildContext>
33
@{
44

55
var project = Model.Project;
Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,45 @@
11
@using SmartCode
2-
@model BuildContext
2+
@inherits SmartCode.TemplateEngine.Impl.RazorCoreTemplate<BuildContext>
33
@{
4-
Layout = "../_CSharpLayout.cshtml";
54
var project = Model.Project;
65
}
6+
@Include("../Copyright.cshtml", Model)
77

8-
using Microsoft.AspNetCore.Hosting;
9-
using Microsoft.AspNetCore.Mvc;
10-
using Microsoft.AspNetCore.Mvc.Filters;
11-
using Microsoft.Extensions.Logging;
8+
using System.Net;
129
using @(project.Module).API.Exceptions;
1310
using @(project.Module).API.Messages;
14-
using System.Net;
11+
using Microsoft.AspNetCore.Mvc;
12+
using Microsoft.AspNetCore.Mvc.Filters;
1513

1614
namespace @(project.Module).API.Filters
1715
{
1816
public class GlobalExceptionFilter : IExceptionFilter
1917
{
20-
private readonly IHostingEnvironment env;
2118
private readonly ILogger@("<GlobalExceptionFilter>") logger;
2219

23-
public GlobalExceptionFilter(IHostingEnvironment env, ILogger@("<GlobalExceptionFilter>") logger)
20+
public GlobalExceptionFilter(ILogger@("<GlobalExceptionFilter>") logger)
2421
{
25-
this.env = env;
26-
this.logger = logger;
22+
this.logger = logger;
2723
}
2824

2925
public void OnException(ExceptionContext context)
3026
{
31-
context.ExceptionHandled = true;
32-
var exception = context.Exception;
33-
logger.LogError(
34-
new EventId(exception.HResult),
35-
exception,
36-
exception.Message);
37-
string errorCode = "0001";
38-
if (exception is APIException) { errorCode = (exception as APIException).ErrorCode; }
39-
var errorResp = new ResponseMessage
40-
{
41-
Message = exception.Message,
42-
ErrorCode = errorCode,
43-
IsSuccess = false
44-
};
45-
var result = new JsonResult(errorResp)
46-
{
47-
StatusCode = (int)HttpStatusCode.OK
48-
};
49-
context.Result = result;
50-
51-
}
27+
context.ExceptionHandled = true;
28+
var exception = context.Exception;
29+
logger.LogError(new EventId(exception.HResult), exception, exception.Message);
30+
string errorCode = "0001";
31+
if (exception is APIException apiException) { errorCode = apiException.ErrorCode; }
32+
var errorResp = new ResponseMessage
33+
{
34+
Message = exception.Message,
35+
ErrorCode = errorCode,
36+
IsSuccess = false
37+
};
38+
var result = new JsonResult(errorResp)
39+
{
40+
StatusCode = (int)HttpStatusCode.OK
41+
};
42+
context.Result = result;
5243
}
53-
}
54-
55-
56-
57-
58-
44+
}
45+
}
Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
11
@using SmartCode
2-
@model BuildContext
2+
@inherits SmartCode.TemplateEngine.Impl.RazorCoreTemplate<BuildContext>
33
@{
4-
Layout = "../_CSharpLayout.cshtml";
54
var project = Model.Project;
65
}
6+
@Include("../Copyright.cshtml", Model)
77

8-
using Microsoft.AspNetCore.Hosting;
8+
using System.Text;
9+
using @(project.Module).API.Messages;
910
using Microsoft.AspNetCore.Mvc;
1011
using Microsoft.AspNetCore.Mvc.Filters;
11-
using Microsoft.Extensions.Logging;
1212
using Newtonsoft.Json;
13-
using @(project.Module).API.Messages;
14-
using System.Linq;
15-
using System.Text;
1613

1714
namespace @(project.Module).API.Filters
1815
{
1916
public class GlobalValidateModelFilter : IActionFilter
2017
{
21-
private readonly IHostingEnvironment _env;
2218
private readonly ILogger@("<GlobalValidateModelFilter>") _logger;
2319

24-
public GlobalValidateModelFilter(IHostingEnvironment env, ILogger@("<GlobalValidateModelFilter>") logger)
20+
public GlobalValidateModelFilter(ILogger@("<GlobalValidateModelFilter>") logger)
2521
{
26-
_env = env;
27-
_logger = logger;
22+
_logger = logger;
2823
}
2924
public void OnActionExecuted(ActionExecutedContext context)
3025
{
3126

3227
}
33-
28+
3429
public void OnActionExecuting(ActionExecutingContext context)
3530
{
36-
if (!context.ModelState.IsValid)
37-
{
38-
_logger.LogDebug("ModelState not valid:{0}", JsonConvert.SerializeObject(context.ModelState));
39-
StringBuilder errStr = new StringBuilder();
40-
41-
foreach (var error in context.ModelState.Values)
42-
{
43-
string errorMsg = error.Errors?.FirstOrDefault()?.ErrorMessage;
44-
errStr.AppendFormat("{0} |", errorMsg);
45-
}
46-
47-
var resp = new ResponseMessage
48-
{
49-
ErrorCode = "0006",
50-
Message = errStr.ToString().TrimEnd('|'),
51-
IsSuccess = false
52-
};
53-
54-
var result = new JsonResult(resp);
55-
context.Result = result;
56-
}
57-
}
58-
}
31+
if (!context.ModelState.IsValid)
32+
{
33+
_logger.LogDebug("ModelState not valid:{0}", JsonConvert.SerializeObject(context.ModelState));
34+
StringBuilder errStr = new StringBuilder();
35+
36+
foreach (var error in context.ModelState.Values)
37+
{
38+
string? errorMsg = error.Errors.FirstOrDefault()?.ErrorMessage;
39+
errStr.AppendFormat("{0} |", errorMsg);
40+
}
41+
42+
var resp = new ResponseMessage
43+
{
44+
ErrorCode = "0006",
45+
Message = errStr.ToString().TrimEnd('|'),
46+
IsSuccess = false
47+
};
48+
49+
var result = new JsonResult(resp);
50+
context.Result = result;
51+
}
5952
}
53+
}
54+
}

‎src/SmartCode.Generator/RazorTemplates/CSharp/API/LaunchSettings.cshtml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@using SmartCode
2-
@model BuildContext
2+
@inherits SmartCode.TemplateEngine.Impl.RazorCoreTemplate<BuildContext>
33
@{
44

55
var project = Model.Project;

0 commit comments

Comments
 (0)