Skip to content

Commit c504afd

Browse files
committed
v0.4
1 parent f3acb78 commit c504afd

File tree

11 files changed

+262
-103
lines changed

11 files changed

+262
-103
lines changed

Daikoz.SQLWrapper/Daikoz.SQLWrapper.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<LangVersion>latest</LangVersion>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
8-
<Version>0.2</Version>
8+
<Version>0.4</Version>
99
<Authors>DAIKOZ</Authors>
1010
<Company>DAIKOZ</Company>
1111
<Copyright>© 2019 - DAIKOZ - All rights reserved</Copyright>
@@ -22,8 +22,8 @@ SQL Wrapper is not a ORM: it generate code form SQL request. It have better perf
2222
SQL Wrapper get database structure to check SQL syntax and generate a XML with all returned columns of SQL request. From this XML, you can apply our XLST (or the XLST provided) to generate the code.
2323

2424
Thus, SQL Wrapper can generate SQL call code from any language like C#, Java, Python, Javascript, VB .NET, ADO .NET ...</Description>
25-
<AssemblyVersion>0.2.0.0</AssemblyVersion>
26-
<FileVersion>0.2.0.0</FileVersion>
25+
<AssemblyVersion>0.4.0</AssemblyVersion>
26+
<FileVersion>0.4.0</FileVersion>
2727
<PackageLicenseUrl></PackageLicenseUrl>
2828
<PackageLicenseExpression></PackageLicenseExpression>
2929
<PackageIconUrl>https://www.daikoz.com/img/sqlwrapper.png</PackageIconUrl>

Daikoz.SQLWrapper/Properties/Resources.Designer.cs

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Daikoz.SQLWrapper/Properties/Resources.resx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@
126126
"ConnectionStrings": [
127127
"server=mysqlserver;user id=user1;password=pwd;database=DB1;",
128128
"server=mysqlserver;user id=user2;password=pwd;database=DB2;"
129-
]
129+
],
130+
"HelperRelativePath": ""
130131
}
131132
]</value>
132133
</data>

Daikoz.SQLWrapper/SQLWrapper.cs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,49 @@ public bool Execute()
4848
filePattern = "*.sql";
4949

5050
if (config.RelativePath == null || config.RelativePath.Length == 0)
51-
Execute("", filePattern, config.Namespace, config.ConnectionStrings, config.SQLWrapperPath, cacheDBPath);
51+
Execute("", filePattern, config.Namespace, config.SQLWrapperPath, cacheDBPath, config.CustomTypes);
5252
else
5353
{
5454
foreach (string relativePath in config.RelativePath)
55-
Execute(relativePath, filePattern, config.Namespace, config.ConnectionStrings, config.SQLWrapperPath, cacheDBPath);
55+
Execute(relativePath, filePattern, config.Namespace, config.SQLWrapperPath, cacheDBPath, config.CustomTypes);
56+
}
57+
58+
if (config.HelperRelativePath != null)
59+
{
60+
using (Process sqlwrapperProcess = new Process())
61+
{
62+
string outputPath = Path.Combine(System.Environment.CurrentDirectory, config.HelperRelativePath);
63+
string sqlWrapperPath = config.SQLWrapperPath;
64+
string assemblyDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(SQLWrapper)).Location);
65+
if (!Directory.Exists(Path.Combine(assemblyDirectory, "tools")))
66+
{
67+
// nuget
68+
assemblyDirectory = Path.Combine(assemblyDirectory, "..", "..");
69+
}
70+
if (string.IsNullOrWhiteSpace(sqlWrapperPath))
71+
sqlWrapperPath = Path.Combine(assemblyDirectory, "tools", "SQLWrapper.exe");
72+
73+
sqlwrapperProcess.StartInfo.WorkingDirectory = assemblyDirectory;
74+
sqlwrapperProcess.StartInfo.FileName = sqlWrapperPath;
75+
sqlwrapperProcess.StartInfo.UseShellExecute = false;
76+
sqlwrapperProcess.StartInfo.CreateNoWindow = true;
77+
sqlwrapperProcess.StartInfo.RedirectStandardOutput = true;
78+
sqlwrapperProcess.StartInfo.RedirectStandardError = true;
79+
sqlwrapperProcess.StartInfo.Arguments = "helper -o " + outputPath + " -p namespace=" + config.Namespace + " -x " + Path.Combine("tools", "Template", "CSharp", "Helper.xslt") + " -d " + cacheDBPath;
80+
sqlwrapperProcess.Start();
81+
82+
// Synchronously read the standard output of the spawned process.
83+
StreamReader readerOutput = sqlwrapperProcess.StandardOutput;
84+
_log.LogWarning(readerOutput.ReadToEnd());
85+
86+
StreamReader readerError = sqlwrapperProcess.StandardError;
87+
string error = readerError.ReadToEnd();
88+
if (!string.IsNullOrWhiteSpace(error))
89+
_log.LogError(error);
90+
91+
92+
sqlwrapperProcess.WaitForExit();
93+
}
5694
}
5795

