using TriAxis.RunSharp
public void GenerateMsgs()
{
#region Init
string strAssemblyName = "GenApp.Generated";
string strAssemblyDirPath = @"D:\GenApp\ga_dev\ga_dev\Bin\"; //refers to the GenApp's bin folder
string strDbHost = "hostName"; //the hostName of the db
string strDbName = "dbName"; //the name of the db
string strLoginName = "dbLoginName";
string strLoginPass = "dbLoginPass";
string strTableName = "Lang_en_US_Msg"; //the table where to get the vals
string strConnectionStringTemplate = "Data Source={0:G};Initial Catalog={1:G};Persist Security Info=False;User ID={2:G};Password={3:G};MultipleActiveResultSets=True";
string connectionString = String.Format(strConnectionStringTemplate, strDbHost, strDbName,
strLoginName, strLoginPass);
#endregion Init
#region InitializeTheAssemblyGeneratingEnvironment
// Get the current application domain for the current thread
AppDomain objAppDomainCurrent = AppDomain.CurrentDomain;
// Create a dynamic assembly in the current application domain,
// and allow it to be executed and saved to disk.
AssemblyName objAssemblyName = new AssemblyName(strAssemblyName);
//Create the assembly generator
AssemblyGen objAssemblyGen = new AssemblyGen
(objAppDomainCurrent, objAssemblyName, AssemblyBuilderAccess.RunAndSave,
strAssemblyDirPath + strAssemblyName + ".dll", true);
objAssemblyGen.Public.Namespace("GenApp.Generated");
#endregion InitializeTheAssemblyGeneratingEnvironment
#region GetTheDataFromTheDatabase
DataTable objDataTableForEnum = new DataTable(strTableName);
#region FillUpTheDataTable
using (SqlConnection objSqlConnection = new SqlConnection(connectionString))
{
SqlCommand objSqlCommand = objSqlConnection.CreateCommand();
objSqlCommand.CommandText = string.Format("SELECT [MsgId],[MsgKey] FROM [ocms_dev].[dbo].[Lang_en_US_Msg]");
//Console.WriteLine("command.CommandText is " + objSqlCommand.CommandText);
objSqlConnection.Open();
objDataTableForEnum.Load(objSqlCommand.ExecuteReader(CommandBehavior.CloseConnection));
} //eof using
#endregion FillUpTheDataTable
#region GenerateTheClass
TypeGen objClassTypeGen = objAssemblyGen.Public.Class("ConstMsg", typeof(object));
{
CodeGen g = objClassTypeGen.Public.Constructor();
{
foreach (DataRow dr in objDataTableForEnum.Rows)
{
string msgKey = dr[1].ToString();
FieldGen objXvalFieldGen =
objClassTypeGen.Private.Field(typeof(string), msgKey, msgKey);
PropertyGen objPropertyGenForXVal =
objClassTypeGen.Public.SimpleProperty(objXvalFieldGen, msgKey.ToUpper());
g.Assign(objPropertyGenForXVal, msgKey);
} //eof foreach DataRow
} //eof CodeGen
}//eof TypeGen
#endregion GenerateTheClass
#endregion GetTheDataFromTheDatabase
// Finally, save the assembly
objAssemblyGen.Save();
Console.WriteLine("\n HIT A KEY TO EXIT ");
Console.ReadLine();
} //eof method
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!