Skip to content

Commit 8b49658

Browse files
committed
add support for CultureInfo config.
1 parent d47a2a1 commit 8b49658

File tree

4 files changed

+220
-12
lines changed

4 files changed

+220
-12
lines changed

src/SmartCode.CLI/SmartCodeCommand.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,38 @@ public class SmartCodeCommand
2323
[Argument(0, Description = "Config Path")]
2424
[FileExists]
2525
public String ConfigPath { get; set; }
26+
27+
[Option("-ci|--culture-info", Description = "CultureInfo")]
28+
public String CultureInfo { get; set; }
2629

2730
private async Task OnExecute()
2831
{
32+
if (!String.IsNullOrEmpty(CultureInfo))
33+
{
34+
System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo(CultureInfo);
35+
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
36+
}
37+
2938
if (String.IsNullOrEmpty(ConfigPath))
3039
{
31-
var useDefaultConfig = Prompt.GetYesNo($"If you do not enter ConfigPath, you will use the default configuration:{DEFAULT_CONFIG_PATH}", true);
32-
ConfigPath = useDefaultConfig ? DEFAULT_CONFIG_PATH
40+
var useDefaultConfig =
41+
Prompt.GetYesNo(
42+
$"If you do not enter ConfigPath, you will use the default configuration:{DEFAULT_CONFIG_PATH}",
43+
true);
44+
ConfigPath = useDefaultConfig
45+
? DEFAULT_CONFIG_PATH
3346
: Prompt.GetString("Please enter the path to build configuration file:");
3447
}
3548

3649
SmartCodeApp app = new DefaultSmartCodeAppBuilder().Build(ConfigPath);
3750
await app.Run();
3851
}
52+
3953
private static string GetVersion()
40-
=> typeof(SmartCodeCommand).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
41-
[Command(name: "pull",Description = "Pull Git Template.")]
54+
=> typeof(SmartCodeCommand).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
55+
.InformationalVersion;
56+
57+
[Command(name: "pull", Description = "Pull Git Template.")]
4258
public class MarketCommand
4359
{
4460
private readonly IConsole _console;
@@ -48,18 +64,16 @@ public MarketCommand(IConsole console)
4864
_console = console;
4965
}
5066

51-
[Option(Description = "Source Path")]
52-
public String Source { get; set; }
53-
[Option(Description = "Target Path")]
54-
public String Target { get; set; }
67+
[Option(Description = "Source Path")] public String Source { get; set; }
68+
[Option(Description = "Target Path")] public String Target { get; set; }
5569

5670
private string ParseGitArgs()
5771
{
5872
var toPath = Path.Combine(AppContext.BaseDirectory, "RazorTemplates", Target);
5973
return $"clone --progress -v \"{Source}\" \"{toPath}\"";
6074
}
6175

62-
private void OnExecute(IConsole console)
76+
private void OnExecute(IConsole console)
6377
{
6478
var startInfo = new ProcessStartInfo("git")
6579
{
@@ -74,8 +88,10 @@ private void OnExecute(IConsole console)
7488

7589
using (var process = Process.Start(startInfo))
7690
{
77-
process.OutputDataReceived += Process_OutputDataReceived; ;
78-
process.ErrorDataReceived += Process_ErrorDataReceived; ;
91+
process.OutputDataReceived += Process_OutputDataReceived;
92+
;
93+
process.ErrorDataReceived += Process_ErrorDataReceived;
94+
;
7995
process.BeginOutputReadLine();
8096
process.BeginErrorReadLine();
8197
process.WaitForExit();
@@ -95,4 +111,4 @@ private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
95111
}
96112
}
97113
}
98-
}
114+
}

src/SmartCode.Generator/DbTypeConverter/DbTypeMap.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,39 @@
361361
<DbType Name="geography" To="geography"/>
362362
</Database>
363363

