From 408b7c2c49369a43423272a739a8e3ffff5447af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Laval?= Date: Fri, 21 Jan 2011 15:26:57 +0000 Subject: Add ConnectionOpened event to Database --- mcs/class/WebMatrix.Data/WebMatrix.Data/Database.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mcs/class/WebMatrix.Data') diff --git a/mcs/class/WebMatrix.Data/WebMatrix.Data/Database.cs b/mcs/class/WebMatrix.Data/WebMatrix.Data/Database.cs index c5d52066006..00aacf2b259 100644 --- a/mcs/class/WebMatrix.Data/WebMatrix.Data/Database.cs +++ b/mcs/class/WebMatrix.Data/WebMatrix.Data/Database.cs @@ -39,6 +39,8 @@ namespace WebMatrix.Data { public class Database : IDisposable { + public static event EventHandler ConnectionOpened; + DbConnection connection; private Database (DbConnection connection) @@ -86,7 +88,10 @@ namespace WebMatrix.Data PrepareCommandParameters (command, args); connection.Open (); + TriggerConnectionOpened (this, connection); + var result = command.ExecuteNonQuery (); + connection.Close (); command.Dispose (); @@ -115,6 +120,7 @@ namespace WebMatrix.Data var rows = new List> (); connection.Open (); + TriggerConnectionOpened (this, connection); using (var reader = command.ExecuteReader ()) { if (!reader.Read () || !reader.HasRows) @@ -148,7 +154,10 @@ namespace WebMatrix.Data PrepareCommandParameters (command, args); connection.Open (); + TriggerConnectionOpened (this, connection); + var result = command.ExecuteScalar (); + connection.Close (); command.Dispose (); @@ -175,6 +184,13 @@ namespace WebMatrix.Data } } + static TriggerConnectionOpened (Database self, DbConnection connection) + { + EventHandler evt = ConnectionOpened; + if (evt != null) + evt (self, new ConnectionEventArgs (connection)); + } + public DbConnection Connection { get { return connection; -- cgit v1.2.3