@@ -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.
0 commit comments