Hello:
Little by little and thanks to the Help of Tedd the Events API
implementation is in the right way, here is a little example of use:
public static void Main(string[] args)
{
string connectionString =
"User=SYSDBA;" +
"Password=masterkey;" +
@"Database=TESTDB.GDB;" +
"DataSource=localhost;" +
"Port=3050;" +
"Dialect=3;" +
"Charset=NONE;" +
"Role=;" +
"Connection lifetime=15;" +
"Pooling=false;" +
"Packet Size=8192";
FbConnection connection = new FbConnection(connectionString);
connection.Open();
FbTransaction transaction = connection.BeginTransaction();
FbEvents fbEvents = new FbEvents(connection);
FbEventAlertEventHandler e = new
FbEventAlertEventHandler(EventAlertHandler);
fbEvents.EventAlert += e;
fbEvents.RegisterEvents("new row", "updated row");
// First Event Request
fbEvents.QueEvents();
FbCommand command = new FbCommand("UPDATE test_table_01 SET char_field
= 'events test' WHERE INT_FIELD = 3", connection , transaction);
command.ExecuteNonQuery();
transaction.Commit();
fbEvents.QueEvents();
transaction = connection.BeginTransaction();
// Second Event Request
fbEvents.QueEvents();
command = new FbCommand("DELETE FROM test_table_01 WHERE int_field =
3", connection , transaction);
command.ExecuteNonQuery();
command.CommandText = "UPDATE test_table_01 SET char_field = 'events
test'";
command.ExecuteNonQuery();
command.CommandText = "UPDATE test_table_01 SET char_field = 'events
test 2'";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO test_table_01 (int_field) VALUES (3)";
command.ExecuteNonQuery();
transaction.Commit();
fbEvents.QueEvents();
connection.Close();
Console.ReadLine();
}
public static void EventAlertHandler(object sender, FbEventAlertEventArgs e)
{
for (int i = 0; i < e.Counts.Length; i++)
{
Console.WriteLine(e.Counts[i]);
}
}
Tedd has asked to me if the programmer should be responsible for calling
QueEvents each time an event is received? or should the provider do it?
I think that it's better to left this responsability to the programmer
but i want to know opinions about this.
--
Best regards
Carlos Guzmán Álvarez
Vigo-Spain
|