banshee r4398 - in trunk/banshee: . src/Dap/Banshee.Dap/Banshee.Dap src/Libraries/Hyena/Hyena.Data.Sqlite



Author: gburt
Date: Tue Aug 19 00:01:20 2008
New Revision: 4398
URL: http://svn.gnome.org/viewvc/banshee?rev=4398&view=rev

Log:
2008-08-18  Gabriel Burt  <gabriel burt gmail com>

	* src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs: Add inner class for
	testing sync logic.  Currently will calculate how many items are on the
	device but not in the library and vice versa, and logs that info.

	* src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs: Add new
	HyenaDataReader convenience class.

	* src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs: Use the
	QueryEnumerable<T> method instead of manually reading the IDataReader.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
   trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs

Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs	(original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapSource.cs	Tue Aug 19 00:01:20 2008
@@ -34,6 +34,7 @@
 
 using Hyena;
 using Hyena.Data.Sqlite;
+
 using Banshee.Base;
 using Banshee.ServiceStack;
 using Banshee.Sources;
@@ -201,6 +202,75 @@
         
 #region Track Management/Syncing   
 
+        public void SyncWith (PrimarySource source)
+        {
+            try {
+                SourceSync from_music = new SourceSync (ServiceManager.SourceManager.MusicLibrary, this);
+                Log.Information (from_music.ToString ());
+                
+                SourceSync to_music = new SourceSync (this, ServiceManager.SourceManager.MusicLibrary);
+                Log.Information (to_music.ToString ());
+            } catch (Exception e) {
+                Log.Exception (e);
+            }
+        }
+        
+        public class SourceSync
+        {
+            const string intersection = @"PrimarySourceId = ? AND MetadataHash NOT IN 
+                    (SELECT MetadataHash FROM CoreTracks WHERE PrimarySourceID = ?)";
+            
+            PrimarySource from, to;
+            int count;
+            long file_size;
+            TimeSpan duration;
+            
+            public SourceSync (PrimarySource from, PrimarySource to)
+            {
+                this.from = from;
+                this.to = to;
+                Update ();
+            }
+            
+            public void Update ()
+            {
+                using (new Hyena.Timer ("seeing what there is to sync")) {
+                    using (HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query (SelectSql (
+                        "COUNT(*), SUM(FileSize), SUM(Duration)")))) {
+                        count = reader.Get<int> (0);
+                        file_size = reader.Get<long> (1);
+                        duration = reader.Get<TimeSpan> (2); 
+                    }
+                }
+            }
+                    
+            private HyenaSqliteCommand SelectSql (string select)
+            {
+                return new HyenaSqliteCommand (
+                    String.Format ("SELECT {0} FROM CoreTracks WHERE {1}", select, intersection),
+                    from.DbId, to.DbId
+                );
+            }
+            
+            public int Count {
+                get { return count; }
+            }
+            
+            public long FileSize {
+                get { return file_size; }
+            }
+            
+            public TimeSpan Duration {
+                get { return duration; }
+            }
+            
+            public override string ToString ()
+            {
+                return String.Format ("There are {0} items, {1} MB, and {2} to sync from {3} to {4}",
+                    count, file_size/(1024*1024), duration, from, to);
+            }
+        }
+        
         public void LoadDeviceContents ()
         {
             ThreadPool.QueueUserWorkItem (ThreadedLoadDeviceContents);
@@ -214,6 +284,8 @@
                 LoadFromDevice ();
                 OnTracksAdded ();
                 HideStatus ();
+                
+                SyncWith (ServiceManager.SourceManager.MusicLibrary);
             } catch (Exception e) {
                 Log.Exception (e);
             }

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/HyenaSqliteConnection.cs	Tue Aug 19 00:01:20 2008
@@ -39,6 +39,33 @@
 
 namespace Hyena.Data.Sqlite
 {
+    public class HyenaDataReader : IDisposable
+    {
+        private IDataReader reader;
+        
+        public HyenaDataReader (IDataReader reader)
+        {
+            this.reader = reader;
+            reader.Read ();
+        }
+        
+        public T Get<T> (int i)
+        {
+            return (T) SqliteUtils.FromDbFormat (typeof(T), reader[i]);
+        }
+        
+        public bool Read ()
+        {
+            return reader.Read ();
+        }
+        
+        public void Dispose ()
+        {
+            reader.Dispose ();
+            reader = null;
+        }
+    }
+    
     public class ExecutingEventArgs : EventArgs
     {
         public readonly SqliteCommand Command;
@@ -120,7 +147,7 @@
             Type type = typeof (T);
             using (IDataReader reader = Query (command)) {
                 while (reader.Read ()) {
-                    yield return (T)SqliteUtils.FromDbFormat (type, reader[0]);
+                    yield return (T) SqliteUtils.FromDbFormat (type, reader[0]);
                 }
             }
         }

Modified: trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs	Tue Aug 19 00:01:20 2008
@@ -348,11 +348,9 @@
 
                 model.Selection.Clear (false);
 
-                using (IDataReader reader = connection.Query (get_selection_command)) {
-                    while (reader.Read ()) {
-                        selected_id = Convert.ToInt64 (reader[0]) - first_id;
-                        model.Selection.QuietSelect ((int)selected_id);
-                    }
+                foreach (long order_id in connection.QueryEnumerable<long> (get_selection_command)) {
+                    selected_id = order_id - first_id;
+                    model.Selection.QuietSelect ((int)selected_id);
                 }
 
                 if (has_select_all_item && model.Selection.Count == 0) {



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