5896
++configIdx;
@@ -103,16 +141,18 @@ private void CacheDatabase(string cacheDBPath, string[] connectionStrings, strin
103141
}
104142
}
105143

106-
private void Execute(string relativePath, string filePattern, string namespaceName, string[] connectionString, string sqlWrapperPath, string cacheDBPath)
144+
private void Execute(string relativePath, string filePattern, string namespaceName, string sqlWrapperPath, string cacheDBPath, string[] customTypes)
107145
{
108146
string directory = Path.Combine(Directory.GetCurrentDirectory(), relativePath);
109147
if (!Directory.Exists(directory))
110148
_log.LogError("SQLWrapper: " + directory + "doesn't exist");
111149
else
112150
{
113151
_log.LogMessage(MessageImportance.Low, "SQLWrapper: Find in directory " + directory + ": " + filePattern);
114-
List<string> listDirectories = new List<string>(Directory.GetDirectories(directory, "*", SearchOption.AllDirectories));
115-
listDirectories.Add(directory);
152+
List<string> listDirectories = new List<string>(Directory.GetDirectories(directory, "*", SearchOption.AllDirectories))
153+
{
154+
directory
155+
};
116156
foreach (string subdirectory in listDirectories)
117157
{
118158
List<string> listFiles = new List<string>(Directory.EnumerateFiles(subdirectory, filePattern, SearchOption.TopDirectoryOnly));
@@ -161,7 +201,13 @@ private void Execute(string relativePath, string filePattern, string namespaceNa
161201
sqlwrapperProcess.StartInfo.Arguments = "wrapper -i";
162202
foreach (string file in listFiles)
163203
sqlwrapperProcess.StartInfo.Arguments += " \"" + file.Replace("\"", "\"\"") + "\" ";
164-
sqlwrapperProcess.StartInfo.Arguments += " -o " + outputFile + " -p namespace=" + newNameSpace + " classname=" + className + " -x " + Path.Combine("tools", "Template", "charpADO.xslt") + " -d " + cacheDBPath;
204+
sqlwrapperProcess.StartInfo.Arguments += " -o " + outputFile + " -p namespace=" + newNameSpace + " classname=" + className + " -x " + Path.Combine("tools", "Template", "CSharp", "ADO.xslt") + " -d " + cacheDBPath;
205+
if (customTypes != null && customTypes.Length > 0)
206+
{
207+
sqlwrapperProcess.StartInfo.Arguments += " -t ";
208+
foreach (string type in customTypes)
209+
sqlwrapperProcess.StartInfo.Arguments += " \"" + type.Replace("\"", "\"\"") + "\" ";
210+
}
165211
sqlwrapperProcess.Start();
166212

167213
// Synchronously read the standard output of the spawned process.

Daikoz.SQLWrapper/SQLWrapperBuild.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class SQLWrapperBuild : Task
1212

1313
public override bool Execute()
1414
{
15-
// Debugger.Launch();
15+
//Debugger.Launch();
1616

1717
if (FileName == null)
1818
{

Daikoz.SQLWrapper/SQLWrapperConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ internal struct SQLWrapperConfig
2020
[DataMember]
2121
public string SQLWrapperPath { get; set; }
2222

23+
[DataMember]
24+
public string[] CustomTypes { get; set; }
25+
26+
[DataMember]
27+
public string HelperRelativePath { get; set; }
2328
}
2429
}
901 KB
Binary file not shown.

0 commit comments

Comments
 (0)