Exemple #1
0
        internal void Sync(bool force)
        {
            if (Enabled)
            {
                ThreadAssist.AssertNotInMainThread();

                CalculateSync();

                if (!force && to_remove.Count > MAX_NOWARN_TRACKS_REMOVAL)
                {
                    throw new PossibleUserErrorException(to_remove.Count);
                }

                Hyena.Log.Debug("Starting DAP sync");

                sync.Dap.DeleteAllTracks(to_remove);
                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);
                        }
                    }
                }

                Hyena.Log.Debug("Ending DAP sync");

                CalculateSync();
                sync.OnUpdated();
            }
        }
Exemple #2
0
        private void SnapshotPlaylists()
        {
            // 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);
                }
            }
        }
Exemple #3
0
        private void SnapshotPlaylists()
        {
            // 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);
                }
            }
        }