[banshee] Dap: refactoring (extract method)



commit 553e9e72bdecd25f7c431ebbee3f14759c014f3f
Author: Andres G. Aragoneses <knocte gmail com>
Date:   Fri Jan 20 00:57:27 2012 +0000

    Dap: refactoring (extract method)
    
    Extract method to have two small methods
    instead of a much larger one, increasing
    readibility and levels of abstraction.

 src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs |   59 +++++++++++---------
 1 files changed, 32 insertions(+), 27 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs b/src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs
index b0b846e..8a35cc2 100644
--- a/src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs
+++ b/src/Dap/Banshee.Dap/Banshee.Dap/DapLibrarySync.cs
@@ -217,33 +217,7 @@ namespace Banshee.Dap
                 sync.Dap.AddAllTracks (to_add);
 
                 if (library.SupportsPlaylists && sync.Dap.SupportsPlaylists) {
-                    // Now create the playlists, taking snapshots of smart playlists and saving them
-                    // as normal playlists
-                    IList<AbstractPlaylistSource> playlists = GetSyncPlaylists ();
-                    foreach (AbstractPlaylistSource from in playlists) {
-                        if (from.Count == 0) {
-                            continue;
-                        }
-                        var to = new SyncPlaylist (from.Name, sync.Dap, this);
-                        to.Save ();
-
-                        ServiceManager.DbConnection.Execute (
-                            String.Format (
-                                @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
-                                    SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND MetadataHash IN
-                                        (SELECT MetadataHash FROM {0} WHERE {1})",
-                                from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition),
-                            to.DbId, sync.Dap.DbId
-                        );
-                        to.UpdateCounts ();
-
-                        if (to.Count == 0) {
-                            // If it's empty, don't leave it on the device
-                            to.Unmap ();
-                        } else {
-                            sync.Dap.AddChildSource (to);
-                        }
-                    }
+                    SyncPlaylists ();
                 }
 
                 Hyena.Log.Debug ("Ending DAP sync");
@@ -253,6 +227,37 @@ namespace Banshee.Dap
             }
         }
 
+        private void SyncPlaylists ()
+        {
+            // Now create the playlists, taking snapshots of smart playlists and saving them
+            // as normal playlists
+            IList<AbstractPlaylistSource> playlists = GetSyncPlaylists ();
+            foreach (AbstractPlaylistSource from in playlists) {
+                if (from.Count == 0) {
+                    continue;
+                }
+                var to = new SyncPlaylist (from.Name, sync.Dap, this);
+                to.Save ();
+
+                ServiceManager.DbConnection.Execute (
+                    String.Format (
+                        @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
+                            SELECT ?, TrackID FROM CoreTracks WHERE PrimarySourceID = ? AND MetadataHash IN
+                                (SELECT MetadataHash FROM {0} WHERE {1})",
+                        from.DatabaseTrackModel.ConditionFromFragment, from.DatabaseTrackModel.Condition),
+                    to.DbId, sync.Dap.DbId
+                );
+                to.UpdateCounts ();
+
+                if (to.Count == 0) {
+                    // If it's empty, don't leave it on the device
+                    to.Unmap ();
+                } else {
+                    sync.Dap.AddChildSource (to);
+                }
+            }
+        }
+
         internal class PossibleUserErrorException : ApplicationException
         {
             internal int TracksToRemove { get; private set; }



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