dimanche 1 février 2015

How to call a method knowing its signature as a string?

If i have set of business processes like that :



  • Reward

  • Vacation

  • Course

  • Overtime




And every process has an Insert Method Like this :



public string InsertReward()
{
using (IfxConnection con = new IfxConnection(ConfigurationManager.ConnectionStrings["rr35"].ToString()))
{
int affectedRow = -1;
int req_serial = 0;
req_serial = GetMaxSerial(DateTime.Now.Year);
StringBuilder cmdTxt = new StringBuilder();
cmdTxt.Append(" INSERT INTO RewardProcess(gen_year,gen_ser,bonus_type,bonus_date,bonus_desc,main_code,year,emp_num,active_ser) VALUES (?,?,?,?,?,?,?,?,? ) ");
using (var myIfxCmd = new IfxCommand(cmdTxt.ToString(), con))
{
myIfxCmd.CommandType = CommandType.Text;
myIfxCmd.Parameters.Add("gen_year", IfxType.Integer);
myIfxCmd.Parameters.Add("gen_ser", IfxType.Integer);
myIfxCmd.Parameters.Add("bonus_type", IfxType.SmallInt);
myIfxCmd.Parameters.Add("bonus_date", IfxType.Date);
myIfxCmd.Parameters.Add("bonus_desc", IfxType.NVarChar);
myIfxCmd.Parameters.Add("main_code", IfxType.Integer);
myIfxCmd.Parameters.Add("year", IfxType.Integer);
myIfxCmd.Parameters.Add("emp_num", IfxType.Integer);
myIfxCmd.Parameters.Add("active_ser", IfxType.SmallInt);

if (con.State == ConnectionState.Closed)
{
con.Open();
}

myIfxCmd.Parameters[0].Value = ((object)Req_year) ?? DBNull.Value;
myIfxCmd.Parameters[1].Value = ((object)req_serial) ?? DBNull.Value;
myIfxCmd.Parameters[2].Value = ((object)Bonus_type) ?? DBNull.Value;
myIfxCmd.Parameters[3].Value = ((object)Bonus_date) ?? DBNull.Value;
myIfxCmd.Parameters[4].Value = ((object)Bonus_desc) ?? DBNull.Value;
myIfxCmd.Parameters[5].Value = ((object)Main_code) ?? DBNull.Value;
myIfxCmd.Parameters[6].Value = ((object)Year) ?? DBNull.Value;
myIfxCmd.Parameters[7].Value = ((object)Emp_num) ?? DBNull.Value;
myIfxCmd.Parameters[8].Value = ((object)Active_ser) ?? DBNull.Value;
affectedRow = myIfxCmd.ExecuteNonQuery();
}
con.Close();
con.Dispose();
if (affectedRow > 0)
{
return DateTime.Now.Year + "," + req_serial;
}
else if (affectedRow == 0)
{
return string.Empty;
}
else
{
return affectedRow.ToString();
}
}
}




And After the business process insertion ,i insert transaction with the process ID .


Now I want to create a general method(for all Processes) , this method will check the process ID and call its insertion method and after that call the second method concerning the transaction method . i want all this in one transaction using ambient transaction


Is there something in .net allow to call the method knowing its signature as a string?



Void RootMethod(int processId)
{
using(TransactionScope scope = new TransactionScope())
{
//1-Detect the signature of the insertion method by process id then call it by passing the suitable filled object
//2-call transaction method
}
}

How to call a method knowing its signature as a string?

If i have set of business processes like that :



  • Reward

  • Vacation

  • Course

  • Overtime




And every process has an Insert Method Like this :



public string InsertReward()
{
using (IfxConnection con = new IfxConnection(ConfigurationManager.ConnectionStrings["rr35"].ToString()))
{
int affectedRow = -1;
int req_serial = 0;
req_serial = GetMaxSerial(DateTime.Now.Year);
StringBuilder cmdTxt = new StringBuilder();
cmdTxt.Append(" INSERT INTO RewardProcess(gen_year,gen_ser,bonus_type,bonus_date,bonus_desc,main_code,year,emp_num,active_ser) VALUES (?,?,?,?,?,?,?,?,? ) ");
using (var myIfxCmd = new IfxCommand(cmdTxt.ToString(), con))
{
myIfxCmd.CommandType = CommandType.Text;
myIfxCmd.Parameters.Add("gen_year", IfxType.Integer);
myIfxCmd.Parameters.Add("gen_ser", IfxType.Integer);
myIfxCmd.Parameters.Add("bonus_type", IfxType.SmallInt);
myIfxCmd.Parameters.Add("bonus_date", IfxType.Date);
myIfxCmd.Parameters.Add("bonus_desc", IfxType.NVarChar);
myIfxCmd.Parameters.Add("main_code", IfxType.Integer);
myIfxCmd.Parameters.Add("year", IfxType.Integer);
myIfxCmd.Parameters.Add("emp_num", IfxType.Integer);
myIfxCmd.Parameters.Add("active_ser", IfxType.SmallInt);

if (con.State == ConnectionState.Closed)
{
con.Open();
}

myIfxCmd.Parameters[0].Value = ((object)Req_year) ?? DBNull.Value;
myIfxCmd.Parameters[1].Value = ((object)req_serial) ?? DBNull.Value;
myIfxCmd.Parameters[2].Value = ((object)Bonus_type) ?? DBNull.Value;
myIfxCmd.Parameters[3].Value = ((object)Bonus_date) ?? DBNull.Value;
myIfxCmd.Parameters[4].Value = ((object)Bonus_desc) ?? DBNull.Value;
myIfxCmd.Parameters[5].Value = ((object)Main_code) ?? DBNull.Value;
myIfxCmd.Parameters[6].Value = ((object)Year) ?? DBNull.Value;
myIfxCmd.Parameters[7].Value = ((object)Emp_num) ?? DBNull.Value;
myIfxCmd.Parameters[8].Value = ((object)Active_ser) ?? DBNull.Value;
affectedRow = myIfxCmd.ExecuteNonQuery();
}
con.Close();
con.Dispose();
if (affectedRow > 0)
{
return DateTime.Now.Year + "," + req_serial;
}
else if (affectedRow == 0)
{
return string.Empty;
}
else
{
return affectedRow.ToString();
}
}
}




