//-------------------------------------------------------------------------------------------------------------------- protected void DoStoredProc(Program p, string fqstoredprocedure) { Helper h = new Helper(); StoredProcedureParameterInfo sppi = new StoredProcedureParameterInfo(); StoredProcedureResultsetInfo sprsi = new StoredProcedureResultsetInfo(); var schemastoredprocedure = h.SplitSchemaFromTable(fqstoredprocedure); string thedatabase = h.GetCsharpClassName(null, null, p._databaseName); string csharpnamespace = p._namespace + "." + p._storedProcsSubDirectory; string csharpstoredproc = h.GetCsharpClassName(p._prefixObjectsWithSchema, schemastoredprocedure.Item1, schemastoredprocedure.Item2); string csharpfile = p._directory + @"\" + p._storedProcsSubDirectory + @"\" + csharpstoredproc + ".cs"; string thefactoryclass = "StoredProcedureFactory"; string csharpfactoryfile = p._directory + @"\" + p._storedProcsSubDirectory + @"\" + thefactoryclass + ".cs"; // do each stored proc in a separate file, but same factory class h.MessageVerbose("[{0}]", csharpfile); // check for dud parameters - cursor, table - ignore the sp if so if (sppi.HasDudParameterStoredProcedure(fqstoredprocedure)) { h.MessageVerbose("[{0}] Ignoring stored procedure because it has dud parameters.", fqstoredprocedure); return; } // get sp parameters List <string> parameters = new List <string>(); parameters.Add("connˡ"); var spparameters = sppi.GetStoredProcedureParameterInfo(fqstoredprocedure); if (spparameters != null) { foreach (var spparameter in spparameters) { parameters.Add(spparameter.Name); } } parameters.Add("tranˡ"); // the results sets var rsi = sprsi.GetResultsetInfo(fqstoredprocedure); // write out the stored proc wrapper to its file using (StreamWriter sw = new StreamWriter(csharpfile, false, UTF8Encoding.UTF8)) { int tab = 0; // header h.WriteCodeGenHeader(sw); h.WriteUsing(sw, p._namespace); // namespace using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace)) { using (ClassBlock cb = new ClassBlock( sw, tab++, thefactoryclass, "acr.StoredProcedureFactoryBase< " + "ns." + p._databaseSubDirectory + "." + thedatabase + "DatabaseSingletonHelper, " + "ns." + p._databaseSubDirectory + "." + thedatabase + "Database >")) { // execute block h.MessageVerbose("[{0}].[{1}]", csharpnamespace, csharpstoredproc); using (StoredProcedureFactoryExecuteBlock mb = new StoredProcedureFactoryExecuteBlock( p, sw, tab, fqstoredprocedure, csharpstoredproc, parameters, sppi, rsi)) {} } // end class } // end namespace } // eof // write out the classes for stored proc result sets, if any int i = 0; foreach (var rs in rsi.Resultsets) { i++; string therecordsetclass = csharpstoredproc + h.IdentifierSeparator + "rs" + i; string csharprecordsetfile = p._directory + @"\" + p._storedProcsSubDirectory + @"\" + csharpstoredproc + ".rs" + i + ".cs"; h.MessageVerbose("[{0}]", csharprecordsetfile); using (StreamWriter sw = new StreamWriter(csharprecordsetfile, false, UTF8Encoding.UTF8)) { int tab = 0; // header h.WriteCodeGenHeader(sw); h.WriteUsing(sw, p._namespace); // namespace using (NamespaceBlock nsb = new NamespaceBlock(sw, tab++, csharpnamespace)) { using (ClassBlock cb = new ClassBlock(sw, tab++, therecordsetclass, "acr.RowBase")) { h.MessageVerbose("[{0}].[{1}] row", csharpnamespace, therecordsetclass); using (StoredProcedureRowConstructorBlock mb = new StoredProcedureRowConstructorBlock(sw, tab, therecordsetclass, rs.Columns)) {} } // end class } // end namespace } // eof } } // end do sp
protected void Init() { Helper h = new Helper(); Settings settings = new Settings(); _codegenFile = _args[0]; h.MessageVerbose("Config file [{0}]", _codegenFile); // load the xml configuration file _codegen.Load(_codegenFile); // basic codegen info _namespace = _codegen.SelectSingleNode("/CodeGen/Namespace").InnerText; h.MessageVerbose("Namespace [{0}]", _namespace); _resourceNamespace = _codegen.SelectSingleNode("/CodeGen/ResourceNamespace").InnerText; h.MessageVerbose("ResourceNamespace [{0}]", _resourceNamespace); _directory = _codegen.SelectSingleNode("/CodeGen/Directory").InnerText; h.MessageVerbose("Directory [{0}]", _directory); _connectionString = _codegen.SelectSingleNode("/CodeGen/ConnectionString").InnerText; h.MessageVerbose("ConnectionString [{0}]", _connectionString); _concurrencyColumn = _codegen.SelectSingleNode("/CodeGen/ConcurrencyColumn").InnerText; h.MessageVerbose("ConcurrencyColumn [{0}]", _concurrencyColumn); string prefixes = _codegen.SelectSingleNode("/CodeGen/PrefixObjectsWithSchema").InnerText; h.MessageVerbose("PrefixObjectsWithSchema [{0}]", prefixes); _prefixObjectsWithSchema = new List <string>(prefixes.ToUpper().Split(',')); // items related to auto codegened unit test _unitTestNamespace = _codegen.SelectSingleNode("/CodeGen/UnitTest/Namespace").InnerText; h.MessageVerbose("Unit test namespace [{0}]", _unitTestNamespace); _unitTestDirectory = _codegen.SelectSingleNode("/CodeGen/UnitTest/Directory").InnerText; h.MessageVerbose("Unit test directory [{0}]", _unitTestDirectory); _unitTestTableNamespace = _codegen.SelectSingleNode("/CodeGen/UnitTest/TableNamespace").InnerText; h.MessageVerbose("Unit test table namespace [{0}]", _unitTestTableNamespace); _unitTestTableNamespacePrefix = _codegen.SelectSingleNode("/CodeGen/UnitTest/TableNamespacePrefix").InnerText; h.MessageVerbose("Unit test table namespace prefix [{0}]", _unitTestTableNamespacePrefix); _threads = settings.Threads; h.MessageVerbose("Threads [{0}]", _threads); _tableSubDirectory = _codegen.SelectSingleNode("/CodeGen/Tables/@SubDirectory").Value; h.MessageVerbose("Table subdirectory [{0}]", _tableSubDirectory); _viewSubDirectory = _codegen.SelectSingleNode("/CodeGen/Views/@SubDirectory").Value; h.MessageVerbose("View subdirectory [{0}]", _viewSubDirectory); _querySubDirectory = _codegen.SelectSingleNode("/CodeGen/Queries/@SubDirectory").Value; h.MessageVerbose("Query subdirectory [{0}]", _querySubDirectory); _queries = _codegen.SelectNodes("/CodeGen/Queries/Query"); // connect to the database so we can do some code jen ! _connection = new SqlConnection(_connectionString); _connection.Open(); // get all the database metadata that we may need ! _di.CreateDatabaseInfo(_connection); _databaseName = _di.GetDatabaseName(); h.MessageVerbose("DatabaseName [{0}]", _databaseName); DataSetHelper dsh = new DataSetHelper(_di.GetDatabaseInfo()); h.MessageVerbose("Database information:\n\n{0}", dsh.ToString()); ColumnInfo ci = new ColumnInfo(); ci.CreateColumnInfo(_connection, _di.Tables.Get(), _di.Views.Get(), _directory, _querySubDirectory, _queries); h.MessageVerbose("Table, view and query column information:\n\n{0}", ci.ToString()); StoredProcedureParameterInfo sppi = new StoredProcedureParameterInfo(); sppi.CreateStoredProcedureInfo(_di); StoredProcedureResultsetInfo sprsi = new StoredProcedureResultsetInfo(); sprsi.CreateStoredProcedureInfo(_connection, _di, _codegen, sppi); h.MessageVerbose("Stored procedure resultset information:\n\n{0}", sprsi.ToString()); }