364+
<Database DbProvider="SqlServer" Language="MySql">
365+
<DbType Name="text" To="text"/>
366+
<DbType Name="varchar" To="varchar"/>
367+
<DbType Name="nvarchar" To="varchar"/>
368+
<DbType Name="uniqueidentifier" To="char(36)"/>
369+
<DbType Name="date" To="datetime"/>
370+
<DbType Name="smalldatetime" To="datetime"/>
371+
<DbType Name="datetime" To="datetime"/>
372+
<DbType Name="datetime2" To="datetime"/>
373+
<DbType Name="time" To="datetime"/>
374+
<DbType Name="datetimeoffset" To="datetime"/>
375+
<DbType Name="tinyint" To="int"/>
376+
<DbType Name="smallint" To="int"/>
377+
<DbType Name="int" To="int"/>
378+
<DbType Name="bigint" To="bigint"/>
379+
<DbType Name="bit" To="bool"/>
380+
<DbType Name="char" To="char"/>
381+
<DbType Name="uniqueide" To="char(36)"/>
382+
<DbType Name="numeric" To="int"/>
383+
<DbType Name="integer" To="int"/>
384+
<DbType Name="money" To="decimal(10,2)"/>
385+
<DbType Name="real" To="decimal(10,2)"/>
386+
<DbType Name="single" To="int"/>
387+
<DbType Name="smallmoney" To="decimal(10,2)"/>
388+
<DbType Name="decimal" To="decimal(10,2)"/>
389+
<DbType Name="float" To="float"/>
390+
<DbType Name="number" To="decimal(10,2)"/>
391+
<DbType Name="boolean" To="bool"/>
392+
<DbType Name="long" To="bigint"/>
393+
<DbType Name="longtext" To="text"/>
394+
<DbType Name="timestamp" To="datetime"/>
395+
</Database>
396+
364397
<Database DbProvider="MySql" Language="PostgreSql">
365398
<DbType Name="text" To="text"/>
366399
<DbType Name="varchar" To="varchar"/>
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
@using SmartCode
2+
@using SmartCode.Db
3+
@model BuildContext
4+
@{
5+
var project = Model.Project;
6+
var dbSource = Model.GetDataSource<DbSource>();
7+
var buildTask = Model.Build;
8+
project.Parameters.Value("ExtractMode", out string extractMode);//Last: Full,LastMaxModifyTime,LastQueryTime,LastMaxId
9+
bool extractModeUseTime = extractMode == "LastMaxModifyTime" || extractMode == "LastQueryTime";
10+
project.Parameters.Value("ExtractConnectionString", out string extractConnectionString);
11+
extractConnectionString = extractConnectionString ?? dbSource.Database.Write.ConnectionString;
12+
project.Parameters.Value("LoadDbProvider", out string loadDbProvider);
13+
project.Parameters.Value("LoadConnectionString", out string loadConnectionString);
14+
project.Parameters.Value("SecureFilePriv", out string secureFilePriv);
15+
Model.Project.Parameters.Value("ModifyTime", out string modifyTime);
16+
var table = Model.GetCurrentTable();
17+
var loadTable = extractModeUseTime ? $"{table.ConvertedName}__temp" : table.ConvertedName;
18+
var PKColumn = Model.GetCurrentTable().PKColumn;
19+
}
20+
21+
@functions{
22+
string GetExtractWhere()
23+
{
24+
string sql = String.Empty;
25+
Model.Project.Parameters.Value("ExtractMode", out string extractMode);
26+
switch (extractMode)
27+
{
28+
case "Full": { return ""; }
29+
case "LastMaxModifyTime":
30+
{
31+
Model.Project.Parameters.Value("ModifyTime", out string modifyTime);
32+
sql = $"{modifyTime}>@LastMaxModifyTime";
33+
break;
34+
}
35+
case "LastQueryTime":
36+
{
37+
Model.Project.Parameters.Value("ModifyTime", out string modifyTime);
38+
sql = $"{modifyTime}>@LastQueryTime";
39+
break;
40+
}
41+
case "LastMaxId":
42+
default:
43+
{
44+
sql = $"{Model.GetCurrentTable().PKColumn.Name}>@LastMaxId";
45+
break;
46+
}
47+
}
48+
return $"Where {sql}";
49+
}
50+
}
51+
52+
Author: Rocher Kong
53+
DataSource:
54+
Name: Extract
55+
Parameters:
56+
DbProvider: @dbSource.DbRepository.DbProviderName
57+
ConnectionString: @extractConnectionString
58+
Query: 'Select * From @table.Name @GetExtractWhere()'
59+
PKColumn: @PKColumn.Name
60+
AutoIncrement: @(PKColumn.AutoIncrement ? "true" : "false")
61+
@if (!String.IsNullOrEmpty(modifyTime))
62+
{
63+
<text>@Html.PadLeft(4)ModifyTime: @modifyTime</text>
64+
}
65+
66+
67+
Parameters:
68+
ETLCode: @(project.Module).@table.Name
69+
ETLRepository: MySql
70+
71+
Build:
72+
Transform:
73+
Type: Transform
74+
Parameters:
75+
Script:
76+
77+
Load:
78+
Type: Load
79+
Parameters:
80+
DbProvider: @loadDbProvider
81+
SecureFilePriv: @secureFilePriv
82+
ConnectionString: @loadConnectionString
83+
Table: @loadTable
84+
@switch (extractMode)
85+
{
86+
case "LastMaxModifyTime":
87+
case "LastQueryTime":
88+
{
89+
<text>
90+
PreCommand: create TEMPORARY table @(loadTable) select * from @table.ConvertedName where 1=0;
91+
PostCommand: "delete from @table.ConvertedName where EXISTS(select * from @(loadTable) as temp where temp.@(PKColumn.ConvertedName)=t_payment.@(PKColumn.ConvertedName));
92+
insert into @table.ConvertedName select * from @loadTable;"
93+
</text>
94+
break;
95+
}
96+
case "Full":
97+
{
98+
<text>
99+
PreCommand: TRUNCATE TABLE @(loadTable);
100+
</text>
101+
break;
102+
}
103+
}
104+
105+
ColumnMapping: [
106+
@for (var colIndex = 0; colIndex < table.Columns.Count(); colIndex++)
107+
{
108+
var col = table.Columns.ElementAt(colIndex);
109+
<text>{Column: @col.Name,Mapping: @col.ConvertedName}</text>
110+
if (colIndex < table.Columns.Count() - 1)
111+
{@(",")}
112+
@Html.NewLine()
113+
}
114+
]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@using SmartCode
2+
@model BuildContext
3+
@{
4+
var all_table = Model.GetCurrentAllTable();
5+
}
6+
@functions {
7+
String GetPGSqlType(SmartCode.Generator.Entity.Column col)
8+
{
9+
var sqlDbType = col.LanguageType;
10+
if (string.IsNullOrEmpty(sqlDbType)) {
11+
return "NAType";
12+
}
13+
if (sqlDbType.StartsWith("varchar"))
14+
{
15+
if (col.DataLength == -1) {
16+
return "text";
17+
}
18+
return $"varchar({col.DataLength})";
19+
}
20+
return sqlDbType;
21+
}
22+
}
23+
24+
@foreach (var table in all_table)
25+
{
26+
<text>
27+
/*==============================================================*/
28+
/* Table: @table.ConvertedName */
29+
/*==============================================================*/
30+
create table @table.ConvertedName (
31+
32+
@for (var colIndex = 0; colIndex < table.Columns.Count(); colIndex++)
33+
{
34+
var col = table.Columns.ElementAt(colIndex);
35+
@col.ConvertedName @Html.PadLeft(4) @GetPGSqlType(col) @Html.PadLeft(4) @(col.IsNullable ? "null" : "not null") @(col.IsPrimaryKey?" primary key":"") @if (!String.IsNullOrEmpty(col.Description))
36+
{
37+
<text> comment '@col.Description';</text>
38+
} if (colIndex < table.Columns.Count() - 1)
39+
{@(",")}
40+
@Html.NewLine()
41+
}
42+
);
43+
44+
</text>
45+
}

0 commit comments

Comments
 (0)