BusinessMgr 3.0.0.1
This commit is contained in:
@@ -34,6 +34,12 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
ODBC,
|
||||
SQL,
|
||||
}
|
||||
public enum DefinitionOutput
|
||||
{
|
||||
DatabaseSchema,
|
||||
DatabaseDefinitionClass,
|
||||
TableInterfaceClasses
|
||||
}
|
||||
public class Config
|
||||
{
|
||||
public SarandCommonVersion SarandCommonVersion { get; set; } = SarandCommonVersion.VS2019;
|
||||
@@ -48,6 +54,9 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
// Tables to be included (all others excluded) or those to be excluded.
|
||||
public HashSet<String> Tables_Included { get; } = new HashSet<String>(StringComparer.OrdinalIgnoreCase);
|
||||
public HashSet<String> Tables_Excluded { get; } = new HashSet<String>(StringComparer.OrdinalIgnoreCase);
|
||||
public HashSet<String> Tables_ExcludedFromDatabaseSchema { get; } = new HashSet<String>(StringComparer.OrdinalIgnoreCase);
|
||||
public HashSet<String> Tables_ExcludedFromDatabaseDefinitionClass { get; } = new HashSet<String>(StringComparer.OrdinalIgnoreCase);
|
||||
public HashSet<String> Tables_ExcludedFromTableInterfaceClasses { get; } = new HashSet<String>(StringComparer.OrdinalIgnoreCase);
|
||||
// Schema capitalisation - for class name prefix etc - where capitalising first letter is insufficient.
|
||||
public Dictionary<String, String> SchemaNameCapitalisation { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
// Alternative table names.
|
||||
@@ -125,44 +134,41 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
}
|
||||
|
||||
// Table definitions.
|
||||
List<DbDfnTable> tableDfns = new List<DbDfnTable>();
|
||||
foreach (DbDfnTable tableDfn in config.Database.GetTableDfns())
|
||||
{
|
||||
if (!IsValidTable(tableDfn.Name)) continue;
|
||||
tableDfns.Add(tableDfn);
|
||||
}
|
||||
List<DbDfnTable> tableDfns = new List<DbDfnTable>(config.Database.GetTableDfns());
|
||||
|
||||
// Database schema XML.
|
||||
GenerateDatabaseSchemaXml(tableDfns);
|
||||
GenerateDatabaseSchemaXml(tableDfns.Where(item => IsValidTable(item.Name, DefinitionOutput.DatabaseSchema)));
|
||||
|
||||
// Database definition class.
|
||||
GenerateDatabaseDefinitionClass(tableDfns);
|
||||
GenerateDatabaseDefinitionClass(tableDfns.Where(item => IsValidTable(item.Name, DefinitionOutput.DatabaseDefinitionClass)));
|
||||
|
||||
// Database table Classes.
|
||||
foreach (DbDfnTable tableDfn in tableDfns)
|
||||
foreach (DbDfnTable tableDfn in tableDfns.Where(item => IsValidTable(item.Name, DefinitionOutput.TableInterfaceClasses)))
|
||||
GenerateTableInterfaceClass(tableDfn);
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
private bool IsValidTable(String table)
|
||||
private bool IsValidTable(String table, DefinitionOutput output)
|
||||
{
|
||||
if (String.IsNullOrEmpty(table)) return false;
|
||||
if (config.Schema.Tables_Included.Count > 0 && !config.Schema.Tables_Included.ContainsCI(table)) return false;
|
||||
if (config.Schema.Tables_Excluded.Count > 0 && config.Schema.Tables_Excluded.ContainsCI(table)) return false;
|
||||
// Tables excluded from specific output.
|
||||
if (output == DefinitionOutput.DatabaseSchema && config.Schema.Tables_ExcludedFromDatabaseSchema.Contains(table)) return false;
|
||||
if (output == DefinitionOutput.DatabaseDefinitionClass && config.Schema.Tables_ExcludedFromDatabaseDefinitionClass.Contains(table)) return false;
|
||||
if (output == DefinitionOutput.TableInterfaceClasses && config.Schema.Tables_ExcludedFromTableInterfaceClasses.Contains(table)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
private void GenerateDatabaseSchemaXml(List<DbDfnTable> tableDfns)
|
||||
private void GenerateDatabaseSchemaXml(IEnumerable<DbDfnTable> tableDfns)
|
||||
{
|
||||
String filePath = config.OutputDirectory + Path.DirectorySeparatorChar + config.DefinitionClass.Classname + ".xml";
|
||||
// Construct database definition.
|
||||
DbDfnDatabase databaseDfn = new DbDfnDatabase();
|
||||
foreach (DbDfnTable tableDfn in tableDfns)
|
||||
{
|
||||
databaseDfn.AddTable(tableDfn);
|
||||
}
|
||||
using (StreamWriter file = new StreamWriter(filePath))
|
||||
{
|
||||
file.Write(SerializableUtil.ToXml(databaseDfn));
|
||||
@@ -252,8 +258,10 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
//-------------------------------------------------------------------
|
||||
// D a t a b a s e D e f i n i t i o n C l a s s
|
||||
//-------------------------------------------------------------------
|
||||
private void GenerateDatabaseDefinitionClass(List<DbDfnTable> tableDfns)
|
||||
private void GenerateDatabaseDefinitionClass(IEnumerable<DbDfnTable> tableDfns)
|
||||
{
|
||||
// Remove excluded tables.
|
||||
tableDfns = tableDfns.Where(item => IsValidTable(item.Name, DefinitionOutput.DatabaseDefinitionClass)).ToList();
|
||||
String filePath = config.OutputDirectory + Path.DirectorySeparatorChar + config.DefinitionClass.Classname + ".cs";
|
||||
using (StreamWriter file = new StreamWriter(filePath))
|
||||
{
|
||||
@@ -284,7 +292,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
//-------------------------------------------------------------------
|
||||
// D a t a b a s e E n u m s
|
||||
//-------------------------------------------------------------------
|
||||
public static void GenerateDatabaseDefinitionTablesEnum(List<DbDfnTable> tableDfns, StreamWriter file)
|
||||
public static void GenerateDatabaseDefinitionTablesEnum(IEnumerable<DbDfnTable> tableDfns, StreamWriter file)
|
||||
{
|
||||
file.WriteLine(tab2 + "// Table identifiers.");
|
||||
file.WriteLine(tab2 + "public enum TableIdx");
|
||||
@@ -299,7 +307,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public static void GenerateDatabaseDefinitionColumnsEnum(List<DbDfnTable> tableDfns, StreamWriter file)
|
||||
public static void GenerateDatabaseDefinitionColumnsEnum(IEnumerable<DbDfnTable> tableDfns, StreamWriter file)
|
||||
{
|
||||
file.WriteLine(tab2 + "// Column identifiers.");
|
||||
file.WriteLine(tab2 + "public enum ColumnIdx");
|
||||
@@ -315,12 +323,12 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public static void GenerateDatabaseDefinitionClass(List<DbDfnTable> tableDfns, String classnameDefinition, StreamWriter file)
|
||||
public static void GenerateDatabaseDefinitionClass(IEnumerable<DbDfnTable> tableDfns, String classnameDefinition, StreamWriter file)
|
||||
{
|
||||
file.WriteLine(tab2 + "// Data members.");
|
||||
file.WriteLine(tab2 + "private static readonly int tableCount = " + tableDfns.Count + ";");
|
||||
file.WriteLine(tab2 + "private static readonly int tableCount = " + tableDfns.Count() + ";");
|
||||
file.WriteLine(tab2 + "private static readonly int columnCount = " + tableDfns.GetColumnCount() + ";");
|
||||
file.WriteLine(tab2 + "private static ulong maxTextLen = 0;");
|
||||
file.WriteLine(tab2 + "public static ulong MaxTextLen { get; private set; }");
|
||||
file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------");
|
||||
|
||||
// Table methods.
|
||||
@@ -446,7 +454,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(tab2 + "public static void SetMaxTextLen (ulong maxTextLen)");
|
||||
file.WriteLine(tab2 + "{");
|
||||
file.WriteLine(tab3 + classnameDefinition + ".maxTextLen = maxTextLen;");
|
||||
file.WriteLine(tab3 + classnameDefinition + ".MaxTextLen = maxTextLen;");
|
||||
file.WriteLine(tab2 + "}");
|
||||
file.WriteLine(tab2 + "public static bool IsColFmtText (ColumnIdx column)");
|
||||
file.WriteLine(tab2 + "{");
|
||||
@@ -461,7 +469,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
file.WriteLine(tab3 + "if (columns[columnIdx].DataType == DbColumnDataType.VarChar)");
|
||||
file.WriteLine(tab3 + "{");
|
||||
file.WriteLine(tab4 + "ulong textLen = columns[columnIdx].DataLen;");
|
||||
file.WriteLine(tab4 + "if (maxTextLen > 0 && textLen > maxTextLen) textLen = maxTextLen;");
|
||||
file.WriteLine(tab4 + "if (MaxTextLen > 0 && textLen > MaxTextLen) textLen = MaxTextLen;");
|
||||
file.WriteLine(tab4 + "return textLen;");
|
||||
file.WriteLine(tab3 + "}");
|
||||
file.WriteLine(tab3 + "return 0;");
|
||||
@@ -544,7 +552,7 @@ namespace Sarand.Net.Standard.Dbas.Base
|
||||
|
||||
// Reserved words.
|
||||
file.WriteLine(tab2 + "// Reserved words.");
|
||||
file.WriteLine(tab2 + "private static readonly List<String> reservedWords = new List<String>()");
|
||||
file.WriteLine(tab2 + "private static readonly HashSet<String> reservedWords = new HashSet<String>()");
|
||||
file.WriteLine(tab2 + "{");
|
||||
foreach (String reservedword in reservedWords)
|
||||
file.WriteLine(tab3 + "\"" + reservedword + "\", ");
|
||||
|
||||
Reference in New Issue
Block a user