protected virtual void OnPlaylistTracksDownloaded(DownloadedTracksEventArgs args)
        {
            var handler = PlaylistTracksDownloaded;

            if (handler != null)
            {
                handler(this, args);
            }
        }
        private void OnTubeManagerPlaylistTracksDownloaded(object sender, EventArgs args)
        {
            DownloadedTracksEventArgs track_args = args as DownloadedTracksEventArgs;

            IDictionary <string, object> [] chunk = track_args.tracks as IDictionary <string, object> [];
            if (chunk == null)
            {
                return;
            }

            LibraryDownload d = track_args.download as LibraryDownload;

            ThreadAssist.ProxyToMain(delegate {
                SetStatus(String.Format(AddinManager.CurrentLocalizer.GetString("Loading {0} of {1}"),
                                        CalculateLoadingTracks(chunk.Length, d.TotalExpected),
                                        d.TotalExpected), false);
            });

            ContactPlaylistSource source = null;

            if (playlist_map.ContainsKey(d))
            {
                source = playlist_map[d];
            }
            else
            {
                source = new ContactPlaylistSource(track_args.name, this);
                playlist_map.Add(d, source);
            }

            source.AddTracks(chunk);

            ThreadAssist.ProxyToMain(delegate {
                if (d != null && d.IsFinished)
                {
                    Hyena.Log.DebugFormat("Download complete for {0}", source.Name);
                    AddChildSource(source);
                    playlist_map.Remove(d);
                    HideStatus();
                }
            });
        }
        private void OnTubeManagerTracksDownloaded(object sender, EventArgs args)
        {
            DownloadedTracksEventArgs track_args = args as DownloadedTracksEventArgs;

            IDictionary <string, object> [] chunk = track_args.tracks as IDictionary <string, object> [];
            if (chunk == null)
            {
                return;
            }

            LibraryDownload d = track_args.download as LibraryDownload;

            ThreadAssist.ProxyToMain(delegate {
                SetStatus(String.Format(AddinManager.CurrentLocalizer.GetString("Loading {0} of {1}"),
                                        CalculateLoadingTracks(chunk.Length, d.TotalExpected),
                                        d.TotalExpected), false);
            });

            HyenaSqliteConnection conn = ServiceManager.DbConnection;

            conn.BeginTransaction();

            for (int i = 0; i < chunk.Length; i++)
            {
                IDictionary <string, object> track         = chunk[i];
                ContactTrackInfo             contact_track = new ContactTrackInfo(track, this);

                // notify once per chunk
                if (i == chunk.Length - 1)
                {
                    conn.CommitTransaction();
                    contact_track.Save(true);
                }
                else
                {
                    contact_track.Save(false);
                }
            }
        }