f-spot r4295 - in trunk: . src



Author: sdelcroix
Date: Tue Aug 26 07:14:10 2008
New Revision: 4295
URL: http://svn.gnome.org/viewvc/f-spot?rev=4295&view=rev

Log:
2008-08-26  Stephane Delcroix  <sdelcroix novell com>

	* src/Db.cs:
	* src/QueuedSqliteDatabase.cs: move the Connect out of the ProcessQueue
	thread so we can catch connect exception. Add an event handler for
	ExceptionThrown.

	* src/FSpot.addin.xml: bump addin version.


Modified:
   trunk/ChangeLog
   trunk/src/Db.cs
   trunk/src/FSpot.addin.xml
   trunk/src/QueuedSqliteDatabase.cs

Modified: trunk/src/Db.cs
==============================================================================
--- trunk/src/Db.cs	(original)
+++ trunk/src/Db.cs	Tue Aug 26 07:14:10 2008
@@ -145,6 +145,10 @@
 	bool empty;
 	string path;
 
+	public delegate void ExceptionThrownHandler (Exception e);
+	public event ExceptionThrownHandler ExceptionThrown;
+
+
 	public TagStore Tags {
 		get { return tag_store; }
 	}
@@ -213,6 +217,8 @@
 			throw new Exception (path + ": File not found");
 
 		database = new QueuedSqliteDatabase(path);
+		database.ExceptionThrown += HandleDbException;
+
 		if (database.GetFileVersion(path) == 2)
 			SqliteUpgrade ();
 
@@ -236,6 +242,14 @@
 		Log.DebugTimerPrint (timer, "Db Initialization took {0}");
 	}
 
+	void HandleDbException (Exception e)
+	{
+		if (ExceptionThrown != null)
+			ExceptionThrown (e);
+		else
+			throw e;
+	}
+
 	public bool Empty {
 		get {
 			return empty;

Modified: trunk/src/FSpot.addin.xml
==============================================================================
--- trunk/src/FSpot.addin.xml	(original)
+++ trunk/src/FSpot.addin.xml	Tue Aug 26 07:14:10 2008
@@ -1,6 +1,6 @@
 <Addin namespace = "FSpot" 
        id = "Core" 
-       version = "0.4.4.102"
+       version = "0.4.4.103"
        compatVersion = "0.4.4.100"
        isroot="true">
 

Modified: trunk/src/QueuedSqliteDatabase.cs
==============================================================================
--- trunk/src/QueuedSqliteDatabase.cs	(original)
+++ trunk/src/QueuedSqliteDatabase.cs	Tue Aug 26 07:14:10 2008
@@ -82,9 +82,27 @@
         /// </summary>
         private AutoResetEvent queue_signal = new AutoResetEvent(false);
         
+	public delegate void ExceptionThrownHandler (Exception e);
+	public event ExceptionThrownHandler ExceptionThrown;
+
         public QueuedSqliteDatabase(string dbpath)
         {
             this.dbpath = dbpath;
+
+            // Connect
+            if(connection == null) {
+                version = GetFileVersion(dbpath);
+                if (version == 3) {
+                    connection = new SqliteConnection("Version=3,URI=file:" + dbpath);
+                } else if (version == 2) {
+                    connection = new SqliteConnection("Version=2,encoding=UTF-8,URI=file:" + dbpath);
+                } else {
+                    throw new Exception("Unsupported SQLite database version");
+                }
+                connection.Open();
+                connected = true;
+            }
+ 
             queue_thread = new Thread(ProcessQueue);
             queue_thread.IsBackground = true;
             queue_thread.Start();
@@ -261,20 +279,8 @@
 
         private void ProcessQueue()
         {         
-            // Connect
-            if(connection == null) {
-                version = GetFileVersion(dbpath);
-                if (version == 3) {
-                    connection = new SqliteConnection("Version=3,URI=file:" + dbpath);
-                } else if (version == 2) {
-                    connection = new SqliteConnection("Version=2,encoding=UTF-8,URI=file:" + dbpath);
-                } else {
-                    throw new Exception("Unsupported SQLite database version");
-                }
-                connection.Open();
-                connected = true;
-            }
-            
+	    try {
+           
             // Keep handling queries
             while(!dispose_requested) {
                 while(command_queue.Count > 0) {
@@ -291,6 +297,12 @@
 
             // Finish
             connection.Close();
+	    } catch (Exception e) {
+		    if (ExceptionThrown != null)
+			    ExceptionThrown (e);
+		    else
+			    throw;
+	    }
         }
 
         public int GetFileVersion(string path) 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]