private void RunCompile(Source source) { source.Clear(); java.io.StringWriter writer = new java.io.StringWriter(); try { java.io.PrintWriter log = new java.io.PrintWriter(writer); try { string currDir = Directory.GetCurrentDirectory(); try { FileInfo info = new FileInfo(source.FileName); LogVerbose = "Changing to " + info.DirectoryName; Directory.SetCurrentDirectory(info.DirectoryName); LogVerbose = "Compiling " + info.Name; bbd.jportal.Database database = JPortal.run(info.FullName, log); RunGenerators(database, log); } finally { Directory.SetCurrentDirectory(currDir); } } finally { log.flush(); log.close(); } string result = writer.ToString(); char[] sep = { '\n' }; string[] lines = result.Split(sep); for (int i = 0; i < lines.Length; i++) { string line = lines[i].Trim(); if (line.Length == 0) { continue; } if (line.IndexOf("Code: ") == 0) { source.Add(line.Substring(6).Trim()); } else if (line.IndexOf("DDL: ") == 0) { source.Add(line.Substring(5).Trim()); } LogInfo = line; } } finally { writer.close(); } }
private void RunGenerators(bbd.jportal.Database database, java.io.PrintWriter log) { object[] args = { database, typeof(string), log }; string name = source.ToString("S"); for (int i = 0; i < generatorList.Count; i++) { string generatorKey = string.Format("{0}.{1}Generator", name, generatorList.GetKey(i)); if (project.Switch.IndexOfKey(generatorKey) == -1) { continue; } bool required = bool.Parse((string)project.Switch[generatorKey]); if (required == false) { continue; } string directoryKey = string.Format("{0}.{1}Directory", source.ToString("S"), generatorList.GetKey(i)); if (project.Switch.IndexOfKey(generatorKey) != -1) { args[1] = project.Switch[directoryKey]; } MethodInfo method = generatorList.GetByIndex(i) as MethodInfo; if (method == null) { LogWarn = "No proper generator for " + name; continue; } try { method.Invoke(null, args); } catch { LogVerbose = "Generation failed for " + name; } } }