And After the business process insertion ,i insert transaction with the process ID .


Now I want to create a general method(for all Processes) , this method will check the process ID and call its insertion method and after that call the second method concerning the transaction method . i want all this in one transaction using ambient transaction


Is there something in .net allow to call the method knowing its signature as a string?



Void RootMethod(int processId)
{
using(TransactionScope scope = new TransactionScope())
{
//1-Detect the signature of the insertion method by process id then call it by passing the suitable filled object
//2-call transaction method
}
}

Improving ADO.NET impelementation

I have some thoughts about my software design. I have three entities. Order , Order Type and Order Type Items. Order can have 1-N Order Type and Order Type can have 1-N Order Type Item.


I'm working on Xamarin so using ado.net is my only option and I'm still new to ado.net. (I was using EF alot in .NET).


I've create a manager for each entity Order Manager , Order Type Manager and Order Type Item Manager. Each manager is used to provide an interface for the database. I guess they are called Data Access Classes. I use Singleton pattern in each manager.


Ok , so if I want to get the order items for a specific order I have to write something like this :



FSServiceOrder currentOrder = GetCurrentOrder();

List<FSOrderTypeItem> orderItems = FSOrderManager.Instance.GetOrderTypesItems(currentOrder.ServiceOrderID);


What should I change in the design to be able to write something like this smoothly



List<FSOrderTypeItem> orderItems = FSOrderManager.ActiveOrder.GetOrderTypesItems(currentOrder.ServiceOrderID);


And can I incorporate some caching capabilities with this ? I mean like caching the active order and the items of it and so on


Improving ADO.NET impelementation

I have some thoughts about my software design. I have three entities. Order , Order Type and Order Type Items. Order can have 1-N Order Type and Order Type can have 1-N Order Type Item.


I'm working on Xamarin so using ado.net is my only option and I'm still new to ado.net. (I was using EF alot in .NET).


I've create a manager for each entity Order Manager , Order Type Manager and Order Type Item Manager. Each manager is used to provide an interface for the database. I guess they are called Data Access Classes. I use Singleton pattern in each manager.


Ok , so if I want to get the order items for a specific order I have to write something like this :



FSServiceOrder currentOrder = GetCurrentOrder();

List<FSOrderTypeItem> orderItems = FSOrderManager.Instance.GetOrderTypesItems(currentOrder.ServiceOrderID);


What should I change in the design to be able to write something like this smoothly



List<FSOrderTypeItem> orderItems = FSOrderManager.ActiveOrder.GetOrderTypesItems(currentOrder.ServiceOrderID);


And can I incorporate some caching capabilities with this ? I mean like caching the active order and the items of it and so on


Code design: Which pattern to use

I am developing the client-server-architecture of a game. The "Client" class communicates with the server and has to interact with other classes depending on the type of information it receives, for instance: If the client class receives



  • map data then it should interact with the class which stores the maps

  • data about other players (name, ip, ...) then it should interact with the GUI (in order to display the data)


Should the client class store references (pointer) to the "maps" and the "lobbyGUI" class or is this a typical case for using the MVC pattern?


Code design: Which pattern to use

I am developing the client-server-architecture of a game. The "Client" class communicates with the server and has to interact with other classes depending on the type of information it receives, for instance: If the client class receives



  • map data then it should interact with the class which stores the maps

  • data about other players (name, ip, ...) then it should interact with the GUI (in order to display the data)


Should the client class store references (pointer) to the "maps" and the "lobbyGUI" class or is this a typical case for using the MVC pattern?


In java, why is Observable's setChanged() protected?

If a java class, say classA, is extending classB, it cannot extend Observable. But if the setChanged() function were public, instead of protected, we can use composition to create an instance of Observable in classA.


I wonder what was the thought process behind making setChanged() protected.